Merge with trunk R2978.
[ardour.git] / libs / ardour / plugin_insert.cc
index 81c615aa11b3f9e65c815d5b0387647608f76e8a..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 */
@@ -80,7 +84,7 @@ PluginInsert::PluginInsert (Session& s, const XMLNode& node)
 
        {
                Glib::Mutex::Lock em (_session.engine().process_lock());
-               IO::MoreChannels (max(input_streams(), output_streams()));
+               IO::PortCountChanged (max(input_streams(), output_streams()));
        }
 }
 
@@ -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,17 +617,10 @@ 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());
 
@@ -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"