From 9023209dfd6973f08588a1963d383eefde385afc Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Wed, 28 Apr 2021 17:59:37 +0200 Subject: [PATCH] Add thread checker for the VST controller --- plugins/vst/SfizzVstController.cpp | 10 ++++++++++ plugins/vst/SfizzVstController.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/plugins/vst/SfizzVstController.cpp b/plugins/vst/SfizzVstController.cpp index eb658137..9f7b9246 100644 --- a/plugins/vst/SfizzVstController.cpp +++ b/plugins/vst/SfizzVstController.cpp @@ -10,6 +10,7 @@ #include "SfizzVstIDs.h" #include "base/source/fstreamer.h" #include "base/source/updatehandler.h" +#include tresult PLUGIN_API SfizzVstControllerNoUi::initialize(FUnknown* context) { @@ -20,6 +21,9 @@ tresult PLUGIN_API SfizzVstControllerNoUi::initialize(FUnknown* context) // initialize the update handler Steinberg::UpdateHandler::instance(); + // initialize the thread checker + threadChecker_ = Vst::ThreadChecker::create(); + // create update objects queuedUpdates_ = Steinberg::owned(new QueuedUpdates); sfzUpdate_ = Steinberg::owned(new SfzUpdate); @@ -228,6 +232,12 @@ tresult SfizzVstControllerNoUi::notify(Vst::IMessage* message) if (result != kResultFalse) return result; + if (!threadChecker_->test()) { + static std::atomic_bool warn_once_flag { false }; + if (!warn_once_flag.exchange(true)) + fprintf(stderr, "[sfizz] controller notification arrives from the wrong thread\n"); + } + const char* id = message->getMessageID(); Vst::IAttributeList* attr = message->getAttributes(); diff --git a/plugins/vst/SfizzVstController.h b/plugins/vst/SfizzVstController.h index db52179f..153bcd85 100644 --- a/plugins/vst/SfizzVstController.h +++ b/plugins/vst/SfizzVstController.h @@ -9,6 +9,7 @@ #include "SfizzVstUpdates.h" #include "public.sdk/source/vst/vsteditcontroller.h" #include "public.sdk/source/vst/vstparameters.h" +#include "public.sdk/source/common/threadchecker.h" #include "pluginterfaces/vst/ivstmidicontrollers.h" #include "vstgui/plugin-bindings/vst3editor.h" #include @@ -44,6 +45,7 @@ public: REFCOUNT_METHODS(Vst::EditController) protected: + std::unique_ptr threadChecker_; Steinberg::IPtr queuedUpdates_; Steinberg::IPtr sfzUpdate_; Steinberg::IPtr sfzDescriptionUpdate_;