Simplify VST3 parameter caching

This commit is contained in:
Robbert van der Helm
2023-05-06 22:26:25 +02:00
parent 8289d76818
commit 135ea8e9c4
2 changed files with 19 additions and 48 deletions
+12 -41
View File
@@ -624,23 +624,11 @@ Vst3PluginProxyImpl::setComponentState(Steinberg::IBStream* state) {
int32 PLUGIN_API Vst3PluginProxyImpl::getParameterCount() { int32 PLUGIN_API Vst3PluginProxyImpl::getParameterCount() {
// Parameter information is queried all at once to work around a Kontakt // Parameter information is queried all at once to work around a Kontakt
// bug, see https://github.com/robbert-vdh/yabridge/issues/236 // bug, see <https://github.com/robbert-vdh/yabridge/issues/236>. The first
{ // time either of these two functions is called we'll fetch the infos for
// We'll assume that the plugin has at least one parameter. If it does // all parameters. These are cleared when the plugin triggers a component
// not have any parameters then everything will work as expected, except // restart.
// that the parameter count is not cached. maybe_query_parameter_info();
std::lock_guard lock(function_result_cache_mutex_);
if (!function_result_cache_.parameter_info.empty()) {
// We can't cleanly log here, but it also doesn't really matter
return static_cast<int32>(
function_result_cache_.parameter_info.size());
}
}
// The first time either of these two functions is called we'll fetch the
// infos for all parameters. These are cleared when the plugin triggers a
// component restart.
query_parameter_info();
std::lock_guard lock(function_result_cache_mutex_); std::lock_guard lock(function_result_cache_mutex_);
return static_cast<int32>(function_result_cache_.parameter_info.size()); return static_cast<int32>(function_result_cache_.parameter_info.size());
@@ -655,29 +643,7 @@ tresult PLUGIN_API Vst3PluginProxyImpl::getParameterInfo(
} }
// See above // See above
{ maybe_query_parameter_info();
std::lock_guard lock(function_result_cache_mutex_);
if (!function_result_cache_.parameter_info.empty()) {
if (paramIndex <
static_cast<int32>(
function_result_cache_.parameter_info.size())) {
if (const auto& result =
function_result_cache_.parameter_info[paramIndex]) {
info = *result;
return Steinberg::kResultOk;
} else {
return Steinberg::kResultFalse;
}
} else {
return Steinberg::kInvalidArgument;
}
}
}
// The first time either of these two functions is called we'll fetch the
// infos for all parameters. These are cleared when the plugin triggers a
// component restart.
query_parameter_info();
std::lock_guard lock(function_result_cache_mutex_); std::lock_guard lock(function_result_cache_mutex_);
if (paramIndex < if (paramIndex <
@@ -1379,13 +1345,18 @@ tresult PLUGIN_API Vst3PluginProxyImpl::getXmlRepresentationStream(
} }
} }
void Vst3PluginProxyImpl::query_parameter_info() { void Vst3PluginProxyImpl::maybe_query_parameter_info() {
std::lock_guard lock(function_result_cache_mutex_); std::lock_guard lock(function_result_cache_mutex_);
// We'll assume that the plugin has at least one parameter. If it does not
// have any parameters then everything will work as expected, except that
// the parameter count is not cached.
if (function_result_cache_.parameter_info.empty()) {
const GetParameterInfosResponse response = bridge_.send_message( const GetParameterInfosResponse response = bridge_.send_message(
YaEditController::GetParameterInfos{.instance_id = instance_id()}); YaEditController::GetParameterInfos{.instance_id = instance_id()});
function_result_cache_.parameter_info = std::move(response.infos); function_result_cache_.parameter_info = std::move(response.infos);
} }
}
void Vst3PluginProxyImpl::clear_bus_cache() noexcept { void Vst3PluginProxyImpl::clear_bus_cache() noexcept {
std::lock_guard lock(processing_bus_cache_mutex_); std::lock_guard lock(processing_bus_cache_mutex_);
+4 -4
View File
@@ -400,11 +400,11 @@ class Vst3PluginProxyImpl : public Vst3PluginProxy {
private: private:
/** /**
* Query information for all of the plugin's parameters and writes the * Query information for all of the plugin's parameters and writes the
* results to `function_result_cache_`. Acquires a lock on the struct in the * results to `function_result_cache_` if necessary. Otherwise does nothing.
* process, so it must not be locked before calling this function (thanks * Acquires a lock on the struct in the process, so it must not be locked
* STL). * before calling this function (thanks STL).
*/ */
void query_parameter_info(); void maybe_query_parameter_info();
/** /**
* Clear the bus count and information cache. We need this cache for REAPER * Clear the bus count and information cache. We need this cache for REAPER