refine self-automating plugin interface
[ardour.git] / libs / ardour / ardour / chan_mapping.h
index 730ecadc7258443dde1e157d67f8222f6bc0d6f0..ac546e3bbd6000b180ec22db4a20b1c600d307bb 100644 (file)
 #include <ostream>
 #include <utility>
 
+#include "pbd/xml++.h"
 #include "ardour/data_type.h"
 #include "ardour/chan_count.h"
 
 namespace ARDOUR {
 
 
-/** A mapping from one set of channels to another
- * (e.g. how to 'connect' two BufferSets).
+/** A mapping from one set of channels to another.
+ * The general form is  1 source (from), many sinks (to).
+ * numeric IDs are used to identify sources and sinks.
  *
- * for plugins the form is  "pin" -> "buffer"
+ * for plugins this is used to map "plugin-pin" to "audio-buffer"
  */
 class LIBARDOUR_API ChanMapping {
 public:
        ChanMapping() {}
        ChanMapping(ARDOUR::ChanCount identity);
        ChanMapping(const ChanMapping&);
+       ChanMapping(const XMLNode& node);
 
        uint32_t get(DataType t, uint32_t from, bool* valid) const;
 
+       /** reverse lookup
+        * @param type data type
+        * @param to pin
+        * @param valid pointer to a boolean. If not NULL it is set to true if the mapping is found, and false otherwise.
+        * @returns first "from" that matches given "to"
+        */
+       uint32_t get_src(DataType t, uint32_t to, bool* valid) const;
+
        /** get buffer mapping for given data type and pin
         * @param type data type
-        * @param from pin
+        * @param from numeric source id
         * @returns mapped buffer number (or ChanMapping::Invalid)
         */
-       uint32_t get(DataType t, uint32_t from) const { return get (t, from, NULL); }
+       uint32_t get (DataType t, uint32_t from) const { return get (t, from, NULL); }
+
        /** set buffer mapping for given data type
         * @param type data type
-        * @param from pin
+        * @param from numeric source id
         * @param to buffer
         */
        void     set(DataType t, uint32_t from, uint32_t to);
@@ -61,7 +73,7 @@ public:
 
        /** remove mapping
         * @param type data type
-        * @param from source to remove from mapping
+        * @param from numeric source to remove from mapping
         */
        void     unset(DataType t, uint32_t from);
 
@@ -76,6 +88,11 @@ public:
         */
        bool     is_monotonic () const;
 
+       uint32_t n_total () const;
+
+       ChanCount count () const;
+
+       XMLNode* state(const std::string& name) const;
 
        /** Test if this mapping is a subset
         * @param superset to test against
@@ -97,20 +114,6 @@ public:
                return ! (*this == other);
        }
 
-       ChanMapping operator+=(const ChanMapping& other) {
-               const ChanMapping::Mappings& mp (other.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) {
-#if 0
-                               bool valid; uint32_t x = get (tm->first, i->first, &valid);
-                               assert (!valid || x == i->second);
-#endif
-                               set (tm->first, i->first, i->second);
-                       }
-               }
-               return *this;
-       }
-
 private:
        Mappings _mappings;
 };