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