mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Temporarily memoize IPlugView::canResize()
This makes VST3 plugin resizing more responsive, because this function would otherwise be constantly running in lockstep from the GUI thread.
This commit is contained in:
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic
|
||||
Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Added a timed cache for the `IPluginView::canResize()` VST3 function, so value
|
||||
will be remembered during an active resize. This makes resizing VST3 plugin
|
||||
editor windows more responsive.
|
||||
|
||||
## [3.2.0] - 2021-05-03
|
||||
|
||||
### Added
|
||||
|
||||
@@ -1400,9 +1400,14 @@ void Vst3Logger::log_response(bool is_host_vst, const Ack&) {
|
||||
}
|
||||
|
||||
void Vst3Logger::log_response(bool is_host_vst,
|
||||
const UniversalTResult& result) {
|
||||
log_response_base(is_host_vst,
|
||||
[&](auto& message) { message << result.string(); });
|
||||
const UniversalTResult& result,
|
||||
bool from_cache) {
|
||||
log_response_base(is_host_vst, [&](auto& message) {
|
||||
message << result.string();
|
||||
if (from_cache) {
|
||||
message << " (from cache)";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Vst3Logger::log_response(
|
||||
|
||||
@@ -242,7 +242,9 @@ class Vst3Logger {
|
||||
const YaUnitHandler2::NotifyUnitByBusChange&);
|
||||
|
||||
void log_response(bool is_host_vst, const Ack&);
|
||||
void log_response(bool is_host_vst, const UniversalTResult&);
|
||||
void log_response(bool is_host_vst,
|
||||
const UniversalTResult&,
|
||||
bool from_cache = false);
|
||||
void log_response(bool is_host_vst,
|
||||
const Vst3PluginFactoryProxy::ConstructArgs&);
|
||||
void log_response(
|
||||
|
||||
@@ -244,8 +244,30 @@ Vst3PlugViewProxyImpl::setFrame(Steinberg::IPlugFrame* frame) {
|
||||
}
|
||||
|
||||
tresult PLUGIN_API Vst3PlugViewProxyImpl::canResize() {
|
||||
return send_mutually_recursive_message(
|
||||
YaPlugView::CanResize{.owner_instance_id = owner_instance_id()});
|
||||
const auto request =
|
||||
YaPlugView::CanResize{.owner_instance_id = owner_instance_id()};
|
||||
|
||||
{
|
||||
std::lock_guard lock(can_resize_cache_mutex);
|
||||
if (const tresult* result = can_resize_cache.get_and_keep_alive(5)) {
|
||||
const bool log_response = bridge.logger.log_request(true, request);
|
||||
if (log_response) {
|
||||
bridge.logger.log_response(
|
||||
true, YaPlugView::CanResize::Response(*result));
|
||||
}
|
||||
|
||||
return *result;
|
||||
}
|
||||
}
|
||||
|
||||
const UniversalTResult result = send_mutually_recursive_message(request);
|
||||
|
||||
{
|
||||
std::lock_guard lock(can_resize_cache_mutex);
|
||||
can_resize_cache.set(result, 5);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
tresult PLUGIN_API
|
||||
|
||||
@@ -301,4 +301,20 @@ class Vst3PlugViewProxyImpl : public Vst3PlugViewProxy {
|
||||
* This will be an `std::nullopt` if the hostdoes not support `IRunLoop`.
|
||||
*/
|
||||
std::optional<RunLoopTasks> run_loop_tasks;
|
||||
|
||||
// Caches
|
||||
|
||||
/**
|
||||
* During resizing the host will likely constantly ask the plugin if it can
|
||||
* be freely resized. Even if it is technically possible, I'm not aware of
|
||||
* any plugins that change from not being able arbitrarily resizeable to
|
||||
* being able to be resized like this. The reason why we might want to cache
|
||||
* `IPlugView::canResize()` is because this function has to be run on the
|
||||
* GUI thread, just like `IPlugView::onSize()` and
|
||||
* `IPlugView::checkSizeConstraint`. Everything running in lockstep makes
|
||||
* resizing a lot laggier than they would have to be, so as a compromise
|
||||
* we'll remember this value for the duration of the resize.
|
||||
*/
|
||||
TimedValueCache<tresult> can_resize_cache;
|
||||
std::mutex can_resize_cache_mutex;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user