2008-06-02 17:41:35 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006,2007 John Anderson
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
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"
|
2013-08-07 22:22:11 -04:00
|
|
|
#include "ardour/async_midi_port.h"
|
|
|
|
#include "ardour/midiport_manager.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
|
|
|
|
2012-04-10 10:27:44 -04:00
|
|
|
#include "i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Mackie;
|
2012-04-10 10:27:44 -04:00
|
|
|
using namespace PBD;
|
2013-08-07 22:22:11 -04:00
|
|
|
using namespace ARDOUR;
|
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
|
|
|
{
|
2013-09-06 10:39:14 -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;
|
|
|
|
} else {
|
2013-08-07 22:22:11 -04:00
|
|
|
_async_in = AudioEngine::instance()->register_input_port (DataType::MIDI, string_compose (_("%1 in"), _surface->name()), true);
|
|
|
|
_async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, string_compose (_("%1 out"), _surface->name()), true);
|
|
|
|
|
2013-09-06 10:39:14 -04:00
|
|
|
if (_async_in == 0 || _async_out == 0) {
|
|
|
|
throw failed_constructor();
|
|
|
|
}
|
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
_input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in).get();
|
|
|
|
_output_port = boost::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()
|
|
|
|
{
|
2012-04-23 22:28:51 -04:00
|
|
|
if (_surface->mcp().device_info().uses_ipmidi()) {
|
2011-09-26 16:35:16 -04:00
|
|
|
delete _input_port;
|
2012-04-23 22:28:51 -04:00
|
|
|
} else {
|
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
if (_async_in) {
|
|
|
|
AudioEngine::instance()->unregister_port (_async_in);
|
|
|
|
_async_in.reset ();
|
2012-04-23 22:28:51 -04:00
|
|
|
}
|
|
|
|
|
2013-08-07 22:22:11 -04:00
|
|
|
if (_async_out) {
|
2012-04-23 22:28:51 -04:00
|
|
|
_output_port->drain (10000);
|
2013-08-07 22:22:11 -04:00
|
|
|
AudioEngine::instance()->unregister_port (_async_out);
|
|
|
|
_async_out.reset ();
|
2012-04-23 22:28:51 -04:00
|
|
|
}
|
2011-09-26 16:35:16 -04:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-12 12:41:07 -04:00
|
|
|
int
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-10 10:45:21 -04:00
|
|
|
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("port %1 write %2\n", output_port().name(), mba));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2012-04-12 12:41:07 -04:00
|
|
|
ostream &
|
|
|
|
Mackie::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;
|
|
|
|
}
|
2011-05-04 05:22:32 -04:00
|
|
|
|