diff nodescore.js @ 70:753414e075a0

danger stash pop
author tzara <rc-web@kiben.net>
date Sat, 26 Oct 2013 13:43:08 +0000
parents 333afcfd3f3a
children 9af4250ff7d5
line wrap: on
line diff
--- a/nodescore.js	Sat Oct 26 14:12:50 2013 +0100
+++ b/nodescore.js	Sat Oct 26 13:43:08 2013 +0000
@@ -22,7 +22,6 @@
     //are loaded relative to the top-level JS file.
     nodeRequire: require,
     findNestedDependencies: true
-
 });
 
 // run webserver serving static html
@@ -71,35 +70,30 @@
 	    io.sockets.emit('nicknames', nicknames);
 	}
     });  
-
+    
     /// chat user messages to screens and to log file
     // date format for filename
-
     var da = new Date(); var dtstring = da.getFullYear()+ '-' + da.getMonth()+ '-' + da.getDate();
-
     ////////////////////////
     /// log messages to file
     socket.on('user message', function (msg) {
 	fs.open('logs/chatlog-'+dtstring+'.txt', 'a', 666, function( e, id ) {	
 	    //time format for message stamp
 	    var dt = new Date();var timestring = dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
-	    
-	    socket.broadcast.emit('user message', socket.nickname, msg);
-	    
+	    socket.broadcast.emit('user message', socket.nickname, msg);	    
 	    var fs = require('fs'), str = msg;
 	    fs.write( id, timestring+" " + socket.nickname + ": "+ msg+"\n", null, 'utf8', function(){});
 	});	
     });
-  
-//  /*
+
     ////////////////////////////////////////////
     // chronometer + sequencer controls (all this should be modularised)
     ////////////////////////////////////////////
 
     socket.on('stopWatch', function (state) { stopWatch(state);});
-    socket.on('stopChr', function () { stopChr();});    
+    socket.on('stopChr', function () { stopChr();  });    
     socket.on('resetChr', function () { resetChr();});
-    socket.on('startSeq', function () { startChr();});  
+    socket.on('startSeq', function () { startChr(); });  
     var chronstate=0;
 
     // send the date/time every second
@@ -109,84 +103,45 @@
 	socket.broadcast.emit('dateTime', d)
 	socket.emit('dateTime', d)	
     }, 1000)
+              
+    //////////////////////////////
+    //    /* this should be moved to its own file chronometer.js
     
+    function chronCtrl (state,interval){
+	if (state==1){ console.log("chronControl....onestate")
+		       var date = new Date(); var starttime = new Date().getTime() / 1000;
+		       xstopwatch =  setInterval(function () {
+			   var nowtime = new Date().getTime() / 1000;
+			   now = nowtime-starttime
+			   hours = parseInt( now / 3600 ) % 24;
+			   minutes = parseInt( now / 60 ) % 60;
+			   seconds = parseInt(now  % 60);
+			   milliseconds = Math.floor((now-seconds)*10)%60;
+			   time = 
+			       (hours < 10 ? "0" + hours : hours) + ":" + 
+			       (minutes < 10 ? "0" + minutes : minutes) + ":" + 
+			       (seconds  < 10 ? "0" + seconds : seconds) + "."+ 
+			       milliseconds;
+			   socket.broadcast.emit('chronFromServer', time)
+			   socket.emit('chronFromServer', time)
+		       }, 100)
+		     }
+	
+	if (state==0) { console.log("chronControl....zerostate") ; clearInterval(xstopwatch); }	
+   
+    }
+
+
+    // if not already started start the chronometer and sequencer    
+    function startChr(socket) { chronCtrl(1,100); step(seqA);step(seqB); step(seqC); step(seqD); }
+    // stop the chronometer   
+    function stopChr() { console.log("stop chron"); chronCtrl(0); }  
     
-    // if not already started start the chronometer and sequencer    
-    function startChr(socket) { if (chronstate !== 1) { 
-	chronstate = 1; 
-	chronCtrl(1,100);
-	step(seqA);step(seqB); step(seqC); step(seqD);	    
-    } 
-			      }
-     
-    // if not already started start the chronometer    
-    function stopWatch(state) { if (chronstate !== 1) {
-	if (state==1){
-	    chronstate = 1; 
-	    chronCtrl(1,100);}
-    }
-				
-				// if get 0 then stop the chron
-				if (state==0){
-				    chronstate = 0; 
-				    clearInterval(xstopwatch);
-				}
-				// if get 2 then reset the chron
-				if (state==2){
-				    chronstate = 0; 
-				    c=ch.zeroChron()
-				    socket.broadcast.emit('chronFromServer', c)
-				    socket.emit('chronFromServer', c)
-				}
-			      } 
-
-
-//////////////////////////////
-//    /* this should be moved to its own file chronometer.js
-
-    function chronCtrl (state,interval){
-	console.log("=========================== chronstate=" + chronstate)
-	if (state==1){
-	    var date = new Date()
-	    var starttime = new Date().getTime() / 1000;
-	    //var interval = 1020 - date.getMilliseconds();
-	    xstopwatch =  setInterval(function () {
-		var nowtime = new Date().getTime() / 1000;
-		now = nowtime-starttime
-		hours = parseInt( now / 3600 ) % 24;
-		minutes = parseInt( now / 60 ) % 60;
-		seconds = parseInt(now  % 60);
-		milliseconds = Math.floor((now-seconds)*10)%60;
-		time = 
-		    (hours < 10 ? "0" + hours : hours) + ":" + 
-		    (minutes < 10 ? "0" + minutes : minutes) + ":" + 
-		    (seconds  < 10 ? "0" + seconds : seconds) + "."+ 
-		    milliseconds;
-		socket.broadcast.emit('chronFromServer', time)
-		socket.emit('chronFromServer', time)
-	    }, 100)
-    }
-	if (state==0) {
-	    clearInterval(xstopwatch);
-	     }	
-    }
-//*/
-
-    // stop the chronometer   
-
-    function stopChr() {console.log("stop chron................................................")
-			chronCtrl(0)
-			chronstate=0
-		       }  
-
     function pad(number) { return (number < 10 ? '0' : '') + number }
     function resetChr() {//clearInterval();
-	chronstate = 0;
-	zecsec = 0; seconds = 0; 
-	mins = 0; hours = 0; 
-	chronstate = 0; 
+	zecsec = 0; seconds = 0; mins = 0; hours = 0; 
 	var chron = pad(hours) +":"+pad(mins)+ ':'+ pad(seconds)+ ":"+ zecsec
-	// send 0.0.0 values to display
+	// send 0.00.00 values to display
 	socket.broadcast.emit('chronFromServer', chron)
 	socket.emit('chronFromServer', chron)
     }
