From 391f9e9a0b7fa02ba56c8ebda793fffc47603715 Mon Sep 17 00:00:00 2001 From: Aleks Rutins Date: Fri, 14 Apr 2023 11:07:04 -0400 Subject: [PATCH] first commit --- .vscode/settings.json | 4 +++ LICENSE | 7 ++++++ dynamite.cc | 42 +++++++++++++++++++++++++++++++ dynamite.ttl | 41 +++++++++++++++++++++++++++++++ install.sh | 10 ++++++++ manifest.ttl | 6 +++++ meson.build | 57 +++++++++++++++++++++++++++++++++++++++++++ plugin.cc | 33 +++++++++++++++++++++++++ plugin.hh | 19 +++++++++++++++ util.hh | 6 +++++ 10 files changed, 225 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 LICENSE create mode 100644 dynamite.cc create mode 100644 dynamite.ttl create mode 100755 install.sh create mode 100644 manifest.ttl create mode 100644 meson.build create mode 100644 plugin.cc create mode 100644 plugin.hh create mode 100644 util.hh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..23f26b4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "mesonbuild.configureOnOpen": false, + "C_Cpp.default.compileCommands": "builddir/vscode_compile_commands.json" +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a39486c --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2023 Aleks Rutins + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/dynamite.cc b/dynamite.cc new file mode 100644 index 0000000..1af40d3 --- /dev/null +++ b/dynamite.cc @@ -0,0 +1,42 @@ +#include +#include "plugin.hh" + +using Dynamite::Plugin; + +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 diff --git a/dynamite.ttl b/dynamite.ttl new file mode 100644 index 0000000..3b28470 --- /dev/null +++ b/dynamite.ttl @@ -0,0 +1,41 @@ +@prefix lv2: . +@prefix rdf: . +@prefix rdfs: . +@prefix doap: . +@prefix foaf: . + + a lv2:Plugin , lv2:AmplifierPlugin , doap:Project ; + lv2:binary ; + doap:name "Dynamite" ; + doap:license ; + doap:maintainer [ + a foaf:Person ; + foaf:homepage ; + foaf:name "Aleks Rutins" ; + ] ; + lv2:optionalFeature lv2:hardRTCapable ; + + lv2:port + [ + a lv2:InputPort , lv2:AudioPort ; + lv2:index 0 ; + lv2:symbol "audio_in" ; + lv2:name "Audio Input" ; + ] , + + [ + a lv2:OutputPort , lv2:AudioPort ; + lv2:index 1 ; + lv2:symbol "audio_out" ; + lv2:name "Audio Output" ; + ] , + + [ + a lv2:InputPort , lv2:ControlPort ; + lv2:index 2 ; + lv2:symbol "drive" ; + lv2:name "Drive" ; + lv2:default 0.0 ; + lv2:minimum -20.0 ; + lv2:maximum 20.0 ; + ] . \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..f9547fe --- /dev/null +++ b/install.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +: "${PREFIX:="$HOME/.lv2"}" + +meson builddir +ninja -C builddir + +rm -rf $PREFIX/dynamite.lv2 +mkdir -p $PREFIX/dynamite.lv2 +cp {dynamite,manifest}.ttl builddir/dynamite.{so,dylib,dll} $PREFIX/dynamite.lv2/ \ No newline at end of file diff --git a/manifest.ttl b/manifest.ttl new file mode 100644 index 0000000..d0194f5 --- /dev/null +++ b/manifest.ttl @@ -0,0 +1,6 @@ +@prefix lv2: . +@prefix rdfs: . + + a lv2:Plugin ; + lv2:binary ; + rdfs:seeAlso . \ No newline at end of file diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..f9ca107 --- /dev/null +++ b/meson.build @@ -0,0 +1,57 @@ +project('dynamite', 'cpp', + version : '0.1', + default_options : ['warning_level=3', 'cpp_std=c++14']) + +srcs = [ + 'dynamite.cc', + 'plugin.cc', +] + +# These arguments are only used to build the shared library +# not the executables that use the library. +lib_args = [ + '-DBUILDING_DYNAMITE', + '-fvisibility=hidden', + '-fPIC', + '-Wl,-Bstatic', + '-Wl,-Bdynamic', + '-Wl,--as-needed', + '-shared' +] + +cc = meson.get_compiler('cpp') + +shlib = shared_library('dynamite', srcs, + install : false, + cpp_args : lib_args, + gnu_symbol_visibility : 'hidden', + name_prefix : '', + dependencies : [ + dependency('lv2'), + cc.find_library('m'), + dependency('threads') + ] +) + +# test_exe = executable('dynamite_test', 'dynamite_test.cpp', +# link_with : shlib) +# test('dynamite', test_exe) + +# Make this library usable as a Meson subproject. +#dynamite_dep = declare_dependency( +# include_directories: include_directories('.'), +# link_with : shlib) + +# Make this library usable from the system's11 +# package manager. +# install_headers('dynamite.hpp', subdir : 'dynamite') + +# pkg_mod = import('pkgconfig') +# pkg_mod.generate( +# name : 'dynamite', +# filebase : 'dynamite', +# description : 'Meson sample project.', +# subdirs : 'dynamite', +# libraries : shlib, +# version : '0.1', +# ) diff --git a/plugin.cc b/plugin.cc new file mode 100644 index 0000000..21cc181 --- /dev/null +++ b/plugin.cc @@ -0,0 +1,33 @@ +#include +#include "plugin.hh" +#include "util.hh" + +namespace Dynamite { + void Plugin::activate() { + + } + + void Plugin::connect_port(PluginPort port, void* data) { + switch(port) { + case IN: + input = (const float *)data; + break; + case OUT: + output = (float *)data; + break; + case DRIVE: + drive = (const float *)data; + break; + } + } + + void Plugin::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 new file mode 100644 index 0000000..1c0044a --- /dev/null +++ b/plugin.hh @@ -0,0 +1,19 @@ +#pragma once +#include + +namespace Dynamite { + enum PluginPort { + IN, OUT, DRIVE + }; + + class Plugin { + const float *drive; + const float *input; + float *output; + public: + void connect_port(PluginPort port, void* data); + void activate(); + void run(uint32_t n_samples); + void deactivate(); + }; +} \ No newline at end of file diff --git a/util.hh b/util.hh new file mode 100644 index 0000000..b7f4179 --- /dev/null +++ b/util.hh @@ -0,0 +1,6 @@ +#pragma once +#include + +inline float dbCo(float g) { + return powf(10.0f, g*0.05f); +} \ No newline at end of file