2 Copyright (C) 2002-2009 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "port_group.h"
21 #include "port_matrix.h"
23 #include "ardour/session.h"
24 #include "ardour/audio_track.h"
25 #include "ardour/midi_track.h"
26 #include "ardour/audioengine.h"
27 #include "ardour/port.h"
28 #include "ardour/bundle.h"
29 #include <boost/shared_ptr.hpp>
35 /** Add a bundle to a group.
39 PortGroup::add_bundle (boost::shared_ptr<ARDOUR::Bundle> b)
41 bundles.push_back (b);
44 /** Add a port to a group.
48 PortGroup::add_port (std::string const &p)
60 /** PortGroupUI constructor.
61 * @param m PortMatrix to work for.
62 * @Param g PortGroup to represent.
65 PortGroupUI::PortGroupUI (PortMatrix* m, PortGroup* g)
68 , _visibility_checkbutton (g->name)
70 _port_group->visible = true;
71 setup_visibility_checkbutton ();
73 _visibility_checkbutton.signal_toggled().connect (sigc::mem_fun (*this, &PortGroupUI::visibility_checkbutton_toggled));
76 /** The visibility of a PortGroupUI has been toggled */
78 PortGroupUI::visibility_checkbutton_toggled ()
80 _port_group->visible = _visibility_checkbutton.get_active ();
81 setup_visibility_checkbutton ();
82 _port_matrix->setup ();
85 /** Set up the visibility checkbutton according to PortGroup::visible */
87 PortGroupUI::setup_visibility_checkbutton ()
89 if (_visibility_checkbutton.get_active () != _port_group->visible) {
90 _visibility_checkbutton.set_active (_port_group->visible);
94 /** PortGroupList constructor.
95 * @param session Session to get bundles from.
96 * @param type Type of bundles to offer (audio or MIDI)
97 * @param offer_inputs true to offer output bundles, otherwise false.
98 * @param mask Mask of groups to make visible by default.
101 PortGroupList::PortGroupList (ARDOUR::Session & session, ARDOUR::DataType type, bool offer_inputs, Mask mask)
102 : _session (session), _type (type), _offer_inputs (offer_inputs),
103 _buss (_("Bus"), mask & BUSS),
104 _track (_("Track"), mask & TRACK),
105 _system (_("System"), mask & SYSTEM),
106 _other (_("Other"), mask & OTHER)
111 /** Find or re-find all our bundles and set up our lists */
113 PortGroupList::refresh ()
122 /* Find the bundles for routes */
124 boost::shared_ptr<ARDOUR::Session::RouteList> routes = _session.get_routes ();
126 for (ARDOUR::Session::RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
130 if (_type == ARDOUR::DataType::AUDIO) {
132 if (boost::dynamic_pointer_cast<ARDOUR::AudioTrack> (*i)) {
134 } else if (!boost::dynamic_pointer_cast<ARDOUR::MidiTrack>(*i)) {
139 } else if (_type == ARDOUR::DataType::MIDI) {
141 if (boost::dynamic_pointer_cast<ARDOUR::MidiTrack> (*i)) {
145 /* No MIDI busses yet */
149 g->add_bundle (_offer_inputs ? (*i)->bundle_for_inputs() : (*i)->bundle_for_outputs ());
153 /* Bundles created by the session */
154 _session.foreach_bundle (sigc::mem_fun (*this, &PortGroupList::maybe_add_session_bundle));
156 /* XXX: inserts, sends, plugin inserts? */
158 /* Now we need to find the non-ardour ports; we do this by first
159 finding all the ports that we can connect to.
162 const char **ports = _session.engine().get_ports ("", _type.to_jack_type(), _offer_inputs ?
163 JackPortIsInput : JackPortIsOutput);
167 string client_matching_string;
169 client_matching_string = _session.engine().client_name();
170 client_matching_string += ':';
173 std::string const p = ports[n];
175 if (p.substr(0, strlen ("system:")) == "system:" || p.substr (0, strlen ("alsa_pcm:")) == "alsa_pcm:") {
176 /* system: or alsa_pcm: prefix */
177 _system.add_port (p);
179 if (p.substr(0, client_matching_string.length()) != client_matching_string) {
180 /* other (non-ardour) prefix */
191 push_back (&_system);
198 PortGroupList::set_type (ARDOUR::DataType t)
204 PortGroupList::set_offer_inputs (bool i)
210 PortGroupList::maybe_add_session_bundle (boost::shared_ptr<ARDOUR::Bundle> b)
212 if (b->ports_are_inputs () == _offer_inputs && b->type () == _type) {
213 _system.bundles.push_back (b);