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