diff --git a/src/CardinalUI.cpp b/src/CardinalUI.cpp index f2503a5..3952e83 100644 --- a/src/CardinalUI.cpp +++ b/src/CardinalUI.cpp @@ -69,9 +69,19 @@ class CardinalUI : public UI, WindowParametersRestore(context->window); } + ScopedContext(CardinalUI* const ui, const int mods) + : context(ui->fContext), + cml(context->plugin->contextMutex) + { + rack::contextSet(context); + rack::window::WindowMods(context->window, mods); + WindowParametersRestore(context->window); + } + ~ScopedContext() { - WindowParametersSave(context->window); + if (context->window != nullptr) + WindowParametersSave(context->window); rack::contextSet(nullptr); } }; @@ -321,9 +331,7 @@ protected: #endif */ - rack::window::WindowMods(fContext->window, mods); - - const ScopedContext sc(this); + const ScopedContext sc(this, mods); return fContext->event->handleButton(fLastMousePos, button, action, mods); } @@ -333,9 +341,8 @@ protected: const rack::math::Vec mouseDelta = mousePos.minus(fLastMousePos); fLastMousePos = mousePos; - rack::window::WindowMods(fContext->window, glfwMods(ev.mod)); - const ScopedContext sc(this); + const ScopedContext sc(this, glfwMods(ev.mod)); return fContext->event->handleHover(mousePos, mouseDelta); } @@ -348,9 +355,7 @@ protected: scrollDelta = scrollDelta.mult(50.0); #endif - rack::window::WindowMods(fContext->window, glfwMods(ev.mod)); - - const ScopedContext sc(this); + const ScopedContext sc(this, glfwMods(ev.mod)); return fContext->event->handleScroll(fLastMousePos, scrollDelta); } @@ -359,9 +364,7 @@ protected: if (ev.character <= ' ' || ev.character >= kKeyDelete) return false; - rack::window::WindowMods(fContext->window, glfwMods(ev.mod)); - - const ScopedContext sc(this); + const ScopedContext sc(this, glfwMods(ev.mod)); return fContext->event->handleText(fLastMousePos, ev.character); } @@ -438,7 +441,7 @@ protected: rack::window::WindowMods(fContext->window, mods); - const ScopedContext sc(this); + const ScopedContext sc(this, mods); return fContext->event->handleKey(fLastMousePos, key, ev.keycode, action, mods); } @@ -447,9 +450,7 @@ protected: if (focus) return; - rack::window::WindowMods(fContext->window, 0); - - const ScopedContext sc(this); + const ScopedContext sc(this, 0); fContext->event->handleLeave(); } diff --git a/src/PluginContext.hpp b/src/PluginContext.hpp index bcf3a46..bcbf6c2 100644 --- a/src/PluginContext.hpp +++ b/src/PluginContext.hpp @@ -114,7 +114,12 @@ struct CardinalAudioDriver : rack::audio::Driver { std::vector getDeviceIds() override { - return std::vector({ 1 }); + return std::vector({ 0 }); + } + + int getDefaultDeviceId() override + { + return 0; } std::string getDeviceName(int) override