I’m implementing a Markov chain music generator. Everything works fine in debug mode. However, if I open it from the terminal by typing “open MarkovMusic.app
” (I’m on Mac OS) the program crashes. I tried commenting out several parts of my program to narrow down the scope and it seems the error has something to do with my own “MidiPaser
” class in which I get the midi events and put them in some std containers:
void MainComponent::playButtonClicked() {
vector<std::pair<int, double>> noteSequence = midiParser.getNoteSequenceForTrack(audioFilePath, 3);
}
vector<pair<int, double>> MidiParser::getNoteSequenceForTrack(String path, int index) {
vector<pair<int, double>> resSequence; //!< midi pitch and note duration pair
vector<pair<MidiMessage, double>> noteOnSequence; //!< midi message and note duration pair
MidiFile localMidiFile;
File targetFile(path);
FileInputStream stream(targetFile);
localMidiFile.readFrom(stream);
localMidiFile.convertTimestampTicksToSeconds();
const MidiMessageSequence* sequence = localMidiFile.getTrack(index);
double duration = 0;
for (int i = 0; i < sequence->getNumEvents(); i++) {
if (sequence->getEventPointer(i)->message.isNoteOn()) {
duration = sequence->getTimeOfMatchingKeyUp(i) - sequence->getEventPointer(i)->message.getTimeStamp();
noteOnSequence.push_back(std::make_pair(MidiMessage (sequence->getEventPointer(i)->message), duration));
}
}
// other processing I commented out
return resSequence;
}
Although I hard code the index
parameter, since it works properly in debug mode, I guess the problem might not be caused by the invalid index value. Does the snippet here have any bug?