filter-chain: simplify plugin API some more

This commit is contained in:
Wim Taymans 2021-08-10 20:38:38 +02:00
parent 48136b4c2b
commit a2aaa71392
4 changed files with 41 additions and 107 deletions

View file

@ -318,7 +318,7 @@ done:
static float get_default(struct impl *impl, struct descriptor *desc, uint32_t p) static float get_default(struct impl *impl, struct descriptor *desc, uint32_t p)
{ {
struct fc_port *port = &desc->desc->ports[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) 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; struct descriptor *desc = node->desc;
const struct fc_descriptor *d = desc->desc; const struct fc_descriptor *d = desc->desc;
struct fc_port *p = &d->ports[port->p]; struct fc_port *p = &d->ports[port->p];
float def, min, max;
char name[512]; 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') if (node->name[0] != '\0')
snprintf(name, sizeof(name), "%s:%s", node->name, p->name); snprintf(name, sizeof(name), "%s:%s", node->name, p->name);
else 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), SPA_PROP_INFO_name, SPA_POD_String(name),
0); 0);
spa_pod_builder_prop(b, SPA_PROP_INFO_type, 0); spa_pod_builder_prop(b, SPA_PROP_INFO_type, 0);
if (min == max) { if (p->min == p->max) {
spa_pod_builder_float(b, def); spa_pod_builder_float(b, p->def);
} else { } else {
spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_Range, 0); spa_pod_builder_push_choice(b, &f[1], SPA_CHOICE_Range, 0);
spa_pod_builder_float(b, def); spa_pod_builder_float(b, p->def);
spa_pod_builder_float(b, min); spa_pod_builder_float(b, p->min);
spa_pod_builder_float(b, max); spa_pod_builder_float(b, p->max);
spa_pod_builder_pop(b, &f[1]); spa_pod_builder_pop(b, &f[1]);
} }
spa_pod_builder_prop(b, SPA_PROP_INFO_params, 0); 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); pl = load_builtin_plugin(path, NULL);
} }
else if (spa_streq(path, "ladspa")) { else if (spa_streq(type, "ladspa")) {
pl = load_ladspa_plugin(path, NULL); pl = load_ladspa_plugin(path, NULL);
} }
if (pl == NULL) if (pl == NULL)

View file

