diff options
author | Robin Gareus <robin@gareus.org> | 2016-03-29 19:12:29 +0200 |
---|---|---|
committer | Robin Gareus <robin@gareus.org> | 2016-03-29 19:49:37 +0200 |
commit | e0dbb95b721efee5457a8456aa2838df1ecbe199 (patch) | |
tree | 36dd94ce11dc05203b00c37cb3bdba9942c31ffb /libs/ardour/chan_mapping.cc | |
parent | 234b06a18cf3e8c07bc44fb4f8c1218e17fb65f1 (diff) |
extend channel-map
add tests for identity matrix, monotonic, subset,
which are handy to verify if inplace processing is possible.
add `unset()` for upcoming GUI work.
Diffstat (limited to 'libs/ardour/chan_mapping.cc')
-rw-r--r-- | libs/ardour/chan_mapping.cc | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/libs/ardour/chan_mapping.cc b/libs/ardour/chan_mapping.cc index 83ded4141c..bc6c4051fc 100644 --- a/libs/ardour/chan_mapping.cc +++ b/libs/ardour/chan_mapping.cc @@ -46,14 +46,14 @@ ChanMapping::ChanMapping (const ChanMapping& other ) } uint32_t -ChanMapping::get(DataType t, uint32_t from, bool* valid) +ChanMapping::get(DataType t, uint32_t from, bool* valid) const { - Mappings::iterator tm = _mappings.find(t); + Mappings::const_iterator tm = _mappings.find(t); if (tm == _mappings.end()) { if (valid) { *valid = false; } return -1; } - TypeMapping::iterator m = tm->second.find(from); + TypeMapping::const_iterator m = tm->second.find(from); if (m == tm->second.end()) { if (valid) { *valid = false; } return -1; @@ -73,6 +73,17 @@ ChanMapping::set(DataType t, uint32_t from, uint32_t to) tm->second.insert(std::make_pair(from, to)); } +void +ChanMapping::unset(DataType t, uint32_t from) +{ + assert(t != DataType::NIL); + Mappings::iterator tm = _mappings.find(t); + if (tm == _mappings.end()) { + return; + } + tm->second.erase(from); +} + /** Offset the 'from' field of every mapping for type @a t by @a delta */ void ChanMapping::offset_from(DataType t, int32_t delta) @@ -99,6 +110,52 @@ ChanMapping::offset_to(DataType t, int32_t delta) } } +bool +ChanMapping::is_subset (const ChanMapping& superset) const +{ + for (ARDOUR::ChanMapping::Mappings::const_iterator tm = mappings().begin(); tm != mappings().end(); ++tm) { + for (ARDOUR::ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) { + bool valid; + if (i->second != superset.get (tm->first, i->first, &valid)) { + return false; + } + if (!valid) { + return false; + } + } + } + return true; +} + +bool +ChanMapping::is_monotonic () const +{ + for (ARDOUR::ChanMapping::Mappings::const_iterator tm = mappings().begin(); tm != mappings().end(); ++tm) { + uint32_t prev = UINT32_MAX; + for (ARDOUR::ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) { + // set keys are strictly weak ordered + if (i->first < i->second || i->second == prev) { + return false; + } + prev = i->second; + } + } + return true; +} + +bool +ChanMapping::is_identity (ChanCount offset) const +{ + for (ARDOUR::ChanMapping::Mappings::const_iterator tm = mappings().begin(); tm != mappings().end(); ++tm) { + for (ARDOUR::ChanMapping::TypeMapping::const_iterator i = tm->second.begin(); i != tm->second.end(); ++i) { + if (i->first + offset.get (tm->first) != i->second) { + return false; + } + } + } + return true; +} + } // namespace ARDOUR std::ostream& operator<<(std::ostream& o, const ARDOUR::ChanMapping& cm) |