Ardour  8.7-11-g2d99ff9703
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  PBD::Signal0<void> ActiveChanged;
65 
66  /* signals that a control protocol can emit and other (presumably graphical)
67  * user interfaces can respond to
68  */
69 
70  static PBD::Signal0<void> ZoomToSession;
71  static PBD::Signal0<void> ZoomIn;
72  static PBD::Signal0<void> ZoomOut;
73  static PBD::Signal0<void> Enter;
74  static PBD::Signal0<void> Undo;
75  static PBD::Signal0<void> Redo;
76  static PBD::Signal1<void, float> ScrollTimeline;
77  static PBD::Signal1<void, uint32_t> GotoView;
78  static PBD::Signal0<void> CloseDialog;
79  static PBD::Signal0<void> VerticalZoomInAll;
80  static PBD::Signal0<void> VerticalZoomOutAll;
81  static PBD::Signal0<void> VerticalZoomInSelected;
82  static PBD::Signal0<void> VerticalZoomOutSelected;
83  static PBD::Signal0<void> StepTracksDown;
84  static PBD::Signal0<void> StepTracksUp;
85  static PBD::Signal1<void, std::weak_ptr<ARDOUR::PluginInsert> > PluginSelected;
86 
87  void add_stripable_to_selection (std::shared_ptr<ARDOUR::Stripable>);
88  void set_stripable_selection (std::shared_ptr<ARDOUR::Stripable>);
89  void toggle_stripable_selection (std::shared_ptr<ARDOUR::Stripable>);
90  void remove_stripable_from_selection (std::shared_ptr<ARDOUR::Stripable>);
92 
93  virtual void add_rid_to_selection (int rid);
94  virtual void set_rid_selection (int rid);
95  virtual void toggle_rid_selection (int rid);
96  virtual void remove_rid_from_selection (int rid);
97 
98  std::shared_ptr<ARDOUR::Stripable> first_selected_stripable () const;
99 
100  /* the model here is as follows:
101 
102  we imagine most control surfaces being able to control
103  from 1 to N tracks at a time, with a session that may
104  contain 1 to M tracks, where M may be smaller, larger or
105  equal to N.
106 
107  the control surface has a fixed set of physical controllers
108  which can potentially be mapped onto different tracks/busses
109  via some mechanism.
110 
111  therefore, the control protocol object maintains
112  a table that reflects the current mapping between
113  the controls and route object.
114  */
115 
116  void set_route_table_size (uint32_t size);
117  void set_route_table (uint32_t table_index, std::shared_ptr<ARDOUR::Route>);
118  bool set_route_table (uint32_t table_index, uint32_t remote_control_id);
119 
120  void route_set_rec_enable (uint32_t table_index, bool yn);
121  bool route_get_rec_enable (uint32_t table_index);
122 
123  float route_get_gain (uint32_t table_index);
124  void route_set_gain (uint32_t table_index, float);
125  float route_get_effective_gain (uint32_t table_index);
126 
127  float route_get_peak_input_power (uint32_t table_index, uint32_t which_input);
128 
129  bool route_get_muted (uint32_t table_index);
130  void route_set_muted (uint32_t table_index, bool);
131 
132  bool route_get_soloed (uint32_t table_index);
133  void route_set_soloed (uint32_t table_index, bool);
134 
135  std::string route_get_name (uint32_t table_index);
136 
137  virtual std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
138 
139  virtual bool has_editor () const { return false; }
140  virtual void* get_gui () const { return 0; }
141  virtual void tear_down_gui () {}
142 
143  XMLNode& get_state () const;
144  int set_state (XMLNode const&, int version);
145 
146  static const std::string state_node_name;
147 
148  static StripableNotificationList const& last_selected () { return _last_selected; }
150 
151 protected:
152  void next_track (uint32_t initial_id);
153  void prev_track (uint32_t initial_id);
154 
155  std::vector<std::shared_ptr<ARDOUR::Route> > route_table;
156  std::string _name;
158  virtual void event_loop_precall ();
159  void install_precall_handler (Glib::RefPtr<Glib::MainContext>);
160 
161 private:
163 
164  bool _active;
165 
168  static bool selection_connected;
169 };
170 
171 extern "C" {
173 {
174 public:
175  const char* name; /* descriptive */
176  const char* id; /* unique and version-specific */
177  void* module; /* not for public access */
178  bool (*available) (); /* called directly after loading module */
179  bool (*probe_port) (); /* called when ports change (PortRegisteredOrUnregistered) */
180  bool (*match_usb) (uint16_t, uint16_t); /* called when USB devices are hotplugged (libusb) */
181  ControlProtocol* (*initialize) (Session*);
183 };
184 }
185 }
186 
187 /* this is where the strange inheritance pattern hits the wall. A control
188  protocol thread/event loop is inherited from AbstractUI, but the precall
189  handler is inherited from ControlProtocol. When the AbstractUI sets up the
190  event loop, it will call attach_request_source() which will in turn pass a
191  Glib::MainContext to maybe_install_precall_handler(). We override the
192  definition of that method here to make it actuall install the
193  ControlProtocol's handler.
194 */
195 
196 #define CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL() \
197  void maybe_install_precall_handler (Glib::RefPtr<Glib::MainContext> ctxt) { install_precall_handler (ctxt); }
198 
199 
200 #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
PBD::Signal0< void > ActiveChanged
static PBD::Signal0< void > VerticalZoomOutAll
std::shared_ptr< ARDOUR::Stripable > first_selected_stripable() const
virtual void * get_gui() const
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)
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::Signal0< void > ZoomIn
bool route_get_soloed(uint32_t table_index)
static PBD::Signal0< void > ZoomOut
static PBD::Signal0< void > Redo
static PBD::Signal0< void > Undo
static PBD::Signal1< void, std::weak_ptr< ARDOUR::PluginInsert > > PluginSelected
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)
static PBD::Signal0< void > StepTracksDown
static PBD::Signal1< void, float > ScrollTimeline
GlibEventLoopCallback glib_event_callback
void route_set_soloed(uint32_t table_index, bool)
LIBCONTROLCP_LOCAL ControlProtocol(const ControlProtocol &)
ControlProtocol(Session &, std::string name)
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)
static PBD::Signal0< void > CloseDialog
void add_stripable_to_selection(std::shared_ptr< ARDOUR::Stripable >)
static PBD::Signal0< void > VerticalZoomInAll
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::Signal0< void > VerticalZoomOutSelected
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)
virtual int set_feedback(bool)
virtual std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
virtual void stripable_selection_changed()=0
static PBD::Signal0< void > StepTracksUp
static PBD::ScopedConnection selection_connection
static PBD::Signal0< void > ZoomToSession
static const std::string state_node_name
static PBD::Signal1< void, uint32_t > GotoView
void route_set_muted(uint32_t table_index, bool)
static PBD::Signal0< void > VerticalZoomInSelected
void set_route_table(uint32_t table_index, std::shared_ptr< ARDOUR::Route >)
static PBD::Signal0< void > Enter
void next_track(uint32_t initial_id)
virtual std::string name() const
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
std::vector< std::weak_ptr< ARDOUR::Stripable > > StripableNotificationList
std::shared_ptr< StripableNotificationList > StripableNotificationListPtr