now lv2 works

This commit is contained in:
Stefano D'Angelo 2024-01-05 14:45:14 +01:00
parent 238ec0fff4
commit 4a7cbd79ab
6 changed files with 75 additions and 10 deletions

View File

@ -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

View File

@ -0,0 +1 @@
BUNDLE_NAME := {{=it.product.bundleName}}

View File

@ -1,25 +1,26 @@
#include "lv2/core/lv2.h"
#include <stdlib.h>
#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

View File

@ -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);
};

35
test/plugin.h Normal file
View File

@ -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];
}
}

View File

@ -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