prevent exception in MIDI in/out from crashing

This commit is contained in:
tildearrow 2022-07-24 02:45:21 -05:00
parent 9a0609ae1a
commit 1d77719640
1 changed files with 32 additions and 17 deletions

View File

@ -46,6 +46,7 @@ String sanitizePortName(const String& name) {
bool TAMidiInRtMidi::gather() {
std::vector<unsigned char> msg;
if (port==NULL) return false;
try {
while (true) {
TAMidiMessage m;
double t=port->getMessage(&msg);
@ -64,6 +65,10 @@ bool TAMidiInRtMidi::gather() {
}
queue.push(m);
}
} catch (RtMidiError& e) {
logE("MIDI input error! %s",e.what());
return false;
}
return true;
}
@ -180,7 +185,12 @@ bool TAMidiOutRtMidi::send(const TAMidiMessage& what) {
return false;
}
len=what.sysExLen;
try {
port->sendMessage(what.sysExData.get(),len);
} catch (RtMidiError& e) {
logE("MIDI output error! %s",e.what());
return false;
}
return true;
break;
case TA_MIDI_MTC_FRAME:
@ -194,7 +204,12 @@ bool TAMidiOutRtMidi::send(const TAMidiMessage& what) {
len=1;
break;
}
try {
port->sendMessage((const unsigned char*)&what.type,len);
} catch (RtMidiError& e) {
logE("MIDI output error! %s",e.what());
return false;
}
return true;
}