428
|
1 /* Sound functions.
|
|
2 Copyright (C) 1992, 1993, 1994 Lucid Inc.
|
|
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
793
|
4 Copyright (C) 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
563
|
25 /* This file Mule-ized by Ben Wing, 5-15-01. */
|
|
26
|
428
|
27 /* Originally written by Jamie Zawinski.
|
|
28 Hacked on quite a bit by various others. */
|
|
29
|
|
30 #include <config.h>
|
|
31 #include <time.h>
|
|
32 #include "lisp.h"
|
|
33
|
|
34 #include "buffer.h"
|
|
35 #ifdef HAVE_X_WINDOWS
|
872
|
36 #include "console-x-impl.h"
|
428
|
37 #endif
|
872
|
38 #include "device-impl.h"
|
428
|
39 #include "redisplay.h"
|
563
|
40 #include "sound.h"
|
|
41
|
428
|
42 #include "sysdep.h"
|
|
43
|
442
|
44 #include "sysfile.h"
|
428
|
45
|
|
46 #ifdef HAVE_NATIVE_SOUND
|
442
|
47 # include "sysproc.h"
|
428
|
48 #endif
|
|
49
|
872
|
50 #ifdef WIN32_NATIVE
|
|
51 #include "syswindows.h"
|
|
52 #endif
|
|
53
|
428
|
54 #ifdef HAVE_ESD_SOUND
|
563
|
55 extern int esd_play_sound_file (Extbyte *file, int vol);
|
|
56 extern int esd_play_sound_data (UChar_Binary *data, size_t length, int vol);
|
|
57 # define DEVICE_CONNECTED_TO_ESD_P(x) 1 /* #### better check */
|
428
|
58 #endif
|
|
59
|
458
|
60 Fixnum bell_volume;
|
|
61 Fixnum bell_inhibit_time;
|
428
|
62 Lisp_Object Vsound_alist;
|
|
63 Lisp_Object Vsynchronous_sounds;
|
|
64 Lisp_Object Vnative_sound_only_on_console;
|
|
65 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound;
|
563
|
66 Lisp_Object Qsound_error;
|
428
|
67
|
|
68
|
|
69 #ifdef HAVE_NAS_SOUND
|
563
|
70 extern int nas_play_sound_file (Extbyte *name, int volume);
|
|
71 extern int nas_play_sound_data (UChar_Binary *data, int length, int volume);
|
428
|
72 extern int nas_wait_for_sounds (void);
|
563
|
73 extern Extbyte *nas_init_play (Display *);
|
|
74 #endif
|
428
|
75
|
563
|
76 DOESNT_RETURN
|
|
77 report_sound_error (const Char_ASCII *string, Lisp_Object data)
|
|
78 {
|
|
79 report_error_with_errno (Qsound_error, string, data);
|
|
80 }
|
428
|
81
|
|
82 DEFUN ("play-sound-file", Fplay_sound_file, 1, 3, "fSound file name: ", /*
|
|
83 Play the named sound file on DEVICE's speaker at the specified volume
|
|
84 \(0-100, default specified by the `bell-volume' variable).
|
|
85 On Unix machines the sound file must be in the Sun/NeXT U-LAW format
|
|
86 except under Linux where WAV files are also supported. On Microsoft
|
|
87 Windows the sound file must be in WAV format.
|
|
88 DEVICE defaults to the selected device.
|
|
89 */
|
|
90 (file, volume, device))
|
|
91 {
|
|
92 /* This function can call lisp */
|
|
93 int vol;
|
|
94 #if defined (HAVE_NATIVE_SOUND) || defined (HAVE_NAS_SOUND) \
|
|
95 || defined (HAVE_ESD_SOUND)
|
|
96 struct device *d = decode_device (device);
|
|
97 #endif
|
|
98 struct gcpro gcpro1;
|
|
99
|
|
100 CHECK_STRING (file);
|
|
101 if (NILP (volume))
|
|
102 vol = bell_volume;
|
|
103 else
|
|
104 {
|
|
105 CHECK_INT (volume);
|
|
106 vol = XINT (volume);
|
|
107 }
|
|
108
|
|
109 GCPRO1 (file);
|
|
110 while (1)
|
|
111 {
|
|
112 file = Fexpand_file_name (file, Qnil);
|
|
113 if (!NILP(Ffile_readable_p (file)))
|
|
114 break;
|
|
115 else
|
|
116 {
|
|
117 /* #### This is crockish. It might be a better idea to try
|
|
118 to open the file, and use report_file_error() if it
|
|
119 fails. --hniksic */
|
|
120 if (NILP (Ffile_exists_p (file)))
|
|
121 file =
|
563
|
122 signal_continuable_error (Qfile_error,
|
|
123 "File does not exist", file);
|
428
|
124 else
|
|
125 file =
|
563
|
126 signal_continuable_error (Qfile_error,
|
|
127 "File is unreadable", file);
|
428
|
128 }
|
|
129 }
|
|
130 UNGCPRO;
|
|
131
|
|
132 #ifdef HAVE_NAS_SOUND
|
|
133 if (DEVICE_CONNECTED_TO_NAS_P (d))
|
|
134 {
|
563
|
135 Extbyte *fileext;
|
428
|
136
|
442
|
137 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
|
428
|
138 /* #### NAS code should allow specification of a device. */
|
|
139 if (nas_play_sound_file (fileext, vol))
|
|
140 return Qnil;
|
|
141 }
|
|
142 #endif /* HAVE_NAS_SOUND */
|
|
143
|
|
144 #ifdef HAVE_ESD_SOUND
|
|
145 if (DEVICE_CONNECTED_TO_ESD_P (d))
|
|
146 {
|
563
|
147 Extbyte *fileext;
|
442
|
148 int result;
|
428
|
149
|
442
|
150 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
|
|
151
|
|
152 /* #### ESD uses alarm(). But why should we also stop SIGIO? */
|
|
153 stop_interrupts ();
|
|
154 result = esd_play_sound_file (fileext, vol);
|
|
155 start_interrupts ();
|
|
156 if (result)
|
428
|
157 return Qnil;
|
|
158 }
|
|
159 #endif /* HAVE_ESD_SOUND */
|
|
160
|
|
161 #ifdef HAVE_NATIVE_SOUND
|
|
162 if (NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d))
|
|
163 {
|
563
|
164 Extbyte *fileext;
|
428
|
165
|
771
|
166 #ifdef WIN32_NATIVE
|
|
167 /* #### more garbage. we should be passing the internal file name
|
|
168 to play_sound_file. */
|
|
169 LISP_STRING_TO_EXTERNAL (file, fileext, Qmswindows_tstr);
|
|
170 #else
|
442
|
171 LISP_STRING_TO_EXTERNAL (file, fileext, Qfile_name);
|
771
|
172 #endif
|
428
|
173 /* The sound code doesn't like getting SIGIO interrupts.
|
|
174 Unix sucks! */
|
|
175 stop_interrupts ();
|
563
|
176 play_sound_file (fileext, vol);
|
428
|
177 start_interrupts ();
|
|
178 QUIT;
|
|
179 }
|
|
180 #endif /* HAVE_NATIVE_SOUND */
|
|
181
|
|
182 return Qnil;
|
|
183 }
|
|
184
|
|
185 static void
|
|
186 parse_sound_alist_elt (Lisp_Object elt,
|
|
187 Lisp_Object *volume,
|
|
188 Lisp_Object *pitch,
|
|
189 Lisp_Object *duration,
|
|
190 Lisp_Object *sound)
|
|
191 {
|
|
192 *volume = Qnil;
|
|
193 *pitch = Qnil;
|
|
194 *duration = Qnil;
|
|
195 *sound = Qnil;
|
|
196 if (! CONSP (elt))
|
|
197 return;
|
|
198
|
|
199 /* The things we do for backward compatibility...
|
|
200 I wish I had just forced this to be a plist to begin with.
|
|
201 */
|
|
202
|
|
203 if (SYMBOLP (elt) || STRINGP (elt)) /* ( name . <sound> ) */
|
|
204 {
|
|
205 *sound = elt;
|
|
206 }
|
|
207 else if (!CONSP (elt))
|
|
208 {
|
|
209 return;
|
|
210 }
|
|
211 else if (NILP (XCDR (elt)) && /* ( name <sound> ) */
|
|
212 (SYMBOLP (XCAR (elt)) ||
|
|
213 STRINGP (XCAR (elt))))
|
|
214 {
|
|
215 *sound = XCAR (elt);
|
|
216 }
|
|
217 else if (INT_OR_FLOATP (XCAR (elt)) && /* ( name <vol> . <sound> ) */
|
|
218 (SYMBOLP (XCDR (elt)) ||
|
|
219 STRINGP (XCDR (elt))))
|
|
220 {
|
|
221 *volume = XCAR (elt);
|
|
222 *sound = XCDR (elt);
|
|
223 }
|
|
224 else if (INT_OR_FLOATP (XCAR (elt)) && /* ( name <vol> <sound> ) */
|
|
225 CONSP (XCDR (elt)) &&
|
|
226 NILP (XCDR (XCDR (elt))) &&
|
|
227 (SYMBOLP (XCAR (XCDR (elt))) ||
|
|
228 STRINGP (XCAR (XCDR (elt)))))
|
|
229 {
|
|
230 *volume = XCAR (elt);
|
|
231 *sound = XCAR (XCDR (elt));
|
|
232 }
|
|
233 else if ((SYMBOLP (XCAR (elt)) || /* ( name <sound> . <vol> ) */
|
|
234 STRINGP (XCAR (elt))) &&
|
|
235 INT_OR_FLOATP (XCDR (elt)))
|
|
236 {
|
|
237 *sound = XCAR (elt);
|
|
238 *volume = XCDR (elt);
|
|
239 }
|
|
240 #if 0 /* this one is ambiguous with the plist form */
|
|
241 else if ((SYMBOLP (XCAR (elt)) || /* ( name <sound> <vol> ) */
|
|
242 STRINGP (XCAR (elt))) &&
|
|
243 CONSP (XCDR (elt)) &&
|
|
244 NILP (XCDR (XCDR (elt))) &&
|
|
245 INT_OR_FLOATP (XCAR (XCDR (elt))))
|
|
246 {
|
|
247 *sound = XCAR (elt);
|
|
248 *volume = XCAR (XCDR (elt));
|
|
249 }
|
|
250 #endif /* 0 */
|
|
251 else /* ( name [ keyword <value> ]* ) */
|
|
252 {
|
|
253 while (CONSP (elt))
|
|
254 {
|
|
255 Lisp_Object key, val;
|
|
256 key = XCAR (elt);
|
|
257 val = XCDR (elt);
|
|
258 if (!CONSP (val))
|
|
259 return;
|
|
260 elt = XCDR (val);
|
|
261 val = XCAR (val);
|
|
262 if (EQ (key, Q_volume))
|
|
263 {
|
|
264 if (INT_OR_FLOATP (val)) *volume = val;
|
|
265 }
|
|
266 else if (EQ (key, Q_pitch))
|
|
267 {
|
|
268 if (INT_OR_FLOATP (val)) *pitch = val;
|
|
269 if (NILP (*sound)) *sound = Qt;
|
|
270 }
|
|
271 else if (EQ (key, Q_duration))
|
|
272 {
|
|
273 if (INT_OR_FLOATP (val)) *duration = val;
|
|
274 if (NILP (*sound)) *sound = Qt;
|
|
275 }
|
|
276 else if (EQ (key, Q_sound))
|
|
277 {
|
|
278 if (SYMBOLP (val) || STRINGP (val)) *sound = val;
|
|
279 }
|
|
280 }
|
|
281 }
|
|
282 }
|
|
283
|
|
284 DEFUN ("play-sound", Fplay_sound, 1, 3, 0, /*
|
|
285 Play a sound of the provided type.
|
793
|
286
|
|
287 SOUND can a symbol, specifying a sound to be looked up in `sound-alist'
|
|
288 \(generally, either the symbol directly maps to a sound or is an "abstract"
|
|
289 symbol that maps to another symbol and is used to specify the sound that is
|
|
290 played when a particular behavior occurs. `ding' lists the built-in
|
|
291 abstract sounds and their intended purpose.
|
|
292
|
|
293 SOUND can also be a string, which directly encodes the sound data to be played.
|
|
294
|
|
295 If SOUND is nil, the abstract sound `default' will be used.
|
|
296
|
|
297 VOLUME controls the volume (max is around 150? not sure).
|
|
298
|
|
299 DEVICE is the device to play the sound on (defaults to the selected device).
|
609
|
300
|
|
301 If the sound cannot be played in any other way, the standard "bell" will sound.
|
428
|
302 */
|
|
303 (sound, volume, device))
|
|
304 {
|
|
305 int looking_for_default = 0;
|
|
306 /* variable `sound' is anything that can be a cdr in sound-alist */
|
|
307 Lisp_Object new_volume, pitch, duration, data;
|
|
308 int loop_count = 0;
|
|
309 int vol, pit, dur;
|
|
310 struct device *d = decode_device (device);
|
|
311
|
|
312 /* NOTE! You'd better not signal an error in here. */
|
|
313
|
|
314
|
|
315 try_it_again:
|
|
316 while (1)
|
|
317 {
|
|
318 if (SYMBOLP (sound))
|
|
319 sound = Fcdr (Fassq (sound, Vsound_alist));
|
|
320 parse_sound_alist_elt (sound, &new_volume, &pitch, &duration, &data);
|
|
321 sound = data;
|
|
322 if (NILP (volume)) volume = new_volume;
|
|
323 if (EQ (sound, Qt) || EQ (sound, Qnil) || STRINGP (sound))
|
|
324 break;
|
|
325 if (loop_count++ > 500) /* much bogosity has occurred */
|
|
326 break;
|
|
327 }
|
|
328
|
|
329 if (NILP (sound) && !looking_for_default)
|
|
330 {
|
|
331 looking_for_default = 1;
|
|
332 loop_count = 0;
|
|
333 sound = Qdefault;
|
|
334 goto try_it_again;
|
|
335 }
|
|
336
|
|
337
|
|
338 vol = (INT_OR_FLOATP (volume) ? (int) XFLOATINT (volume) : bell_volume);
|
|
339 pit = (INT_OR_FLOATP (pitch) ? (int) XFLOATINT (pitch) : -1);
|
|
340 dur = (INT_OR_FLOATP (duration) ? (int) XFLOATINT (duration) : -1);
|
|
341
|
|
342 /* If the sound is a string, and we're connected to Nas, do that.
|
|
343 Else if the sound is a string, and we're on console, play it natively.
|
|
344 Else just beep.
|
|
345 */
|
|
346 #ifdef HAVE_NAS_SOUND
|
|
347 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound))
|
|
348 {
|
1346
|
349 UChar_Binary *soundext;
|
665
|
350 Bytecount soundextlen;
|
428
|
351
|
440
|
352 TO_EXTERNAL_FORMAT (LISP_STRING, sound,
|
|
353 ALLOCA, (soundext, soundextlen),
|
|
354 Qbinary);
|
563
|
355 if (nas_play_sound_data (soundext, soundextlen, vol))
|
428
|
356 return Qnil;
|
|
357 }
|
|
358 #endif /* HAVE_NAS_SOUND */
|
|
359
|
|
360 #ifdef HAVE_ESD_SOUND
|
|
361 if (DEVICE_CONNECTED_TO_ESD_P (d) && STRINGP (sound))
|
|
362 {
|
563
|
363 UChar_Binary *soundext;
|
665
|
364 Bytecount soundextlen;
|
442
|
365 int succes;
|
428
|
366
|
440
|
367 TO_EXTERNAL_FORMAT (LISP_STRING, sound, ALLOCA, (soundext, soundextlen),
|
|
368 Qbinary);
|
442
|
369
|
|
370 /* #### ESD uses alarm(). But why should we also stop SIGIO? */
|
|
371 stop_interrupts ();
|
563
|
372 succes = esd_play_sound_data (soundext, soundextlen, vol);
|
442
|
373 start_interrupts ();
|
|
374 QUIT;
|
|
375 if(succes)
|
|
376 return Qnil;
|
428
|
377 }
|
|
378 #endif /* HAVE_ESD_SOUND */
|
|
379
|
|
380 #ifdef HAVE_NATIVE_SOUND
|
|
381 if ((NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d))
|
|
382 && STRINGP (sound))
|
|
383 {
|
563
|
384 UChar_Binary *soundext;
|
665
|
385 Bytecount soundextlen;
|
442
|
386 int succes;
|
428
|
387
|
440
|
388 TO_EXTERNAL_FORMAT (LISP_STRING, sound,
|
|
389 ALLOCA, (soundext, soundextlen),
|
|
390 Qbinary);
|
428
|
391 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */
|
|
392 stop_interrupts ();
|
563
|
393 succes = play_sound_data (soundext, soundextlen, vol);
|
428
|
394 start_interrupts ();
|
|
395 QUIT;
|
442
|
396 if (succes)
|
|
397 return Qnil;
|
428
|
398 }
|
|
399 #endif /* HAVE_NATIVE_SOUND */
|
|
400
|
|
401 DEVMETH (d, ring_bell, (d, vol, pit, dur));
|
|
402 return Qnil;
|
|
403 }
|
|
404
|
|
405 DEFUN ("device-sound-enabled-p", Fdevice_sound_enabled_p, 0, 1, 0, /*
|
|
406 Return t if DEVICE is able to play sound. Defaults to selected device.
|
|
407 */
|
|
408 (device))
|
|
409 {
|
|
410 #ifdef HAVE_NAS_SOUND
|
|
411 if (DEVICE_CONNECTED_TO_NAS_P (decode_device (device)))
|
|
412 return Qt;
|
|
413 #endif
|
|
414 #ifdef HAVE_NATIVE_SOUND
|
|
415 if (DEVICE_ON_CONSOLE_P (decode_device (device)))
|
|
416 return Qt;
|
|
417 #endif
|
|
418 return Qnil;
|
|
419 }
|
|
420
|
|
421 DEFUN ("ding", Fding, 0, 3, 0, /*
|
|
422 Beep, or flash the frame.
|
793
|
423
|
|
424 \(See `visible-bell'; setting this makes the frame flash instead of
|
|
425 beeping.) Also, unless NO-TERMINATE is given, terminate any keyboard macro
|
|
426 currently executing. SOUND specifies the sound to make and DEVICE the
|
|
427 device to make it on (defaults to the selected device).
|
|
428
|
|
429 SOUND is either a string (raw data to be played directly), a symbol, or
|
|
430 `nil' (equivalent to the symbol `default'). Sound symbols are looked up in
|
|
431 `sound-alist', and resolve either to strings of data or to other symbols.
|
|
432 Sound symbols that map directly to data should be considered named sounds;
|
|
433 sound symbols that map to other sounds should be considered abstract
|
|
434 sounds, and are used when a particular behavior or state occurs.
|
|
435
|
|
436 Rremember that the sound symbol is the *second* argument to `ding', not the
|
|
437 first.
|
|
438
|
|
439 The following abstract sounds are used by XEmacs itself:
|
|
440
|
|
441 alarm when a package wants to remind the user
|
|
442 auto-save-error when an auto-save does not succeed
|
|
443 buffer-bound when you attempt to move off the end of a buffer
|
|
444 command-error any uncaught error (i.e. any error that the user
|
|
445 sees) except those handled by undefined-click,
|
|
446 undefined-key, buffer-bound, or read-only
|
|
447 default used when nothing else is appropriate.
|
|
448 isearch-failed unable to locate search text during incremental search
|
|
449 isearch-quit when you delete chars past the beginning of the search
|
|
450 text in isearch
|
|
451 no-completion during completing-read
|
|
452 quit when C-g is typed
|
|
453 read-only when you try to modify a read-only buffer
|
|
454 ready when a compile or other time-consuming task is done
|
|
455 undefined-click when you use an undefined mouse-click combination
|
|
456 undefined-key when you type a key that is undefined
|
|
457 warp XEmacs has changed the selected-window or frame
|
|
458 asynchronously -- e.g. a debugger breakpoint is hit
|
|
459 in an asynchronous process filter
|
|
460 y-or-n-p when you type something other than 'y' or 'n'
|
|
461 yes-or-no-p when you type something other than 'yes' or 'no'
|
|
462
|
|
463 Other lisp packages may use other beep types, but these are the ones that
|
|
464 the C kernel of Emacs uses.
|
|
465
|
428
|
466 */
|
793
|
467 (no_terminate, sound, device))
|
428
|
468 {
|
430
|
469 static time_t last_bell_time;
|
|
470 static struct device *last_bell_device;
|
428
|
471 time_t now;
|
|
472 struct device *d = decode_device (device);
|
|
473
|
793
|
474 device = wrap_device (d);
|
428
|
475 now = time (0);
|
|
476
|
793
|
477 if (NILP (no_terminate) && !NILP (Vexecuting_macro))
|
428
|
478 /* Stop executing a keyboard macro. */
|
563
|
479 invalid_operation ("Keyboard macro terminated by a command ringing the bell", Qunbound);
|
428
|
480
|
|
481 if (d == last_bell_device && now-last_bell_time < bell_inhibit_time)
|
|
482 return Qnil;
|
442
|
483 else if (!NILP (Vvisible_bell) && DEVMETH (d, flash, (d)))
|
428
|
484 ;
|
|
485 else
|
|
486 Fplay_sound (sound, Qnil, device);
|
|
487
|
|
488 last_bell_time = now;
|
|
489 last_bell_device = d;
|
|
490 return Qnil;
|
|
491 }
|
|
492
|
|
493 DEFUN ("wait-for-sounds", Fwait_for_sounds, 0, 1, 0, /*
|
|
494 Wait for all sounds to finish playing on DEVICE.
|
|
495 */
|
|
496 (device))
|
|
497
|
|
498 {
|
|
499 #ifdef HAVE_NAS_SOUND
|
|
500 struct device *d = decode_device (device);
|
|
501 if (DEVICE_CONNECTED_TO_NAS_P (d))
|
|
502 {
|
|
503 /* #### somebody fix this to be device-dependent. */
|
|
504 nas_wait_for_sounds ();
|
|
505 }
|
|
506 #endif
|
|
507 return Qnil;
|
|
508 }
|
|
509
|
|
510 DEFUN ("connected-to-nas-p", Fconnected_to_nas_p, 0, 1, 0, /*
|
|
511 Return t if connected to NAS server for sounds on DEVICE.
|
|
512 */
|
|
513 (device))
|
|
514 {
|
|
515 #ifdef HAVE_NAS_SOUND
|
|
516 return DEVICE_CONNECTED_TO_NAS_P (decode_device (device)) ? Qt : Qnil;
|
|
517 #else
|
|
518 return Qnil;
|
|
519 #endif
|
|
520 }
|
|
521 #ifdef HAVE_NAS_SOUND
|
|
522
|
|
523 static void
|
|
524 init_nas_sound (struct device *d)
|
|
525 {
|
|
526 #ifdef HAVE_X_WINDOWS
|
|
527 if (DEVICE_X_P (d))
|
|
528 {
|
563
|
529 Extbyte *err_message = nas_init_play (DEVICE_X_DISPLAY (d));
|
442
|
530 DEVICE_CONNECTED_TO_NAS_P (d) = !err_message;
|
428
|
531 /* Print out the message? */
|
|
532 }
|
|
533 #endif /* HAVE_X_WINDOWS */
|
|
534 }
|
|
535
|
|
536 #endif /* HAVE_NAS_SOUND */
|
|
537
|
|
538 #ifdef HAVE_NATIVE_SOUND
|
|
539
|
|
540 static void
|
|
541 init_native_sound (struct device *d)
|
|
542 {
|
|
543 if (DEVICE_TTY_P (d) || DEVICE_STREAM_P (d) || DEVICE_MSWINDOWS_P(d))
|
|
544 DEVICE_ON_CONSOLE_P (d) = 1;
|
|
545 #ifdef HAVE_X_WINDOWS
|
|
546 else
|
|
547 {
|
|
548 /* When running on a machine with native sound support, we cannot use
|
|
549 digitized sounds as beeps unless emacs is running on the same machine
|
|
550 that $DISPLAY points to, and $DISPLAY points to frame 0 of that
|
|
551 machine.
|
|
552 */
|
|
553
|
|
554 Display *display = DEVICE_X_DISPLAY (d);
|
563
|
555 Extbyte *dpy = DisplayString (display);
|
|
556 Extbyte *tail = strchr (dpy, ':');
|
428
|
557 if (! tail ||
|
|
558 strncmp (tail, ":0", 2))
|
|
559 DEVICE_ON_CONSOLE_P (d) = 0;
|
|
560 else
|
|
561 {
|
563
|
562 Extbyte dpyname[255], localname[255];
|
428
|
563
|
|
564 /* some systems can't handle SIGIO or SIGALARM in gethostbyname. */
|
|
565 stop_interrupts ();
|
|
566 strncpy (dpyname, dpy, tail-dpy);
|
|
567 dpyname [tail-dpy] = 0;
|
|
568 if (!*dpyname ||
|
|
569 !strcmp (dpyname, "unix") ||
|
|
570 !strcmp (dpyname, "localhost"))
|
|
571 DEVICE_ON_CONSOLE_P (d) = 1;
|
|
572 else if (gethostname (localname, sizeof (localname)))
|
|
573 DEVICE_ON_CONSOLE_P (d) = 0; /* can't find hostname? */
|
|
574 else
|
|
575 {
|
|
576 /* We have to call gethostbyname() on the result of gethostname()
|
|
577 because the two aren't guaranteed to be the same name for the
|
|
578 same host: on some losing systems, one is a FQDN and the other
|
|
579 is not. Here in the wide wonderful world of Unix it's rocket
|
|
580 science to obtain the local hostname in a portable fashion.
|
|
581
|
|
582 And don't forget, gethostbyname() reuses the structure it
|
|
583 returns, so we have to copy the fucker before calling it
|
|
584 again.
|
|
585
|
|
586 Thank you master, may I have another.
|
|
587 */
|
|
588 struct hostent *h = gethostbyname (dpyname);
|
|
589 if (!h)
|
|
590 DEVICE_ON_CONSOLE_P (d) = 0;
|
|
591 else
|
|
592 {
|
563
|
593 Extbyte hn [255];
|
428
|
594 struct hostent *l;
|
|
595 strcpy (hn, h->h_name);
|
|
596 l = gethostbyname (localname);
|
|
597 DEVICE_ON_CONSOLE_P (d) = (l && !(strcmp (l->h_name, hn)));
|
|
598 }
|
|
599 }
|
|
600 start_interrupts ();
|
|
601 }
|
|
602 }
|
|
603 #endif /* HAVE_X_WINDOWS */
|
|
604 }
|
|
605
|
|
606 #endif /* HAVE_NATIVE_SOUND */
|
|
607
|
|
608 void
|
|
609 init_device_sound (struct device *d)
|
|
610 {
|
|
611 #ifdef HAVE_NAS_SOUND
|
|
612 init_nas_sound (d);
|
|
613 #endif
|
|
614
|
|
615 #ifdef HAVE_NATIVE_SOUND
|
|
616 init_native_sound (d);
|
|
617 #endif
|
|
618 }
|
|
619
|
|
620 void
|
|
621 syms_of_sound (void)
|
|
622 {
|
563
|
623 DEFKEYWORD (Q_volume);
|
|
624 DEFKEYWORD (Q_pitch);
|
|
625 DEFKEYWORD (Q_duration);
|
|
626 DEFKEYWORD (Q_sound);
|
428
|
627
|
563
|
628 DEFERROR_STANDARD (Qsound_error, Qio_error);
|
428
|
629
|
|
630 DEFSUBR (Fplay_sound_file);
|
|
631 DEFSUBR (Fplay_sound);
|
|
632 DEFSUBR (Fding);
|
|
633 DEFSUBR (Fwait_for_sounds);
|
|
634 DEFSUBR (Fconnected_to_nas_p);
|
|
635 DEFSUBR (Fdevice_sound_enabled_p);
|
|
636 }
|
|
637
|
|
638
|
|
639 void
|
|
640 vars_of_sound (void)
|
|
641 {
|
|
642 #ifdef HAVE_NATIVE_SOUND
|
|
643 Fprovide (intern ("native-sound"));
|
|
644 #endif
|
|
645 #ifdef HAVE_NAS_SOUND
|
|
646 Fprovide (intern ("nas-sound"));
|
|
647 #endif
|
432
|
648 #ifdef HAVE_ESD_SOUND
|
|
649 Fprovide (intern ("esd-sound"));
|
|
650 #endif
|
428
|
651
|
|
652 DEFVAR_INT ("bell-volume", &bell_volume /*
|
|
653 *How loud to be, from 0 to 100.
|
|
654 */ );
|
|
655 bell_volume = 50;
|
|
656
|
|
657 DEFVAR_INT ("bell-inhibit-time", &bell_inhibit_time /*
|
|
658 *Don't ring the bell on the same device more than once within this many seconds.
|
|
659 */ );
|
|
660 bell_inhibit_time = 0;
|
|
661
|
|
662 DEFVAR_LISP ("sound-alist", &Vsound_alist /*
|
|
663 An alist associating names with sounds.
|
|
664 When `beep' or `ding' is called with one of the name symbols, the associated
|
|
665 sound will be generated instead of the standard beep.
|
|
666
|
|
667 Each element of `sound-alist' is a list describing a sound.
|
|
668 The first element of the list is the name of the sound being defined.
|
|
669 Subsequent elements of the list are alternating keyword/value pairs:
|
|
670
|
|
671 Keyword: Value:
|
|
672 ------- -----
|
|
673 sound A string of raw sound data, or the name of another sound to
|
|
674 play. The symbol `t' here means use the default X beep.
|
|
675 volume An integer from 0-100, defaulting to `bell-volume'
|
|
676 pitch If using the default X beep, the pitch (Hz) to generate.
|
|
677 duration If using the default X beep, the duration (milliseconds).
|
|
678
|
|
679 For compatibility, elements of `sound-alist' may also be:
|
|
680
|
|
681 ( sound-name . <sound> )
|
|
682 ( sound-name <volume> <sound> )
|
|
683
|
|
684 You should probably add things to this list by calling the function
|
|
685 load-sound-file.
|
|
686
|
|
687 Caveats:
|
|
688 - XEmacs must be built with sound support for your system. Not all
|
|
689 systems support sound.
|
|
690
|
|
691 - The pitch, duration, and volume options are available everywhere, but
|
|
692 many X servers ignore the `pitch' option.
|
|
693
|
793
|
694 Sound symbols that map directly to data should be considered named sounds;
|
|
695 sound symbols that map to other sounds should be considered abstract
|
|
696 sounds, and are used when a particular behavior or state occurs. See
|
|
697 `ding' for a list of the standard abstract sounds.
|
428
|
698 */ );
|
|
699 Vsound_alist = Qnil;
|
|
700
|
|
701 DEFVAR_LISP ("synchronous-sounds", &Vsynchronous_sounds /*
|
|
702 Play sounds synchronously, if non-nil.
|
|
703 Only applies if NAS is used and supports asynchronous playing
|
|
704 of sounds. Otherwise, sounds are always played synchronously.
|
|
705 */ );
|
|
706 Vsynchronous_sounds = Qnil;
|
|
707
|
|
708 DEFVAR_LISP ("native-sound-only-on-console", &Vnative_sound_only_on_console /*
|
|
709 Non-nil value means play sounds only if XEmacs is running
|
|
710 on the system console.
|
442
|
711 Nil means always play sounds, even if running on a non-console tty
|
428
|
712 or a secondary X display.
|
|
713
|
|
714 This variable only applies to native sound support.
|
|
715 */ );
|
|
716 Vnative_sound_only_on_console = Qt;
|
|
717
|
|
718 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800)
|
|
719 {
|
|
720 void vars_of_hpplay (void);
|
|
721 vars_of_hpplay ();
|
|
722 }
|
|
723 #endif
|
|
724 }
|