Ardour  8.12
chan_mapping.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
3  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __ardour_chan_mapping_h__
21 #define __ardour_chan_mapping_h__
22 
23 #include <map>
24 #include <cassert>
25 #include <ostream>
26 #include <utility>
27 
28 #include "pbd/stack_allocator.h"
29 #include "pbd/xml++.h"
30 
31 #include "ardour/data_type.h"
32 #include "ardour/chan_count.h"
33 
34 namespace ARDOUR {
35 
43 public:
47  ChanMapping(const XMLNode& node);
48 
50 
51  uint32_t get(DataType t, uint32_t from, bool* valid) const;
52 
59  uint32_t get_src(DataType type, uint32_t to, bool* valid) const;
60 
66  uint32_t get (DataType type, uint32_t from) const { return get (type, from, NULL); }
67 
73  void set (DataType type, uint32_t from, uint32_t to);
74 
75  void offset_from (DataType t, int32_t delta);
76  void offset_to (DataType t, int32_t delta);
77 
82  void unset(DataType type, uint32_t from);
83 
89 
93  bool is_monotonic () const;
94 
95  uint32_t n_total () const;
96 
97  ChanCount count () const;
98 
99  XMLNode* state(const std::string& name) const;
100 
105  bool is_subset (const ChanMapping& superset) const;
106 
107 #if defined(_MSC_VER) /* && (_MSC_VER < 1900)
108  * Regarding the note (below) it was initially
109  * thought that this got fixed in VS2015 - but
110  * in fact it's still faulty (JE - Feb 2021) */
111  /* Use the older (heap based) mapping for early versions of MSVC.
112  * In fact it might be safer to use this for all MSVC builds - as
113  * our StackAllocator class depends on 'boost::aligned_storage'
114  * which is known to be troublesome with Visual C++ :-
115  * https://www.boost.org/doc/libs/1_65_0/libs/type_traits/doc/html/boost_typetraits/reference/aligned_storage.html
116  */
117  typedef std::map<uint32_t, uint32_t> TypeMapping;
118  typedef std::map<DataType, TypeMapping> Mappings;
119 #else
120  typedef std::map<uint32_t, uint32_t, std::less<uint32_t>, PBD::StackAllocator<std::pair<const uint32_t, uint32_t>, 16> > TypeMapping;
121  typedef std::map<DataType, TypeMapping, std::less<DataType>, PBD::StackAllocator<std::pair<const DataType, TypeMapping>, 2> > Mappings;
122 #endif
123 
124  Mappings mappings() { return _mappings; }
125  const Mappings& mappings() const { return _mappings; }
126 
127  bool operator==(const ChanMapping& other) const {
128  return (_mappings == other._mappings);
129  }
130 
131  bool operator!=(const ChanMapping& other) const {
132  return ! (*this == other);
133  }
134 
135 private:
137 };
138 
139 } // namespace ARDOUR
140 
141 std::ostream& operator<<(std::ostream& o, const ARDOUR::ChanMapping& m);
142 
143 #endif // __ardour_chan_mapping_h__
144 
std::ostream & operator<<(std::ostream &o, const ARDOUR::ChanMapping &m)
uint32_t get(DataType type, uint32_t from) const
Definition: chan_mapping.h:66
ChanMapping(ARDOUR::ChanCount identity)
bool operator!=(const ChanMapping &other) const
Definition: chan_mapping.h:131
ChanMapping operator=(const ChanMapping &)
uint32_t n_total() const
const Mappings & mappings() const
Definition: chan_mapping.h:125
void offset_to(DataType t, int32_t delta)
std::map< DataType, TypeMapping, std::less< DataType >, PBD::StackAllocator< std::pair< const DataType, TypeMapping >, 2 > > Mappings
Definition: chan_mapping.h:121
uint32_t get_src(DataType type, uint32_t to, bool *valid) const
XMLNode * state(const std::string &name) const
ChanMapping(const ChanMapping &)
bool is_subset(const ChanMapping &superset) const
void unset(DataType type, uint32_t from)
bool operator==(const ChanMapping &other) const
Definition: chan_mapping.h:127
void offset_from(DataType t, int32_t delta)
uint32_t get(DataType t, uint32_t from, bool *valid) const
ChanMapping(const XMLNode &node)
bool is_monotonic() const
void set(DataType type, uint32_t from, uint32_t to)
std::map< uint32_t, uint32_t, std::less< uint32_t >, PBD::StackAllocator< std::pair< const uint32_t, uint32_t >, 16 > > TypeMapping
Definition: chan_mapping.h:120
ChanCount count() const
bool is_identity(ARDOUR::ChanCount offset=ARDOUR::ChanCount()) const
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API