mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
💥 Redo all higher order template functions
This does what we did for a few functions in the last few commits for every function. We now use either the `std::invocable` concept or our own `invocable_returning` concept wherever possible to make sure we pass function types to these template functions, since constraint errors are a lot more readable than template deduction errors. And instead of having to specify the return type as a template argument, we now just use `std::invoke_result_t<F>` instead. The VST3 message handling functions are still using the good old `typename F` since those are overloaded polymorphic functions. This was also a good moment to modify `AdHocSocketHandler::send()` to allow functions returning void (this got rid of an old fixme where we had to return some dummy value from a function instead of just not returning anything).
This commit is contained in:
@@ -51,14 +51,13 @@ class PluginBridge {
|
||||
* Using a lambda here feels wrong, but I can't think of a better
|
||||
* solution right now.
|
||||
*
|
||||
* @tparam F A `TSockets(boost::asio::io_context&, const PluginInfo&)`
|
||||
* function to create the `TSockets` instance.
|
||||
*
|
||||
* @throw std::runtime_error Thrown when the Wine plugin host could not be
|
||||
* found, or if it could not locate and load a VST3 module.
|
||||
*/
|
||||
template <typename F>
|
||||
PluginBridge(PluginType plugin_type, F create_socket_instance)
|
||||
template <invocable_returning<TSockets,
|
||||
boost::asio::io_context&,
|
||||
const PluginInfo&> F>
|
||||
PluginBridge(PluginType plugin_type, F&& create_socket_instance)
|
||||
// This is still correct for VST3 plugins because we can configure an
|
||||
// entire directory (the module's bundle) at once
|
||||
: config(load_config_for(get_this_file_location())),
|
||||
|
||||
@@ -136,12 +136,11 @@ class Vst3PlugViewProxyImpl : public Vst3PlugViewProxy {
|
||||
* right now.
|
||||
*
|
||||
* @see Vst3HostBridge::send_mutually_recursive_message
|
||||
*
|
||||
* TODO: As mentioned elsewhere, refactor these functions to use
|
||||
* `std::invoke_result_t`
|
||||
*/
|
||||
template <typename T, typename F>
|
||||
T run_gui_task(F fn) {
|
||||
template <std::invocable F>
|
||||
std::invoke_result_t<F> run_gui_task(F&& fn) {
|
||||
using Result = std::invoke_result_t<F>;
|
||||
|
||||
// If `Vst3Bridge::send_mutually_recursive_message()` is currently being
|
||||
// called (because the host is calling one of `IPlugView`'s methods from
|
||||
// its UGI thread), then we'll call `fn` from that same thread.
|
||||
@@ -154,8 +153,8 @@ class Vst3PlugViewProxyImpl : public Vst3PlugViewProxy {
|
||||
}
|
||||
|
||||
if (run_loop_tasks) {
|
||||
std::packaged_task<T()> do_call(std::move(fn));
|
||||
std::future<T> do_call_response = do_call.get_future();
|
||||
std::packaged_task<Result()> do_call(std::forward<F>(fn));
|
||||
std::future<Result> do_call_response = do_call.get_future();
|
||||
|
||||
run_loop_tasks->schedule(std::move(do_call));
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ Vst3PluginBridge::Vst3PluginBridge()
|
||||
// loop or else it will likely segfault at some point
|
||||
return plugin_proxies.at(request.owner_instance_id)
|
||||
.get()
|
||||
.last_created_plug_view->run_gui_task<tresult>([&]() {
|
||||
.last_created_plug_view->run_gui_task([&]() -> tresult {
|
||||
return plugin_proxies.at(request.owner_instance_id)
|
||||
.get()
|
||||
.context_menus.at(request.context_menu_id)
|
||||
@@ -285,7 +285,7 @@ Vst3PluginBridge::Vst3PluginBridge()
|
||||
|
||||
// REAPER requires this to be run from its provided event
|
||||
// loop or else it will likely segfault at some point
|
||||
return plug_view->run_gui_task<tresult>([&]() {
|
||||
return plug_view->run_gui_task([&]() -> tresult {
|
||||
return plug_view->plug_frame->resizeView(
|
||||
plug_view, &request.new_size);
|
||||
});
|
||||
|
||||
@@ -165,7 +165,7 @@ class Vst3PluginBridge : PluginBridge<Vst3Sockets<std::jthread>> {
|
||||
*
|
||||
* @see Vst3PlugViewProxyImpl::run_gui_task
|
||||
*/
|
||||
template <typename F>
|
||||
template <std::invocable F>
|
||||
std::optional<std::invoke_result_t<F>> maybe_run_on_mutual_recursion_thread(
|
||||
F&& fn) {
|
||||
return mutual_recursion.maybe_handle(std::forward<F>(fn));
|
||||
|
||||
Reference in New Issue
Block a user