2 Copyright (C) 2002-2006 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 <pbd/error.h>
22 #include <ardour/jack_port.h>
23 #include <ardour/audioengine.h>
27 using namespace ARDOUR;
31 JackPort::JackPort (const std::string& name, DataType type, Flags flgs)
32 : Port (name, flgs), _port (0)
34 _port = jack_port_register (engine->jack(), name.c_str(), type.to_jack_type(), flgs, 0);
37 throw failed_constructor();
42 _name = jack_port_name (_port);
45 JackPort::~JackPort ()
47 cerr << "deleting jack port " << _name << endl;
49 jack_port_unregister (engine->jack(), _port);
53 JackPort::set_name (const string& str)
57 if ((ret = jack_port_set_name (_port, str.c_str())) == 0) {
65 JackPort::disconnect ()
67 return jack_port_disconnect (engine->jack(), _port);
71 JackPort::total_latency () const
73 return jack_port_get_total_latency (engine->jack(), _port);
77 JackPort::reestablish ()
81 short_name = _name.substr (_name.find_last_of (':') + 1);
83 _port = jack_port_register (engine->jack(), short_name.c_str(), type().to_jack_type(), _flags, 0);
86 error << string_compose (_("could not reregister %1"), _name) << endmsg;
97 JackPort::recompute_total_latency () const
99 #ifdef HAVE_JACK_RECOMPUTE_LATENCY
100 jack_recompute_total_latency (engine->jack(), _port);
105 JackPort::reconnect ()
107 /* caller must hold process lock; intended to be used only after reestablish() */
109 for (set<string>::iterator i = _named_connections.begin(); i != _named_connections.end(); ++i) {
119 JackPort::connect (const std::string& other)
123 if (_flags & IsOutput) {
124 /* this is the source */
125 ret = jack_connect (engine->jack(), _name.c_str(), other.c_str());
127 ret = jack_connect (engine->jack(), other.c_str(), _name.c_str());
131 _named_connections.insert (other);
138 JackPort::disconnect (const std::string& other)
142 if (_flags & IsInput) {
143 ret = jack_disconnect (engine->jack(), other.c_str(), _name.c_str());
145 ret = jack_disconnect (engine->jack(), _name.c_str(), other.c_str());
148 set<string>::iterator i = _named_connections.find (other);
150 if (i != _named_connections.end()) {
151 _named_connections.erase (i);
158 JackPort::disconnect_all ()
160 _named_connections.clear ();
161 return jack_port_disconnect (engine->jack(), _port);
165 JackPort::get_connections (vector<string>& names) const
167 const char** cstrs = jack_port_get_connections (_port);
174 for (i = 0; cstrs[i]; ++i) {
175 names.push_back (string (cstrs[i]));