From a2aaa713920c7e22dc4f99426acc5389a42f730c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 10 Aug 2021 20:38:38 +0200 Subject: [PATCH] filter-chain: simplify plugin API some more --- src/modules/module-filter-chain.c | 21 ++--- .../module-filter-chain/builtin_plugin.c | 87 +++++-------------- .../module-filter-chain/ladspa_plugin.c | 30 ++----- src/modules/module-filter-chain/plugin.h | 10 +-- 4 files changed, 41 insertions(+), 107 deletions(-) diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 886ba8c70..c9601e297 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -318,7 +318,7 @@ done: static float get_default(struct impl *impl, struct descriptor *desc, uint32_t p) { struct fc_port *port = &desc->desc->ports[p]; - return port->get_param(port, "default"); + return port->def; } static struct node *find_node(struct graph *graph, const char *name) @@ -388,13 +388,8 @@ static struct spa_pod *get_prop_info(struct graph *graph, struct spa_pod_builder struct descriptor *desc = node->desc; const struct fc_descriptor *d = desc->desc; struct fc_port *p = &d->ports[port->p]; - float def, min, max; char name[512]; - def = p->get_param(p, "default"); - min = p->get_param(p, "min"); - max = p->get_param(p, "max"); - if (node->name[0] != '\0') snprintf(name, sizeof(name), "%s:%s", node->name, p->name); else @@ -407,13 +402,13 @@ static struct spa_pod *get_prop_info(struct graph *graph, struct spa_pod_builder SPA_PROP_INFO_name, SPA_POD_String(name), 0); spa_pod_builder_prop(b, SPA_PROP_INFO_type, 0); - if (min == max) { - spa_pod_builder_float(b, def); + if (p->min == p->max) { + spa_pod_builder_float(b, p->def); } else { spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_Range, 0); - spa_pod_builder_float(b, def); - spa_pod_builder_float(b, min); - spa_pod_builder_float(b, max); + spa_pod_builder_float(b, p->def); + spa_pod_builder_float(b, p->min); + spa_pod_builder_float(b, p->max); spa_pod_builder_pop(b, &f[1]); } spa_pod_builder_prop(b, SPA_PROP_INFO_params, 0); @@ -736,10 +731,10 @@ static struct plugin *plugin_load(struct impl *impl, const char *type, const cha } } - if (spa_streq(path, "builtin")) { + if (spa_streq(type, "builtin")) { pl = load_builtin_plugin(path, NULL); } - else if (spa_streq(path, "ladspa")) { + else if (spa_streq(type, "ladspa")) { pl = load_ladspa_plugin(path, NULL); } if (pl == NULL) diff --git a/src/modules/module-filter-chain/builtin_plugin.c b/src/modules/module-filter-chain/builtin_plugin.c index 3f6ab926c..81e33520b 100644 --- a/src/modules/module-filter-chain/builtin_plugin.c +++ b/src/modules/module-filter-chain/builtin_plugin.c @@ -89,10 +89,6 @@ static struct fc_port copy_ports[] = { static const struct fc_descriptor copy_desc = { .name = "copy", - //.Name = "Copy input to output", - //.Maker = "PipeWire", - //.Copyright = "MIT", - .n_ports = 2, .ports = copy_ports, @@ -122,14 +118,6 @@ static void mixer_run(void * Instance, unsigned long SampleCount) } } -#if 0 -static const LADSPA_PortRangeHint mixer_range_hints[] = { - { 0, }, { 0, }, { 0, }, - { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_1, 0.0, 10.0 }, - { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_1, 0.0, 10.0 } -}; -#endif - static struct fc_port mixer_ports[] = { { .index = 0, .name = "Out", @@ -146,29 +134,18 @@ static struct fc_port mixer_ports[] = { { .index = 3, .name = "Gain 1", .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + .def = 1.0f, .min = 0.0f, .max = 10.0f }, { .index = 4, .name = "Gain 2", .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + .def = 1.0f, .min = 0.0f, .max = 10.0f }, }; -static const char *mixer_get_prop(struct fc_descriptor *desc, const char *name) -{ - if (spa_streq(name, "description")) - return "Mix 2 inputs"; - if (spa_streq(name, "maker")) - return "PipeWire"; - if (spa_streq(name, "copyright")) - return "MIT"; - return NULL; -} - static const struct fc_descriptor mixer_desc = { .name = "mixer", - .get_prop = mixer_get_prop, - .n_ports = 5, .ports = mixer_ports, @@ -178,18 +155,6 @@ static const struct fc_descriptor mixer_desc = { .cleanup = builtin_cleanup, }; -#if 0 -static const LADSPA_PortRangeHint bq_range_hints[] = { - { 0, }, { 0, }, - { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | - LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_DEFAULT_LOW, 0.0, 1.0 }, - { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | - LADSPA_HINT_DEFAULT_0, 0.0, 10.0 }, - { LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | - LADSPA_HINT_DEFAULT_0, -120.0, 5.0 }, -}; -#endif - static struct fc_port bq_ports[] = { { .index = 0, .name = "Out", @@ -202,14 +167,18 @@ static struct fc_port bq_ports[] = { { .index = 2, .name = "Freq", .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + .hint = LADSPA_HINT_SAMPLE_RATE, + .def = 0.0f, .min = 0.0f, .max = 1.0f, }, { .index = 3, .name = "Q", .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + .def = 0.0f, .min = 0.0f, .max = 10.0f, }, { .index = 4, .name = "Gain", .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, + .def = 0.0f, .min = -120.0f, .max = 5.0f, }, }; @@ -264,9 +233,7 @@ static void bq_lowpass_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_lowpass_desc = { .name = "bq_lowpass", - //.Name = "Biquad lowpass filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, @@ -285,11 +252,10 @@ static void bq_highpass_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_highpass_desc = { .name = "bq_highpass", - //.Name = "Biquad highpass filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_highpass_run, @@ -305,11 +271,10 @@ static void bq_bandpass_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_bandpass_desc = { .name = "bq_bandpass", - //.Name = "Biquad bandpass filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_bandpass_run, @@ -325,11 +290,10 @@ static void bq_lowshelf_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_lowshelf_desc = { .name = "bq_lowshelf", - //.Name = "Biquad lowshelf filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_lowshelf_run, @@ -345,11 +309,10 @@ static void bq_highshelf_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_highshelf_desc = { .name = "bq_highshelf", - //.Name = "Biquad highshelf filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_highshelf_run, @@ -365,11 +328,10 @@ static void bq_peaking_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_peaking_desc = { .name = "bq_peaking", - //.Name = "Biquad peaking filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_peaking_run, @@ -385,11 +347,10 @@ static void bq_notch_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_notch_desc = { .name = "bq_notch", - //.Name = "Biquad notch filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_notch_run, @@ -406,11 +367,10 @@ static void bq_allpass_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor bq_allpass_desc = { .name = "bq_allpass", - //.Name = "Biquad allpass filter", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 5, .ports = bq_ports, + .instantiate = builtin_instantiate, .connect_port = builtin_connect_port, .run = bq_allpass_run, @@ -495,11 +455,10 @@ static void convolve_run(void * Instance, unsigned long SampleCount) static const struct fc_descriptor convolve_desc = { .name = "convolver", - //.Name = "Convolver", - //.Maker = "PipeWire", - //.Copyright = "MIT", + .n_ports = 2, .ports = convolve_ports, + .instantiate = convolver_instantiate, .connect_port = convolver_connect_port, .run = convolve_run, diff --git a/src/modules/module-filter-chain/ladspa_plugin.c b/src/modules/module-filter-chain/ladspa_plugin.c index 194f3f6ce..de042560e 100644 --- a/src/modules/module-filter-chain/ladspa_plugin.c +++ b/src/modules/module-filter-chain/ladspa_plugin.c @@ -67,11 +67,6 @@ static const LADSPA_Descriptor *find_desc(LADSPA_Descriptor_Function desc_func, return NULL; } -static const char *ladspa_get_prop(struct fc_descriptor *desc, const char *name) -{ - return NULL; -} - static float get_default(struct fc_port *port, LADSPA_PortRangeHintDescriptor hint, LADSPA_Data lower, LADSPA_Data upper) { @@ -126,9 +121,8 @@ static float get_default(struct fc_port *port, LADSPA_PortRangeHintDescriptor hi return def; } -static float ladspa_port_get_param(struct fc_port *port, const char *name) +static void ladspa_port_update_ranges(struct descriptor *dd, struct fc_port *port) { - struct descriptor *dd = (struct descriptor*)port->desc; const LADSPA_Descriptor *d = dd->d; unsigned long p = port->index; LADSPA_PortRangeHintDescriptor hint = d->PortRangeHints[p].HintDescriptor; @@ -137,21 +131,10 @@ static float ladspa_port_get_param(struct fc_port *port, const char *name) lower = d->PortRangeHints[p].LowerBound; upper = d->PortRangeHints[p].UpperBound; - if (LADSPA_IS_HINT_SAMPLE_RATE(hint)) { - lower *= (LADSPA_Data) 48000.0f; - upper *= (LADSPA_Data) 48000.0f; - } - - if (spa_streq(name, "default")) { - return get_default(port, hint, lower, upper); - } - if (spa_streq(name, "min")) { - return lower; - } - if (spa_streq(name, "max")) { - return upper; - } - return 0.0f; + port->hint = hint; + port->def = get_default(port, hint, lower, upper); + port->min = lower; + port->max = upper; } static void ladspa_free(struct fc_descriptor *desc) @@ -183,7 +166,6 @@ static const struct fc_descriptor *ladspa_make_desc(struct fc_plugin *plugin, co desc->desc.run = d->run; desc->desc.free = ladspa_free; - desc->desc.get_prop = ladspa_get_prop; desc->desc.name = d->Label; desc->desc.flags = d->Properties; @@ -195,7 +177,7 @@ static const struct fc_descriptor *ladspa_make_desc(struct fc_plugin *plugin, co desc->desc.ports[i].index = i; desc->desc.ports[i].name = d->PortNames[i]; desc->desc.ports[i].flags = d->PortDescriptors[i]; - desc->desc.ports[i].get_param = ladspa_port_get_param; + ladspa_port_update_ranges(desc, &desc->desc.ports[i]); } return &desc->desc; } diff --git a/src/modules/module-filter-chain/plugin.h b/src/modules/module-filter-chain/plugin.h index bd22bb10f..b773a4e5c 100644 --- a/src/modules/module-filter-chain/plugin.h +++ b/src/modules/module-filter-chain/plugin.h @@ -39,23 +39,21 @@ struct fc_plugin { struct fc_port { uint32_t index; - struct fc_descriptor *desc; const char *name; uint64_t flags; - float (*get_param) (struct fc_port *port, const char *name); + uint64_t hint; + float def; + float min; + float max; }; struct fc_descriptor { - struct fc_plugin *plugin; - const char *name; uint64_t flags; void (*free) (struct fc_descriptor *desc); - const char *(*get_prop) (struct fc_descriptor *desc, const char *name); - uint32_t n_ports; struct fc_port *ports;