From 5e40e31c83a86a91a670f0da4ad1ed690b520326 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Sun, 15 Mar 2020 10:56:22 +0100 Subject: [PATCH] Only set the sample rate, per block, and the worker in setEnable; don't recreate the synth --- vst/SfizzVstProcessor.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/vst/SfizzVstProcessor.cpp b/vst/SfizzVstProcessor.cpp index 62d6b785..ea87680f 100644 --- a/vst/SfizzVstProcessor.cpp +++ b/vst/SfizzVstProcessor.cpp @@ -46,6 +46,13 @@ tresult PLUGIN_API SfizzVstProcessor::initialize(FUnknown* context) _state = SfizzVstState(); + fprintf(stderr, "[sfizz] new synth\n"); + _synth.reset(new sfz::Sfizz); + if (!_synth) { + fprintf(stderr, "[sfizz] Could not create synth!\n"); + return kResultFalse; + } + return result; } @@ -105,21 +112,27 @@ tresult PLUGIN_API SfizzVstProcessor::canProcessSampleSize(int32 symbolicSampleS tresult PLUGIN_API SfizzVstProcessor::setActive(TBool state) { - stopBackgroundWork(); - _synth.reset(); + sfz::Sfizz* synth = _synth.get(); + + if (!synth) { + fprintf(stderr, "[sfizz] Synth was destroyed? Trying to recreate...\n"); + synth = new sfz::Sfizz; + if (!synth) { + fprintf(stderr, "[sfizz] Something is very wrong\n"); + return kResultFalse; + } + _synth.reset(synth); + syncStateToSynth(); + } if (state) { - fprintf(stderr, "[Sfizz] new synth\n"); - sfz::Sfizz* synth = new sfz::Sfizz; - _synth.reset(synth); - - synth->setSampleRate(processSetup.sampleRate); - synth->setSamplesPerBlock(processSetup.maxSamplesPerBlock); - - syncStateToSynth(); + _synth->setSampleRate(processSetup.sampleRate); + _synth->setSamplesPerBlock(processSetup.maxSamplesPerBlock); _workRunning = true; _worker = std::thread([this]() { doBackgroundWork(); }); + } else { + stopBackgroundWork(); } return kResultTrue;