diff options
author | David Robillard <d@drobilla.net> | 2009-05-04 15:50:51 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-05-04 15:50:51 +0000 |
commit | ca10cc82a4374a5b413c06ead6cc89c53f8881ee (patch) | |
tree | 3d44716ed02d80bd1256609631c77a730d04e169 /libs/ardour/ardour/chan_mapping.h | |
parent | 9b06b1da0cec57a6848cf1f7920691ae022b30e7 (diff) |
Preliminary MIDI plugin support.
git-svn-id: svn://localhost/ardour2/branches/3.0@5036 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/chan_mapping.h')
-rw-r--r-- | libs/ardour/ardour/chan_mapping.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/libs/ardour/ardour/chan_mapping.h b/libs/ardour/ardour/chan_mapping.h new file mode 100644 index 0000000000..1dae20e34a --- /dev/null +++ b/libs/ardour/ardour/chan_mapping.h @@ -0,0 +1,82 @@ +/* + Copyright (C) 2009 Paul Davis + Author: Dave Robillard + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef __ardour_chan_mapping_h__ +#define __ardour_chan_mapping_h__ + +#include <map> +#include <cassert> +#include <ostream> +#include <utility> + +#include "ardour/data_type.h" + +namespace ARDOUR { + + +/** A mapping from one set of channels to another + * (e.g. how to 'connect' two BufferSets). + */ +class ChanMapping { +public: + ChanMapping() {} + ChanMapping(ChanCount identity) { + for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) { + for (size_t i = 0; i <= identity.get(*t); ++i) + set(*t, i, i); + } + } + + uint32_t get(DataType t, uint32_t from) { + Mappings::iterator tm = _mappings.find(t); + assert(tm != _mappings.end()); + TypeMapping::iterator m = tm->second.find(from); + assert(m != tm->second.end()); + return m->second; + } + + void set(DataType t, uint32_t from, uint32_t to) { + Mappings::iterator tm = _mappings.find(t); + if (tm == _mappings.end()) { + tm = _mappings.insert(std::make_pair(t, TypeMapping())).first; + } + tm->second.insert(std::make_pair(from, to)); + } + + /** Increase the 'to' field of every mapping for type @a t by @a delta */ + void offset(DataType t, uint32_t delta) { + Mappings::iterator tm = _mappings.find(t); + if (tm != _mappings.end()) { + for (TypeMapping::iterator m = tm->second.begin(); m != tm->second.end(); ++m) { + m->second += delta; + } + } + } + +private: + typedef std::map<uint32_t, uint32_t> TypeMapping; + typedef std::map<DataType, TypeMapping> Mappings; + + Mappings _mappings; +}; + +} // namespace ARDOUR + +#endif // __ardour_chan_mapping_h__ + |