mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-06-14 23:43:52 +02:00
Add mutexes for the VST3 data caches
Since the restart will always be called from another thread, and when a plugin asks for a restart during initialization this can quickly lead to issues.
This commit is contained in:
@@ -145,10 +145,13 @@ tresult PLUGIN_API Vst3PluginProxyImpl::setProcessing(TBool state) {
|
|||||||
// REAPER will repeatedly query the plugin for its bus information on every
|
// REAPER will repeatedly query the plugin for its bus information on every
|
||||||
// processing cycle. Because this really adds up in terms of latency we
|
// processing cycle. Because this really adds up in terms of latency we
|
||||||
// sadly have to deviate from yabridge's principles and implement a cache
|
// sadly have to deviate from yabridge's principles and implement a cache
|
||||||
if (state) {
|
{
|
||||||
processing_bus_cache.emplace();
|
std::lock_guard lock(processing_bus_cache_mutex);
|
||||||
} else {
|
if (state) {
|
||||||
processing_bus_cache.reset();
|
processing_bus_cache.emplace();
|
||||||
|
} else {
|
||||||
|
processing_bus_cache.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bridge.send_audio_processor_message(YaAudioProcessor::SetProcessing{
|
return bridge.send_audio_processor_message(YaAudioProcessor::SetProcessing{
|
||||||
@@ -225,23 +228,31 @@ Vst3PluginProxyImpl::getBusCount(Steinberg::Vst::MediaType type,
|
|||||||
// issue in REAPER
|
// issue in REAPER
|
||||||
std::tuple<Steinberg::Vst::MediaType, Steinberg::Vst::BusDirection> args{
|
std::tuple<Steinberg::Vst::MediaType, Steinberg::Vst::BusDirection> args{
|
||||||
type, dir};
|
type, dir};
|
||||||
if (processing_bus_cache) {
|
{
|
||||||
if (auto it = processing_bus_cache->bus_count.find(args);
|
std::lock_guard lock(processing_bus_cache_mutex);
|
||||||
it != processing_bus_cache->bus_count.end()) {
|
if (processing_bus_cache) {
|
||||||
const bool log_response = bridge.logger.log_request(true, request);
|
if (auto it = processing_bus_cache->bus_count.find(args);
|
||||||
if (log_response) {
|
it != processing_bus_cache->bus_count.end()) {
|
||||||
bridge.logger.log_response(
|
const bool log_response =
|
||||||
true, YaComponent::GetBusCount::Response(it->second), true);
|
bridge.logger.log_request(true, request);
|
||||||
}
|
if (log_response) {
|
||||||
|
bridge.logger.log_response(
|
||||||
|
true, YaComponent::GetBusCount::Response(it->second),
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
return it->second;
|
return it->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int32 result = bridge.send_audio_processor_message(request);
|
const int32 result = bridge.send_audio_processor_message(request);
|
||||||
|
|
||||||
if (processing_bus_cache) {
|
{
|
||||||
processing_bus_cache->bus_count[args] = result;
|
std::lock_guard lock(processing_bus_cache_mutex);
|
||||||
|
if (processing_bus_cache) {
|
||||||
|
processing_bus_cache->bus_count[args] = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -262,21 +273,26 @@ Vst3PluginProxyImpl::getBusInfo(Steinberg::Vst::MediaType type,
|
|||||||
// issue in REAPER
|
// issue in REAPER
|
||||||
std::tuple<Steinberg::Vst::MediaType, Steinberg::Vst::BusDirection, int32>
|
std::tuple<Steinberg::Vst::MediaType, Steinberg::Vst::BusDirection, int32>
|
||||||
args{type, dir, index};
|
args{type, dir, index};
|
||||||
if (processing_bus_cache) {
|
{
|
||||||
if (auto it = processing_bus_cache->bus_info.find(args);
|
std::lock_guard lock(processing_bus_cache_mutex);
|
||||||
it != processing_bus_cache->bus_info.end()) {
|
if (processing_bus_cache) {
|
||||||
const bool log_response = bridge.logger.log_request(true, request);
|
if (auto it = processing_bus_cache->bus_info.find(args);
|
||||||
if (log_response) {
|
it != processing_bus_cache->bus_info.end()) {
|
||||||
bridge.logger.log_response(true,
|
const bool log_response =
|
||||||
YaComponent::GetBusInfo::Response{
|
bridge.logger.log_request(true, request);
|
||||||
.result = Steinberg::kResultOk,
|
if (log_response) {
|
||||||
.updated_bus = it->second},
|
bridge.logger.log_response(
|
||||||
true);
|
true,
|
||||||
|
YaComponent::GetBusInfo::Response{
|
||||||
|
.result = Steinberg::kResultOk,
|
||||||
|
.updated_bus = it->second},
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bus = it->second;
|
||||||
|
|
||||||
|
return Steinberg::kResultOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
bus = it->second;
|
|
||||||
|
|
||||||
return Steinberg::kResultOk;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -284,8 +300,12 @@ Vst3PluginProxyImpl::getBusInfo(Steinberg::Vst::MediaType type,
|
|||||||
bridge.send_audio_processor_message(request);
|
bridge.send_audio_processor_message(request);
|
||||||
|
|
||||||
bus = response.updated_bus;
|
bus = response.updated_bus;
|
||||||
if (processing_bus_cache) {
|
|
||||||
processing_bus_cache->bus_info[args] = response.updated_bus;
|
{
|
||||||
|
std::lock_guard lock(processing_bus_cache_mutex);
|
||||||
|
if (processing_bus_cache) {
|
||||||
|
processing_bus_cache->bus_info[args] = response.updated_bus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.result;
|
return response.result;
|
||||||
@@ -440,22 +460,28 @@ int32 PLUGIN_API Vst3PluginProxyImpl::getParameterCount() {
|
|||||||
|
|
||||||
// We'll cache this information to work around an issue in REAPER, see
|
// We'll cache this information to work around an issue in REAPER, see
|
||||||
// `parameter_info_cache`
|
// `parameter_info_cache`
|
||||||
if (parameter_info_cache.parameter_count) {
|
{
|
||||||
const bool log_response = bridge.logger.log_request(true, request);
|
std::lock_guard lock(parameter_info_cache_mutex);
|
||||||
if (log_response) {
|
if (parameter_info_cache.parameter_count) {
|
||||||
bridge.logger.log_response(
|
const bool log_response = bridge.logger.log_request(true, request);
|
||||||
true,
|
if (log_response) {
|
||||||
YaEditController::GetParameterCount::Response(
|
bridge.logger.log_response(
|
||||||
*parameter_info_cache.parameter_count),
|
true,
|
||||||
true);
|
YaEditController::GetParameterCount::Response(
|
||||||
}
|
*parameter_info_cache.parameter_count),
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
return *parameter_info_cache.parameter_count;
|
return *parameter_info_cache.parameter_count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int32 result = bridge.send_message(request);
|
const int32 result = bridge.send_message(request);
|
||||||
|
|
||||||
parameter_info_cache.parameter_count = result;
|
{
|
||||||
|
std::lock_guard lock(parameter_info_cache_mutex);
|
||||||
|
parameter_info_cache.parameter_count = result;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -468,26 +494,34 @@ tresult PLUGIN_API Vst3PluginProxyImpl::getParameterInfo(
|
|||||||
|
|
||||||
// We'll cache this information to work around an issue in REAPER, see
|
// We'll cache this information to work around an issue in REAPER, see
|
||||||
// `parameter_info_cache`
|
// `parameter_info_cache`
|
||||||
if (auto it = parameter_info_cache.parameter_info.find(paramIndex);
|
{
|
||||||
it != parameter_info_cache.parameter_info.end()) {
|
std::lock_guard lock(parameter_info_cache_mutex);
|
||||||
const bool log_response = bridge.logger.log_request(true, request);
|
if (auto it = parameter_info_cache.parameter_info.find(paramIndex);
|
||||||
if (log_response) {
|
it != parameter_info_cache.parameter_info.end()) {
|
||||||
bridge.logger.log_response(
|
const bool log_response = bridge.logger.log_request(true, request);
|
||||||
true,
|
if (log_response) {
|
||||||
YaEditController::GetParameterInfo::Response{
|
bridge.logger.log_response(
|
||||||
.result = Steinberg::kResultOk, .updated_info = it->second},
|
true,
|
||||||
true);
|
YaEditController::GetParameterInfo::Response{
|
||||||
|
.result = Steinberg::kResultOk,
|
||||||
|
.updated_info = it->second},
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
info = it->second;
|
||||||
|
|
||||||
|
return Steinberg::kResultOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
info = it->second;
|
|
||||||
|
|
||||||
return Steinberg::kResultOk;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const GetParameterInfoResponse response = bridge.send_message(request);
|
const GetParameterInfoResponse response = bridge.send_message(request);
|
||||||
|
|
||||||
info = response.updated_info;
|
info = response.updated_info;
|
||||||
parameter_info_cache.parameter_info[paramIndex] = response.updated_info;
|
|
||||||
|
{
|
||||||
|
std::lock_guard lock(parameter_info_cache_mutex);
|
||||||
|
parameter_info_cache.parameter_info[paramIndex] = response.updated_info;
|
||||||
|
}
|
||||||
|
|
||||||
return response.result;
|
return response.result;
|
||||||
}
|
}
|
||||||
@@ -1158,11 +1192,13 @@ tresult PLUGIN_API Vst3PluginProxyImpl::getXmlRepresentationStream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Vst3PluginProxyImpl::clear_bus_cache() {
|
void Vst3PluginProxyImpl::clear_bus_cache() {
|
||||||
|
std::lock_guard lock(processing_bus_cache_mutex);
|
||||||
if (processing_bus_cache) {
|
if (processing_bus_cache) {
|
||||||
processing_bus_cache.emplace();
|
processing_bus_cache.emplace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vst3PluginProxyImpl::clear_parameter_cache() {
|
void Vst3PluginProxyImpl::clear_parameter_cache() {
|
||||||
|
std::lock_guard lock(parameter_info_cache_mutex);
|
||||||
parameter_info_cache = ParameterInfoCache{};
|
parameter_info_cache = ParameterInfoCache{};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -487,6 +487,7 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
|
|||||||
* does that.
|
* does that.
|
||||||
*/
|
*/
|
||||||
std::optional<BusInfoCache> processing_bus_cache;
|
std::optional<BusInfoCache> processing_bus_cache;
|
||||||
|
std::mutex processing_bus_cache_mutex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cache for `IEditController::getParameterCount()` and
|
* A cache for `IEditController::getParameterCount()` and
|
||||||
@@ -513,4 +514,5 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
|
|||||||
* information four times per second.
|
* information four times per second.
|
||||||
*/
|
*/
|
||||||
ParameterInfoCache parameter_info_cache;
|
ParameterInfoCache parameter_info_cache;
|
||||||
|
std::mutex parameter_info_cache_mutex;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user