summaryrefslogtreecommitdiff
path: root/chess-sound.el
diff options
context:
space:
mode:
authordickmao <dick.r.chiang@gmail.com>2018-08-27 17:00:35 -0400
committerdickmao <dick.r.chiang@gmail.com>2018-09-06 09:24:10 -0400
commit3222b53d942daa404852e5148ba9d3ebb8fe96d0 (patch)
tree37e2af6242423e57adbbc1238433f58c92ac9bd0 /chess-sound.el
parent67339d896aa65d75272b80134a8128276c8c6a0f (diff)
Pre-moves
To activate, look for Chess Display Allow Pre Moves in: M-x customize-group chess-display Tested via: make test make test24 (requires evim)
Diffstat (limited to 'chess-sound.el')
-rw-r--r--chess-sound.el94
1 files changed, 50 insertions, 44 deletions
diff --git a/chess-sound.el b/chess-sound.el
index 8397c79..c4f7166 100644
--- a/chess-sound.el
+++ b/chess-sound.el
@@ -58,16 +58,22 @@
:type '(repeat string)
:group 'chess-sound)
-(defcustom chess-sound-my-moves nil
- "If non-nil, plays the move.wav sound whenever you make a move."
+(defcustom chess-sound-moves nil
+ "If non-nil, plays move.wav for each move."
+ :type 'boolean
+ :group 'chess-sound)
+
+(defcustom chess-sound-voiced-moves nil
+ "If non-nil, announces opponent's algebraic move."
:type 'boolean
:group 'chess-sound)
(defsubst chess-sound (file)
(ignore-errors
- (funcall chess-sound-play-function
- (expand-file-name (concat file ".wav")
- chess-sound-directory))))
+ (let ((wav (expand-file-name (concat file ".wav") chess-sound-directory)))
+ (if (file-readable-p wav)
+ (funcall chess-sound-play-function wav)
+ (ding)))))
(defsubst chess-sound-play (file)
(apply 'call-process chess-sound-program
@@ -86,45 +92,45 @@
((eq event 'move)
(let* ((ply (chess-game-ply game (1- (chess-game-index game))))
(pos (chess-ply-pos ply)))
- (if (eq (chess-game-data game 'my-color)
- (chess-pos-side-to-move pos))
- (if chess-sound-my-moves
- (chess-sound "move"))
- (let* ((source (chess-ply-source ply))
- (target (chess-ply-target ply))
- (s-piece (and source (chess-pos-piece pos source)))
- (t-piece (and target (chess-pos-piece pos target)))
- (which (chess-ply-keyword ply :which)))
- (cond
- ((chess-ply-keyword ply :castle)
- (chess-sound "O-O"))
- ((chess-ply-keyword ply :long-castle)
- (chess-sound "O-O-O"))
- ((and s-piece t-piece (= t-piece ? ) target)
- (if which
- (chess-sound (char-to-string which)))
- (chess-sound (format "%c_" (downcase s-piece)))
- (chess-sound (chess-index-to-coord target)))
- ((and s-piece t-piece target)
- (if which
- (chess-sound (char-to-string which)))
- (chess-sound (format "%c_" (downcase s-piece)))
- (chess-sound "x_")
- (chess-sound (format "%c_" (downcase t-piece)))
- (chess-sound (chess-index-to-coord target))))
-
- (if (chess-ply-keyword ply :promote)
- (chess-sound
- (format "%c_" (downcase
- (chess-ply-keyword ply :promote)))))
- (if (chess-ply-keyword ply :en-passant)
- (chess-sound "enpassant"))
- (if (chess-ply-keyword ply :check)
- (chess-sound "+_"))
- (if (chess-ply-keyword ply :checkmate)
- (chess-sound "#_"))
- (if (chess-ply-keyword ply :stalemate)
- (chess-sound "smate"))))))))
+ (if (and chess-sound-voiced-moves
+ (not (eq (chess-game-data game 'my-color)
+ (chess-pos-side-to-move pos))))
+ (let* ((source (chess-ply-source ply))
+ (target (chess-ply-target ply))
+ (s-piece (and source (chess-pos-piece pos source)))
+ (t-piece (and target (chess-pos-piece pos target)))
+ (which (chess-ply-keyword ply :which)))
+ (cond
+ ((chess-ply-keyword ply :castle)
+ (chess-sound "O-O"))
+ ((chess-ply-keyword ply :long-castle)
+ (chess-sound "O-O-O"))
+ ((and s-piece t-piece (= t-piece ? ) target)
+ (if which
+ (chess-sound (char-to-string which)))
+ (chess-sound (format "%c_" (downcase s-piece)))
+ (chess-sound (chess-index-to-coord target)))
+ ((and s-piece t-piece target)
+ (if which
+ (chess-sound (char-to-string which)))
+ (chess-sound (format "%c_" (downcase s-piece)))
+ (chess-sound "x_")
+ (chess-sound (format "%c_" (downcase t-piece)))
+ (chess-sound (chess-index-to-coord target))))
+
+ (if (chess-ply-keyword ply :promote)
+ (chess-sound
+ (format "%c_" (downcase
+ (chess-ply-keyword ply :promote)))))
+ (if (chess-ply-keyword ply :en-passant)
+ (chess-sound "enpassant"))
+ (if (chess-ply-keyword ply :check)
+ (chess-sound "+_"))
+ (if (chess-ply-keyword ply :checkmate)
+ (chess-sound "#_"))
+ (if (chess-ply-keyword ply :stalemate)
+ (chess-sound "smate")))
+ (if chess-sound-moves (chess-sound "move")))))))
(provide 'chess-sound)