From ed187c94dd75fc9d83c40781418a08e02d633411 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Mon, 26 Aug 2024 17:29:35 +0200 Subject: [PATCH] plugin api in common template and plugin_parameter enum --- templates/android/src/jni.cpp | 8 +---- templates/cmd/src/main.c | 8 +---- templates/common/src/plugin_api.h | 49 +++++++++++++++++++++++++++++++ templates/common/tibia-index.js | 26 ++++++++++++++++ templates/daisy-seed/src/main.cpp | 8 +---- templates/ios/src/native.mm | 8 +---- templates/lv2/src/lv2.c | 18 +----------- templates/vst3/src/vst3.c | 18 +----------- templates/web/src/processor.c | 8 +---- test/plugin.h | 8 ++--- test/run.sh | 7 +++++ 11 files changed, 93 insertions(+), 73 deletions(-) create mode 100644 templates/common/src/plugin_api.h create mode 100644 templates/common/tibia-index.js diff --git a/templates/android/src/jni.cpp b/templates/android/src/jni.cpp index f935597..a65dfa5 100644 --- a/templates/android/src/jni.cpp +++ b/templates/android/src/jni.cpp @@ -21,14 +21,8 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - #include "data.h" +#include "plugin_api.h" #include "plugin.h" #include diff --git a/templates/cmd/src/main.c b/templates/cmd/src/main.c index 97a9ed1..6f598f2 100644 --- a/templates/cmd/src/main.c +++ b/templates/cmd/src/main.c @@ -21,14 +21,8 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - #include "data.h" +#include "plugin_api.h" #include "plugin.h" #include diff --git a/templates/common/src/plugin_api.h b/templates/common/src/plugin_api.h new file mode 100644 index 0000000..dcd696b --- /dev/null +++ b/templates/common/src/plugin_api.h @@ -0,0 +1,49 @@ +/* + * Tibia + * + * Copyright (C) 2024 Orastron Srl unipersonale + * + * Tibia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * Tibia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tibia. If not, see . + * + * File author: Stefano D'Angelo + */ + +#ifndef PLUGIN_API_H +#define PLUGIN_API_H + +typedef struct { + void * handle; + const char * format; + const char * (*get_bindir)(void *handle); + const char * (*get_datadir)(void *handle); +} plugin_callbacks; + +typedef struct { + void * handle; + const char * format; + const char * (*get_bindir)(void *handle); + const char * (*get_datadir)(void *handle); + void (*set_parameter_begin)(void *handle, size_t index); + void (*set_parameter)(void *handle, size_t index, float value); + void (*set_parameter_end)(void *handle, size_t index); +} plugin_ui_callbacks; + +{{?it.product.parameters.length > 0}} +enum { + {{~it.product.parameters :p}} + plugin_parameter_{{=p.id}}, + {{~}} +}; +{{?}} + +#endif diff --git a/templates/common/tibia-index.js b/templates/common/tibia-index.js new file mode 100644 index 0000000..1dfd137 --- /dev/null +++ b/templates/common/tibia-index.js @@ -0,0 +1,26 @@ +/* + * Tibia + * + * Copyright (C) 2024 Orastron Srl unipersonale + * + * Tibia is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * Tibia is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tibia. If not, see . + * + * File author: Stefano D'Angelo + */ + +var path = require("path"); +var sep = path.sep; + +module.exports = function (data, api) { + api.generateFileFromTemplateFile(`src${sep}plugin_api.h`, `src${sep}plugin_api.h`, data); +}; diff --git a/templates/daisy-seed/src/main.cpp b/templates/daisy-seed/src/main.cpp index 7e218a7..43253b3 100644 --- a/templates/daisy-seed/src/main.cpp +++ b/templates/daisy-seed/src/main.cpp @@ -21,14 +21,8 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - #include "data.h" +#include "plugin_api.h" #include "plugin.h" #include diff --git a/templates/ios/src/native.mm b/templates/ios/src/native.mm index 509328f..b7c1ebe 100644 --- a/templates/ios/src/native.mm +++ b/templates/ios/src/native.mm @@ -21,14 +21,8 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - #include "data.h" +#include "plugin_api.h" #include "plugin.h" #if PARAMETERS_N > 0 #include diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index 03d46d4..787c25b 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -21,24 +21,8 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); - void (*set_parameter_begin)(void *handle, size_t index); - void (*set_parameter)(void *handle, size_t index, float value); - void (*set_parameter_end)(void *handle, size_t index); -} plugin_ui_callbacks; - #include "data.h" +#include "plugin_api.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" #include "plugin.h" diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index 9e8d180..f695277 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -21,29 +21,13 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); - void (*set_parameter_begin)(void *handle, size_t index); - void (*set_parameter)(void *handle, size_t index, float value); - void (*set_parameter_end)(void *handle, size_t index); -} plugin_ui_callbacks; - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #include "vst3_c_api.h" #pragma GCC diagnostic pop #include "data.h" +#include "plugin_api.h" #include "plugin.h" #ifdef DATA_UI # include "plugin_ui.h" diff --git a/templates/web/src/processor.c b/templates/web/src/processor.c index e658695..a559be3 100644 --- a/templates/web/src/processor.c +++ b/templates/web/src/processor.c @@ -21,14 +21,8 @@ #include #include -typedef struct { - void * handle; - const char * format; - const char * (*get_bindir)(void *handle); - const char * (*get_datadir)(void *handle); -} plugin_callbacks; - #include "data.h" +#include "plugin_api.h" #include "plugin.h" #include "string.h" diff --git a/test/plugin.h b/test/plugin.h index ffbbb13..56adce4 100644 --- a/test/plugin.h +++ b/test/plugin.h @@ -68,17 +68,17 @@ static void plugin_reset(plugin *instance) { static void plugin_set_parameter(plugin *instance, size_t index, float value) { switch (index) { - case 0: + case plugin_parameter_gain: //approx instance->gain = powf(10.f, 0.05f * value); instance->gain = ((2.6039890429412597e-4f * value + 0.032131027163547855f) * value + 1.f) / ((0.0012705124328080768f * value - 0.0666763481312185f) * value + 1.f); break; - case 1: + case plugin_parameter_delay: instance->delay = 0.001f * value; break; - case 2: + case plugin_parameter_cutoff: instance->cutoff = value; break; - case 3: + case plugin_parameter_bypass: instance->bypass = value >= 0.5f; break; } diff --git a/test/run.sh b/test/run.sh index 50f3173..4b3eeb8 100755 --- a/test/run.sh +++ b/test/run.sh @@ -1,32 +1,39 @@ #!/bin/sh dir=`dirname $0` +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/vst3 $dir/../tibia $dir/product.json,$dir/company.json,$dir/vst3.json $dir/../templates/vst3 $dir/../out/vst3 $dir/../tibia $dir/product.json,$dir/company.json,$dir/vst3.json,$dir/vst3-make.json $dir/../templates/vst3-make $dir/../out/vst3 cp $dir/plugin.h $dir/plugin_ui.h $dir/../out/vst3/src +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/lv2 $dir/../tibia $dir/product.json,$dir/company.json,$dir/lv2.json $dir/../templates/lv2 $dir/../out/lv2 $dir/../tibia $dir/product.json,$dir/company.json,$dir/lv2.json,$dir/lv2-make.json $dir/../templates/lv2-make $dir/../out/lv2 cp $dir/plugin.h $dir/plugin_ui.h $dir/../out/lv2/src +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/web $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web $dir/../out/web $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web-make $dir/../out/web $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/web-demo $dir/../out/web cp $dir/plugin.h $dir/../out/web/src +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/android $dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json $dir/../templates/android $dir/../out/android $dir/../tibia $dir/product.json,$dir/company.json,$dir/android.json,$dir/android-make.json $dir/../templates/android-make $dir/../out/android cp $dir/keystore.jks $dir/../out/android cp $dir/plugin.h $dir/../out/android/src +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/ios $dir/../tibia $dir/product.json,$dir/company.json,$dir/ios.json $dir/../templates/ios $dir/../out/ios $dir/../tibia $dir/product.json,$dir/company.json,$dir/ios.json,$dir/ios-make.json $dir/../templates/ios-make $dir/../out/ios cp $dir/plugin.h $dir/../out/ios/src +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/cmd $dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/cmd $dir/../out/cmd $dir/../tibia $dir/product.json,$dir/company.json,$dir/cmd-make.json $dir/../templates/cmd-make $dir/../out/cmd cp $dir/plugin.h $dir/../out/cmd/src +$dir/../tibia $dir/product.json,$dir/company.json $dir/../templates/common $dir/../out/daisy-seed $dir/../tibia $dir/product.json,$dir/company.json,$dir/daisy-seed.json $dir/../templates/daisy-seed $dir/../out/daisy-seed $dir/../tibia $dir/product.json,$dir/company.json,$dir/daisy-seed.json,$dir/daisy-seed-make.json $dir/../templates/daisy-seed-make $dir/../out/daisy-seed cp $dir/plugin.h $dir/../out/daisy-seed/src