From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Ben Key" Newsgroups: gmane.emacs.devel Subject: Updated patch for a Windows implementation of play-sound - 2 Date: Fri, 25 Oct 2002 01:03:52 -0400 Sender: emacs-devel-admin@gnu.org Message-ID: <001001c27be3$e9a32110$6401a8c0@GODDESS> Reply-To: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0011_01C27BC2.62918110" X-Trace: main.gmane.org 1035522502 17804 80.91.224.249 (25 Oct 2002 05:08:22 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 25 Oct 2002 05:08:22 +0000 (UTC) Cc: , Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 184whn-0004ce-00 for ; Fri, 25 Oct 2002 07:08:19 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 184wkI-000154-00 for ; Fri, 25 Oct 2002 07:10:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 184wdt-0001K2-00; Fri, 25 Oct 2002 01:04:18 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 184wdb-0000xx-00 for emacs-devel@gnu.org; Fri, 25 Oct 2002 01:03:59 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 184wdZ-0000xF-00 for emacs-devel@gnu.org; Fri, 25 Oct 2002 01:03:58 -0400 Original-Received: from smtp-server3.tampabay.rr.com ([65.32.1.41]) by monty-python.gnu.org with esmtp (Exim 4.10) id 184wdU-0000lp-00; Fri, 25 Oct 2002 01:03:52 -0400 Original-Received: from GODDESS (6535194hfc48.tampabay.rr.com [65.35.194.48]) by smtp-server3.tampabay.rr.com (8.12.2/8.12.2) with SMTP id g9P53d7Z022755; Fri, 25 Oct 2002 01:03:39 -0400 (EDT) Original-To: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:8756 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:8756 This is a multi-part message in MIME format. ------=_NextPart_000_0011_01C27BC2.62918110 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This is another updated version of my patch to provide a Windows compatible implementation of play-sound. In this update I incorporated several more suggestions made to me by members of this list. The largest change between this patch and my previous one is thaI am no longer adding a file w32sound.c. Instead I am using sound.c. The changes made by this patch are as follows: * nt/nmake.defs and nt/gmake.defs have been modified so that the constant WINMM is defined in such a way to indicate how to link with the library WINMM.LIB. This constant was defined much like the constants ADVAPI32, COMDLG32, GDI32, MPR, SHELL32, USER32, and WSOCK32. * src/makefile.w32-in has been modified to compile sound.c and to link with WINMM.LIB. * src/s/ms-w32.h has been modified so that the preprocessor symbol HAVE_SOUND is defined. This enables sound support in Emacs. * The code that was previously in w32sound.c has been merged into sound.c. sound.c has been reorganized sightly to make it easier for the platform specific portions of the code to be enclosed by #ifdef statements and has been divided up into well commented sections to ensure that there is no misunderstanding about the purpose of a particular #ifdef block. In order to do this in as clear and orderly a fashion as possible, I had to move some blocks of code up or down to deal with situations where code that works in all platforms was thrown right in the middle of a large block of platform specific code. So far I have tested this patch under Windows using both MSVC 6.0 and MinGW 2.0. I have not been able to test this patch under Linux because I have not yet finished setting up my Linux machine (maybe tomorrow). I cannot test this patch under any other platforms besides Windows and after tomorrow, Linux, because I do not have access to any other platforms. I would appreciate it if someone would apply this patch on a platform that I do not have access to yet has sound support and see if sound.c will compile properly on that platform (perhaps Mac OSX). ------=_NextPart_000_0011_01C27BC2.62918110 Content-Type: application/octet-stream; name="emacs-21.3.50-w32-play-sound.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="emacs-21.3.50-w32-play-sound.diff" --- _21.3/nt/nmake.defs 2002-01-04 09:04:53.000000000 -0500=0A= +++ 21.3/nt/nmake.defs 2002-10-23 22:27:03.000000000 -0400=0A= @@ -123,6 +123,7 @@=0A= SHELL32 =3D shell32.lib USER32 =3D user32.lib WSOCK32 =3D wsock32.lib +WINMM =3D winmm.lib=0A= =20 !ifdef NOOPT DEBUG_CFLAGS =3D -DEMACSDEBUG --- _21.3/nt/gmake.defs 2002-01-04 09:04:26.000000000 -0500=0A= +++ 21.3/nt/gmake.defs 2002-10-23 22:27:03.000000000 -0400=0A= @@ -166,6 +166,7 @@=0A= SHELL32 =3D -lshell32=0A= USER32 =3D -luser32=0A= WSOCK32 =3D -lwsock32=0A= +WINMM =3D -lwinmm=0A= =0A= ifdef NOOPT=0A= DEBUG_CFLAGS =3D -DEMACSDEBUG=0A= --- _21.3/src/makefile.w32-in 2002-09-04 02:20:50.000000000 -0400=0A= +++ 21.3/src/makefile.w32-in 2002-10-23 23:11:10.000000000 -0400=0A= @@ -94,6 +94,7 @@=0A= $(BLD)/regex.$(O) \=0A= $(BLD)/scroll.$(O) \=0A= $(BLD)/search.$(O) \=0A= + $(BLD)/sound.$(O) \=0A= $(BLD)/syntax.$(O) \=0A= $(BLD)/sysdep.$(O) \=0A= $(BLD)/term.$(O) \=0A= @@ -133,6 +134,7 @@=0A= $(TLIB1) \=0A= $(TLIBW32) \=0A= $(TLASTLIB) \=0A= + $(WINMM) \=0A= $(ADVAPI32) \=0A= $(GDI32) \=0A= $(COMDLG32) \=0A= @@ -1094,6 +1096,13 @@=0A= $(SRC)/w32bdf.h \=0A= $(SRC)/w32gui.h=0A= =0A= +$(BLD)/sound.$(O) : \=0A= + $(SRC)/sound.c \=0A= + $(SRC)/lisp.h \=0A= + $(SRC)/dispextern.h \=0A= + $(SRC)/atimer.h \=0A= + $(SRC)/syssignal.h=0A= +=0A= $(BLD)/strftime.$(O) : \=0A= $(SRC)/strftime.c \=0A= $(EMACS_ROOT)/src/s/ms-w32.h \=0A= --- _21.3/src/s/ms-w32.h 2002-05-03 16:42:33.000000000 -0400=0A= +++ 21.3/src/s/ms-w32.h 2002-10-23 22:27:03.000000000 -0400=0A= @@ -217,6 +217,7 @@=0A= #define MAXPATHLEN _MAX_PATH=0A= #endif=0A= =0A= +#define HAVE_SOUND 1=0A= #define LISP_FLOAT_TYPE 1=0A= =0A= #undef HAVE_SYS_SELECT_H=0A= --- _21.3/src/sound.c 2002-07-19 10:27:20.000000000 -0400=0A= +++ 21.3/src/sound.c 2002-10-24 22:08:38.000000000 -0400=0A= @@ -21,10 +21,30 @@=0A= /* Written by Gerd Moellmann . Tested with Luigi's=0A= driver on FreeBSD 2.2.7 with a SoundBlaster 16. */=0A= =0A= +/*=0A= + Modified by Ben Key to add a partial=0A= + implementation of the play-sound specification for Windows.=0A= +=0A= + Notes:=0A= + In the Windows implementation of play-sound-internal only the=0A= + :file and :volume keywords are supported. The :device keyword,=0A= + if present, is ignored. The :data keyword, if present, will=0A= + cause an error to be generated.=0A= +=0A= + The Windows implementation of play-sound is implemented via the=0A= + Win32 API functions mciSendString, waveOutGetVolume, and=0A= + waveOutGetVolume which are exported by Winmm.dll.=0A= +*/=0A= +=0A= #include =0A= =0A= #if defined HAVE_SOUND=0A= =0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Common Includes=0A= + Include files that are common to all platforms=0A= +*/=0A= #include =0A= #include =0A= #include =0A= @@ -34,6 +54,18 @@=0A= #include "atimer.h"=0A= #include =0A= #include "syssignal.h"=0A= +/*=0A= + END SECTION: Common Includes=0A= + Include files that are common to all platforms=0A= + <<@@=0A= +*/=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Non Windows Includes=0A= + Include files that are not used in Microsoft Windows=0A= +*/=0A= +#if !defined(WINDOWSNT)=0A= =0A= #ifndef MSDOS=0A= #include =0A= @@ -51,12 +83,86 @@=0A= #ifdef HAVE_SOUNDCARD_H=0A= #include =0A= #endif=0A= +/*=0A= + END SECTION: Non Windows Includes=0A= + Include files that are not used in Microsoft Windows=0A= + <<@@=0A= +*/=0A= +=0A= +#else /* #if !defined(WINDOWSNT) */=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Windows Specific Includes=0A= + Include files that are only in Microsoft Windows=0A= +*/=0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +/*=0A= + END SECTION: Windows Specific Includes=0A= + Include files that are only in Microsoft Windows=0A= + <<@@=0A= +*/=0A= +=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Common Definitions=0A= + Contains macro, type, and variable definitions that are=0A= + common to all platforms. Also contains function prototypes=0A= + for functions that are common to all platforms.=0A= +*/=0A= +#define abs(X) ((X) < 0 ? -(X) : (X))=0A= +=0A= +/* Symbols. */=0A= +=0A= +extern Lisp_Object QCfile, QCdata;=0A= +Lisp_Object QCvolume, QCdevice;=0A= +Lisp_Object Qsound;=0A= +Lisp_Object Qplay_sound_functions;=0A= +=0A= +/* Indices of attributes in a sound attributes vector. */=0A= +=0A= +enum sound_attr=0A= +{=0A= + SOUND_FILE,=0A= + SOUND_DATA,=0A= + SOUND_DEVICE,=0A= + SOUND_VOLUME,=0A= + SOUND_ATTR_SENTINEL=0A= +};=0A= +=0A= +static void sound_perror P_ ((char *));=0A= +static void sound_warning P_ ((char *));=0A= +static int parse_sound P_ ((Lisp_Object, Lisp_Object *));=0A= +=0A= +/*=0A= + END SECTION: Common Definitions=0A= + Contains macro, type, and variable definitions that are=0A= + common to all platforms. Also contains function prototypes=0A= + for functions that are common to all platforms.=0A= + <<@@=0A= +*/=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Non Windows Definitions=0A= + Contains macro, type, and variable definitions that are=0A= + only used on platforms other then Microsoft Windows.=0A= + Also contains function prototypes for functions that=0A= + are only used on platforms other then Microsoft Windows.=0A= +*/=0A= +#if !defined(WINDOWSNT)=0A= =0A= #ifndef DEFAULT_SOUND_DEVICE=0A= #define DEFAULT_SOUND_DEVICE "/dev/dsp"=0A= #endif=0A= =0A= -#define abs(X) ((X) < 0 ? -(X) : (X))=0A= =0A= /* Structure forward declarations. */=0A= =0A= @@ -203,24 +309,6 @@=0A= void (* play) P_ ((struct sound *s, struct sound_device *sd));=0A= };=0A= =0A= -/* Indices of attributes in a sound attributes vector. */=0A= -=0A= -enum sound_attr=0A= -{=0A= - SOUND_FILE,=0A= - SOUND_DATA,=0A= - SOUND_DEVICE,=0A= - SOUND_VOLUME,=0A= - SOUND_ATTR_SENTINEL=0A= -};=0A= -=0A= -/* Symbols. */=0A= -=0A= -extern Lisp_Object QCfile, QCdata;=0A= -Lisp_Object QCvolume, QCdevice;=0A= -Lisp_Object Qsound;=0A= -Lisp_Object Qplay_sound_functions;=0A= -=0A= /* These are set during `play-sound-internal' so that sound_cleanup has=0A= access to them. */=0A= =0A= @@ -235,9 +323,6 @@=0A= static void vox_choose_format P_ ((struct sound_device *, struct sound = *));=0A= static void vox_init P_ ((struct sound_device *));=0A= static void vox_write P_ ((struct sound_device *, const char *, int));=0A= -static void sound_perror P_ ((char *));=0A= -static void sound_warning P_ ((char *));=0A= -static int parse_sound P_ ((Lisp_Object, Lisp_Object *));=0A= static void find_sound_type P_ ((struct sound *));=0A= static u_int32_t le2hl P_ ((u_int32_t));=0A= static u_int16_t le2hs P_ ((u_int16_t));=0A= @@ -251,12 +336,46 @@=0A= static u_int16_t be2hs P_ ((u_int16_t));=0A= #endif=0A= =0A= +/*=0A= + END SECTION: Non Windows Definitions=0A= + Contains macro, type, and variable definitions that are=0A= + only used on platforms other then Microsoft Windows.=0A= + Also contains function prototypes for functions that=0A= + are only used on platforms other then Microsoft Windows.=0A= + <<@@=0A= +*/=0A= +#else /* #if !defined(WINDOWSNT) */=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Windows Specific Definitions=0A= + Contains macro, type, and variable definitions that are=0A= + specific to Microsoft Windows.=0A= + Also contains function prototypes for functions that=0A= + are specific to Microsoft Windows.=0A= +*/=0A= +static int do_play_sound P_ ((const char *,unsigned int));=0A= +/*=0A= + END SECTION: Windows Specific Definitions=0A= + Contains macro, type, and variable definitions that are=0A= + specific to Microsoft Windows.=0A= + Also contains function prototypes for functions that=0A= + are specific to Microsoft Windows.=0A= + <<@@=0A= +*/=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= =0A= =0C=0A= /***********************************************************************=0A= General=0A= = ***********************************************************************/=0A= =0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Common functions=0A= + Functions that are common to all platformas=0A= +*/=0A= +=0A= /* Like perror, but signals an error. */=0A= =0A= static void=0A= @@ -327,10 +446,21 @@=0A= attrs[SOUND_DEVICE] =3D Fplist_get (sound, QCdevice);=0A= attrs[SOUND_VOLUME] =3D Fplist_get (sound, QCvolume);=0A= =0A= +#if !defined(WINDOWSNT)=0A= /* File name or data must be specified. */=0A= if (!STRINGP (attrs[SOUND_FILE])=0A= && !STRINGP (attrs[SOUND_DATA]))=0A= return 0;=0A= +#else /* #if !defined(WINDOWSNT) */=0A= + /*=0A= + Data is not supported in Windows. Therefore a=0A= + File name MUST be supplied.=0A= + */=0A= + if (!STRINGP(attrs[SOUND_FILE]))=0A= + {=0A= + return 0;=0A= + }=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= =0A= /* Volume must be in the range 0..100 or unspecified. */=0A= if (!NILP (attrs[SOUND_VOLUME]))=0A= @@ -351,14 +481,31 @@=0A= return 0;=0A= }=0A= =0A= +#if !defined(WINDOWSNT)=0A= /* Device must be a string or unspecified. */=0A= if (!NILP (attrs[SOUND_DEVICE])=0A= && !STRINGP (attrs[SOUND_DEVICE]))=0A= return 0;=0A= -=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= + /*=0A= + Since device is ignored in Windows, it does not matter=0A= + what it is.=0A= + */=0A= return 1;=0A= }=0A= =0A= +/*=0A= + END SECTION: Common functions=0A= + Functions that are common to all platformas=0A= + <<@@=0A= +*/=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Non Windows functions=0A= + Functions that are only used on non Windows platforms=0A= +*/=0A= +#if !defined(WINDOWSNT)=0A= =0A= /* Find out the type of the sound file whose file descriptor is FD.=0A= S is the sound file structure to fill in. */=0A= @@ -389,105 +536,6 @@=0A= return Qnil;=0A= }=0A= =0A= -=0A= -DEFUN ("play-sound-internal", Fplay_sound_internal, = Splay_sound_internal, 1, 1, 0,=0A= - doc: /* Play sound SOUND.=0A= -=0A= -Internal use only, use `play-sound' instead. */)=0A= - (sound)=0A= - Lisp_Object sound;=0A= -{=0A= - Lisp_Object attrs[SOUND_ATTR_SENTINEL];=0A= - Lisp_Object file;=0A= - struct gcpro gcpro1, gcpro2;=0A= - struct sound_device sd;=0A= - struct sound s;=0A= - Lisp_Object args[2];=0A= - int count =3D SPECPDL_INDEX ();=0A= -=0A= - file =3D Qnil;=0A= - GCPRO2 (sound, file);=0A= - bzero (&sd, sizeof sd);=0A= - bzero (&s, sizeof s);=0A= - current_sound_device =3D &sd;=0A= - current_sound =3D &s;=0A= - record_unwind_protect (sound_cleanup, Qnil);=0A= - s.header =3D (char *) alloca (MAX_SOUND_HEADER_BYTES);=0A= -=0A= - /* Parse the sound specification. Give up if it is invalid. */=0A= - if (!parse_sound (sound, attrs))=0A= - error ("Invalid sound specification");=0A= -=0A= - if (STRINGP (attrs[SOUND_FILE]))=0A= - {=0A= - /* Open the sound file. */=0A= - s.fd =3D openp (Fcons (Vdata_directory, Qnil),=0A= - attrs[SOUND_FILE], Qnil, &file, Qnil);=0A= - if (s.fd < 0)=0A= - sound_perror ("Could not open sound file");=0A= -=0A= - /* Read the first bytes from the file. */=0A= - s.header_size =3D emacs_read (s.fd, s.header, = MAX_SOUND_HEADER_BYTES);=0A= - if (s.header_size < 0)=0A= - sound_perror ("Invalid sound file header");=0A= - }=0A= - else=0A= - {=0A= - s.data =3D attrs[SOUND_DATA];=0A= - s.header_size =3D min (MAX_SOUND_HEADER_BYTES, SBYTES (s.data));=0A= - bcopy (SDATA (s.data), s.header, s.header_size);=0A= - }=0A= -=0A= - /* Find out the type of sound. Give up if we can't tell. */=0A= - find_sound_type (&s);=0A= -=0A= - /* Set up a device. */=0A= - if (STRINGP (attrs[SOUND_DEVICE]))=0A= - {=0A= - int len =3D SCHARS (attrs[SOUND_DEVICE]);=0A= - sd.file =3D (char *) alloca (len + 1);=0A= - strcpy (sd.file, SDATA (attrs[SOUND_DEVICE]));=0A= - }=0A= -=0A= - if (INTEGERP (attrs[SOUND_VOLUME]))=0A= - sd.volume =3D XFASTINT (attrs[SOUND_VOLUME]);=0A= - else if (FLOATP (attrs[SOUND_VOLUME]))=0A= - sd.volume =3D XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;=0A= -=0A= - args[0] =3D Qplay_sound_functions;=0A= - args[1] =3D sound;=0A= - Frun_hook_with_args (2, args);=0A= -=0A= - /* There is only one type of device we currently support, the VOX=0A= - sound driver. Set up the device interface functions for that=0A= - device. */=0A= - vox_init (&sd);=0A= -=0A= - /* Open the device. */=0A= - sd.open (&sd);=0A= -=0A= - /* Play the sound. */=0A= - s.play (&s, &sd);=0A= -=0A= - /* Close the input file, if any. */=0A= - if (!STRINGP (s.data))=0A= - {=0A= - emacs_close (s.fd);=0A= - s.fd =3D -1;=0A= - }=0A= -=0A= - /* Close the device. */=0A= - sd.close (&sd);=0A= -=0A= - /* Clean up. */=0A= - current_sound_device =3D NULL;=0A= - current_sound =3D NULL;=0A= - UNGCPRO;=0A= - unbind_to (count, Qnil);=0A= - return Qnil;=0A= -}=0A= -=0A= -=0C=0A= /***********************************************************************=0A= Byte-order Conversion=0A= = ***********************************************************************/=0A= @@ -909,7 +957,6 @@=0A= sd->write =3D vox_write;=0A= }=0A= =0A= -=0A= /* Write NBYTES bytes from BUFFER to device SD. */=0A= =0A= static void=0A= @@ -923,7 +970,241 @@=0A= sound_perror ("Error writing to sound device");=0A= }=0A= =0A= +/*=0A= + END SECTION: Non Windows functions=0A= + Functions that are only used on non Windows platforms=0A= + <<@@=0A= +*/=0A= +#else /* #if !defined(WINDOWSNT) */=0A= +=0A= +/*=0A= + @@>>=0A= + BEGIN SECTION: Windows specific functions=0A= + Functions that are only used Microsoft Windows=0A= +*/=0A= +=0A= +static int=0A= +do_play_sound(psz_file,ui_volume)=0A= + const char * psz_file;=0A= + unsigned int ui_volume;=0A= +{=0A= + int i_result=3D0;=0A= + MCIERROR mci_error=3D0;=0A= + char sz_cmd_buf[520]=3D{0};=0A= + char sz_ret_buf[520]=3D{0};=0A= + MMRESULT mm_result=3DMMSYSERR_NOERROR;=0A= + unsigned int ui_volume_org=3D0;=0A= + BOOL b_reset_volume=3DFALSE;=0A= + memset(sz_cmd_buf,0,sizeof(sz_cmd_buf));=0A= + memset(sz_ret_buf,0,sizeof(sz_ret_buf));=0A= + sprintf(=0A= + sz_cmd_buf,=0A= + "open \"%s\" alias GNUEmacs_PlaySound_Device wait",=0A= + psz_file);=0A= + mci_error=3DmciSendString(sz_cmd_buf,sz_ret_buf,520,NULL);=0A= + if (mci_error!=3D0)=0A= + {=0A= + sound_warning(=0A= + "The open mciSendString command failed to open\n"=0A= + "the specified sound file");=0A= + i_result=3D(int)mci_error;=0A= + return i_result;=0A= + }=0A= + if (ui_volume>0 && ui_volume!=3DUINT_MAX)=0A= + {=0A= + = mm_result=3DwaveOutGetVolume((HWAVEOUT)WAVE_MAPPER,&ui_volume_org);=0A= + if (mm_result=3D=3DMMSYSERR_NOERROR)=0A= + {=0A= + b_reset_volume=3DTRUE;=0A= + mm_result=3DwaveOutSetVolume((HWAVEOUT)WAVE_MAPPER,ui_volume);=0A= + if (mm_result!=3DMMSYSERR_NOERROR)=0A= + {=0A= + sound_warning(=0A= + "waveOutSetVolume failed to set the volume level\n"=0A= + "of the WAVE_MAPPER device.\n"=0A= + "As a result, the user selected volume level will\n"=0A= + "not be used.");=0A= + }=0A= + }=0A= + else=0A= + {=0A= + sound_warning(=0A= + "waveOutGetVolume failed to obtain the original\n"=0A= + "volume level of the WAVE_MAPPER device.\n"=0A= + "As a result, the user selected volume level will\n"=0A= + "not be used.");=0A= + }=0A= + }=0A= + memset(sz_cmd_buf,0,sizeof(sz_cmd_buf));=0A= + memset(sz_ret_buf,0,sizeof(sz_ret_buf));=0A= + strcpy(sz_cmd_buf,"play GNUEmacs_PlaySound_Device wait");=0A= + mci_error=3DmciSendString(sz_cmd_buf,sz_ret_buf,520,NULL);=0A= + if (mci_error!=3D0)=0A= + {=0A= + sound_warning(=0A= + "The play mciSendString command failed to play the\n"=0A= + "opened sound file.");=0A= + i_result=3D(int)mci_error;=0A= + }=0A= + memset(sz_cmd_buf,0,sizeof(sz_cmd_buf));=0A= + memset(sz_ret_buf,0,sizeof(sz_ret_buf));=0A= + strcpy(sz_cmd_buf,"close GNUEmacs_PlaySound_Device wait");=0A= + mci_error=3DmciSendString(sz_cmd_buf,sz_ret_buf,520,NULL);=0A= + if (b_reset_volume=3D=3DTRUE)=0A= + {=0A= + mm_result=3DwaveOutSetVolume((HWAVEOUT)WAVE_MAPPER,ui_volume_org);=0A= + if (mm_result!=3DMMSYSERR_NOERROR)=0A= + {=0A= + sound_warning(=0A= + "waveOutSetVolume failed to reset the original volume\n"=0A= + "level of the WAVE_MAPPER device.");=0A= + }=0A= + }=0A= + return i_result;=0A= +}=0A= +=0A= +/*=0A= + END SECTION: Windows specific functions=0A= + Functions that are only used Microsoft Windows=0A= + <<@@=0A= +*/=0A= +=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= +=0A= +=0A= +DEFUN ("play-sound-internal", Fplay_sound_internal, = Splay_sound_internal, 1, 1, 0,=0A= + doc: /* Play sound SOUND.=0A= +=0A= +Internal use only, use `play-sound' instead.\n */)=0A= + (sound)=0A= + Lisp_Object sound;=0A= +{=0A= + Lisp_Object attrs[SOUND_ATTR_SENTINEL];=0A= + int count =3D SPECPDL_INDEX ();=0A= +=0A= +#if !defined(WINDOWSNT)=0A= + Lisp_Object file;=0A= + struct gcpro gcpro1, gcpro2;=0A= + struct sound_device sd;=0A= + struct sound s;=0A= + Lisp_Object args[2];=0A= +#else /* #if !defined(WINDOWSNT) */=0A= + int len=3D0;=0A= + char * psz_file=3DNULL;=0A= + unsigned int ui_volume_tmp=3DUINT_MAX;=0A= + unsigned int ui_volume=3DUINT_MAX;=0A= + int i_result=3D0;=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= +=0A= + /* Parse the sound specification. Give up if it is invalid. */=0A= + if (!parse_sound (sound, attrs))=0A= + error ("Invalid sound specification");=0A= +=0A= +#if !defined(WINDOWSNT)=0A= + file =3D Qnil;=0A= + GCPRO2 (sound, file);=0A= + bzero (&sd, sizeof sd);=0A= + bzero (&s, sizeof s);=0A= + current_sound_device =3D &sd;=0A= + current_sound =3D &s;=0A= + record_unwind_protect (sound_cleanup, Qnil);=0A= + s.header =3D (char *) alloca (MAX_SOUND_HEADER_BYTES);=0A= +=0A= + if (STRINGP (attrs[SOUND_FILE]))=0A= + {=0A= + /* Open the sound file. */=0A= + s.fd =3D openp (Fcons (Vdata_directory, Qnil),=0A= + attrs[SOUND_FILE], Qnil, &file, Qnil);=0A= + if (s.fd < 0)=0A= + sound_perror ("Could not open sound file");=0A= +=0A= + /* Read the first bytes from the file. */=0A= + s.header_size =3D emacs_read (s.fd, s.header, = MAX_SOUND_HEADER_BYTES);=0A= + if (s.header_size < 0)=0A= + sound_perror ("Invalid sound file header");=0A= + }=0A= + else=0A= + {=0A= + s.data =3D attrs[SOUND_DATA];=0A= + s.header_size =3D min (MAX_SOUND_HEADER_BYTES, SBYTES (s.data));=0A= + bcopy (SDATA (s.data), s.header, s.header_size);=0A= + }=0A= +=0A= + /* Find out the type of sound. Give up if we can't tell. */=0A= + find_sound_type (&s);=0A= =0A= + /* Set up a device. */=0A= + if (STRINGP (attrs[SOUND_DEVICE]))=0A= + {=0A= + int len =3D SCHARS (attrs[SOUND_DEVICE]);=0A= + sd.file =3D (char *) alloca (len + 1);=0A= + strcpy (sd.file, SDATA (attrs[SOUND_DEVICE]));=0A= + }=0A= +=0A= + if (INTEGERP (attrs[SOUND_VOLUME]))=0A= + sd.volume =3D XFASTINT (attrs[SOUND_VOLUME]);=0A= + else if (FLOATP (attrs[SOUND_VOLUME]))=0A= + sd.volume =3D XFLOAT_DATA (attrs[SOUND_VOLUME]) * 100;=0A= +=0A= + args[0] =3D Qplay_sound_functions;=0A= + args[1] =3D sound;=0A= + Frun_hook_with_args (2, args);=0A= +=0A= + /* There is only one type of device we currently support, the VOX=0A= + sound driver. Set up the device interface functions for that=0A= + device. */=0A= + vox_init (&sd);=0A= +=0A= + /* Open the device. */=0A= + sd.open (&sd);=0A= +=0A= + /* Play the sound. */=0A= + s.play (&s, &sd);=0A= +=0A= + /* Close the input file, if any. */=0A= + if (!STRINGP (s.data))=0A= + {=0A= + emacs_close (s.fd);=0A= + s.fd =3D -1;=0A= + }=0A= +=0A= + /* Close the device. */=0A= + sd.close (&sd);=0A= +=0A= + /* Clean up. */=0A= + current_sound_device =3D NULL;=0A= + current_sound =3D NULL;=0A= + UNGCPRO;=0A= +#else /* #if !defined(WINDOWSNT) */=0A= + len=3DXSTRING(attrs[SOUND_FILE])->size;=0A= + psz_file=3D(char *)alloca(len+1);=0A= + strcpy(psz_file,XSTRING(attrs[SOUND_FILE])->data);=0A= + if (INTEGERP (attrs[SOUND_VOLUME]))=0A= + {=0A= + ui_volume_tmp=3DXFASTINT(attrs[SOUND_VOLUME]);=0A= + }=0A= + else if (FLOATP(attrs[SOUND_VOLUME]))=0A= + {=0A= + ui_volume_tmp=3DXFLOAT_DATA(attrs[SOUND_VOLUME])*100;=0A= + }=0A= + /*=0A= + Based on some experiments I have conducted, a value of 100 or less=0A= + for the sound volume is much too low. You cannot even hear it.=0A= + A value of UINT_MAX indicates that you wish for the sound to played=0A= + at the maximum possible volume. A value of UINT_MAX/2 plays the=0A= + sound at 50% maximum volume. Therefore the value passed to = do_play_sound=0A= + (and thus to waveOutSetVolume must be some fraction of UINT_MAX.=0A= + The following code adjusts the user specified volume level = appropriately.=0A= + */=0A= + if (ui_volume_tmp>0 && ui_volume_tmp<=3D100)=0A= + {=0A= + ui_volume=3Dui_volume_tmp*(UINT_MAX/100);=0A= + }=0A= + i_result=3Ddo_play_sound(psz_file,ui_volume);=0A= +#endif /* #if !defined(WINDOWSNT) */=0A= + unbind_to (count, Qnil);=0A= + return Qnil;=0A= +}=0A= =0C=0A= /***********************************************************************=0A= Initialization=0A= ------=_NextPart_000_0011_01C27BC2.62918110 Content-Type: application/octet-stream; name="dopatch21_3.sh" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="dopatch21_3.sh" #!/bin/sh patch --unified --quiet --strip=1 --input=emacs-21.3.50-w32-play-sound.diff ------=_NextPart_000_0011_01C27BC2.62918110--