[ardour-dev] logic to consider
Paul Davis
paul at linuxaudiosystems.com
Wed Dec 1 07:45:10 PST 2004
This is the actual code, in its almost pseudo-code-like simplicity,
that i am currently using to decide if we can configure a plugin
insert to match a given set of inputs+outputs. A -1 value for either
input or output counts means that we don't care about that
setting. the 3rd boolean argument to the function means that we
require an *exact* match on the number of inputs.
the "set_count()" function multiplies the (hidden) instances of the
plugin to get the required i/o counts.
If anyone has the time and inclination to review this, i'd appreciate
it. I've tried to comment it a bit more liberally than is my habit :)
int
PluginInsert::require_io (int32_t in, int32_t out, bool hard_input_limit)
{
int32_t outputs = _plugins[0]->get_info().n_outputs;
int32_t inputs = _plugins[0]->get_info().n_inputs;
if (in == 0 || out == 0) {
warning << _("programming error: ")
<< X_("PluginInsert::require_io() called with inputs/outputs = zero!")
<< endmsg;
return -1;
}
if (outputs == 0) {
warning << compose (_("plugin %1 has no outputs. It cannot be used as an insert."),
_plugins[0]->name())
<< endmsg;
return -1;
}
if (inputs == 0) {
/* instrument plugin, always legal, but it throws
away any existing active streams.
we do not multiply instrument plugins
to match in/out counts. if one instance
doesn't match the required outputs,
we fail.
*/
if (out != outputs) {
return -1;
}
return set_count (1);
}
if (out == -1) {
/* we don't care about outputs */
if (in == -1) {
/* we just don't care */
return set_count (1);
}
/* we care about the input set up */
if (hard_input_limit) {
/* the number of inputs requested must
be an exact multiple of natural plugin inputs.
*/
if ((in % inputs) != 0) {
return -1;
}
/*
examples:
in = 1, plugin = 1in, cnt = 1
in = 1, plugin = 2in, rejected by mod test
in = 2, plugin = 1in, cnt = 2
in = 2, plugin = 2in, cnt = 1
in = 2, plugin = 4in, rejected by mod test
in = 3, plugin = 2in, rejected by mod test
in = 4, plugin = 2in, cnt = 2
*/
return set_count (in/inputs);
} else {
/* natural plugin inputs must be >= than the
number of inputs requested.
*/
if (inputs < in) {
return -1;
}
/* we will use whatever input setup the plugin
has.
*/
/* use at least one plugin, or more if we
need more.
examples:
in = 1, plugin = 1in, cnt = 1
in = 1, plugin = 2in, cnt = 1
in = 2, plugin = 1in, cnt = 2
in = 2, plugin = 2in, cnt = 1
in = 2, plugin = 4in, cnt = 1
in = 3, plugin = 2in, cnt = ceil (3/2) = 2
in = 4, plugin = 2in, cnt = 2
*/
if (inputs > in) {
return set_count (1);
} else {
return set_count ((int32_t) ceil ((float)in/inputs));
}
}
}
if (in == -1) {
/* we don't care about inputs */
if (out == -1) {
/* we just don't care */
return set_count (1);
}
/* we care about the output set up */
/* the number of outputs requested must
be an exact multiple of natural plugin outputs.
*/
if ((out % outputs) != 0) {
return -1;
}
return set_count (out/outputs);
}
/* we care about both input and output */
/* require that the ratio of in/out requested matches
the ratio of the natural plugin in/out.
*/
if (((float)in/out) != ((float)inputs/outputs)) {
return -1;
}
/* requested inputs+outputs must be exact multiples of
natural plugin in/out.
*/
if (in % inputs != 0 || out % outputs != 0) {
return -1;
}
/* from here on we know that any adjustment
based on inputs will have the same effect
on outputs.
*/
if (inputs > in) {
/* examples:
in = 1, plugin = 2in, cnt = 1
in = 2, plugin = 3in, cnt = 1
*/
set_count (1);
} else {
/* examples:
in = 1, plugin = 1in, cnt = 1
in = 2, plugin = 2in, cnt = 1
in = 2, plugin = 1in, cnt = 2
in = 3, plugin = 1in, cnt = 3
in = 3, plugin = 2in, cnt = rejected by mod test
*/
set_count ((int32_t) ceil ((float)in / inputs));
}
return 0;
}
More information about the Ardour-Dev
mailing list