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
|
|
|
|
2011-09-26 16:35:16 -04:00
|
|
|
#include "midi++/types.h"
|
|
|
|
#include "midi++/port.h"
|
|
|
|
#include "midi++/manager.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
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
|
|
|
|
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;
|
2008-12-12 17:55:03 -05:00
|
|
|
|
2012-04-12 12:41:07 -04:00
|
|
|
/** @param input_port Input MIDI::Port; this object takes responsibility for
|
|
|
|
* adding & removing it from the MIDI::Manager and destroying it. @param
|
|
|
|
* output_port Output MIDI::Port; responsibility similarly taken.
|
2011-09-26 16:35:16 -04: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-12 12:41:07 -04:00
|
|
|
jack_client_t* jack = MackieControlProtocol::instance()->get_session().engine().jack();
|
|
|
|
|
|
|
|
_input_port = new MIDI::Port (string_compose (_("%1 in"), _surface->name()), MIDI::Port::IsInput, jack);
|
|
|
|
_output_port =new MIDI::Port (string_compose (_("%1 out"), _surface->name()), MIDI::Port::IsOutput, jack);
|
|
|
|
|
|
|
|
/* MackieControl has its own thread for handling input from the input
|
|
|
|
* port, and we don't want anything handling output from the output
|
|
|
|
* port. This stops the Generic MIDI UI event loop in ardour from
|
|
|
|
* attempting to handle these ports.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_input_port->set_centrally_parsed (false);
|
|
|
|
_output_port->set_centrally_parsed (false);
|
|
|
|
|
|
|
|
MIDI::Manager * mm = MIDI::Manager::instance();
|
|
|
|
|
|
|
|
mm->add_port (_input_port);
|
|
|
|
mm->add_port (_output_port);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
SurfacePort::~SurfacePort()
|
|
|
|
{
|
2011-09-26 16:35:16 -04:00
|
|
|
MIDI::Manager* mm = MIDI::Manager::instance ();
|
|
|
|
|
|
|
|
if (_input_port) {
|
|
|
|
mm->remove_port (_input_port);
|
|
|
|
delete _input_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_output_port) {
|
|
|
|
mm->remove_port (_output_port);
|
|
|
|
delete _output_port;
|
|
|
|
}
|
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()) {
|
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-08 10:11:00 -04:00
|
|
|
int count = output_port().write (mba.bytes().get(), mba.size(), 0);
|
2012-04-10 10:45:21 -04:00
|
|
|
|
2012-04-08 10:11:00 -04:00
|
|
|
if (count != (int)mba.size()) {
|
2012-04-12 12:41:07 -04:00
|
|
|
|
2012-04-08 10:11:00 -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
|
|
|
|