2 Copyright (C) 2006,2007 John Anderson
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.
23 #include <sigc++/sigc++.h>
24 #include <boost/shared_array.hpp>
26 #include "midi++/types.h"
27 #include "midi++/port.h"
28 #include "midi++/manager.h"
30 #include "ardour/debug.h"
31 #include "ardour/rc_configuration.h"
32 #include "ardour/session.h"
33 #include "ardour/audioengine.h"
36 #include "mackie_control_protocol.h"
38 #include "surface_port.h"
44 using namespace Mackie;
47 /** @param input_port Input MIDI::Port; this object takes responsibility for
48 * adding & removing it from the MIDI::Manager and destroying it. @param
49 * output_port Output MIDI::Port; responsibility similarly taken.
51 SurfacePort::SurfacePort (Surface& s)
54 jack_client_t* jack = MackieControlProtocol::instance()->get_session().engine().jack();
56 _input_port = new MIDI::Port (string_compose (_("%1 in"), _surface->name()), MIDI::Port::IsInput, jack);
57 _output_port =new MIDI::Port (string_compose (_("%1 out"), _surface->name()), MIDI::Port::IsOutput, jack);
59 /* MackieControl has its own thread for handling input from the input
60 * port, and we don't want anything handling output from the output
61 * port. This stops the Generic MIDI UI event loop in ardour from
62 * attempting to handle these ports.
65 _input_port->set_centrally_parsed (false);
66 _output_port->set_centrally_parsed (false);
68 MIDI::Manager * mm = MIDI::Manager::instance();
70 mm->add_port (_input_port);
71 mm->add_port (_output_port);
74 SurfacePort::~SurfacePort()
76 MIDI::Manager* mm = MIDI::Manager::instance ();
79 mm->remove_port (_input_port);
84 mm->remove_port (_output_port);
89 // wrapper for one day when strerror_r is working properly
90 string fetch_errmsg (int error_number)
92 char * msg = strerror (error_number);
97 SurfacePort::write (const MidiByteArray & mba)
103 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("port %1 write %2\n", output_port().name(), mba));
105 int count = output_port().write (mba.bytes().get(), mba.size(), 0);
107 if (count != (int)mba.size()) {
111 cout << "port overflow on " << output_port().name() << ". Did not write all of " << mba << endl;
113 } else if (errno != EAGAIN) {
115 os << "Surface: couldn't write to port " << output_port().name();
116 os << ", error: " << fetch_errmsg (errno) << "(" << errno << ")";
117 cout << os.str() << endl;
127 Mackie::operator << (ostream & os, const SurfacePort & port)
130 os << "name: " << port.input_port().name() << " " << port.output_port().name();