Mercurial > hg > xemacs-beta
comparison src/sound.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 6719134a07c2 |
children | 2f8bb876ab1d |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
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" |
42 | 43 |
43 #ifdef HAVE_NATIVE_SOUND | 44 #ifdef HAVE_NATIVE_SOUND |
44 # include <netdb.h> | 45 # include <netdb.h> |
45 #endif | 46 #endif |
46 | 47 |
48 #ifdef HAVE_ESD_SOUND | |
49 extern int esd_play_sound_file (char *file, int vol); | |
50 extern int esd_play_sound_data (unsigned char *data, size_t length, int vol); | |
51 # define DEVICE_CONNECTED_TO_ESD_P(x) 1 /* FIXME: better check */ | |
52 #endif | |
53 | |
47 int bell_volume; | 54 int bell_volume; |
55 int bell_inhibit_time; | |
48 Lisp_Object Vsound_alist; | 56 Lisp_Object Vsound_alist; |
49 Lisp_Object Vsynchronous_sounds; | 57 Lisp_Object Vsynchronous_sounds; |
50 Lisp_Object Vnative_sound_only_on_console; | 58 Lisp_Object Vnative_sound_only_on_console; |
51 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound; | 59 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound; |
52 | 60 |
75 */ | 83 */ |
76 (file, volume, device)) | 84 (file, volume, device)) |
77 { | 85 { |
78 /* This function can call lisp */ | 86 /* This function can call lisp */ |
79 int vol; | 87 int vol; |
80 #if defined (HAVE_NATIVE_SOUND) || defined (HAVE_NAS_SOUND) | 88 #if defined (HAVE_NATIVE_SOUND) || defined (HAVE_NAS_SOUND) \ |
89 || defined (HAVE_ESD_SOUND) | |
81 struct device *d = decode_device (device); | 90 struct device *d = decode_device (device); |
82 #endif | 91 #endif |
83 struct gcpro gcpro1; | 92 struct gcpro gcpro1; |
84 | 93 |
85 CHECK_STRING (file); | 94 CHECK_STRING (file); |
115 #ifdef HAVE_NAS_SOUND | 124 #ifdef HAVE_NAS_SOUND |
116 if (DEVICE_CONNECTED_TO_NAS_P (d)) | 125 if (DEVICE_CONNECTED_TO_NAS_P (d)) |
117 { | 126 { |
118 char *fileext; | 127 char *fileext; |
119 | 128 |
120 GET_C_STRING_FILENAME_DATA_ALLOCA (file, fileext); | 129 TO_EXTERNAL_FORMAT (LISP_STRING, file, |
130 C_STRING_ALLOCA, fileext, | |
131 Qfile_name); | |
121 /* #### NAS code should allow specification of a device. */ | 132 /* #### NAS code should allow specification of a device. */ |
122 if (nas_play_sound_file (fileext, vol)) | 133 if (nas_play_sound_file (fileext, vol)) |
123 return Qnil; | 134 return Qnil; |
124 } | 135 } |
125 #endif /* HAVE_NAS_SOUND */ | 136 #endif /* HAVE_NAS_SOUND */ |
126 | 137 |
138 #ifdef HAVE_ESD_SOUND | |
139 if (DEVICE_CONNECTED_TO_ESD_P (d)) | |
140 { | |
141 char *fileext; | |
142 | |
143 TO_EXTERNAL_FORMAT (LISP_STRING, file, | |
144 C_STRING_ALLOCA, fileext, | |
145 Qfile_name); | |
146 if (esd_play_sound_file (fileext, vol)) | |
147 return Qnil; | |
148 } | |
149 #endif /* HAVE_ESD_SOUND */ | |
150 | |
127 #ifdef HAVE_NATIVE_SOUND | 151 #ifdef HAVE_NATIVE_SOUND |
128 if (NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d)) | 152 if (NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d)) |
129 { | 153 { |
130 CONST char *fileext; | 154 const char *fileext; |
131 | 155 |
132 GET_C_STRING_FILENAME_DATA_ALLOCA (file, fileext); | 156 TO_EXTERNAL_FORMAT (LISP_STRING, file, |
157 C_STRING_ALLOCA, fileext, | |
158 Qfile_name); | |
133 /* The sound code doesn't like getting SIGIO interrupts. | 159 /* The sound code doesn't like getting SIGIO interrupts. |
134 Unix sucks! */ | 160 Unix sucks! */ |
135 stop_interrupts (); | 161 stop_interrupts (); |
136 play_sound_file ((char *) fileext, vol); | 162 play_sound_file ((char *) fileext, vol); |
137 start_interrupts (); | 163 start_interrupts (); |
289 Else just beep. | 315 Else just beep. |
290 */ | 316 */ |
291 #ifdef HAVE_NAS_SOUND | 317 #ifdef HAVE_NAS_SOUND |
292 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound)) | 318 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound)) |
293 { | 319 { |
294 CONST Extbyte *soundext; | 320 const Extbyte *soundext; |
295 Extcount soundextlen; | 321 Extcount soundextlen; |
296 | 322 |
297 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen); | 323 TO_EXTERNAL_FORMAT (LISP_STRING, sound, |
324 ALLOCA, (soundext, soundextlen), | |
325 Qbinary); | |
298 if (nas_play_sound_data ((unsigned char*)soundext, soundextlen, vol)) | 326 if (nas_play_sound_data ((unsigned char*)soundext, soundextlen, vol)) |
299 return Qnil; | 327 return Qnil; |
300 } | 328 } |
301 #endif /* HAVE_NAS_SOUND */ | 329 #endif /* HAVE_NAS_SOUND */ |
330 | |
331 #ifdef HAVE_ESD_SOUND | |
332 if (DEVICE_CONNECTED_TO_ESD_P (d) && STRINGP (sound)) | |
333 { | |
334 Extbyte *soundext; | |
335 Extcount soundextlen; | |
336 | |
337 TO_EXTERNAL_FORMAT (LISP_STRING, sound, ALLOCA, (soundext, soundextlen), | |
338 Qbinary); | |
339 if (esd_play_sound_data (soundext, soundextlen, vol)) | |
340 return Qnil; | |
341 } | |
342 #endif /* HAVE_ESD_SOUND */ | |
302 | 343 |
303 #ifdef HAVE_NATIVE_SOUND | 344 #ifdef HAVE_NATIVE_SOUND |
304 if ((NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d)) | 345 if ((NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d)) |
305 && STRINGP (sound)) | 346 && STRINGP (sound)) |
306 { | 347 { |
307 CONST Extbyte *soundext; | 348 const Extbyte *soundext; |
308 Extcount soundextlen; | 349 Extcount soundextlen; |
309 | 350 |
310 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen); | 351 TO_EXTERNAL_FORMAT (LISP_STRING, sound, |
352 ALLOCA, (soundext, soundextlen), | |
353 Qbinary); | |
311 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */ | 354 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */ |
312 stop_interrupts (); | 355 stop_interrupts (); |
313 play_sound_data ((unsigned char*)soundext, soundextlen, vol); | 356 play_sound_data ((unsigned char*)soundext, soundextlen, vol); |
314 start_interrupts (); | 357 start_interrupts (); |
315 QUIT; | 358 QUIT; |
345 the third argument is the device to make it in (defaults to the selected | 388 the third argument is the device to make it in (defaults to the selected |
346 device). | 389 device). |
347 */ | 390 */ |
348 (arg, sound, device)) | 391 (arg, sound, device)) |
349 { | 392 { |
350 struct device *d = decode_device (device); | 393 static time_t last_bell_time; |
394 static struct device *last_bell_device; | |
395 time_t now; | |
396 struct device *d = decode_device (device); | |
351 | 397 |
352 XSETDEVICE (device, d); | 398 XSETDEVICE (device, d); |
353 | 399 now = time (0); |
354 /* #### This is utterly disgusting, and is probably a remnant from | 400 |
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)) | 401 if (NILP (arg) && !NILP (Vexecuting_macro)) |
361 /* Stop executing a keyboard macro. */ | 402 /* Stop executing a keyboard macro. */ |
362 error ("Keyboard macro terminated by a command ringing the bell"); | 403 error ("Keyboard macro terminated by a command ringing the bell"); |
404 | |
405 if (d == last_bell_device && now-last_bell_time < bell_inhibit_time) | |
406 return Qnil; | |
363 else if (visible_bell && DEVMETH (d, flash, (d))) | 407 else if (visible_bell && DEVMETH (d, flash, (d))) |
364 ; | 408 ; |
365 else | 409 else |
366 Fplay_sound (sound, Qnil, device); | 410 Fplay_sound (sound, Qnil, device); |
367 | 411 |
368 return Qnil; | 412 last_bell_time = now; |
413 last_bell_device = d; | |
414 return Qnil; | |
369 } | 415 } |
370 | 416 |
371 DEFUN ("wait-for-sounds", Fwait_for_sounds, 0, 1, 0, /* | 417 DEFUN ("wait-for-sounds", Fwait_for_sounds, 0, 1, 0, /* |
372 Wait for all sounds to finish playing on DEVICE. | 418 Wait for all sounds to finish playing on DEVICE. |
373 */ | 419 */ |
525 Fprovide (intern ("native-sound")); | 571 Fprovide (intern ("native-sound")); |
526 #endif | 572 #endif |
527 #ifdef HAVE_NAS_SOUND | 573 #ifdef HAVE_NAS_SOUND |
528 Fprovide (intern ("nas-sound")); | 574 Fprovide (intern ("nas-sound")); |
529 #endif | 575 #endif |
576 #ifdef HAVE_ESD_SOUND | |
577 Fprovide (intern ("esd-sound")); | |
578 #endif | |
530 | 579 |
531 DEFVAR_INT ("bell-volume", &bell_volume /* | 580 DEFVAR_INT ("bell-volume", &bell_volume /* |
532 *How loud to be, from 0 to 100. | 581 *How loud to be, from 0 to 100. |
533 */ ); | 582 */ ); |
534 bell_volume = 50; | 583 bell_volume = 50; |
584 | |
585 DEFVAR_INT ("bell-inhibit-time", &bell_inhibit_time /* | |
586 *Don't ring the bell on the same device more than once within this many seconds. | |
587 */ ); | |
588 bell_inhibit_time = 0; | |
535 | 589 |
536 DEFVAR_LISP ("sound-alist", &Vsound_alist /* | 590 DEFVAR_LISP ("sound-alist", &Vsound_alist /* |
537 An alist associating names with sounds. | 591 An alist associating names with sounds. |
538 When `beep' or `ding' is called with one of the name symbols, the associated | 592 When `beep' or `ding' is called with one of the name symbols, the associated |
539 sound will be generated instead of the standard beep. | 593 sound will be generated instead of the standard beep. |
557 | 611 |
558 You should probably add things to this list by calling the function | 612 You should probably add things to this list by calling the function |
559 load-sound-file. | 613 load-sound-file. |
560 | 614 |
561 Caveats: | 615 Caveats: |
562 - You can only play audio data if running on the console screen of a | 616 - XEmacs must be built with sound support for your system. Not all |
563 Sun SparcStation, SGI, or HP9000s700. | 617 systems support sound. |
564 | 618 |
565 - The pitch, duration, and volume options are available everywhere, but | 619 - The pitch, duration, and volume options are available everywhere, but |
566 many X servers ignore the `pitch' option. | 620 many X servers ignore the `pitch' option. |
567 | 621 |
568 The following beep-types are used by emacs itself: | 622 The following beep-types are used by emacs itself: |