From 0d8deb1fb911b26522799abc8b5803954ecdc2b9 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Fri, 2 Apr 2021 17:43:15 +0200 Subject: [PATCH] Keep path and description updated separately --- plugins/vst/SfizzVstController.cpp | 8 +++++++- plugins/vst/SfizzVstController.h | 1 + plugins/vst/SfizzVstEditor.cpp | 6 ++++++ plugins/vst/SfizzVstUpdates.h | 24 ++++++++++++++++++++---- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/plugins/vst/SfizzVstController.cpp b/plugins/vst/SfizzVstController.cpp index e695e6ba..de2f1c32 100644 --- a/plugins/vst/SfizzVstController.cpp +++ b/plugins/vst/SfizzVstController.cpp @@ -23,6 +23,7 @@ tresult PLUGIN_API SfizzVstControllerNoUi::initialize(FUnknown* context) oscUpdate_ = Steinberg::owned(new OSCUpdate); noteUpdate_ = Steinberg::owned(new NoteUpdate); sfzUpdate_ = Steinberg::owned(new SfzUpdate); + sfzDescriptionUpdate_ = Steinberg::owned(new SfzDescriptionUpdate); scalaUpdate_ = Steinberg::owned(new ScalaUpdate); processorStateUpdate_ = Steinberg::owned(new ProcessorStateUpdate); playStateUpdate_ = Steinberg::owned(new PlayStateUpdate); @@ -211,6 +212,8 @@ tresult PLUGIN_API SfizzVstControllerNoUi::setComponentState(IBStream* stream) setParam(kPidTuningFrequency, s.tuningFrequency); setParam(kPidStretchedTuning, s.stretchedTuning); + sfzUpdate_->setPath(s.sfzFile); + sfzUpdate_->deferUpdate(); scalaUpdate_->setPath(s.scalaFile); scalaUpdate_->deferUpdate(); @@ -254,8 +257,10 @@ tresult SfizzVstControllerNoUi::notify(Vst::IMessage* message) processorStateUpdate_->access([sfzFile](SfizzVstState& state) { state.sfzFile = std::string(sfzFile); }); - sfzUpdate_->setPath(std::string(sfzFile), std::string(sfzDescriptionBlob)); + sfzUpdate_->setPath(std::string(sfzFile)); sfzUpdate_->deferUpdate(); + sfzDescriptionUpdate_->setDescription(std::string(sfzDescriptionBlob)); + sfzDescriptionUpdate_->deferUpdate(); } else if (!strcmp(id, "LoadedScala")) { absl::string_view scalaFile; @@ -325,6 +330,7 @@ IPlugView* PLUGIN_API SfizzVstController::createView(FIDString _name) std::vector continuousUpdates; continuousUpdates.push_back(sfzUpdate_); + continuousUpdates.push_back(sfzDescriptionUpdate_); continuousUpdates.push_back(scalaUpdate_); continuousUpdates.push_back(playStateUpdate_); for (uint32 i = 0, n = parameters.getParameterCount(); i < n; ++i) diff --git a/plugins/vst/SfizzVstController.h b/plugins/vst/SfizzVstController.h index 4d4192df..7ea01f60 100644 --- a/plugins/vst/SfizzVstController.h +++ b/plugins/vst/SfizzVstController.h @@ -48,6 +48,7 @@ protected: Steinberg::IPtr oscUpdate_; Steinberg::IPtr noteUpdate_; Steinberg::IPtr sfzUpdate_; + Steinberg::IPtr sfzDescriptionUpdate_; Steinberg::IPtr scalaUpdate_; Steinberg::IPtr processorStateUpdate_; Steinberg::IPtr playStateUpdate_; diff --git a/plugins/vst/SfizzVstEditor.cpp b/plugins/vst/SfizzVstEditor.cpp index c9c83b47..dea3d3e6 100644 --- a/plugins/vst/SfizzVstEditor.cpp +++ b/plugins/vst/SfizzVstEditor.cpp @@ -11,6 +11,7 @@ #include "SfizzFileScan.h" #include "editor/Editor.h" #include "editor/EditIds.h" +#include "plugin/InstrumentDescription.h" #include "IdleUpdateHandler.h" #if !defined(__APPLE__) && !defined(_WIN32) #include "X11RunLoop.h" @@ -193,6 +194,11 @@ void PLUGIN_API SfizzVstEditor::update(FUnknown* changedUnknown, int32 message) uiReceiveValue(EditId::SfzFile, path); } + if (SfzDescriptionUpdate* update = FCast(changedUnknown)) { + const InstrumentDescription desc = parseDescriptionBlob(update->getDescription()); + // TODO(jpc) instrument description + } + if (ScalaUpdate* update = FCast(changedUnknown)) { const std::string path = update->getPath(); uiReceiveValue(EditId::ScalaFile, path); diff --git a/plugins/vst/SfizzVstUpdates.h b/plugins/vst/SfizzVstUpdates.h index 716ff6e5..3d0ce944 100644 --- a/plugins/vst/SfizzVstUpdates.h +++ b/plugins/vst/SfizzVstUpdates.h @@ -71,11 +71,10 @@ private: */ class SfzUpdate : public Steinberg::FObject { public: - void setPath(std::string newPath, std::string newDescription) + void setPath(std::string newPath) { std::lock_guard lock(mutex_); path_ = std::move(newPath); - description_ = std::move(newDescription); } std::string getPath() const @@ -84,16 +83,33 @@ public: return path_; } + OBJ_METHODS(SfzUpdate, FObject) + +private: + std::string path_; + mutable std::mutex mutex_; +}; + +/** + * @brief Update which notifies a change of SFZ description. + */ +class SfzDescriptionUpdate : public Steinberg::FObject { +public: + void setDescription(std::string newDescription) + { + std::lock_guard lock(mutex_); + description_ = std::move(newDescription); + } + std::string getDescription() const { std::lock_guard lock(mutex_); return description_; } - OBJ_METHODS(SfzUpdate, FObject) + OBJ_METHODS(SfzDescriptionUpdate, FObject) private: - std::string path_; std::string description_; mutable std::mutex mutex_; };