Add thread checker for the VST controller

This commit is contained in:
Jean Pierre Cimalando 2021-04-28 17:59:37 +02:00
parent eba974cfe1
commit 9023209dfd
2 changed files with 12 additions and 0 deletions

View file

@ -10,6 +10,7 @@
#include "SfizzVstIDs.h"
#include "base/source/fstreamer.h"
#include "base/source/updatehandler.h"
#include <atomic>
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();

View file

@ -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 <sfizz_message.h>
@ -44,6 +45,7 @@ public:
REFCOUNT_METHODS(Vst::EditController)
protected:
std::unique_ptr<Vst::ThreadChecker> threadChecker_;
Steinberg::IPtr<QueuedUpdates> queuedUpdates_;
Steinberg::IPtr<SfzUpdate> sfzUpdate_;
Steinberg::IPtr<SfzDescriptionUpdate> sfzDescriptionUpdate_;