diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-07-19 16:57:20 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-07-19 16:57:20 +0200 |
commit | 83254f1690123dc66991ce50c9db23c7cadba711 (patch) | |
tree | a8c53ba99c47672a61c67146932125320f4fc5a6 | |
parent | 225608fe4a2370a08e80db0b72f70a56fbcf5060 (diff) | |
download | airwindows-lv2-port-83254f1690123dc66991ce50c9db23c7cadba711.tar.gz airwindows-lv2-port-83254f1690123dc66991ce50c9db23c7cadba711.tar.bz2 airwindows-lv2-port-83254f1690123dc66991ce50c9db23c7cadba711.zip |
LV2: Refactor common LV2Wrapper.
Move the common wrapper code into a template class that can be
instantiated from each plugin.
-rwxr-xr-x | plugins/LV2/CMakeLists.txt | 2 | ||||
-rw-r--r-- | plugins/LV2/include/lv2wrapper.h | 75 | ||||
-rw-r--r-- | plugins/LV2/src/ADClip7/ADClip7.cpp | 4 | ||||
-rw-r--r-- | plugins/LV2/src/ADClip7/ADClip7.h | 2 | ||||
-rw-r--r-- | plugins/LV2/src/ADClip7/lv2wrapper.cpp | 70 | ||||
-rw-r--r-- | plugins/LV2/src/Acceleration/Acceleration.cpp | 4 | ||||
-rw-r--r-- | plugins/LV2/src/Acceleration/Acceleration.h | 2 | ||||
-rw-r--r-- | plugins/LV2/src/Acceleration/lv2wrapper.cpp | 70 |
8 files changed, 89 insertions, 140 deletions
diff --git a/plugins/LV2/CMakeLists.txt b/plugins/LV2/CMakeLists.txt index bd6ac57..4923f92 100755 --- a/plugins/LV2/CMakeLists.txt +++ b/plugins/LV2/CMakeLists.txt @@ -6,6 +6,8 @@ add_compile_options(-Wall -Werror -Wno-unused-value) include(Helpers.cmake) +include_directories(include) + # add_subdirectory(include/vstsdk) add_airwindows_plugin(Acceleration) add_airwindows_plugin(ADClip7) diff --git a/plugins/LV2/include/lv2wrapper.h b/plugins/LV2/include/lv2wrapper.h new file mode 100644 index 0000000..26531cb --- /dev/null +++ b/plugins/LV2/include/lv2wrapper.h @@ -0,0 +1,75 @@ +#include "lv2/core/lv2.h" + +LV2_Descriptor descriptor; + +template<typename Plugin> +class LV2Wrapper +{ +public: + LV2Wrapper() + { + LV2_Descriptor d = { + Plugin::URI, + LV2Wrapper::instantiate, + LV2Wrapper::connect_port, + LV2Wrapper::activate, + LV2Wrapper::run, + LV2Wrapper::deactivate, + LV2Wrapper::destroy, + LV2Wrapper::extension_data + }; + descriptor = d; + } + +private: + static LV2_Handle instantiate( + const LV2_Descriptor * d, + double rate, + const char * path, + const LV2_Feature * const * features) + { + return new Plugin{rate}; + } + + static void connect_port( + LV2_Handle instance, + uint32_t port, + void * data) + { + auto accel = static_cast<Plugin *>(instance); + accel->connect_port(port, data); + } + + static void activate(LV2_Handle instance) + { + } + + static void run(LV2_Handle instance, uint32_t num_samples) + { + auto accel = static_cast<Plugin *>(instance); + accel->run(num_samples); + } + + static void deactivate(LV2_Handle) + { + } + + static void destroy(LV2_Handle instance) + { + delete static_cast<Plugin *>(instance); + } + + static const void * extension_data(const char * uri) + { + return nullptr; + } +}; + +LV2_SYMBOL_EXPORT +const LV2_Descriptor * lv2_descriptor(uint32_t idx) +{ + if (idx == 0) + return &descriptor; + + return nullptr; +} diff --git a/plugins/LV2/src/ADClip7/ADClip7.cpp b/plugins/LV2/src/ADClip7/ADClip7.cpp index 0c0891a..adf6eb9 100644 --- a/plugins/LV2/src/ADClip7/ADClip7.cpp +++ b/plugins/LV2/src/ADClip7/ADClip7.cpp @@ -1,6 +1,7 @@ #include "ADClip7.h" #include <cmath> #include <iostream> +#include <lv2wrapper.h> namespace { @@ -88,3 +89,6 @@ double ADClip7::getSampleRate() // Include the processing code from the VST version. // #include "../../../LinuxVST/src/ADClip7/ADClip7Proc.cpp" + +// Create the LV2Wrapper and register the plugin +LV2Wrapper<ADClip7> plugin; diff --git a/plugins/LV2/src/ADClip7/ADClip7.h b/plugins/LV2/src/ADClip7/ADClip7.h index 3ec6033..cfe7f40 100644 --- a/plugins/LV2/src/ADClip7/ADClip7.h +++ b/plugins/LV2/src/ADClip7/ADClip7.h @@ -13,6 +13,8 @@ public: void connect_port(uint32_t port, void * data); void run(uint32_t num_samples); + static constexpr const char * URI = "https://www.airwindows.com/adclip-7"; + private: void processReplacing(float **in, float **out, VstInt32 samples); void processDoubleReplacing(double **in, double **out, VstInt32 samples); diff --git a/plugins/LV2/src/ADClip7/lv2wrapper.cpp b/plugins/LV2/src/ADClip7/lv2wrapper.cpp deleted file mode 100644 index 2ff55c8..0000000 --- a/plugins/LV2/src/ADClip7/lv2wrapper.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "lv2/core/lv2.h" -#include "ADClip7.h" - -namespace { - -const char * PLUGIN_URI = "https://www.airwindows.com/adclip-7"; - -LV2_Handle instantiate( - const LV2_Descriptor * d, - double rate, - const char * path, - const LV2_Feature * const * features) -{ - return new ADClip7{rate}; -} - -void connect_port( - LV2_Handle instance, - uint32_t port, - void * data) -{ - auto accel = static_cast<ADClip7 *>(instance); - accel->connect_port(port, data); -} - -void activate(LV2_Handle instance) -{ -} - -void run(LV2_Handle instance, uint32_t num_samples) -{ - auto accel = static_cast<ADClip7 *>(instance); - accel->run(num_samples); -} - -void deactivate(LV2_Handle) -{ -} - -void destroy(LV2_Handle instance) -{ - delete static_cast<ADClip7 *>(instance); -} - -const void * extension_data(const char * uri) -{ - return nullptr; -} - -const LV2_Descriptor descriptor = { - PLUGIN_URI, - instantiate, - connect_port, - activate, - run, - deactivate, - destroy, - extension_data -}; - -} // anon namespace - -LV2_SYMBOL_EXPORT -const LV2_Descriptor * lv2_descriptor(uint32_t idx) -{ - if (idx == 0) - return &descriptor; - - return nullptr; -} diff --git a/plugins/LV2/src/Acceleration/Acceleration.cpp b/plugins/LV2/src/Acceleration/Acceleration.cpp index 824f4b3..c873e53 100644 --- a/plugins/LV2/src/Acceleration/Acceleration.cpp +++ b/plugins/LV2/src/Acceleration/Acceleration.cpp @@ -1,5 +1,6 @@ #include "Acceleration.h" #include <iostream> +#include <lv2wrapper.h> namespace { @@ -73,3 +74,6 @@ double Acceleration::getSampleRate() // #include <cmath> #include "../../../LinuxVST/src/Acceleration/AccelerationProc.cpp" + +// Create the LV2Wrapper and register the plugin +LV2Wrapper<Acceleration> accel; diff --git a/plugins/LV2/src/Acceleration/Acceleration.h b/plugins/LV2/src/Acceleration/Acceleration.h index cfef367..16efc9a 100644 --- a/plugins/LV2/src/Acceleration/Acceleration.h +++ b/plugins/LV2/src/Acceleration/Acceleration.h @@ -13,6 +13,8 @@ public: void connect_port(uint32_t port, void * data); void run(uint32_t num_samples); + static constexpr const char * URI = "https://www.airwindows.com/acceleration"; + private: void processReplacing(float **in, float **out, VstInt32 samples); void processDoubleReplacing(double **in, double **out, VstInt32 samples); diff --git a/plugins/LV2/src/Acceleration/lv2wrapper.cpp b/plugins/LV2/src/Acceleration/lv2wrapper.cpp deleted file mode 100644 index 3b1c04c..0000000 --- a/plugins/LV2/src/Acceleration/lv2wrapper.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "lv2/core/lv2.h" -#include "Acceleration.h" - -namespace { - -const char * ACCELERATION_URI = "https://www.airwindows.com/acceleration"; - -LV2_Handle instantiate( - const LV2_Descriptor * d, - double rate, - const char * path, - const LV2_Feature * const * features) -{ - return new Acceleration{rate}; -} - -void connect_port( - LV2_Handle instance, - uint32_t port, - void * data) -{ - auto accel = static_cast<Acceleration *>(instance); - accel->connect_port(port, data); -} - -void activate(LV2_Handle instance) -{ -} - -void run(LV2_Handle instance, uint32_t num_samples) -{ - auto accel = static_cast<Acceleration *>(instance); - accel->run(num_samples); -} - -void deactivate(LV2_Handle) -{ -} - -void destroy(LV2_Handle instance) -{ - delete static_cast<Acceleration *>(instance); -} - -const void * extension_data(const char * uri) -{ - return nullptr; -} - -const LV2_Descriptor descriptor = { - ACCELERATION_URI, - instantiate, - connect_port, - activate, - run, - deactivate, - destroy, - extension_data -}; - -} // anon namespace - -LV2_SYMBOL_EXPORT -const LV2_Descriptor * lv2_descriptor(uint32_t idx) -{ - if (idx == 0) - return &descriptor; - - return nullptr; -} |