Optimize automation-event process splitting
[ardour.git] / libs / ardour / chan_mapping.cc
index 9e69294fdbad233d926ec6c86b9579319a291884..1840af0d25a1aabfd96092bc093cfc3a3e2c70aa 100644 (file)
 
 #include <stdint.h>
 #include <iostream>
+#include "ardour/types_convert.h"
 #include "ardour/chan_mapping.h"
 
+#include "pbd/i18n.h"
+
+static const char* state_node_name = "Channelmap";
+
 using namespace std;
 
 namespace ARDOUR {
 
 ChanMapping::ChanMapping(ChanCount identity)
 {
-       if (identity == ChanCount::INFINITE) {
-               return;
-       }
-
        for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
                for (size_t i = 0; i < identity.get(*t); ++i) {
                        set(*t, i, i);
@@ -40,7 +41,7 @@ ChanMapping::ChanMapping(ChanCount identity)
        }
 }
 
-ChanMapping::ChanMapping (const ChanMapping& other )
+ChanMapping::ChanMapping (const ChanMapping& other)
 {
        const ChanMapping::Mappings& mp (other.mappings());
        for (Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
@@ -50,6 +51,22 @@ ChanMapping::ChanMapping (const ChanMapping& other )
        }
 }
 
+ChanMapping::ChanMapping (const XMLNode& node)
+{
+       XMLNodeConstIterator iter = node.children().begin();
+       for ( ; iter != node.children().end(); ++iter) {
+               if ((*iter)->name() == X_(state_node_name)) {
+                       DataType type(DataType::NIL);
+                       uint32_t from;
+                       uint32_t to;
+                       (*iter)->get_property("type", type);
+                       (*iter)->get_property("from", from);
+                       (*iter)->get_property("to", to);
+                       set(type, from, to);
+               }
+       }
+}
+
 uint32_t
 ChanMapping::get(DataType t, uint32_t from, bool* valid) const
 {
@@ -135,6 +152,23 @@ ChanMapping::offset_to(DataType t, int32_t delta)
        }
 }
 
+XMLNode*
+ChanMapping::state(const std::string& name) const
+{
+       XMLNode* node = new XMLNode (name);
+       const Mappings& mp (mappings());
+       for (Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
+               for (TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) {
+                       XMLNode* n = new XMLNode(X_(state_node_name));
+                       n->set_property("type", tm->first.to_string());
+                       n->set_property("from", i->first);
+                       n->set_property("to", i->second);
+                       node->add_child_nocopy(*n);
+               }
+       }
+       return node;
+}
+
 bool
 ChanMapping::is_subset (const ChanMapping& superset) const
 {
@@ -185,8 +219,9 @@ ChanMapping::is_identity (ChanCount offset) const
 }
 
 uint32_t
-ChanMapping::count () const
+ChanMapping::n_total () const
 {
+       // fast version of count().n_total();
        uint32_t rv = 0;
        const Mappings& mp (mappings());
        for (Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
@@ -195,6 +230,19 @@ ChanMapping::count () const
        return rv;
 }
 
+ChanCount
+ChanMapping::count () const
+{
+       ChanCount rv;
+       const Mappings& mp (mappings());
+       for (Mappings::const_iterator tm = mp.begin(); tm != mp.end(); ++tm) {
+               rv.set (tm->first, tm->second.size ());
+       }
+       return rv;
+}
+
+
+
 } // namespace ARDOUR
 
 std::ostream& operator<<(std::ostream& o, const ARDOUR::ChanMapping& cm)