2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-03 08:34:29 -04:00
|
|
|
* Copyright (C) 2006-2007 John Anderson
|
|
|
|
* Copyright (C) 2007-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Len Ovens <len@ovenwerks.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-10 10:27:44 -04:00
|
|
|
#include <sstream>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cerrno>
|
|
|
|
|
|
|
|
#include <sigc++/sigc++.h>
|
|
|
|
#include <boost/shared_array.hpp>
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-09-06 10:39:14 -04:00
|
|
|
#include "pbd/failed_constructor.h"
|
|
|
|
|
2011-09-26 16:35:16 -04:00
|
|
|
#include "midi++/types.h"
|
2012-04-23 22:28:51 -04:00
|
|
|
#include "midi++/ipmidi_port.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
#include "ardour/async_midi_port.h"
|
2012-04-10 10:27:44 -04:00
|
|
|
#include "ardour/debug.h"
|
|
|
|
#include "ardour/rc_configuration.h"
|
2012-04-12 12:41:07 -04:00
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/audioengine.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-04-10 10:27:44 -04:00
|
|
|
#include "controls.h"
|
2012-04-12 12:41:07 -04:00
|
|
|
#include "mackie_control_protocol.h"
|
2012-04-10 10:27:44 -04:00
|
|
|
#include "surface.h"
|
|
|
|
#include "surface_port.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace std;
|
2012-04-10 10:27:44 -04:00
|
|
|
using namespace PBD;
|
2013-08-07 22:22:11 -04:00
|
|
|
using namespace ARDOUR;
|
2015-04-15 20:37:20 -04:00
|
|
|
using namespace ArdourSurface;
|
2023-08-23 07:27:21 -04:00
|
|
|
using namespace ArdourSurface::MACKIE_NAMESPACE;
|
2008-12-12 17:55:03 -05:00
|
|
|
|
2012-04-12 12:41:07 -04:00
|
|
|
SurfacePort::SurfacePort (Surface& s)
|
2012-04-10 10:27:44 -04:00
|
|
|
: _surface (&s)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
if (_surface->mcp().device_info().uses_ipmidi()) {
|
2012-04-25 17:21:36 -04:00
|
|
|
_input_port = new MIDI::IPMIDIPort (_surface->mcp().ipmidi_base() +_surface->number());
|
2012-04-23 22:28:51 -04:00
|
|
|
_output_port = _input_port;
|
2013-12-21 15:30:07 -05:00
|
|
|
|
2012-04-23 22:28:51 -04:00
|
|
|
} else {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2023-08-25 12:08:56 -04:00
|
|
|
#ifdef UF8
|
|
|
|
string in_name = X_("SSL-UFx control in");
|
|
|
|
string out_name = X_("SSL-UFx control out");
|
|
|
|
#else
|
|
|
|
string in_name = X_("mackie control in");
|
|
|
|
string out_name = X_("mackie control out");
|
|
|
|
#endif
|
2015-10-11 11:58:00 -04:00
|
|
|
|
|
|
|
if (_surface->mcp().device_info().extenders() > 0) {
|
2023-08-25 12:08:56 -04:00
|
|
|
if (_surface->number() != _surface->mcp().device_info().master_position()) {
|
|
|
|
#ifdef UF8
|
|
|
|
in_name = string_compose (X_("SSL-UFx control in ext %1"), (_surface->number() + 1));
|
|
|
|
out_name = string_compose (X_("SSL-UFx control out ext %1"), _surface->number() + 1);
|
|
|
|
#else
|
2015-10-12 00:37:04 -04:00
|
|
|
in_name = string_compose (X_("mackie control in ext %1"), (_surface->number() + 1));
|
|
|
|
out_name = string_compose (X_("mackie control out ext %1"), _surface->number() + 1);
|
2023-08-25 12:08:56 -04:00
|
|
|
#endif
|
2015-10-11 11:58:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_async_in = AudioEngine::instance()->register_input_port (DataType::MIDI, in_name, true);
|
|
|
|
_async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, out_name, true);
|
2013-08-07 22:22:11 -04:00
|
|
|
|
2013-09-06 10:39:14 -04:00
|
|
|
if (_async_in == 0 || _async_out == 0) {
|
|
|
|
throw failed_constructor();
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
_input_port = std::dynamic_pointer_cast<AsyncMIDIPort>(_async_in).get();
|
|
|
|
_output_port = std::dynamic_pointer_cast<AsyncMIDIPort>(_async_out).get();
|
2012-04-23 22:28:51 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfacePort::~SurfacePort()
|
|
|
|
{
|
2013-12-21 15:30:07 -05:00
|
|
|
if (dynamic_cast<MIDI::IPMIDIPort*>(_input_port)) {
|
2011-09-26 16:35:16 -04:00
|
|
|
delete _input_port;
|
2015-10-03 13:51:17 -04:00
|
|
|
_input_port = 0;
|
2012-04-23 22:28:51 -04:00
|
|
|
} else {
|
2013-08-07 22:22:11 -04:00
|
|
|
if (_async_in) {
|
2015-10-03 13:51:17 -04:00
|
|
|
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unregistering input port %1\n", _async_in->name()));
|
2017-07-28 14:15:15 -04:00
|
|
|
Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock());
|
2013-08-07 22:22:11 -04:00
|
|
|
AudioEngine::instance()->unregister_port (_async_in);
|
2013-12-21 15:30:07 -05:00
|
|
|
_async_in.reset ((ARDOUR::Port*) 0);
|
2012-04-23 22:28:51 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
if (_async_out) {
|
2016-02-01 13:26:30 -05:00
|
|
|
_output_port->drain (10000, 250000);
|
2015-10-03 13:51:17 -04:00
|
|
|
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unregistering output port %1\n", _async_out->name()));
|
2017-07-28 14:15:15 -04:00
|
|
|
Glib::Threads::Mutex::Lock em (AudioEngine::instance()->process_lock());
|
2013-08-07 22:22:11 -04:00
|
|
|
AudioEngine::instance()->unregister_port (_async_out);
|
2013-12-21 15:30:07 -05:00
|
|
|
_async_out.reset ((ARDOUR::Port*) 0);
|
2012-04-23 22:28:51 -04:00
|
|
|
}
|
2011-09-26 16:35:16 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2013-12-13 16:00:08 -05:00
|
|
|
XMLNode&
|
2022-04-06 23:56:32 -04:00
|
|
|
SurfacePort::get_state () const
|
2013-12-13 16:00:08 -05:00
|
|
|
{
|
|
|
|
XMLNode* node = new XMLNode (X_("Port"));
|
|
|
|
|
2013-12-21 15:30:07 -05:00
|
|
|
if (dynamic_cast<MIDI::IPMIDIPort*>(_input_port)) {
|
2013-12-13 16:00:08 -05:00
|
|
|
/* no state required for IPMidi ports */
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
XMLNode* child;
|
|
|
|
|
|
|
|
child = new XMLNode (X_("Input"));
|
|
|
|
child->add_child_nocopy (_async_in->get_state());
|
|
|
|
node->add_child_nocopy (*child);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-12-13 16:00:08 -05:00
|
|
|
|
|
|
|
child = new XMLNode (X_("Output"));
|
|
|
|
child->add_child_nocopy (_async_out->get_state());
|
|
|
|
node->add_child_nocopy (*child);
|
|
|
|
|
|
|
|
return *node;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SurfacePort::set_state (const XMLNode& node, int version)
|
|
|
|
{
|
2013-12-21 15:30:07 -05:00
|
|
|
if (dynamic_cast<MIDI::IPMIDIPort*>(_input_port)) {
|
2013-12-13 16:00:08 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-14 11:57:13 -04:00
|
|
|
|
2015-10-11 11:58:00 -04:00
|
|
|
XMLNode* child;
|
2013-12-13 16:00:08 -05:00
|
|
|
|
2015-10-11 11:58:00 -04:00
|
|
|
if ((child = node.child (X_("Input"))) != 0) {
|
|
|
|
XMLNode* portnode = child->child (Port::state_node_name.c_str());
|
|
|
|
if (portnode) {
|
2021-04-16 20:07:09 -04:00
|
|
|
portnode->remove_property ("name");
|
2015-10-11 11:58:00 -04:00
|
|
|
_async_in->set_state (*portnode, version);
|
2013-12-13 16:00:08 -05:00
|
|
|
}
|
2015-10-11 11:58:00 -04:00
|
|
|
}
|
2013-12-13 16:00:08 -05:00
|
|
|
|
2015-10-11 11:58:00 -04:00
|
|
|
if ((child = node.child (X_("Output"))) != 0) {
|
|
|
|
XMLNode* portnode = child->child (Port::state_node_name.c_str());
|
|
|
|
if (portnode) {
|
2021-04-16 20:07:09 -04:00
|
|
|
portnode->remove_property ("name");
|
2015-10-11 11:58:00 -04:00
|
|
|
_async_out->set_state (*portnode, version);
|
2013-12-13 16:00:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-11 11:58:00 -04:00
|
|
|
void
|
|
|
|
SurfacePort::reconnect ()
|
|
|
|
{
|
|
|
|
_async_out->reconnect ();
|
|
|
|
_async_in->reconnect ();
|
2021-07-19 13:25:27 -04:00
|
|
|
|
2015-10-11 11:58:00 -04:00
|
|
|
}
|
|
|
|
|
2015-10-07 13:17:42 -04:00
|
|
|
std::string
|
|
|
|
SurfacePort::input_name () const
|
|
|
|
{
|
|
|
|
return _async_in->name();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
SurfacePort::output_name () const
|
|
|
|
{
|
|
|
|
return _async_out->name();
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
// wrapper for one day when strerror_r is working properly
|
2012-04-08 10:11:00 -04:00
|
|
|
string fetch_errmsg (int error_number)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-08 10:11:00 -04:00
|
|
|
char * msg = strerror (error_number);
|
2008-06-02 17:41:35 -04:00
|
|
|
return msg;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
int
|
2012-04-12 12:41:07 -04:00
|
|
|
SurfacePort::write (const MidiByteArray & mba)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-08 10:11:00 -04:00
|
|
|
if (mba.empty()) {
|
2013-03-06 15:15:28 -05:00
|
|
|
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("port %1 asked to write an empty MBA\n", output_port().name()));
|
2012-04-12 12:41:07 -04:00
|
|
|
return 0;
|
2012-04-08 10:11:00 -04:00
|
|
|
}
|
|
|
|
|
2021-07-19 13:25:27 -04:00
|
|
|
#ifndef NDEBUG
|
|
|
|
/* skip meter output since it makes too much output for normal use */
|
|
|
|
if (mba[0] != 0xd0 && mba[0] != 0xd1) {
|
|
|
|
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("port %1 write %2\n", output_port().name(), mba));
|
|
|
|
}
|
|
|
|
#endif
|
2012-04-21 22:15:24 -04:00
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
if (mba[0] != 0xf0 && mba.size() > 3) {
|
|
|
|
std::cerr << "TOO LONG WRITE: " << mba << std::endl;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
/* this call relies on std::vector<T> using contiguous storage. not
|
|
|
|
* actually guaranteed by the standard, but way, way beyond likely.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int count = output_port().write (&mba[0], mba.size(), 0);
|
2012-04-10 10:45:21 -04:00
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
if (count != (int) mba.size()) {
|
2012-04-12 12:41:07 -04:00
|
|
|
|
2012-04-30 11:54:13 -04:00
|
|
|
if (errno == 0) {
|
2012-04-12 12:41:07 -04:00
|
|
|
|
2010-07-07 21:00:46 -04:00
|
|
|
cout << "port overflow on " << output_port().name() << ". Did not write all of " << mba << endl;
|
2012-04-12 12:41:07 -04:00
|
|
|
|
2012-04-08 10:11:00 -04:00
|
|
|
} else if (errno != EAGAIN) {
|
2008-06-02 17:41:35 -04:00
|
|
|
ostringstream os;
|
2010-07-07 21:00:46 -04:00
|
|
|
os << "Surface: couldn't write to port " << output_port().name();
|
2012-04-08 10:11:00 -04:00
|
|
|
os << ", error: " << fetch_errmsg (errno) << "(" << errno << ")";
|
2008-12-12 17:55:03 -05:00
|
|
|
cout << os.str() << endl;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2012-04-10 10:27:44 -04:00
|
|
|
|
2012-04-12 12:41:07 -04:00
|
|
|
return -1;
|
2012-04-10 10:27:44 -04:00
|
|
|
}
|
|
|
|
|
2012-04-12 12:41:07 -04:00
|
|
|
return 0;
|
2012-04-10 10:27:44 -04:00
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
ostream &
|
2023-08-23 07:27:21 -04:00
|
|
|
MACKIE_NAMESPACE::operator << (ostream & os, const SurfacePort & port)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
os << "{ ";
|
2010-07-07 21:00:46 -04:00
|
|
|
os << "name: " << port.input_port().name() << " " << port.output_port().name();
|
2008-06-02 17:41:35 -04:00
|
|
|
os << "; ";
|
|
|
|
os << " }";
|
|
|
|
return os;
|
|
|
|
}
|