diff --git a/include/midi.hpp b/include/midi.hpp index 7d113b42..f53c2bce 100644 --- a/include/midi.hpp +++ b/include/midi.hpp @@ -102,6 +102,7 @@ struct MidiIO { struct MidiInput : MidiIO { + MidiInput(); ~MidiInput(); std::vector getDeviceIds() override; diff --git a/src/midi.cpp b/src/midi.cpp index 93864b8d..6f0afbee 100644 --- a/src/midi.cpp +++ b/src/midi.cpp @@ -118,6 +118,12 @@ void MidiIO::fromJson(json_t *rootJ) { // MidiInput //////////////////// +MidiInput::MidiInput() { + if (driverIds.size() >= 1) { + setDriverId(driverIds[0]); + } +} + MidiInput::~MidiInput() { setDriverId(-1); } @@ -138,8 +144,8 @@ std::string MidiInput::getDeviceName(int deviceId) { void MidiInput::setDeviceId(int deviceId) { // Destroy device - if (driver && deviceId >= 0) { - driver->unsubscribeInputDevice(deviceId, this); + if (driver && this->deviceId >= 0) { + driver->unsubscribeInputDevice(this->deviceId, this); } this->deviceId = -1; diff --git a/src/rtmidi.cpp b/src/rtmidi.cpp index 2d385aa0..d0c65d71 100644 --- a/src/rtmidi.cpp +++ b/src/rtmidi.cpp @@ -27,6 +27,7 @@ RtMidiInputDevice::RtMidiInputDevice(int driverId, int deviceId) { assert(rtMidiIn); rtMidiIn->ignoreTypes(false, false, false); rtMidiIn->setCallback(midiInputCallback, this); + rtMidiIn->openPort(deviceId, "VCV Rack input"); } RtMidiInputDevice::~RtMidiInputDevice() {