More efficient (and safer?)

This commit is contained in:
Jean Pierre Cimalando 2021-02-04 08:29:57 +01:00
parent 35e9240540
commit 96d4eca1ae
2 changed files with 43 additions and 39 deletions

View file

@ -151,10 +151,8 @@ tresult PLUGIN_API SfizzVstControllerNoUi::setParamNormalized(Vst::ParamID tag,
if (r != kResultTrue) if (r != kResultTrue)
return r; return r;
SfizzVstState state = processorStateUpdate_->getState(); processorStateUpdate_->access([tag, normValue](SfizzVstState& state) {
const SfizzRange range = SfizzRange::getForParameter(tag); const SfizzRange range = SfizzRange::getForParameter(tag);
switch (tag) { switch (tag) {
case kPidVolume: case kPidVolume:
state.volume = range.denormalize(normValue); state.volume = range.denormalize(normValue);
@ -178,8 +176,7 @@ tresult PLUGIN_API SfizzVstControllerNoUi::setParamNormalized(Vst::ParamID tag,
state.stretchedTuning = range.denormalize(normValue); state.stretchedTuning = range.denormalize(normValue);
break; break;
} }
});
processorStateUpdate_->setState(state);
return kResultTrue; return kResultTrue;
} }
@ -229,11 +226,11 @@ tresult SfizzVstControllerNoUi::notify(Vst::IMessage* message)
if (result != kResultTrue) if (result != kResultTrue)
return result; return result;
SfizzVstState state = processorStateUpdate_->getState(); std::string sfzFile(static_cast<const char *>(data), size);
state.sfzFile.assign(static_cast<const char *>(data), size); processorStateUpdate_->access([&sfzFile](SfizzVstState& state) {
processorStateUpdate_->setState(state); state.sfzFile = sfzFile;
});
sfzPathUpdate_->setPath(state.sfzFile); sfzPathUpdate_->setPath(std::move(sfzFile));
sfzPathUpdate_->deferUpdate(); sfzPathUpdate_->deferUpdate();
} }
else if (!strcmp(id, "LoadedScala")) { else if (!strcmp(id, "LoadedScala")) {
@ -244,11 +241,11 @@ tresult SfizzVstControllerNoUi::notify(Vst::IMessage* message)
if (result != kResultTrue) if (result != kResultTrue)
return result; return result;
SfizzVstState state = processorStateUpdate_->getState(); std::string scalaFile(static_cast<const char *>(data), size);
state.scalaFile.assign(static_cast<const char *>(data), size); processorStateUpdate_->access([&scalaFile](SfizzVstState& state) {
processorStateUpdate_->setState(state); state.scalaFile = scalaFile;
});
scalaPathUpdate_->setPath(state.scalaFile); scalaPathUpdate_->setPath(std::move(scalaFile));
scalaPathUpdate_->deferUpdate(); scalaPathUpdate_->deferUpdate();
} }
else if (!strcmp(id, "NotifiedPlayState")) { else if (!strcmp(id, "NotifiedPlayState")) {

View file

@ -97,6 +97,13 @@ public:
return state_; return state_;
} }
template <class F>
void access(F&& fn)
{
std::lock_guard<std::mutex> lock(mutex_);
fn(state_);
}
OBJ_METHODS(ProcessorStateUpdate, FObject) OBJ_METHODS(ProcessorStateUpdate, FObject)
private: private: