59bfc66e7b726553f034aab547f74acd9bfad89a
[ardour.git] / libs / surfaces / mackie / route_signal.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 route_signal_h
19 #define route_signal_h
20
21 #include <vector>
22 #include <boost/shared_ptr.hpp>
23
24 #include "pbd/signals.h"
25
26 #include "midi_byte_array.h"
27
28 class MackieControlProtocol;
29
30 namespace ARDOUR {
31         class Route;
32 }
33         
34 namespace Mackie
35 {
36
37 class Strip;
38 class SurfacePort;
39
40 /**
41   This class is intended to easily create and destroy the set of
42   connections from a route to a control surface strip. Instantiating
43   it will connect the signals, and destructing it will disconnect
44   the signals.
45 */
46 class RouteSignal
47 {
48 public:
49         RouteSignal(boost::shared_ptr<ARDOUR::Route> route, MackieControlProtocol & mcp, Strip & strip, SurfacePort & port )
50         : _route( route ), _mcp( mcp ), _strip( strip ), _port( port ), _last_gain_written(0.0)
51         {
52                 connect();
53         }
54         
55         ~RouteSignal()
56         {
57                 disconnect();
58         }
59         
60         void connect();
61         void disconnect();
62         
63         // call all signal handlers manually
64         void notify_all();
65         
66         boost::shared_ptr<const ARDOUR::Route> route() const { return _route; }
67         Strip & strip() { return _strip; }
68         SurfacePort & port() { return _port; }
69         
70         float last_gain_written() const { return _last_gain_written; }
71         void last_gain_written( float other ) { _last_gain_written = other; }
72         
73         const MidiByteArray & last_pan_written() const { return _last_pan_written; }
74         void last_pan_written( const MidiByteArray & other ) { _last_pan_written = other; }
75         
76 private:
77         boost::shared_ptr<ARDOUR::Route> _route;
78         MackieControlProtocol & _mcp;
79         Strip & _strip;
80         SurfacePort & _port;
81
82         PBD::ScopedConnectionList connections;
83
84         // Last written values for the gain and pan, to avoid overloading
85         // the midi connection to the surface
86         float _last_gain_written;
87         MidiByteArray _last_pan_written;
88 };
89
90 }
91
92 #endif