diff --git a/templates/lv2/make/Makefile b/templates/lv2/make/Makefile new file mode 100644 index 0000000..7782d6e --- /dev/null +++ b/templates/lv2/make/Makefile @@ -0,0 +1,24 @@ +include vars.mk + +CC = gcc +CFLAGS = -fPIC -Wall -Wpedantic -Wextra -Wno-unused-parameter + +BUNDLE_DIR = ${BUNDLE_NAME}.lv2 + +SO_FILE := ${BUNDLE_NAME}.so + +all: build/${BUNDLE_DIR}/manifest.ttl build/${BUNDLE_DIR}/${SO_FILE} + +build/${BUNDLE_DIR}/manifest.ttl: data/manifest.ttl | build/${BUNDLE_DIR} + cp $^ $@ + +build/${BUNDLE_DIR}/${SO_FILE}: src/lv2.c | build/${BUNDLE_DIR} + ${CC} $^ -o $@ ${CFLAGS} -shared + +build/${BUNDLE_DIR}: + mkdir -p $@ + +clean: + rm -fr build + +.PHONY: clean diff --git a/templates/lv2/make/vars.mk b/templates/lv2/make/vars.mk new file mode 100644 index 0000000..92b8d2a --- /dev/null +++ b/templates/lv2/make/vars.mk @@ -0,0 +1 @@ +BUNDLE_NAME := {{=it.product.bundleName}} diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index 6f46869..d71b850 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -1,25 +1,26 @@ #include "lv2/core/lv2.h" +#include #include "data.h" #include "plugin.h" typedef struct { - plugin p; + plugin p; #if DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N > 0 - float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N]; + const float * x[DATA_PRODUCT_AUDIO_INPUT_CHANNELS_N]; #endif #if DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N > 0 - float * y[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N]; + float * y[DATA_PRODUCT_AUDIO_OUTPUT_CHANNELS_N]; #endif #if (DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N) > 0 - float * c[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N]; + float * c[DATA_PRODUCT_CONTROL_INPUTS_N + DATA_PRODUCT_CONTROL_OUTPUTS_N]; #endif #if DATA_PRODUCT_CONTROL_INPUTS_N > 0 - float params[DATA_PRODUCT_CONTROL_INPUTS_N}; + float params[DATA_PRODUCT_CONTROL_INPUTS_N]; #endif } plugin_instance; -static const LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double sample_rate, const char * bundle_path, const LV2_Feature * const * features) { +static LV2_Handle instantiate(const struct LV2_Descriptor * descriptor, double sample_rate, const char * bundle_path, const LV2_Feature * const * features) { plugin_instance *instance = malloc(sizeof(plugin_instance)); if (instance == NULL) return NULL; @@ -56,8 +57,8 @@ static void connect_port(LV2_Handle instance, uint32_t port, void * data_locatio static void activate(LV2_Handle instance) { plugin_instance * i = (plugin_instance *)instance; #if DATA_PRODUCT_CONTROL_INPUTS_N > 0 - for (size_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) - i->params[j] = i->c[j] != NULL ? i->c[j] : param_defaults[j]; + for (size_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) { + i->params[j] = i->c[j] != NULL ? *i->c[j] : param_defaults[j]; plugin_set_parameter(&i->p, j, i->params[j]); } #endif @@ -68,8 +69,8 @@ static void run(LV2_Handle instance, uint32_t sample_count) { plugin_instance * i = (plugin_instance *)instance; #if DATA_PRODUCT_CONTROL_INPUTS_N > 0 for (size_t j = 0; j < DATA_PRODUCT_CONTROL_INPUTS_N; j++) - if (i->c[j] != i->params[j]) { - i->params[j] = i->c[j]; + if (*i->c[j] != i->params[j]) { + i->params[j] = *i->c[j]; plugin_set_parameter(&i->p, j, i->params[j]); } #endif diff --git a/templates/lv2/tibia-index.js b/templates/lv2/tibia-index.js index 07116e8..1d810e0 100644 --- a/templates/lv2/tibia-index.js +++ b/templates/lv2/tibia-index.js @@ -62,4 +62,6 @@ module.exports = function (data, api) { api.copyFile(`src${sep}lv2.c`, `src${sep}lv2.c`); api.generateFileFromTemplateFile(`src${sep}data.h`, `src${sep}data.h`, data); api.copyFileIfNotExists(`src${sep}plugin.h`, `src${sep}plugin.h`); + api.copyFile(`make${sep}Makefile`, `Makefile`); + api.generateFileFromTemplateFile(`make${sep}vars.mk`, `vars.mk`, data); }; diff --git a/test/plugin.h b/test/plugin.h new file mode 100644 index 0000000..7253db1 --- /dev/null +++ b/test/plugin.h @@ -0,0 +1,35 @@ +typedef struct plugin { + float gain; + char bypass; +} plugin; + +void plugin_init(plugin *instance) { + instance->gain = 1.f; + instance->bypass = 0; +} + +void plugin_fini(plugin *instance) { +} + +void plugin_set_sample_rate(plugin *instance, float sample_rate) { +} + +void plugin_reset(plugin *instance) { +} + +void plugin_set_parameter(plugin *instance, size_t index, float value) { + switch (index) { + case 0: + instance->gain = value; + break; + case 1: + instance->bypass = value >= 0.5f; + break; + } +} + +void plugin_process(plugin *instance, const float **inputs, float **outputs, size_t n_samples) { + for (size_t i = 0; i < n_samples; i++) { + outputs[0][i] = instance->bypass ? inputs[0][i] : instance->gain * inputs[0][i]; + } +} diff --git a/test/run.sh b/test/run.sh index e3dcb9b..d42387b 100755 --- a/test/run.sh +++ b/test/run.sh @@ -2,4 +2,6 @@ dir=`dirname $0` $dir/../tibia $dir/product.json,$dir/company.json,$dir/vst3.json $dir/../templates/vst3 $dir/../out/vst3 +cp $dir/plugin.h $dir/../out/vst3/src $dir/../tibia $dir/product.json,$dir/company.json,$dir/lv2.json $dir/../templates/lv2 $dir/../out/lv2 +cp $dir/plugin.h $dir/../out/lv2/src