annotate src/sound.c @ 7:c153ca296910

Added tag r19-15b4 for changeset 27bc7f280385
author cvs
date Mon, 13 Aug 2007 08:47:16 +0200
parents 376386a54a3c
children 859a2309aef8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Sound functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1992, 1993, 1994 Lucid Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Originally written by Jamie Zawinski.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 Hacked on quite a bit by various others. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #ifdef HAVE_X_WINDOWS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "console-x.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #ifdef HAVE_NEXTSTEP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "console-ns.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "redisplay.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 # include <netdb.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 int bell_volume;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 Lisp_Object Vsound_alist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 Lisp_Object Vsynchronous_sounds;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 Lisp_Object Vnative_sound_only_on_console;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Lisp_Object Q_volume, Q_pitch, Q_duration, Q_sound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* These are defined in the appropriate file (sunplay.c, sgiplay.c,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 or hpplay.c). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 extern void play_sound_file (char *name, int volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 extern void play_sound_data (unsigned char *data, int length, int volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 extern int nas_play_sound_file (char *name, int volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 extern int nas_play_sound_data (unsigned char *data, int length, int volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 extern int nas_wait_for_sounds (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 extern char *nas_init_play (Display *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 Lisp_Object Qnas;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 DEFUN ("play-sound-file", Fplay_sound_file, Splay_sound_file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 1, 3, "fSound file name: " /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 Play the named sound file on DEVICE's speaker at the specified volume
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (0-100, default specified by the `bell-volume' variable).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 The sound file must be in the Sun/NeXT U-LAW format except under Linux
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 where WAV files are also supported.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 DEVICE defaults to the selected device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (file, volume, device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 Lisp_Object file, volume, device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 int vol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #if defined (HAVE_NATIVE_SOUND) || defined (HAVE_NAS_SOUND)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 struct device *d = decode_device (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 CHECK_STRING (file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 if (NILP (volume))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 vol = bell_volume;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 CHECK_INT (volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 vol = XINT (volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 file = Fexpand_file_name (file, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 if (NILP (Ffile_readable_p (file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 if (NILP (Ffile_exists_p (file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 error ("file does not exist.");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 error ("file is unreadable.");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 if (DEVICE_CONNECTED_TO_NAS_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 char *fileext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 GET_C_STRING_FILENAME_DATA_ALLOCA (file, fileext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 /* #### NAS code should allow specification of a device. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 if (nas_play_sound_file (fileext, vol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 #endif /* HAVE_NAS_SOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 if (NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 CONST char *fileext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 GET_C_STRING_FILENAME_DATA_ALLOCA (file, fileext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 /* The sound code doesn't like getting SIGIO interrupts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Unix sucks! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 play_sound_file ((char *) fileext, vol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 #endif /* HAVE_NATIVE_SOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 parse_sound_alist_elt (Lisp_Object elt,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 Lisp_Object *volume,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Lisp_Object *pitch,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Lisp_Object *duration,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 Lisp_Object *sound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 *volume = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 *pitch = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 *duration = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 *sound = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 if (! CONSP (elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 /* The things we do for backward compatibility...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 I wish I had just forced this to be a plist to begin with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 if (SYMBOLP (elt) || STRINGP (elt)) /* ( name . <sound> ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 *sound = elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 else if (!CONSP (elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 else if (NILP (XCDR (elt)) && /* ( name <sound> ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (SYMBOLP (XCAR (elt)) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 STRINGP (XCAR (elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 *sound = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 else if (INT_OR_FLOATP (XCAR (elt)) && /* ( name <vol> . <sound> ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (SYMBOLP (XCDR (elt)) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 STRINGP (XCDR (elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 *volume = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 *sound = XCDR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 else if (INT_OR_FLOATP (XCAR (elt)) && /* ( name <vol> <sound> ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 CONSP (XCDR (elt)) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 NILP (XCDR (XCDR (elt))) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (SYMBOLP (XCAR (XCDR (elt))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 STRINGP (XCAR (XCDR (elt)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 *volume = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 *sound = XCAR (XCDR (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 else if ((SYMBOLP (XCAR (elt)) || /* ( name <sound> . <vol> ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 STRINGP (XCAR (elt))) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 INT_OR_FLOATP (XCDR (elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 *sound = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 *volume = XCDR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #if 0 /* this one is ambiguous with the plist form */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 else if ((SYMBOLP (XCAR (elt)) || /* ( name <sound> <vol> ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 STRINGP (XCAR (elt))) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 CONSP (XCDR (elt)) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 NILP (XCDR (XCDR (elt))) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 INT_OR_FLOATP (XCAR (XCDR (elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 *sound = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 *volume = XCAR (XCDR (elt));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 else /* ( name [ keyword <value> ]* ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 while (CONSP (elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 Lisp_Object key, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 key = XCAR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 val = XCDR (elt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 if (!CONSP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 elt = XCDR (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 val = XCAR (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 if (EQ (key, Q_volume))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 if (INT_OR_FLOATP (val)) *volume = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 else if (EQ (key, Q_pitch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 if (INT_OR_FLOATP (val)) *pitch = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 if (NILP (*sound)) *sound = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 else if (EQ (key, Q_duration))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 if (INT_OR_FLOATP (val)) *duration = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 if (NILP (*sound)) *sound = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 else if (EQ (key, Q_sound))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 if (SYMBOLP (val) || STRINGP (val)) *sound = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 DEFUN ("play-sound", Fplay_sound, Splay_sound, 1, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 Play a sound of the provided type.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 See the variable `sound-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (sound, volume, device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Lisp_Object sound, volume, device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 int looking_for_default = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 /* variable `sound' is anything that can be a cdr in sound-alist */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 Lisp_Object new_volume, pitch, duration, data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 int loop_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 int vol, pit, dur;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 struct device *d = decode_device (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 /* NOTE! You'd better not signal an error in here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 try_it_again:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (SYMBOLP (sound))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 sound = Fcdr (Fassq (sound, Vsound_alist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 parse_sound_alist_elt (sound, &new_volume, &pitch, &duration, &data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 sound = data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 if (NILP (volume)) volume = new_volume;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 if (EQ (sound, Qt) || EQ (sound, Qnil) || STRINGP (sound))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 if (loop_count++ > 500) /* much bogosity has occurred */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 if (NILP (sound) && !looking_for_default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 looking_for_default = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 loop_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 sound = Qdefault;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 goto try_it_again;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 vol = (INT_OR_FLOATP (volume) ? XFLOATINT (volume) : bell_volume);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 pit = (INT_OR_FLOATP (pitch) ? XFLOATINT (pitch) : -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 dur = (INT_OR_FLOATP (duration) ? XFLOATINT (duration) : -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 /* If the sound is a string, and we're connected to Nas, do that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 Else if the sound is a string, and we're on console, play it natively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 Else just beep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 if (DEVICE_CONNECTED_TO_NAS_P (d) && STRINGP (sound))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 Extbyte *soundext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 Extcount soundextlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 if (nas_play_sound_data (soundext, soundextlen, vol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 #endif /* HAVE_NAS_SOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 if ((NILP (Vnative_sound_only_on_console) || DEVICE_ON_CONSOLE_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 && STRINGP (sound))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 Extbyte *soundext;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 Extcount soundextlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 GET_STRING_BINARY_DATA_ALLOCA (sound, soundext, soundextlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 /* The sound code doesn't like getting SIGIO interrupts. Unix sucks! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 play_sound_data (soundext, soundextlen, vol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 #endif /* HAVE_NATIVE_SOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 DEVMETH (d, ring_bell, (d, vol, pit, dur));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 DEFUN ("device-sound-enabled-p", Fdevice_sound_enabled_p, Sdevice_sound_enabled_p, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 Return T iff DEVICE is able to play sound. Defaults to selected device.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 struct device *d = decode_device(device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 if ( DEVICE_CONNECTED_TO_NAS_P (d) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 return (Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 if ( DEVICE_ON_CONSOLE_P (d) )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 return (Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 DEFUN ("ding", Fding, Sding, 0, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 Beep, or flash the frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 Also, unless an argument is given,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 terminate any keyboard macro currently executing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 When called from lisp, the second argument is what sound to make, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 the third argument is the device to make it in (defaults to the selected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 device).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (arg, sound, device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 Lisp_Object arg, sound, device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 struct device *d = decode_device (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 XSETDEVICE (device, d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 if (NILP (arg) && !NILP (Vexecuting_macro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 /* Stop executing a keyboard macro. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 error ("Keyboard macro terminated by a command ringing the bell");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 else if (visible_bell && DEVMETH (d, flash, (d)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 Fplay_sound (sound, Qnil, device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 DEFUN ("wait-for-sounds", Fwait_for_sounds, Swait_for_sounds,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 Wait for all sounds to finish playing on DEVICE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 struct device *d = decode_device (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 if (DEVICE_CONNECTED_TO_NAS_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 /* #### somebody fix this to be device-dependent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 nas_wait_for_sounds ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 DEFUN ("connected-to-nas-p", Fconnected_to_nas_p, Sconnected_to_nas_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 t if connected to NAS server for sounds on DEVICE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (device)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 Lisp_Object device;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 struct device *d = decode_device (device);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 if (DEVICE_CONNECTED_TO_NAS_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 init_nas_sound (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 char *error;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 #ifdef HAVE_X_WINDOWS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 if (DEVICE_X_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 error = nas_init_play (DEVICE_X_DISPLAY (d));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 DEVICE_CONNECTED_TO_NAS_P (d) = !error;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 /* Print out the message? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #endif /* HAVE_X_WINDOWS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 #endif /* HAVE_NAS_SOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 init_native_sound (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 if (DEVICE_TTY_P (d) || DEVICE_STREAM_P (d))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 DEVICE_ON_CONSOLE_P (d) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 #ifdef HAVE_X_WINDOWS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 /* When running on a machine with native sound support, we cannot use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 digitized sounds as beeps unless emacs is running on the same machine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 that $DISPLAY points to, and $DISPLAY points to frame 0 of that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 machine.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 Display *display = DEVICE_X_DISPLAY (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 char *dpy = DisplayString (display);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 char *tail = (char *) strchr (dpy, ':');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 if (! tail ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 strncmp (tail, ":0", 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 DEVICE_ON_CONSOLE_P (d) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 char dpyname[255], localname[255];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 /* some systems can't handle SIGIO or SIGALARM in gethostbyname. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 strncpy (dpyname, dpy, tail-dpy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 dpyname [tail-dpy] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 if (!*dpyname ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 !strcmp (dpyname, "unix") ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 !strcmp (dpyname, "localhost"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 DEVICE_ON_CONSOLE_P (d) = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 else if (gethostname (localname, sizeof (localname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 DEVICE_ON_CONSOLE_P (d) = 0; /* can't find hostname? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 /* We have to call gethostbyname() on the result of gethostname()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 because the two aren't guarenteed to be the same name for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 same host: on some losing systems, one is a FQDN and the other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 is not. Here in the wide wonderful world of Unix it's rocket
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 science to obtain the local hostname in a portable fashion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 And don't forget, gethostbyname() reuses the structure it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 returns, so we have to copy the fucker before calling it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 Thank you master, may I have another.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 struct hostent *h = gethostbyname (dpyname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 if (!h)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 DEVICE_ON_CONSOLE_P (d) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 char hn [255];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 struct hostent *l;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 strcpy (hn, h->h_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 l = gethostbyname (localname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 DEVICE_ON_CONSOLE_P (d) = (l && !(strcmp (l->h_name, hn)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 #endif /* HAVE_X_WINDOWS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 #endif /* HAVE_NATIVE_SOUND */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 init_device_sound (struct device *d)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 init_nas_sound (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 init_native_sound (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 syms_of_sound (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 defkeyword (&Q_volume, ":volume");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 defkeyword (&Q_pitch, ":pitch");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 defkeyword (&Q_duration, ":duration");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 defkeyword (&Q_sound, ":sound");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 defsymbol (&Qnas, "nas");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 defsubr (&Splay_sound_file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 defsubr (&Splay_sound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 defsubr (&Sding);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 defsubr (&Swait_for_sounds);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 defsubr (&Sconnected_to_nas_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 defsubr (&Sdevice_sound_enabled_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 vars_of_sound (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 #ifdef HAVE_NATIVE_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 Fprovide (intern ("native-sound"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 #ifdef HAVE_NAS_SOUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 Fprovide (intern ("nas-sound"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 DEFVAR_INT ("bell-volume", &bell_volume /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 *How loud to be, from 0 to 100.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 bell_volume = 50;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 DEFVAR_LISP ("sound-alist", &Vsound_alist /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 An alist associating names with sounds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 When `beep' or `ding' is called with one of the name symbols, the associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 sound will be generated instead of the standard beep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 Each element of `sound-alist' is a list describing a sound.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 The first element of the list is the name of the sound being defined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 Subsequent elements of the list are alternating keyword/value pairs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 Keyword: Value:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ------- -----
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 sound A string of raw sound data, or the name of another sound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 play. The symbol `t' here means use the default X beep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 volume An integer from 0-100, defaulting to `bell-volume'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 pitch If using the default X beep, the pitch (Hz) to generate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 duration If using the default X beep, the duration (milliseconds).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 For compatibility, elements of `sound-alist' may also be:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ( sound-name . <sound> )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ( sound-name <volume> <sound> )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 You should probably add things to this list by calling the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 load-sound-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 Caveats:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 - You can only play audio data if running on the console screen of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 Sun SparcStation, SGI, or HP9000s700.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 - The pitch, duration, and volume options are available everywhere, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 many X servers ignore the `pitch' option.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 The following beep-types are used by emacs itself:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 auto-save-error when an auto-save does not succeed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 command-error when the emacs command loop catches an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 undefined-key when you type a key that is undefined
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 undefined-click when you use an undefined mouse-click combination
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 no-completion during completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 y-or-n-p when you type something other than 'y' or 'n'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 yes-or-no-p when you type something other than 'yes' or 'no'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 default used when nothing else is appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 Other lisp packages may use other beep types, but these are the ones that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 the C kernel of Emacs uses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 Vsound_alist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 DEFVAR_LISP ("synchronous-sounds", &Vsynchronous_sounds /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 Play sounds synchronously, if non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 Only applies if NAS is used and supports asynchronous playing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 of sounds. Otherwise, sounds are always played synchronously.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Vsynchronous_sounds = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 DEFVAR_LISP ("native-sound-only-on-console", &Vnative_sound_only_on_console /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 Non-nil value means play sounds only if XEmacs is running
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 on the system console.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 Nil means always always play sounds, even if running on a non-console tty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 or a secondary X display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 This variable only applies to native sound support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 Vnative_sound_only_on_console = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 #if defined (HAVE_NATIVE_SOUND) && defined (hp9000s800)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 vars_of_hpplay ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 }