Use a timeout to reset faders' in_use flags when in BCF mode (ie with faders that...
[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 <glibmm/thread.h>
22
23 #include "pbd/signals.h"
24 #include "midi_byte_array.h"
25 #include "types.h"
26
27 namespace MIDI {
28         class Port;
29 }
30
31 namespace Mackie
32 {
33
34 /**
35         Make a relationship between a midi port and a Mackie device.
36 */
37 class SurfacePort
38 {
39 public:
40         SurfacePort (MIDI::Port & input_port, MIDI::Port & output_port, int number);
41         virtual ~SurfacePort();
42         
43         // when this is successful, active() should return true
44         virtual void open() = 0;
45         
46         // subclasses should call this before doing their own close
47         virtual void close() = 0;
48
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();
52         
53         /// an easier way to output bytes via midi
54         virtual void write( const MidiByteArray & );
55         
56         /// write a sysex message
57         void write_sysex( const MidiByteArray & mba );
58         void write_sysex( MIDI::byte msg );
59
60         /// return the correct sysex header for this port
61         virtual const MidiByteArray & sysex_hdr() const = 0;
62
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; }
67         
68         // all control notofications are sent from here
69         PBD::Signal3<void,SurfacePort &, Control &, const ControlState &> control_event;
70         
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;
74         
75         // emitted when the port completes initialisation successfully
76         PBD::Signal0<void> active_event;
77
78         // emitted when the port goes inactive (ie a read or write failed)
79         PBD::Signal0<void> inactive_event;
80         
81         // the port number - master is 0(extenders are 1((,4
82         virtual int number() const { return _number; }
83         
84         // number of strips handled by this port. Usually 8.
85         virtual int strips() const = 0;
86
87         virtual bool active() const { return _active; }
88         virtual void active( bool yn ) { _active = yn; }
89
90         void add_in_use_timeout (Control &, Control *);
91         
92 protected:
93         /// Only for use by DummyPort
94         SurfacePort();
95         
96 private:
97         bool control_in_use_timeout (Control *, Control *);
98
99         MIDI::Port * _input_port;
100         MIDI::Port * _output_port;
101         int _number;
102         bool _active;
103
104         Glib::RecMutex _rwlock;
105 };      
106
107 std::ostream & operator << ( std::ostream & , const SurfacePort & port );
108
109 }
110
111 #endif