Merge remote-tracking branch 'remotes/origin/exportvis' into windows+cc
[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/visibility.h"
34 #include "control_protocol/basic_ui.h"
35 #include "control_protocol/types.h"
36
37 #ifdef ARDOURSURFACE_DLL_EXPORTS // defined if we are building the ARDOUR surface DLLs (instead of using them)
38     #define ARDOURSURFACE_API LIBARDOUR_HELPER_DLL_EXPORT
39 #else
40     #define ARDOURSURFACE_API LIBARDOUR_HELPER_DLL_IMPORT
41 #endif 
42 #define ARDOURSURFACE_LOCAL LIBARDOUR_HELPER_DLL_LOCAL
43
44 namespace ARDOUR {
45
46 class Route;
47 class Session;
48 class Bundle;
49
50 class LIBCONTROLCP_API ControlProtocol : public PBD::Stateful, public PBD::ScopedConnectionList, public BasicUI
51 {
52   public:
53         ControlProtocol (Session&, std::string name);
54         virtual ~ControlProtocol();
55
56         std::string name() const { return _name; }
57
58         virtual int set_active (bool yn) = 0;
59         bool get_active() const { return _active; }
60
61         virtual int set_feedback (bool /*yn*/) { return 0; }
62         virtual bool get_feedback () const { return false; }
63
64         virtual void midi_connectivity_established () {}
65
66         PBD::Signal0<void> ActiveChanged;
67
68         /* signals that a control protocol can emit and other (presumably graphical)
69            user interfaces can respond to
70         */
71
72         static PBD::Signal0<void> ZoomToSession;
73         static PBD::Signal0<void> ZoomIn;
74         static PBD::Signal0<void> ZoomOut;
75         static PBD::Signal0<void> Enter;
76         static PBD::Signal0<void> Undo;
77         static PBD::Signal0<void> Redo;
78         static PBD::Signal1<void,float> ScrollTimeline;
79         static PBD::Signal1<void,uint32_t> GotoView;
80         static PBD::Signal0<void> CloseDialog;
81         static PBD::Signal0<void> VerticalZoomInAll;
82         static PBD::Signal0<void> VerticalZoomOutAll;
83         static PBD::Signal0<void> VerticalZoomInSelected;
84         static PBD::Signal0<void> VerticalZoomOutSelected;
85         static PBD::Signal0<void> StepTracksDown;
86         static PBD::Signal0<void> StepTracksUp;
87
88         static PBD::Signal1<void,uint32_t> AddRouteToSelection;
89         static PBD::Signal1<void,uint32_t> SetRouteSelection;
90         static PBD::Signal1<void,uint32_t> ToggleRouteSelection;
91         static PBD::Signal1<void,uint32_t> RemoveRouteFromSelection;
92         static PBD::Signal0<void>          ClearRouteSelection;
93
94         /* signals that one UI (e.g. the GUI) can emit to get all other UI's to 
95            respond. Typically this will always be GUI->"others" - the GUI pays
96            no attention to these signals.
97         */
98         
99         static PBD::Signal1<void,RouteNotificationListPtr> TrackSelectionChanged;
100
101         /* the model here is as follows:
102
103            we imagine most control surfaces being able to control
104            from 1 to N tracks at a time, with a session that may
105            contain 1 to M tracks, where M may be smaller, larger or
106            equal to N. 
107
108            the control surface has a fixed set of physical controllers
109            which can potentially be mapped onto different tracks/busses
110            via some mechanism.
111
112            therefore, the control protocol object maintains
113            a table that reflects the current mapping between
114            the controls and route object.
115         */
116
117         void set_route_table_size (uint32_t size);
118         void set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route>);
119         bool set_route_table (uint32_t table_index, uint32_t remote_control_id);
120
121         void route_set_rec_enable (uint32_t table_index, bool yn);
122         bool route_get_rec_enable (uint32_t table_index);
123
124         float route_get_gain (uint32_t table_index);
125         void route_set_gain (uint32_t table_index, float);
126         float route_get_effective_gain (uint32_t table_index);
127
128         float route_get_peak_input_power (uint32_t table_index, uint32_t which_input);
129
130         bool route_get_muted (uint32_t table_index);
131         void route_set_muted (uint32_t table_index, bool);
132
133         bool route_get_soloed (uint32_t table_index);
134         void route_set_soloed (uint32_t table_index, bool);
135
136         std::string route_get_name (uint32_t table_index);
137
138         virtual std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
139
140         virtual bool  has_editor () const { return false; }
141         virtual void* get_gui() const { return 0; }
142         virtual void  tear_down_gui() { }
143
144   protected:
145         std::vector<boost::shared_ptr<ARDOUR::Route> > route_table;
146         std::string _name;
147         bool _active;
148
149         void next_track (uint32_t initial_id);
150         void prev_track (uint32_t initial_id);
151
152   private:
153         ARDOURSURFACE_LOCAL ControlProtocol (const ControlProtocol&); /* noncopyable */
154 };
155
156 extern "C" {
157         class ControlProtocolDescriptor {
158         public:
159             const char* name;      /* descriptive */
160             const char* id;        /* unique and version-specific */
161             void*       ptr;       /* protocol can store a value here */
162             void*       module;    /* not for public access */
163             int         mandatory; /* if non-zero, always load and do not make optional */
164             bool        supports_feedback; /* if true, protocol has toggleable feedback mechanism */
165             bool             (*probe)(ControlProtocolDescriptor*);
166             ControlProtocol* (*initialize)(ControlProtocolDescriptor*,Session*);
167             void             (*destroy)(ControlProtocolDescriptor*,ControlProtocol*);
168             
169         };
170 }
171
172 }
173
174 #endif // ardour_control_protocols_h