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