Merge pull request #139 from jpcima/vst
Allow VST to reload its files automatically
This commit is contained in:
commit
25ca3eeb0b
2 changed files with 33 additions and 0 deletions
|
|
@ -117,6 +117,16 @@ tresult PLUGIN_API SfizzVstProcessor::setActive(TBool state)
|
||||||
synth->setSampleRate(processSetup.sampleRate);
|
synth->setSampleRate(processSetup.sampleRate);
|
||||||
synth->setSamplesPerBlock(processSetup.maxSamplesPerBlock);
|
synth->setSamplesPerBlock(processSetup.maxSamplesPerBlock);
|
||||||
|
|
||||||
|
_fileChangePeriod = static_cast<uint32>(processSetup.sampleRate);
|
||||||
|
|
||||||
|
if (!_msgCheckShouldReload) {
|
||||||
|
auto msg = IPtr<Vst::IMessage>::adopt(allocateMessage());
|
||||||
|
if (!msg)
|
||||||
|
return kResultFalse;
|
||||||
|
msg->setMessageID("CheckShouldReload");
|
||||||
|
_msgCheckShouldReload = msg;
|
||||||
|
}
|
||||||
|
|
||||||
_workRunning = true;
|
_workRunning = true;
|
||||||
_worker = std::thread([this]() { doBackgroundWork(); });
|
_worker = std::thread([this]() { doBackgroundWork(); });
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -169,6 +179,17 @@ tresult PLUGIN_API SfizzVstProcessor::process(Vst::ProcessData& data)
|
||||||
synth.setVolume(_state.volume);
|
synth.setVolume(_state.volume);
|
||||||
|
|
||||||
synth.renderBlock(outputs, numFrames, numChannels);
|
synth.renderBlock(outputs, numFrames, numChannels);
|
||||||
|
|
||||||
|
_fileChangeCounter += numFrames;
|
||||||
|
if (_fileChangeCounter > _fileChangePeriod) {
|
||||||
|
_fileChangeCounter %= _fileChangePeriod;
|
||||||
|
Vst::IMessage* msg = _msgCheckShouldReload.get();
|
||||||
|
if (_fifoToWorker.push(msg)) {
|
||||||
|
msg->addRef();
|
||||||
|
_semaToWorker.post();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return kResultTrue;
|
return kResultTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,6 +401,13 @@ void SfizzVstProcessor::doBackgroundWork()
|
||||||
_synth->setPreloadSize(value);
|
_synth->setPreloadSize(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!std::strcmp(id, "CheckShouldReload")) {
|
||||||
|
if (_synth->shouldReloadFile()) {
|
||||||
|
fprintf(stderr, "[Sfizz] file has changed, reloading\n");
|
||||||
|
std::lock_guard<std::mutex> lock(_processMutex);
|
||||||
|
_synth->loadSfzFile(_state.sfzFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
msg->release();
|
msg->release();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ private:
|
||||||
RTSemaphore _semaToWorker;
|
RTSemaphore _semaToWorker;
|
||||||
std::mutex _processMutex;
|
std::mutex _processMutex;
|
||||||
|
|
||||||
|
// file modification periodic checker
|
||||||
|
uint32 _fileChangeCounter = 0;
|
||||||
|
uint32 _fileChangePeriod = 0;
|
||||||
|
IPtr<Vst::IMessage> _msgCheckShouldReload;
|
||||||
|
|
||||||
// worker
|
// worker
|
||||||
void doBackgroundWork();
|
void doBackgroundWork();
|
||||||
void stopBackgroundWork();
|
void stopBackgroundWork();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue