2 Copyright (C) 2006,2007 John Anderson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #ifndef surface_port_h
19 #define surface_port_h
21 #include <glibmm/thread.h>
23 #include "pbd/signals.h"
24 #include "midi_byte_array.h"
35 Make a relationship between a midi port and a Mackie device.
40 SurfacePort (MIDI::Port & input_port, MIDI::Port & output_port, int number);
41 virtual ~SurfacePort();
43 // when this is successful, active() should return true
44 virtual void open() = 0;
46 // subclasses should call this before doing their own close
47 virtual void close() = 0;
49 /// read bytes from the port. They'll either end up in the
50 /// parser, or if that's not active they'll be returned
51 virtual MidiByteArray read();
53 /// an easier way to output bytes via midi
54 virtual void write( const MidiByteArray & );
56 /// write a sysex message
57 void write_sysex( const MidiByteArray & mba );
58 void write_sysex( MIDI::byte msg );
60 /// return the correct sysex header for this port
61 virtual const MidiByteArray & sysex_hdr() const = 0;
63 MIDI::Port & input_port() { return *_input_port; }
64 const MIDI::Port & input_port() const { return *_input_port; }
65 MIDI::Port & output_port() { return *_output_port; }
66 const MIDI::Port & output_port() const { return *_output_port; }
68 // all control notofications are sent from here
69 PBD::Signal3<void,SurfacePort &, Control &, const ControlState &> control_event;
71 // emitted just before the port goes into initialisation
72 // where it tries to establish that its device is connected
73 PBD::Signal0<void> init_event;
75 // emitted when the port completes initialisation successfully
76 PBD::Signal0<void> active_event;
78 // emitted when the port goes inactive (ie a read or write failed)
79 PBD::Signal0<void> inactive_event;
81 // the port number - master is 0(extenders are 1((,4
82 virtual int number() const { return _number; }
84 // number of strips handled by this port. Usually 8.
85 virtual int strips() const = 0;
87 virtual bool active() const { return _active; }
88 virtual void active( bool yn ) { _active = yn; }
90 void add_in_use_timeout (Control &, Control *);
93 /// Only for use by DummyPort
97 bool control_in_use_timeout (Control *, Control *);
99 MIDI::Port * _input_port;
100 MIDI::Port * _output_port;
104 Glib::RecMutex _rwlock;
107 std::ostream & operator << ( std::ostream & , const SurfacePort & port );