428
+ − 1 ;;; sound.el --- Loading sound files in XEmacs
+ − 2
+ − 3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
+ − 4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
793
+ − 5 ;; Copyright (C) 2002 Ben Wing.
428
+ − 6
+ − 7 ;; Maintainer: XEmacs Development Team
+ − 8 ;; Keywords: internal
+ − 9
+ − 10 ;; This file is part of XEmacs.
+ − 11
+ − 12 ;; XEmacs is free software; you can redistribute it and/or modify it
+ − 13 ;; under the terms of the GNU General Public License as published by
+ − 14 ;; the Free Software Foundation; either version 2, or (at your option)
+ − 15 ;; any later version.
+ − 16
+ − 17 ;; XEmacs is distributed in the hope that it will be useful, but
+ − 18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ − 20 ;; General Public License for more details.
+ − 21
+ − 22 ;; You should have received a copy of the GNU General Public License
+ − 23 ;; along with XEmacs; see the file COPYING. If not, write to the
+ − 24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
+ − 25 ;; Boston, MA 02111-1307, USA.
+ − 26
+ − 27 ;;; Synched up with: Not in FSF.
+ − 28
+ − 29 ;;; Commentary:
+ − 30
+ − 31 ;;; Code:
+ − 32 (defgroup sound nil
+ − 33 "Configure XEmacs sounds and properties"
+ − 34 :group 'environment)
+ − 35
+ − 36 (defcustom sound-default-alist
+ − 37 '((default :sound bass)
+ − 38 (undefined-key :sound drum)
+ − 39 (undefined-click :sound drum)
+ − 40 ;; beginning-of-buffer or end-of-buffer errors.
+ − 41 (buffer-bound :sound drum)
+ − 42 ;; buffer-read-only error
+ − 43 (read-only :sound drum)
793
+ − 44 ;; any error other than those handled by undefined-key,
+ − 45 ;; undefined-click, buffer-bound, read-only
428
+ − 46 (command-error :sound bass)
+ − 47 (y-or-n-p :sound quiet)
+ − 48 (yes-or-no-p :sound quiet)
+ − 49 (auto-save-error :sound whip :volume 100)
+ − 50 (no-completion :sound whip)
+ − 51 (isearch-failed :sound quiet)
+ − 52 (isearch-quit :sound bass)
+ − 53 ;; QUIT: sound generated by ^G and its variants.
+ − 54 (quit :sound quiet :volume 75)
+ − 55 ;; READY: time-consuming task has completed... compile,
+ − 56 ;; cvs-update, etc.
+ − 57 (ready :sound cuckoo)
+ − 58 ;; WARP: XEmacs has changed the selected-window or frame
+ − 59 ;; asynchronously... Especially when it's done by an
+ − 60 ;; asynchronous process filter. Perhaps by a debugger breakpoint
+ − 61 ;; has been hit?
+ − 62 (warp :sound yeep :volume 75)
+ − 63 ;; ALARM: used for reminders...
+ − 64 (alarm :sound cuckoo :volume 100)
+ − 65 )
+ − 66 "The alist of sounds and associated error symbols.
+ − 67
+ − 68 Used to set sound-alist in load-default-sounds."
+ − 69 :group 'sound
+ − 70 :type '(repeat
+ − 71 (group (symbol :tag "Name")
+ − 72 (checklist :inline t
+ − 73 :greedy t
+ − 74 (group :inline t
+ − 75 (const :format "" :value :sound)
+ − 76 (symbol :tag "Sound"))
+ − 77 (group :inline t
+ − 78 (const :format "" :value :volume)
+ − 79 (integer :tag "Volume"))
+ − 80 (group :inline t
+ − 81 (const :format "" :value :pitch)
+ − 82 (integer :tag "Pitch"))
+ − 83 (group :inline t
+ − 84 (const :format "" :value :duration)
+ − 85 (integer :tag "Duration"))))))
+ − 86
+ − 87 (defcustom sound-load-list
+ − 88 '((load-sound-file "drum-beep" 'drum)
+ − 89 (load-sound-file "quiet-beep" 'quiet)
+ − 90 (load-sound-file "bass-snap" 'bass 80)
+ − 91 (load-sound-file "whip" 'whip 70)
+ − 92 (load-sound-file "cuckoo" 'cuckoo)
+ − 93 (load-sound-file "yeep" 'yeep)
+ − 94 (load-sound-file "hype" 'hype 100)
+ − 95 )
+ − 96 "A list of calls to load-sound-file to be processed by load-default-sounds.
+ − 97
+ − 98 Reference load-sound-file for more information."
+ − 99
+ − 100 :group 'sound
+ − 101 :type '(repeat (sexp :tag "Sound")
+ − 102 ))
+ − 103
+ − 104 (defcustom default-sound-directory (locate-data-directory "sounds")
+ − 105 "Default directory to load a sound file from."
+ − 106 :group 'sound
+ − 107 :type 'directory
+ − 108 )
+ − 109
+ − 110 ;; #### This should really be a list. --hniksic
458
+ − 111 (defcustom sound-extension-list (cond ((or (eq system-type 'cygwin32)
+ − 112 (eq system-type 'windows-nt))
+ − 113 ".wav:")
+ − 114 ((eq system-type 'linux)
+ − 115 ".wav:.au:")
+ − 116 (t
+ − 117 ".au:"))
428
+ − 118 "Filename extensions to complete sound file name with. If more than one
+ − 119 extension is used, they should be separated by \":\". "
+ − 120 :group 'sound
+ − 121 :type 'string)
+ − 122
+ − 123 (defcustom default-sound-directory-list (locate-data-directory-list "sounds")
+ − 124 "List of directories which to search for sound files"
+ − 125 :group 'sound
+ − 126 :type '(repeat directory )
+ − 127 )
+ − 128
+ − 129 ;;;###autoload
+ − 130 (or sound-alist
+ − 131 ;; these should be silent until sounds are loaded
+ − 132 (setq sound-alist '((ready nil) (warp nil))))
+ − 133
+ − 134 ;;;###autoload
+ − 135 (defun load-sound-file (filename sound-name &optional volume)
+ − 136 "Read in an audio-file and add it to the sound-alist.
+ − 137
458
+ − 138 FILENAME can either be absolute or relative, in which case the file will
+ − 139 be searched in the directories given by `default-sound-directory-list'.
+ − 140 When looking for the file, the extensions given by `sound-extension-list' are
+ − 141 also tried in the given order.
+ − 142
428
+ − 143 You can only play sound files if you are running on display 0 of the
+ − 144 console of a machine with native sound support or running a NetAudio
502
+ − 145 or ESD server and XEmacs has the necessary sound support compiled in.
428
+ − 146
502
+ − 147 The sound file must be in the Sun/NeXT U-LAW format, except on Linux
+ − 148 and MS Windows, where .wav files are also supported by the sound card
+ − 149 drivers."
428
+ − 150 (interactive "fSound file name: \n\
+ − 151 SSymbol to name this sound: \n\
+ − 152 nVolume (0 for default): ")
+ − 153 (unless (symbolp sound-name)
+ − 154 (error "sound-name not a symbol"))
+ − 155 (unless (or (null volume) (integerp volume))
+ − 156 (error "volume not an integer or nil"))
502
+ − 157 (let ((file
+ − 158 ;; For absolute file names, we don't have on choice on the
+ − 159 ;; location, but sound extensions however can still be tried
+ − 160 (locate-file filename
+ − 161 (if (file-name-absolute-p filename)
+ − 162 (list (file-name-directory filename))
+ − 163 default-sound-directory-list)
+ − 164 (split-string sound-extension-list ":")))
458
+ − 165 buf data)
428
+ − 166 (unless file
+ − 167 (error "Couldn't load sound file %s" filename))
+ − 168 (unwind-protect
+ − 169 (save-excursion
+ − 170 (set-buffer (setq buf (get-buffer-create " *sound-tmp*")))
+ − 171 (buffer-disable-undo (current-buffer))
+ − 172 (erase-buffer)
+ − 173 (let ((coding-system-for-read 'binary))
+ − 174 (insert-file-contents file))
+ − 175 (setq data (buffer-string))
+ − 176 (erase-buffer))
+ − 177 (and buf (kill-buffer buf)))
+ − 178 (let ((old (assq sound-name sound-alist)))
+ − 179 ;; some conses in sound-alist might have been dumped with emacs.
+ − 180 (if old (setq sound-alist (delq old (copy-sequence sound-alist)))))
+ − 181 (setq sound-alist (cons
444
+ − 182 (nconc (list sound-name)
+ − 183 (if (and volume (not (eq 0 volume)))
+ − 184 (list ':volume volume))
+ − 185 (list ':sound data))
+ − 186 sound-alist)))
428
+ − 187 sound-name)
+ − 188
+ − 189 ;;;###autoload
+ − 190 (defun load-default-sounds ()
+ − 191 "Load and install some sound files as beep-types, using
+ − 192 `load-sound-file'. This only works if you're on display 0 of the
+ − 193 console of a machine with native sound support or running a NetAudio
+ − 194 server and XEmacs has the necessary sound support compiled in."
+ − 195 (interactive)
+ − 196 ;; #### - this should do NOTHING if the sounds can't be played.
+ − 197 (message "Loading sounds...")
+ − 198 (setq sound-alist nil)
+ − 199 ;; this is where the calls to load-sound-file get done
+ − 200 (mapc 'eval sound-load-list)
+ − 201 (setq sound-alist
+ − 202 (append sound-default-alist
+ − 203 sound-alist))
+ − 204 (message "Loading sounds...done")
+ − 205 ;; (beep nil 'quiet)
+ − 206 )
+ − 207
+ − 208 ;;; sound.el ends here.