Create sidechain ports when created from template (#0007680)
authorJohannes Mueller <github@johannes-mueller.org>
Thu, 1 Nov 2018 19:30:06 +0000 (20:30 +0100)
committerJohannes Mueller <github@johannes-mueller.org>
Thu, 1 Nov 2018 21:17:01 +0000 (22:17 +0100)
When a route with a sidechain is created from a template or by route
duplication the number of ports of the sidechain are set according to the
XMLNode defining the sidechain. Then the names are set according to the name of
the newly created route.

Thus all the pin connections defined in the template are replicated in the
newly created route.

libs/ardour/ardour/plugin_insert.h
libs/ardour/ardour/sidechain.h
libs/ardour/plugin_insert.cc

index a68110177fa2f50aaafb7efe9ecf95397400fd20..0a56373972ce0c378fb2a0392cc41d2097d6ca09 100644 (file)
@@ -388,6 +388,8 @@ private:
        boost::shared_ptr<Plugin> plugin_factory (boost::shared_ptr<Plugin>);
        void add_plugin (boost::shared_ptr<Plugin>);
 
+       void add_sidechain_from_xml (const XMLNode& node, int version);
+
        void start_touch (uint32_t param_id);
        void end_touch (uint32_t param_id);
 
index dd608c8951942d72cbe5c7f23bdc5998162b3c9e..16773609905c21b590d47dd3ad74b938926f71c4 100644 (file)
@@ -39,7 +39,7 @@ public:
        bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
        bool configure_io (ChanCount in, ChanCount out);
 
-       int  set_state(const XMLNode&, int version);
+       int set_state(const XMLNode&, int version);
 
 protected:
        XMLNode& state ();
index 4fc97fb0c816ab0bcafaa9d7de0b82cead81b708..983d3b9aa8ae3c411640881504c8c8ff9c16c90e 100644 (file)
@@ -2763,10 +2763,16 @@ PluginInsert::set_state(const XMLNode& node, int version)
                // sidechain is a Processor (IO)
                if ((*i)->name () ==  Processor::state_node_name) {
                        if (!_sidechain) {
-                               add_sidechain (0);
+                               if (regenerate_xml_or_string_ids ()) {
+                                       add_sidechain_from_xml (**i, version);
+                               } else {
+                                       add_sidechain (0);
+                               }
                        }
                        if (!regenerate_xml_or_string_ids ()) {
                                _sidechain->set_state (**i, version);
+                       } else {
+                               update_sidechain_name ();
                        }
                }
        }
@@ -3096,6 +3102,42 @@ PluginInsert::add_plugin (boost::shared_ptr<Plugin> plugin)
        _plugins.push_back (plugin);
 }
 
+void
+PluginInsert::add_sidechain_from_xml (const XMLNode& node, int version)
+{
+       if (version < 3000) {
+               return;
+       }
+
+       XMLNodeList nlist = node.children();
+
+       if (nlist.size() == 0) {
+               return;
+       }
+
+       uint32_t audio = 0;
+       uint32_t midi = 0;
+
+       XMLNodeConstIterator it = nlist.front()->children().begin();
+       for ( ; it != nlist.front()->children().end(); ++ it) {
+               if ((*it)->name() == "Port") {
+                       DataType type(DataType::NIL);
+                       (*it)->get_property ("type", type);
+                       if (type == DataType::AUDIO) {
+                               ++audio;
+                       } else if (type == DataType::MIDI) {
+                               ++midi;
+                       }
+               }
+       }
+
+       ChanCount in_cc = ChanCount();
+       in_cc.set (DataType::AUDIO, audio);
+       in_cc.set (DataType::MIDI, midi);
+
+       add_sidechain (audio, midi);
+}
+
 bool
 PluginInsert::load_preset (ARDOUR::Plugin::PresetRecord pr)
 {