Keep path and description updated separately

This commit is contained in:
Jean Pierre Cimalando 2021-04-02 17:43:15 +02:00
parent 5fbb499d9b
commit 0d8deb1fb9
4 changed files with 34 additions and 5 deletions

View file

@ -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<FObject*> 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)

View file

@ -48,6 +48,7 @@ protected:
Steinberg::IPtr<OSCUpdate> oscUpdate_;
Steinberg::IPtr<NoteUpdate> noteUpdate_;
Steinberg::IPtr<SfzUpdate> sfzUpdate_;
Steinberg::IPtr<SfzDescriptionUpdate> sfzDescriptionUpdate_;
Steinberg::IPtr<ScalaUpdate> scalaUpdate_;
Steinberg::IPtr<ProcessorStateUpdate> processorStateUpdate_;
Steinberg::IPtr<PlayStateUpdate> playStateUpdate_;

View file

@ -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<SfzDescriptionUpdate>(changedUnknown)) {
const InstrumentDescription desc = parseDescriptionBlob(update->getDescription());
// TODO(jpc) instrument description
}
if (ScalaUpdate* update = FCast<ScalaUpdate>(changedUnknown)) {
const std::string path = update->getPath();
uiReceiveValue(EditId::ScalaFile, path);

View file

@ -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<std::mutex> 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<std::mutex> lock(mutex_);
description_ = std::move(newDescription);
}
std::string getDescription() const
{
std::lock_guard<std::mutex> lock(mutex_);
return description_;
}
OBJ_METHODS(SfzUpdate, FObject)
OBJ_METHODS(SfzDescriptionUpdate, FObject)
private:
std::string path_;
std::string description_;
mutable std::mutex mutex_;
};