From bd2dda58e0eb8ada9a680e7f3b8aaa3d62a0b5ee Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 18 May 2018 18:18:09 -0400 Subject: [PATCH] Clean up temporary code, properly handle unsubscribing from rtmidi device --- src/main.cpp | 4 ---- src/rtmidi.cpp | 12 +++++++----- src/window.cpp | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dade5432..5d5aa2d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,10 +18,6 @@ using namespace rack; int main(int argc, char* argv[]) { randomInit(); loggerInit(); - debug("Hello world!"); - info("Hello world!"); - warn("Hello world!"); - fatal("Hello world!"); info("Rack %s", gApplicationVersion.c_str()); diff --git a/src/rtmidi.cpp b/src/rtmidi.cpp index 6feaaa05..21eb13eb 100644 --- a/src/rtmidi.cpp +++ b/src/rtmidi.cpp @@ -77,6 +77,8 @@ std::string RtMidiDriver::getInputDeviceName(int deviceId) { } MidiInputDevice *RtMidiDriver::subscribeInputDevice(int deviceId, MidiInput *midiInput) { + if (!(0 <= deviceId && deviceId < (int) rtMidiIn->getPortCount())) + return NULL; RtMidiInputDevice *device = devices[deviceId]; if (!device) { devices[deviceId] = device = new RtMidiInputDevice(driverId, deviceId); @@ -87,14 +89,14 @@ MidiInputDevice *RtMidiDriver::subscribeInputDevice(int deviceId, MidiInput *mid } void RtMidiDriver::unsubscribeInputDevice(int deviceId, MidiInput *midiInput) { - RtMidiInputDevice *device = devices[deviceId]; - assert(device); + auto it = devices.find(deviceId); + if (it == devices.end()) + return; + RtMidiInputDevice *device = it->second; device->unsubscribe(midiInput); - // Destroy device if nothing else is subscribed + // Destroy device if nothing is subscribed anymore if (device->subscribed.empty()) { - auto it = devices.find(deviceId); - assert(it != devices.end()); devices.erase(it); delete device; } diff --git a/src/window.cpp b/src/window.cpp index 337d5c37..26c3ba35 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -264,7 +264,7 @@ void charCallback(GLFWwindow *window, unsigned int codepoint) { void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods) { // Keyboard MIDI driver - if (1 || glfwGetInputMode(gWindow, GLFW_LOCK_KEY_MODS) & GLFW_MOD_CAPS_LOCK) { + if (glfwGetInputMode(gWindow, GLFW_LOCK_KEY_MODS) & GLFW_MOD_CAPS_LOCK) { if (action == GLFW_PRESS) { keyboardPress(key); }