@@ -196,7 +151,7 @@
     ////////////////////////////////////////////
     // all the variables this sequencer needs are in scoreB.js
     requirejs(['scoreB'],function(scoreB) {});
-
+    
     var sequencerState=0;
     var numberoftransects=3
     var order=8
@@ -211,36 +166,26 @@
 	var time = dur;
 	var ztime=time; 
 	var totaltime=time
+	initPage=function(seq){
+	    // initiate first page here
+	    socket.emit("pageIni", voice, unit, time, seq.mm,seq.counter,seq.nextunit );
+	    socket.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,seq.nextunit );
+	}
 
-	if (seq.counter == 7){ seq.nexttransect=seq.transect+1 ; 
-			       seq.nextunit=seq.units[seq.nexttransect%numberoftransects][seq.counter];
-			     }
-	 else
-	     seq.nextunit=seq.units[seq.transect%numberoftransects][seq.counter+1];
-
-	 // initiate first page here
-	socket.broadcast.emit("pageFlipfromserver", 
-			      voice, unit, time, 
-			      seq.mm,seq.counter,seq.nextunit );
-	socket.emit("pageFlipfromserver", 
-		    voice, unit, time, 
-		    seq.mm,seq.counter,seq.nextunit );
-	 
 	function sequenCer() {
-	    if (ztime >= 0 ){
+	    if (ztime >= 0 ){	
 		var counter = ztime
-	    // flip the page 
-	    if (counter == 0){	
-		//increment the row position
-		seq.counter = (seq.counter + 1) % (order)	    				
-		//increment the transect
-		if ( seq.counter==0 ){ seq.transect += 1 }
-		socket.broadcast.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,seq.nextunit);
-
-		clearInterval(pulse)
-		step(seq);     
-	    }
-
+		// flip the page 
+		if (counter == 0){	
+		    //increment the row position
+		    seq.counter = (seq.counter + 1) % (order)	    				
+		    //increment the transect
+		    if ( seq.counter==0 ){ seq.transect += 1 }
+		    socket.broadcast.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,seq.nextunit);
+		    clearInterval(pulse)
+		    step(seq);     
+		}
+		
 		if (counter >= 0 ){
 		    socket.broadcast.emit('counterText', 
 					  voice, unit, counter,seq.counter,unitlast,seq.transect%numberoftransects);
@@ -282,8 +227,6 @@
 		socket.emit('metroPulse', tempoms, voice, seq.metrobeat);
 	    }
 	    
-
-
 	    // decrement the time 
 	    ztime -= 1
 
@@ -294,21 +237,21 @@
 	var pulse = setInterval(sequenCer, tempoms);
 	
 	socket.on('stopSeq', function () {
-	    //donaldduck = mickeymouse + 7
 	    sequenCer.clearInterval
 	    console.log("sequencer stopping...")	    
 	    // grrr why wont this clearInterval work
 	    sequencerState = 0
 	    clearInterval(pulse)
-	    stopChr();
+	    sequenCer.clearInterval(pulse)
+	    stopChr();	    
 	});
     };
     
     step = function (seq) {
-	
 	clearInterval(countdowntick);
 	countdowntick(seq)
 	sequencerState=1;
+	initPage(seq)
     };
     
     socket.on('resetSeq', function () { resetChr(); });
@@ -356,14 +299,7 @@
 	socket.emit("latencyFromServer", latency);
     });	      
     
-    // this is the trigger from the control client to start the process
-    // maybe remove this and have latency connections constantly running
-    
-    /*
-      socket.on("getLatencies", function(x){
-      serverTime(x);
-      });
-    */
+
     
     serverTime(1000);
     
@@ -378,10 +314,7 @@
 	socket.broadcast.emit('nicknames', nicknames);
     });
 
+});
 
-});
-//});
-//exports.io = io;
-//exports.sio = sio;
 exports.socket= io.sockets;
 exports.httpServer = httpServer;