2 Copyright (C) 2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2 of the License, or (at your option)
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 675 Mass Ave, Cambridge, MA 02139, USA.
19 #ifndef __ardour_port_set_h__
20 #define __ardour_port_set_h__
23 #include <ardour/port.h>
24 #include <ardour/audio_port.h>
25 #include <ardour/midi_port.h>
26 #include <ardour/chan_count.h>
31 /** An ordered list of Ports, possibly of various types.
33 * This allows access to all the ports as a list, ignoring type, or accessing
34 * the nth port of a given type. Note that port(n) and nth_audio_port(n) may
35 * NOT return the same port.
41 size_t num_ports() const;
42 size_t num_ports(DataType type) const { return _ports[type.to_index()].size(); }
44 void add_port(Port* port);
46 Port* port(size_t index) const;
48 Port* nth_port_of_type(DataType type, size_t n) const;
50 AudioPort* nth_audio_port(size_t n) const;
52 MidiPort* nth_midi_port(size_t n) const;
54 bool contains(const Port* port) const;
56 /** Remove all ports from the PortSet. Ports are not deregistered with
57 * the engine, it's the caller's responsibility to not leak here!
59 void clear() { _ports.clear(); }
61 const ChanCount& chan_count() const { return _chan_count; }
63 bool empty() const { return (_chan_count.get_total() == 0); }
67 // obviously these iterators will need to get more clever
68 // experimental phase, it's the interface that counts right now
73 Port* operator*() { return _list.port(_index); }
74 iterator& operator++() { ++_index; return *this; } // yes, prefix only
75 bool operator==(const iterator& other) { return (_index == other._index); }
76 bool operator!=(const iterator& other) { return (_index != other._index); }
81 iterator(PortSet& list, size_t index) : _list(list), _index(index) {}
87 iterator begin() { return iterator(*this, 0); }
88 iterator end() { return iterator(*this, _chan_count.get_total()); }
90 class const_iterator {
93 const Port* operator*() { return _list.port(_index); }
94 const_iterator& operator++() { ++_index; return *this; } // yes, prefix only
95 bool operator==(const const_iterator& other) { return (_index == other._index); }
96 bool operator!=(const const_iterator& other) { return (_index != other._index); }
101 const_iterator(const PortSet& list, size_t index) : _list(list), _index(index) {}
103 const PortSet& _list;
107 const_iterator begin() const { return const_iterator(*this, 0); }
108 const_iterator end() const { return const_iterator(*this, _chan_count.get_total()); }
112 class audio_iterator {
115 AudioPort* operator*() { return _list.nth_audio_port(_index); }
116 audio_iterator& operator++() { ++_index; return *this; } // yes, prefix only
117 bool operator==(const audio_iterator& other) { return (_index == other._index); }
118 bool operator!=(const audio_iterator& other) { return (_index != other._index); }
121 friend class PortSet;
123 audio_iterator(PortSet& list, size_t index) : _list(list), _index(index) {}
129 audio_iterator audio_begin() { return audio_iterator(*this, 0); }
130 audio_iterator audio_end() { return audio_iterator(*this, _chan_count.get(DataType::AUDIO)); }
136 // Prevent copies (undefined)
137 PortSet(const PortSet& copy);
138 void operator=(const PortSet& other);
140 typedef std::vector<Port*> PortVec;
142 // Vector of vectors, indexed by DataType::to_index()
143 std::vector<PortVec> _ports;
145 ChanCount _chan_count;
149 } // namespace ARDOUR
151 #endif // __ardour_port_set_h__