Ardour  9.2-129-gdf5e1050bd
us2400_control_protocol.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18 
19 #ifndef ardour_us2400_control_protocol_h
20 #define ardour_us2400_control_protocol_h
21 
22 #include <vector>
23 #include <map>
24 #include <list>
25 #include <set>
26 
27 #include <pthread.h>
28 #define ABSTRACT_UI_EXPORTS
29 #include "pbd/abstract_ui.h"
30 #include "midi++/types.h"
31 #include "ardour/types.h"
33 
34 #include "types.h"
35 #include "midi_byte_array.h"
36 #include "controls.h"
37 #include "jog_wheel.h"
38 #include "timer.h"
39 #include "device_info.h"
40 #include "device_profile.h"
41 
42 namespace ARDOUR {
43  class AutomationControl;
44  class Port;
45 }
46 
47 namespace MIDI {
48  class Port;
49 }
50 
51 namespace ArdourSurface {
52 
53 namespace US2400 {
54  class Surface;
55  class Control;
56  class SurfacePort;
57  class Button;
58  class Strip;
59 }
60 
61 struct US2400ControlUIRequest : public BaseUI::BaseRequestObject {
62 public:
65 };
66 
69  , public AbstractUI<US2400ControlUIRequest>
70 {
71  public:
72  static const int MODIFIER_OPTION;
73  static const int MODIFIER_CONTROL;
74  static const int MODIFIER_SHIFT;
75  static const int MODIFIER_CMDALT;
76  static const int MODIFIER_ZOOM;
77  static const int MODIFIER_SCRUB;
78  static const int MODIFIER_MARKER;
79  static const int MODIFIER_DROP; //US2400 replaces MODIFIER_NUDGE which is unused
80  static const int MAIN_MODIFIER_MASK;
81 
82  enum ViewMode {
85  };
86 
87  enum SubViewMode {
90  };
91 
93  virtual ~US2400Protocol();
94 
95  static US2400Protocol* instance() { return _instance; }
96 
97  const US2400::DeviceInfo& device_info() const { return _device_info; }
99 
101  PBD::Signal<void(std::shared_ptr<US2400::Surface> )> ConnectionChange;
102 
103  void device_ready ();
104 
105  int set_active (bool yn);
106  int set_device (const std::string&, bool force);
107  void set_profile (const std::string&);
108 
109  ViewMode view_mode () const { return _view_mode; }
111  static bool subview_mode_would_be_ok (SubViewMode, std::shared_ptr<ARDOUR::Stripable>);
112  std::shared_ptr<ARDOUR::Stripable> subview_stripable() const;
113  bool zoom_mode () const { return modifier_state() & MODIFIER_ZOOM; }
114  bool metering_active () const { return _metering_active; }
115 
116  bool is_track (std::shared_ptr<ARDOUR::Stripable>) const;
117  bool is_audio_track (std::shared_ptr<ARDOUR::Stripable>) const;
118  bool is_midi_track (std::shared_ptr<ARDOUR::Stripable>) const;
119  bool is_mapped (std::shared_ptr<ARDOUR::Stripable>) const;
120  std::shared_ptr<ARDOUR::Stripable> first_selected_stripable () const;
121 
125 
127  int set_subview_mode (SubViewMode, std::shared_ptr<ARDOUR::Stripable>);
129 
130  XMLNode& get_state () const;
131  int set_state (const XMLNode&, int version);
132 
133  /* Note: because Mackie control is inherently a duplex protocol,
134  we do not implement get/set_feedback() since this aspect of
135  support for the protocol is not optional.
136  */
137 
139  typedef std::list<std::shared_ptr<US2400::Surface> > Surfaces;
141 
142  std::shared_ptr<US2400::Surface> get_surface_by_raw_pointer (void*) const;
143  std::shared_ptr<US2400::Surface> nth_surface (uint32_t) const;
144 
147 
148  std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
149 
150  void set_master_on_surface_strip (uint32_t surface, uint32_t strip);
151  void set_monitor_on_surface_strip (uint32_t surface, uint32_t strip);
152 
153  uint32_t n_strips (bool with_locked_strips = true) const;
154 
155  bool has_editor () const { return true; }
156  void* get_gui () const;
157  void tear_down_gui ();
158 
160 
165 
167 
171 
175 
176  // button-related signals
181  // mainly to pick up punch-in and punch-out
182  void notify_parameter_changed(std::string const &);
184 
188 
191 
194 
197 
198  int modifier_state() const { return _modifier_state; }
200 
201  typedef std::list<std::shared_ptr<ARDOUR::AutomationControl> > ControlList;
202 
203  void add_down_button (ARDOUR::AutomationType, int surface, int strip);
204  void remove_down_button (ARDOUR::AutomationType, int surface, int strip);
206 
207  void add_down_select_button (int surface, int strip);
208  void remove_down_select_button (int surface, int strip);
209  void select_range (uint32_t pressed);
210 
212 
214 
215  protected:
216  // shut down the surface
217  void close();
218 
219  // This sets up the notifications and sets the
220  // controls to the correct values
222 
223  // connects global (not strip) signals from the Session to here
224  // so the surface can be notified of changes from the other UIs.
226 
227  // set all controls to their zero position
228  void zero_all();
229 
234  typedef std::vector<std::shared_ptr<ARDOUR::Stripable> > Sorted;
236 
237  // bank switching
238  int switch_banks (uint32_t first_remote_id, bool force = false);
239  void prev_track ();
240  void next_track ();
241 
243  int stop ();
244 
245  void thread_init ();
246 
247  bool stripable_is_locked_to_strip (std::shared_ptr<ARDOUR::Stripable>) const;
248 
249  private:
250 
251  struct ButtonHandlers {
254 
257  : press (p)
258  , release (r) {}
259  };
260 
261  typedef std::map<US2400::Button::ID,ButtonHandlers> ButtonMap;
262 
264 
265  bool profile_exists (std::string const&) const;
266 
269  sigc::connection periodic_connection;
270  sigc::connection redisplay_connection;
271  sigc::connection hui_connection;
278  // timer for two quick marker left presses
280  // last written timecode string
281  std::string _timecode_last;
283  // Which timecode are we displaying? BBT or Timecode
285  // Bundle to represent our input ports
286  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
287  // Bundle to represent our output ports
288  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
289  void* _gui;
293  std::shared_ptr<ARDOUR::Stripable> _subview_stripable;
300  int _last_bank[9];
304 
305  std::shared_ptr<ArdourSurface::US2400::Surface> _master_surface;
306 
308  bool periodic();
309  bool redisplay();
311  bool hui_heartbeat ();
312  void build_gui ();
313  bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
314  void clear_ports ();
315  void clear_surfaces ();
316  void force_special_stripable_to_strip (std::shared_ptr<ARDOUR::Stripable> r, uint32_t surface, uint32_t strip_number);
319  void initialize ();
320  int set_device_info (const std::string& device_name);
322 
323  /* MIDI port connection management */
324 
326  void connection_handler (std::weak_ptr<ARDOUR::Port>, std::string name1, std::weak_ptr<ARDOUR::Port>, std::string name2, bool);
327 
328  /* BUTTON HANDLING */
329 
330  typedef std::set<uint32_t> DownButtonList;
331  typedef std::map<ARDOUR::AutomationType,DownButtonList> DownButtonMap;
334 
336 
337  /* implemented button handlers */
386 
401 // US2400::LedState F1_press (US2400::Button &);
402 // US2400::LedState F1_release (US2400::Button &);
403 // US2400::LedState F2_press (US2400::Button &);
404 // US2400::LedState F2_release (US2400::Button &);
405 // US2400::LedState F3_press (US2400::Button &);
406 // US2400::LedState F3_release (US2400::Button &);
407 // US2400::LedState F4_press (US2400::Button &);
408 // US2400::LedState F4_release (US2400::Button &);
409 // US2400::LedState F5_press (US2400::Button &);
410 // US2400::LedState F5_release (US2400::Button &);
411 // US2400::LedState F6_press (US2400::Button &);
412 // US2400::LedState F6_release (US2400::Button &);
413 // US2400::LedState F7_press (US2400::Button &);
414 // US2400::LedState F7_release (US2400::Button &);
415 // US2400::LedState F8_press (US2400::Button &);
416 // US2400::LedState F8_release (US2400::Button &);
431 
474 
476 };
477 
478 } // namespace
479 
480 #endif // ardour_us2400_control_protocol_h
void remove_down_select_button(int surface, int strip)
US2400::LedState read_press(US2400::Button &)
US2400::LedState enter_release(US2400::Button &)
bool is_midi_track(std::shared_ptr< ARDOUR::Stripable >) const
US2400::LedState enter_press(US2400::Button &)
US2400::LedState scrub_press(US2400::Button &)
std::shared_ptr< US2400::Surface > get_surface_by_raw_pointer(void *) const
void handle_button_event(US2400::Surface &, US2400::Button &button, US2400::ButtonState)
US2400::LedState send_press(US2400::Button &)
std::map< ARDOUR::AutomationType, DownButtonList > DownButtonMap
void update_led(US2400::Surface &, US2400::Button &button, US2400::LedState)
this is called to generate the midi to send in response to a button press.
US2400::LedState cursor_left_release(US2400::Button &)
US2400::LedState control_release(US2400::Button &)
US2400::LedState miditracks_press(US2400::Button &)
US2400::LedState eq_release(US2400::Button &)
US2400::LedState clearsolo_press(US2400::Button &)
US2400::LedState rewind_release(US2400::Button &button)
US2400::LedState stop_press(US2400::Button &)
US2400::LedState play_press(US2400::Button &)
US2400::LedState timecode_beats_press(US2400::Button &)
US2400::LedState right_press(US2400::Button &)
US2400::LedState outputs_press(US2400::Button &)
US2400::LedState audioinstruments_press(US2400::Button &)
US2400::LedState cursor_down_release(US2400::Button &)
US2400::LedState loop_release(US2400::Button &)
US2400::LedState undo_press(US2400::Button &)
US2400::LedState send_release(US2400::Button &)
US2400::LedState cursor_right_press(US2400::Button &)
US2400::LedState trim_press(US2400::Button &)
uint32_t n_strips(bool with_locked_strips=true) const
std::shared_ptr< ArdourSurface::US2400::Surface > _master_surface
void notify_routes_added(ARDOUR::RouteList &)
US2400::LedState flip_press(US2400::Button &)
US2400::LedState fader_touch_release(US2400::Button &)
US2400::LedState cancel_press(US2400::Button &)
US2400::LedState cancel_release(US2400::Button &)
void select_range(uint32_t pressed)
US2400::LedState mstr_release(US2400::Button &)
void force_special_stripable_to_strip(std::shared_ptr< ARDOUR::Stripable > r, uint32_t surface, uint32_t strip_number)
bool is_audio_track(std::shared_ptr< ARDOUR::Stripable >) const
US2400::LedState replace_press(US2400::Button &)
std::vector< std::shared_ptr< ARDOUR::Stripable > > Sorted
US2400::LedState zoom_press(US2400::Button &)
PBD::ScopedConnectionList subview_stripable_connections
US2400::LedState latch_press(US2400::Button &)
US2400::DeviceProfile & device_profile()
US2400::LedState marker_release(US2400::Button &)
US2400::LedState user_press(US2400::Button &)
US2400::LedState channel_left_release(US2400::Button &)
std::list< std::shared_ptr< US2400::Surface > > Surfaces
US2400::LedState cmd_alt_release(US2400::Button &)
US2400::LedState bank_release(US2400::Button &, uint32_t bank_num)
std::list< std::shared_ptr< ARDOUR::AutomationControl > > ControlList
void update_configuration_state() const
US2400::LedState aux_release(US2400::Button &)
std::shared_ptr< ARDOUR::Bundle > _output_bundle
void add_down_button(ARDOUR::AutomationType, int surface, int strip)
US2400::LedState outputs_release(US2400::Button &)
US2400::LedState fader_touch_press(US2400::Button &)
void do_request(US2400ControlUIRequest *)
static US2400Protocol * instance()
void notify_parameter_changed(std::string const &)
bool midi_input_handler(Glib::IOCondition ioc, MIDI::Port *port)
US2400::LedState dyn_press(US2400::Button &)
bool is_mapped(std::shared_ptr< ARDOUR::Stripable >) const
US2400::LedState inputs_release(US2400::Button &)
int set_device_info(const std::string &device_name)
US2400::LedState play_release(US2400::Button &)
std::shared_ptr< ARDOUR::Stripable > first_selected_stripable() const
US2400::LedState option_release(US2400::Button &)
US2400::LedState plugin_press(US2400::Button &)
US2400::LedState pan_press(US2400::Button &)
US2400::LedState record_press(US2400::Button &)
PBD::Signal< void(std::shared_ptr< US2400::Surface >)> ConnectionChange
US2400::LedState loop_press(US2400::Button &)
US2400::LedState audiotracks_press(US2400::Button &)
US2400::LedState stop_release(US2400::Button &)
US2400::LedState channel_right_press(US2400::Button &)
US2400::LedState drop_press(US2400::Button &)
US2400::LedState grp_press(US2400::Button &)
std::shared_ptr< ARDOUR::Stripable > _subview_stripable
US2400::LedState drop_release(US2400::Button &)
US2400::LedState dyn_release(US2400::Button &)
US2400::LedState audioinstruments_release(US2400::Button &)
US2400::LedState trim_release(US2400::Button &)
const US2400::DeviceInfo & device_info() const
US2400::LedState write_release(US2400::Button &)
int set_device(const std::string &, bool force)
US2400::LedState user_b_press(US2400::Button &)
US2400Protocol(ARDOUR::Session &)
US2400::LedState master_fader_touch_release(US2400::Button &)
US2400::LedState left_release(US2400::Button &)
US2400::LedState clearsolo_release(US2400::Button &)
void connection_handler(std::weak_ptr< ARDOUR::Port >, std::string name1, std::weak_ptr< ARDOUR::Port >, std::string name2, bool)
int set_subview_mode(SubViewMode, std::shared_ptr< ARDOUR::Stripable >)
US2400::LedState busses_release(US2400::Button &)
US2400::LedState channel_right_release(US2400::Button &)
void set_automation_state(ARDOUR::AutoState)
PBD::ScopedConnectionList audio_engine_connections
int set_state(const XMLNode &, int version)
US2400::LedState rewind_press(US2400::Button &button)
US2400::LedState undo_release(US2400::Button &)
US2400::LedState shift_press(US2400::Button &)
samplepos_t transport_sample() const
void set_monitor_on_surface_strip(uint32_t surface, uint32_t strip)
std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
void notify_presentation_info_changed(PBD::PropertyChange const &)
std::shared_ptr< US2400::Surface > nth_surface(uint32_t) const
US2400::LedState grp_release(US2400::Button &)
US2400::LedState control_press(US2400::Button &)
US2400::LedState name_value_release(US2400::Button &)
US2400::LedState nudge_release(US2400::Button &)
US2400::LedState cursor_left_press(US2400::Button &)
US2400::LedState track_press(US2400::Button &)
US2400::LedState record_release(US2400::Button &)
void update_global_led(int id, US2400::LedState)
US2400::LedState cursor_down_press(US2400::Button &)
US2400::LedState marker_press(US2400::Button &)
US2400::LedState touch_press(US2400::Button &)
US2400::LedState cmd_alt_press(US2400::Button &)
US2400::LedState cursor_up_press(US2400::Button &)
int switch_banks(uint32_t first_remote_id, bool force=false)
US2400::LedState pan_release(US2400::Button &)
US2400::LedState plugin_release(US2400::Button &)
bool profile_exists(std::string const &) const
US2400::LedState flip_release(US2400::Button &)
US2400::LedState master_fader_touch_press(US2400::Button &)
US2400::LedState click_release(US2400::Button &)
US2400::LedState audiotracks_release(US2400::Button &)
US2400::LedState option_press(US2400::Button &)
void set_master_on_surface_strip(uint32_t surface, uint32_t strip)
US2400::LedState busses_press(US2400::Button &)
US2400::LedState latch_release(US2400::Button &)
US2400::LedState miditracks_release(US2400::Button &)
std::shared_ptr< ARDOUR::Bundle > _input_bundle
void pull_stripable_range(DownButtonList &, ARDOUR::StripableList &, uint32_t pressed)
PBD::ScopedConnectionList stripable_connections
US2400::LedState user_a_release(US2400::Button &)
void remove_down_button(ARDOUR::AutomationType, int surface, int strip)
US2400::LedState view_release(US2400::Button &)
US2400::LedState user_release(US2400::Button &)
US2400::LedState shift_release(US2400::Button &)
bool stripable_is_locked_to_strip(std::shared_ptr< ARDOUR::Stripable >) const
std::map< US2400::Button::ID, ButtonHandlers > ButtonMap
US2400::LedState user_a_press(US2400::Button &)
XMLNode & get_state() const
US2400::LedState click_press(US2400::Button &)
US2400::LedState touch_release(US2400::Button &)
US2400::LedState zoom_release(US2400::Button &)
PBD::ScopedConnectionList session_connections
US2400::LedState user_b_release(US2400::Button &)
US2400::LedState cursor_up_release(US2400::Button &)
US2400::LedState scrub_release(US2400::Button &)
US2400::LedState ffwd_press(US2400::Button &button)
US2400::LedState aux_press(US2400::Button &)
US2400::LedState read_release(US2400::Button &)
US2400::LedState save_release(US2400::Button &)
uint32_t global_index_locked(US2400::Strip &)
US2400::LedState left_press(US2400::Button &)
US2400::LedState view_press(US2400::Button &)
void set_profile(const std::string &)
US2400::LedState write_press(US2400::Button &)
US2400::LedState inputs_press(US2400::Button &)
US2400::LedState timecode_beats_release(US2400::Button &)
PBD::ScopedConnectionList gui_connections
US2400::LedState track_release(US2400::Button &)
US2400::LedState replace_release(US2400::Button &)
void update_global_button(int id, US2400::LedState)
US2400::LedState nudge_press(US2400::Button &)
US2400::LedState eq_press(US2400::Button &)
US2400::LedState mstr_press(US2400::Button &)
ControlList down_controls(ARDOUR::AutomationType, uint32_t pressed)
US2400::LedState right_release(US2400::Button &)
static bool subview_mode_would_be_ok(SubViewMode, std::shared_ptr< ARDOUR::Stripable >)
void notify_vca_added(ARDOUR::VCAList &)
US2400::LedState channel_left_press(US2400::Button &)
US2400::LedState ffwd_release(US2400::Button &button)
US2400::LedState save_press(US2400::Button &)
bool is_track(std::shared_ptr< ARDOUR::Stripable >) const
uint32_t global_index(US2400::Strip &)
US2400::LedState name_value_press(US2400::Button &)
US2400::LedState cursor_right_release(US2400::Button &)
std::shared_ptr< ARDOUR::Stripable > subview_stripable() const
void add_down_select_button(int surface, int strip)
ARDOUR::Session * session
Definition: basic_ui.h:204
Definition: xml++.h:114
std::list< std::shared_ptr< Stripable > > StripableList
std::list< std::shared_ptr< VCA > > VCAList
std::list< std::shared_ptr< Route > > RouteList
Temporal::samplepos_t samplepos_t
DebugBits US2400
US2400::LedState(US2400Protocol::* release)(US2400::Button &)
ButtonHandlers(US2400::LedState(US2400Protocol::*p)(US2400::Button &), US2400::LedState(US2400Protocol::*r)(US2400::Button &))
US2400::LedState(US2400Protocol::* press)(US2400::Button &)