comparison src/midiEventHolder.cpp @ 5:195907bb8bb7

added purple where notes have been seen - lets you see what updates have been used. Also the chopping of midi files to the beginning was introduced recently, so when they load, you chop any white space at the beginning, then use first note to launch.
author Andrew N Robertson <andrew.robertson@eecs.qmul.ac.uk>
date Fri, 19 Aug 2011 16:38:30 +0100
parents 4a8e6a6cd224
children 6f5836d432ca
comparison
equal deleted inserted replaced
4:4a8e6a6cd224 5:195907bb8bb7
68 bayesStruct.posterior.offset = 0; 68 bayesStruct.posterior.offset = 0;
69 69
70 playedEventTimes.clear(); 70 playedEventTimes.clear();
71 playedNoteOnMatrix.clear(); 71 playedNoteOnMatrix.clear();
72 matchMatrix.clear(); 72 matchMatrix.clear();
73 bestMatchIndex = 0;
73 74
74 bayesStruct.resetSpeedToOne(); 75 bayesStruct.resetSpeedToOne();
75 bayesStruct.setSpeedPrior(speedPriorValue); 76 bayesStruct.setSpeedPrior(speedPriorValue);
76 77 setMatchedNotesBackToFalse();
78 }
79
80 void midiEventHolder::setMatchedNotesBackToFalse(){
81 for (int i = 0;i < noteOnMatches.size();i++)
82 noteOnMatches[i] = false;
77 } 83 }
78 84
79 void midiEventHolder::clearAllEvents(){ 85 void midiEventHolder::clearAllEvents(){
80 recordedNoteOnMatrix.clear(); 86 recordedNoteOnMatrix.clear();
81 matchesFound.clear(); 87 matchesFound.clear();
207 213
208 matchString = ""; 214 matchString = "";
209 215
210 windowStartTime = max(0.0,(bayesStruct.bestEstimate - matchWindowWidth/2));//was playPositionInMillis 216 windowStartTime = max(0.0,(bayesStruct.bestEstimate - matchWindowWidth/2));//was playPositionInMillis
211 int numberOfMatches = findMatch(notePitch, windowStartTime, windowStartTime + matchWindowWidth); 217 int numberOfMatches = findMatch(notePitch, windowStartTime, windowStartTime + matchWindowWidth);
218
212 219
213 matchString += " pitch: "+ofToString(notePitch)+" matches "+ofToString(numberOfMatches)+" win start "+ofToString(windowStartTime); 220 matchString += " pitch: "+ofToString(notePitch)+" matches "+ofToString(numberOfMatches)+" win start "+ofToString(windowStartTime);
214 221
215 return numberOfMatches; 222 return numberOfMatches;
216 223
250 while (startIndex < recordedEventTimes.size() && recordedEventTimes[startIndex] < startTime) 257 while (startIndex < recordedEventTimes.size() && recordedEventTimes[startIndex] < startTime)
251 startIndex++; 258 startIndex++;
252 259
253 } 260 }
254 261
255 262 double minimumConfidence = 0;
256 while (startIndex < recordedEventTimes.size() && recordedEventTimes[startIndex] < endTime){ 263 while (startIndex < recordedEventTimes.size() && recordedEventTimes[startIndex] < endTime){
257 if (recordedNoteOnMatrix[startIndex][1] == notePitch){ 264 if (recordedNoteOnMatrix[startIndex][1] == notePitch){
258 matchesFound.push_back(startIndex); 265 matchesFound.push_back(startIndex);
266 double eventConfidence = bayesStruct.posterior.getValueAtMillis(recordedEventTimes[startIndex]);
267 if (eventConfidence > minimumConfidence){
268 minimumConfidence = eventConfidence;
269 bestMatchIndex = startIndex;
270 }
271
259 double confidence = bayesStruct.posterior.getValueAtMillis(mouseX); 272 double confidence = bayesStruct.posterior.getValueAtMillis(mouseX);
260 // recordedEventTimes[startIndex]); 273 // recordedEventTimes[startIndex]);
261 matchString += "["+ofToString(startIndex)+"] = "+ofToString(confidence, 3)+" ."; 274 matchString += "["+ofToString(startIndex)+"] = "+ofToString(confidence, 3)+" .";
262 } 275 }
263 startIndex++; 276 startIndex++;
264 } 277 }
265 278
279
266 // printf("%i MATCHES TO Note %i found\n", (int)matchesFound.size(), notePitch); 280 // printf("%i MATCHES TO Note %i found\n", (int)matchesFound.size(), notePitch);
267 int size = matchesFound.size(); 281 int size = matchesFound.size();
268 282 if (size > 0)
283 noteOnMatches[bestMatchIndex] = true;
284
269 IntVector v; 285 IntVector v;
270 v.push_back(size); 286 v.push_back(size);
271 for (int i = 0;i < matchesFound.size();i++) 287 for (int i = 0;i < matchesFound.size();i++)
272 v.push_back(matchesFound[i]); 288 v.push_back(matchesFound[i]);
273 289
387 403
388 for (int tmpIndex = max(0,minNoteIndexToPrint);tmpIndex < min(maxNoteIndexToPrint, (int)recordedNoteOnMatrix.size());tmpIndex++){ 404 for (int tmpIndex = max(0,minNoteIndexToPrint);tmpIndex < min(maxNoteIndexToPrint, (int)recordedNoteOnMatrix.size());tmpIndex++){
389 405
390 if (checkIfMatchedNote(tmpIndex)) 406 if (checkIfMatchedNote(tmpIndex))
391 ofSetColor(0,0,255); 407 ofSetColor(0,0,255);
392 else 408 else if(noteOnMatches[tmpIndex]){
409 ofSetColor(255,0,255);
410 }else{
393 ofSetColor(255,255,255); 411 ofSetColor(255,255,255);
412 }
413
414
394 415
395 // XXX replace ofgetwidth below 416 // XXX replace ofgetwidth below
396 //if (tmpIndex >= 0 && tmpIndex < size) 417 //if (tmpIndex >= 0 && tmpIndex < size)
397 int xLocation = (float)(recordedNoteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen; 418 int xLocation = (float)(recordedNoteOnMatrix[tmpIndex][0] - numberOfScreensIn*ticksPerScreen)*(*screenWidth)/(float)ticksPerScreen;
398 int duration = (float)(recordedNoteOnMatrix[tmpIndex][3]*(*screenWidth))/(float)ticksPerScreen; 419 int duration = (float)(recordedNoteOnMatrix[tmpIndex][3]*(*screenWidth))/(float)ticksPerScreen;