diff options
author | Carl Hetherington <carl@carlh.net> | 2010-07-08 01:00:46 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2010-07-08 01:00:46 +0000 |
commit | 4885f29be158999626eb6dfa5507fe2258d388b0 (patch) | |
tree | a82c57b53937deed062cb0fad9226ce8d81626c8 /libs/surfaces | |
parent | a15bdfc6d9b42b4078976da54bdd84325cea3d16 (diff) |
Trim midi++ port code to either do in or out, but not both in the same object.
git-svn-id: svn://localhost/ardour2/branches/3.0@7391 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/surfaces')
-rw-r--r-- | libs/surfaces/generic_midi/midicontrollable.cc | 8 | ||||
-rw-r--r-- | libs/surfaces/generic_midi/midiinvokable.cc | 4 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_control_protocol.cc | 22 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_control_protocol.h | 2 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_port.cc | 20 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_port.h | 2 | ||||
-rw-r--r-- | libs/surfaces/mackie/surface_port.cc | 18 | ||||
-rw-r--r-- | libs/surfaces/mackie/surface_port.h | 11 |
8 files changed, 46 insertions, 41 deletions
diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc index 32b6ff8fe1..aa8ac6ae35 100644 --- a/libs/surfaces/generic_midi/midicontrollable.cc +++ b/libs/surfaces/generic_midi/midicontrollable.cc @@ -124,7 +124,7 @@ void MIDIControllable::learn_about_external_control () { drop_external_control (); - _port.input()->any.connect_same_thread (midi_learn_connection, boost::bind (&MIDIControllable::midi_receiver, this, _1, _2, _3)); + _port.parser()->any.connect_same_thread (midi_learn_connection, boost::bind (&MIDIControllable::midi_receiver, this, _1, _2, _3)); } void @@ -268,7 +268,7 @@ MIDIControllable::midi_receiver (Parser &, byte *msg, size_t /*len*/) /* if the our port doesn't do input anymore, forget it ... */ - if (!_port.input()) { + if (!_port.parser()) { return; } @@ -288,11 +288,11 @@ MIDIControllable::bind_midi (channel_t chn, eventType ev, MIDI::byte additional) control_channel = chn; control_additional = additional; - if (_port.input() == 0) { + if (_port.parser() == 0) { return; } - Parser& p = *_port.input(); + Parser& p = *_port.parser(); int chn_i = chn; switch (ev) { diff --git a/libs/surfaces/generic_midi/midiinvokable.cc b/libs/surfaces/generic_midi/midiinvokable.cc index a77335fa7a..79835835a4 100644 --- a/libs/surfaces/generic_midi/midiinvokable.cc +++ b/libs/surfaces/generic_midi/midiinvokable.cc @@ -127,11 +127,11 @@ MIDIInvokable::bind_midi (channel_t chn, eventType ev, MIDI::byte additional) control_channel = chn; control_additional = additional; - if (_port.input() == 0) { + if (_port.parser() == 0) { return; } - Parser& p = *_port.input(); + Parser& p = *_port.parser(); int chn_i = chn; diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc index f25b31439d..073d0c475f 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.cc +++ b/libs/surfaces/mackie/mackie_control_protocol.cc @@ -563,11 +563,11 @@ MackieControlProtocol::connect_session_signals() } void -MackieControlProtocol::add_port (MIDI::Port & midi_port, int number) +MackieControlProtocol::add_port (MIDI::Port & midi_input_port, MIDI::Port & midi_output_port, int number) { - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("add port %1\n", midi_port.name())); + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("add port %1 %2\n", midi_input_port.name(), midi_output_port.name())); - MackiePort * sport = new MackiePort (*this, midi_port, number); + MackiePort * sport = new MackiePort (*this, midi_input_port, midi_output_port, number); _ports.push_back (sport); sport->init_event.connect_same_thread (port_connections, boost::bind (&MackieControlProtocol::handle_port_init, this, sport)); @@ -579,18 +579,19 @@ void MackieControlProtocol::create_ports() { MIDI::Manager * mm = MIDI::Manager::instance(); - MIDI::Port * midi_port = mm->add_port (new MIDI::Port (default_port_name, O_RDWR, session->engine().jack())); + MIDI::Port * midi_input_port = mm->add_port (new MIDI::Port (default_port_name, MIDI::Port::IsInput, session->engine().jack())); + MIDI::Port * midi_output_port = mm->add_port (new MIDI::Port (default_port_name, MIDI::Port::IsOutput, session->engine().jack())); // open main port - if (!midi_port->ok()) { + if (!midi_input_port->ok() || !midi_output_port->ok()) { ostringstream os; - os << string_compose (_("no MIDI port named \"%1\" exists - Mackie control disabled"), default_port_name); + os << _("Mackie control MIDI ports could not be created; Mackie control disabled"); error << os.str() << endmsg; throw MackieControlException (os.str()); } - add_port (*midi_port, 0); + add_port (*midi_input_port, *midi_output_port, 0); // open extender ports. Up to 9. Should be enough. // could also use mm->get_midi_ports() @@ -600,9 +601,10 @@ MackieControlProtocol::create_ports() for (int index = 1; index <= 9; ++index) { ostringstream os; os << ext_port_base << index; - MIDI::Port * midi_port = mm->add_port (new MIDI::Port (os.str(), O_RDWR, session->engine().jack())); - if (midi_port->ok()) { - add_port (*midi_port, index); + MIDI::Port * midi_input_port = mm->add_port (new MIDI::Port (os.str(), MIDI::Port::IsInput, session->engine().jack())); + MIDI::Port * midi_output_port = mm->add_port (new MIDI::Port (os.str(), MIDI::Port::IsOutput, session->engine().jack())); + if (midi_input_port->ok() && midi_output_port->ok()) { + add_port (*midi_input_port, *midi_output_port, index); } } } diff --git a/libs/surfaces/mackie/mackie_control_protocol.h b/libs/surfaces/mackie/mackie_control_protocol.h index d920173eca..f84530c733 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.h +++ b/libs/surfaces/mackie/mackie_control_protocol.h @@ -266,7 +266,7 @@ class MackieControlProtocol */ bool handle_strip_button(Mackie::Control &, Mackie::ButtonState, boost::shared_ptr<ARDOUR::Route>); - void add_port(MIDI::Port &, int number); + void add_port (MIDI::Port &, MIDI::Port &, int number); /** Read session data and send to surface. Includes diff --git a/libs/surfaces/mackie/mackie_port.cc b/libs/surfaces/mackie/mackie_port.cc index 5d8ea56a69..1443aaa425 100644 --- a/libs/surfaces/mackie/mackie_port.cc +++ b/libs/surfaces/mackie/mackie_port.cc @@ -48,12 +48,12 @@ MidiByteArray mackie_sysex_hdr ( 5, MIDI::sysex, 0x0, 0x0, 0x66, 0x10 ); // The MCU extender sysex header MidiByteArray mackie_sysex_hdr_xt ( 5, MIDI::sysex, 0x0, 0x0, 0x66, 0x11 ); -MackiePort::MackiePort( MackieControlProtocol & mcp, MIDI::Port & port, int number, port_type_t port_type ) - : SurfacePort( port, number ) - , _mcp( mcp ) - , _port_type( port_type ) - , _emulation( none ) - , _initialising( true ) +MackiePort::MackiePort (MackieControlProtocol & mcp, MIDI::Port & input_port, MIDI::Port & output_port, int number, port_type_t port_type) + : SurfacePort (input_port, output_port, number) + , _mcp( mcp ) + , _port_type( port_type ) + , _emulation( none ) + , _initialising( true ) { DEBUG_TRACE (DEBUG::MackieControl, "MackiePort::MackiePort\n"); } @@ -91,7 +91,7 @@ void MackiePort::open() { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackiePort::open %1\n", *this)); - port().input()->sysex.connect_same_thread (sysex_connection, boost::bind (&MackiePort::handle_midi_sysex, this, _1, _2, _3)); + input_port().parser()->sysex.connect_same_thread (sysex_connection, boost::bind (&MackiePort::handle_midi_sysex, this, _1, _2, _3)); // make sure the device is connected init(); @@ -147,7 +147,7 @@ MidiByteArray MackiePort::host_connection_query( MidiByteArray & bytes ) { finalise_init( false ); ostringstream os; - os << "expecting 18 bytes, read " << bytes << " from " << port().name(); + os << "expecting 18 bytes, read " << bytes << " from " << input_port().name(); throw MackieControlException( os.str() ); } @@ -169,7 +169,7 @@ MidiByteArray MackiePort::host_connection_confirmation( const MidiByteArray & by { finalise_init( false ); ostringstream os; - os << "expecting 14 bytes, read " << bytes << " from " << port().name(); + os << "expecting 14 bytes, read " << bytes << " from " << input_port().name(); throw MackieControlException( os.str() ); } @@ -273,7 +273,7 @@ void MackiePort::finalise_init( bool yn ) void MackiePort::connect_any() { if (!any_connection.connected()) { - port().input()->any.connect_same_thread (any_connection, boost::bind (&MackiePort::handle_midi_any, this, _1, _2, _3)); + input_port().parser()->any.connect_same_thread (any_connection, boost::bind (&MackiePort::handle_midi_any, this, _1, _2, _3)); } } diff --git a/libs/surfaces/mackie/mackie_port.h b/libs/surfaces/mackie/mackie_port.h index 292fc2ac13..65dcf850b1 100644 --- a/libs/surfaces/mackie/mackie_port.h +++ b/libs/surfaces/mackie/mackie_port.h @@ -43,7 +43,7 @@ public: enum port_type_t { mcu, ext }; enum emulation_t { none, mackie, bcf2000 }; - MackiePort( MackieControlProtocol & mcp, MIDI::Port & port, int number, port_type_t = mcu ); + MackiePort (MackieControlProtocol & mcp, MIDI::Port & input_port, MIDI::Port & output_port, int number, port_type_t = mcu); ~MackiePort(); virtual void open(); diff --git a/libs/surfaces/mackie/surface_port.cc b/libs/surfaces/mackie/surface_port.cc index 9dd456157e..994fdfd50a 100644 --- a/libs/surfaces/mackie/surface_port.cc +++ b/libs/surfaces/mackie/surface_port.cc @@ -36,12 +36,12 @@ using namespace std; using namespace Mackie; SurfacePort::SurfacePort() -: _port( 0 ), _number( 0 ), _active( false ) + : _input_port (0), _output_port (0), _number (0), _active (false) { } -SurfacePort::SurfacePort( MIDI::Port & port, int number ) -: _port( &port ), _number( number ), _active( false ) +SurfacePort::SurfacePort (MIDI::Port & input_port, MIDI::Port & output_port, int number) + : _input_port (&input_port), _output_port (&output_port), _number (number), _active (false) { } @@ -90,7 +90,7 @@ MidiByteArray SurfacePort::read() #endif // read port and copy to return value - int nread = port().read( buf, sizeof (buf) ); + int nread = input_port().read( buf, sizeof (buf) ); if (nread >= 0) { retval.copy( nread, buf ); @@ -107,7 +107,7 @@ MidiByteArray SurfacePort::read() if ( errno != EAGAIN ) { ostringstream os; - os << "Surface: error reading from port: " << port().name(); + os << "Surface: error reading from port: " << input_port().name(); os << ": " << errno << fetch_errmsg( errno ); cout << os.str() << endl; @@ -134,17 +134,17 @@ void SurfacePort::write( const MidiByteArray & mba ) Glib::RecMutex::Lock lock( _rwlock ); if ( !active() ) return; - int count = port().write( mba.bytes().get(), mba.size(), 0); + int count = output_port().write( mba.bytes().get(), mba.size(), 0); if ( count != (int)mba.size() ) { if ( errno == 0 ) { - cout << "port overflow on " << port().name() << ". Did not write all of " << mba << endl; + cout << "port overflow on " << output_port().name() << ". Did not write all of " << mba << endl; } else if ( errno != EAGAIN ) { ostringstream os; - os << "Surface: couldn't write to port " << port().name(); + os << "Surface: couldn't write to port " << output_port().name(); os << ", error: " << fetch_errmsg( errno ) << "(" << errno << ")"; cout << os.str() << endl; @@ -173,7 +173,7 @@ void SurfacePort::write_sysex( MIDI::byte msg ) ostream & Mackie::operator << ( ostream & os, const SurfacePort & port ) { os << "{ "; - os << "name: " << port.port().name(); + os << "name: " << port.input_port().name() << " " << port.output_port().name(); os << "; "; os << " }"; return os; diff --git a/libs/surfaces/mackie/surface_port.h b/libs/surfaces/mackie/surface_port.h index 86ec8ffd9e..214c8e6291 100644 --- a/libs/surfaces/mackie/surface_port.h +++ b/libs/surfaces/mackie/surface_port.h @@ -37,7 +37,7 @@ namespace Mackie class SurfacePort { public: - SurfacePort( MIDI::Port & port, int number ); + SurfacePort (MIDI::Port & input_port, MIDI::Port & output_port, int number); virtual ~SurfacePort(); // when this is successful, active() should return true @@ -60,8 +60,10 @@ public: /// return the correct sysex header for this port virtual const MidiByteArray & sysex_hdr() const = 0; - MIDI::Port & port() { return *_port; } - const MIDI::Port & port() const { return *_port; } + MIDI::Port & input_port() { return *_input_port; } + const MIDI::Port & input_port() const { return *_input_port; } + MIDI::Port & output_port() { return *_output_port; } + const MIDI::Port & output_port() const { return *_output_port; } // all control notofications are sent from here PBD::Signal3<void,SurfacePort &, Control &, const ControlState &> control_event; @@ -90,7 +92,8 @@ protected: SurfacePort(); private: - MIDI::Port * _port; + MIDI::Port * _input_port; + MIDI::Port * _output_port; int _number; bool _active; |