Ardour  9.0-pre0-582-g084a23a80d
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 #pragma once
21 
22 #include <map>
23 #include <cassert>
24 #include <ostream>
25 #include <utility>
26 
27 #include "pbd/stack_allocator.h"
28 #include "pbd/xml++.h"
29 
30 #include "ardour/data_type.h"
31 #include "ardour/chan_count.h"
32 
33 namespace ARDOUR {
34 
42 public:
46  ChanMapping(const XMLNode& node);
47 
49 
50  uint32_t get(DataType t, uint32_t from, bool* valid) const;
51 
58  uint32_t get_src(DataType type, uint32_t to, bool* valid) const;
59 
65  uint32_t get (DataType type, uint32_t from) const { return get (type, from, NULL); }
66 
72  void set (DataType type, uint32_t from, uint32_t to);
73 
74  void offset_from (DataType t, int32_t delta);
75  void offset_to (DataType t, int32_t delta);
76 
81  void unset(DataType type, uint32_t from);
82 
88 
92  bool is_monotonic () const;
93 
94  uint32_t n_total () const;
95 
96  ChanCount count () const;
97 
98  XMLNode* state(const std::string& name) const;
99 
104  bool is_subset (const ChanMapping& superset) const;
105 
106 #if defined(_MSC_VER) /* && (_MSC_VER < 1900)
107  * Regarding the note (below) it was initially
108  * thought that this got fixed in VS2015 - but
109  * in fact it's still faulty (JE - Feb 2021).
110  * 2024-09-03 update: Faulty compile up to
111  * VS2022 17.4. From there it compiles but does
112  * not link with the exception of the arm64
113  * platform. This quirk is actually a bug that
114  * Microsoft seems to have failed to
115  * acknowledge as such for years judging from
116  * web search results about MSVC's std::map,
117  * and have not even fixed correctly when they
118  * tried.
119  */
120  /* Use the older (heap based) mapping for early versions of MSVC.
121  * In fact it might be safer to use this for all MSVC builds. It
122  * was thought that this was related to issues with
123  * boost::aligned_storage, but actually it seems to be that there
124  * are bugs in the std::map implementation of MSVC that are being
125  * triggered, messing with the copy constructor of
126  * PBD::StackAllocator.
127  */
128  typedef std::map<uint32_t, uint32_t> TypeMapping;
129  typedef std::map<DataType, TypeMapping> Mappings;
130 #else
131  typedef std::map<uint32_t, uint32_t, std::less<uint32_t>, PBD::StackAllocator<std::pair<const uint32_t, uint32_t>, 16> > TypeMapping;
132  typedef std::map<DataType, TypeMapping, std::less<DataType>, PBD::StackAllocator<std::pair<const DataType, TypeMapping>, 2> > Mappings;
133 #endif
134 
135  Mappings mappings() { return _mappings; }
136  const Mappings& mappings() const { return _mappings; }
137 
138  bool operator==(const ChanMapping& other) const {
139  return (_mappings == other._mappings);
140  }
141 
142  bool operator!=(const ChanMapping& other) const {
143  return ! (*this == other);
144  }
145 
146 private:
148 };
149 
150 } // namespace ARDOUR
151 
152 std::ostream& operator<<(std::ostream& o, const ARDOUR::ChanMapping& m);
153 
154 
std::ostream & operator<<(std::ostream &o, const ARDOUR::ChanMapping &m)
uint32_t get(DataType type, uint32_t from) const
Definition: chan_mapping.h:65
ChanMapping(ARDOUR::ChanCount identity)
bool operator!=(const ChanMapping &other) const
Definition: chan_mapping.h:142
ChanMapping operator=(const ChanMapping &)
uint32_t n_total() const
const Mappings & mappings() const
Definition: chan_mapping.h:136
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:132
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:138
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:131
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