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)
46 (funcall chess-sound-play-function
47 (expand-file-name (concat file ".wav")
48 chess-sound-directory))))
50 (defsubst chess-sound-play (file)
51 (apply 'call-process chess-sound-program
52 nil nil nil (append chess-sound-args (list file))))
54 (defun chess-sound-handler (game event &rest args)
56 ((eq event 'initialize)
57 (and (file-directory-p chess-sound-directory)
58 (file-readable-p (expand-file-name "move.wav"
59 chess-sound-directory))
60 (or (eq chess-sound-play-function 'play-sound-file)
61 (and chess-sound-program
62 (file-executable-p chess-sound-program)))))
65 (let* ((ply (chess-game-ply game (1- (chess-game-index game))))
66 (pos (chess-ply-pos ply)))
67 (if (eq (chess-game-data game 'my-color)
68 (chess-pos-side-to-move pos))
69 (if chess-sound-my-moves
71 (let* ((source (chess-ply-source ply))
72 (target (chess-ply-target ply))
73 (s-piece (and source (chess-pos-piece pos source)))
74 (t-piece (and target (chess-pos-piece pos target)))
75 (which (chess-ply-keyword ply :which))
78 ((chess-ply-keyword ply :castle)
80 ((chess-ply-keyword ply :long-castle)
81 (chess-sound "O-O-O"))
82 ((and s-piece t-piece (= t-piece ? ) target)
84 (chess-sound (char-to-string which)))
85 (chess-sound (format "%c_" (downcase s-piece)))
86 (chess-sound (chess-index-to-coord target)))
87 ((and s-piece t-piece target)
89 (chess-sound (char-to-string which)))
90 (chess-sound (format "%c_" (downcase s-piece)))
92 (chess-sound (format "%c_" (downcase t-piece)))
93 (chess-sound (chess-index-to-coord target))))
95 (if (chess-ply-keyword ply :promote)
97 (format "%c_" (downcase
98 (chess-ply-keyword ply :promote)))))
99 (if (chess-ply-keyword ply :en-passant)
100 (chess-sound "enpassant"))
101 (if (chess-ply-keyword ply :check)
103 (if (chess-ply-keyword ply :checkmate)
105 (if (chess-ply-keyword ply :stalemate)
106 (chess-sound "smate"))))))))
108 (provide 'chess-sound)
110 ;;; chess-sound.el ends here