diff nodescore.js @ 91:1a706a2880ee

reset bug fixed but still todo unit transect to 0 reset
author Rob Canning <rob@foo.net>
date Thu, 31 Jul 2014 00:16:27 +0100
parents f214909fb108
children 6889df0494a4
line wrap: on
line diff
--- a/nodescore.js	Wed Jul 30 10:44:14 2014 +0100
+++ b/nodescore.js	Thu Jul 31 00:16:27 2014 +0100
@@ -80,7 +80,7 @@
 
 //var sequencer = require('./sequencer')
 
-io.set('log level', 4); // reduce logging
+//io.set('log level', 4); // reduce logging
 io.sockets.on('connection', function (socket) {
 
     socket.on('nickname', function (nick, fn) {
@@ -113,10 +113,27 @@
     // chronometer + sequencer controls (all this should be modularised)
     ////////////////////////////////////////////
 
+    sstate=0;
     socket.on('stopWatch', function (state) { stopWatch(state);});
-    socket.on('stopChr', function () { stopChr();  });    
-    socket.on('resetChr', function () { resetChr();});
-    socket.on('startSeq', function () { startChr(); });  
+    socket.on('stopChr',  function () { 
+	//sstate=0;  
+	stopChr(); 
+
+    });    
+   
+    socket.on('resetChr', function () { 
+	//reset currently just restarts current unit
+	//todo: make a total reset that sets unit and transect to 0
+	resetChr();  
+    });
+   
+    socket.on('startSeq', function () { 
+	//if( sstate==0 ){ 
+	    startChr();  
+	  //  sstate=1;
+	//}
+    });  
+    
     var chronstate=0;
 
     // send the date/time every second
@@ -207,15 +224,6 @@
 	    //socket.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,nextunit );
 	}
 
-	socket.on('resetSeq', function (seq) { 
-	    //var unit=seq.units[seq.transect%numberoftransects][seq.counter];
-	    //resetChr(); 
-	    //socket.emit("pageIni", 1, unit, 0, 60, 0,1 )
-	    //socket.emit("pageIni", 2, 1, 0, 60, 0,1 );
-	    //socket.emit("pageIni", 3, 1, 0, 60, 0,1 );
-	    //socket.emit("pageIni", 4, 1, 0, 60, 0,1 );
-	    console.log("reset message recieved from client");
-	});
 
 	function sequenCer() {
 	    if (ztime >= 0 ){	
@@ -266,16 +274,18 @@
 				    "","playing.. ", "green","transparent",unit);
 		    }
 		}
+		
 		// on each beat do:		
 		// push out the pulse to metronome	
+		
 		seq.metrobeat = (seq.metrobeat+1)%seq.beatsinbar ;
-     		socket.broadcast.emit('metroPulse', tempoms, voice,seq.metrobeat); 
+     		socket.broadcast.emit('metroPulse', tempoms, voice, seq.metrobeat); 
 		socket.emit('metroPulse', tempoms, voice, seq.metrobeat);
-	    	console.log("sdfasfdasdfasdfasf");
-		//socket.emit("pageFlipfromserver", voice, unit, time, seq.mm,seq.counter,nextunit);
+	
 		var nextunit=seq.units[seq.transect%numberoftransects][seq.counter+1];
 	    	socket.broadcast.emit("pageIni", voice, unit, time, seq.mm,seq.counter,nextunit );
 	    }
+
 	    // decrement the time 
 	    ztime -= 1
 	    // this shows undefined counter output - bug related	    
@@ -284,16 +294,21 @@
 	
 	var pulse = setInterval(sequenCer, tempoms);
 	
-
-
-
 	socket.on('stopSeq', function () {
 	    sequenCer.clearInterval
 	    console.log("sequencer stopping...")	    
+	    
 	    // grrr why wont this clearInterval work
+	    
 	    sequencerState = 0
 	    clearInterval(pulse)
-	    sequenCer.clearInterval(pulse)
+
+	    // the below breaks things but maybe this is for the best
+	    // without breakage and nodejs supervisor restart then too many instances
+	    // mount up and slow thinks down until crash
+	    //sequenCer.clearInterval(pulse)
+	    
+
 	    stopChr();	    
 	});
     };
@@ -306,13 +321,13 @@
     };
     
     socket.on('resetSeq', function () { 
+	// start stop reset in sucession to setup page easy never mind the below
 	//var unit=seq.units[seq.transect%numberoftransects][seq.counter];
 	resetChr(); 
 	//socket.emit("pageIni", 1, unit, 0, 60, 0,1 )
 	//socket.emit("pageIni", 2, 1, 0, 60, 0,1 );
 	//socket.emit("pageIni", 3, 1, 0, 60, 0,1 );
 	//socket.emit("pageIni", 4, 1, 0, 60, 0,1 );
-	console.log("reset message recieved from client");
     });
 
     ////////////////////////////////////////////  
@@ -358,8 +373,6 @@
 	socket.emit("latencyFromServer", latency);
     });	      
     
-
-    
     serverTime(1000);
     
     socket.on('disconnect', function(client) {