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