Merge with trunk R2978.
[ardour.git] / libs / ardour / plugin_insert.cc
index f6ec9f9ba0b843b5b22bb4299dee45a3b671df46..26d344dee4331c4d993a475fdb01ee4a13f7bcf0 100644 (file)
 #include <ardour/buffer_set.h>
 #include <ardour/automation_event.h>
 
+#ifdef HAVE_SLV2
+#include <ardour/lv2_plugin.h>
+#endif
+
 #ifdef VST_SUPPORT
 #include <ardour/vst_plugin.h>
 #endif
@@ -63,7 +67,7 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug, Placemen
 
        {
                Glib::Mutex::Lock em (_session.engine().process_lock());
-               IO::MoreChannels (max(input_streams(), output_streams()));
+               IO::PortCountChanged (max(input_streams(), output_streams()));
        }
 
        ProcessorCreated (this); /* EMIT SIGNAL */
@@ -76,11 +80,11 @@ PluginInsert::PluginInsert (Session& s, const XMLNode& node)
                throw failed_constructor();
        }
 
-       set_automatable ();
+       // set_automatable ();
 
        {
                Glib::Mutex::Lock em (_session.engine().process_lock());
-               IO::MoreChannels (max(input_streams(), output_streams()));
+               IO::PortCountChanged (max(input_streams(), output_streams()));
        }
 }
 
@@ -143,7 +147,7 @@ PluginInsert::~PluginInsert ()
 }
 
 void
