Merge pull request #625 from jpcima/vst-pluginval

Fix a crash that makes VST fail pluginval
This commit is contained in:
JP Cimalando 2021-02-03 18:11:06 +01:00 committed by GitHub
commit 1a50bcaa72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View file

@ -182,6 +182,9 @@ tresult PLUGIN_API SfizzVstProcessor::setActive(TBool state)
{
sfz::Sfizz* synth = _synth.get();
if (bool(state) == _isActive)
return kResultTrue;
if (!synth)
return kResultFalse;
@ -192,13 +195,13 @@ tresult PLUGIN_API SfizzVstProcessor::setActive(TBool state)
_fileChangePeriod = static_cast<uint32>(1.0 * processSetup.sampleRate);
_playStateChangePeriod = static_cast<uint32>(50e-3 * processSetup.sampleRate);
_workRunning = true;
_worker = std::thread([this]() { doBackgroundWork(); });
startBackgroundWork();
} else {
synth->allSoundOff();
stopBackgroundWork();
synth->allSoundOff();
}
_isActive = bool(state);
return kResultTrue;
}
@ -642,6 +645,15 @@ void SfizzVstProcessor::doBackgroundWork()
}
}
void SfizzVstProcessor::startBackgroundWork()
{
if (_workRunning)
return;
_workRunning = true;
_worker = std::thread([this]() { doBackgroundWork(); });
}
void SfizzVstProcessor::stopBackgroundWork()
{
if (!_workRunning)

View file

@ -48,6 +48,7 @@ public:
private:
// synth state. acquire processMutex before accessing
std::unique_ptr<sfz::Sfizz> _synth;
bool _isActive = false;
SfizzVstState _state;
float _currentStretchedTuning = 0;
@ -94,6 +95,7 @@ private:
// worker
void doBackgroundWork();
void startBackgroundWork();
void stopBackgroundWork();
// writer
bool writeWorkerMessage(const char* type, const void* data, uintptr_t size);