The bells. the bells... lazarus / 31-LCL ---------------------------------------------------------------------- MarkMLl · 2019-11-15 20:37 Is there a fairly portable way of getting a beep out of an LCL program, typically not invoked from the system console or an SSH shell? I'm porting a program originally written using Delphi which happily goes "beep" when I output #$07. So far the only way I can get a beep in e.g. a Linux ssh session is to run the xkbbell utility. I could obviously start messing around with Alsa etc., but is there a "correct" way of doing this? It's nothing of earth-shattering importance, merely a simulated getty to test a simulated modem. As usual, apologies if this is a frequently-answered question. MarkMLl ---------------------------------------------------------------------- sstvmaster · 2019-11-15 20:51 Hi, Beep is in unit SysUtils eg: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SysUtils.Beep; and in unit Windows: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Windows.Beep(1000,250); ---------------------------------------------------------------------- MarkMLl · 2019-11-15 21:05 Sysutils.Beep has no apparent effect inside an LCL-based app (not started from a shell session etc.). I presume the Windows unit is Windows-specific. MarkMLl ---------------------------------------------------------------------- MarkMLl · 2019-11-17 11:39 Emphasising that this is an X11-specific question, I've been having a bit of a play with this referring to the source of xkbbell (in C) and the relevant FPC libraries. https://gitlab.freedesktop.org/xorg/app/xkbutils/blob/master/xkbbell.c Cutting out all the optional parameters I'm left with Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program xkbbell; uses  xkb, xkblib, xlib, x; var  dpyName: string= '';  volume: integer= 99;  devSpec: integer= xkb.XkbUseCoreKbd;  xlass: integer= -1;  id: integer= -1;  bellName: string= '';  nameAtom: TAtom= x.None;  synch: integer= 0;  win: integer= x.None;  force: integer= 0;  nobeep: integer= 0;  function parseArgs(): integer; begin  result := 1end { parseArgs } ;  var  dpy: PDisplay;  ok: boolean;  begin  if parseArgs() < 1 then begin    WriteLn(StdErr, 'Sorry, helpless');    Halt(1)  end;  dpy := XOpenDisplay(nil (* PChar(dpyName) *) );  if dpy = nil then begin    WriteLn(StdErr, 'Couldn''t open display ""');    Halt(1)  end;//  ok := xkblib.XkbForceBell(dpy, volume);  ok := xkblib.XkbBell(dpy, win, volume, nameAtom);  if not ok then    WriteLn(StdErr, 'XkbBell request failed')end.  The program compiles without error and runs without complaint, but is silent. xkbbell as shipped by Debian beeps as expected. I might try to put a bit more time into it later in case one of the library calls checking extension etc. is actually enabling the extension, but apart from that does anybody have any thoughts or suggestions? MarkMLl ---------------------------------------------------------------------- Thaddy · 2019-11-17 13:54 The bell signal is a real problem if there is no old school speaker available. Try this to test: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  T:Text;begin  Assign(T,'/dev/tty');  Rewrite(T);  Writeln(T,#7);  Flush(T);  Close(T);end.If that produces no sound, the pcspkr kernel module is either not loaded or there is no supported speaker. The above code is similar to Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i # produces a sound if there is support for itecho -ne '\007'Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i # test speaker supportsudo modprobe pcspkrIf neither of these produce a sound, your hardware does not have support for it even if a speaker is present. As an alternative I often use a short wav file and use the alsa system to reproduce the sound. ---------------------------------------------------------------------- winni · 2019-11-17 14:40 Hi! In the most new PCs there is no PC speaker - they saved one € - or less. As mplayer is installed by default in all distros I know just do Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mplayer MyFunny.wav as your personal alarm sound Winni ---------------------------------------------------------------------- MarkMLl · 2019-11-17 14:51 [Sigh] On a fairly standard Linux desktop 0 1>markMLl@desktop:~$ echo -ne '\007' does nothing. 0 1>markMLl@desktop:~$ xkbbell Beeps. Look, guys, I thought I'd already said > xkbbell as shipped by Debian beeps as expected. That uses the X11 extensions, and looking at various systems around here has been shipped as standard since at least 2000. Now in principle it should be possible to transcribe xkbbell.c into Pascal. So far I've not got that working, and suspect that it's one of the version-check calls I omitted. MarkMLl ---------------------------------------------------------------------- winni · 2019-11-17 15:22 Hi! Yes : xkbbell is shipped with suse distros but it did not work in 9.xx and now it does not work with Tumbleweed. That's why I am using mplayer. Winni ---------------------------------------------------------------------- zeljko · 2019-11-17 16:04 Quote from: MarkMLl on November 17, 2019, 12:39:07 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program xkbbell; uses  xkb, xkblib, xlib, x; var  dpyName: string= '';  volume: integer= 99;  devSpec: integer= xkb.XkbUseCoreKbd;  xlass: integer= -1;  id: integer= -1;  bellName: string= '';  nameAtom: TAtom= x.None;  synch: integer= 0;  win: integer= x.None;  force: integer= 0;  nobeep: integer= 0;  function parseArgs(): integer; begin  result := 1end { parseArgs } ;  var  dpy: PDisplay;  ok: boolean;  begin  if parseArgs() < 1 then begin    WriteLn(StdErr, 'Sorry, helpless');    Halt(1)  end;  dpy := XOpenDisplay(nil (* PChar(dpyName) *) );  if dpy = nil then begin    WriteLn(StdErr, 'Couldn''t open display ""');    Halt(1)  end;//  ok := xkblib.XkbForceBell(dpy, volume);  ok := xkblib.XkbBell(dpy, win, volume, nameAtom);  if not ok then    WriteLn(StdErr, 'XkbBell request failed')end.  1.win param should not be integer 2.try to call xkbBell with rootWindow as win param ---------------------------------------------------------------------- MarkMLl · 2019-11-17 17:24 Quote from: winni on November 17, 2019, 04:22:18 pmYes : xkbbell is shipped with suse distros but it did not work in 9.xx and now it does not work with Tumbleweed. That's why I am using mplayer. Is that another casualty of attempts to migrate towards Wayland? mplayer is a bit OTT for a single beep. Other members of the program suite (still running on Windows) use MIDI for simple annunciator "jingles" and I'll probably use ALSA to replicate that, but again it's overkill for a simple beep. MarkMLl ---------------------------------------------------------------------- MarkMLl · 2019-11-17 20:16 Quote from: zeljko on November 17, 2019, 05:04:22 pm1.win param should not be integer 2.try to call xkbBell with rootWindow as win param 1: Muy bad, I plead that was due to its being a transcript from C. In actual fact it didn't apply if I used xkblib.XkbForceBell(). 2: If I use  ok := xkblib.XkbBell(dpy, rootWindow(dpy, DefaultScreen(dpy)), 99, nameAtom);  it's still silent. I used the usage of RootWindow() in TGtkWidgetSet.GetCursorPos() MarkMLl ---------------------------------------------------------------------- MarkMLl · 2019-11-17 20:40 I've added a couple more version etc. calls with no obvious improvement. Code now looks like Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program xkbbell; uses  xkb, xkblib, xlib, x; var  dpyName: string= '';  volume: integer= 99;  devSpec: integer= xkb.XkbUseCoreKbd;  xlass: integer= -1;  id: integer= -1;  bellName: string= '';  nameAtom: TAtom= x.None;  synch: integer= 0;  win: TWindow= x.None;  force: integer= 0;  nobeep: integer= 0;  function parseArgs(): integer; begin  result := 1end { parseArgs } ;  const  XkbMajorVersion= 1;  XkbMinorVersion= 0; var  dpy: PDisplay;  ok: boolean;  i1: smallint= XkbMajorVersion;  i2: smallint= XkbMinorVersion;  i3, i4, i5: smallint;  begin  if parseArgs() < 1 then begin    WriteLn(StdErr, 'Sorry, helpless');    Halt(1)  end;  dpy := XOpenDisplay(nil (* PChar(dpyName) *) );  if dpy = nil then begin    WriteLn(StdErr, 'Couldn''t open display ""');    Halt(1)  end;  if not XkbLibraryVersion(@i1, @i2) then begin    WriteLn(StdErr, 'Wrong xkblib library version');    Halt(1)  end;  if not XkbQueryExtension(dpy, @i1, @i2, @i3, @i4, @i5) then begin    WriteLn(StdErr, 'Wrong xkblib extension');    Halt(1)  end;   ok := xkblib.XkbForceBell(dpy, volume);//  ok := xkblib.XkbBell(dpy, win, volume, nameAtom);//  ok := xkblib.XkbBell(dpy, rootWindow(dpy, DefaultScreen(dpy)), 99, nameAtom);   if not ok then    WriteLn(StdErr, 'XkbBell request failed')end.  If nobody's got any last-minute suggestions I'll probably simply invoke the distro-provided xkbbell binary. I know that works, I've just been looking and can see no unexpected setuid or capabilities setting. MarkMLl ---------------------------------------------------------------------- PascalDragon · 2019-11-18 08:16 Quote from: winni on November 17, 2019, 03:40:55 pmIn the most new PCs there is no PC speaker - they saved one € - or less. Usually at least the OS routes it through the soundcard then (e.g. on my Windows the Bell signal of the Windows Services for Linux shell always comes through the soundcard and even my nearly 15 year old laptop (which did not have any PC speaker either) routes the BIOS beeps through the soundcard). Quote from: winni on November 17, 2019, 03:40:55 pmAs mplayer is installed by default in all distros I know just do That's a very bold statement. Neither Debian, nor ArchLinux, nor Gentoo install it by default.[/quote] ---------------------------------------------------------------------- MarkMLl · 2019-11-23 11:43 Stepping through the C original with gdb indicates that since synchronous operation isn't being forced, the beep isn't output until the display is closed. The code below is adequate: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program xkbbell; uses  xkblib, xlib; var  dpy: PDisplay;  ok: boolean; begin  dpy := XOpenDisplay(nil);  if dpy = nil then begin    WriteLn(StdErr, 'Couldn''t open display ""');    Halt(1)  end;  ok := xkblib.XkbForceBell(dpy, 100);  if not ok then    WriteLn(StdErr, 'XkbBell request failed');  XCloseDisplay(dpy)end.  Synchronous operation might need to be forced if dpy were derived from an existing form or application object. As far as I can find out the named bell facility is effectively unused by this API. It is distinct from the various tones etc. that a modern desktop emits, which uses the soundcard APIs. It's a pity that something like this isn't a standard form operation since an equivalent API appears to exist for both Windows and X11. MarkMLl