mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +02:00
Implement start_processing, stop_processing, reset
This commit is contained in:
@@ -91,6 +91,27 @@ bool ClapLogger::log_request(bool is_host_plugin,
|
||||
});
|
||||
}
|
||||
|
||||
bool ClapLogger::log_request(bool is_host_plugin,
|
||||
const clap::plugin::StartProcessing& request) {
|
||||
return log_request_base(is_host_plugin, [&](auto& message) {
|
||||
message << request.instance_id << ": clap_plugin::start_processing()";
|
||||
});
|
||||
}
|
||||
|
||||
bool ClapLogger::log_request(bool is_host_plugin,
|
||||
const clap::plugin::StopProcessing& request) {
|
||||
return log_request_base(is_host_plugin, [&](auto& message) {
|
||||
message << request.instance_id << ": clap_plugin::stop_processing()";
|
||||
});
|
||||
}
|
||||
|
||||
bool ClapLogger::log_request(bool is_host_plugin,
|
||||
const clap::plugin::Reset& request) {
|
||||
return log_request_base(is_host_plugin, [&](auto& message) {
|
||||
message << request.instance_id << ": clap_plugin::reset()";
|
||||
});
|
||||
}
|
||||
|
||||
bool ClapLogger::log_request(bool is_host_plugin, const WantsConfiguration&) {
|
||||
return log_request_base(is_host_plugin, [&](auto& message) {
|
||||
message << "Requesting <Configuration>";
|
||||
|
||||
@@ -52,9 +52,9 @@ class ClapLogger {
|
||||
bool log_request(bool is_host_plugin, const clap::plugin::Activate&);
|
||||
bool log_request(bool is_host_plugin, const clap::plugin::Deactivate&);
|
||||
|
||||
// TODO: Audio thread requests
|
||||
// bool log_request(bool is_host_plugin,
|
||||
// const YaAudioProcessor::SetBusArrangements&);
|
||||
bool log_request(bool is_host_plugin, const clap::plugin::StartProcessing&);
|
||||
bool log_request(bool is_host_plugin, const clap::plugin::StopProcessing&);
|
||||
bool log_request(bool is_host_plugin, const clap::plugin::Reset&);
|
||||
|
||||
bool log_request(bool is_host_plugin, const WantsConfiguration&);
|
||||
|
||||
|
||||
@@ -76,8 +76,9 @@ struct ClapAudioThreadControlRequest {
|
||||
template <typename T>
|
||||
ClapAudioThreadControlRequest(T request) : payload(std::move(request)) {}
|
||||
|
||||
// TODO:
|
||||
using Payload = std::variant<WantsConfiguration>;
|
||||
using Payload = std::variant<clap::plugin::StartProcessing,
|
||||
clap::plugin::StopProcessing,
|
||||
clap::plugin::Reset>;
|
||||
|
||||
Payload payload;
|
||||
|
||||
|
||||
@@ -108,8 +108,8 @@ clap_plugin_proxy::plugin_start_processing(const struct clap_plugin* plugin) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
// TODO: Implement
|
||||
return false;
|
||||
return self->bridge_.send_audio_thread_message(
|
||||
clap::plugin::StartProcessing{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
@@ -117,7 +117,8 @@ clap_plugin_proxy::plugin_stop_processing(const struct clap_plugin* plugin) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
// TODO: Implement
|
||||
self->bridge_.send_audio_thread_message(
|
||||
clap::plugin::StopProcessing{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
void CLAP_ABI
|
||||
@@ -125,7 +126,8 @@ clap_plugin_proxy::plugin_reset(const struct clap_plugin* plugin) {
|
||||
assert(plugin && plugin->plugin_data);
|
||||
auto self = static_cast<const clap_plugin_proxy*>(plugin->plugin_data);
|
||||
|
||||
// TODO: Implement
|
||||
self->bridge_.send_audio_thread_message(
|
||||
clap::plugin::Reset{.instance_id = self->instance_id()});
|
||||
}
|
||||
|
||||
clap_process_status CLAP_ABI
|
||||
|
||||
@@ -115,17 +115,15 @@ class ClapPluginBridge : PluginBridge<ClapSockets<std::jthread>> {
|
||||
object, std::pair<ClapLogger&, bool>(logger_, true));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Send an a message to a plugin instance's audio thread. This is
|
||||
// separate
|
||||
// * from `send_message()`, which shares one socket for all plugin
|
||||
// instances.
|
||||
// */
|
||||
// template <typename T>
|
||||
// typename T::Response send_audio_thread_message(const T& object) {
|
||||
// return sockets_.send_audio_processor_message(
|
||||
// object, std::pair<ClapLogger&, bool>(logger_, true));
|
||||
// }
|
||||
/**
|
||||
* Send an a message to a plugin instance's audio thread. This is separate
|
||||
* from `send_message()`, which shares one socket for all plugin instances.
|
||||
*/
|
||||
template <typename T>
|
||||
typename T::Response send_audio_thread_message(const T& object) {
|
||||
return sockets_.send_audio_thread_message(
|
||||
object, std::pair<ClapLogger&, bool>(logger_, true));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Send an audio thread control message to a specific plugin instance,
|
||||
|
||||
@@ -489,28 +489,49 @@ void ClapBridge::register_plugin_instance(
|
||||
|
||||
// Every plugin instance gets its own audio thread
|
||||
std::promise<void> socket_listening_latch;
|
||||
object_instances_.at(instance_id)
|
||||
.audio_thread_handler = Win32Thread([&, instance_id]() {
|
||||
set_realtime_priority(true);
|
||||
object_instances_.at(instance_id).audio_thread_handler =
|
||||
Win32Thread([&, instance_id]() {
|
||||
set_realtime_priority(true);
|
||||
|
||||
// XXX: Like with VST2 worker threads, when using plugin groups the
|
||||
// thread names from different plugins will clash. Not a huge
|
||||
// deal probably, since duplicate thread names are still more
|
||||
// useful than no thread names.
|
||||
const std::string thread_name = "audio-" + std::to_string(instance_id);
|
||||
pthread_setname_np(pthread_self(), thread_name.c_str());
|
||||
// XXX: Like with VST2 worker threads, when using plugin groups the
|
||||
// thread names from different plugins will clash. Not a huge
|
||||
// deal probably, since duplicate thread names are still more
|
||||
// useful than no thread names.
|
||||
const std::string thread_name =
|
||||
"audio-" + std::to_string(instance_id);
|
||||
pthread_setname_np(pthread_self(), thread_name.c_str());
|
||||
|
||||
sockets_.add_audio_thread_and_listen(
|
||||
instance_id, socket_listening_latch,
|
||||
overload{
|
||||
[&](const WantsConfiguration&) -> WantsConfiguration::Response {
|
||||
// FIXME: This overload shouldn't be here, but
|
||||
// bitsery simply won't allow us to serialize the
|
||||
// variant without it.
|
||||
return {};
|
||||
},
|
||||
});
|
||||
});
|
||||
sockets_.add_audio_thread_and_listen(
|
||||
instance_id, socket_listening_latch,
|
||||
overload{
|
||||
[&](const clap::plugin::StartProcessing& request)
|
||||
-> clap::plugin::StartProcessing::Response {
|
||||
const auto& [instance, _] =
|
||||
get_instance(request.instance_id);
|
||||
|
||||
return instance.plugin->start_processing(
|
||||
instance.plugin.get());
|
||||
},
|
||||
[&](const clap::plugin::StopProcessing& request)
|
||||
-> clap::plugin::StopProcessing::Response {
|
||||
const auto& [instance, _] =
|
||||
get_instance(request.instance_id);
|
||||
|
||||
instance.plugin->stop_processing(instance.plugin.get());
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
[&](const clap::plugin::Reset& request)
|
||||
-> clap::plugin::Reset::Response {
|
||||
const auto& [instance, _] =
|
||||
get_instance(request.instance_id);
|
||||
|
||||
instance.plugin->reset(instance.plugin.get());
|
||||
|
||||
return Ack{};
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// Wait for the new socket to be listening on before continuing. Otherwise
|
||||
// the native plugin may try to connect to it before our thread is up and
|
||||
|
||||
Reference in New Issue
Block a user