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 #include <ardour/port_set.h>
25 for (size_t i=0; i < DataType::num_types; ++i)
26 _ports.push_back( PortVec() );
29 static bool sort_ports_by_name (Port* a, Port* b)
31 return (a->name() < b->name());
35 PortSet::add_port(Port* port)
37 const size_t list_index = port->type().to_index();
38 assert(list_index < _ports.size());
40 PortVec& v = _ports[list_index];
43 sort(v.begin(), v.end(), sort_ports_by_name);
45 _count.set(port->type(), _count.get(port->type()) + 1);
47 assert(_count.get(port->type()) == _ports[port->type().to_index()].size());
51 /** Get the total number of ports (of all types) in the PortSet
54 PortSet::num_ports() const
58 for (std::vector<PortVec>::const_iterator l = _ports.begin(); l != _ports.end(); ++l)
65 PortSet::contains(const Port* port) const
67 for (std::vector<PortVec>::const_iterator l = _ports.begin(); l != _ports.end(); ++l)
68 if (find((*l).begin(), (*l).end(), port) != (*l).end())
75 PortSet::port(size_t n) const
79 size_t size_so_far = 0;
81 for (std::vector<PortVec>::const_iterator l = _ports.begin(); l != _ports.end(); ++l) {
82 if (n < size_so_far + (*l).size())
83 return (*l)[n - size_so_far];
85 size_so_far += (*l).size();
88 return NULL; // n out of range
92 PortSet::port(DataType type, size_t n) const
94 if (type == DataType::NIL) {
97 const PortVec& v = _ports[type.to_index()];
104 PortSet::nth_audio_port(size_t n) const
106 return dynamic_cast<AudioPort*>(port(DataType::AUDIO, n));
110 PortSet::nth_midi_port(size_t n) const
112 return dynamic_cast<MidiPort*>(port(DataType::MIDI, n));