c481d023212af08f181e1c1a7a9cd97471ff95ad
[ardour.git] / libs / surfaces / mackie / surface_port.h
1 /*
2         Copyright (C) 2006,2007 John Anderson
3
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.
8
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.
13
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.
17 */
18 #ifndef surface_port_h
19 #define surface_port_h
20
21 #include <sigc++/signal.h>
22
23 #include "midi_byte_array.h"
24 #include "types.h"
25
26 namespace MIDI {
27         class Port;
28 }
29
30 namespace Mackie
31 {
32
33 /**
34         Make a relationship between a midi port and a Mackie device.
35 */
36 class SurfacePort : public sigc::trackable
37 {
38 public:
39         SurfacePort( MIDI::Port & port, int number );
40         virtual ~SurfacePort() {}
41         
42         // when this is successful, active() should return true
43         virtual void open() = 0;
44         virtual void close() = 0;
45
46         /// read bytes from the port. They'll either end up in the
47         /// parser, or if that's not active they'll be returned
48         MidiByteArray read();
49         
50         /// an easier way to output bytes via midi
51         void write( const MidiByteArray & );
52         
53         /// write a sysex message
54         void write_sysex( const MidiByteArray & mba );
55         void write_sysex( MIDI::byte msg );
56
57         // return the correct sysex header for this port
58         virtual const MidiByteArray & sysex_hdr() const = 0;
59
60         MIDI::Port & port() { return _port; }
61         const MIDI::Port & port() const { return _port; }
62         
63         // all control notofications are sent from here
64         sigc::signal<void, SurfacePort &, Control &, const ControlState &> control_event;
65         
66         // emitted just before the port goes into initialisation
67         // where it tries to establish that its device is connected
68         sigc::signal<void> init_event;
69         
70         // emitted when the port completes initialisation successfully
71         sigc::signal<void> active_event;
72
73         // emitted when the port goes inactive (ie a read or write failed)
74         sigc::signal<void> inactive_event;
75         
76         // the port number - master is 0, extenders are 1,2,3,4
77         virtual int number() const { return _number; }
78         
79         // number of strips handled by this port. Usually 8.
80         virtual int strips() const = 0;
81
82         virtual bool active() const { return _active; }
83         virtual void active( bool yn ) { _active = yn; }
84         
85 private:
86         MIDI::Port & _port;
87         int _number;
88         bool _active;
89 };      
90
91 std::ostream & operator << ( std::ostream & , const SurfacePort & port );
92
93 }
94
95 #endif