Merge remote-tracking branch 'remotes/origin/cairocanvas' into windows
[ardour.git] / libs / surfaces / control_protocol / control_protocol / control_protocol.h
1 /*
2     Copyright (C) 2006 Paul Davis 
3
4     This program is free software; you can redistribute it
5     and/or modify it under the terms of the GNU Lesser
6     General Public License as published by the Free Software
7     Foundation; either version 2 of the License, or (at your
8     option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef ardour_control_protocols_h
22 #define ardour_control_protocols_h
23
24 #include <string>
25 #include <vector>
26 #include <list>
27
28 #include <boost/shared_ptr.hpp>
29
30 #include "pbd/stateful.h"
31 #include "pbd/signals.h"
32
33 #include "control_protocol/basic_ui.h"
34 #include "control_protocol/types.h"
35
36 #ifdef ARDOURSURFACE_DLL_EXPORTS // defined if we are building the ARDOUR surface DLLs (instead of using them)
37     #define ARDOURSURFACE_API LIBARDOUR_HELPER_DLL_EXPORT
38 #else
39     #define ARDOURSURFACE_API LIBARDOUR_HELPER_DLL_IMPORT
40 #endif 
41 #define ARDOURSURFACE_LOCAL LIBARDOUR_HELPER_DLL_LOCAL
42
43 namespace ARDOUR {
44
45 class Route;
46 class Session;
47 class Bundle;
48
49 class ARDOURCP_API ControlProtocol : public PBD::Stateful, public PBD::ScopedConnectionList, public BasicUI
50 {
51   public:
52         ControlProtocol (Session&, std::string name);
53         virtual ~ControlProtocol();
54
55         std::string name() const { return _name; }
56
57         virtual int set_active (bool yn) = 0;
58         bool get_active() const { return _active; }
59
60         virtual int set_feedback (bool /*yn*/) { return 0; }
61         virtual bool get_feedback () const { return false; }
62
63         virtual void midi_connectivity_established () {}
64
65         PBD::Signal0<void> ActiveChanged;
66
67         /* signals that a control protocol can emit and other (presumably graphical)
68            user interfaces can respond to
69         */
70
71         static PBD::Signal0<void> ZoomToSession;
72         static PBD::Signal0<void> ZoomIn;
73         static PBD::Signal0<void> ZoomOut;
74         static PBD::Signal0<void> Enter;
75         static PBD::Signal0<void> Undo;
76         static PBD::Signal0<void> Redo;
77         static PBD::Signal1<void,float> ScrollTimeline;
78         static PBD::Signal1<void,uint32_t> GotoView;
79         static PBD::Signal0<void> CloseDialog;
80         static PBD::Signal0<void> VerticalZoomInAll;
81         static PBD::Signal0<void> VerticalZoomOutAll;
82         static PBD::Signal0<void> VerticalZoomInSelected;
83         static PBD::Signal0<void> VerticalZoomOutSelected;
84         static PBD::Signal0<void> StepTracksDown;
85         static PBD::Signal0<void> StepTracksUp;
86
87         static PBD::Signal1<void,uint32_t> AddRouteToSelection;
88         static PBD::Signal1<void,uint32_t> SetRouteSelection;
89         static PBD::Signal1<void,uint32_t> ToggleRouteSelection;
90         static PBD::Signal1<void,uint32_t> RemoveRouteFromSelection;
91         static PBD::Signal0<void>          ClearRouteSelection;
92
93         /* signals that one UI (e.g. the GUI) can emit to get all other UI's to 
94            respond. Typically this will always be GUI->"others" - the GUI pays
95            no attention to these signals.
96         */
97         
98         static PBD::Signal1<void,RouteNotificationListPtr> TrackSelectionChanged;
99
100         /* the model here is as follows:
101
102            we imagine most control surfaces being able to control
103            from 1 to N tracks at a time, with a session that may
104            contain 1 to M tracks, where M may be smaller, larger or
105            equal to N. 
106
107            the control surface has a fixed set of physical controllers
108            which can potentially be mapped onto different tracks/busses
109            via some mechanism.
110
111            therefore, the control protocol object maintains
112            a table that reflects the current mapping between
113            the controls and route object.
114         */
115
116         void set_route_table_size (uint32_t size);
117         void set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route>);
118         bool set_route_table (uint32_t table_index, uint32_t remote_control_id);
119
120         void route_set_rec_enable (uint32_t table_index, bool yn);
121         bool route_get_rec_enable (uint32_t table_index);
122
123         float route_get_gain (uint32_t table_index);
124         void route_set_gain (uint32_t table_index, float);
125         float route_get_effective_gain (uint32_t table_index);
126
127         float route_get_peak_input_power (uint32_t table_index, uint32_t which_input);
128
129         bool route_get_muted (uint32_t table_index);
130         void route_set_muted (uint32_t table_index, bool);
131
132         bool route_get_soloed (uint32_t table_index);
133         void route_set_soloed (uint32_t table_index, bool);
134
135         std::string route_get_name (uint32_t table_index);
136
137         virtual std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
138
139         virtual bool  has_editor () const { return false; }
140         virtual void* get_gui() const { return 0; }
141         virtual void  tear_down_gui() { }
142
143   protected:
144         std::vector<boost::shared_ptr<ARDOUR::Route> > route_table;
145         std::string _name;
146         bool _active;
147
148         void next_track (uint32_t initial_id);
149         void prev_track (uint32_t initial_id);
150
151   private:
152         ARDOURSURFACE_LOCAL ControlProtocol (const ControlProtocol&); /* noncopyable */
153 };
154
155 extern "C" {
156         class ControlProtocolDescriptor {
157         public:
158             const char* name;      /* descriptive */
159             const char* id;        /* unique and version-specific */
160             void*       ptr;       /* protocol can store a value here */
161             void*       module;    /* not for public access */
162             int         mandatory; /* if non-zero, always load and do not make optional */
163             bool        supports_feedback; /* if true, protocol has toggleable feedback mechanism */
164             bool             (*probe)(ControlProtocolDescriptor*);
165             ControlProtocol* (*initialize)(ControlProtocolDescriptor*,Session*);
166             void             (*destroy)(ControlProtocolDescriptor*,ControlProtocol*);
167             
168         };
169 }
170
171 }
172
173 #endif // ardour_control_protocols_h