From 8aeb3d4d2107ab6adb511f86c8c5ce6240136213 Mon Sep 17 00:00:00 2001 From: Mattias D <52885812+madah81pnz1@users.noreply.github.com> Date: Wed, 19 Feb 2025 09:09:29 +0100 Subject: [PATCH 01/15] Fix no newline at end of file (#72) --- include/clap/helpers/checking-level.hh | 2 +- include/clap/helpers/misbehaviour-handler.hh | 2 +- include/clap/helpers/param-queue.hh | 2 +- include/clap/helpers/preset-discovery-indexer.hxx | 2 +- include/clap/helpers/reducing-param-queue.hh | 2 +- include/clap/helpers/reducing-param-queue.hxx | 2 +- tests/create-an-actual-plugin.cc | 2 +- tests/event-list-tests.cc | 2 +- tests/hex-encoder.cc | 2 +- tests/main.cc | 2 +- tests/param-queue-tests.cc | 2 +- tests/plugin.cc | 2 +- tests/preset-discovery-indexer.cc | 2 +- tests/preset-discovery-metadata-receiver.cc | 2 +- tests/preset-discovery-provider.cc | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/clap/helpers/checking-level.hh b/include/clap/helpers/checking-level.hh index b0a9619..8336261 100644 --- a/include/clap/helpers/checking-level.hh +++ b/include/clap/helpers/checking-level.hh @@ -6,4 +6,4 @@ namespace clap { namespace helpers { Minimal, Maximal, }; -}} // namespace clap::helpers \ No newline at end of file +}} // namespace clap::helpers diff --git a/include/clap/helpers/misbehaviour-handler.hh b/include/clap/helpers/misbehaviour-handler.hh index 754a46e..c627d2b 100644 --- a/include/clap/helpers/misbehaviour-handler.hh +++ b/include/clap/helpers/misbehaviour-handler.hh @@ -5,4 +5,4 @@ namespace clap { namespace helpers { Ignore, Terminate, }; -}} // namespace clap::helpers \ No newline at end of file +}} // namespace clap::helpers diff --git a/include/clap/helpers/param-queue.hh b/include/clap/helpers/param-queue.hh index 155d427..4f72702 100644 --- a/include/clap/helpers/param-queue.hh +++ b/include/clap/helpers/param-queue.hh @@ -71,4 +71,4 @@ namespace clap { namespace helpers { std::atomic _writeOffset = {0}; std::atomic _readOffset = {0}; }; -}} // namespace clap::helpers \ No newline at end of file +}} // namespace clap::helpers diff --git a/include/clap/helpers/preset-discovery-indexer.hxx b/include/clap/helpers/preset-discovery-indexer.hxx index bbffc75..64455fc 100644 --- a/include/clap/helpers/preset-discovery-indexer.hxx +++ b/include/clap/helpers/preset-discovery-indexer.hxx @@ -61,4 +61,4 @@ namespace clap { namespace helpers { auto &self = from(indexer); return self.extension(id); } -}} // namespace clap::helpers \ No newline at end of file +}} // namespace clap::helpers diff --git a/include/clap/helpers/reducing-param-queue.hh b/include/clap/helpers/reducing-param-queue.hh index 13c3934..04c3aa0 100644 --- a/include/clap/helpers/reducing-param-queue.hh +++ b/include/clap/helpers/reducing-param-queue.hh @@ -45,4 +45,4 @@ namespace clap { namespace helpers { std::atomic _producer = nullptr; std::atomic _consumer = nullptr; }; -}} // namespace clap::helpers \ No newline at end of file +}} // namespace clap::helpers diff --git a/include/clap/helpers/reducing-param-queue.hxx b/include/clap/helpers/reducing-param-queue.hxx index 99e5936..180d55d 100644 --- a/include/clap/helpers/reducing-param-queue.hxx +++ b/include/clap/helpers/reducing-param-queue.hxx @@ -69,4 +69,4 @@ namespace clap { namespace helpers { _free = _consumer.load(); _consumer = nullptr; } -}} // namespace clap::helpers \ No newline at end of file +}} // namespace clap::helpers diff --git a/tests/create-an-actual-plugin.cc b/tests/create-an-actual-plugin.cc index f6f625c..a223569 100644 --- a/tests/create-an-actual-plugin.cc +++ b/tests/create-an-actual-plugin.cc @@ -39,4 +39,4 @@ CATCH_TEST_CASE("Create an Actual Plugin") { CATCH_REQUIRE(std::is_constructible::value); } -} \ No newline at end of file +} diff --git a/tests/event-list-tests.cc b/tests/event-list-tests.cc index 80935cf..454e0a5 100644 --- a/tests/event-list-tests.cc +++ b/tests/event-list-tests.cc @@ -40,4 +40,4 @@ namespace { CATCH_CHECK(ev->buffer[i] == i); } -} // namespace \ No newline at end of file +} // namespace diff --git a/tests/hex-encoder.cc b/tests/hex-encoder.cc index 9c4c485..65b41f2 100644 --- a/tests/hex-encoder.cc +++ b/tests/hex-encoder.cc @@ -26,4 +26,4 @@ namespace { CATCH_TEST_CASE("hex decoder - bad length") { CATCH_CHECK_THROWS(clap::helpers::hex_decode("f3d")); } -} // namespace \ No newline at end of file +} // namespace diff --git a/tests/main.cc b/tests/main.cc index cbcca02..2c344d5 100644 --- a/tests/main.cc +++ b/tests/main.cc @@ -1,2 +1,2 @@ #define CATCH_CONFIG_MAIN -#include \ No newline at end of file +#include diff --git a/tests/param-queue-tests.cc b/tests/param-queue-tests.cc index ee449fa..b12d32a 100644 --- a/tests/param-queue-tests.cc +++ b/tests/param-queue-tests.cc @@ -69,4 +69,4 @@ namespace { CATCH_CHECK(!failed); } -} // namespace \ No newline at end of file +} // namespace diff --git a/tests/plugin.cc b/tests/plugin.cc index 18267c9..13b3ad1 100644 --- a/tests/plugin.cc +++ b/tests/plugin.cc @@ -34,4 +34,4 @@ CATCH_TEST_CASE("Plugin - Link") { clap::helpers::CheckingLevel::None> *p2 = nullptr; clap::helpers::Plugin *p3 = nullptr; -} \ No newline at end of file +} diff --git a/tests/preset-discovery-indexer.cc b/tests/preset-discovery-indexer.cc index fe58905..937ffd2 100644 --- a/tests/preset-discovery-indexer.cc +++ b/tests/preset-discovery-indexer.cc @@ -20,4 +20,4 @@ CATCH_TEST_CASE("PresetDiscoveryIndexer - Link") { clap::helpers::CheckingLevel::None> *p2 = nullptr; clap::helpers::PresetDiscoveryIndexer *p3 = nullptr; -} \ No newline at end of file +} diff --git a/tests/preset-discovery-metadata-receiver.cc b/tests/preset-discovery-metadata-receiver.cc index 713b07a..91c846b 100644 --- a/tests/preset-discovery-metadata-receiver.cc +++ b/tests/preset-discovery-metadata-receiver.cc @@ -27,4 +27,4 @@ CATCH_TEST_CASE("PresetDiscoveryMetadataReceiver - Link") { clap::helpers::PresetDiscoveryMetadataReceiver *p3 = nullptr; -} \ No newline at end of file +} diff --git a/tests/preset-discovery-provider.cc b/tests/preset-discovery-provider.cc index 9ee48ba..4218f75 100644 --- a/tests/preset-discovery-provider.cc +++ b/tests/preset-discovery-provider.cc @@ -20,4 +20,4 @@ CATCH_TEST_CASE("PresetDiscoveryProvider - Link") { clap::helpers::CheckingLevel::None> *p2 = nullptr; clap::helpers::PresetDiscoveryProvider *p3 = nullptr; -} \ No newline at end of file +} From aa83251d428db11efc7a9e53341dfb86dfcb4d7d Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Sat, 8 Mar 2025 18:35:14 +0100 Subject: [PATCH 02/15] Initial work for CLAP 1.2.6 --- include/clap/helpers/host-proxy.hh | 1 + include/clap/helpers/host-proxy.hxx | 14 ++++++++++++++ include/clap/helpers/plugin.hh | 20 +++++++++++++------- include/clap/helpers/plugin.hxx | 27 +++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index ae82eac..4e864f1 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -213,6 +213,7 @@ namespace clap { namespace helpers { bool canUseMiniCurveDisplay() const noexcept; void miniCurveDisplaySetDynamic(bool is_dynamic) const noexcept; void miniCurveDisplayChanged(uint32_t flags) const noexcept; + bool miniCurveDisplayGetHints(uint32_t kind, clap_mini_display_curve_hints_t *hints) const noexcept; protected: void ensureMainThread(const char *method) const noexcept; diff --git a/include/clap/helpers/host-proxy.hxx b/include/clap/helpers/host-proxy.hxx index 9fd10c0..5c5c614 100644 --- a/include/clap/helpers/host-proxy.hxx +++ b/include/clap/helpers/host-proxy.hxx @@ -806,4 +806,18 @@ namespace clap { namespace helpers { _hostMiniCurveDisplay->changed(_host, flags); } + template + bool HostProxy::miniCurveDisplayGetHints( + uint32_t kind, clap_mini_display_curve_hints_t *hints) const noexcept { + assert(canUseMiniCurveDisplay()); + ensureMainThread("mini_curve_display_get_hints"); + + if (!hints) { + pluginMisbehaving("mini_curve_display_get_hints() called with a null hints pointer"); + return false; + } + + return _hostMiniCurveDisplay->get_hints(_host, kind, hints); + } + }} // namespace clap::helpers diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index 56482cc..b62bfed 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -339,12 +339,16 @@ namespace clap { namespace helpers { // clap_plugin_mini_curve_display // //--------------------------------// virtual bool implementsMiniCurveDisplay() const noexcept { return false; } - virtual bool miniCurveDisplayRender(uint16_t *data, uint32_t data_size) noexcept { - return false; + virtual uint32_t miniCurveDisplayGetCurveCount() const noexcept { return 0; } + virtual uint32_t miniCurveDisplayRender(clap_mini_display_curve_data_t *data, + uint32_t data_size) noexcept { + return 0; } virtual void miniCurveDisplaySetObserved(bool is_observed) noexcept {} - virtual bool - miniCurveDisplayGetAxisName(char *x_name, char *y_name, uint32_t name_capacity) noexcept { + virtual bool miniCurveDisplayGetAxisName(uint32_t curve_index, + char *x_name, + char *y_name, + uint32_t name_capacity) noexcept { return false; } @@ -640,12 +644,14 @@ namespace clap { namespace helpers { static double clapGainAdjustmentMeteringGet(const clap_plugin_t *plugin) noexcept; // clap_plugin_mini_curve_display - static bool clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - uint16_t *data, - uint32_t data_size) noexcept; + static uint32_t clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept; + static uint32_t clapMiniCurveDisplayRender(const clap_plugin_t *plugin, + clap_mini_display_curve_data_t *data, + uint32_t data_size) noexcept; static void clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, bool is_observed) noexcept; static bool clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, + uint32_t curve_index, char *x_name, char *y_name, uint32_t name_capacity) noexcept; diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index 8b15261..f70bf0b 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -183,6 +183,7 @@ namespace clap { namespace helpers { template const clap_plugin_mini_curve_display Plugin::_pluginMiniCurveDisplay = { + clapMiniCurveDisplayGetCurveCount, clapMiniCurveDisplayRender, clapMiniCurveDisplaySetObserved, clapMiniCurveDisplayGetAxisName, @@ -1870,9 +1871,9 @@ namespace clap { namespace helpers { // clap_plugin_mini_curve_display // //--------------------------------// template - bool Plugin::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - uint16_t *data, - uint32_t data_size) noexcept { + uint32_t Plugin::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, + clap_mini_display_curve_data_t *data, + uint32_t data_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.render"); @@ -1902,8 +1903,17 @@ namespace clap { namespace helpers { self.miniCurveDisplaySetObserved(is_observed); } + template + uint32_t Plugin::clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_plugin_mini_curve_display.get_curve_count"); + + return self.miniCurveDisplayGetCurveCount(); + } + template bool Plugin::clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, + uint32_t curve_index, char *x_name, char *y_name, uint32_t name_capacity) noexcept { @@ -1916,9 +1926,18 @@ namespace clap { namespace helpers { "clap_plugin_mini_curve_display.get_axis_name() called with null name pointer(s)"); return false; } + + const auto curve_count = self.miniCurveDisplayGetCurveCount(); + if (curve_index >= curve_count) { + std::ostringstream os; + os << "clap_plugin_mini_curve_display.get_axis_name() called with curve_index = " + << curve_index << ", while the curve count is " << curve_count; + self.hostMisbehaving(os.str()); + return false; + } } - return self.miniCurveDisplayGetAxisName(x_name, y_name, name_capacity); + return self.miniCurveDisplayGetAxisName(curve_index, x_name, y_name, name_capacity); } ///////////// From 5dc4b8be9169207f30a82793f8e5b75b0b15f56a Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Sun, 9 Mar 2025 00:51:22 +0100 Subject: [PATCH 03/15] Better names --- include/clap/helpers/plugin.hh | 8 ++++---- include/clap/helpers/plugin.hxx | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index b62bfed..287f999 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -340,8 +340,8 @@ namespace clap { namespace helpers { //--------------------------------// virtual bool implementsMiniCurveDisplay() const noexcept { return false; } virtual uint32_t miniCurveDisplayGetCurveCount() const noexcept { return 0; } - virtual uint32_t miniCurveDisplayRender(clap_mini_display_curve_data_t *data, - uint32_t data_size) noexcept { + virtual uint32_t miniCurveDisplayRender(clap_mini_display_curve_data_t *curves, + uint32_t curves_size) noexcept { return 0; } virtual void miniCurveDisplaySetObserved(bool is_observed) noexcept {} @@ -646,8 +646,8 @@ namespace clap { namespace helpers { // clap_plugin_mini_curve_display static uint32_t clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept; static uint32_t clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - clap_mini_display_curve_data_t *data, - uint32_t data_size) noexcept; + clap_mini_display_curve_data_t *curves, + uint32_t curves_size) noexcept; static void clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, bool is_observed) noexcept; static bool clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index f70bf0b..4d22c05 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -1872,26 +1872,26 @@ namespace clap { namespace helpers { //--------------------------------// template uint32_t Plugin::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - clap_mini_display_curve_data_t *data, - uint32_t data_size) noexcept { + clap_mini_display_curve_data_t *curves, + uint32_t curves_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.render"); if (l >= CheckingLevel::Minimal) { - if (!data) { + if (!curves) { self.hostMisbehaving( "clap_plugin_mini_curve_display.render() called with null data pointer!!!"); return false; } - if (data_size == 0) { + if (curves_size == 0) { self.hostMisbehaving("clap_plugin_mini_curve_display.render() called an empty data " "array, meaningless..."); return false; } } - return self.miniCurveDisplayRender(data, data_size); + return self.miniCurveDisplayRender(curves, curves_size); } template From 2a37588b8e0838a376162023b8df7c8290e73214 Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Tue, 11 Mar 2025 08:51:03 +0100 Subject: [PATCH 04/15] Fix bad struct name --- include/clap/helpers/host-proxy.hh | 3 ++- include/clap/helpers/host-proxy.hxx | 2 +- include/clap/helpers/plugin.hh | 4 ++-- include/clap/helpers/plugin.hxx | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index 4e864f1..a0b3a2f 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -213,7 +213,8 @@ namespace clap { namespace helpers { bool canUseMiniCurveDisplay() const noexcept; void miniCurveDisplaySetDynamic(bool is_dynamic) const noexcept; void miniCurveDisplayChanged(uint32_t flags) const noexcept; - bool miniCurveDisplayGetHints(uint32_t kind, clap_mini_display_curve_hints_t *hints) const noexcept; + bool miniCurveDisplayGetHints(uint32_t kind, + clap_mini_curve_display_curve_hints_t *hints) const noexcept; protected: void ensureMainThread(const char *method) const noexcept; diff --git a/include/clap/helpers/host-proxy.hxx b/include/clap/helpers/host-proxy.hxx index 5c5c614..ac9f640 100644 --- a/include/clap/helpers/host-proxy.hxx +++ b/include/clap/helpers/host-proxy.hxx @@ -808,7 +808,7 @@ namespace clap { namespace helpers { template bool HostProxy::miniCurveDisplayGetHints( - uint32_t kind, clap_mini_display_curve_hints_t *hints) const noexcept { + uint32_t kind, clap_mini_curve_display_curve_hints_t *hints) const noexcept { assert(canUseMiniCurveDisplay()); ensureMainThread("mini_curve_display_get_hints"); diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index 287f999..84dc9da 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -340,7 +340,7 @@ namespace clap { namespace helpers { //--------------------------------// virtual bool implementsMiniCurveDisplay() const noexcept { return false; } virtual uint32_t miniCurveDisplayGetCurveCount() const noexcept { return 0; } - virtual uint32_t miniCurveDisplayRender(clap_mini_display_curve_data_t *curves, + virtual uint32_t miniCurveDisplayRender(clap_mini_curve_display_curve_data_t *curves, uint32_t curves_size) noexcept { return 0; } @@ -646,7 +646,7 @@ namespace clap { namespace helpers { // clap_plugin_mini_curve_display static uint32_t clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept; static uint32_t clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - clap_mini_display_curve_data_t *curves, + clap_mini_curve_display_curve_data_t *curves, uint32_t curves_size) noexcept; static void clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, bool is_observed) noexcept; diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index 4d22c05..d366fdf 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -1872,7 +1872,7 @@ namespace clap { namespace helpers { //--------------------------------// template uint32_t Plugin::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - clap_mini_display_curve_data_t *curves, + clap_mini_curve_display_curve_data_t *curves, uint32_t curves_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.render"); From c75ab5f828033744b013cb5834f6f2d05fcf6a35 Mon Sep 17 00:00:00 2001 From: Michael Fisher <880111+mfisher31@users.noreply.github.com> Date: Tue, 25 Mar 2025 07:05:10 -0400 Subject: [PATCH 05/15] Host Get Extension and Meson (#77) * * Add host getExtension() handler * Ignore generated files when used as a meson subproject * host/plugin: check overriden extension access before built-ins * host.hh: remove string_view include; not used. * plugin: call extension on the 'self' object --- .gitignore | 3 +++ include/clap/helpers/host.hh | 1 + include/clap/helpers/host.hxx | 3 +++ include/clap/helpers/plugin.hxx | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4ee5684..96a5983 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,6 @@ ignore/ build/ out/ .DS_Store + +# Meson +.meson-subproject* diff --git a/include/clap/helpers/host.hh b/include/clap/helpers/host.hh index 71f3b74..d712214 100644 --- a/include/clap/helpers/host.hh +++ b/include/clap/helpers/host.hh @@ -51,6 +51,7 @@ namespace clap { namespace helpers { virtual void requestCallback() noexcept = 0; virtual bool enableDraftExtensions() const noexcept { return false; } + virtual const void* getExtension(const char* extensionId) const noexcept { return nullptr; } // clap_host_audio_ports virtual bool implementsAudioPorts() const noexcept { return false; } diff --git a/include/clap/helpers/host.hxx b/include/clap/helpers/host.hxx index 428ebce..d0a6b1d 100644 --- a/include/clap/helpers/host.hxx +++ b/include/clap/helpers/host.hxx @@ -132,6 +132,8 @@ namespace clap { namespace helpers { const void *Host::clapGetExtension(const clap_host_t *host, const char *extension_id) noexcept { auto &self = from(host); + if (auto ext = self.getExtension(extension_id)) + return ext; if (!std::strcmp(extension_id, CLAP_EXT_AUDIO_PORTS) && self.implementsAudioPorts()) return &_hostAudioPorts; if (!std::strcmp(extension_id, CLAP_EXT_GUI) && self.implementsGui()) @@ -162,6 +164,7 @@ namespace clap { namespace helpers { if (self.enableDraftExtensions()) { // put draft ext here } + return nullptr; } diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index d366fdf..179cfcc 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -484,6 +484,8 @@ namespace clap { namespace helpers { auto &self = from(plugin); self.ensureInitialized("extension"); + if (auto ext = self.extension(id)) + return ext; if (!strcmp(id, CLAP_EXT_STATE) && self.implementsState()) return &_pluginState; if (!strcmp(id, CLAP_EXT_STATE_CONTEXT) && self.implementsStateContext() && @@ -554,7 +556,7 @@ namespace clap { namespace helpers { return &_pluginMiniCurveDisplay; } - return self.extension(id); + return nullptr; } //-------------------// From 4d8c96fd7da2a7a67a91cf87b008643d6ad2c9ba Mon Sep 17 00:00:00 2001 From: Schroedingers-Cat <6382400+Schroedingers-Cat@users.noreply.github.com> Date: Tue, 8 Jul 2025 13:35:52 +0000 Subject: [PATCH 06/15] Add base implementation of surround extension (#84) * Add base implementation of surround extension * Comment out windows clang test due to broken env * Remove wrong check #84#discussion_r2192490266 * Remove wrong check #84#discussion_r2192491651 --- .github/workflows/pullreq.yml | 10 ++++---- include/clap/helpers/host.hh | 8 ++++++ include/clap/helpers/host.hxx | 17 +++++++++++++ include/clap/helpers/plugin.hh | 22 +++++++++++++++++ include/clap/helpers/plugin.hxx | 44 +++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pullreq.yml b/.github/workflows/pullreq.yml index a9d916b..ac0c521 100644 --- a/.github/workflows/pullreq.yml +++ b/.github/workflows/pullreq.yml @@ -31,11 +31,11 @@ jobs: # name: Windows gcc/minGW # exe: .exe - - os: windows-latest - cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang - install_ninja: true - name: Windows clang - exe: .exe +# - os: windows-latest +# cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang +# install_ninja: true +# name: Windows clang +# exe: .exe - os: ubuntu-latest cmakeargs: -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_C_COMPILER=gcc-12 -DCLAP_HELPERS_TESTS_CXX_STANDARD=11 diff --git a/include/clap/helpers/host.hh b/include/clap/helpers/host.hh index d712214..4a9a9e7 100644 --- a/include/clap/helpers/host.hh +++ b/include/clap/helpers/host.hh @@ -108,6 +108,10 @@ namespace clap { namespace helpers { virtual bool implementsThreadPool() const noexcept { return false; } virtual bool threadPoolRequestExec(uint32_t numTasks) noexcept { return false; } + // clap_host_surround + virtual bool implementsSurround() const noexcept { return false; } + virtual void surroundChanged() noexcept {} + ///////////////////// // Thread Checking // ///////////////////// @@ -187,6 +191,9 @@ namespace clap { namespace helpers { // clap_host_thread_pool static bool clapThreadPoolRequestExec(const clap_host *host, uint32_t num_tasks) noexcept; + // clap_host_surround + static void clapSurroundChanged(const clap_host_t *host) noexcept; + // interfaces static const clap_host_audio_ports _hostAudioPorts; static const clap_host_gui _hostGui; @@ -200,5 +207,6 @@ namespace clap { namespace helpers { static const clap_host_tail _hostTail; static const clap_host_thread_check _hostThreadCheck; static const clap_host_thread_pool _hostThreadPool; + static const clap_host_surround _hostSurround; }; }} // namespace clap::helpers diff --git a/include/clap/helpers/host.hxx b/include/clap/helpers/host.hxx index d0a6b1d..c466d32 100644 --- a/include/clap/helpers/host.hxx +++ b/include/clap/helpers/host.hxx @@ -81,6 +81,11 @@ namespace clap { namespace helpers { clapThreadPoolRequestExec, }; + template + const clap_host_surround Host::_hostSurround = { + clapSurroundChanged, + }; + template Host::Host(const char *name, const char *vendor, const char *url, const char *version) : _host{ @@ -160,6 +165,8 @@ namespace clap { namespace helpers { return &_hostThreadCheck; if (!strcmp(extension_id, CLAP_EXT_THREAD_POOL) && self.implementsThreadPool()) return &_hostThreadPool; + if (!std::strcmp(extension_id, CLAP_EXT_SURROUND) && self.implementsSurround()) + return &_hostSurround; if (self.enableDraftExtensions()) { // put draft ext here @@ -397,6 +404,16 @@ namespace clap { namespace helpers { return self.threadPoolRequestExec(num_tasks); } + //--------------------// + // clap_host_surround // + //--------------------// + template + void Host::clapSurroundChanged(const clap_host *host) noexcept { + auto &self = from(host); + self.ensureMainThread("surround.changed"); + self.surroundChanged(); + } + ///////////////////// // Thread Checking // ///////////////////// diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index 84dc9da..e7a5c26 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -163,6 +163,18 @@ namespace clap { namespace helpers { return false; } + //----------------------// + // clap_plugin_surround // + //----------------------// + virtual bool implementsSurround() const noexcept { return false; } + virtual bool isChannelMaskSupported(uint64_t channel_mask) const noexcept { return false; } + virtual uint32_t getChannelMap(bool is_input, + uint32_t port_index, + uint8_t *channel_map, + uint32_t channel_map_capacity) const noexcept { + return 0; + } + //--------------------// // clap_plugin_params // //--------------------// @@ -505,6 +517,15 @@ namespace clap { namespace helpers { const clap_audio_port_configuration_request *requests, uint32_t request_count) noexcept; + // clap_plugin_surround + static bool clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin, + uint64_t channel_mask) noexcept; + static uint32_t clapSurroundGetChannelMap(const clap_plugin_t *plugin, + bool is_input, + uint32_t port_index, + uint8_t *channel_map, + uint32_t channel_map_capacity) noexcept; + // clap_plugin_params static uint32_t clapParamsCount(const clap_plugin *plugin) noexcept; static bool clapParamsInfo(const clap_plugin *plugin, @@ -661,6 +682,7 @@ namespace clap { namespace helpers { static const clap_plugin_audio_ports_config _pluginAudioPortsConfig; static const clap_plugin_audio_ports_activation _pluginAudioPortsActivation; static const clap_plugin_configurable_audio_ports _pluginConfigurableAudioPorts; + static const clap_plugin_surround_t _pluginSurroundConfig; static const clap_plugin_gui _pluginGui; static const clap_plugin_latency _pluginLatency; static const clap_plugin_note_name _pluginNoteName; diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index 179cfcc..f844101 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -69,6 +69,12 @@ namespace clap { namespace helpers { clapConfigurableAudioPortsApplyConfiguration, }; + template + const clap_plugin_surround_t Plugin::_pluginSurroundConfig = { + clapSurroundIsChannelMaskSupported, + clapSurroundGetChannelMap, + }; + template const clap_plugin_params Plugin::_pluginParams = { clapParamsCount, @@ -509,6 +515,8 @@ namespace clap { namespace helpers { return &_pluginAudioPortsActivation; if (!strcmp(id, CLAP_EXT_AUDIO_PORTS_CONFIG) && self.implementsAudioPortsConfig()) return &_pluginAudioPortsConfig; + if (!strcmp(id, CLAP_EXT_SURROUND) && self.implementsSurround()) + return &_pluginSurroundConfig; if (!strcmp(id, CLAP_EXT_CONFIGURABLE_AUDIO_PORTS) && self.implementsConfigurableAudioPorts()) return &_pluginConfigurableAudioPorts; if (!strcmp(id, CLAP_EXT_PARAMS) && self.implementsParams()) @@ -888,6 +896,42 @@ namespace clap { namespace helpers { return applyConfigurationSuccess; } + //----------------------// + // clap_plugin_surround // + //----------------------// + template + bool Plugin::clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin, + uint64_t channel_mask) noexcept { + auto &self = from(plugin); + auto methodName = "clap_plugin_surround.is_channel_mask_supported"; + self.ensureMainThread(methodName); + + return self.isChannelMaskSupported(channel_mask); + } + + template + uint32_t Plugin::clapSurroundGetChannelMap(const clap_plugin_t *plugin, + bool is_input, + uint32_t port_index, + uint8_t *channel_map, + uint32_t channel_map_capacity) noexcept { + auto &self = from(plugin); + auto methodName = "clap_plugin_surround.get_channel_map"; + self.ensureMainThread(methodName); + + const uint32_t channel_count = + self.getChannelMap(is_input, port_index, channel_map, channel_map_capacity); + + if (l >= CheckingLevel::Minimal && channel_count > channel_map_capacity) { + self._host.pluginMisbehaving( + "Plugin's functions clap_plugin_surround.get_channel_map cannot return a channel " + "count greater than channel_map_capacity."); + return channel_map_capacity; + } + + return channel_count; + } + //--------------------// // clap_plugin_params // //--------------------// From 08df762f1d7b00a9711fe74aa58af7f2cafcb55e Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Tue, 22 Jul 2025 12:15:23 +0200 Subject: [PATCH 07/15] Enable deriving from HostProxy --- include/clap/helpers/plugin.hh | 26 +- include/clap/helpers/plugin.hxx | 569 ++++++++++++++++---------------- 2 files changed, 310 insertions(+), 285 deletions(-) diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index e7a5c26..533ebd9 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -20,19 +20,19 @@ namespace clap { namespace helpers { /// /// @note for an higher level implementation, see @ref PluginHelper template - class Plugin { + class PluginBase { public: // not copyable, not moveable - Plugin(const Plugin &) = delete; - Plugin(Plugin &&) = delete; - Plugin &operator=(const Plugin &) = delete; - Plugin &operator=(Plugin &&) = delete; + PluginBase(const PluginBase &) = delete; + PluginBase(PluginBase &&) = delete; + PluginBase &operator=(const PluginBase &) = delete; + PluginBase &operator=(PluginBase &&) = delete; const clap_plugin *clapPlugin() noexcept { return &_plugin; } protected: - Plugin(const clap_plugin_descriptor *desc, const clap_host *host); - virtual ~Plugin() = default; + PluginBase(const clap_plugin_descriptor &desc, HostProxy &hostProxy); + virtual ~PluginBase() = default; ///////////////////////// // Methods to override // @@ -398,7 +398,7 @@ namespace clap { namespace helpers { /////////////// // Utilities // /////////////// - static Plugin &from(const clap_plugin *plugin, bool requireInitialized = true) noexcept; + static PluginBase &from(const clap_plugin *plugin, bool requireInitialized = true) noexcept; // runs the callback immediately if on the main thread, otherwise queue it. // be aware that the callback may be ran during the plugin destruction phase, @@ -425,7 +425,7 @@ namespace clap { namespace helpers { bool isBeingDestroyed() const noexcept { return _isBeingDestroyed; } protected: - HostProxy _host; + HostProxy &_hostProxy; private: void ensureInitialized(const char *method) const noexcept; @@ -724,4 +724,12 @@ namespace clap { namespace helpers { std::mutex _mainThreadCallbacksLock; std::queue> _mainThreadCallbacks; }; + + // for compatibility. If you want to derive from HostProxy, use PluginBase instead + template + class Plugin : public PluginBase { + protected: + Plugin(const clap_plugin_descriptor *desc, const clap_host *host); + HostProxy _host; + }; }} // namespace clap::helpers diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index f844101..403cf46 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -14,69 +14,69 @@ namespace clap { namespace helpers { template - const clap_plugin_render Plugin::_pluginRender = { + const clap_plugin_render PluginBase::_pluginRender = { clapRenderHasHardRealtimeRequirement, clapRenderSetMode, }; template - const clap_plugin_thread_pool Plugin::_pluginThreadPool = { + const clap_plugin_thread_pool PluginBase::_pluginThreadPool = { clapThreadPoolExec, }; template - const clap_plugin_state Plugin::_pluginState = { + const clap_plugin_state PluginBase::_pluginState = { clapStateSave, clapStateLoad, }; template - const clap_plugin_state_context Plugin::_pluginStateContext = { + const clap_plugin_state_context PluginBase::_pluginStateContext = { clapStateContextSave, clapStateContextLoad, }; template - const clap_plugin_preset_load Plugin::_pluginPresetLoad = { + const clap_plugin_preset_load PluginBase::_pluginPresetLoad = { clapPresetLoadFromLocation, }; template - const clap_plugin_track_info Plugin::_pluginTrackInfo = { + const clap_plugin_track_info PluginBase::_pluginTrackInfo = { clapTrackInfoChanged, }; template - const clap_plugin_audio_ports Plugin::_pluginAudioPorts = {clapAudioPortsCount, - clapAudioPortsInfo}; + const clap_plugin_audio_ports PluginBase::_pluginAudioPorts = {clapAudioPortsCount, + clapAudioPortsInfo}; template - const clap_plugin_audio_ports_config Plugin::_pluginAudioPortsConfig = { + const clap_plugin_audio_ports_config PluginBase::_pluginAudioPortsConfig = { clapAudioPortsConfigCount, clapAudioPortsGetConfig, clapAudioPortsSetConfig, }; template - const clap_plugin_audio_ports_activation Plugin::_pluginAudioPortsActivation = { + const clap_plugin_audio_ports_activation PluginBase::_pluginAudioPortsActivation = { clapAudioPortsActivationCanActivateWhileProcessing, clapAudioPortsActivationSetActive, }; template - const clap_plugin_configurable_audio_ports Plugin::_pluginConfigurableAudioPorts = { + const clap_plugin_configurable_audio_ports PluginBase::_pluginConfigurableAudioPorts = { clapConfigurableAudioPortsCanApplyConfiguration, clapConfigurableAudioPortsApplyConfiguration, }; template - const clap_plugin_surround_t Plugin::_pluginSurroundConfig = { + const clap_plugin_surround_t PluginBase::_pluginSurroundConfig = { clapSurroundIsChannelMaskSupported, clapSurroundGetChannelMap, }; template - const clap_plugin_params Plugin::_pluginParams = { + const clap_plugin_params PluginBase::_pluginParams = { clapParamsCount, clapParamsInfo, clapParamsValue, @@ -86,40 +86,40 @@ namespace clap { namespace helpers { }; template - const clap_plugin_param_indication Plugin::_pluginParamIndication = { + const clap_plugin_param_indication PluginBase::_pluginParamIndication = { clapParamIndicationSetMapping, clapParamIndicationSetAutomation, }; template - const clap_plugin_remote_controls Plugin::_pluginRemoteControls = { + const clap_plugin_remote_controls PluginBase::_pluginRemoteControls = { clapRemoteControlsPageCount, clapRemoteControlsPageGet}; template - const clap_plugin_latency Plugin::_pluginLatency = { + const clap_plugin_latency PluginBase::_pluginLatency = { clapLatencyGet, }; template - const clap_plugin_note_ports Plugin::_pluginNotePorts = {clapNotePortsCount, - clapNotePortsInfo}; + const clap_plugin_note_ports PluginBase::_pluginNotePorts = {clapNotePortsCount, + clapNotePortsInfo}; template - const clap_plugin_note_name Plugin::_pluginNoteName = { + const clap_plugin_note_name PluginBase::_pluginNoteName = { clapNoteNameCount, clapNoteNameGet, }; template - const clap_plugin_timer_support Plugin::_pluginTimerSupport = {clapOnTimer}; + const clap_plugin_timer_support PluginBase::_pluginTimerSupport = {clapOnTimer}; template - const clap_plugin_posix_fd_support Plugin::_pluginPosixFdSupport = { + const clap_plugin_posix_fd_support PluginBase::_pluginPosixFdSupport = { clapOnPosixFd, }; template - const clap_plugin_gui Plugin::_pluginGui = { + const clap_plugin_gui PluginBase::_pluginGui = { clapGuiIsApiSupported, clapGuiGetPreferredApi, clapGuiCreate, @@ -138,13 +138,13 @@ namespace clap { namespace helpers { }; template - const clap_plugin_context_menu Plugin::_pluginContextMenu = { + const clap_plugin_context_menu PluginBase::_pluginContextMenu = { clapContextMenuPopulate, clapContextMenuPerform, }; template - const clap_plugin_resource_directory Plugin::_pluginResourceDirectory = { + const clap_plugin_resource_directory PluginBase::_pluginResourceDirectory = { clapResourceDirectorySetDirectory, clapResourceDirectoryCollect, clapResourceDirectoryGetFilesCount, @@ -152,17 +152,17 @@ namespace clap { namespace helpers { }; template - const clap_plugin_voice_info Plugin::_pluginVoiceInfo = { + const clap_plugin_voice_info PluginBase::_pluginVoiceInfo = { clapVoiceInfoGet, }; template - const clap_plugin_tail Plugin::_pluginTail = { + const clap_plugin_tail PluginBase::_pluginTail = { clapTailGet, }; template - const clap_plugin_undo_delta Plugin::_pluginUndoDelta = { + const clap_plugin_undo_delta PluginBase::_pluginUndoDelta = { clapUndoDeltaGetDeltaProperties, clapUndoDeltaCanUseDeltaFormatVersion, clapUndoDeltaUndo, @@ -170,7 +170,7 @@ namespace clap { namespace helpers { }; template - const clap_plugin_undo_context Plugin::_pluginUndoContext = { + const clap_plugin_undo_context PluginBase::_pluginUndoContext = { clapUndoContextSetCanUndo, clapUndoContextSetCanRedo, clapUndoContextSetUndoName, @@ -178,17 +178,17 @@ namespace clap { namespace helpers { }; template - const clap_plugin_project_location Plugin::_pluginProjectLocation = { + const clap_plugin_project_location PluginBase::_pluginProjectLocation = { clapProjectLocationSet, }; template - const clap_plugin_gain_adjustment_metering Plugin::_pluginGainAdjustmentMetering = { + const clap_plugin_gain_adjustment_metering PluginBase::_pluginGainAdjustmentMetering = { clapGainAdjustmentMeteringGet, }; template - const clap_plugin_mini_curve_display Plugin::_pluginMiniCurveDisplay = { + const clap_plugin_mini_curve_display PluginBase::_pluginMiniCurveDisplay = { clapMiniCurveDisplayGetCurveCount, clapMiniCurveDisplayRender, clapMiniCurveDisplaySetObserved, @@ -196,19 +196,20 @@ namespace clap { namespace helpers { }; template - Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : _host(host) { + PluginBase::PluginBase(const clap_plugin_descriptor &desc, HostProxy &hostProxy) + : _hostProxy(hostProxy) { _plugin.plugin_data = this; - _plugin.desc = desc; - _plugin.init = Plugin::clapInit; - _plugin.destroy = Plugin::clapDestroy; - _plugin.get_extension = Plugin::clapExtension; - _plugin.process = Plugin::clapProcess; - _plugin.activate = Plugin::clapActivate; - _plugin.deactivate = Plugin::clapDeactivate; - _plugin.start_processing = Plugin::clapStartProcessing; - _plugin.stop_processing = Plugin::clapStopProcessing; - _plugin.reset = Plugin::clapReset; - _plugin.on_main_thread = Plugin::clapOnMainThread; + _plugin.desc = &desc; + _plugin.init = PluginBase::clapInit; + _plugin.destroy = PluginBase::clapDestroy; + _plugin.get_extension = PluginBase::clapExtension; + _plugin.process = PluginBase::clapProcess; + _plugin.activate = PluginBase::clapActivate; + _plugin.deactivate = PluginBase::clapDeactivate; + _plugin.start_processing = PluginBase::clapStartProcessing; + _plugin.stop_processing = PluginBase::clapStopProcessing; + _plugin.reset = PluginBase::clapReset; + _plugin.on_main_thread = PluginBase::clapOnMainThread; } ///////////////////// @@ -219,7 +220,7 @@ namespace clap { namespace helpers { // clap_plugin // //-------------// template - bool Plugin::clapInit(const clap_plugin *plugin) noexcept { + bool PluginBase::clapInit(const clap_plugin *plugin) noexcept { auto &self = from(plugin, false); if (l >= CheckingLevel::Minimal && self._wasInitialized) { @@ -231,13 +232,13 @@ namespace clap { namespace helpers { self._wasInitialized = true; - self._host.init(); + self._hostProxy.init(); self.ensureMainThread("clap_plugin.init"); return self.init(); } template - void Plugin::ensureInitialized(const char *method) const noexcept { + void PluginBase::ensureInitialized(const char *method) const noexcept { if (l == CheckingLevel::None || _wasInitialized) return; @@ -249,20 +250,21 @@ namespace clap { namespace helpers { } template - void Plugin::clapDestroy(const clap_plugin *plugin) noexcept { + void PluginBase::clapDestroy(const clap_plugin *plugin) noexcept { auto &self = from(plugin, false); self.ensureMainThread("clap_plugin.destroy"); self._isBeingDestroyed = true; if (self._isGuiCreated) { if (l >= CheckingLevel::Minimal) - self._host.hostMisbehaving("host forgot to destroy the gui"); + self._hostProxy.hostMisbehaving("host forgot to destroy the gui"); clapGuiDestroy(plugin); } if (self._isActive) { if (l >= CheckingLevel::Minimal) - self._host.hostMisbehaving("host forgot to deactivate the plugin before destroying it"); + self._hostProxy.hostMisbehaving( + "host forgot to deactivate the plugin before destroying it"); clapDeactivate(plugin); } assert(!self._isActive); @@ -273,7 +275,7 @@ namespace clap { namespace helpers { } template - void Plugin::clapOnMainThread(const clap_plugin *plugin) noexcept { + void PluginBase::clapOnMainThread(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("on_maint_thread"); self.ensureMainThread("clap_plugin.on_main_thread"); @@ -283,10 +285,10 @@ namespace clap { namespace helpers { } template - void Plugin::runCallbacksOnMainThread() { + void PluginBase::runCallbacksOnMainThread() { if (l >= CheckingLevel::Minimal) { - if (_host.canUseThreadCheck() && !_host.isMainThread()) { - _host.pluginMisbehaving( + if (_hostProxy.canUseThreadCheck() && !_hostProxy.isMainThread()) { + _hostProxy.pluginMisbehaving( "plugin called runCallbacksOnMainThread(), but not on the main thread!"); return; } @@ -309,10 +311,10 @@ namespace clap { namespace helpers { } template - bool Plugin::clapActivate(const clap_plugin *plugin, - double sample_rate, - uint32_t minFrameCount, - uint32_t maxFrameCount) noexcept { + bool PluginBase::clapActivate(const clap_plugin *plugin, + double sample_rate, + uint32_t minFrameCount, + uint32_t maxFrameCount) noexcept { auto &self = from(plugin); self.ensureInitialized("activate"); self.ensureMainThread("clap_plugin.activate"); @@ -383,7 +385,7 @@ namespace clap { namespace helpers { } template - void Plugin::clapDeactivate(const clap_plugin *plugin) noexcept { + void PluginBase::clapDeactivate(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("deactivate"); self.ensureMainThread("clap_plugin.deactivate"); @@ -401,7 +403,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapStartProcessing(const clap_plugin *plugin) noexcept { + bool PluginBase::clapStartProcessing(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("start_processing"); self.ensureAudioThread("clap_plugin.start_processing"); @@ -424,7 +426,7 @@ namespace clap { namespace helpers { } template - void Plugin::clapStopProcessing(const clap_plugin *plugin) noexcept { + void PluginBase::clapStopProcessing(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("stop_processing"); self.ensureAudioThread("clap_plugin.stop_processing"); @@ -447,7 +449,7 @@ namespace clap { namespace helpers { } template - void Plugin::clapReset(const clap_plugin *plugin) noexcept { + void PluginBase::clapReset(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("reset"); self.ensureAudioThread("clap_plugin.reset"); @@ -463,8 +465,8 @@ namespace clap { namespace helpers { } template - clap_process_status Plugin::clapProcess(const clap_plugin *plugin, - const clap_process *process) noexcept { + clap_process_status PluginBase::clapProcess(const clap_plugin *plugin, + const clap_process *process) noexcept { auto &self = from(plugin); self.ensureInitialized("process"); self.ensureAudioThread("clap_plugin.process"); @@ -486,7 +488,7 @@ namespace clap { namespace helpers { } template - const void *Plugin::clapExtension(const clap_plugin *plugin, const char *id) noexcept { + const void *PluginBase::clapExtension(const clap_plugin *plugin, const char *id) noexcept { auto &self = from(plugin); self.ensureInitialized("extension"); @@ -571,7 +573,7 @@ namespace clap { namespace helpers { // clap_plugin_state // //-------------------// template - uint32_t Plugin::clapLatencyGet(const clap_plugin *plugin) noexcept { + uint32_t PluginBase::clapLatencyGet(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_latency.get"); @@ -589,7 +591,7 @@ namespace clap { namespace helpers { // clap_plugin_tail // //------------------// template - uint32_t Plugin::clapTailGet(const clap_plugin_t *plugin) noexcept { + uint32_t PluginBase::clapTailGet(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); if (l >= CheckingLevel::Minimal) { @@ -606,15 +608,15 @@ namespace clap { namespace helpers { // clap_plugin_render // //--------------------// template - bool Plugin::clapRenderHasHardRealtimeRequirement(const clap_plugin *plugin) noexcept { + bool PluginBase::clapRenderHasHardRealtimeRequirement(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_render.has_hard_realtime_requirement"); return self.renderHasHardRealtimeRequirement(); } template - bool Plugin::clapRenderSetMode(const clap_plugin *plugin, - clap_plugin_render_mode mode) noexcept { + bool PluginBase::clapRenderSetMode(const clap_plugin *plugin, + clap_plugin_render_mode mode) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_render.set_mode"); @@ -641,7 +643,8 @@ namespace clap { namespace helpers { // clap_plugin_thread_pool // //-------------------------// template - void Plugin::clapThreadPoolExec(const clap_plugin *plugin, uint32_t task_index) noexcept { + void PluginBase::clapThreadPoolExec(const clap_plugin *plugin, + uint32_t task_index) noexcept { auto &self = from(plugin); self.threadPoolExec(task_index); @@ -651,8 +654,8 @@ namespace clap { namespace helpers { // clap_plugin_state // //-------------------// template - bool Plugin::clapStateSave(const clap_plugin *plugin, - const clap_ostream *stream) noexcept { + bool PluginBase::clapStateSave(const clap_plugin *plugin, + const clap_ostream *stream) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state.save"); @@ -660,8 +663,8 @@ namespace clap { namespace helpers { } template - bool Plugin::clapStateLoad(const clap_plugin *plugin, - const clap_istream *stream) noexcept { + bool PluginBase::clapStateLoad(const clap_plugin *plugin, + const clap_istream *stream) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state.load"); @@ -672,9 +675,9 @@ namespace clap { namespace helpers { // clap_plugin_state_context // //---------------------------// template - bool Plugin::clapStateContextSave(const clap_plugin *plugin, - const clap_ostream *stream, - uint32_t context) noexcept { + bool PluginBase::clapStateContextSave(const clap_plugin *plugin, + const clap_ostream *stream, + uint32_t context) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state_context.save"); @@ -682,9 +685,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapStateContextLoad(const clap_plugin *plugin, - const clap_istream *stream, - uint32_t context) noexcept { + bool PluginBase::clapStateContextLoad(const clap_plugin *plugin, + const clap_istream *stream, + uint32_t context) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state_context.load"); @@ -695,10 +698,10 @@ namespace clap { namespace helpers { // clap_plugin_preset_load // //-------------------------// template - bool Plugin::clapPresetLoadFromLocation(const clap_plugin *plugin, - uint32_t location_kind, - const char *location, - const char *load_key) noexcept { + bool PluginBase::clapPresetLoadFromLocation(const clap_plugin *plugin, + uint32_t location_kind, + const char *location, + const char *load_key) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_preset_load.from_location"); @@ -718,12 +721,12 @@ namespace clap { namespace helpers { // clap_plugin_track_info // //------------------------// template - void Plugin::clapTrackInfoChanged(const clap_plugin *plugin) noexcept { + void PluginBase::clapTrackInfoChanged(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_track_info.changed"); if (l >= CheckingLevel::Minimal) { - if (!self._host.canUseTrackInfo()) { + if (!self._hostProxy.canUseTrackInfo()) { self.hostMisbehaving( "host called clap_plugin_track_info.changed() but does not provide a " "complete clap_host_track_info interface"); @@ -738,7 +741,8 @@ namespace clap { namespace helpers { // clap_plugin_audio_ports // //-------------------------// template - uint32_t Plugin::clapAudioPortsCount(const clap_plugin *plugin, bool is_input) noexcept { + uint32_t PluginBase::clapAudioPortsCount(const clap_plugin *plugin, + bool is_input) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.count"); @@ -746,10 +750,10 @@ namespace clap { namespace helpers { } template - bool Plugin::clapAudioPortsInfo(const clap_plugin *plugin, - uint32_t index, - bool is_input, - clap_audio_port_info *info) noexcept { + bool PluginBase::clapAudioPortsInfo(const clap_plugin *plugin, + uint32_t index, + bool is_input, + clap_audio_port_info *info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.info"); @@ -768,16 +772,16 @@ namespace clap { namespace helpers { } template - uint32_t Plugin::clapAudioPortsConfigCount(const clap_plugin *plugin) noexcept { + uint32_t PluginBase::clapAudioPortsConfigCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.config_count"); return self.audioPortsConfigCount(); } template - bool Plugin::clapAudioPortsGetConfig(const clap_plugin *plugin, - uint32_t index, - clap_audio_ports_config *config) noexcept { + bool PluginBase::clapAudioPortsGetConfig(const clap_plugin *plugin, + uint32_t index, + clap_audio_ports_config *config) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.get_config"); @@ -795,8 +799,8 @@ namespace clap { namespace helpers { } template - bool Plugin::clapAudioPortsSetConfig(const clap_plugin *plugin, - clap_id config_id) noexcept { + bool PluginBase::clapAudioPortsSetConfig(const clap_plugin *plugin, + clap_id config_id) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.set_config"); @@ -812,7 +816,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapAudioPortsActivationCanActivateWhileProcessing( + bool PluginBase::clapAudioPortsActivationCanActivateWhileProcessing( const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports_activation.can_activate_while_processing"); @@ -821,11 +825,11 @@ namespace clap { namespace helpers { } template - bool Plugin::clapAudioPortsActivationSetActive(const clap_plugin_t *plugin, - bool is_input, - uint32_t port_index, - bool is_active, - uint32_t sample_size) noexcept { + bool PluginBase::clapAudioPortsActivationSetActive(const clap_plugin_t *plugin, + bool is_input, + uint32_t port_index, + bool is_active, + uint32_t sample_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports_activation.set_active"); @@ -843,7 +847,7 @@ namespace clap { namespace helpers { } template - uint32_t Plugin::clapParamsCount(const clap_plugin *plugin) noexcept { + uint32_t PluginBase::clapParamsCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.count"); @@ -855,7 +859,7 @@ namespace clap { namespace helpers { //--------------------------------------// template - bool Plugin::clapConfigurableAudioPortsCanApplyConfiguration( + bool PluginBase::clapConfigurableAudioPortsCanApplyConfiguration( const clap_plugin_t *plugin, const clap_audio_port_configuration_request *requests, uint32_t request_count) noexcept { @@ -868,7 +872,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapConfigurableAudioPortsApplyConfiguration( + bool PluginBase::clapConfigurableAudioPortsApplyConfiguration( const clap_plugin_t *plugin, const clap_audio_port_configuration_request *requests, uint32_t request_count) noexcept { @@ -887,7 +891,7 @@ namespace clap { namespace helpers { self.configurableAudioPortsApplyConfiguration(requests, request_count); if (l >= CheckingLevel::Minimal && canApplyConfiguration != applyConfigurationSuccess) { - self._host.pluginMisbehaving( + self._hostProxy.pluginMisbehaving( "Plugin's functions clap_plugin_configurable_audio_ports.can_apply_configuration and " "clap_plugin_configurable_audio_ports.apply_configuration returned different values " "for the same configuration."); @@ -900,8 +904,8 @@ namespace clap { namespace helpers { // clap_plugin_surround // //----------------------// template - bool Plugin::clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin, - uint64_t channel_mask) noexcept { + bool PluginBase::clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin, + uint64_t channel_mask) noexcept { auto &self = from(plugin); auto methodName = "clap_plugin_surround.is_channel_mask_supported"; self.ensureMainThread(methodName); @@ -910,11 +914,11 @@ namespace clap { namespace helpers { } template - uint32_t Plugin::clapSurroundGetChannelMap(const clap_plugin_t *plugin, - bool is_input, - uint32_t port_index, - uint8_t *channel_map, - uint32_t channel_map_capacity) noexcept { + uint32_t PluginBase::clapSurroundGetChannelMap(const clap_plugin_t *plugin, + bool is_input, + uint32_t port_index, + uint8_t *channel_map, + uint32_t channel_map_capacity) noexcept { auto &self = from(plugin); auto methodName = "clap_plugin_surround.get_channel_map"; self.ensureMainThread(methodName); @@ -923,7 +927,7 @@ namespace clap { namespace helpers { self.getChannelMap(is_input, port_index, channel_map, channel_map_capacity); if (l >= CheckingLevel::Minimal && channel_count > channel_map_capacity) { - self._host.pluginMisbehaving( + self._hostProxy.pluginMisbehaving( "Plugin's functions clap_plugin_surround.get_channel_map cannot return a channel " "count greater than channel_map_capacity."); return channel_map_capacity; @@ -936,9 +940,9 @@ namespace clap { namespace helpers { // clap_plugin_params // //--------------------// template - bool Plugin::clapParamsInfo(const clap_plugin *plugin, - uint32_t param_index, - clap_param_info *param_info) noexcept { + bool PluginBase::clapParamsInfo(const clap_plugin *plugin, + uint32_t param_index, + clap_param_info *param_info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.info"); @@ -958,16 +962,16 @@ namespace clap { namespace helpers { if (l >= CheckingLevel::Maximal && !res) { std::ostringstream os; os << "clap_plugin_params.info(" << param_index << ") failed"; - self._host.pluginMisbehaving(os.str()); + self._hostProxy.pluginMisbehaving(os.str()); } return res; } template - bool Plugin::clapParamsValue(const clap_plugin *plugin, - clap_id paramId, - double *value) noexcept { + bool PluginBase::clapParamsValue(const clap_plugin *plugin, + clap_id paramId, + double *value) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.value"); @@ -989,7 +993,7 @@ namespace clap { namespace helpers { std::ostringstream msg; msg << "clap_plugin_params.value(" << paramId << ") = " << *value << ", is out of range [" << info.min_value << " .. " << info.max_value << "]"; - self._host.pluginMisbehaving(msg.str()); + self._hostProxy.pluginMisbehaving(msg.str()); } } } @@ -998,9 +1002,9 @@ namespace clap { namespace helpers { } template - void Plugin::clapParamsFlush(const clap_plugin *plugin, - const clap_input_events *in, - const clap_output_events *out) noexcept { + void PluginBase::clapParamsFlush(const clap_plugin *plugin, + const clap_input_events *in, + const clap_output_events *out) noexcept { auto &self = from(plugin); self.ensureParamThread("clap_plugin_params.flush"); @@ -1037,7 +1041,7 @@ namespace clap { namespace helpers { auto pev = reinterpret_cast(ev); - if (self._host.canUseThreadCheck() && self._host.isMainThread() && + if (self._hostProxy.canUseThreadCheck() && self._hostProxy.isMainThread() && !self.isValidParamId(pev->param_id)) { std::ostringstream msg; msg << "clap_plugin_params.flush called unknown paramId: " << pev->param_id; @@ -1052,7 +1056,7 @@ namespace clap { namespace helpers { msg << "clap_plugin_params.flush() produced the value " << pev->value << " for parameter " << pev->param_id << " which is out of bounds: [" << info.min_value << " .. " << info.max_value << "]"; - self._host.pluginMisbehaving(msg.str()); + self._hostProxy.pluginMisbehaving(msg.str()); } } } @@ -1067,11 +1071,11 @@ namespace clap { namespace helpers { } template - bool Plugin::clapParamsValueToText(const clap_plugin *plugin, - clap_id param_id, - double value, - char *display, - uint32_t size) noexcept { + bool PluginBase::clapParamsValueToText(const clap_plugin *plugin, + clap_id param_id, + double value, + char *display, + uint32_t size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.value_to_text"); @@ -1114,10 +1118,10 @@ namespace clap { namespace helpers { } template - bool Plugin::clapParamsTextToValue(const clap_plugin *plugin, - clap_id param_id, - const char *display, - double *value) noexcept { + bool PluginBase::clapParamsTextToValue(const clap_plugin *plugin, + clap_id param_id, + const char *display, + double *value) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.text_to_value"); @@ -1153,7 +1157,7 @@ namespace clap { namespace helpers { msg << "clap_plugin_params.text_to_value() produced the value " << value << " for parameter " << param_id << " which is out of bounds: [" << info.min_value << " .. " << info.max_value << "]"; - self._host.pluginMisbehaving(msg.str()); + self._hostProxy.pluginMisbehaving(msg.str()); } } } @@ -1161,7 +1165,7 @@ namespace clap { namespace helpers { } template - int32_t Plugin::getParamIndexForParamId(clap_id param_id) const noexcept { + int32_t PluginBase::getParamIndexForParamId(clap_id param_id) const noexcept { checkMainThread(); const auto count = paramsCount(); @@ -1178,8 +1182,8 @@ namespace clap { namespace helpers { } template - bool Plugin::getParamInfoForParamId(clap_id paramId, - clap_param_info *info) const noexcept { + bool PluginBase::getParamInfoForParamId(clap_id paramId, + clap_param_info *info) const noexcept { checkMainThread(); const auto count = paramsCount(); @@ -1191,7 +1195,7 @@ namespace clap { namespace helpers { } template - bool Plugin::isValidParamId(clap_id param_id) const noexcept { + bool PluginBase::isValidParamId(clap_id param_id) const noexcept { checkMainThread(); return getParamIndexForParamId(param_id) != -1; @@ -1202,12 +1206,12 @@ namespace clap { namespace helpers { //------------------------------// template - void Plugin::clapParamIndicationSetMapping(const clap_plugin_t *plugin, - clap_id param_id, - bool has_mapping, - const clap_color_t *color, - const char *label, - const char *description) noexcept { + void PluginBase::clapParamIndicationSetMapping(const clap_plugin_t *plugin, + clap_id param_id, + bool has_mapping, + const clap_color_t *color, + const char *label, + const char *description) noexcept { auto &self = from(plugin); self.checkMainThread(); @@ -1225,10 +1229,10 @@ namespace clap { namespace helpers { } template - void Plugin::clapParamIndicationSetAutomation(const clap_plugin_t *plugin, - clap_id param_id, - uint32_t automation_state, - const clap_color_t *color) noexcept { + void PluginBase::clapParamIndicationSetAutomation(const clap_plugin_t *plugin, + clap_id param_id, + uint32_t automation_state, + const clap_color_t *color) noexcept { auto &self = from(plugin); self.checkMainThread(); @@ -1249,7 +1253,7 @@ namespace clap { namespace helpers { // clap_plugin_remote_controls // //----------------------------// template - uint32_t Plugin::clapRemoteControlsPageCount(const clap_plugin *plugin) noexcept { + uint32_t PluginBase::clapRemoteControlsPageCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_remote_controls.page_count"); @@ -1257,9 +1261,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapRemoteControlsPageGet(const clap_plugin *plugin, - uint32_t page_index, - clap_remote_controls_page *page) noexcept { + bool PluginBase::clapRemoteControlsPageGet(const clap_plugin *plugin, + uint32_t page_index, + clap_remote_controls_page *page) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_remote_controls.page_info"); @@ -1282,17 +1286,18 @@ namespace clap { namespace helpers { // clap_plugin_note_ports // //------------------------// template - uint32_t Plugin::clapNotePortsCount(const clap_plugin *plugin, bool is_input) noexcept { + uint32_t PluginBase::clapNotePortsCount(const clap_plugin *plugin, + bool is_input) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_port.count"); return self.notePortsCount(is_input); } template - bool Plugin::clapNotePortsInfo(const clap_plugin *plugin, - uint32_t index, - bool is_input, - clap_note_port_info *info) noexcept { + bool PluginBase::clapNotePortsInfo(const clap_plugin *plugin, + uint32_t index, + bool is_input, + clap_note_port_info *info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_ports.info"); @@ -1314,16 +1319,16 @@ namespace clap { namespace helpers { // clap_plugin_note_name // //-----------------------// template - uint32_t Plugin::clapNoteNameCount(const clap_plugin *plugin) noexcept { + uint32_t PluginBase::clapNoteNameCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_name.count"); return self.noteNameCount(); } template - bool Plugin::clapNoteNameGet(const clap_plugin *plugin, - uint32_t index, - clap_note_name *note_name) noexcept { + bool PluginBase::clapNoteNameGet(const clap_plugin *plugin, + uint32_t index, + clap_note_name *note_name) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_name.get"); @@ -1345,7 +1350,7 @@ namespace clap { namespace helpers { // clap_plugin_event_loop // //------------------------// template - void Plugin::clapOnTimer(const clap_plugin *plugin, clap_id timer_id) noexcept { + void PluginBase::clapOnTimer(const clap_plugin *plugin, clap_id timer_id) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_timer_support.on_timer"); @@ -1361,9 +1366,9 @@ namespace clap { namespace helpers { } template - void Plugin::clapOnPosixFd(const clap_plugin *plugin, - int fd, - clap_posix_fd_flags_t flags) noexcept { + void PluginBase::clapOnPosixFd(const clap_plugin *plugin, + int fd, + clap_posix_fd_flags_t flags) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_event_loop.on_fd"); @@ -1375,7 +1380,8 @@ namespace clap { namespace helpers { //------------------------// template - bool Plugin::clapVoiceInfoGet(const clap_plugin *plugin, clap_voice_info *info) noexcept { + bool PluginBase::clapVoiceInfoGet(const clap_plugin *plugin, + clap_voice_info *info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_voice_info.get"); @@ -1394,9 +1400,9 @@ namespace clap { namespace helpers { // clap_plugin_gui // //-----------------// template - bool Plugin::clapGuiGetSize(const clap_plugin *plugin, - uint32_t *width, - uint32_t *height) noexcept { + bool PluginBase::clapGuiGetSize(const clap_plugin *plugin, + uint32_t *width, + uint32_t *height) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.size"); @@ -1416,7 +1422,7 @@ namespace clap { namespace helpers { uint32_t testHeight = *height; if (!self.guiAdjustSize(&testWidth, &testHeight)) - self._host.pluginMisbehaving( + self._hostProxy.pluginMisbehaving( "the plugin claims to be resizable but the value returned" " by guiGetSize() needs can't be adjusted using guiAdjustSize()"); } @@ -1425,7 +1431,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiCanResize(const clap_plugin *plugin) noexcept { + bool PluginBase::clapGuiCanResize(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.can_resize"); @@ -1441,8 +1447,8 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiGetResizeHints(const clap_plugin_t *plugin, - clap_gui_resize_hints_t *hints) noexcept { + bool PluginBase::clapGuiGetResizeHints(const clap_plugin_t *plugin, + clap_gui_resize_hints_t *hints) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.get_resize_hints"); @@ -1459,9 +1465,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiAdjustSize(const clap_plugin *plugin, - uint32_t *width, - uint32_t *height) noexcept { + bool PluginBase::clapGuiAdjustSize(const clap_plugin *plugin, + uint32_t *width, + uint32_t *height) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.adjust_size"); @@ -1484,7 +1490,7 @@ namespace clap { namespace helpers { uint32_t testHeight = *height; if (!self.guiAdjustSize(&testWidth, &testHeight)) { - self._host.pluginMisbehaving( + self._hostProxy.pluginMisbehaving( "clap_plugin_gui.adjust_size() failed when called with adjusted values"); return true; } @@ -1497,7 +1503,7 @@ namespace clap { namespace helpers { << " (" << *width << ", " << *height << ") -> (" << testWidth << ", " << testHeight << ")" << std::endl << " !! Check you're rounding math!"; - self._host.pluginMisbehaving(os.str()); + self._hostProxy.pluginMisbehaving(os.str()); } } @@ -1505,9 +1511,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiSetSize(const clap_plugin *plugin, - uint32_t width, - uint32_t height) noexcept { + bool PluginBase::clapGuiSetSize(const clap_plugin *plugin, + uint32_t width, + uint32_t height) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_size"); @@ -1541,7 +1547,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiSetScale(const clap_plugin *plugin, double scale) noexcept { + bool PluginBase::clapGuiSetScale(const clap_plugin *plugin, double scale) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_scale"); @@ -1557,7 +1563,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiShow(const clap_plugin *plugin) noexcept { + bool PluginBase::clapGuiShow(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.show"); @@ -1573,7 +1579,7 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiHide(const clap_plugin *plugin) noexcept { + bool PluginBase::clapGuiHide(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.hide"); @@ -1589,9 +1595,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiIsApiSupported(const clap_plugin *plugin, - const char *api, - bool isFloating) noexcept { + bool PluginBase::clapGuiIsApiSupported(const clap_plugin *plugin, + const char *api, + bool isFloating) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.is_api_supported"); @@ -1599,9 +1605,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiGetPreferredApi(const clap_plugin_t *plugin, - const char **api, - bool *isFloating) noexcept { + bool PluginBase::clapGuiGetPreferredApi(const clap_plugin_t *plugin, + const char **api, + bool *isFloating) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.get_preferred_api"); @@ -1609,9 +1615,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiCreate(const clap_plugin *plugin, - const char *api, - bool isFloating) noexcept { + bool PluginBase::clapGuiCreate(const clap_plugin *plugin, + const char *api, + bool isFloating) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.create"); @@ -1641,7 +1647,7 @@ namespace clap { namespace helpers { } template - void Plugin::clapGuiDestroy(const clap_plugin *plugin) noexcept { + void PluginBase::clapGuiDestroy(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.destroy"); @@ -1660,8 +1666,8 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiSetParent(const clap_plugin *plugin, - const clap_window *window) noexcept { + bool PluginBase::clapGuiSetParent(const clap_plugin *plugin, + const clap_window *window) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_parent"); @@ -1687,8 +1693,8 @@ namespace clap { namespace helpers { } template - bool Plugin::clapGuiSetTransient(const clap_plugin *plugin, - const clap_window *window) noexcept { + bool PluginBase::clapGuiSetTransient(const clap_plugin *plugin, + const clap_window *window) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_transient"); @@ -1710,7 +1716,8 @@ namespace clap { namespace helpers { } template - void Plugin::clapGuiSuggestTitle(const clap_plugin *plugin, const char *title) noexcept { + void PluginBase::clapGuiSuggestTitle(const clap_plugin *plugin, + const char *title) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.suggest_title"); @@ -1741,9 +1748,10 @@ namespace clap { namespace helpers { // clap_plugin_context_menu // //--------------------------// template - bool Plugin::clapContextMenuPopulate(const clap_plugin_t *plugin, - const clap_context_menu_target_t *target, - const clap_context_menu_builder_t *builder) noexcept { + bool + PluginBase::clapContextMenuPopulate(const clap_plugin_t *plugin, + const clap_context_menu_target_t *target, + const clap_context_menu_builder_t *builder) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_context_menu.populate"); @@ -1751,9 +1759,9 @@ namespace clap { namespace helpers { } template - bool Plugin::clapContextMenuPerform(const clap_plugin_t *plugin, - const clap_context_menu_target_t *target, - clap_id action_id) noexcept { + bool PluginBase::clapContextMenuPerform(const clap_plugin_t *plugin, + const clap_context_menu_target_t *target, + clap_id action_id) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_context_menu.perform"); @@ -1764,33 +1772,35 @@ namespace clap { namespace helpers { // clap_plugin_resource_directory // //--------------------------------// template - void Plugin::clapResourceDirectorySetDirectory(const clap_plugin_t *plugin, - const char *path, - bool is_shared) noexcept { + void PluginBase::clapResourceDirectorySetDirectory(const clap_plugin_t *plugin, + const char *path, + bool is_shared) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.set_directory"); self.resourceDirectorySetDirectory(path, is_shared); } template - void Plugin::clapResourceDirectoryCollect(const clap_plugin_t *plugin, bool all) noexcept { + void PluginBase::clapResourceDirectoryCollect(const clap_plugin_t *plugin, + bool all) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.collect"); self.resourceDirectoryCollect(all); } template - uint32_t Plugin::clapResourceDirectoryGetFilesCount(const clap_plugin_t *plugin) noexcept { + uint32_t + PluginBase::clapResourceDirectoryGetFilesCount(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.get_files_count"); return self.resourceDirectoryGetFilesCount(); } template - int32_t Plugin::clapResourceDirectoryGetFilePath(const clap_plugin_t *plugin, - uint32_t index, - char *path, - uint32_t path_size) noexcept { + int32_t PluginBase::clapResourceDirectoryGetFilePath(const clap_plugin_t *plugin, + uint32_t index, + char *path, + uint32_t path_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.get_file_path"); return self.resourceDirectoryGetFilePath(index, path, path_size); @@ -1800,7 +1810,7 @@ namespace clap { namespace helpers { // clap_plugin_undo // //------------------// template - void Plugin::clapUndoDeltaGetDeltaProperties( + void PluginBase::clapUndoDeltaGetDeltaProperties( const clap_plugin_t *plugin, clap_undo_delta_properties_t *properties) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.get_delta_properties"); @@ -1808,60 +1818,60 @@ namespace clap { namespace helpers { } template - bool Plugin::clapUndoDeltaCanUseDeltaFormatVersion(const clap_plugin_t *plugin, - clap_id format_version) noexcept { + bool PluginBase::clapUndoDeltaCanUseDeltaFormatVersion(const clap_plugin_t *plugin, + clap_id format_version) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.can_use_delta_format_version"); return self.undoDeltaCanUseDeltaFormatVersion(format_version); } template - bool Plugin::clapUndoDeltaUndo(const clap_plugin_t *plugin, - clap_id format_version, - const void *delta, - size_t delta_size) noexcept { + bool PluginBase::clapUndoDeltaUndo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.undo"); return self.undoDeltaUndo(format_version, delta, delta_size); } template - bool Plugin::clapUndoDeltaRedo(const clap_plugin_t *plugin, - clap_id format_version, - const void *delta, - size_t delta_size) noexcept { + bool PluginBase::clapUndoDeltaRedo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.redo"); return self.undoDeltaRedo(format_version, delta, delta_size); } template - void Plugin::clapUndoContextSetCanUndo(const clap_plugin_t *plugin, - bool can_undo) noexcept { + void PluginBase::clapUndoContextSetCanUndo(const clap_plugin_t *plugin, + bool can_undo) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo.set_can_undo"); self.undoContextSetCanUndo(can_undo); } template - void Plugin::clapUndoContextSetCanRedo(const clap_plugin_t *plugin, - bool can_redo) noexcept { + void PluginBase::clapUndoContextSetCanRedo(const clap_plugin_t *plugin, + bool can_redo) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_context.set_can_redo"); self.undoContextSetCanRedo(can_redo); } template - void Plugin::clapUndoContextSetUndoName(const clap_plugin_t *plugin, - const char *name) noexcept { + void PluginBase::clapUndoContextSetUndoName(const clap_plugin_t *plugin, + const char *name) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_context.set_undo_name"); self.undoContextSetUndoName(name); } template - void Plugin::clapUndoContextSetRedoName(const clap_plugin_t *plugin, - const char *name) noexcept { + void PluginBase::clapUndoContextSetRedoName(const clap_plugin_t *plugin, + const char *name) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_context.set_redo_name"); self.undoContextSetRedoName(name); @@ -1872,9 +1882,9 @@ namespace clap { namespace helpers { //------------------// template - void Plugin::clapProjectLocationSet(const clap_plugin_t *plugin, - const clap_project_location_element_t *path, - uint32_t num_elements) noexcept { + void PluginBase::clapProjectLocationSet(const clap_plugin_t *plugin, + const clap_project_location_element_t *path, + uint32_t num_elements) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_location.set_location"); @@ -1899,7 +1909,7 @@ namespace clap { namespace helpers { // clap_plugin_gain_adjustment_metering // //--------------------------------------// template - double Plugin::clapGainAdjustmentMeteringGet(const clap_plugin_t *plugin) noexcept { + double PluginBase::clapGainAdjustmentMeteringGet(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureAudioThread("clap_plugin_gain_adjustment_meterig.get"); @@ -1917,9 +1927,10 @@ namespace clap { namespace helpers { // clap_plugin_mini_curve_display // //--------------------------------// template - uint32_t Plugin::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - clap_mini_curve_display_curve_data_t *curves, - uint32_t curves_size) noexcept { + uint32_t + PluginBase::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, + clap_mini_curve_display_curve_data_t *curves, + uint32_t curves_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.render"); @@ -1941,8 +1952,8 @@ namespace clap { namespace helpers { } template - void Plugin::clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, - bool is_observed) noexcept { + void PluginBase::clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, + bool is_observed) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.set_observed"); @@ -1950,7 +1961,8 @@ namespace clap { namespace helpers { } template - uint32_t Plugin::clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept { + uint32_t + PluginBase::clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.get_curve_count"); @@ -1958,11 +1970,11 @@ namespace clap { namespace helpers { } template - bool Plugin::clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, - uint32_t curve_index, - char *x_name, - char *y_name, - uint32_t name_capacity) noexcept { + bool PluginBase::clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, + uint32_t curve_index, + char *x_name, + char *y_name, + uint32_t name_capacity) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.get_axis_name"); @@ -1990,13 +2002,13 @@ namespace clap { namespace helpers { // Logging // ///////////// template - void Plugin::log(clap_log_severity severity, const char *msg) const noexcept { + void PluginBase::log(clap_log_severity severity, const char *msg) const noexcept { logTee(severity, msg); - _host.log(severity, msg); + _hostProxy.log(severity, msg); } template - void Plugin::hostMisbehaving(const char *msg) const noexcept { + void PluginBase::hostMisbehaving(const char *msg) const noexcept { log(CLAP_LOG_HOST_MISBEHAVING, msg); if (h == MisbehaviourHandler::Terminate) @@ -2004,7 +2016,7 @@ namespace clap { namespace helpers { } template - void Plugin::pluginMisbehaving(const char *msg) const noexcept { + void PluginBase::pluginMisbehaving(const char *msg) const noexcept { log(CLAP_LOG_PLUGIN_MISBEHAVING, msg); if (h == MisbehaviourHandler::Terminate) @@ -2015,11 +2027,11 @@ namespace clap { namespace helpers { // Thread Checking // ///////////////////// template - void Plugin::checkMainThread() const noexcept { + void PluginBase::checkMainThread() const noexcept { if (l == CheckingLevel::None) return; - if (!_host.canUseThreadCheck() || _host.isMainThread()) + if (!_hostProxy.canUseThreadCheck() || _hostProxy.isMainThread()) return; std::cerr << "thread-error: this code must be running on the main thread" << std::endl; @@ -2029,11 +2041,11 @@ namespace clap { namespace helpers { } template - void Plugin::checkAudioThread() const noexcept { + void PluginBase::checkAudioThread() const noexcept { if (l == CheckingLevel::None) return; - if (!_host.canUseThreadCheck() || _host.isAudioThread()) + if (!_hostProxy.canUseThreadCheck() || _hostProxy.isAudioThread()) return; std::cerr << "thread-error: this code must be running on the audio thread" << std::endl; @@ -2043,7 +2055,7 @@ namespace clap { namespace helpers { } template - void Plugin::checkParamThread() const noexcept { + void PluginBase::checkParamThread() const noexcept { if (l == CheckingLevel::None) return; @@ -2054,7 +2066,7 @@ namespace clap { namespace helpers { } template - void Plugin::ensureParamThread(const char *method) const noexcept { + void PluginBase::ensureParamThread(const char *method) const noexcept { if (l == CheckingLevel::None) return; @@ -2065,11 +2077,11 @@ namespace clap { namespace helpers { } template - void Plugin::ensureMainThread(const char *method) const noexcept { + void PluginBase::ensureMainThread(const char *method) const noexcept { if (l == CheckingLevel::None) return; - if (!_host.canUseThreadCheck() || _host.isMainThread()) + if (!_hostProxy.canUseThreadCheck() || _hostProxy.isMainThread()) return; std::ostringstream msg; @@ -2079,11 +2091,11 @@ namespace clap { namespace helpers { } template - void Plugin::ensureAudioThread(const char *method) const noexcept { + void PluginBase::ensureAudioThread(const char *method) const noexcept { if (l == CheckingLevel::None) return; - if (!_host.canUseThreadCheck() || _host.isAudioThread()) + if (!_hostProxy.canUseThreadCheck() || _hostProxy.isAudioThread()) return; std::ostringstream msg; @@ -2096,7 +2108,7 @@ namespace clap { namespace helpers { // General Checks // //////////////////// template - void Plugin::ensureIsInactive(const char *methodName) const noexcept { + void PluginBase::ensureIsInactive(const char *methodName) const noexcept { if (l == CheckingLevel::None) return; @@ -2109,7 +2121,7 @@ namespace clap { namespace helpers { } template - void Plugin::ensureIsActive(const char *methodName) const noexcept { + void PluginBase::ensureIsActive(const char *methodName) const noexcept { if (l == CheckingLevel::None) return; @@ -2125,7 +2137,8 @@ namespace clap { namespace helpers { // Utilities // /////////////// template - Plugin &Plugin::from(const clap_plugin *plugin, bool requireInitialized) noexcept { + PluginBase &PluginBase::from(const clap_plugin *plugin, + bool requireInitialized) noexcept { if (l >= CheckingLevel::Minimal) { if (!plugin) { std::cerr << "called with a null clap_plugin pointer!" << std::endl; @@ -2139,7 +2152,7 @@ namespace clap { namespace helpers { std::terminate(); } - auto &self = *static_cast(plugin->plugin_data); + auto &self = *static_cast(plugin->plugin_data); if (requireInitialized && !self._wasInitialized) { self.hostMisbehaving("Host is required to call clap_plugin.init() first"); if (h == MisbehaviourHandler::Terminate) @@ -2147,24 +2160,24 @@ namespace clap { namespace helpers { } } - return *static_cast(plugin->plugin_data); + return *static_cast(plugin->plugin_data); } template - void Plugin::runOnMainThread(std::function callback) { - if (_host.canUseThreadCheck() && _host.isMainThread()) { + void PluginBase::runOnMainThread(std::function callback) { + if (_hostProxy.canUseThreadCheck() && _hostProxy.isMainThread()) { callback(); return; } std::lock_guard guard(_mainThreadCallbacksLock); _mainThreadCallbacks.emplace(std::move(callback)); - _host.requestCallback(); + _hostProxy.requestCallback(); } template - uint32_t Plugin::compareAudioPortsInfo(const clap_audio_port_info &a, - const clap_audio_port_info &b) noexcept { + uint32_t PluginBase::compareAudioPortsInfo(const clap_audio_port_info &a, + const clap_audio_port_info &b) noexcept { uint32_t flags = 0; if (strncmp(a.name, b.name, sizeof(a.name))) @@ -2184,4 +2197,8 @@ namespace clap { namespace helpers { return flags; } + + template + Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) + : _host(host), PluginBase(*desc, _host) {} }} // namespace clap::helpers From 9c7785d594498f87ef46cc3f300e5826e73c3fcb Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Tue, 22 Jul 2025 13:00:58 +0200 Subject: [PATCH 08/15] Some adjustments --- include/clap/helpers/host-proxy.hh | 1 + include/clap/helpers/plugin-proxy.hh | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index a0b3a2f..644edb5 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -12,6 +12,7 @@ namespace clap { namespace helpers { class HostProxy { public: HostProxy(const clap_host *host); + virtual ~HostProxy() = default; // not copyable, not moveable HostProxy(const HostProxy &) = delete; diff --git a/include/clap/helpers/plugin-proxy.hh b/include/clap/helpers/plugin-proxy.hh index ff56860..03d2fc7 100644 --- a/include/clap/helpers/plugin-proxy.hh +++ b/include/clap/helpers/plugin-proxy.hh @@ -12,6 +12,13 @@ namespace clap { namespace helpers { public: PluginProxy(const clap_plugin &plugin, const Host &host) : _host{host}, _plugin{plugin} {} + virtual ~PluginProxy() = default; + + // not copyable, not moveable + PluginProxy(const PluginProxy &) = delete; + PluginProxy(PluginProxy &&) = delete; + PluginProxy &operator=(const PluginProxy &) = delete; + PluginProxy &operator=(PluginProxy &&) = delete; ///////////////// // clap_plugin // @@ -144,7 +151,7 @@ namespace clap { namespace helpers { ////////////////////////// bool canUseLocation() const noexcept; void projectLocationSet(const clap_project_location_element_t *path, - uint32_t num_elements) const noexcept; + uint32_t num_elements) const noexcept; /////////////////////////////////// // clap_gain_adjustment_metering // From 568fdb4687ed735d185b8d84a2eae61d1e8bfa07 Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Tue, 22 Jul 2025 14:01:00 +0200 Subject: [PATCH 09/15] Enable custom extension initialization for proxy classes --- include/clap/helpers/host-proxy.hh | 2 ++ include/clap/helpers/host-proxy.hxx | 2 ++ include/clap/helpers/plugin-proxy.hh | 2 ++ include/clap/helpers/plugin-proxy.hxx | 4 +++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index 644edb5..c001c36 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -221,6 +221,8 @@ namespace clap { namespace helpers { void ensureMainThread(const char *method) const noexcept; void ensureAudioThread(const char *method) const noexcept; + virtual void initCustomExtensions() noexcept {} + const clap_host *const _host; const clap_host_log *_hostLog = nullptr; diff --git a/include/clap/helpers/host-proxy.hxx b/include/clap/helpers/host-proxy.hxx index ac9f640..38c7b2c 100644 --- a/include/clap/helpers/host-proxy.hxx +++ b/include/clap/helpers/host-proxy.hxx @@ -13,6 +13,8 @@ namespace clap { namespace helpers { template void HostProxy::init() { + initCustomExtensions(); + getExtension(_hostLog, CLAP_EXT_LOG); getExtension(_hostThreadCheck, CLAP_EXT_THREAD_CHECK); getExtension(_hostThreadPool, CLAP_EXT_THREAD_POOL); diff --git a/include/clap/helpers/plugin-proxy.hh b/include/clap/helpers/plugin-proxy.hh index 03d2fc7..84c24a8 100644 --- a/include/clap/helpers/plugin-proxy.hh +++ b/include/clap/helpers/plugin-proxy.hh @@ -168,6 +168,8 @@ namespace clap { namespace helpers { void ensureActivated(const char *method, bool expectedState) const noexcept; void ensureProcessing(const char *method, bool expectedState) const noexcept; + virtual void initCustomExtensions() noexcept {} + const Host &_host; const clap_plugin &_plugin; diff --git a/include/clap/helpers/plugin-proxy.hxx b/include/clap/helpers/plugin-proxy.hxx index 0f3a867..c2ecb03 100644 --- a/include/clap/helpers/plugin-proxy.hxx +++ b/include/clap/helpers/plugin-proxy.hxx @@ -15,6 +15,8 @@ namespace clap { namespace helpers { if (!_plugin.init(&_plugin)) return false; + initCustomExtensions(); + getExtension(_pluginAudioPorts, CLAP_EXT_AUDIO_PORTS); getExtension(_pluginGui, CLAP_EXT_GUI); getExtension(_pluginLatency, CLAP_EXT_LATENCY); @@ -609,7 +611,7 @@ namespace clap { namespace helpers { template void PluginProxy::projectLocationSet(const clap_project_location_element_t *path, - uint32_t num_elements) const noexcept { + uint32_t num_elements) const noexcept { assert(canUseLocation()); ensureMainThread("clap_plugin_project_location.set"); _pluginProjectLocation->set(&_plugin, path, num_elements); From a3926ed1068b7e2e605cc545c8aae8c365e15ef1 Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Thu, 31 Jul 2025 10:35:39 +0200 Subject: [PATCH 10/15] add test for using custom extensions fixup --- CMakeLists.txt | 1 + tests/use-custom-extension.cc | 190 ++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 tests/use-custom-extension.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index e27afe4..3d70fec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,7 @@ if (${CLAP_HELPERS_BUILD_TESTS}) tests/preset-discovery-indexer.cc tests/preset-discovery-provider.cc tests/preset-discovery-metadata-receiver.cc + tests/use-custom-extension.cc ) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD ${CLAP_HELPERS_TESTS_CXX_STANDARD}) set_target_properties(${PROJECT_NAME}-tests PROPERTIES CXX_STANDARD ${CLAP_HELPERS_TESTS_CXX_STANDARD}) diff --git a/tests/use-custom-extension.cc b/tests/use-custom-extension.cc new file mode 100644 index 0000000..513821d --- /dev/null +++ b/tests/use-custom-extension.cc @@ -0,0 +1,190 @@ +#include +#include +#include + +#include + +namespace { + ////////////////////// + // custom extension // + ////////////////////// + + static CLAP_CONSTEXPR const char CLAP_HELPERS_EXT_TEST_PING_PONG[] = + "clap-helpers.test.ping-pong"; + + extern "C" { + typedef struct clap_plugin_test_ping_pong { + // Request the plugin to send back a pong + // [main-thread] + void(CLAP_ABI *ping)(const clap_plugin_t *plugin); + // Respond to a ping received from the plugin + // [main-thread] + void(CLAP_ABI *pong)(const clap_plugin_t *plugin); + } clap_plugin_ping_ping_t; + + typedef struct clap_host_test_ping_pong { + // Request the host to send back a pong + // [main-thread] + void(CLAP_ABI *ping)(const clap_host_t *host); + // Respond to a ping received from the host + // [main-thread] + void(CLAP_ABI *pong)(const clap_host_t *host); + } clap_host_test_ping_pong_t; + } + + ///////////////////////// + // template parameters // + ///////////////////////// + + static constexpr auto test_mh = clap::helpers::MisbehaviourHandler::Terminate; + static constexpr auto test_cl = clap::helpers::CheckingLevel::Maximal; + + ////////////////////////////// + // test host implementation // + ////////////////////////////// + + using test_plugin_proxy_base = clap::helpers::PluginProxy; + using test_host_base = clap::helpers::Host; + + struct test_plugin_proxy : test_plugin_proxy_base { + const clap_plugin_test_ping_pong *_pluginPingPong{}; + + test_plugin_proxy(const clap_plugin &plugin, const test_host_base &host) + : test_plugin_proxy_base(plugin, host) {} + + void initCustomExtensions() noexcept override { + getExtension(_pluginPingPong, CLAP_HELPERS_EXT_TEST_PING_PONG); + } + + bool canUsePingPong() const { + return _pluginPingPong && _pluginPingPong->ping && _pluginPingPong->pong; + } + void ping() const { + ensureMainThread("test_ping_pong.ping"); + _pluginPingPong->ping(&_plugin); + } + void pong() const { + ensureMainThread("test_ping_pong.ping"); + _pluginPingPong->pong(&_plugin); + } + }; + + struct test_host : test_host_base { + std::unique_ptr _pluginProxy; + bool _pluginCalledPong{}; + + test_host() + : test_host_base("Test Case Host", "Free Audio", "http://cleveraudio.org", "1.0.0") {} + ~test_host() { _pluginProxy->destroy(); } + + bool threadCheckIsMainThread() const noexcept override { return true; }; + bool threadCheckIsAudioThread() const noexcept override { return false; }; + void requestRestart() noexcept override {}; + void requestProcess() noexcept override {}; + void requestCallback() noexcept override {}; + + const void *getExtension(const char *extensionId) const noexcept override { + if (!strcmp(extensionId, CLAP_HELPERS_EXT_TEST_PING_PONG)) { + static const clap_host_test_ping_pong hostPingPong{ + [](const clap_host *host) { + auto &self = *static_cast(host->host_data); + self.ensureMainThread("clap_host_test_ping_pong.ping"); + if (self._pluginProxy->canUsePingPong()) + self._pluginProxy->pong(); + }, + [](const clap_host *host) { + auto &self = *static_cast(host->host_data); + self.ensureMainThread("clap_host_test_ping_pong.pong"); + self._pluginCalledPong = true; + }, + }; + return &hostPingPong; + } + return nullptr; + } + }; + + //////////////////////////////// + // test plugin implementation // + //////////////////////////////// + + using test_host_proxy_base = clap::helpers::HostProxy; + using test_plugin_base = clap::helpers::PluginBase; + + struct test_host_proxy : test_host_proxy_base { + const clap_host_test_ping_pong *_hostPingPong{}; + + test_host_proxy(const clap_host *host) : test_host_proxy_base(host) {} + void initCustomExtensions() noexcept override { + getExtension(_hostPingPong, CLAP_HELPERS_EXT_TEST_PING_PONG); + } + + bool canUsePingPong() const { + return _hostPingPong && _hostPingPong->ping && _hostPingPong->pong; + } + void ping() const noexcept { + ensureMainThread("test_ping_pong.ping"); + _hostPingPong->ping(_host); + } + void pong() const noexcept { + ensureMainThread("test_ping_pong.ping"); + _hostPingPong->pong(_host); + } + }; + + struct test_plugin : test_plugin_base { + test_host_proxy _hostProxy; + bool _hostCalledPong{}; + + static clap_plugin_descriptor &dummyDesc() { + static clap_plugin_descriptor d{}; + return d; + } + test_plugin(const clap_host *host) + : _hostProxy(host), test_plugin_base(dummyDesc(), _hostProxy) {} + + const void *extension(const char *id) noexcept { + if (!strcmp(id, CLAP_HELPERS_EXT_TEST_PING_PONG)) { + static const clap_plugin_test_ping_pong pluginPingPong{ + [](const clap_plugin *plugin) { + auto &self = *static_cast(&from(plugin)); + self.ensureMainThread("clap_plugin_test_ping_pong.ping"); + self._hostProxy.pong(); + }, + [](const clap_plugin *plugin) { + auto &self = *static_cast(&from(plugin)); + self.ensureMainThread("clap_plugin_test_ping_pong.pong"); + self._hostCalledPong = true; + }, + }; + return &pluginPingPong; + } + return nullptr; + } + }; +} // namespace + +CATCH_TEST_CASE("Use a custom extension") { + CATCH_WHEN("host and plugin are initialized") { + test_host host{}; + auto plugin = new test_plugin(host.clapHost()); + host._pluginProxy = std::make_unique(*plugin->clapPlugin(), host); + CATCH_REQUIRE(host._pluginProxy->init()); + + CATCH_THEN("no pong responds are registered yet") { + CATCH_REQUIRE_FALSE(plugin->_hostCalledPong); + CATCH_REQUIRE_FALSE(host._pluginCalledPong); + } + + CATCH_AND_WHEN("host calls ping on plugin") { + host._pluginProxy->ping(); + CATCH_THEN("plugin responds with pong") { CATCH_CHECK(host._pluginCalledPong); } + } + + CATCH_AND_WHEN("plugin calls ping on host") { + CATCH_REQUIRE(plugin->_hostProxy.canUsePingPong()); + plugin->_hostProxy.ping(); + CATCH_THEN("host responds with pong") { CATCH_CHECK(plugin->_hostCalledPong); } + } + } +} From d7e98c02d9437333ce5ac7deabac56143d00a370 Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:22:20 +0200 Subject: [PATCH 11/15] Revert "Enable custom extension initialization for proxy classes" This reverts commit 568fdb4687ed735d185b8d84a2eae61d1e8bfa07. --- include/clap/helpers/host-proxy.hh | 2 -- include/clap/helpers/host-proxy.hxx | 2 -- include/clap/helpers/plugin-proxy.hh | 2 -- include/clap/helpers/plugin-proxy.hxx | 4 +--- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index c001c36..644edb5 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -221,8 +221,6 @@ namespace clap { namespace helpers { void ensureMainThread(const char *method) const noexcept; void ensureAudioThread(const char *method) const noexcept; - virtual void initCustomExtensions() noexcept {} - const clap_host *const _host; const clap_host_log *_hostLog = nullptr; diff --git a/include/clap/helpers/host-proxy.hxx b/include/clap/helpers/host-proxy.hxx index 38c7b2c..ac9f640 100644 --- a/include/clap/helpers/host-proxy.hxx +++ b/include/clap/helpers/host-proxy.hxx @@ -13,8 +13,6 @@ namespace clap { namespace helpers { template void HostProxy::init() { - initCustomExtensions(); - getExtension(_hostLog, CLAP_EXT_LOG); getExtension(_hostThreadCheck, CLAP_EXT_THREAD_CHECK); getExtension(_hostThreadPool, CLAP_EXT_THREAD_POOL); diff --git a/include/clap/helpers/plugin-proxy.hh b/include/clap/helpers/plugin-proxy.hh index 84c24a8..03d2fc7 100644 --- a/include/clap/helpers/plugin-proxy.hh +++ b/include/clap/helpers/plugin-proxy.hh @@ -168,8 +168,6 @@ namespace clap { namespace helpers { void ensureActivated(const char *method, bool expectedState) const noexcept; void ensureProcessing(const char *method, bool expectedState) const noexcept; - virtual void initCustomExtensions() noexcept {} - const Host &_host; const clap_plugin &_plugin; diff --git a/include/clap/helpers/plugin-proxy.hxx b/include/clap/helpers/plugin-proxy.hxx index c2ecb03..0f3a867 100644 --- a/include/clap/helpers/plugin-proxy.hxx +++ b/include/clap/helpers/plugin-proxy.hxx @@ -15,8 +15,6 @@ namespace clap { namespace helpers { if (!_plugin.init(&_plugin)) return false; - initCustomExtensions(); - getExtension(_pluginAudioPorts, CLAP_EXT_AUDIO_PORTS); getExtension(_pluginGui, CLAP_EXT_GUI); getExtension(_pluginLatency, CLAP_EXT_LATENCY); @@ -611,7 +609,7 @@ namespace clap { namespace helpers { template void PluginProxy::projectLocationSet(const clap_project_location_element_t *path, - uint32_t num_elements) const noexcept { + uint32_t num_elements) const noexcept { assert(canUseLocation()); ensureMainThread("clap_plugin_project_location.set"); _pluginProjectLocation->set(&_plugin, path, num_elements); From 71c2d08dcbb21a8d0cf78d3ae31889f0f9dcc689 Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:36:53 +0200 Subject: [PATCH 12/15] Revert "Some adjustments" This reverts commit 9c7785d594498f87ef46cc3f300e5826e73c3fcb. --- include/clap/helpers/host-proxy.hh | 1 - include/clap/helpers/plugin-proxy.hh | 9 +-------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index 644edb5..a0b3a2f 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -12,7 +12,6 @@ namespace clap { namespace helpers { class HostProxy { public: HostProxy(const clap_host *host); - virtual ~HostProxy() = default; // not copyable, not moveable HostProxy(const HostProxy &) = delete; diff --git a/include/clap/helpers/plugin-proxy.hh b/include/clap/helpers/plugin-proxy.hh index 03d2fc7..ff56860 100644 --- a/include/clap/helpers/plugin-proxy.hh +++ b/include/clap/helpers/plugin-proxy.hh @@ -12,13 +12,6 @@ namespace clap { namespace helpers { public: PluginProxy(const clap_plugin &plugin, const Host &host) : _host{host}, _plugin{plugin} {} - virtual ~PluginProxy() = default; - - // not copyable, not moveable - PluginProxy(const PluginProxy &) = delete; - PluginProxy(PluginProxy &&) = delete; - PluginProxy &operator=(const PluginProxy &) = delete; - PluginProxy &operator=(PluginProxy &&) = delete; ///////////////// // clap_plugin // @@ -151,7 +144,7 @@ namespace clap { namespace helpers { ////////////////////////// bool canUseLocation() const noexcept; void projectLocationSet(const clap_project_location_element_t *path, - uint32_t num_elements) const noexcept; + uint32_t num_elements) const noexcept; /////////////////////////////////// // clap_gain_adjustment_metering // From 2578d2eb760d44c3ea4682a8e4657441e159e8ca Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:37:00 +0200 Subject: [PATCH 13/15] Revert "Enable deriving from HostProxy" This reverts commit 08df762f1d7b00a9711fe74aa58af7f2cafcb55e. --- include/clap/helpers/plugin.hh | 26 +- include/clap/helpers/plugin.hxx | 569 ++++++++++++++++---------------- 2 files changed, 285 insertions(+), 310 deletions(-) diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index 533ebd9..e7a5c26 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -20,19 +20,19 @@ namespace clap { namespace helpers { /// /// @note for an higher level implementation, see @ref PluginHelper template - class PluginBase { + class Plugin { public: // not copyable, not moveable - PluginBase(const PluginBase &) = delete; - PluginBase(PluginBase &&) = delete; - PluginBase &operator=(const PluginBase &) = delete; - PluginBase &operator=(PluginBase &&) = delete; + Plugin(const Plugin &) = delete; + Plugin(Plugin &&) = delete; + Plugin &operator=(const Plugin &) = delete; + Plugin &operator=(Plugin &&) = delete; const clap_plugin *clapPlugin() noexcept { return &_plugin; } protected: - PluginBase(const clap_plugin_descriptor &desc, HostProxy &hostProxy); - virtual ~PluginBase() = default; + Plugin(const clap_plugin_descriptor *desc, const clap_host *host); + virtual ~Plugin() = default; ///////////////////////// // Methods to override // @@ -398,7 +398,7 @@ namespace clap { namespace helpers { /////////////// // Utilities // /////////////// - static PluginBase &from(const clap_plugin *plugin, bool requireInitialized = true) noexcept; + static Plugin &from(const clap_plugin *plugin, bool requireInitialized = true) noexcept; // runs the callback immediately if on the main thread, otherwise queue it. // be aware that the callback may be ran during the plugin destruction phase, @@ -425,7 +425,7 @@ namespace clap { namespace helpers { bool isBeingDestroyed() const noexcept { return _isBeingDestroyed; } protected: - HostProxy &_hostProxy; + HostProxy _host; private: void ensureInitialized(const char *method) const noexcept; @@ -724,12 +724,4 @@ namespace clap { namespace helpers { std::mutex _mainThreadCallbacksLock; std::queue> _mainThreadCallbacks; }; - - // for compatibility. If you want to derive from HostProxy, use PluginBase instead - template - class Plugin : public PluginBase { - protected: - Plugin(const clap_plugin_descriptor *desc, const clap_host *host); - HostProxy _host; - }; }} // namespace clap::helpers diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index 403cf46..f844101 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -14,69 +14,69 @@ namespace clap { namespace helpers { template - const clap_plugin_render PluginBase::_pluginRender = { + const clap_plugin_render Plugin::_pluginRender = { clapRenderHasHardRealtimeRequirement, clapRenderSetMode, }; template - const clap_plugin_thread_pool PluginBase::_pluginThreadPool = { + const clap_plugin_thread_pool Plugin::_pluginThreadPool = { clapThreadPoolExec, }; template - const clap_plugin_state PluginBase::_pluginState = { + const clap_plugin_state Plugin::_pluginState = { clapStateSave, clapStateLoad, }; template - const clap_plugin_state_context PluginBase::_pluginStateContext = { + const clap_plugin_state_context Plugin::_pluginStateContext = { clapStateContextSave, clapStateContextLoad, }; template - const clap_plugin_preset_load PluginBase::_pluginPresetLoad = { + const clap_plugin_preset_load Plugin::_pluginPresetLoad = { clapPresetLoadFromLocation, }; template - const clap_plugin_track_info PluginBase::_pluginTrackInfo = { + const clap_plugin_track_info Plugin::_pluginTrackInfo = { clapTrackInfoChanged, }; template - const clap_plugin_audio_ports PluginBase::_pluginAudioPorts = {clapAudioPortsCount, - clapAudioPortsInfo}; + const clap_plugin_audio_ports Plugin::_pluginAudioPorts = {clapAudioPortsCount, + clapAudioPortsInfo}; template - const clap_plugin_audio_ports_config PluginBase::_pluginAudioPortsConfig = { + const clap_plugin_audio_ports_config Plugin::_pluginAudioPortsConfig = { clapAudioPortsConfigCount, clapAudioPortsGetConfig, clapAudioPortsSetConfig, }; template - const clap_plugin_audio_ports_activation PluginBase::_pluginAudioPortsActivation = { + const clap_plugin_audio_ports_activation Plugin::_pluginAudioPortsActivation = { clapAudioPortsActivationCanActivateWhileProcessing, clapAudioPortsActivationSetActive, }; template - const clap_plugin_configurable_audio_ports PluginBase::_pluginConfigurableAudioPorts = { + const clap_plugin_configurable_audio_ports Plugin::_pluginConfigurableAudioPorts = { clapConfigurableAudioPortsCanApplyConfiguration, clapConfigurableAudioPortsApplyConfiguration, }; template - const clap_plugin_surround_t PluginBase::_pluginSurroundConfig = { + const clap_plugin_surround_t Plugin::_pluginSurroundConfig = { clapSurroundIsChannelMaskSupported, clapSurroundGetChannelMap, }; template - const clap_plugin_params PluginBase::_pluginParams = { + const clap_plugin_params Plugin::_pluginParams = { clapParamsCount, clapParamsInfo, clapParamsValue, @@ -86,40 +86,40 @@ namespace clap { namespace helpers { }; template - const clap_plugin_param_indication PluginBase::_pluginParamIndication = { + const clap_plugin_param_indication Plugin::_pluginParamIndication = { clapParamIndicationSetMapping, clapParamIndicationSetAutomation, }; template - const clap_plugin_remote_controls PluginBase::_pluginRemoteControls = { + const clap_plugin_remote_controls Plugin::_pluginRemoteControls = { clapRemoteControlsPageCount, clapRemoteControlsPageGet}; template - const clap_plugin_latency PluginBase::_pluginLatency = { + const clap_plugin_latency Plugin::_pluginLatency = { clapLatencyGet, }; template - const clap_plugin_note_ports PluginBase::_pluginNotePorts = {clapNotePortsCount, - clapNotePortsInfo}; + const clap_plugin_note_ports Plugin::_pluginNotePorts = {clapNotePortsCount, + clapNotePortsInfo}; template - const clap_plugin_note_name PluginBase::_pluginNoteName = { + const clap_plugin_note_name Plugin::_pluginNoteName = { clapNoteNameCount, clapNoteNameGet, }; template - const clap_plugin_timer_support PluginBase::_pluginTimerSupport = {clapOnTimer}; + const clap_plugin_timer_support Plugin::_pluginTimerSupport = {clapOnTimer}; template - const clap_plugin_posix_fd_support PluginBase::_pluginPosixFdSupport = { + const clap_plugin_posix_fd_support Plugin::_pluginPosixFdSupport = { clapOnPosixFd, }; template - const clap_plugin_gui PluginBase::_pluginGui = { + const clap_plugin_gui Plugin::_pluginGui = { clapGuiIsApiSupported, clapGuiGetPreferredApi, clapGuiCreate, @@ -138,13 +138,13 @@ namespace clap { namespace helpers { }; template - const clap_plugin_context_menu PluginBase::_pluginContextMenu = { + const clap_plugin_context_menu Plugin::_pluginContextMenu = { clapContextMenuPopulate, clapContextMenuPerform, }; template - const clap_plugin_resource_directory PluginBase::_pluginResourceDirectory = { + const clap_plugin_resource_directory Plugin::_pluginResourceDirectory = { clapResourceDirectorySetDirectory, clapResourceDirectoryCollect, clapResourceDirectoryGetFilesCount, @@ -152,17 +152,17 @@ namespace clap { namespace helpers { }; template - const clap_plugin_voice_info PluginBase::_pluginVoiceInfo = { + const clap_plugin_voice_info Plugin::_pluginVoiceInfo = { clapVoiceInfoGet, }; template - const clap_plugin_tail PluginBase::_pluginTail = { + const clap_plugin_tail Plugin::_pluginTail = { clapTailGet, }; template - const clap_plugin_undo_delta PluginBase::_pluginUndoDelta = { + const clap_plugin_undo_delta Plugin::_pluginUndoDelta = { clapUndoDeltaGetDeltaProperties, clapUndoDeltaCanUseDeltaFormatVersion, clapUndoDeltaUndo, @@ -170,7 +170,7 @@ namespace clap { namespace helpers { }; template - const clap_plugin_undo_context PluginBase::_pluginUndoContext = { + const clap_plugin_undo_context Plugin::_pluginUndoContext = { clapUndoContextSetCanUndo, clapUndoContextSetCanRedo, clapUndoContextSetUndoName, @@ -178,17 +178,17 @@ namespace clap { namespace helpers { }; template - const clap_plugin_project_location PluginBase::_pluginProjectLocation = { + const clap_plugin_project_location Plugin::_pluginProjectLocation = { clapProjectLocationSet, }; template - const clap_plugin_gain_adjustment_metering PluginBase::_pluginGainAdjustmentMetering = { + const clap_plugin_gain_adjustment_metering Plugin::_pluginGainAdjustmentMetering = { clapGainAdjustmentMeteringGet, }; template - const clap_plugin_mini_curve_display PluginBase::_pluginMiniCurveDisplay = { + const clap_plugin_mini_curve_display Plugin::_pluginMiniCurveDisplay = { clapMiniCurveDisplayGetCurveCount, clapMiniCurveDisplayRender, clapMiniCurveDisplaySetObserved, @@ -196,20 +196,19 @@ namespace clap { namespace helpers { }; template - PluginBase::PluginBase(const clap_plugin_descriptor &desc, HostProxy &hostProxy) - : _hostProxy(hostProxy) { + Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : _host(host) { _plugin.plugin_data = this; - _plugin.desc = &desc; - _plugin.init = PluginBase::clapInit; - _plugin.destroy = PluginBase::clapDestroy; - _plugin.get_extension = PluginBase::clapExtension; - _plugin.process = PluginBase::clapProcess; - _plugin.activate = PluginBase::clapActivate; - _plugin.deactivate = PluginBase::clapDeactivate; - _plugin.start_processing = PluginBase::clapStartProcessing; - _plugin.stop_processing = PluginBase::clapStopProcessing; - _plugin.reset = PluginBase::clapReset; - _plugin.on_main_thread = PluginBase::clapOnMainThread; + _plugin.desc = desc; + _plugin.init = Plugin::clapInit; + _plugin.destroy = Plugin::clapDestroy; + _plugin.get_extension = Plugin::clapExtension; + _plugin.process = Plugin::clapProcess; + _plugin.activate = Plugin::clapActivate; + _plugin.deactivate = Plugin::clapDeactivate; + _plugin.start_processing = Plugin::clapStartProcessing; + _plugin.stop_processing = Plugin::clapStopProcessing; + _plugin.reset = Plugin::clapReset; + _plugin.on_main_thread = Plugin::clapOnMainThread; } ///////////////////// @@ -220,7 +219,7 @@ namespace clap { namespace helpers { // clap_plugin // //-------------// template - bool PluginBase::clapInit(const clap_plugin *plugin) noexcept { + bool Plugin::clapInit(const clap_plugin *plugin) noexcept { auto &self = from(plugin, false); if (l >= CheckingLevel::Minimal && self._wasInitialized) { @@ -232,13 +231,13 @@ namespace clap { namespace helpers { self._wasInitialized = true; - self._hostProxy.init(); + self._host.init(); self.ensureMainThread("clap_plugin.init"); return self.init(); } template - void PluginBase::ensureInitialized(const char *method) const noexcept { + void Plugin::ensureInitialized(const char *method) const noexcept { if (l == CheckingLevel::None || _wasInitialized) return; @@ -250,21 +249,20 @@ namespace clap { namespace helpers { } template - void PluginBase::clapDestroy(const clap_plugin *plugin) noexcept { + void Plugin::clapDestroy(const clap_plugin *plugin) noexcept { auto &self = from(plugin, false); self.ensureMainThread("clap_plugin.destroy"); self._isBeingDestroyed = true; if (self._isGuiCreated) { if (l >= CheckingLevel::Minimal) - self._hostProxy.hostMisbehaving("host forgot to destroy the gui"); + self._host.hostMisbehaving("host forgot to destroy the gui"); clapGuiDestroy(plugin); } if (self._isActive) { if (l >= CheckingLevel::Minimal) - self._hostProxy.hostMisbehaving( - "host forgot to deactivate the plugin before destroying it"); + self._host.hostMisbehaving("host forgot to deactivate the plugin before destroying it"); clapDeactivate(plugin); } assert(!self._isActive); @@ -275,7 +273,7 @@ namespace clap { namespace helpers { } template - void PluginBase::clapOnMainThread(const clap_plugin *plugin) noexcept { + void Plugin::clapOnMainThread(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("on_maint_thread"); self.ensureMainThread("clap_plugin.on_main_thread"); @@ -285,10 +283,10 @@ namespace clap { namespace helpers { } template - void PluginBase::runCallbacksOnMainThread() { + void Plugin::runCallbacksOnMainThread() { if (l >= CheckingLevel::Minimal) { - if (_hostProxy.canUseThreadCheck() && !_hostProxy.isMainThread()) { - _hostProxy.pluginMisbehaving( + if (_host.canUseThreadCheck() && !_host.isMainThread()) { + _host.pluginMisbehaving( "plugin called runCallbacksOnMainThread(), but not on the main thread!"); return; } @@ -311,10 +309,10 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapActivate(const clap_plugin *plugin, - double sample_rate, - uint32_t minFrameCount, - uint32_t maxFrameCount) noexcept { + bool Plugin::clapActivate(const clap_plugin *plugin, + double sample_rate, + uint32_t minFrameCount, + uint32_t maxFrameCount) noexcept { auto &self = from(plugin); self.ensureInitialized("activate"); self.ensureMainThread("clap_plugin.activate"); @@ -385,7 +383,7 @@ namespace clap { namespace helpers { } template - void PluginBase::clapDeactivate(const clap_plugin *plugin) noexcept { + void Plugin::clapDeactivate(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("deactivate"); self.ensureMainThread("clap_plugin.deactivate"); @@ -403,7 +401,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapStartProcessing(const clap_plugin *plugin) noexcept { + bool Plugin::clapStartProcessing(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("start_processing"); self.ensureAudioThread("clap_plugin.start_processing"); @@ -426,7 +424,7 @@ namespace clap { namespace helpers { } template - void PluginBase::clapStopProcessing(const clap_plugin *plugin) noexcept { + void Plugin::clapStopProcessing(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("stop_processing"); self.ensureAudioThread("clap_plugin.stop_processing"); @@ -449,7 +447,7 @@ namespace clap { namespace helpers { } template - void PluginBase::clapReset(const clap_plugin *plugin) noexcept { + void Plugin::clapReset(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureInitialized("reset"); self.ensureAudioThread("clap_plugin.reset"); @@ -465,8 +463,8 @@ namespace clap { namespace helpers { } template - clap_process_status PluginBase::clapProcess(const clap_plugin *plugin, - const clap_process *process) noexcept { + clap_process_status Plugin::clapProcess(const clap_plugin *plugin, + const clap_process *process) noexcept { auto &self = from(plugin); self.ensureInitialized("process"); self.ensureAudioThread("clap_plugin.process"); @@ -488,7 +486,7 @@ namespace clap { namespace helpers { } template - const void *PluginBase::clapExtension(const clap_plugin *plugin, const char *id) noexcept { + const void *Plugin::clapExtension(const clap_plugin *plugin, const char *id) noexcept { auto &self = from(plugin); self.ensureInitialized("extension"); @@ -573,7 +571,7 @@ namespace clap { namespace helpers { // clap_plugin_state // //-------------------// template - uint32_t PluginBase::clapLatencyGet(const clap_plugin *plugin) noexcept { + uint32_t Plugin::clapLatencyGet(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_latency.get"); @@ -591,7 +589,7 @@ namespace clap { namespace helpers { // clap_plugin_tail // //------------------// template - uint32_t PluginBase::clapTailGet(const clap_plugin_t *plugin) noexcept { + uint32_t Plugin::clapTailGet(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); if (l >= CheckingLevel::Minimal) { @@ -608,15 +606,15 @@ namespace clap { namespace helpers { // clap_plugin_render // //--------------------// template - bool PluginBase::clapRenderHasHardRealtimeRequirement(const clap_plugin *plugin) noexcept { + bool Plugin::clapRenderHasHardRealtimeRequirement(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_render.has_hard_realtime_requirement"); return self.renderHasHardRealtimeRequirement(); } template - bool PluginBase::clapRenderSetMode(const clap_plugin *plugin, - clap_plugin_render_mode mode) noexcept { + bool Plugin::clapRenderSetMode(const clap_plugin *plugin, + clap_plugin_render_mode mode) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_render.set_mode"); @@ -643,8 +641,7 @@ namespace clap { namespace helpers { // clap_plugin_thread_pool // //-------------------------// template - void PluginBase::clapThreadPoolExec(const clap_plugin *plugin, - uint32_t task_index) noexcept { + void Plugin::clapThreadPoolExec(const clap_plugin *plugin, uint32_t task_index) noexcept { auto &self = from(plugin); self.threadPoolExec(task_index); @@ -654,8 +651,8 @@ namespace clap { namespace helpers { // clap_plugin_state // //-------------------// template - bool PluginBase::clapStateSave(const clap_plugin *plugin, - const clap_ostream *stream) noexcept { + bool Plugin::clapStateSave(const clap_plugin *plugin, + const clap_ostream *stream) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state.save"); @@ -663,8 +660,8 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapStateLoad(const clap_plugin *plugin, - const clap_istream *stream) noexcept { + bool Plugin::clapStateLoad(const clap_plugin *plugin, + const clap_istream *stream) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state.load"); @@ -675,9 +672,9 @@ namespace clap { namespace helpers { // clap_plugin_state_context // //---------------------------// template - bool PluginBase::clapStateContextSave(const clap_plugin *plugin, - const clap_ostream *stream, - uint32_t context) noexcept { + bool Plugin::clapStateContextSave(const clap_plugin *plugin, + const clap_ostream *stream, + uint32_t context) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state_context.save"); @@ -685,9 +682,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapStateContextLoad(const clap_plugin *plugin, - const clap_istream *stream, - uint32_t context) noexcept { + bool Plugin::clapStateContextLoad(const clap_plugin *plugin, + const clap_istream *stream, + uint32_t context) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_state_context.load"); @@ -698,10 +695,10 @@ namespace clap { namespace helpers { // clap_plugin_preset_load // //-------------------------// template - bool PluginBase::clapPresetLoadFromLocation(const clap_plugin *plugin, - uint32_t location_kind, - const char *location, - const char *load_key) noexcept { + bool Plugin::clapPresetLoadFromLocation(const clap_plugin *plugin, + uint32_t location_kind, + const char *location, + const char *load_key) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_preset_load.from_location"); @@ -721,12 +718,12 @@ namespace clap { namespace helpers { // clap_plugin_track_info // //------------------------// template - void PluginBase::clapTrackInfoChanged(const clap_plugin *plugin) noexcept { + void Plugin::clapTrackInfoChanged(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_track_info.changed"); if (l >= CheckingLevel::Minimal) { - if (!self._hostProxy.canUseTrackInfo()) { + if (!self._host.canUseTrackInfo()) { self.hostMisbehaving( "host called clap_plugin_track_info.changed() but does not provide a " "complete clap_host_track_info interface"); @@ -741,8 +738,7 @@ namespace clap { namespace helpers { // clap_plugin_audio_ports // //-------------------------// template - uint32_t PluginBase::clapAudioPortsCount(const clap_plugin *plugin, - bool is_input) noexcept { + uint32_t Plugin::clapAudioPortsCount(const clap_plugin *plugin, bool is_input) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.count"); @@ -750,10 +746,10 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapAudioPortsInfo(const clap_plugin *plugin, - uint32_t index, - bool is_input, - clap_audio_port_info *info) noexcept { + bool Plugin::clapAudioPortsInfo(const clap_plugin *plugin, + uint32_t index, + bool is_input, + clap_audio_port_info *info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.info"); @@ -772,16 +768,16 @@ namespace clap { namespace helpers { } template - uint32_t PluginBase::clapAudioPortsConfigCount(const clap_plugin *plugin) noexcept { + uint32_t Plugin::clapAudioPortsConfigCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.config_count"); return self.audioPortsConfigCount(); } template - bool PluginBase::clapAudioPortsGetConfig(const clap_plugin *plugin, - uint32_t index, - clap_audio_ports_config *config) noexcept { + bool Plugin::clapAudioPortsGetConfig(const clap_plugin *plugin, + uint32_t index, + clap_audio_ports_config *config) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.get_config"); @@ -799,8 +795,8 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapAudioPortsSetConfig(const clap_plugin *plugin, - clap_id config_id) noexcept { + bool Plugin::clapAudioPortsSetConfig(const clap_plugin *plugin, + clap_id config_id) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.set_config"); @@ -816,7 +812,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapAudioPortsActivationCanActivateWhileProcessing( + bool Plugin::clapAudioPortsActivationCanActivateWhileProcessing( const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports_activation.can_activate_while_processing"); @@ -825,11 +821,11 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapAudioPortsActivationSetActive(const clap_plugin_t *plugin, - bool is_input, - uint32_t port_index, - bool is_active, - uint32_t sample_size) noexcept { + bool Plugin::clapAudioPortsActivationSetActive(const clap_plugin_t *plugin, + bool is_input, + uint32_t port_index, + bool is_active, + uint32_t sample_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports_activation.set_active"); @@ -847,7 +843,7 @@ namespace clap { namespace helpers { } template - uint32_t PluginBase::clapParamsCount(const clap_plugin *plugin) noexcept { + uint32_t Plugin::clapParamsCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.count"); @@ -859,7 +855,7 @@ namespace clap { namespace helpers { //--------------------------------------// template - bool PluginBase::clapConfigurableAudioPortsCanApplyConfiguration( + bool Plugin::clapConfigurableAudioPortsCanApplyConfiguration( const clap_plugin_t *plugin, const clap_audio_port_configuration_request *requests, uint32_t request_count) noexcept { @@ -872,7 +868,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapConfigurableAudioPortsApplyConfiguration( + bool Plugin::clapConfigurableAudioPortsApplyConfiguration( const clap_plugin_t *plugin, const clap_audio_port_configuration_request *requests, uint32_t request_count) noexcept { @@ -891,7 +887,7 @@ namespace clap { namespace helpers { self.configurableAudioPortsApplyConfiguration(requests, request_count); if (l >= CheckingLevel::Minimal && canApplyConfiguration != applyConfigurationSuccess) { - self._hostProxy.pluginMisbehaving( + self._host.pluginMisbehaving( "Plugin's functions clap_plugin_configurable_audio_ports.can_apply_configuration and " "clap_plugin_configurable_audio_ports.apply_configuration returned different values " "for the same configuration."); @@ -904,8 +900,8 @@ namespace clap { namespace helpers { // clap_plugin_surround // //----------------------// template - bool PluginBase::clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin, - uint64_t channel_mask) noexcept { + bool Plugin::clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin, + uint64_t channel_mask) noexcept { auto &self = from(plugin); auto methodName = "clap_plugin_surround.is_channel_mask_supported"; self.ensureMainThread(methodName); @@ -914,11 +910,11 @@ namespace clap { namespace helpers { } template - uint32_t PluginBase::clapSurroundGetChannelMap(const clap_plugin_t *plugin, - bool is_input, - uint32_t port_index, - uint8_t *channel_map, - uint32_t channel_map_capacity) noexcept { + uint32_t Plugin::clapSurroundGetChannelMap(const clap_plugin_t *plugin, + bool is_input, + uint32_t port_index, + uint8_t *channel_map, + uint32_t channel_map_capacity) noexcept { auto &self = from(plugin); auto methodName = "clap_plugin_surround.get_channel_map"; self.ensureMainThread(methodName); @@ -927,7 +923,7 @@ namespace clap { namespace helpers { self.getChannelMap(is_input, port_index, channel_map, channel_map_capacity); if (l >= CheckingLevel::Minimal && channel_count > channel_map_capacity) { - self._hostProxy.pluginMisbehaving( + self._host.pluginMisbehaving( "Plugin's functions clap_plugin_surround.get_channel_map cannot return a channel " "count greater than channel_map_capacity."); return channel_map_capacity; @@ -940,9 +936,9 @@ namespace clap { namespace helpers { // clap_plugin_params // //--------------------// template - bool PluginBase::clapParamsInfo(const clap_plugin *plugin, - uint32_t param_index, - clap_param_info *param_info) noexcept { + bool Plugin::clapParamsInfo(const clap_plugin *plugin, + uint32_t param_index, + clap_param_info *param_info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.info"); @@ -962,16 +958,16 @@ namespace clap { namespace helpers { if (l >= CheckingLevel::Maximal && !res) { std::ostringstream os; os << "clap_plugin_params.info(" << param_index << ") failed"; - self._hostProxy.pluginMisbehaving(os.str()); + self._host.pluginMisbehaving(os.str()); } return res; } template - bool PluginBase::clapParamsValue(const clap_plugin *plugin, - clap_id paramId, - double *value) noexcept { + bool Plugin::clapParamsValue(const clap_plugin *plugin, + clap_id paramId, + double *value) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.value"); @@ -993,7 +989,7 @@ namespace clap { namespace helpers { std::ostringstream msg; msg << "clap_plugin_params.value(" << paramId << ") = " << *value << ", is out of range [" << info.min_value << " .. " << info.max_value << "]"; - self._hostProxy.pluginMisbehaving(msg.str()); + self._host.pluginMisbehaving(msg.str()); } } } @@ -1002,9 +998,9 @@ namespace clap { namespace helpers { } template - void PluginBase::clapParamsFlush(const clap_plugin *plugin, - const clap_input_events *in, - const clap_output_events *out) noexcept { + void Plugin::clapParamsFlush(const clap_plugin *plugin, + const clap_input_events *in, + const clap_output_events *out) noexcept { auto &self = from(plugin); self.ensureParamThread("clap_plugin_params.flush"); @@ -1041,7 +1037,7 @@ namespace clap { namespace helpers { auto pev = reinterpret_cast(ev); - if (self._hostProxy.canUseThreadCheck() && self._hostProxy.isMainThread() && + if (self._host.canUseThreadCheck() && self._host.isMainThread() && !self.isValidParamId(pev->param_id)) { std::ostringstream msg; msg << "clap_plugin_params.flush called unknown paramId: " << pev->param_id; @@ -1056,7 +1052,7 @@ namespace clap { namespace helpers { msg << "clap_plugin_params.flush() produced the value " << pev->value << " for parameter " << pev->param_id << " which is out of bounds: [" << info.min_value << " .. " << info.max_value << "]"; - self._hostProxy.pluginMisbehaving(msg.str()); + self._host.pluginMisbehaving(msg.str()); } } } @@ -1071,11 +1067,11 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapParamsValueToText(const clap_plugin *plugin, - clap_id param_id, - double value, - char *display, - uint32_t size) noexcept { + bool Plugin::clapParamsValueToText(const clap_plugin *plugin, + clap_id param_id, + double value, + char *display, + uint32_t size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.value_to_text"); @@ -1118,10 +1114,10 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapParamsTextToValue(const clap_plugin *plugin, - clap_id param_id, - const char *display, - double *value) noexcept { + bool Plugin::clapParamsTextToValue(const clap_plugin *plugin, + clap_id param_id, + const char *display, + double *value) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_params.text_to_value"); @@ -1157,7 +1153,7 @@ namespace clap { namespace helpers { msg << "clap_plugin_params.text_to_value() produced the value " << value << " for parameter " << param_id << " which is out of bounds: [" << info.min_value << " .. " << info.max_value << "]"; - self._hostProxy.pluginMisbehaving(msg.str()); + self._host.pluginMisbehaving(msg.str()); } } } @@ -1165,7 +1161,7 @@ namespace clap { namespace helpers { } template - int32_t PluginBase::getParamIndexForParamId(clap_id param_id) const noexcept { + int32_t Plugin::getParamIndexForParamId(clap_id param_id) const noexcept { checkMainThread(); const auto count = paramsCount(); @@ -1182,8 +1178,8 @@ namespace clap { namespace helpers { } template - bool PluginBase::getParamInfoForParamId(clap_id paramId, - clap_param_info *info) const noexcept { + bool Plugin::getParamInfoForParamId(clap_id paramId, + clap_param_info *info) const noexcept { checkMainThread(); const auto count = paramsCount(); @@ -1195,7 +1191,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::isValidParamId(clap_id param_id) const noexcept { + bool Plugin::isValidParamId(clap_id param_id) const noexcept { checkMainThread(); return getParamIndexForParamId(param_id) != -1; @@ -1206,12 +1202,12 @@ namespace clap { namespace helpers { //------------------------------// template - void PluginBase::clapParamIndicationSetMapping(const clap_plugin_t *plugin, - clap_id param_id, - bool has_mapping, - const clap_color_t *color, - const char *label, - const char *description) noexcept { + void Plugin::clapParamIndicationSetMapping(const clap_plugin_t *plugin, + clap_id param_id, + bool has_mapping, + const clap_color_t *color, + const char *label, + const char *description) noexcept { auto &self = from(plugin); self.checkMainThread(); @@ -1229,10 +1225,10 @@ namespace clap { namespace helpers { } template - void PluginBase::clapParamIndicationSetAutomation(const clap_plugin_t *plugin, - clap_id param_id, - uint32_t automation_state, - const clap_color_t *color) noexcept { + void Plugin::clapParamIndicationSetAutomation(const clap_plugin_t *plugin, + clap_id param_id, + uint32_t automation_state, + const clap_color_t *color) noexcept { auto &self = from(plugin); self.checkMainThread(); @@ -1253,7 +1249,7 @@ namespace clap { namespace helpers { // clap_plugin_remote_controls // //----------------------------// template - uint32_t PluginBase::clapRemoteControlsPageCount(const clap_plugin *plugin) noexcept { + uint32_t Plugin::clapRemoteControlsPageCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_remote_controls.page_count"); @@ -1261,9 +1257,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapRemoteControlsPageGet(const clap_plugin *plugin, - uint32_t page_index, - clap_remote_controls_page *page) noexcept { + bool Plugin::clapRemoteControlsPageGet(const clap_plugin *plugin, + uint32_t page_index, + clap_remote_controls_page *page) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_remote_controls.page_info"); @@ -1286,18 +1282,17 @@ namespace clap { namespace helpers { // clap_plugin_note_ports // //------------------------// template - uint32_t PluginBase::clapNotePortsCount(const clap_plugin *plugin, - bool is_input) noexcept { + uint32_t Plugin::clapNotePortsCount(const clap_plugin *plugin, bool is_input) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_port.count"); return self.notePortsCount(is_input); } template - bool PluginBase::clapNotePortsInfo(const clap_plugin *plugin, - uint32_t index, - bool is_input, - clap_note_port_info *info) noexcept { + bool Plugin::clapNotePortsInfo(const clap_plugin *plugin, + uint32_t index, + bool is_input, + clap_note_port_info *info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_ports.info"); @@ -1319,16 +1314,16 @@ namespace clap { namespace helpers { // clap_plugin_note_name // //-----------------------// template - uint32_t PluginBase::clapNoteNameCount(const clap_plugin *plugin) noexcept { + uint32_t Plugin::clapNoteNameCount(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_name.count"); return self.noteNameCount(); } template - bool PluginBase::clapNoteNameGet(const clap_plugin *plugin, - uint32_t index, - clap_note_name *note_name) noexcept { + bool Plugin::clapNoteNameGet(const clap_plugin *plugin, + uint32_t index, + clap_note_name *note_name) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_note_name.get"); @@ -1350,7 +1345,7 @@ namespace clap { namespace helpers { // clap_plugin_event_loop // //------------------------// template - void PluginBase::clapOnTimer(const clap_plugin *plugin, clap_id timer_id) noexcept { + void Plugin::clapOnTimer(const clap_plugin *plugin, clap_id timer_id) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_timer_support.on_timer"); @@ -1366,9 +1361,9 @@ namespace clap { namespace helpers { } template - void PluginBase::clapOnPosixFd(const clap_plugin *plugin, - int fd, - clap_posix_fd_flags_t flags) noexcept { + void Plugin::clapOnPosixFd(const clap_plugin *plugin, + int fd, + clap_posix_fd_flags_t flags) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_event_loop.on_fd"); @@ -1380,8 +1375,7 @@ namespace clap { namespace helpers { //------------------------// template - bool PluginBase::clapVoiceInfoGet(const clap_plugin *plugin, - clap_voice_info *info) noexcept { + bool Plugin::clapVoiceInfoGet(const clap_plugin *plugin, clap_voice_info *info) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_voice_info.get"); @@ -1400,9 +1394,9 @@ namespace clap { namespace helpers { // clap_plugin_gui // //-----------------// template - bool PluginBase::clapGuiGetSize(const clap_plugin *plugin, - uint32_t *width, - uint32_t *height) noexcept { + bool Plugin::clapGuiGetSize(const clap_plugin *plugin, + uint32_t *width, + uint32_t *height) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.size"); @@ -1422,7 +1416,7 @@ namespace clap { namespace helpers { uint32_t testHeight = *height; if (!self.guiAdjustSize(&testWidth, &testHeight)) - self._hostProxy.pluginMisbehaving( + self._host.pluginMisbehaving( "the plugin claims to be resizable but the value returned" " by guiGetSize() needs can't be adjusted using guiAdjustSize()"); } @@ -1431,7 +1425,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiCanResize(const clap_plugin *plugin) noexcept { + bool Plugin::clapGuiCanResize(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.can_resize"); @@ -1447,8 +1441,8 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiGetResizeHints(const clap_plugin_t *plugin, - clap_gui_resize_hints_t *hints) noexcept { + bool Plugin::clapGuiGetResizeHints(const clap_plugin_t *plugin, + clap_gui_resize_hints_t *hints) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.get_resize_hints"); @@ -1465,9 +1459,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiAdjustSize(const clap_plugin *plugin, - uint32_t *width, - uint32_t *height) noexcept { + bool Plugin::clapGuiAdjustSize(const clap_plugin *plugin, + uint32_t *width, + uint32_t *height) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.adjust_size"); @@ -1490,7 +1484,7 @@ namespace clap { namespace helpers { uint32_t testHeight = *height; if (!self.guiAdjustSize(&testWidth, &testHeight)) { - self._hostProxy.pluginMisbehaving( + self._host.pluginMisbehaving( "clap_plugin_gui.adjust_size() failed when called with adjusted values"); return true; } @@ -1503,7 +1497,7 @@ namespace clap { namespace helpers { << " (" << *width << ", " << *height << ") -> (" << testWidth << ", " << testHeight << ")" << std::endl << " !! Check you're rounding math!"; - self._hostProxy.pluginMisbehaving(os.str()); + self._host.pluginMisbehaving(os.str()); } } @@ -1511,9 +1505,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiSetSize(const clap_plugin *plugin, - uint32_t width, - uint32_t height) noexcept { + bool Plugin::clapGuiSetSize(const clap_plugin *plugin, + uint32_t width, + uint32_t height) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_size"); @@ -1547,7 +1541,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiSetScale(const clap_plugin *plugin, double scale) noexcept { + bool Plugin::clapGuiSetScale(const clap_plugin *plugin, double scale) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_scale"); @@ -1563,7 +1557,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiShow(const clap_plugin *plugin) noexcept { + bool Plugin::clapGuiShow(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.show"); @@ -1579,7 +1573,7 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiHide(const clap_plugin *plugin) noexcept { + bool Plugin::clapGuiHide(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.hide"); @@ -1595,9 +1589,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiIsApiSupported(const clap_plugin *plugin, - const char *api, - bool isFloating) noexcept { + bool Plugin::clapGuiIsApiSupported(const clap_plugin *plugin, + const char *api, + bool isFloating) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.is_api_supported"); @@ -1605,9 +1599,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiGetPreferredApi(const clap_plugin_t *plugin, - const char **api, - bool *isFloating) noexcept { + bool Plugin::clapGuiGetPreferredApi(const clap_plugin_t *plugin, + const char **api, + bool *isFloating) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.get_preferred_api"); @@ -1615,9 +1609,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiCreate(const clap_plugin *plugin, - const char *api, - bool isFloating) noexcept { + bool Plugin::clapGuiCreate(const clap_plugin *plugin, + const char *api, + bool isFloating) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.create"); @@ -1647,7 +1641,7 @@ namespace clap { namespace helpers { } template - void PluginBase::clapGuiDestroy(const clap_plugin *plugin) noexcept { + void Plugin::clapGuiDestroy(const clap_plugin *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.destroy"); @@ -1666,8 +1660,8 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiSetParent(const clap_plugin *plugin, - const clap_window *window) noexcept { + bool Plugin::clapGuiSetParent(const clap_plugin *plugin, + const clap_window *window) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_parent"); @@ -1693,8 +1687,8 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapGuiSetTransient(const clap_plugin *plugin, - const clap_window *window) noexcept { + bool Plugin::clapGuiSetTransient(const clap_plugin *plugin, + const clap_window *window) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.set_transient"); @@ -1716,8 +1710,7 @@ namespace clap { namespace helpers { } template - void PluginBase::clapGuiSuggestTitle(const clap_plugin *plugin, - const char *title) noexcept { + void Plugin::clapGuiSuggestTitle(const clap_plugin *plugin, const char *title) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_gui.suggest_title"); @@ -1748,10 +1741,9 @@ namespace clap { namespace helpers { // clap_plugin_context_menu // //--------------------------// template - bool - PluginBase::clapContextMenuPopulate(const clap_plugin_t *plugin, - const clap_context_menu_target_t *target, - const clap_context_menu_builder_t *builder) noexcept { + bool Plugin::clapContextMenuPopulate(const clap_plugin_t *plugin, + const clap_context_menu_target_t *target, + const clap_context_menu_builder_t *builder) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_context_menu.populate"); @@ -1759,9 +1751,9 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapContextMenuPerform(const clap_plugin_t *plugin, - const clap_context_menu_target_t *target, - clap_id action_id) noexcept { + bool Plugin::clapContextMenuPerform(const clap_plugin_t *plugin, + const clap_context_menu_target_t *target, + clap_id action_id) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_context_menu.perform"); @@ -1772,35 +1764,33 @@ namespace clap { namespace helpers { // clap_plugin_resource_directory // //--------------------------------// template - void PluginBase::clapResourceDirectorySetDirectory(const clap_plugin_t *plugin, - const char *path, - bool is_shared) noexcept { + void Plugin::clapResourceDirectorySetDirectory(const clap_plugin_t *plugin, + const char *path, + bool is_shared) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.set_directory"); self.resourceDirectorySetDirectory(path, is_shared); } template - void PluginBase::clapResourceDirectoryCollect(const clap_plugin_t *plugin, - bool all) noexcept { + void Plugin::clapResourceDirectoryCollect(const clap_plugin_t *plugin, bool all) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.collect"); self.resourceDirectoryCollect(all); } template - uint32_t - PluginBase::clapResourceDirectoryGetFilesCount(const clap_plugin_t *plugin) noexcept { + uint32_t Plugin::clapResourceDirectoryGetFilesCount(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.get_files_count"); return self.resourceDirectoryGetFilesCount(); } template - int32_t PluginBase::clapResourceDirectoryGetFilePath(const clap_plugin_t *plugin, - uint32_t index, - char *path, - uint32_t path_size) noexcept { + int32_t Plugin::clapResourceDirectoryGetFilePath(const clap_plugin_t *plugin, + uint32_t index, + char *path, + uint32_t path_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_resource_directory.get_file_path"); return self.resourceDirectoryGetFilePath(index, path, path_size); @@ -1810,7 +1800,7 @@ namespace clap { namespace helpers { // clap_plugin_undo // //------------------// template - void PluginBase::clapUndoDeltaGetDeltaProperties( + void Plugin::clapUndoDeltaGetDeltaProperties( const clap_plugin_t *plugin, clap_undo_delta_properties_t *properties) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.get_delta_properties"); @@ -1818,60 +1808,60 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapUndoDeltaCanUseDeltaFormatVersion(const clap_plugin_t *plugin, - clap_id format_version) noexcept { + bool Plugin::clapUndoDeltaCanUseDeltaFormatVersion(const clap_plugin_t *plugin, + clap_id format_version) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.can_use_delta_format_version"); return self.undoDeltaCanUseDeltaFormatVersion(format_version); } template - bool PluginBase::clapUndoDeltaUndo(const clap_plugin_t *plugin, - clap_id format_version, - const void *delta, - size_t delta_size) noexcept { + bool Plugin::clapUndoDeltaUndo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.undo"); return self.undoDeltaUndo(format_version, delta, delta_size); } template - bool PluginBase::clapUndoDeltaRedo(const clap_plugin_t *plugin, - clap_id format_version, - const void *delta, - size_t delta_size) noexcept { + bool Plugin::clapUndoDeltaRedo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_delta.redo"); return self.undoDeltaRedo(format_version, delta, delta_size); } template - void PluginBase::clapUndoContextSetCanUndo(const clap_plugin_t *plugin, - bool can_undo) noexcept { + void Plugin::clapUndoContextSetCanUndo(const clap_plugin_t *plugin, + bool can_undo) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo.set_can_undo"); self.undoContextSetCanUndo(can_undo); } template - void PluginBase::clapUndoContextSetCanRedo(const clap_plugin_t *plugin, - bool can_redo) noexcept { + void Plugin::clapUndoContextSetCanRedo(const clap_plugin_t *plugin, + bool can_redo) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_context.set_can_redo"); self.undoContextSetCanRedo(can_redo); } template - void PluginBase::clapUndoContextSetUndoName(const clap_plugin_t *plugin, - const char *name) noexcept { + void Plugin::clapUndoContextSetUndoName(const clap_plugin_t *plugin, + const char *name) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_context.set_undo_name"); self.undoContextSetUndoName(name); } template - void PluginBase::clapUndoContextSetRedoName(const clap_plugin_t *plugin, - const char *name) noexcept { + void Plugin::clapUndoContextSetRedoName(const clap_plugin_t *plugin, + const char *name) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_undo_context.set_redo_name"); self.undoContextSetRedoName(name); @@ -1882,9 +1872,9 @@ namespace clap { namespace helpers { //------------------// template - void PluginBase::clapProjectLocationSet(const clap_plugin_t *plugin, - const clap_project_location_element_t *path, - uint32_t num_elements) noexcept { + void Plugin::clapProjectLocationSet(const clap_plugin_t *plugin, + const clap_project_location_element_t *path, + uint32_t num_elements) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_location.set_location"); @@ -1909,7 +1899,7 @@ namespace clap { namespace helpers { // clap_plugin_gain_adjustment_metering // //--------------------------------------// template - double PluginBase::clapGainAdjustmentMeteringGet(const clap_plugin_t *plugin) noexcept { + double Plugin::clapGainAdjustmentMeteringGet(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureAudioThread("clap_plugin_gain_adjustment_meterig.get"); @@ -1927,10 +1917,9 @@ namespace clap { namespace helpers { // clap_plugin_mini_curve_display // //--------------------------------// template - uint32_t - PluginBase::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, - clap_mini_curve_display_curve_data_t *curves, - uint32_t curves_size) noexcept { + uint32_t Plugin::clapMiniCurveDisplayRender(const clap_plugin_t *plugin, + clap_mini_curve_display_curve_data_t *curves, + uint32_t curves_size) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.render"); @@ -1952,8 +1941,8 @@ namespace clap { namespace helpers { } template - void PluginBase::clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, - bool is_observed) noexcept { + void Plugin::clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin, + bool is_observed) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.set_observed"); @@ -1961,8 +1950,7 @@ namespace clap { namespace helpers { } template - uint32_t - PluginBase::clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept { + uint32_t Plugin::clapMiniCurveDisplayGetCurveCount(const clap_plugin_t *plugin) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.get_curve_count"); @@ -1970,11 +1958,11 @@ namespace clap { namespace helpers { } template - bool PluginBase::clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, - uint32_t curve_index, - char *x_name, - char *y_name, - uint32_t name_capacity) noexcept { + bool Plugin::clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin, + uint32_t curve_index, + char *x_name, + char *y_name, + uint32_t name_capacity) noexcept { auto &self = from(plugin); self.ensureMainThread("clap_plugin_mini_curve_display.get_axis_name"); @@ -2002,13 +1990,13 @@ namespace clap { namespace helpers { // Logging // ///////////// template - void PluginBase::log(clap_log_severity severity, const char *msg) const noexcept { + void Plugin::log(clap_log_severity severity, const char *msg) const noexcept { logTee(severity, msg); - _hostProxy.log(severity, msg); + _host.log(severity, msg); } template - void PluginBase::hostMisbehaving(const char *msg) const noexcept { + void Plugin::hostMisbehaving(const char *msg) const noexcept { log(CLAP_LOG_HOST_MISBEHAVING, msg); if (h == MisbehaviourHandler::Terminate) @@ -2016,7 +2004,7 @@ namespace clap { namespace helpers { } template - void PluginBase::pluginMisbehaving(const char *msg) const noexcept { + void Plugin::pluginMisbehaving(const char *msg) const noexcept { log(CLAP_LOG_PLUGIN_MISBEHAVING, msg); if (h == MisbehaviourHandler::Terminate) @@ -2027,11 +2015,11 @@ namespace clap { namespace helpers { // Thread Checking // ///////////////////// template - void PluginBase::checkMainThread() const noexcept { + void Plugin::checkMainThread() const noexcept { if (l == CheckingLevel::None) return; - if (!_hostProxy.canUseThreadCheck() || _hostProxy.isMainThread()) + if (!_host.canUseThreadCheck() || _host.isMainThread()) return; std::cerr << "thread-error: this code must be running on the main thread" << std::endl; @@ -2041,11 +2029,11 @@ namespace clap { namespace helpers { } template - void PluginBase::checkAudioThread() const noexcept { + void Plugin::checkAudioThread() const noexcept { if (l == CheckingLevel::None) return; - if (!_hostProxy.canUseThreadCheck() || _hostProxy.isAudioThread()) + if (!_host.canUseThreadCheck() || _host.isAudioThread()) return; std::cerr << "thread-error: this code must be running on the audio thread" << std::endl; @@ -2055,7 +2043,7 @@ namespace clap { namespace helpers { } template - void PluginBase::checkParamThread() const noexcept { + void Plugin::checkParamThread() const noexcept { if (l == CheckingLevel::None) return; @@ -2066,7 +2054,7 @@ namespace clap { namespace helpers { } template - void PluginBase::ensureParamThread(const char *method) const noexcept { + void Plugin::ensureParamThread(const char *method) const noexcept { if (l == CheckingLevel::None) return; @@ -2077,11 +2065,11 @@ namespace clap { namespace helpers { } template - void PluginBase::ensureMainThread(const char *method) const noexcept { + void Plugin::ensureMainThread(const char *method) const noexcept { if (l == CheckingLevel::None) return; - if (!_hostProxy.canUseThreadCheck() || _hostProxy.isMainThread()) + if (!_host.canUseThreadCheck() || _host.isMainThread()) return; std::ostringstream msg; @@ -2091,11 +2079,11 @@ namespace clap { namespace helpers { } template - void PluginBase::ensureAudioThread(const char *method) const noexcept { + void Plugin::ensureAudioThread(const char *method) const noexcept { if (l == CheckingLevel::None) return; - if (!_hostProxy.canUseThreadCheck() || _hostProxy.isAudioThread()) + if (!_host.canUseThreadCheck() || _host.isAudioThread()) return; std::ostringstream msg; @@ -2108,7 +2096,7 @@ namespace clap { namespace helpers { // General Checks // //////////////////// template - void PluginBase::ensureIsInactive(const char *methodName) const noexcept { + void Plugin::ensureIsInactive(const char *methodName) const noexcept { if (l == CheckingLevel::None) return; @@ -2121,7 +2109,7 @@ namespace clap { namespace helpers { } template - void PluginBase::ensureIsActive(const char *methodName) const noexcept { + void Plugin::ensureIsActive(const char *methodName) const noexcept { if (l == CheckingLevel::None) return; @@ -2137,8 +2125,7 @@ namespace clap { namespace helpers { // Utilities // /////////////// template - PluginBase &PluginBase::from(const clap_plugin *plugin, - bool requireInitialized) noexcept { + Plugin &Plugin::from(const clap_plugin *plugin, bool requireInitialized) noexcept { if (l >= CheckingLevel::Minimal) { if (!plugin) { std::cerr << "called with a null clap_plugin pointer!" << std::endl; @@ -2152,7 +2139,7 @@ namespace clap { namespace helpers { std::terminate(); } - auto &self = *static_cast(plugin->plugin_data); + auto &self = *static_cast(plugin->plugin_data); if (requireInitialized && !self._wasInitialized) { self.hostMisbehaving("Host is required to call clap_plugin.init() first"); if (h == MisbehaviourHandler::Terminate) @@ -2160,24 +2147,24 @@ namespace clap { namespace helpers { } } - return *static_cast(plugin->plugin_data); + return *static_cast(plugin->plugin_data); } template - void PluginBase::runOnMainThread(std::function callback) { - if (_hostProxy.canUseThreadCheck() && _hostProxy.isMainThread()) { + void Plugin::runOnMainThread(std::function callback) { + if (_host.canUseThreadCheck() && _host.isMainThread()) { callback(); return; } std::lock_guard guard(_mainThreadCallbacksLock); _mainThreadCallbacks.emplace(std::move(callback)); - _hostProxy.requestCallback(); + _host.requestCallback(); } template - uint32_t PluginBase::compareAudioPortsInfo(const clap_audio_port_info &a, - const clap_audio_port_info &b) noexcept { + uint32_t Plugin::compareAudioPortsInfo(const clap_audio_port_info &a, + const clap_audio_port_info &b) noexcept { uint32_t flags = 0; if (strncmp(a.name, b.name, sizeof(a.name))) @@ -2197,8 +2184,4 @@ namespace clap { namespace helpers { return flags; } - - template - Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) - : _host(host), PluginBase(*desc, _host) {} }} // namespace clap::helpers From acf44c380624f3b57135eda838d755408e413076 Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:29:26 +0200 Subject: [PATCH 14/15] adapt custom extension test to reverted changes --- include/clap/helpers/host-proxy.hh | 7 ++++- tests/use-custom-extension.cc | 41 ++++++++++++++++++------------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index a0b3a2f..14748d6 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -216,10 +216,15 @@ namespace clap { namespace helpers { bool miniCurveDisplayGetHints(uint32_t kind, clap_mini_curve_display_curve_hints_t *hints) const noexcept; - protected: + ////////////////////////////// + // Custom extension helpers // + ////////////////////////////// + void ensureMainThread(const char *method) const noexcept; void ensureAudioThread(const char *method) const noexcept; + const clap_host *clapHost() const noexcept { return _host; } + protected: const clap_host *const _host; const clap_host_log *_hostLog = nullptr; diff --git a/tests/use-custom-extension.cc b/tests/use-custom-extension.cc index 513821d..ca174dd 100644 --- a/tests/use-custom-extension.cc +++ b/tests/use-custom-extension.cc @@ -52,8 +52,11 @@ namespace { test_plugin_proxy(const clap_plugin &plugin, const test_host_base &host) : test_plugin_proxy_base(plugin, host) {} - void initCustomExtensions() noexcept override { + bool init() noexcept { + if (!test_plugin_proxy_base::init()) + return false; getExtension(_pluginPingPong, CLAP_HELPERS_EXT_TEST_PING_PONG); + return true; } bool canUsePingPong() const { @@ -108,32 +111,32 @@ namespace { // test plugin implementation // //////////////////////////////// - using test_host_proxy_base = clap::helpers::HostProxy; - using test_plugin_base = clap::helpers::PluginBase; + using test_host_proxy = clap::helpers::HostProxy; + using test_plugin_base = clap::helpers::Plugin; - struct test_host_proxy : test_host_proxy_base { + struct test_host_custom_extension_proxy { + test_host_proxy &_hostProxy; const clap_host_test_ping_pong *_hostPingPong{}; - test_host_proxy(const clap_host *host) : test_host_proxy_base(host) {} - void initCustomExtensions() noexcept override { - getExtension(_hostPingPong, CLAP_HELPERS_EXT_TEST_PING_PONG); - } + test_host_custom_extension_proxy(test_host_proxy &hostProxy) : _hostProxy(hostProxy) {} + void init() { _hostProxy.getExtension(_hostPingPong, CLAP_HELPERS_EXT_TEST_PING_PONG); } bool canUsePingPong() const { return _hostPingPong && _hostPingPong->ping && _hostPingPong->pong; } void ping() const noexcept { - ensureMainThread("test_ping_pong.ping"); - _hostPingPong->ping(_host); + _hostProxy.ensureMainThread("test_ping_pong.ping"); + _hostPingPong->ping(_hostProxy.clapHost()); } void pong() const noexcept { - ensureMainThread("test_ping_pong.ping"); - _hostPingPong->pong(_host); + _hostProxy.ensureMainThread("test_ping_pong.ping"); + _hostPingPong->pong(_hostProxy.clapHost()); } }; struct test_plugin : test_plugin_base { test_host_proxy _hostProxy; + test_host_custom_extension_proxy _hostExtensionProxy; bool _hostCalledPong{}; static clap_plugin_descriptor &dummyDesc() { @@ -141,7 +144,8 @@ namespace { return d; } test_plugin(const clap_host *host) - : _hostProxy(host), test_plugin_base(dummyDesc(), _hostProxy) {} + : _hostProxy(host), test_plugin_base(&dummyDesc(), host), _hostExtensionProxy(_hostProxy) { + } const void *extension(const char *id) noexcept { if (!strcmp(id, CLAP_HELPERS_EXT_TEST_PING_PONG)) { @@ -149,7 +153,7 @@ namespace { [](const clap_plugin *plugin) { auto &self = *static_cast(&from(plugin)); self.ensureMainThread("clap_plugin_test_ping_pong.ping"); - self._hostProxy.pong(); + self._hostExtensionProxy.pong(); }, [](const clap_plugin *plugin) { auto &self = *static_cast(&from(plugin)); @@ -161,6 +165,11 @@ namespace { } return nullptr; } + + bool init() noexcept override { + _hostExtensionProxy.init(); + return true; + } }; } // namespace @@ -182,8 +191,8 @@ CATCH_TEST_CASE("Use a custom extension") { } CATCH_AND_WHEN("plugin calls ping on host") { - CATCH_REQUIRE(plugin->_hostProxy.canUsePingPong()); - plugin->_hostProxy.ping(); + CATCH_REQUIRE(plugin->_hostExtensionProxy.canUsePingPong()); + plugin->_hostExtensionProxy.ping(); CATCH_THEN("host responds with pong") { CATCH_CHECK(plugin->_hostCalledPong); } } } From f1c14c6bfb7a9036ad8ca5d0aa169a364302a22c Mon Sep 17 00:00:00 2001 From: Trinitou <106991375+Trinitou@users.noreply.github.com> Date: Thu, 31 Jul 2025 13:02:39 +0200 Subject: [PATCH 15/15] build fix --- tests/use-custom-extension.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/use-custom-extension.cc b/tests/use-custom-extension.cc index ca174dd..d896762 100644 --- a/tests/use-custom-extension.cc +++ b/tests/use-custom-extension.cc @@ -147,7 +147,7 @@ namespace { : _hostProxy(host), test_plugin_base(&dummyDesc(), host), _hostExtensionProxy(_hostProxy) { } - const void *extension(const char *id) noexcept { + const void *extension(const char *id) noexcept override { if (!strcmp(id, CLAP_HELPERS_EXT_TEST_PING_PONG)) { static const clap_plugin_test_ping_pong pluginPingPong{ [](const clap_plugin *plugin) {