/*
- Copyright (C) 2000-2006 Paul Davis
+ Copyright (C) 2000-2006 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
*/
-#define __STDC_FORMAT_MACROS 1
#include <inttypes.h>
#include <vector>
error << string_compose(_("LADSPA: \"%1\" cannot be used, since it cannot do inplace processing"), _descriptor->Name) << endmsg;
throw failed_constructor();
}
-
+
_sample_rate = rate;
if (_descriptor->instantiate == 0) {
for (i = 0; i < port_cnt; ++i) {
if (LADSPA_IS_PORT_CONTROL(port_descriptor (i))) {
connect_port (i, &_control_data[i]);
-
+
if (LADSPA_IS_PORT_OUTPUT(port_descriptor (i)) &&
strcmp (port_names()[i], X_("latency")) == 0) {
_latency_control_port = &_control_data[i];
if (!LADSPA_IS_PORT_INPUT(port_descriptor (i))) {
continue;
}
-
+
_shadow_data[i] = default_value (i);
}
}
deactivate ();
cleanup ();
- GoingAway (); /* EMIT SIGNAL */
-
/* XXX who should close a plugin? */
// dlclose (module);
bool earlier_hint = false;
/* defaults - case 1 */
-
+
if (LADSPA_IS_HINT_HAS_DEFAULT(prh[port].HintDescriptor)) {
if (LADSPA_IS_HINT_DEFAULT_MINIMUM(prh[port].HintDescriptor)) {
ret = prh[port].LowerBound;
bounds_given = true;
sr_scaling = true;
- earlier_hint = true;
}
-
- /* FIXME: add support for logarithmic defaults */
-
+
else if (LADSPA_IS_HINT_DEFAULT_LOW(prh[port].HintDescriptor)) {
- ret = prh[port].LowerBound * 0.75f + prh[port].UpperBound * 0.25f;
+ if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) {
+ ret = exp(log(prh[port].LowerBound) * 0.75f + log(prh[port].UpperBound) * 0.25f);
+ }
+ else {
+ ret = prh[port].LowerBound * 0.75f + prh[port].UpperBound * 0.25f;
+ }
bounds_given = true;
sr_scaling = true;
- earlier_hint = true;
}
else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(prh[port].HintDescriptor)) {
- ret = prh[port].LowerBound * 0.50f + prh[port].UpperBound * 0.50f;
+ if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) {
+ ret = exp(log(prh[port].LowerBound) * 0.5f + log(prh[port].UpperBound) * 0.5f);
+ }
+ else {
+ ret = prh[port].LowerBound * 0.5f + prh[port].UpperBound * 0.5f;
+ }
bounds_given = true;
sr_scaling = true;
- earlier_hint = true;
}
else if (LADSPA_IS_HINT_DEFAULT_HIGH(prh[port].HintDescriptor)) {
- ret = prh[port].LowerBound * 0.25f + prh[port].UpperBound * 0.75f;
+ if (LADSPA_IS_HINT_LOGARITHMIC(prh[port].HintDescriptor)) {
+ ret = exp(log(prh[port].LowerBound) * 0.25f + log(prh[port].UpperBound) * 0.75f);
+ }
+ else {
+ ret = prh[port].LowerBound * 0.25f + prh[port].UpperBound * 0.75f;
+ }
bounds_given = true;
sr_scaling = true;
- earlier_hint = true;
}
else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(prh[port].HintDescriptor)) {
ret = prh[port].UpperBound;
bounds_given = true;
sr_scaling = true;
- earlier_hint = true;
}
else if (LADSPA_IS_HINT_DEFAULT_0(prh[port].HintDescriptor)) {
ret = 0.0f;
ret = 0.0f;
}
}
-
+
/* defaults - case 2 */
else if (LADSPA_IS_HINT_BOUNDED_BELOW(prh[port].HintDescriptor) &&
!LADSPA_IS_HINT_BOUNDED_ABOVE(prh[port].HintDescriptor)) {
-
+
if (prh[port].LowerBound < 0) {
ret = 0.0f;
} else {
bounds_given = true;
sr_scaling = true;
}
-
+
/* defaults - case 3 */
else if (!LADSPA_IS_HINT_BOUNDED_BELOW(prh[port].HintDescriptor) &&
LADSPA_IS_HINT_BOUNDED_ABOVE(prh[port].HintDescriptor)) {
-
+
if (prh[port].UpperBound > 0) {
ret = 0.0f;
} else {
bounds_given = true;
sr_scaling = true;
}
-
+
/* defaults - case 4 */
else if (LADSPA_IS_HINT_BOUNDED_BELOW(prh[port].HintDescriptor) &&
LADSPA_IS_HINT_BOUNDED_ABOVE(prh[port].HintDescriptor)) {
-
+
if (prh[port].LowerBound < 0 && prh[port].UpperBound > 0) {
ret = 0.0f;
} else if (prh[port].LowerBound < 0 && prh[port].UpperBound < 0) {
} else {
ret = prh[port].LowerBound;
}
- bounds_given = true;
+ bounds_given = true;
sr_scaling = true;
}
-
+
/* defaults - case 5 */
-
+
if (LADSPA_IS_HINT_SAMPLE_RATE(prh[port].HintDescriptor) && !earlier_hint) {
if (bounds_given) {
if (sr_scaling) {
}
return ret;
-}
+}
void
LadspaPlugin::set_parameter (uint32_t which, float val)
controls[which]->Changed ();
}
#endif
-
+
} else {
warning << string_compose (_("illegal parameter number used with plugin \"%1\". This may"
"indicate a change in the plugin design, and presets may be"
for (uint32_t i = 0; i < parameter_count(); ++i){
- if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) &&
+ if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) &&
LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
child = new XMLNode("Port");
}
int
-LadspaPlugin::set_state(const XMLNode& node)
+LadspaPlugin::set_state (const XMLNode& node, int version)
{
+ if (version < 3000) {
+ return set_state_2X (node, version);
+ }
+
XMLNodeList nodes;
XMLProperty *prop;
XMLNodeConstIterator iter;
return 0;
}
+int
+LadspaPlugin::set_state_2X (const XMLNode& node, int /* version */)
+{
+ XMLNodeList nodes;
+ XMLProperty *prop;
+ XMLNodeConstIterator iter;
+ XMLNode *child;
+ const char *port;
+ const char *data;
+ uint32_t port_id;
+ LocaleGuard lg (X_("POSIX"));
+
+ if (node.name() != state_node_name()) {
+ error << _("Bad node sent to LadspaPlugin::set_state") << endmsg;
+ return -1;
+ }
+
+ nodes = node.children ("port");
+
+ for(iter = nodes.begin(); iter != nodes.end(); ++iter){
+
+ child = *iter;
+
+ if ((prop = child->property("number")) != 0) {
+ port = prop->value().c_str();
+ } else {
+ warning << _("LADSPA: no ladspa port number") << endmsg;
+ continue;
+ }
+ if ((prop = child->property("value")) != 0) {
+ data = prop->value().c_str();
+ } else {
+ warning << _("LADSPA: no ladspa port data") << endmsg;
+ continue;
+ }
+
+ sscanf (port, "%" PRIu32, &port_id);
+ set_parameter (port_id, atof(data));
+ }
+
+ latency_compute_run ();
+
+ return 0;
+}
+
int
LadspaPlugin::get_parameter_descriptor (uint32_t which, ParameterDescriptor& desc) const
{
LADSPA_PortRangeHint prh;
prh = port_range_hints()[which];
-
+
if (LADSPA_IS_HINT_BOUNDED_BELOW(prh.HintDescriptor)) {
desc.min_unbound = false;
desc.min_unbound = true;
desc.lower = 0;
}
-
+
if (LADSPA_IS_HINT_BOUNDED_ABOVE(prh.HintDescriptor)) {
desc.max_unbound = false;
desc.max_unbound = true;
desc.upper = 4; /* completely arbitrary */
}
-
+
if (LADSPA_IS_HINT_INTEGER (prh.HintDescriptor)) {
desc.step = 1.0;
desc.smallstep = 0.1;
desc.smallstep = delta / 10000.0f;
desc.largestep = delta/10.0f;
}
-
+
desc.toggled = LADSPA_IS_HINT_TOGGLED (prh.HintDescriptor);
desc.logarithmic = LADSPA_IS_HINT_LOGARITHMIC (prh.HintDescriptor);
desc.sr_dependent = LADSPA_IS_HINT_SAMPLE_RATE (prh.HintDescriptor);
set<Evoral::Parameter> ret;
for (uint32_t i = 0; i < parameter_count(); ++i){
- if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) &&
+ if (LADSPA_IS_PORT_INPUT(port_descriptor (i)) &&
LADSPA_IS_PORT_CONTROL(port_descriptor (i))){
-
+
ret.insert (ret.end(), Evoral::Parameter(PluginAutomation, 0, i));
}
}
}
int
-LadspaPlugin::connect_and_run (BufferSet& bufs, uint32_t& in_index, uint32_t& out_index, nframes_t nframes, nframes_t offset)
+LadspaPlugin::connect_and_run (BufferSet& bufs,
+ ChanMapping in_map, ChanMapping out_map,
+ nframes_t nframes, nframes_t offset)
{
- uint32_t port_index = 0;
- cycles_t then, now;
-
- then = get_cycles ();
-
- const uint32_t nbufs = bufs.count().n_audio();
-
- while (port_index < parameter_count()) {
- if (LADSPA_IS_PORT_AUDIO (port_descriptor(port_index))) {
- if (LADSPA_IS_PORT_INPUT (port_descriptor(port_index))) {
- const size_t index = min(in_index, nbufs - 1);
- connect_port (port_index, bufs.get_audio(index).data(offset));
- //cerr << this << ' ' << name() << " @ " << offset << " inport " << in_index << " = buf "
- // << min((uint32_t)in_index,nbufs) << " = " << &bufs[min((uint32_t)in_index,nbufs)][offset] << endl;
- in_index++;
-
-
- } else if (LADSPA_IS_PORT_OUTPUT (port_descriptor (port_index))) {
- const size_t index = min(out_index,nbufs - 1);
- connect_port (port_index, bufs.get_audio(index).data(offset));
- // cerr << this << ' ' << name() << " @ " << offset << " outport " << out_index << " = buf "
- // << min((uint32_t)out_index,nbufs) << " = " << &bufs[min((uint32_t)out_index,nbufs)][offset] << endl;
- out_index++;
+ cycles_t now;
+ cycles_t then = get_cycles ();
+
+ uint32_t audio_in_index = 0;
+ uint32_t audio_out_index = 0;
+ for (uint32_t port_index = 0; port_index < parameter_count(); ++port_index) {
+ if (LADSPA_IS_PORT_AUDIO(port_descriptor(port_index))) {
+ if (LADSPA_IS_PORT_INPUT(port_descriptor(port_index))) {
+ const uint32_t buf_index = in_map.get(DataType::AUDIO, audio_in_index++);
+ connect_port(port_index, bufs.get_audio(buf_index).data(offset));
+ } else if (LADSPA_IS_PORT_OUTPUT(port_descriptor(port_index))) {
+ const uint32_t buf_index = out_map.get(DataType::AUDIO, audio_out_index++);
+ connect_port(port_index, bufs.get_audio(buf_index).data(offset));
}
}
- port_index++;
}
-
+
run_in_place (nframes);
now = get_cycles ();
set_cycles ((uint32_t) (now - then));
_control_data[i] = _shadow_data[i];
}
}
+
+ assert (_was_activated);
+
_descriptor->run (_handle, nframes);
}
/* we need to run the plugin so that it can set its latency
parameter.
*/
-
+
activate ();
-
+
uint32_t port_index = 0;
uint32_t in_index = 0;
uint32_t out_index = 0;
LADSPA_Data buffer[bufsize];
memset(buffer,0,sizeof(LADSPA_Data)*bufsize);
-
+
/* Note that we've already required that plugins
be able to handle in-place processing.
*/
-
+
port_index = 0;
-
+
while (port_index < parameter_count()) {
if (LADSPA_IS_PORT_AUDIO (port_descriptor (port_index))) {
if (LADSPA_IS_PORT_INPUT (port_descriptor (port_index))) {
}
port_index++;
}
-
+
run_in_place (bufsize);
deactivate ();
}
if ((module = dlopen (path.c_str(), RTLD_NOW)) == 0) {
error << string_compose(_("LADSPA: cannot load module from \"%1\""), path) << endmsg;
error << dlerror() << endmsg;
+ return PluginPtr ((Plugin*) 0);
} else {
plugin.reset (new LadspaPlugin (module, session.engine(), session, index, session.frame_rate()));
}
catch (failed_constructor &err) {
return PluginPtr ((Plugin*) 0);
- }
+ }
+}
+
+LadspaPluginInfo::LadspaPluginInfo()
+{
+ type = ARDOUR::LADSPA;
}