annotate www/martin/js/nodescore-slides.js @ 74:b7f9ade92165

added template for guitar version
author Rob Canning <rc@kiben.net>
date Sun, 29 Jun 2014 16:53:50 +0000
parents
children e4db7d4d1d08
rev   line source
rc@74 1 /////////////////////////////////////////////////
rc@74 2 // connect to websocket
rc@74 3
rc@74 4 var socket = io.connect();
rc@74 5
rc@74 6 function initPage() { socket.emit("initPage");
rc@74 7 console.log("init.client.log")
rc@74 8 }
rc@74 9
rc@74 10 //socket.on("metroPulse", metronomeTick);
rc@74 11 /////////////////////////////////////////////////
rc@74 12 socket.on("metroPulse", pulseInClient);
rc@74 13 function pulseInClient(pulse,groupID,metrobeat){
rc@74 14 var groupPage=document.getElementById('group').value
rc@74 15 if (groupID == groupPage) {
rc@74 16 metronomeTick(1000, groupID, metrobeat);
rc@74 17 }
rc@74 18 }
rc@74 19
rc@74 20 /////////////////////////////////////////////////
rc@74 21 function metroCss(beat, beatcolor,text){
rc@74 22 var color = beatcolor;
rc@74 23 $(".metrocase > div").each(function(){$(this).stop()});
rc@74 24 $(".metrocase > div").each(function(){$(this).css('background-color', beatcolor)});
rc@74 25 $(".metrocase > div").each(function(){$(this).text(" ")});
rc@74 26 }
rc@74 27
rc@74 28 function metronomeTick(pulse, voice,metrobeat) {
rc@74 29 var color = "gray"
rc@74 30 metroCss(0, "red", "4")
rc@74 31 setTimeout(function(){metroCss(0, "black", "4")},150);
rc@74 32 };
rc@74 33
rc@74 34 /////////////////////////////////////////////////
rc@74 35 // update the stopwatch value on the client page in line with server
rc@74 36 socket.on("chronFromServer", function(chron) { $("div#client_chronometer").text(chron); });
rc@74 37
rc@74 38 // server time
rc@74 39 socket.on("dateTime", function(datetime) {
rc@74 40 $("div#datetime").text("" +datetime);
rc@74 41 });
rc@74 42
rc@74 43 /////////////////////////////////////////////////
rc@74 44 // countdown to change
rc@74 45 socket.on("countinFromServer", countinClient);
rc@74 46 function countinClient(groupID, currentseconds,mm,text,colour,background,unit){
rc@74 47 var groupPage=document.getElementById('group').value
rc@74 48 if (groupID == groupPage) {
rc@74 49 $("#counttitle").css('color','white');
rc@74 50 $("#counttitle").text(text);
rc@74 51 $("#count").text(currentseconds);
rc@74 52 document.getElementById("count").style.color=colour;
rc@74 53 }}
rc@74 54
rc@74 55 /////////////////////////////////////////////////
rc@74 56 // countdown to change
rc@74 57 socket.on("counterText", cText);
rc@74 58 function cText(groupID, currentseconds,text){
rc@74 59 $("#totalcountdown"+groupID).text(text);
rc@74 60 var groupPage=document.getElementById('group').value
rc@74 61 if (groupID == groupPage) {
rc@74 62 //console.log(text)
rc@74 63 $("#totalcountdown").text(text);
rc@74 64 }}
rc@74 65
rc@74 66 ///////////////////////////////////////
rc@74 67 //function pageFlip(unit) { $('#sections').trigger('goto', [parseFloat(unit)]); }
rc@74 68
rc@74 69 /////////////////////////////////////////////////
rc@74 70 // call the fancy jquery functions
rc@74 71 function slideTo (target) { $('#sections').trigger('goto', [target]); }
rc@74 72 function pad2(number) { return (number < 10 ? '0' : '') + number }
rc@74 73
rc@74 74 /////////////////////////////////////////////////
rc@74 75 //var testSound = new buzz.sound( 'audio/testfile', { formats: [ 'ogg', 'mp3' ] } );
rc@74 76 socket.on("pageFlipfromserver", pageTurn);
rc@74 77 function pageTurn (group,unit,time,mm,seqcounter,nextunit) {
rc@74 78 var groupPage=document.getElementById('group').value;
rc@74 79 if (group == groupPage) {
rc@74 80 console.log(unit + " ---> " + nextunit)
rc@74 81 $("#live").load("music.html #"+unit);
rc@74 82 $("#preview").html("<h3 style='background:transparent; position: relative; font-size:1.5em;top:14px; left:10px;';> n e x t : </h3><img src='thumbs/"+ (nextunit) + ".png" + "' width='305'>")
rc@74 83 //$("#previewbox-"+group).html("<img src='svg/"+(unit) + ".svg" + "' width='515'>")
rc@74 84 }
rc@74 85 else {
rc@74 86 console.log("not for this group... ignoring... for group:" + group );
rc@74 87 }
rc@74 88 }
rc@74 89
rc@74 90 socket.on("pageIni", pageIni);
rc@74 91 function pageIni (group,unit,time,mm,seqcounter,nextunit) {
rc@74 92 console.log(unit + " ---> " + nextunit)
rc@74 93 //$("#live").load("music.html #"+unit);
rc@74 94 //$("#preview").html("<h3 style='background:transparent; position: relative; font-size:1.5em;top:14px; left:10px;';> n e x t : </h3><img src='thumbs/"+ (nextunit) + ".png" + "' width='305'>")
rc@74 95 $("#previewbox-"+group).html("<img src='svg/"+(unit) + ".svg" + "' width='515'>")
rc@74 96 }
rc@74 97
rc@74 98 ////////////////////////////////////////////////
rc@74 99
rc@74 100 /* commented out for now as interferes with chat
rc@74 101 need to introduce metakey...manyana... not so usefull anyway really...
rc@74 102
rc@74 103 keyboard controls
rc@74 104 +++++++++++++++++++++++++
rc@74 105
rc@74 106 SPACE to toggle visibilty of preview
rc@74 107 m to toggle visibilty of metronome
rc@74 108 s to toggle visibilty of stopwatch
rc@74 109 h to hide all above
rc@74 110
rc@74 111
rc@74 112 */
rc@74 113 function toggle_visibility(id) {
rc@74 114 var e = document.getElementById(id);
rc@74 115 if(e.style.display == 'block')
rc@74 116 e.style.display = 'none';
rc@74 117 else
rc@74 118 e.style.display = 'block';
rc@74 119 }
rc@74 120
rc@74 121 $(document).keypress(function(e){
rc@74 122 // "space bar" for next unit preview
rc@74 123 var checkWebkitandIE=(e.which==32 ? 1 : 0);
rc@74 124 var checkMoz=(e.which==32 ? 1 : 0);
rc@74 125 // "m" button for metronome
rc@74 126 var mcheckWebkitandIE=(e.which==109 ? 1 : 0);
rc@74 127 var mcheckMoz=(e.which==109 ? 1 : 0);
rc@74 128 // "s" button for stopwatch/chronometer
rc@74 129 var ccheckWebkitandIE=(e.which==115 ? 1 : 0);
rc@74 130 var ccheckMoz=(e.which==115 ? 1 : 0);
rc@74 131
rc@74 132 // "h" button for hideall
rc@74 133 var hcheckWebkitandIE=(e.which==104 ? 1 : 0);
rc@74 134 var hcheckMoz=(e.which==104 ? 1 : 0);
rc@74 135
rc@74 136 // console.log(e.which);
rc@74 137 // if (checkWebkitandIE || checkMoz) { toggle_visibility('preview') }
rc@74 138 // if (mcheckWebkitandIE || mcheckMoz) { toggle_visibility('comms') }
rc@74 139 // if (ccheckWebkitandIE || ccheckMoz) { toggle_visibility('client_chronometer') }
rc@74 140 if (hcheckWebkitandIE || hcheckMoz) {
rc@74 141 toggle_visibility('info')
rc@74 142 //toggle_visibility('comms')
rc@74 143 //toggle_visibility('preview')
rc@74 144 }
rc@74 145 });
rc@74 146
rc@74 147 //*/
rc@74 148
rc@74 149 ////////////////////////////////////////////////
rc@74 150 // this needs to have a variable to define the websocket
rc@74 151 // otherwise we will pings from all sockets connected
rc@74 152 // no! the server broadcasts the ping and the clients emit the pong!
rc@74 153 // ah but then the time reported back from the server needs to be targeted
rc@74 154 // to specific client..
rc@74 155 //////////////////////////////////////////////
rc@74 156 // Latency "Pong"
rc@74 157 socket.on("timeFromServer", function(n) {
rc@74 158 socket.emit("clientTimeResponse",n); });
rc@74 159
rc@74 160 socket.on("latencyFromServer", function(latency) {
rc@74 161 $("#client_latency").text("Latency: "+latency+"ms.")
rc@74 162
rc@74 163 });
rc@74 164
rc@74 165 function getLatencies(x) { socket.emit("getLatencies", x); }
rc@74 166
rc@74 167 //////////////////////////////////////////////
rc@74 168
rc@74 169
rc@74 170 socket.on('connect', function () {
rc@74 171 $('#chat').addClass('connected');
rc@74 172 });
rc@74 173
rc@74 174 socket.on('announcement', function (msg) {
rc@74 175 $('#lines').append($('<p>').append($('<em>').text(msg)));
rc@74 176 });
rc@74 177
rc@74 178 socket.on('nicknames', function (nicknames) {
rc@74 179 $('#nicknames').empty().append($('<span>Online: </span>'));
rc@74 180 for (var i in nicknames) {
rc@74 181 $('#nicknames').append($('<b>').text(nicknames[i]));
rc@74 182 }
rc@74 183 });
rc@74 184
rc@74 185 socket.on('user message', message);
rc@74 186 socket.on('reconnect', function () {
rc@74 187 $('#lines').remove();
rc@74 188 message('System', 'Reconnected to the server');
rc@74 189 });
rc@74 190
rc@74 191 socket.on('reconnecting', function () {
rc@74 192 message('System', 'Attempting to re-connect to the server');
rc@74 193 });
rc@74 194
rc@74 195 socket.on('error', function (e) {
rc@74 196 message('System', e ? e : 'A unknown error occurred');
rc@74 197 });
rc@74 198
rc@74 199 function message (from, msg) {
rc@74 200 $('#lines').prepend($('<p>').prepend($('<b>').text(from), msg));
rc@74 201 }
rc@74 202
rc@74 203 // dom manipulation
rc@74 204 $(function () {
rc@74 205 $('#set-nickname').submit(function (ev) {
rc@74 206 socket.emit('nickname', $('#nick').val(), function (set) {
rc@74 207 if (!set) {
rc@74 208 clear();
rc@74 209 return $('#chat').addClass('nickname-set');
rc@74 210 }
rc@74 211 $('#nickname-err').css('visibility', 'visible');
rc@74 212 });
rc@74 213 return false;
rc@74 214 });
rc@74 215
rc@74 216 $('#send-message').submit(function () {
rc@74 217 message('me', $('#message').val());
rc@74 218 socket.emit('user message', $('#message').val());
rc@74 219 clear();
rc@74 220 $('#lines').get(0).scrollTop = 10000000;
rc@74 221 return false;
rc@74 222 });
rc@74 223
rc@74 224 function clear () {
rc@74 225 $('#message').val('').focus();
rc@74 226 };
rc@74 227 });