Ardour  9.10
control_protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
3  * Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013-2017 John Emmas <john@creativepost.co.uk>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #ifndef ardour_control_protocols_h
23 #define ardour_control_protocols_h
24 
25 #include <list>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 
30 #include "pbd/signals.h"
31 #include "pbd/stateful.h"
32 #include "pbd/glib_event_source.h"
33 
35 #include "control_protocol/types.h"
37 
38 namespace ARDOUR {
39 
40 class Route;
41 class Session;
42 class Bundle;
43 class Stripable;
44 class PluginInsert;
45 
47 {
48 public:
49  ControlProtocol (Session&, std::string name);
50  virtual ~ControlProtocol ();
51 
52  virtual std::string name () const { return _name; }
53 
54  virtual int set_active (bool yn);
55  virtual bool active () const { return _active; }
56 
57  virtual int set_feedback (bool /*yn*/) { return 0; }
58  virtual bool get_feedback () const { return false; }
59 
60  virtual void midi_connectivity_established (bool) {}
61 
62  virtual void stripable_selection_changed () = 0;
63 
64  /* This is not handled as a normal C++ virtual method because we want
65  * to be able to determine if a given ControlProtocol actually
66  * implements this (for cases where we should only call it once.
67  */
68 
69  typedef void (ControlProtocol::*SurfaceCallback) (ARDOUR::SurfaceCallbackType, void* arg);
70  SurfaceCallback surface_callback;
71 
73 
74  /* signals that a control protocol can emit and other (presumably graphical)
75  * user interfaces can respond to
76  */
77 
78  static PBD::Signal<void()> ZoomToSession;
79  static PBD::Signal<void()> ZoomIn;
80  static PBD::Signal<void()> ZoomOut;
81  static PBD::Signal<void()> Enter;
82  static PBD::Signal<void()> Undo;
83  static PBD::Signal<void()> Redo;
84  static PBD::Signal<void(float)> ScrollTimeline;
85  static PBD::Signal<void(uint32_t)> GotoView;
86  static PBD::Signal<void()> CloseDialog;
91  static PBD::Signal<void()> StepTracksDown;
92  static PBD::Signal<void()> StepTracksUp;
93  static PBD::Signal<void(std::weak_ptr<ARDOUR::PluginInsert> )> PluginSelected;
94 
95  void add_stripable_to_selection (std::shared_ptr<ARDOUR::Stripable>);
96  void set_stripable_selection (std::shared_ptr<ARDOUR::Stripable>);
97  void toggle_stripable_selection (std::shared_ptr<ARDOUR::Stripable>);
98  void remove_stripable_from_selection (std::shared_ptr<ARDOUR::Stripable>);
100 
101  virtual void add_rid_to_selection (int rid);
102  virtual void set_rid_selection (int rid);
103  virtual void toggle_rid_selection (int rid);
104  virtual void remove_rid_from_selection (int rid);
105 
106  std::shared_ptr<ARDOUR::Stripable> first_selected_stripable () const;
107 
108  /* the model here is as follows:
109 
110  we imagine most control surfaces being able to control
111  from 1 to N tracks at a time, with a session that may
112  contain 1 to M tracks, where M may be smaller, larger or
113  equal to N.
114 
115  the control surface has a fixed set of physical controllers
116  which can potentially be mapped onto different tracks/busses
117  via some mechanism.
118 
119  therefore, the control protocol object maintains
120  a table that reflects the current mapping between
121  the controls and route object.
122  */
123 
124  void set_route_table_size (uint32_t size);
125  void set_route_table (uint32_t table_index, std::shared_ptr<ARDOUR::Route>);
126  bool set_route_table (uint32_t table_index, uint32_t remote_control_id);
127 
128  void route_set_rec_enable (uint32_t table_index, bool yn);
129  bool route_get_rec_enable (uint32_t table_index);
130 
131  float route_get_gain (uint32_t table_index);
132  void route_set_gain (uint32_t table_index, float);
133  float route_get_effective_gain (uint32_t table_index);
134 
135  float route_get_peak_input_power (uint32_t table_index, uint32_t which_input);
136 
137  bool route_get_muted (uint32_t table_index);
138  void route_set_muted (uint32_t table_index, bool);
139 
140  bool route_get_soloed (uint32_t table_index);
141  void route_set_soloed (uint32_t table_index, bool);
142 
143  std::string route_get_name (uint32_t table_index);
144 
145  virtual std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
146 
147  virtual bool has_editor () const { return false; }
148  virtual void* get_gui () const { return 0; }
149  virtual void tear_down_gui () {}
150 
151  XMLNode& get_state () const;
152  int set_state (XMLNode const&, int version);
153 
154  static const std::string state_node_name;
155 
156  static StripableNotificationList const& last_selected () { return _last_selected; }
158 
159 protected:
160  void next_track (uint32_t initial_id);
161  void prev_track (uint32_t initial_id);
162 
163  std::vector<std::shared_ptr<ARDOUR::Route> > route_table;
164  std::string _name;
166  virtual void event_loop_precall ();
167  void install_precall_handler (Glib::RefPtr<Glib::MainContext>);
168 
169 private:
171 
172  bool _active;
173 
176  static bool selection_connected;
177 };
178 
179 extern "C" {
181 {
182 public:
183  const char* name; /* descriptive */
184  const char* id; /* unique and version-specific */
185  void* module; /* not for public access */
186  bool (*available) (); /* called directly after loading module */
187  bool (*probe_port) (); /* called when ports change (PortRegisteredOrUnregistered) */
188  bool (*match_usb) (uint16_t, uint16_t); /* called when USB devices are hotplugged (libusb) */
189  ControlProtocol* (*initialize) (Session*, std::string const & config);
191  std::map<std::string, std::vector<std::string>> (*enumerate) ();
192 };
193 }
194 }
195 
196 /* this is where the strange inheritance pattern hits the wall. A control
197  protocol thread/event loop is inherited from AbstractUI, but the precall
198  handler is inherited from ControlProtocol. When the AbstractUI sets up the
199  event loop, it will call attach_request_source() which will in turn pass a
200  Glib::MainContext to maybe_install_precall_handler(). We override the
201  definition of that method here to make it actuall install the
202  ControlProtocol's handler.
203 */
204 
205 #define CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL() \
206  void maybe_install_precall_handler (Glib::RefPtr<Glib::MainContext> ctxt) { install_precall_handler (ctxt); }
207 
208 
209 #endif // ardour_control_protocols_h
void(* destroy)(ControlProtocol *)
bool(* match_usb)(uint16_t, uint16_t)
void install_precall_handler(Glib::RefPtr< Glib::MainContext >)
virtual bool has_editor() const
static PBD::Signal< void()> VerticalZoomInAll
std::shared_ptr< ARDOUR::Stripable > first_selected_stripable() const
static PBD::Signal< void()> Redo
virtual void * get_gui() const
SurfaceCallback surface_callback
virtual void add_rid_to_selection(int rid)
void prev_track(uint32_t initial_id)
bool route_get_muted(uint32_t table_index)
float route_get_effective_gain(uint32_t table_index)
void remove_stripable_from_selection(std::shared_ptr< ARDOUR::Stripable >)
float route_get_peak_input_power(uint32_t table_index, uint32_t which_input)
static PBD::Signal< void(float)> ScrollTimeline
bool route_get_rec_enable(uint32_t table_index)
void set_stripable_selection(std::shared_ptr< ARDOUR::Stripable >)
static StripableNotificationList const & last_selected()
virtual bool get_feedback() const
virtual void midi_connectivity_established(bool)
std::string route_get_name(uint32_t table_index)
static void notify_stripable_selection_changed(StripableNotificationListPtr)
static PBD::Signal< void()> ZoomToSession
static PBD::Signal< void()> Enter
bool route_get_soloed(uint32_t table_index)
static PBD::Signal< void()> StepTracksDown
static PBD::Signal< void()> VerticalZoomOutSelected
virtual void tear_down_gui()
void toggle_stripable_selection(std::shared_ptr< ARDOUR::Stripable >)
std::vector< std::shared_ptr< ARDOUR::Route > > route_table
int set_state(XMLNode const &, int version)
float route_get_gain(uint32_t table_index)
GlibEventLoopCallback glib_event_callback
static PBD::Signal< void()> CloseDialog
static PBD::Signal< void()> Undo
void route_set_soloed(uint32_t table_index, bool)
PBD::Signal< void()> ActiveChanged
LIBCONTROLCP_LOCAL ControlProtocol(const ControlProtocol &)
ControlProtocol(Session &, std::string name)
static PBD::Signal< void()> ZoomIn
static StripableNotificationList _last_selected
virtual void set_rid_selection(int rid)
virtual void remove_rid_from_selection(int rid)
virtual bool active() const
virtual int set_active(bool yn)
void add_stripable_to_selection(std::shared_ptr< ARDOUR::Stripable >)
virtual void toggle_rid_selection(int rid)
bool set_route_table(uint32_t table_index, uint32_t remote_control_id)
void set_route_table_size(uint32_t size)
static PBD::Signal< void(std::weak_ptr< ARDOUR::PluginInsert >)> PluginSelected
static PBD::Signal< void()> StepTracksUp
XMLNode & get_state() const
void route_set_rec_enable(uint32_t table_index, bool yn)
virtual void event_loop_precall()
void route_set_gain(uint32_t table_index, float)
static PBD::Signal< void()> VerticalZoomOutAll
virtual int set_feedback(bool)
virtual std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
virtual void stripable_selection_changed()=0
static PBD::ScopedConnection selection_connection
static PBD::Signal< void(uint32_t)> GotoView
static const std::string state_node_name
void route_set_muted(uint32_t table_index, bool)
void set_route_table(uint32_t table_index, std::shared_ptr< ARDOUR::Route >)
void next_track(uint32_t initial_id)
virtual std::string name() const
static PBD::Signal< void()> ZoomOut
static PBD::Signal< void()> VerticalZoomInSelected
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
std::vector< std::weak_ptr< ARDOUR::Stripable > > StripableNotificationList
std::shared_ptr< StripableNotificationList > StripableNotificationListPtr