1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; This is very similar to chess-announce, except it uses specific
4 ;; .WAV files instead of text-to-speech.
10 (defgroup chess-sound nil
11 "Code to play specific sounds when announcing chess moves."
14 (defcustom chess-sound-directory
15 (expand-file-name "sounds"
17 (or load-file-name buffer-file-name)))
18 "The directory where chess sounds can be found."
22 (defcustom chess-sound-play-function (if (fboundp 'play-sound-file)
25 "Non-nil if chess-sound should play sounds ."
29 (defcustom chess-sound-program (or (executable-find "esdplay")
30 (executable-find "play"))
31 "Program used to play sounds, if `play-sound-file' does not exist."
35 (defcustom chess-sound-args nil
36 "Additional args to pass to `chess-sound-program', before the .WAV file."
37 :type '(repeat string)
40 (defun chess-sound-for-game (game)
41 "Announce the opponent's moves in GAME."
42 (if (and (file-directory-p chess-sound-directory)
43 (file-exists-p (expand-file-name "tap.wav"
44 chess-sound-directory)))
45 (chess-game-add-hook game 'chess-sound-event-handler)))
47 (defun chess-sound (ch)
52 ((memq ch '(?\# ?\+ ?k ?q ?b ?n ?r ?p ?x))
53 (format "%c_.wav" ch))
55 (format "%s.wav" (chess-index-to-coord ch))))))
56 (funcall chess-sound-play-function
57 (expand-file-name file chess-sound-directory))))
59 (defun chess-sound-play (file)
60 (apply 'call-process chess-sound-program
61 nil nil nil chess-sound-args))
63 (defun chess-sound-event-handler (game ignore event &rest args)
64 "This display module presents a standard chessboard.
65 See `chess-display-type' for the different kinds of displays."
67 ((memq event '(move game-over))
68 (let* ((ply (chess-game-ply game (1- (chess-game-index game))))
69 (pos (chess-ply-pos ply)))
70 (if (eq (chess-game-data game 'my-color)
71 (chess-pos-side-to-move pos))
73 (let* ((source (chess-ply-source ply))
74 (target (chess-ply-target ply))
75 (s-piece (chess-pos-piece pos source))
76 (t-piece (chess-pos-piece pos target))
79 ((memq :castle changes)
81 ((memq :long-castle changes)
82 (chess-sound "O-O-O"))
84 (chess-sound (downcase s-piece))
87 (chess-sound (downcase s-piece))
89 (chess-sound (downcase t-piece))
90 (chess-sound target)))
91 (if (memq :check changes)
93 (if (memq :checkmate changes)
95 (if (memq :stalemate changes)
96 (chess-sound "smate")))))
99 (provide 'chess-sound)
101 ;;; chess-sound.el ends here