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

View file

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