1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; This is very similar to chess-announce, except it uses specific
4 ;; .WAV files instead of text-to-speech.
9 (defgroup chess-sound nil
10 "Code to play specific sounds when announcing chess moves."
13 (defcustom chess-sound-directory
14 (expand-file-name "sounds"
16 (or load-file-name buffer-file-name)))
17 "The directory where chess sounds can be found."
21 (defcustom chess-sound-play-function (if (fboundp 'play-sound-file)
24 "Non-nil if chess-sound should play sounds ."
28 (defcustom chess-sound-program (or (executable-find "esdplay")
29 (executable-find "play"))
30 "Program used to play sounds, if `play-sound-file' does not exist."
34 (defcustom chess-sound-args nil
35 "Additional args to pass to `chess-sound-program', before the .WAV file."
36 :type '(repeat string)
39 (defcustom chess-sound-my-moves nil
40 "If non-nil, plays the move.wav sound whenever you make a move."
44 (defsubst chess-sound (file)
45 (funcall chess-sound-play-function
46 (expand-file-name (concat file ".wav")
47 chess-sound-directory)))
49 (defsubst chess-sound-play (file)
50 (apply 'call-process chess-sound-program
51 nil nil nil (append chess-sound-args (list file))))
53 (defun chess-sound-handler (game event &rest args)
55 ((eq event 'initialize)
56 (and (file-directory-p chess-sound-directory)
57 (file-readable-p (expand-file-name "move.wav"
58 chess-sound-directory))
59 (or (eq chess-sound-play-function 'play-sound-file)
60 (and chess-sound-program
61 (file-executable-p chess-sound-program)))))
64 (let* ((ply (chess-game-ply game (1- (chess-game-index game))))
65 (pos (chess-ply-pos ply)))
66 (if (eq (chess-game-data game 'my-color)
67 (chess-pos-side-to-move pos))
68 (if chess-sound-my-moves
70 (let* ((source (chess-ply-source ply))
71 (target (chess-ply-target ply))
72 (s-piece (and source (chess-pos-piece pos source)))
73 (t-piece (and target (chess-pos-piece pos target)))
74 (which (chess-ply-keyword ply :which))
77 ((chess-ply-keyword ply :castle)
79 ((chess-ply-keyword ply :long-castle)
80 (chess-sound "O-O-O"))
81 ((and s-piece t-piece (= t-piece ? ) target)
83 (chess-sound (char-to-string which)))
84 (chess-sound (format "%c_" (downcase s-piece)))
85 (chess-sound (chess-index-to-coord target)))
86 ((and s-piece t-piece target)
88 (chess-sound (char-to-string which)))
89 (chess-sound (format "%c_" (downcase s-piece)))
91 (chess-sound (format "%c_" (downcase t-piece)))
92 (chess-sound (chess-index-to-coord target))))
94 (if (chess-ply-keyword ply :promote)
96 (format "%c_" (downcase
97 (chess-ply-keyword ply :promote)))))
98 (if (chess-ply-keyword ply :en-passant)
99 (chess-sound "enpassant"))
100 (if (chess-ply-keyword ply :check)
102 (if (chess-ply-keyword ply :checkmate)
104 (if (chess-ply-keyword ply :stalemate)
105 (chess-sound "smate"))))))))
107 (provide 'chess-sound)
109 ;;; chess-sound.el ends here