diff hackday/testApp.cpp @ 30:be2e779d76b5

internote calculation added but not running. Better way of waiting for first note to happen before starting.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Wed, 07 Dec 2011 13:04:59 +0000
parents 69083ce48b83
children 9a70d9abdc8b
line wrap: on
line diff
--- a/hackday/testApp.cpp	Mon Dec 05 21:47:19 2011 +0000
+++ b/hackday/testApp.cpp	Wed Dec 07 13:04:59 2011 +0000
@@ -52,7 +52,7 @@
 	verdana30.setLetterSpacing(1.035);
 	
 	playing = false;
-
+	readyToStart = true;
 	
 	receiver.setup( PORT );
 
@@ -95,6 +95,11 @@
 			double time = m.getArgAsFloat(2);
 			
 			if (velocity != 0){
+				if (readyToStart){
+					startPlaying();
+					printf("starting to PLAY!!!");
+				}
+				
 				midiEvents.newNoteOnEvent(newMidiOnPitch, velocity, time);
 				noteInStream.newNoteCounted(newMidiOnPitch);
 			}
@@ -111,7 +116,7 @@
 		
 		if ( m.getAddress() == "/startplaying" )
 		{
-			startPlaying();
+			prepareToStartOnNextNote();
 		}
 		
 		if ( m.getAddress() == "/stopplaying" )
@@ -154,7 +159,7 @@
 		}
 		
 	}//end while osc
-
+	if (midiEvents.recordedEventTimes.size() > 0)
 	checkNewScoreNote();
 	
 }
@@ -198,10 +203,12 @@
 }
 
 void testApp::sendNoteToMuseScore(){
+	if (midiEvents.recordedNoteOnMatrix.size() > 0){
 	int ticks = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][0];
 	int pitch = midiEvents.recordedNoteOnMatrix[midiEvents.bestMatchIndex][1];
 	printf("sending to muse score %i, %i \n", ticks, pitch);
-		
+	sendNoteDataByOsc(pitch, ticks);
+	}
 	/*
 		ofxOscMessage m;
 		m.setAddress( "/plugin" );
@@ -210,7 +217,7 @@
 		m.addStringArg( noteString);
 		sender.sendMessage( m ); 
 	*/
-	sendNoteDataByOsc(pitch, ticks);
+
 	
 //	/color-note 60,3440
 	
@@ -333,10 +340,7 @@
 		midiPort--;
 		midiIn.openPort(midiPort);
 	}
-	
-//	if (key == ' '){
-//		startPlaying();
-//	}
+
 	if (key == '-')
 		transpose -= 12;
 	
@@ -378,6 +382,11 @@
 		sendBlackNotes();
 	}
 	
+	
+	if (key == 'n'){
+		midiEvents.printInterNoteIntervals();
+	}
+	
 	if (key == OF_KEY_DOWN){
 		if (midiEvents.ticksPerScreen >= 4000)
 		midiEvents.ticksPerScreen -= 2000;
@@ -397,7 +406,9 @@
 	}
 
 	if (key == 'l')
-		midiEvents.bayesStruct.decaySpeedDistribution(100);
+		
+		
+		//midiEvents.bayesStruct.decaySpeedDistribution(100);
 	
 	if (key == 't')
 		midiEvents.drawTempoMode = !midiEvents.drawTempoMode;
@@ -418,20 +429,24 @@
 	}
 	
 	if (key == 'o' || key == 'O'){
-		//open audio file
-		string *filePtr;
-		filePtr = &midiFileName;	
-		
-		if (getFilenameFromDialogBox(filePtr)){
-			printf("Midifile: Loaded name okay :\n'%s' \n", midiFileName.c_str());	
-			cannamMainFunction();
-		}
+		loadRecordedMidiFile();
 	}
 
 	
 	
 }
 
+void testApp::loadRecordedMidiFile(){
+	//open audio file
+	string *filePtr;
+	filePtr = &midiFileName;	
+	
+	if (getFilenameFromDialogBox(filePtr)){
+		printf("Midifile: Loaded name okay :\n'%s' \n", midiFileName.c_str());	
+		cannamMainFunction();
+	}
+}
+
 //--------------------------------------------------------------
 void testApp::keyReleased(int key){
 
@@ -465,6 +480,9 @@
 	
 }
 
+void testApp::prepareToStartOnNextNote(){
+	readyToStart = true;
+}
 
 
 void testApp::startPlaying(){
@@ -473,6 +491,7 @@
 	noteInStream.reset();
 	midiEvents.setStartPlayingTimes();
 	sendBlackNotes();
+	readyToStart = false;
 	//this is where we stop and start playing
 }