#include "midi++/types.h"
#include "midi++/port.h"
+#include "midi++/jack_midi_port.h"
+#include "midi++/ipmidi_port.h"
#include "midi++/manager.h"
#include "ardour/debug.h"
*/
SurfacePort::SurfacePort (Surface& s)
: _surface (&s)
+ , _input_port (0)
+ , _output_port (0)
{
- 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);
+ if (_surface->mcp().device_info().uses_ipmidi()) {
+ _input_port = new MIDI::IPMIDIPort (_surface->mcp().ipmidi_base() +_surface->number());
+ _output_port = _input_port;
+ } else {
+ jack_client_t* jack = MackieControlProtocol::instance()->get_session().engine().jack();
+
+ _input_port = new MIDI::JackMIDIPort (string_compose (_("%1 in"), _surface->name()), MIDI::Port::IsInput, jack);
+ _output_port =new MIDI::JackMIDIPort (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);
+ }
}
SurfacePort::~SurfacePort()
{
- MIDI::Manager* mm = MIDI::Manager::instance ();
-
- if (_input_port) {
- mm->remove_port (_input_port);
+ if (_surface->mcp().device_info().uses_ipmidi()) {
delete _input_port;
- }
+ } else {
- if (_output_port) {
- mm->remove_port (_output_port);
- delete _output_port;
+ MIDI::Manager* mm = MIDI::Manager::instance ();
+
+ if (_input_port) {
+ mm->remove_port (_input_port);
+ delete _input_port;
+ }
+
+ if (_output_port) {
+ _output_port->drain (10000);
+ mm->remove_port (_output_port);
+ delete _output_port;
+ }
}
}
DEBUG_TRACE (DEBUG::MackieControl, string_compose ("port %1 write %2\n", output_port().name(), mba));
- int count = output_port().write (mba.bytes().get(), mba.size(), 0);
+ 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);
- if (count != (int)mba.size()) {
+ if (count != (int) mba.size()) {
- if (errno == 0) {
+ if (errno == 0) {
cout << "port overflow on " << output_port().name() << ". Did not write all of " << mba << endl;