Thread-safety at VST level
This commit is contained in:
parent
1d6b06aa2e
commit
e0a7fb1dbc
3 changed files with 14 additions and 8 deletions
|
|
@ -58,8 +58,9 @@ if(WIN32)
|
|||
target_sources(${VSTPLUGIN_PRJ_NAME} PRIVATE vst3.def)
|
||||
endif()
|
||||
target_link_libraries(${VSTPLUGIN_PRJ_NAME}
|
||||
PRIVATE ${PROJECT_NAME}::${PROJECT_NAME}
|
||||
PRIVATE sfizz::sfizz
|
||||
PRIVATE sfizz::editor
|
||||
PRIVATE sfizz::spin_mutex
|
||||
PRIVATE sfizz::pugixml sfizz::filesystem)
|
||||
target_include_directories(${VSTPLUGIN_PRJ_NAME}
|
||||
PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ tresult PLUGIN_API SfizzVstProcessor::setState(IBStream* stream)
|
|||
}
|
||||
|
||||
//
|
||||
std::lock_guard<std::mutex> lock(_processMutex);
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
_state = s;
|
||||
|
||||
syncStateToSynth();
|
||||
|
|
@ -148,7 +148,7 @@ tresult PLUGIN_API SfizzVstProcessor::setState(IBStream* stream)
|
|||
|
||||
tresult PLUGIN_API SfizzVstProcessor::getState(IBStream* stream)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_processMutex);
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
return _state.store(stream);
|
||||
}
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ tresult PLUGIN_API SfizzVstProcessor::process(Vst::ProcessData& data)
|
|||
for (unsigned c = 0; c < numChannels; ++c)
|
||||
outputs[c] = data.outputs[0].channelBuffers32[c];
|
||||
|
||||
std::unique_lock<std::mutex> lock(_processMutex, std::try_to_lock);
|
||||
std::unique_lock<SpinMutex> lock(_processMutex, std::try_to_lock);
|
||||
|
||||
if (!lock.owns_lock()) {
|
||||
for (unsigned c = 0; c < numChannels; ++c)
|
||||
|
|
@ -515,7 +515,7 @@ tresult PLUGIN_API SfizzVstProcessor::notify(Vst::IMessage* message)
|
|||
if (result != kResultTrue)
|
||||
return result;
|
||||
|
||||
std::unique_lock<std::mutex> lock(_processMutex);
|
||||
std::unique_lock<SpinMutex> lock(_processMutex);
|
||||
_state.sfzFile.assign(static_cast<const char *>(data), size);
|
||||
loadSfzFileOrDefault(*_synth, _state.sfzFile);
|
||||
lock.unlock();
|
||||
|
|
@ -533,7 +533,7 @@ tresult PLUGIN_API SfizzVstProcessor::notify(Vst::IMessage* message)
|
|||
if (result != kResultTrue)
|
||||
return result;
|
||||
|
||||
std::unique_lock<std::mutex> lock(_processMutex);
|
||||
std::unique_lock<SpinMutex> lock(_processMutex);
|
||||
_state.scalaFile.assign(static_cast<const char *>(data), size);
|
||||
_synth->loadScalaFile(_state.scalaFile);
|
||||
lock.unlock();
|
||||
|
|
@ -601,23 +601,28 @@ void SfizzVstProcessor::doBackgroundWork()
|
|||
|
||||
if (!std::strcmp(id, "SetNumVoices")) {
|
||||
int32 value = *msg->payload<int32>();
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
_synth->setNumVoices(value);
|
||||
}
|
||||
else if (!std::strcmp(id, "SetOversampling")) {
|
||||
int32 value = *msg->payload<int32>();
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
_synth->setOversamplingFactor(1 << value);
|
||||
}
|
||||
else if (!std::strcmp(id, "SetPreloadSize")) {
|
||||
int32 value = *msg->payload<int32>();
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
_synth->setPreloadSize(value);
|
||||
}
|
||||
else if (!std::strcmp(id, "CheckShouldReload")) {
|
||||
if (_synth->shouldReloadFile()) {
|
||||
fprintf(stderr, "[Sfizz] sfz file has changed, reloading\n");
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
loadSfzFileOrDefault(*_synth, _state.sfzFile);
|
||||
}
|
||||
else if (_synth->shouldReloadScala()) {
|
||||
fprintf(stderr, "[Sfizz] scala file has changed, reloading\n");
|
||||
std::lock_guard<SpinMutex> lock(_processMutex);
|
||||
_synth->loadScalaFile(_state.scalaFile);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#include "ring_buffer/ring_buffer.h"
|
||||
#include "public.sdk/source/vst/vstaudioeffect.h"
|
||||
#include <sfizz.hpp>
|
||||
#include <SpinMutex.h>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ private:
|
|||
Ring_Buffer _fifoToWorker;
|
||||
RTSemaphore _semaToWorker;
|
||||
Ring_Buffer _fifoMessageFromUi;
|
||||
std::mutex _processMutex;
|
||||
SpinMutex _processMutex;
|
||||
|
||||
// file modification periodic checker
|
||||
uint32 _fileChangeCounter = 0;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue