Support a ding sound per move. Off by default, of course.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 22 Nov 2014 01:28:47 +0000 (02:28 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 22 Nov 2014 01:28:47 +0000 (02:28 +0100)
www/ding.mp3 [new file with mode: 0644]
www/ding.opus [new file with mode: 0644]
www/index.html
www/js/remoteglot.js

diff --git a/www/ding.mp3 b/www/ding.mp3
new file mode 100644 (file)
index 0000000..a90cc84
Binary files /dev/null and b/www/ding.mp3 differ
diff --git a/www/ding.opus b/www/ding.opus
new file mode 100644 (file)
index 0000000..c1ee4e2
Binary files /dev/null and b/www/ding.opus differ
index c4e17b2..aece701 100644 (file)
   <meta name="viewport" content="width=device-width, initial-scale=1" />
 </head>
 <body>
+<audio id="ding" preload="none">
+  <source src="ding.opus" type="audio/ogg; codecs=opus" />
+  <source src="ding.mp3" type="audio/mp3" />
+</audio>
 <h1 id="headline">Analysis</h1>
 <div id="boardcontainer">
   <div id="board"></div>
   <p><strong>PV:</strong> <span id="pv"></span></p>
   <p id="searchstats"></p>
   <h3>History and potential moves (multi-PV)</h3>
-  <p id="sortbyscoreholder">Sort by: <span id="sortbyscore0"><a href="javascript:resort_refutation_lines(0)">Move</a></span>
+  <p id="sortbyscoreholder">
+    Sound:
+    <span id="soundon"><a href="javascript:set_sound(true)">On</a></span>
+    <span id="soundoff"><a href="javascript:set_sound(false)">Off</a></span>
+    |
+    Sort by:
+    <span id="sortbyscore0"><a href="javascript:resort_refutation_lines(0)">Move</a></span>
     <span id="sortbyscore1"><a href="javascript:resort_refutation_lines(1)">Score</a></span>
     |
     <span id="history">No history</span>
@@ -55,6 +65,7 @@
   Hosting and multi-PV analysis hardware by <a href="http://www.samfundet.no/">Studentersamfundet i Trondhjem</a>.
   JavaScript chessboard powered by <a href="http://chessboardjs.com/">chessboard.js</a>
   and <a href="https://github.com/jhlywa/chess.js">chess.js</a>.
+  Ding sound by <a href="https://www.freesound.org/people/Aiwha/sounds/196106/">Aiwa</a> (CC-BY-3.0).
   7-man Lomonosov tablebase lookup by <a href="http://tb7.chessok.com/">ChessOK</a>.</p>
 
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
index 1b6952d..cd2ffa5 100644 (file)
@@ -65,6 +65,9 @@ var highlighted_move = null;
 /** @type {?number} @private */
 var unique = null;
 
+/** @type {boolean} @private */
+var enable_sound = false;
+
 /** The current position on the board, represented as a FEN string.
  * @type {?string}
  * @private
@@ -121,6 +124,7 @@ var request_update = function() {
        }).done(function(data, textstatus, xhr) {
                ims = xhr.getResponseHeader('X-Remoteglot-Last-Modified');
                var num_viewers = xhr.getResponseHeader('X-Remoteglot-Num-Viewers');
+               possibly_play_sound(current_analysis_data, data);
                current_analysis_data = data;
                update_board(current_analysis_data, displayed_analysis_data);
                update_num_viewers(num_viewers);
@@ -133,6 +137,24 @@ var request_update = function() {
        });
 }
 
+var possibly_play_sound = function(old_data, new_data) {
+       if (!enable_sound) {
+               return;
+       }
+       if (old_data === null) {
+               return;
+       }
+       var ding = document.getElementById('ding');
+       if (ding && ding.play !== undefined) {
+               if (old_data['position'] && old_data['position']['fen'] &&
+                   new_data['position'] && new_data['position']['fen'] &&
+                   (old_data['position']['fen'] !== new_data['position']['fen'] ||
+                    old_data['position']['move_num'] !== new_data['position']['move_num'])) {
+                       ding.play();
+               }
+       }
+}
+
 var clear_arrows = function() {
        for (var i = 0; i < arrows.length; ++i) {
                if (arrows[i].svg) {
@@ -930,8 +952,24 @@ var update_displayed_line = function() {
        board.position(hiddenboard.fen());
 }
 
+/**
+ * @param {boolean} param_enable_sound
+ */
+var set_sound = function(param_enable_sound) {
+       enable_sound = param_enable_sound;
+       if (enable_sound) {
+               $("#soundon").html("<strong>On</strong>");
+               $("#soundoff").html("<a href=\"javascript:set_sound(false)\">Off</a>");
+       } else {
+               $("#soundon").html("<a href=\"javascript:set_sound(true)\">On</a>");
+               $("#soundoff").html("<strong>Off</strong>");
+       }
+}
+window['set_sound'] = set_sound;
+
 var init = function() {
        unique = get_unique();
+       set_sound(false);
 
        // Create board.
        board = new window.ChessBoard('board', 'start');