force IFS=/ when calling path_expand, so that whitespace in paths doesn't cause worde...
[ardour.git] / libs / ardour / bundle.cc
index 94fada383d1c6f5b35236ea626488cbb106be928..dd4bacdff2b8707c66245208d42dc8d5c01017a6 100644 (file)
@@ -177,6 +177,18 @@ Bundle::add_channel (std::string const & n, DataType t, PortList p)
        emit_changed (ConfigurationChanged);
 }
 
+/** @param n Channel name */
+void
+Bundle::add_channel (std::string const & n, DataType t, std::string const & p)
+{
+       {
+               Glib::Mutex::Lock lm (_channel_mutex);
+               _channel.push_back (Channel (n, t, p));
+       }
+
+       emit_changed (ConfigurationChanged);
+}
+
 bool
 Bundle::port_attached_to_channel (uint32_t ch, std::string portname)
 {
@@ -211,7 +223,7 @@ Bundle::remove_channels ()
  *  @return true if any channel is associated with p.
  */
 bool
-Bundle::uses_port (std::string p) const
+Bundle::offers_port (std::string p) const
 {
        Glib::Mutex::Lock lm (_channel_mutex);
 
@@ -409,8 +421,8 @@ Bundle::connected_to (boost::shared_ptr<Bundle> other, AudioEngine & engine)
                for (uint32_t j = 0; j < A.size(); ++j) {
                        for (uint32_t k = 0; k < B.size(); ++k) {
 
-                               Port* p = engine.get_port_by_name (A[j]);
-                               Port* q = engine.get_port_by_name (B[k]);
+                               boost::shared_ptr<Port> p = engine.get_port_by_name (A[j]);
+                               boost::shared_ptr<Port> q = engine.get_port_by_name (B[k]);
 
                                if (!p && !q) {
                                        return false;
@@ -482,5 +494,96 @@ Bundle::channel_type (uint32_t c) const
 
        Glib::Mutex::Lock lm (_channel_mutex);
        return _channel[c].type;
-}      
+}
+
+ostream &
+operator<< (ostream& os, Bundle const & b)
+{
+       os << "BUNDLE " << b.nchannels() << " channels: ";
+       for (uint32_t i = 0; i < b.nchannels().n_total(); ++i) {
+               os << "( ";
+               Bundle::PortList const & pl = b.channel_ports (i);
+               for (Bundle::PortList::const_iterator j = pl.begin(); j != pl.end(); ++j) {
+                       os << *j << " ";
+               }
+               os << ") ";
+       }
+
+       return os;
+}
+
+bool
+Bundle::operator== (Bundle const & other)
+{
+       return _channel == other._channel;
+}
+
+/** Given an index of a channel as the nth channel of a particular type,
+ *  return an index of that channel when considering channels of all types.
+ *
+ *  e.g. given a bundle with channels:
+ *          fred   [audio]
+ *          jim    [audio]
+ *          sheila [midi]
+ *
+ * If t == MIDI and c == 0, then we would return 2, as 2 is the index of the
+ * 0th MIDI channel.
+ *
+ * If t == NIL, we just return c.
+ */
 
+uint32_t
+Bundle::type_channel_to_overall (DataType t, uint32_t c) const
+{
+       if (t == DataType::NIL) {
+               return c;
+       }
+       
+       Glib::Mutex::Lock lm (_channel_mutex);
+
+       vector<Channel>::const_iterator i = _channel.begin ();
+
+       uint32_t o = 0;
+
+       while (1) {
+
+               assert (i != _channel.end ());
+
+               if (i->type != t) {
+                       ++i;
+               } else {
+                       if (c == 0) {
+                               return o;
+                       }
+                       --c;
+               }
+
+               ++o;
+       }
+
+       /* NOTREACHED */
+       return -1;
+}
+
+/** Perform the reverse of type_channel_to_overall */
+uint32_t
+Bundle::overall_channel_to_type (DataType t, uint32_t c) const
+{
+       if (t == DataType::NIL) {
+               return c;
+       }
+       
+       Glib::Mutex::Lock lm (_channel_mutex);
+
+       uint32_t s = 0;
+       
+       vector<Channel>::const_iterator i = _channel.begin ();
+       for (uint32_t j = 0; j < c; ++j) {
+               if (i->type == t) {
+                       ++s;
+               }
+               ++i;
+       }
+
+       return s;
+}