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