reload alpha1-6 Pannable XML state so that panning of existing sessions should work...
[ardour.git] / libs / ardour / plugin_insert.cc
index 48ffb9bf0cb9eedb1a0e8e3a836998c23cb19bfd..fadf588ffead12fcc1775a21ae7061b6671ea4ff 100644 (file)
@@ -37,7 +37,7 @@
 #include "ardour/port.h"
 #include "ardour/route.h"
 
-#ifdef HAVE_SLV2
+#ifdef LV2_SUPPORT
 #include "ardour/lv2_plugin.h"
 #endif
 
@@ -72,7 +72,8 @@ PluginInsert::PluginInsert (Session& s, boost::shared_ptr<Plugin> plug)
        if (plug) {
                plug->set_insert_info (this);
                _plugins.push_back (plug);
-               set_automatable ();
+
+               create_automatable_parameters ();
 
                Glib::Mutex::Lock em (_session.engine().process_lock());
                IO::PortCountChanged (max(input_streams(), output_streams()));
@@ -192,8 +193,10 @@ PluginInsert::is_generator() const
 }
 
 void
-PluginInsert::set_automatable ()
+PluginInsert::create_automatable_parameters ()
 {
+       assert (!_plugins.empty());
+
        set<Evoral::Parameter> a = _plugins.front()->automatable ();
 
        Plugin::ParameterDescriptor desc;
@@ -426,23 +429,23 @@ PluginInsert::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end
                        }
 
                        bufs.count().set_audio (out);
-               
+
                } else {
 
                        /* does this need to be done with MIDI? it appears not */
-                       
+
                        uint32_t in = _plugins[0]->get_info()->n_inputs.n_audio();
                        uint32_t out = _plugins[0]->get_info()->n_outputs.n_audio();
-                       
+
                        if (out > in) {
-                               
+
                                /* not active, but something has make up for any channel count increase */
-                               
+
                                for (uint32_t n = out - in; n < out; ++n) {
                                        memcpy (bufs.get_audio(n).data(), bufs.get_audio(in - 1).data(), sizeof (Sample) * nframes);
                                }
                        }
-                       
+
                        bufs.count().set_audio (out);
                }
        }
@@ -549,7 +552,7 @@ boost::shared_ptr<Plugin>
 PluginInsert::plugin_factory (boost::shared_ptr<Plugin> other)
 {
        boost::shared_ptr<LadspaPlugin> lp;
-#ifdef HAVE_SLV2
+#ifdef LV2_SUPPORT
        boost::shared_ptr<LV2Plugin> lv2p;
 #endif
 #ifdef VST_SUPPORT
@@ -561,7 +564,7 @@ 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
+#ifdef LV2_SUPPORT
        } else if ((lv2p = boost::dynamic_pointer_cast<LV2Plugin> (other)) != 0) {
                return boost::shared_ptr<Plugin> (new LV2Plugin (*lv2p));
 #endif
@@ -876,54 +879,49 @@ PluginInsert::set_state(const XMLNode& node, int version)
                return -1;
        }
 
+       // The name of the PluginInsert comes from the plugin, nothing else
+       _name = plugin->get_info()->name;
+
        uint32_t count = 1;
-       bool need_automatables = true;
 
        if (_plugins.empty()) {
                /* if we are adding the first plugin, we will need to set
                   up automatable controls.
                */
-               need_automatables = true;
+               add_plugin (plugin);
+               create_automatable_parameters ();
+               set_control_ids (node, version);
        }
 
-       Processor::set_state (node, version);
-       plugin->set_insert_info (this);
-
        if ((prop = node.property ("count")) != 0) {
                sscanf (prop->value().c_str(), "%u", &count);
        }
 
-       /* Handle the node list for this Processor (or Insert if an A2 session).
-        * This needs to happen before the add_plugin_with_activation below, as
-        * the plugin set_state calls may themselves call latency_compute_run,
-        * which will leave the plugin deactivated whether it is currently
-        * activated or not.
-        */
+       if (_plugins.size() != count) {
+               for (uint32_t n = 1; n < count; ++n) {
+                       add_plugin (plugin_factory (plugin));
+               }
+       }
+
        for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
 
+               /* find the node with the type-specific node name ("lv2", "ladspa", etc)
+                  and set all plugins to the same state.
+               */
+
                if ((*niter)->name() == plugin->state_node_name()) {
 
                        plugin->set_state (**niter, version);
+
                        for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
                                (*i)->set_state (**niter, version);
                        }
-                       break;
-               }
-       }
-
-       if (_plugins.size() != count) {
-
-               add_plugin_with_activation (plugin);
 
-               for (uint32_t n = 1; n < count; ++n) {
-                       add_plugin_with_activation (plugin_factory (plugin));
+                       break;
                }
        }
 
-       if (need_automatables) {
-               set_automatable ();
-               set_control_ids (node, version);
-       }
+       Processor::set_state (node, version);
 
        if (version < 3000) {
 
@@ -942,8 +940,13 @@ PluginInsert::set_state(const XMLNode& node, int version)
                set_parameter_state_2X (node, version);
        }
 
-       // The name of the PluginInsert comes from the plugin, nothing else
-       _name = plugin->get_info()->name;
+       for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) {
+               if (active()) {
+                       (*i)->activate ();
+               } else {
+                       (*i)->deactivate ();
+               }
+       }
 
        /* catch up on I/O */
 
@@ -1199,6 +1202,14 @@ PluginInsert::add_plugin_with_activation (boost::shared_ptr<Plugin> plugin)
        }
 }
 
+/** Add a plugin to our list */
+void
+PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
+{
+       plugin->set_insert_info (this);
+       _plugins.push_back (plugin);
+}
+
 void
 PluginInsert::realtime_handle_transport_stopped ()
 {