Ardour  9.0-pre0-582-g084a23a80d
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 <sys/time.h>
28 #include <pthread.h>
29 #define ABSTRACT_UI_EXPORTS
30 #include "pbd/abstract_ui.h"
31 #include "midi++/types.h"
32 #include "ardour/types.h"
34 
35 #include "types.h"
36 #include "midi_byte_array.h"
37 #include "controls.h"
38 #include "jog_wheel.h"
39 #include "timer.h"
40 #include "device_info.h"
41 #include "device_profile.h"
42 
43 namespace ARDOUR {
44  class AutomationControl;
45  class Port;
46 }
47 
48 namespace MIDI {
49  class Port;
50 }
51 
52 namespace ArdourSurface {
53 
54 namespace US2400 {
55  class Surface;
56  class Control;
57  class SurfacePort;
58  class Button;
59  class Strip;
60 }
61 
62 struct US2400ControlUIRequest : public BaseUI::BaseRequestObject {
63 public:
66 };
67 
70  , public AbstractUI<US2400ControlUIRequest>
71 {
72  public:
73  static const int MODIFIER_OPTION;
74  static const int MODIFIER_CONTROL;
75  static const int MODIFIER_SHIFT;
76  static const int MODIFIER_CMDALT;
77  static const int MODIFIER_ZOOM;
78  static const int MODIFIER_SCRUB;
79  static const int MODIFIER_MARKER;
80  static const int MODIFIER_DROP; //US2400 replaces MODIFIER_NUDGE which is unused
81  static const int MAIN_MODIFIER_MASK;
82 
83  enum ViewMode {
86  };
87 
88  enum SubViewMode {
91  };
92 
94  virtual ~US2400Protocol();
95 
96  static US2400Protocol* instance() { return _instance; }
97 
98  const US2400::DeviceInfo& device_info() const { return _device_info; }
100 
102  PBD::Signal<void(std::shared_ptr<US2400::Surface> )> ConnectionChange;
103 
104  void device_ready ();
105 
106  int set_active (bool yn);
107  int set_device (const std::string&, bool force);
108  void set_profile (const std::string&);
109 
110  ViewMode view_mode () const { return _view_mode; }
112  static bool subview_mode_would_be_ok (SubViewMode, std::shared_ptr<ARDOUR::Stripable>);
113  std::shared_ptr<ARDOUR::Stripable> subview_stripable() const;
114  bool zoom_mode () const { return modifier_state() & MODIFIER_ZOOM; }
115  bool metering_active () const { return _metering_active; }
116 
117  bool is_track (std::shared_ptr<ARDOUR::Stripable>) const;
118  bool is_audio_track (std::shared_ptr<ARDOUR::Stripable>) const;
119  bool is_midi_track (std::shared_ptr<ARDOUR::Stripable>) const;
120  bool is_mapped (std::shared_ptr<ARDOUR::Stripable>) const;
121  std::shared_ptr<ARDOUR::Stripable> first_selected_stripable () const;
122 
126 
128  int set_subview_mode (SubViewMode, std::shared_ptr<ARDOUR::Stripable>);
130 
131  XMLNode& get_state () const;
132  int set_state (const XMLNode&, int version);
133 
134  /* Note: because Mackie control is inherently a duplex protocol,
135  we do not implement get/set_feedback() since this aspect of
136  support for the protocol is not optional.
137  */
138 
139  mutable Glib::Threads::Mutex surfaces_lock;
140  typedef std::list<std::shared_ptr<US2400::Surface> > Surfaces;
142 
143  std::shared_ptr<US2400::Surface> get_surface_by_raw_pointer (void*) const;
144  std::shared_ptr<US2400::Surface> nth_surface (uint32_t) const;
145 
148 
149  std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
150 
151  void set_master_on_surface_strip (uint32_t surface, uint32_t strip);
152  void set_monitor_on_surface_strip (uint32_t surface, uint32_t strip);
153 
154  uint32_t n_strips (bool with_locked_strips = true) const;
155 
156  bool has_editor () const { return true; }
157  void* get_gui () const;
158  void tear_down_gui ();
159 
161 
166 
168 
172 
176 
177  // button-related signals
182  // mainly to pick up punch-in and punch-out
183  void notify_parameter_changed(std::string const &);
185 
189 
192 
195 
198 
199  int modifier_state() const { return _modifier_state; }
201 
202  typedef std::list<std::shared_ptr<ARDOUR::AutomationControl> > ControlList;
203 
204  void add_down_button (ARDOUR::AutomationType, int surface, int strip);
205  void remove_down_button (ARDOUR::AutomationType, int surface, int strip);
207 
208  void add_down_select_button (int surface, int strip);
209  void remove_down_select_button (int surface, int strip);
210  void select_range (uint32_t pressed);
211 
213 
215 
216  protected:
217  // shut down the surface
218  void close();
219 
220  // This sets up the notifications and sets the
221  // controls to the correct values
223 
224  // connects global (not strip) signals from the Session to here
225  // so the surface can be notified of changes from the other UIs.
227 
228  // set all controls to their zero position
229  void zero_all();
230 
235  typedef std::vector<std::shared_ptr<ARDOUR::Stripable> > Sorted;
237 
238  // bank switching
239  int switch_banks (uint32_t first_remote_id, bool force = false);
240  void prev_track ();
241  void next_track ();
242 
244  int stop ();
245 
246  void thread_init ();
247 
248  bool stripable_is_locked_to_strip (std::shared_ptr<ARDOUR::Stripable>) const;
249 
250  private:
251 
252  struct ButtonHandlers {
255 
258  : press (p)
259  , release (r) {}
260  };
261 
262  typedef std::map<US2400::Button::ID,ButtonHandlers> ButtonMap;
263 
265 
266  bool profile_exists (std::string const&) const;
267 
270  sigc::connection periodic_connection;
271  sigc::connection redisplay_connection;
272  sigc::connection hui_connection;
279  // timer for two quick marker left presses
281  // last written timecode string
282  std::string _timecode_last;
284  // Which timecode are we displaying? BBT or Timecode
286  // Bundle to represent our input ports
287  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
288  // Bundle to represent our output ports
289  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
290  void* _gui;
294  std::shared_ptr<ARDOUR::Stripable> _subview_stripable;
301  int _last_bank[9];
305 
306  std::shared_ptr<ArdourSurface::US2400::Surface> _master_surface;
307 
309  bool periodic();
310  bool redisplay();
312  bool hui_heartbeat ();
313  void build_gui ();
314  bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
315  void clear_ports ();
316  void clear_surfaces ();
317  void force_special_stripable_to_strip (std::shared_ptr<ARDOUR::Stripable> r, uint32_t surface, uint32_t strip_number);
320  void initialize ();
321  int set_device_info (const std::string& device_name);
323 
324  /* MIDI port connection management */
325 
327  void connection_handler (std::weak_ptr<ARDOUR::Port>, std::string name1, std::weak_ptr<ARDOUR::Port>, std::string name2, bool);
328 
329  /* BUTTON HANDLING */
330 
331  typedef std::set<uint32_t> DownButtonList;
332  typedef std::map<ARDOUR::AutomationType,DownButtonList> DownButtonMap;
335 
337 
338  /* implemented button handlers */
387 
402 // US2400::LedState F1_press (US2400::Button &);
403 // US2400::LedState F1_release (US2400::Button &);
404 // US2400::LedState F2_press (US2400::Button &);
405 // US2400::LedState F2_release (US2400::Button &);
406 // US2400::LedState F3_press (US2400::Button &);
407 // US2400::LedState F3_release (US2400::Button &);
408 // US2400::LedState F4_press (US2400::Button &);
409 // US2400::LedState F4_release (US2400::Button &);
410 // US2400::LedState F5_press (US2400::Button &);
411 // US2400::LedState F5_release (US2400::Button &);
412 // US2400::LedState F6_press (US2400::Button &);
413 // US2400::LedState F6_release (US2400::Button &);
414 // US2400::LedState F7_press (US2400::Button &);
415 // US2400::LedState F7_release (US2400::Button &);
416 // US2400::LedState F8_press (US2400::Button &);
417 // US2400::LedState F8_release (US2400::Button &);
432 
475 
477 };
478 
479 } // namespace
480 
481 #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:201
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 &)