fix thinko when dealing with non-MIDI tracks
[ardour.git] / libs / ardour / chan_count.cc
1 /*
2  * Copyright (C) 2006-2009 David Robillard <d@drobilla.net>
3  * Copyright (C) 2008-2016 Paul Davis <paul@linuxaudiosystems.com>
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 #include <stdint.h>
21 #include "ardour/chan_count.h"
22 #include "ardour/types_convert.h"
23
24 #include "pbd/i18n.h"
25
26 static const char* state_node_name = "Channels";
27
28 using namespace std;
29
30 namespace ARDOUR {
31
32 // infinite/zero chan count stuff, for setting minimums and maximums, etc.
33 // FIXME: implement this in a less fugly way
34
35 ChanCount::ChanCount(const XMLNode& node)
36 {
37         reset();
38         XMLNodeConstIterator iter = node.children().begin();
39         for ( ; iter != node.children().end(); ++iter) {
40                 if ((*iter)->name() == X_(state_node_name)) {
41                         DataType type (DataType::NIL);
42                         uint32_t count;
43                         if ((*iter)->get_property ("type", type) && (*iter)->get_property ("count", count)) {
44                                 set(type, count);
45                         }
46                 }
47         }
48 }
49
50 XMLNode*
51 ChanCount::state(const std::string& name) const
52 {
53         XMLNode* node = new XMLNode (name);
54         for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
55                 uint32_t count = get(*t);
56                 if (count > 0) {
57                         XMLNode* n = new XMLNode(X_(state_node_name));
58                         n->set_property("type", *t);
59                         n->set_property("count", count);
60                         node->add_child_nocopy(*n);
61                 }
62         }
63         return node;
64 }
65
66 // Statics
67 const ChanCount ChanCount::ZERO     = ChanCount();
68
69 } // namespace ARDOUR
70
71 std::ostream& operator<<(std::ostream& o, const ARDOUR::ChanCount& c) {
72         return o << "AUDIO=" << c.n_audio() << ":MIDI=" << c.n_midi();
73 }