Skip to content

Commit cf1f1f8

Browse files
committed
Prevents vector access error with poorly formatted messages
1 parent ac6108a commit cf1f1f8

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/ofxAudioUnitManagerUtils.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ void ofxAudioUnitManagerUtils::setup() {
88
"C#5 ON", "C#5 OFF" etc */
99
void ofxAudioUnitManagerUtils::executeMidiCommand(string command, ofxMidiOut *midi) {
1010
vector<string> args = ofSplitString(command, " ");
11-
int parsedNote = midiNote(args.at(0));
12-
if(args.at(1) == "ON") {
13-
cout << "Sending MIDI ON: " << parsedNote << endl;
14-
midi->sendNoteOn(1, parsedNote);
15-
} else {
16-
cout << "Sending MIDI OFF: " << parsedNote << endl;
17-
midi->sendNoteOff(1, parsedNote);
11+
if(args.size() == 2) {
12+
int parsedNote = midiNote(args.at(0));
13+
if(args.at(1) == "ON") {
14+
cout << "Sending MIDI ON: " << parsedNote << endl;
15+
midi->sendNoteOn(1, parsedNote);
16+
} else {
17+
cout << "Sending MIDI OFF: " << parsedNote << endl;
18+
midi->sendNoteOff(1, parsedNote);
19+
}
1820
}
1921
}
2022

0 commit comments

Comments
 (0)