From c2261774536686950aa6b9d8c829d3efd10e6021 Mon Sep 17 00:00:00 2001 From: Aleks Rutins Date: Fri, 14 Apr 2023 11:22:48 -0400 Subject: [PATCH] Use the C++ version of the LV2 libraries --- dynamite.cc | 40 ++-------------------------------------- dynamite.ttl | 11 ++++++++++- meson.build | 1 + plugin.cc | 13 +++---------- plugin.hh | 12 +++++++----- 5 files changed, 23 insertions(+), 54 deletions(-) diff --git a/dynamite.cc b/dynamite.cc index 1af40d3..ab328a7 100644 --- a/dynamite.cc +++ b/dynamite.cc @@ -1,42 +1,6 @@ #include #include "plugin.hh" -using Dynamite::Plugin; +using Dynamite::Drive; -static LV2_Handle -instantiate(const LV2_Descriptor* descriptor, - double rate, - const char* bundle_path, - const LV2_Feature* const* features) -{ - return new Plugin; -} - -static void -cleanup(LV2_Handle instance) -{ - delete (Plugin *)instance; -} - -static const void* -extension_data(const char *uri) -{ - return nullptr; -} - -static const LV2_Descriptor descriptor = { - "https://github.com/aleksrutins/dynamite", - instantiate, - (void (*)(LV2_Handle, uint32_t, void*)) &Plugin::connect_port, - (void (*)(LV2_Handle)) &Plugin::activate, - (void (*)(LV2_Handle, uint32_t)) &Plugin::run, - (void (*)(LV2_Handle)) &Plugin::deactivate, - cleanup, - extension_data -}; - -LV2_SYMBOL_EXPORT -const LV2_Descriptor* -lv2_descriptor(uint32_t index) { - return index == 0 ? &descriptor : nullptr; -} \ No newline at end of file +static int _ = Drive::register_class("https://github.com/aleksrutins/dynamite"); \ No newline at end of file diff --git a/dynamite.ttl b/dynamite.ttl index 3b28470..e23cacc 100644 --- a/dynamite.ttl +++ b/dynamite.ttl @@ -38,4 +38,13 @@ lv2:default 0.0 ; lv2:minimum -20.0 ; lv2:maximum 20.0 ; - ] . \ No newline at end of file + ] , + [ + a lv2:InputPort , lv2:ControlPort ; + lv2:index 3 ; + lv2:symbol "threshold" ; + lv2:name "Threshold" ; + lv2:default 1.0 ; + lv2:minimum -20.0 ; + lv2:maximum 60.0 ; + ]. \ No newline at end of file diff --git a/meson.build b/meson.build index f9ca107..811a0f2 100644 --- a/meson.build +++ b/meson.build @@ -28,6 +28,7 @@ shlib = shared_library('dynamite', srcs, name_prefix : '', dependencies : [ dependency('lv2'), + dependency('lv2-plugin'), cc.find_library('m'), dependency('threads') ] diff --git a/plugin.cc b/plugin.cc index 21cc181..2603259 100644 --- a/plugin.cc +++ b/plugin.cc @@ -1,14 +1,9 @@ -#include #include "plugin.hh" #include "util.hh" namespace Dynamite { - void Plugin::activate() { - - } - - void Plugin::connect_port(PluginPort port, void* data) { - switch(port) { + void Drive::connect_port(uint32_t port, void* data) { + switch((PluginPort)port) { case IN: input = (const float *)data; break; @@ -21,13 +16,11 @@ namespace Dynamite { } } - void Plugin::run(uint32_t n_samples) { + void Drive::run(uint32_t n_samples) { const float coeff = dbCo(*drive); for(uint32_t pos = 0; pos < n_samples; pos++) { output[pos] = input[pos] * coeff; } } - - void Plugin::deactivate() {} } \ No newline at end of file diff --git a/plugin.hh b/plugin.hh index 1c0044a..3af9681 100644 --- a/plugin.hh +++ b/plugin.hh @@ -1,19 +1,21 @@ #pragma once +#include #include +using namespace LV2; + namespace Dynamite { enum PluginPort { - IN, OUT, DRIVE + IN, OUT, DRIVE, THRESHOLD }; - class Plugin { + class Drive : public Plugin { const float *drive; const float *input; float *output; public: - void connect_port(PluginPort port, void* data); - void activate(); + Drive(double rate) : Plugin(1) {} + void connect_port(uint32_t port, void* data); void run(uint32_t n_samples); - void deactivate(); }; } \ No newline at end of file