comparison nodescore.js @ 33:5088859ace72

Merge branch 'master' of git://gitorious.org/nodescore/nodescore Conflicts: nodescore www/m/thumbs/1.png www/m/thumbs/2.png www/m/thumbs/3.png www/m/thumbs/4.png www/m/thumbs/5.png www/m/thumbs/6.png
author tzara <rc-web@kiben.net>
date Sun, 19 Aug 2012 22:59:48 +0100
parents e4d2a8eb1450
children ea8d61c851c0
comparison
equal deleted inserted replaced
30:0123b4602f8e 33:5088859ace72
23 23
24 var clientFiles = new static.Server('./www'); 24 var clientFiles = new static.Server('./www');
25 var httpServer = http.createServer(function(request, response) { 25 var httpServer = http.createServer(function(request, response) {
26 request.addListener('end', function () { 26 request.addListener('end', function () {
27 clientFiles.serve(request, response); 27 clientFiles.serve(request, response);
28 process.setMaxListeners(0);
28 }); 29 });
29 }); 30 });
30 httpServer.listen(8889); 31 httpServer.listen(8889);
31 32
32 //////////////////////////////////////////// 33 ////////////////////////////////////////////
34 //////////////////////////////////////////// 35 ////////////////////////////////////////////
35 36
36 var io = sio.listen(httpServer) 37 var io = sio.listen(httpServer)
37 , nicknames = {}; 38 , nicknames = {};
38 39
39 io.set('log level', 2); // reduce loggingi 40 io.set('log level', 1); // reduce loggingi
40 io.sockets.on('connection', function (socket) { 41 io.sockets.on('connection', function (socket) {
41 42
42 //////////////////////////////////////////// 43 ////////////////////////////////////////////
43 // metronome 44 // metronome
44 //////////////////////////////////////////// 45 ////////////////////////////////////////////
81 ding = setInterval( function () { 82 ding = setInterval( function () {
82 var datetime= new Date(); 83 var datetime= new Date();
83 var now=datetime.toString() 84 var now=datetime.toString()
84 // console.log(now); 85 // console.log(now);
85 socket.broadcast.emit("dateTime", now); 86 socket.broadcast.emit("dateTime", now);
86 socket.emit("dateTime", now);}, 1000)} 87 // socket.emit("dateTime", now);
88 }, 1000)}
87 89
88 clearInterval(ding); 90 clearInterval(ding);
89 dateTime() 91 dateTime()
90 92
91 93
102 socket.emit('chronFromServer', chron) 104 socket.emit('chronFromServer', chron)
103 } 105 }
104 } 106 }
105 107
106 socket.on('startChr', function () { startChr();}); 108 socket.on('startChr', function () { startChr();});
107 socket.on('stopChr', function () { stopChr();}); 109 socket.on('stopChr', function () { stopChr();} );
108 socket.on('resetChr', function () { resetChr();}); 110 socket.on('resetChr', function () { resetChr();});
109 111
110 112
111 113
112 114
127 var seqB = { metrobeat:0, voice:2, name: "B", counter: 0, mm: 60, beatsinbar: 4, durations: srcsqr[1], units: [3,2,1,1,2,3]}; 129 var seqB = { metrobeat:0, voice:2, name: "B", counter: 0, mm: 60, beatsinbar: 4, durations: srcsqr[1], units: [3,2,1,1,2,3]};
128 var seqC = { metrobeat:0, voice:3, name: "C", counter: 0, mm: 60, beatsinbar: 4, durations: srcsqr[2], units: [4,5,6,5,4,2]}; 130 var seqC = { metrobeat:0, voice:3, name: "C", counter: 0, mm: 60, beatsinbar: 4, durations: srcsqr[2], units: [4,5,6,5,4,2]};
129 var seqD = { metrobeat:0, voice:4, name: "D", counter: 0, mm: 60, beatsinbar: 4, durations: srcsqr[3], units: [2,3,4,2,3,1]}; 131 var seqD = { metrobeat:0, voice:4, name: "D", counter: 0, mm: 60, beatsinbar: 4, durations: srcsqr[3], units: [2,3,4,2,3,1]};
130 132
131 133
132 countdowntick = function(seq){ 134 var countdowntick = function(seq){
133 135
134 var outcount = 12; var incount=12; 136 var outcount = 12; var incount=12;
135 var time = ((seq.durations[seq.counter]+1) *timemultiplier) + 30000 + (outcount*1000); 137 var time = ((seq.durations[seq.counter]+1) *timemultiplier) + 30000 + (outcount*1000);
136 var ztime = time; var totaltime = time/1000 138 var ztime = time; var totaltime = time/1000
137 var unit = seq.units[seq.counter]; 139 var unit = seq.units[seq.counter];
138 var tempoms = 60000/seq.mm 140 var tempoms = 60000/seq.mm
139 141
142 // initiate first page here
143 socket.broadcast.emit("pageFlipfromserver", seq.voice, unit, time, seq.mm,seq.counter);
144
140 var tock = setInterval(function(){ 145 var tock = setInterval(function(){
141 146
147
148
142 if (ztime >= 0 ){ 149 if (ztime >= 0 ){
150
143 // basic unit is still the second/1000ms - change this to tempoms? no i dont think so 151 // basic unit is still the second/1000ms - change this to tempoms? no i dont think so
144 // count in and count out 152 // count in and count out
145 //////////////////////////////////////////// 153 ////////////////////////////////////////////
146 154
147 var counter = ztime/1000 155 var counter = ztime/1000
152 } 160 }
153 161
154 // remove displayed number with " " at end of both countin/out 162 // remove displayed number with " " at end of both countin/out
155 163
156 if (counter == 0 ) { 164 if (counter == 0 ) {
165
157 socket.broadcast.emit('countinFromServer', seq.voice, " ", "","", "white","transparent"); 166 socket.broadcast.emit('countinFromServer', seq.voice, " ", "","", "white","transparent");
158 } 167 }
159 168
160 if (counter > (totaltime)-incount && counter <= totaltime ) { 169 if (counter > (totaltime)-incount && counter <= totaltime ) {
161 socket.broadcast.emit('countinFromServer', seq.voice, counter-(totaltime-incount), "","", "red","gray"); 170 socket.broadcast.emit('countinFromServer', seq.voice, counter-(totaltime-incount), "","", "red","gray");
185 } 194 }
186 195
187 if (ztime < 0){} 196 if (ztime < 0){}
188 // decrement the time 197 // decrement the time
189 ztime -= 1000 198 ztime -= 1000
190 199
191 }, tempoms) 200 }, tempoms)
192 201
193 202 };
194 // socket.on('stopSeq', function (seq) { 203
195 // console.log("stop") 204 // socket.on('stopSeq', function () {
196 // clearInterval(tock); 205 // console.log("sequencer stopping...")
197 // sequencerState=0; 206 // clearInterval(tock)
198 // stopChr(); 207 // sequencerState=0;
199 // }); 208 // stopChr();
200 }; 209 // var tock = function(){null}
201 210
202 step = function (seq) { 211 // });
203 clearInterval(countdowntick); 212
204 countdowntick(seq)
205 };
206
207 socket.on('startSeq', function () { 213 socket.on('startSeq', function () {
208 if (sequencerState == 0) { 214 if (sequencerState == 0) {
215 console.log("sequencer starting...")
209 sequencerState=1; 216 sequencerState=1;
210 startChr(); 217 startChr();
211 step(seqA); step(seqB); step(seqC); step(seqD); 218 step(seqA); step(seqB); step(seqC); step(seqD);
212 ztime =-1; 219 ztime =-1;
213 } 220 }
214 else console.log("already started...") 221 else console.log("sequencer already started...")
215 }); 222 });
216 223
217 224
225
226
227
218 socket.on('resetSeq', function () { 228 socket.on('resetSeq', function () {
219 console.log("rrrrreset") 229 console.log("reset")
220 resetChr(); 230 resetChr();
221
222 }); 231 });
223 232
233
234
235 step = function (seq) {
236 clearInterval(countdowntick);
237 countdowntick(seq)
238 };
224 239
225 240
226 //////////////////////////////////////////// 241 ////////////////////////////////////////////
227 // some latency calculations 242 // some latency calculations
228 /////////////////////////////////////////// 243 ///////////////////////////////////////////