@ -89,10 +89,6 @@ static struct fc_port copy_ports[] = {
static const struct fc_descriptor copy_desc = { static const struct fc_descriptor copy_desc = {
.name = "copy", .name = "copy",
//.Name = "Copy input to output",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 2, .n_ports = 2,
.ports = copy_ports, .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[] = { static struct fc_port mixer_ports[] = {
{ .index = 0, { .index = 0,
.name = "Out", .name = "Out",
@ -146,29 +134,18 @@ static struct fc_port mixer_ports[] = {
{ .index = 3, { .index = 3,
.name = "Gain 1", .name = "Gain 1",
.flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
.def = 1.0f, .min = 0.0f, .max = 10.0f
}, },
{ .index = 4, { .index = 4,
.name = "Gain 2", .name = "Gain 2",
.flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, .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 = { static const struct fc_descriptor mixer_desc = {
.name = "mixer", .name = "mixer",
.get_prop = mixer_get_prop,
.n_ports = 5, .n_ports = 5,
.ports = mixer_ports, .ports = mixer_ports,
@ -178,18 +155,6 @@ static const struct fc_descriptor mixer_desc = {
.cleanup = builtin_cleanup, .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[] = { static struct fc_port bq_ports[] = {
{ .index = 0, { .index = 0,
.name = "Out", .name = "Out",
@ -202,14 +167,18 @@ static struct fc_port bq_ports[] = {
{ .index = 2, { .index = 2,
.name = "Freq", .name = "Freq",
.flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
.hint = LADSPA_HINT_SAMPLE_RATE,
.def = 0.0f, .min = 0.0f, .max = 1.0f,
}, },
{ .index = 3, { .index = 3,
.name = "Q", .name = "Q",
.flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, .flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL,
.def = 0.0f, .min = 0.0f, .max = 10.0f,
}, },
{ .index = 4, { .index = 4,
.name = "Gain", .name = "Gain",
.flags = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL, .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 = { static const struct fc_descriptor bq_lowpass_desc = {
.name = "bq_lowpass", .name = "bq_lowpass",
//.Name = "Biquad lowpass filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .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 = { static const struct fc_descriptor bq_highpass_desc = {
.name = "bq_highpass", .name = "bq_highpass",
//.Name = "Biquad highpass filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_highpass_run, .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 = { static const struct fc_descriptor bq_bandpass_desc = {
.name = "bq_bandpass", .name = "bq_bandpass",
//.Name = "Biquad bandpass filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_bandpass_run, .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 = { static const struct fc_descriptor bq_lowshelf_desc = {
.name = "bq_lowshelf", .name = "bq_lowshelf",
//.Name = "Biquad lowshelf filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_lowshelf_run, .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 = { static const struct fc_descriptor bq_highshelf_desc = {
.name = "bq_highshelf", .name = "bq_highshelf",
//.Name = "Biquad highshelf filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_highshelf_run, .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 = { static const struct fc_descriptor bq_peaking_desc = {
.name = "bq_peaking", .name = "bq_peaking",
//.Name = "Biquad peaking filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_peaking_run, .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 = { static const struct fc_descriptor bq_notch_desc = {
.name = "bq_notch", .name = "bq_notch",
//.Name = "Biquad notch filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_notch_run, .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 = { static const struct fc_descriptor bq_allpass_desc = {
.name = "bq_allpass", .name = "bq_allpass",
//.Name = "Biquad allpass filter",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 5, .n_ports = 5,
.ports = bq_ports, .ports = bq_ports,
.instantiate = builtin_instantiate, .instantiate = builtin_instantiate,
.connect_port = builtin_connect_port, .connect_port = builtin_connect_port,
.run = bq_allpass_run, .run = bq_allpass_run,
@ -495,11 +455,10 @@ static void convolve_run(void * Instance, unsigned long SampleCount)
static const struct fc_descriptor convolve_desc = { static const struct fc_descriptor convolve_desc = {
.name = "convolver", .name = "convolver",
//.Name = "Convolver",
//.Maker = "PipeWire",
//.Copyright = "MIT",
.n_ports = 2, .n_ports = 2,
.ports = convolve_ports, .ports = convolve_ports,
.instantiate = convolver_instantiate, .instantiate = convolver_instantiate,
.connect_port = convolver_connect_port, .connect_port = convolver_connect_port,
.run = convolve_run, .run = convolve_run,

View file

@ -67,11 +67,6 @@ static const LADSPA_Descriptor *find_desc(LADSPA_Descriptor_Function desc_func,
return NULL; 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, static float get_default(struct fc_port *port, LADSPA_PortRangeHintDescriptor hint,
LADSPA_Data lower, LADSPA_Data upper) LADSPA_Data lower, LADSPA_Data upper)
{ {
@ -126,9 +121,8 @@ static float get_default(struct fc_port *port, LADSPA_PortRangeHintDescriptor hi
return def; 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; const LADSPA_Descriptor *d = dd->d;
unsigned long p = port->index; unsigned long p = port->index;
LADSPA_PortRangeHintDescriptor hint = d->PortRangeHints[p].HintDescriptor; 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; lower = d->PortRangeHints[p].LowerBound;
upper = d->PortRangeHints[p].UpperBound; upper = d->PortRangeHints[p].UpperBound;
if (LADSPA_IS_HINT_SAMPLE_RATE(hint)) { port->hint = hint;
lower *= (LADSPA_Data) 48000.0f; port->def = get_default(port, hint, lower, upper);
upper *= (LADSPA_Data) 48000.0f; port->min = lower;
} port->max = upper;
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;
} }
static void ladspa_free(struct fc_descriptor *desc) 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.run = d->run;
desc->desc.free = ladspa_free; desc->desc.free = ladspa_free;
desc->desc.get_prop = ladspa_get_prop;
desc->desc.name = d->Label; desc->desc.name = d->Label;
desc->desc.flags = d->Properties; 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].index = i;
desc->desc.ports[i].name = d->PortNames[i]; desc->desc.ports[i].name = d->PortNames[i];
desc->desc.ports[i].flags = d->PortDescriptors[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; return &desc->desc;
} }

View file

@ -39,23 +39,21 @@ struct fc_plugin {
struct fc_port { struct fc_port {
uint32_t index; uint32_t index;
struct fc_descriptor *desc;
const char *name; const char *name;
uint64_t flags; 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_descriptor {
struct fc_plugin *plugin;
const char *name; const char *name;
uint64_t flags; uint64_t flags;
void (*free) (struct fc_descriptor *desc); void (*free) (struct fc_descriptor *desc);
const char *(*get_prop) (struct fc_descriptor *desc, const char *name);
uint32_t n_ports; uint32_t n_ports;
struct fc_port *ports; struct fc_port *ports;