ofMidiWork issue

Hi there,

I’m using rtMidi and the midi player located here: http://www.openframeworks.cc/files/ofMidiWork-2.zip

I’ve found a problem when updating the whole player [line 218 function update]. You keep the length of your vector so you can go all through it but once a note is dead you just delete it but do not update the counters so at the end it tries to get to an invalid vector position.

  
void midiPlayer::update(){  
  
	int nNotes = notes.size();  
	  
	for (int i = 0; i < nNotes; i++){  
		int id = notes[i].idNumber;	  
		if (notes[i].bHasDuration){  
			float endTime = notes[i].startTime + notes[i].duration;  
			  
			if (ofGetElapsedTimef() > endTime){  
				noteOff(id);  
			}	  
		}  
	}  
}  

I just fixed this by adding 2 lines so you recheck the ‘i’ position [which will be the next to the one you already checked] and decrease the amount not to don’t get out of bounds.

  
  
void midiPlayer::update(){  
  
	int nNotes = notes.size();  
	  
	for (int i = 0; i < nNotes; i++){  
		int id = notes[i].idNumber;	  
		if (notes[i].bHasDuration){  
			float endTime = notes[i].startTime + notes[i].duration;  
			  
			if (ofGetElapsedTimef() > endTime){  
				noteOff(id);  
				nNotes--;  
				i--;  
			}	  
		}  
	}  
}  

Cheers