comparison src/sound.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 697ef44129c6
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
23 23
24 /* Originally written by Jamie Zawinski. 24 /* Originally written by Jamie Zawinski.
25 Hacked on quite a bit by various others. */ 25 Hacked on quite a bit by various others. */
26 26
27 #include <config.h> 27 #include <config.h>
28 #include <time.h>
28 #include "lisp.h" 29 #include "lisp.h"
29 30
30 #include "buffer.h" 31 #include "buffer.h"
31 #ifdef HAVE_X_WINDOWS 32 #ifdef HAVE_X_WINDOWS
32 #include "console-x.h" 33 #include "console-x.h"
43 #ifdef HAVE_NATIVE_SOUND 44 #ifdef HAVE_NATIVE_SOUND
44 # include <netdb.h> 45 # include <netdb.h>
45 #endif 46 #endif
46 47
47 int bell_volume; 48 int bell_volume;
49 int bell_inhibit_time;
48 Lisp_Object Vsound_alist; 50 Lisp_Object Vsound_alist;
49 Lisp_Object Vsynchronous_sounds; 51 Lisp_Object Vsynchronous_sounds;
50 Lisp_Object Vnative_sound_only_on_console; 52 Lisp_Object Vnative_sound_only_on_console;
51 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound; 53 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound;
52 54
345 the third argument is the device to make it in (defaults to the selected 347 the third argument is the device to make it in (defaults to the selected
346 device). 348 device).
347 */ 349 */
348 (arg, sound, device)) 350 (arg, sound, device))
349 { 351 {
350 struct device *d = decode_device (device); 352 static time_t last_bell_time = (time_t) 0;
353 static struct device *last_bell_device = (struct device*) 0;
354 time_t now;
355 struct device *d = decode_device (device);
351 356
352 XSETDEVICE (device, d); 357 XSETDEVICE (device, d);
353 358 now = time (0);
354 /* #### This is utterly disgusting, and is probably a remnant from 359
355 legacy code that used `ding'+`message' to signal error instead
356 calling `error'. As a result, there is no way to beep from Lisp
357 directly, without also invoking this aspect. Maybe we should
358 define a `ring-bell' function that simply beeps on the console,
359 which `ding' should invoke? --hniksic */
360 if (NILP (arg) && !NILP (Vexecuting_macro)) 360 if (NILP (arg) && !NILP (Vexecuting_macro))
361 /* Stop executing a keyboard macro. */ 361 /* Stop executing a keyboard macro. */
362 error ("Keyboard macro terminated by a command ringing the bell"); 362 error ("Keyboard macro terminated by a command ringing the bell");
363
364 if (d == last_bell_device && now-last_bell_time < bell_inhibit_time)
365 return Qnil;
363 else if (visible_bell && DEVMETH (d, flash, (d))) 366 else if (visible_bell && DEVMETH (d, flash, (d)))
364 ; 367 ;
365 else 368 else
366 Fplay_sound (sound, Qnil, device); 369 Fplay_sound (sound, Qnil, device);
367 370
368 return Qnil; 371 last_bell_time = now;
372 last_bell_device = d;
373 return Qnil;
369 } 374 }
370 375
371 DEFUN ("wait-for-sounds", Fwait_for_sounds, 0, 1, 0, /* 376 DEFUN ("wait-for-sounds", Fwait_for_sounds, 0, 1, 0, /*
372 Wait for all sounds to finish playing on DEVICE. 377 Wait for all sounds to finish playing on DEVICE.
373 */ 378 */
530 535
531 DEFVAR_INT ("bell-volume", &bell_volume /* 536 DEFVAR_INT ("bell-volume", &bell_volume /*
532 *How loud to be, from 0 to 100. 537 *How loud to be, from 0 to 100.
533 */ ); 538 */ );
534 bell_volume = 50; 539 bell_volume = 50;
540
541 DEFVAR_INT ("bell-inhibit-time", &bell_inhibit_time /*
542 *Don't ring the bell on the same device more than once within this many seconds.
543 */ );
544 bell_inhibit_time = 0;
535 545
536 DEFVAR_LISP ("sound-alist", &Vsound_alist /* 546 DEFVAR_LISP ("sound-alist", &Vsound_alist /*
537 An alist associating names with sounds. 547 An alist associating names with sounds.
538 When `beep' or `ding' is called with one of the name symbols, the associated 548 When `beep' or `ding' is called with one of the name symbols, the associated
539 sound will be generated instead of the standard beep. 549 sound will be generated instead of the standard beep.
557 567
558 You should probably add things to this list by calling the function 568 You should probably add things to this list by calling the function
559 load-sound-file. 569 load-sound-file.
560 570
561 Caveats: 571 Caveats:
562 - You can only play audio data if running on the console screen of a 572 - XEmacs must be built with sound support for your system. Not all
563 Sun SparcStation, SGI, or HP9000s700. 573 systems support sound.
564 574
565 - The pitch, duration, and volume options are available everywhere, but 575 - The pitch, duration, and volume options are available everywhere, but
566 many X servers ignore the `pitch' option. 576 many X servers ignore the `pitch' option.
567 577
568 The following beep-types are used by emacs itself: 578 The following beep-types are used by emacs itself: