2 Copyright (C) 2006 Paul Davis
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_chan_count_h__
21 #define __ardour_chan_count_h__
26 #include "pbd/xml++.h"
27 #include "ardour/data_type.h"
32 /** A count of channels, possibly with many types.
34 * Operators are defined so this may safely be used as if it were a simple
35 * (single-typed) integer count of channels.
39 ChanCount(const XMLNode& node);
40 ChanCount() { reset(); }
42 // Convenience constructor for making single-typed streams (stereo, mono, etc)
43 ChanCount(DataType type, uint32_t channels) {
49 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
54 void set(DataType t, uint32_t count) { assert(t != DataType::NIL); _counts[t] = count; }
55 uint32_t get(DataType t) const { assert(t != DataType::NIL); return _counts[t]; }
57 inline uint32_t n_audio() const { return _counts[DataType::AUDIO]; }
58 inline void set_audio(uint32_t a) { _counts[DataType::AUDIO] = a; }
60 inline uint32_t n_midi() const { return _counts[DataType::MIDI]; }
61 inline void set_midi(uint32_t m) { _counts[DataType::MIDI] = m; }
63 uint32_t n_total() const {
65 for (uint32_t i=0; i < DataType::num_types; ++i)
71 bool operator==(const ChanCount& other) const {
72 for (uint32_t i=0; i < DataType::num_types; ++i)
73 if (_counts[i] != other._counts[i])
79 bool operator!=(const ChanCount& other) const {
80 return ! (*this == other);
83 bool operator<(const ChanCount& other) const {
84 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
85 if (_counts[*t] > other._counts[*t]) {
89 return (*this != other);
92 bool operator<=(const ChanCount& other) const {
93 return ( (*this < other) || (*this == other) );
96 bool operator>(const ChanCount& other) const {
97 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
98 if (_counts[*t] < other._counts[*t]) {
102 return (*this != other);
105 bool operator>=(const ChanCount& other) const {
106 return ( (*this > other) || (*this == other) );
109 ChanCount operator+(const ChanCount& other) const {
111 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
112 ret.set(*t, get(*t) + other.get(*t));
117 static ChanCount min(const ChanCount& a, const ChanCount& b) {
119 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
120 ret.set(*t, std::min(a.get(*t), b.get(*t)));
125 static ChanCount max(const ChanCount& a, const ChanCount& b) {
127 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
128 ret.set(*t, std::max(a.get(*t), b.get(*t)));
133 XMLNode* state(const std::string& name) const;
135 static const ChanCount INFINITE;
136 static const ChanCount ZERO;
139 uint32_t _counts[DataType::num_types];
142 } // namespace ARDOUR
144 std::ostream& operator<<(std::ostream& o, const ARDOUR::ChanCount& c);
146 #endif // __ardour_chan_count_h__