-PluginInsert::auto_state_changed (ParamID which)
+PluginInsert::auto_state_changed (Parameter which)
 {
        if (which.type() != PluginAutomation)
                return;
@@ -198,11 +202,11 @@ PluginInsert::is_generator() const
 void
 PluginInsert::set_automatable ()
 {
-       set<ParamID> a = _plugins.front()->automatable ();
+       set<Parameter> a = _plugins.front()->automatable ();
 
        Plugin::ParameterDescriptor desc;
 
-       for (set<ParamID>::iterator i = a.begin(); i != a.end(); ++i) {
+       for (set<Parameter>::iterator i = a.begin(); i != a.end(); ++i) {
                if (i->type() == PluginAutomation) {
                        can_automate (*i);
                        _plugins.front()->get_parameter_descriptor(i->id(), desc);
@@ -220,7 +224,7 @@ PluginInsert::set_automatable ()
 }
 
 void
-PluginInsert::parameter_changed (ParamID which, float val)
+PluginInsert::parameter_changed (Parameter which, float val)
 {
        if (which.type() != PluginAutomation)
                return;
@@ -279,7 +283,7 @@ PluginInsert::connect_and_run (BufferSet& bufs, nframes_t nframes, nframes_t off
                        
                        boost::shared_ptr<AutomationControl> c = li->second;
 
-                       if (c->list()->param_id().type() == PluginAutomation && c->list()->automation_playback()) {
+                       if (c->parameter().type() == PluginAutomation && c->list()->automation_playback()) {
                                bool valid;
 
                                const float val = c->list()->rt_safe_eval (now, valid);                         
@@ -313,7 +317,7 @@ PluginInsert::silence (nframes_t nframes, nframes_t offset)
 }
        
 void
-PluginInsert::run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
+PluginInsert::run_in_place (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes, nframes_t offset)
 {
        if (active()) {
 
@@ -343,7 +347,7 @@ PluginInsert::run (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame,
 }
 
 void
-PluginInsert::set_parameter (ParamID param, float val)
+PluginInsert::set_parameter (Parameter param, float val)
 {
        if (param.type() != PluginAutomation)
                return;
@@ -361,7 +365,7 @@ PluginInsert::set_parameter (ParamID param, float val)
 }
 
 float
-PluginInsert::get_parameter (ParamID param)
+PluginInsert::get_parameter (Parameter param)
 {
        if (param.type() != PluginAutomation)
                return 0.0;
@@ -415,7 +419,7 @@ PluginInsert::automation_run (BufferSet& bufs, nframes_t nframes, nframes_t offs
 }      
 
 float
-PluginInsert::default_parameter_value (ParamID param)
+PluginInsert::default_parameter_value (Parameter param)
 {
        if (param.type() != PluginAutomation)
                return 1.0;
@@ -433,6 +437,9 @@ boost::shared_ptr<Plugin>
 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
 {
        boost::shared_ptr<LadspaPlugin> lp;
+#ifdef HAVE_SLV2
+       boost::shared_ptr<LV2Plugin> lv2p;
+#endif
 #ifdef VST_SUPPORT
        boost::shared_ptr<VSTPlugin> vp;
 #endif
@@ -442,6 +449,10 @@ PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
 
        if ((lp = boost::dynamic_pointer_cast<LadspaPlugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new LadspaPlugin (*lp));
+#ifdef HAVE_SLV2
+       } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
+               return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
+#endif
 #ifdef VST_SUPPORT
        } else if ((vp = boost::dynamic_pointer_cast<VSTPlugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new VSTPlugin (*vp));
@@ -606,25 +617,18 @@ PluginInsert::get_state(void)
 XMLNode&
 PluginInsert::state (bool full)
 {
-       char buf[256];
        XMLNode& node = Processor::state (full);
 
        node.add_property ("type", _plugins[0]->state_node_name());
-       snprintf(buf, sizeof(buf), "%s", _plugins[0]->name());
-       node.add_property("id", string(buf));
-       if (_plugins[0]->state_node_name() == "ladspa") {
-               char buf[32];
-               snprintf (buf, sizeof (buf), "%ld", _plugins[0]->get_info()->unique_id); 
-               node.add_property("unique-id", string(buf));
-       }
+       node.add_property("unique-id", _plugins[0]->unique_id());
        node.add_property("count", string_compose("%1", _plugins.size()));
        node.add_child_nocopy (_plugins[0]->get_state());
 
        /* add port automation state */
        XMLNode *autonode = new XMLNode(port_automation_node_name);
-       set<ParamID> automatable = _plugins[0]->automatable();
+       set<Parameter> automatable = _plugins[0]->automatable();
        
-       for (set<ParamID>::iterator x = automatable.begin(); x != automatable.end(); ++x) {
+       for (set<Parameter>::iterator x = automatable.begin(); x != automatable.end(); ++x) {
                
                /*XMLNode* child = new XMLNode("port");
                snprintf(buf, sizeof(buf), "%" PRIu32, *x);
@@ -648,7 +652,6 @@ PluginInsert::set_state(const XMLNode& node)
        XMLNodeIterator niter;
        XMLPropertyList plist;
        const XMLProperty *prop;
-       long unique = 0;
        ARDOUR::PluginType type;
 
        if ((prop = node.property ("type")) == 0) {
@@ -658,6 +661,8 @@ PluginInsert::set_state(const XMLNode& node)
 
        if (prop->value() == X_("ladspa") || prop->value() == X_("Ladspa")) { /* handle old school sessions */
                type = ARDOUR::LADSPA;
+       } else if (prop->value() == X_("lv2")) {
+               type = ARDOUR::LV2;
        } else if (prop->value() == X_("vst")) {
                type = ARDOUR::VST;
        } else {
@@ -666,24 +671,16 @@ PluginInsert::set_state(const XMLNode& node)
                      << endmsg;
                return -1;
        }
-
+       
        prop = node.property ("unique-id");
-       if (prop != 0) {
-               unique = atol(prop->value().c_str());
-       }
-
-       if ((prop = node.property ("id")) == 0) {
-               error << _("XML node describing insert is missing the `id' field") << endmsg;
-               return -1;
+       if (prop == 0) {
+               error << _("Plugin has no unique ID field") << endmsg;
+               return -1;
        }
 
        boost::shared_ptr<Plugin> plugin;
        
-       if (unique != 0) {
-               plugin = find_plugin (_session, "", unique, type);      
-       } else {
-               plugin = find_plugin (_session, prop->value(), 0, type);        
-       }
+       plugin = find_plugin (_session, prop->value(), type);   
 
        if (plugin == 0) {
                error << string_compose(_("Found a reference to a plugin (\"%1\") that is unknown.\n"
@@ -764,7 +761,7 @@ PluginInsert::set_state(const XMLNode& node)
                        }
 
                        if (!child->children().empty()) {
-                               control (ParamID(PluginAutomation, port_id), true)->list()->set_state (*child->children().front());
+                               control (Parameter(PluginAutomation, port_id), true)->list()->set_state (*child->children().front());
                        } else {
                                if ((cprop = child->property("auto")) != 0) {
                                        
@@ -772,13 +769,13 @@ PluginInsert::set_state(const XMLNode& node)
 
                                        int x;
                                        sscanf (cprop->value().c_str(), "0x%x", &x);
-                                       control (ParamID(PluginAutomation, port_id), true)->list()->set_automation_state (AutoState (x));
+                                       control (Parameter(PluginAutomation, port_id), true)->list()->set_automation_state (AutoState (x));
 
                                } else {
                                        
                                        /* missing */
                                        
-                                       control (ParamID(PluginAutomation, port_id), true)->list()->set_automation_state (Off);
+                                       control (Parameter(PluginAutomation, port_id), true)->list()->set_automation_state (Off);
                                }
                        }
 
@@ -800,7 +797,7 @@ PluginInsert::set_state(const XMLNode& node)
 }
 
 string
-PluginInsert::describe_parameter (ParamID param)
+PluginInsert::describe_parameter (Parameter param)
 {
        if (param.type() != PluginAutomation)
                return Automatable::describe_parameter(param);
@@ -848,12 +845,12 @@ PluginInsert::type ()
 }
 
 PluginInsert::PluginControl::PluginControl (PluginInsert& p, boost::shared_ptr<AutomationList> list)
-       : AutomationControl (p.session(), list, p.describe_parameter(list->param_id()))
+       : AutomationControl (p.session(), list, p.describe_parameter(list->parameter()))
        , _plugin (p)
        , _list (list)
 {
        Plugin::ParameterDescriptor desc;
-       p.plugin(0)->get_parameter_descriptor (list->param_id().id(), desc);
+       p.plugin(0)->get_parameter_descriptor (list->parameter().id(), desc);
        _logarithmic = desc.logarithmic;
        _toggled = desc.toggled;
 }
@@ -889,7 +886,7 @@ PluginInsert::PluginControl::set_value (float val)
 
        for (vector<boost::shared_ptr<Plugin> >::iterator i = _plugin._plugins.begin();
                        i != _plugin._plugins.end(); ++i) {
-               (*i)->set_parameter (_list->param_id().id(), val);
+               (*i)->set_parameter (_list->parameter().id(), val);
        }
 
        AutomationControl::set_value(val);
@@ -900,7 +897,7 @@ PluginInsert::PluginControl::get_value (void) const
 {
        /* FIXME: probably should be taking out some lock here.. */
        
-       float val = _plugin.get_parameter (_list->param_id());
+       float val = _plugin.get_parameter (_list->parameter());
 
        return val;