void rtmidi_in_cancel_callback (RtMidiInPtr device) { #if defined(__NO_EXCEPTIONS__) RtMidiIn* rtm = (RtMidiIn*) device->ptr; rtm->resetError(); rtm->cancelCallback (); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); } else { delete (CallbackProxyUserData*) device->data; device->data = 0; } #else try { ((RtMidiIn*) device->ptr)->cancelCallback (); delete (CallbackProxyUserData*) device->data; device->data = 0; } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); } #endif }
double rtmidi_in_get_message (RtMidiInPtr device, unsigned char *message, size_t *size) { #if defined(__NO_EXCEPTIONS__) // FIXME: use allocator to achieve efficient buffering std::vector<unsigned char> v; RtMidiIn* rtm = (RtMidiIn*) device->ptr; rtm->resetError(); double ret = rtm->getMessage (&v); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); return -1; } if (v.size () > 0 && v.size() <= *size) { memcpy (message, v.data (), (int) v.size ()); } *size = v.size(); return ret; #else try { // FIXME: use allocator to achieve efficient buffering std::vector<unsigned char> v; double ret = ((RtMidiIn*) device->ptr)->getMessage (&v); if (v.size () > 0 && v.size() <= *size) { memcpy (message, v.data (), (int) v.size ()); } *size = v.size(); return ret; } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); return -1; } catch (...) { device->ok = false; device->msg = "Unknown error"; return -1; } #endif }
RtMidiInPtr rtmidi_in_create (enum RtMidiApi api, const char *clientName, unsigned int queueSizeLimit) { std::string name = clientName; RtMidiWrapper* wrp = new RtMidiWrapper; #if defined(__NO_EXCEPTIONS__) RtMidiIn* rIn = new RtMidiIn ((RtMidi::Api) api, name, queueSizeLimit); if (rIn->isError()) { wrp->ptr = 0; wrp->data = 0; wrp->ok = false; wrp->msg = rIn->getError().what (); } else { wrp->ptr = (void*) rIn; wrp->data = 0; wrp->ok = true; wrp->msg = ""; } #else try { RtMidiIn* rIn = new RtMidiIn ((RtMidi::Api) api, name, queueSizeLimit); wrp->ptr = (void*) rIn; wrp->data = 0; wrp->ok = true; wrp->msg = ""; } catch (const RtMidiError & err) { wrp->ptr = 0; wrp->data = 0; wrp->ok = false; wrp->msg = err.what (); } #endif return wrp; }
/* RtMidiIn API */ RtMidiInPtr rtmidi_in_create_default () { RtMidiWrapper* wrp = new RtMidiWrapper; #if defined(__NO_EXCEPTIONS__) RtMidiIn* rIn = new RtMidiIn (); if (rIn->isError()) { wrp->ptr = 0; wrp->data = 0; wrp->ok = false; wrp->msg = rIn->getError().what (); } else { wrp->ptr = (void*) rIn; wrp->data = 0; wrp->ok = true; wrp->msg = ""; } #else try { RtMidiIn* rIn = new RtMidiIn (); wrp->ptr = (void*) rIn; wrp->data = 0; wrp->ok = true; wrp->msg = ""; } catch (const RtMidiError & err) { wrp->ptr = 0; wrp->data = 0; wrp->ok = false; wrp->msg = err.what (); } #endif return wrp; }
void rtmidi_in_set_callback (RtMidiInPtr device, RtMidiCCallback callback, void *userData) { device->data = (void*) new CallbackProxyUserData (callback, userData); #if defined(__NO_EXCEPTIONS__) RtMidiIn* rtm = (RtMidiIn*) device->ptr; rtm->resetError(); rtm->setCallback (callback_proxy, device->data); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); delete (CallbackProxyUserData*) device->data; device->data = 0; } #else try { ((RtMidiIn*) device->ptr)->setCallback (callback_proxy, device->data); } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); delete (CallbackProxyUserData*) device->data; device->data = 0; } #endif }
enum RtMidiApi rtmidi_in_get_current_api (RtMidiPtr device) { #if defined(__NO_EXCEPTIONS__) RtMidiIn* rtm = (RtMidiIn*) device->ptr; rtm->resetError(); RtMidiApi curApi = (RtMidiApi) rtm->getCurrentApi (); if (rtm->isError()) { device->ok = false; device->msg = rtm->getError().what (); return RT_MIDI_API_UNSPECIFIED; } return curApi; #else try { return (RtMidiApi) ((RtMidiIn*) device->ptr)->getCurrentApi (); } catch (const RtMidiError & err) { device->ok = false; device->msg = err.what (); return RT_MIDI_API_UNSPECIFIED; } #endif }