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