void rtmidi_close_port (RtMidiPtr device) { #if defined(__NO_EXCEPTIONS__) RtMidi* rtm = (RtMidi*) device->ptr; rtm->resetError(); rtm->closePort (); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); } #else try { ((RtMidi*) device->ptr)->closePort (); } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); } #endif }
void rtmidi_open_port (RtMidiPtr device, unsigned int portNumber, const char *portName) { std::string name = portName; #if defined(__NO_EXCEPTIONS__) RtMidi* rtm = (RtMidi*) device->ptr; rtm->resetError(); rtm->openPort (portNumber, name); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); } #else try { ((RtMidi*) device->ptr)->openPort (portNumber, name); } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); } #endif }
unsigned int rtmidi_get_port_count (RtMidiPtr device) { #if defined(__NO_EXCEPTIONS__) RtMidi* rtm = (RtMidi*) device->ptr; rtm->resetError(); unsigned int ports = rtm->getPortCount(); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); return -1; } return ports; #else try { return ((RtMidi*) device->ptr)->getPortCount (); } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); return -1; } #endif }
const char* rtmidi_get_port_name (RtMidiPtr device, unsigned int portNumber) { #if defined(__NO_EXCEPTIONS__) RtMidi* rtm = (RtMidi*) device->ptr; rtm->resetError(); std::string name = rtm->getPortName (portNumber); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); return ""; } return strdup (name.c_str ()); #else try { std::string name = ((RtMidi*) device->ptr)->getPortName (portNumber); return strdup (name.c_str ()); } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); return ""; } #endif }