From 9474b4481e1477212122725e1a16d646f60f3248 Mon Sep 17 00:00:00 2001 From: Christopher Arndt Date: Wed, 16 Oct 2024 17:21:23 +0200 Subject: [PATCH] feat: add parameter range support Signed-off-by: Christopher Arndt --- examples/faustlpf.c | 8 +++--- examples/{lpf.dsp => faustlpf.dsp} | 0 examples/faustlpf.h | 40 +++++++++++++++++++++--------- examples/faustlpf.nim | 3 +++ examples/faustlpf_plugin.nim | 2 +- 5 files changed, 36 insertions(+), 17 deletions(-) rename examples/{lpf.dsp => faustlpf.dsp} (100%) diff --git a/examples/faustlpf.c b/examples/faustlpf.c index f127c7e..893cd88 100644 --- a/examples/faustlpf.c +++ b/examples/faustlpf.c @@ -3,14 +3,14 @@ // This file was generated using the Faust compiler (https://faust.grame.fr), // and the Faust post-processor (https://github.com/SpotlightKid/faustpp). // -// Source: lpf.dsp +// Source: faustlpf.dsp // Name: FaustLPF // Author: Christopher Arndt // Copyright: Christopher Arndt, 2024 // License: MIT // Version: 0.1.0 // FAUST version: 2.75.10 -// FAUST compilation options: -a /home/chris/tmp/tmp9v2ck7tz.c -lang c -rui -ct 1 -fm def -cn faustlpf -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0 -vec -lv 0 -vs 32 +// FAUST compilation options: -a /home/chris/tmp/tmpebxwoqng.c -lang c -rui -ct 1 -fm def -cn faustlpf -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0 -vec -lv 0 -vs 32 //------------------------------------------------------------------------------ @@ -79,9 +79,9 @@ void deletefaustlpf(faustlpf* dsp) { void metadatafaustlpf(MetaGlue* m) { m->declare(m->metaInterface, "author", "Christopher Arndt"); - m->declare(m->metaInterface, "compile_options", "-a /home/chris/tmp/tmp9v2ck7tz.c -lang c -rui -ct 1 -fm def -cn faustlpf -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0 -vec -lv 0 -vs 32"); + m->declare(m->metaInterface, "compile_options", "-a /home/chris/tmp/tmpebxwoqng.c -lang c -rui -ct 1 -fm def -cn faustlpf -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 0 -vec -lv 0 -vs 32"); m->declare(m->metaInterface, "copyright", "Christopher Arndt, 2024"); - m->declare(m->metaInterface, "filename", "lpf.dsp"); + m->declare(m->metaInterface, "filename", "faustlpf.dsp"); m->declare(m->metaInterface, "filters.lib/fir:author", "Julius O. Smith III"); m->declare(m->metaInterface, "filters.lib/fir:copyright", "Copyright (C) 2003-2019 by Julius O. Smith III "); m->declare(m->metaInterface, "filters.lib/fir:license", "MIT-style STK-4.3 license"); diff --git a/examples/lpf.dsp b/examples/faustlpf.dsp similarity index 100% rename from examples/lpf.dsp rename to examples/faustlpf.dsp diff --git a/examples/faustlpf.h b/examples/faustlpf.h index 688138b..570c0ba 100644 --- a/examples/faustlpf.h +++ b/examples/faustlpf.h @@ -47,6 +47,11 @@ void initfaustlpf(faustlpf* dsp, int sample_rate); void buildUserInterfacefaustlpf(faustlpf* dsp, UIGlue* ui_interface); void computefaustlpf(faustlpf* dsp, int count, FAUSTFLOAT** RESTRICT inputs, FAUSTFLOAT** RESTRICT outputs); +typedef struct { + FAUSTFLOAT init; + FAUSTFLOAT min; + FAUSTFLOAT max; +} ParameterRange; int parameter_group(unsigned index) { switch (index) { @@ -106,20 +111,31 @@ const char *parameter_symbol(unsigned index) { const char *parameter_unit(unsigned index) { switch (index) { - + case 0: return "Hz"; - + default: return 0; } } +const ParameterRange *parameter_range(unsigned index) { + switch (index) { + case 0: { + static const ParameterRange range = { 15000.0, 16.0, 15000.0 }; + return ⦥ + } + + default: + return 0; + } +} bool parameter_is_trigger(unsigned index) { switch (index) { - + default: return false; } @@ -127,7 +143,7 @@ bool parameter_is_trigger(unsigned index) { bool parameter_is_boolean(unsigned index) { switch (index) { - + default: return false; } @@ -135,7 +151,7 @@ bool parameter_is_boolean(unsigned index) { bool parameter_is_enum(unsigned index) { switch (index) { - + default: return false; } @@ -143,7 +159,7 @@ bool parameter_is_enum(unsigned index) { bool parameter_is_integer(unsigned index) { switch (index) { - + default: return false; } @@ -151,10 +167,10 @@ bool parameter_is_integer(unsigned index) { bool parameter_is_logarithmic(unsigned index) { switch (index) { - + case 0: return true; - + default: return false; } @@ -162,10 +178,10 @@ bool parameter_is_logarithmic(unsigned index) { FAUSTFLOAT get_parameter(faustlpf* dsp, unsigned index) { switch (index) { - + case 0: return dsp->fHslider0; - + default: (void)dsp; return 0.0; @@ -174,11 +190,11 @@ FAUSTFLOAT get_parameter(faustlpf* dsp, unsigned index) { void set_parameter(faustlpf* dsp, unsigned index, FAUSTFLOAT value) { switch (index) { - + case 0: dsp->fHslider0 = value; break; - + default: (void)dsp; (void)value; diff --git a/examples/faustlpf.nim b/examples/faustlpf.nim index be63b06..3c44f37 100644 --- a/examples/faustlpf.nim +++ b/examples/faustlpf.nim @@ -2,6 +2,8 @@ type faustlpf* = object + ParameterRange* = object + init*, min*, max*: cfloat SampleBuffer* = UncheckedArray[cfloat] @@ -11,6 +13,7 @@ proc initfaustlpf*(dsp: ptr faustlpf, sample_rate: cint) {.importc.} proc instanceClearfaustlpf*(dsp: ptr faustlpf) {.importc.} proc computefaustlpf*(dsp: ptr faustlpf, count: cint, inputs, outputs: ptr ptr SampleBuffer) {.importc.} +proc parameter_range*(index: cuint): ptr ParameterRange {.importc.} proc parameter_group*(index: cuint): cint {.importc} proc parameter_is_boolean*(index: cuint): bool {.importc} proc parameter_is_enum*(index: cuint): bool {.importc} diff --git a/examples/faustlpf_plugin.nim b/examples/faustlpf_plugin.nim index 6aabebd..bb951e1 100644 --- a/examples/faustlpf_plugin.nim +++ b/examples/faustlpf_plugin.nim @@ -50,7 +50,7 @@ proc activate(instance: Lv2Handle) {.cdecl.} = proc run(instance: Lv2Handle; nSamples: cuint) {.cdecl.} = let plug = cast[ptr FaustLPFPlugin](instance) - set_cutoff(plug.flt, plug.freq[]) + plug.flt.set_cutoff(plug.freq[]) computefaustlpf(plug.flt, nSamples.cint, addr plug.input, addr plug.output)