X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fbundle.cc;h=dd4bacdff2b8707c66245208d42dc8d5c01017a6;hb=80ec3fb37e0156cf02a25e9b353879819b66057d;hp=1948024d91f7b1bc0100382529844eafaea653a7;hpb=7bdcc127e3e42bd76b997b56ecd938b1127d790b;p=ardour.git diff --git a/libs/ardour/bundle.cc b/libs/ardour/bundle.cc index 1948024d91..dd4bacdff2 100644 --- a/libs/ardour/bundle.cc +++ b/libs/ardour/bundle.cc @@ -511,3 +511,79 @@ operator<< (ostream& os, Bundle const & b) 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::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::const_iterator i = _channel.begin (); + for (uint32_t j = 0; j < c; ++j) { + if (i->type == t) { + ++s; + } + ++i; + } + + return s; +}