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