Beispiel #1
0
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
}
Beispiel #2
0
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
}
Beispiel #3
0
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
}
Beispiel #4
0
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
}