diff --git a/plugins/lv2/sfizz.cpp b/plugins/lv2/sfizz.cpp index 8fc65ba9..ea7bbae5 100644 --- a/plugins/lv2/sfizz.cpp +++ b/plugins/lv2/sfizz.cpp @@ -899,6 +899,7 @@ sfizz_lv2_process_midi_event(sfizz_plugin_t *self, const LV2_Atom_Event *ev) (int)ev->time.frames, (int)cc, value); + self->cc_current[cc] = value; } break; case LV2_MIDI_CTL_ALL_NOTES_OFF: @@ -1682,7 +1683,6 @@ save(LV2_Handle instance, self->atom_int_uri, LV2_STATE_IS_POD); } - for (unsigned cc = 0; cc < sfz::config::numCCs; ++cc) { if (desc.ccUsed.test(cc) && !desc.sustainOrSostenuto.test(cc)) { LV2_URID urid = sfizz_lv2_ccmap_map(self->ccmap, int(cc)); diff --git a/plugins/vst/SfizzVstProcessor.cpp b/plugins/vst/SfizzVstProcessor.cpp index 115bf47f..dc7ab601 100644 --- a/plugins/vst/SfizzVstProcessor.cpp +++ b/plugins/vst/SfizzVstProcessor.cpp @@ -113,7 +113,7 @@ tresult PLUGIN_API SfizzVstProcessor::initialize(FUnknown* context) _synth->setBroadcastCallback(onMessage, this); _currentStretchedTuning = 0.0; - loadSfzFileOrDefault({}); + loadSfzFileOrDefault({}, false); _synth->bpmTempo(0, 120); _timeSigNumerator = 4; @@ -220,7 +220,7 @@ void SfizzVstProcessor::syncStateToSynth() if (!synth) return; - loadSfzFileOrDefault(_state.sfzFile); + loadSfzFileOrDefault(_state.sfzFile, true); synth->setVolume(_state.volume); synth->setNumVoices(_state.numVoices); synth->setOversamplingFactor(1 << _state.oversamplingLog2); @@ -602,7 +602,7 @@ tresult PLUGIN_API SfizzVstProcessor::notify(Vst::IMessage* message) std::unique_lock lock(_processMutex); _state.sfzFile.assign(static_cast(data), size); - loadSfzFileOrDefault(_state.sfzFile); + loadSfzFileOrDefault(_state.sfzFile, false); lock.unlock(); } else if (!std::strcmp(id, "LoadScala")) { @@ -717,7 +717,7 @@ void SfizzVstProcessor::receiveOSC(int delay, const char* path, const char* sig, } } -void SfizzVstProcessor::loadSfzFileOrDefault(const std::string& filePath) +void SfizzVstProcessor::loadSfzFileOrDefault(const std::string& filePath, bool initParametersFromState) { sfz::Sfizz& synth = *_synth; @@ -729,7 +729,6 @@ void SfizzVstProcessor::loadSfzFileOrDefault(const std::string& filePath) } const std::string descBlob = getDescriptionBlob(synth.handle()); - { std::vector> newControllers(sfz::config::numCCs); const std::vector> oldControllers = std::move(_state.controllers); @@ -739,6 +738,15 @@ void SfizzVstProcessor::loadSfzFileOrDefault(const std::string& filePath) if (desc.ccUsed.test(cc)) newControllers[cc] = desc.ccValue[cc]; } + // set CC from existing state + if (initParametersFromState) { + for (uint32 cc = 0; cc < sfz::config::numCCs; ++cc) { + if (absl::optional value = oldControllers[cc]) { + newControllers[cc] = *value; + synth.automateHdcc(0, int(cc), *value); + } + } + } _state.controllers = std::move(newControllers); } @@ -841,7 +849,7 @@ void SfizzVstProcessor::doBackgroundIdle(size_t idleCounter) if (_synth->shouldReloadFile()) { fprintf(stderr, "[Sfizz] sfz file has changed, reloading\n"); std::lock_guard lock(_processMutex); - loadSfzFileOrDefault(_state.sfzFile); + loadSfzFileOrDefault(_state.sfzFile, false); } if (_synth->shouldReloadScala()) { fprintf(stderr, "[Sfizz] scala file has changed, reloading\n"); diff --git a/plugins/vst/SfizzVstProcessor.h b/plugins/vst/SfizzVstProcessor.h index 63cfabe4..0f983036 100644 --- a/plugins/vst/SfizzVstProcessor.h +++ b/plugins/vst/SfizzVstProcessor.h @@ -86,7 +86,7 @@ private: void receiveOSC(int delay, const char* path, const char* sig, const sfizz_arg_t* args); // misc - void loadSfzFileOrDefault(const std::string& filePath); + void loadSfzFileOrDefault(const std::string& filePath, bool initParametersFromState); // note event tracking std::array _noteEventsCurrentCycle; // 0: off, >0: on, <0: no change