Ardour  9.2-129-gdf5e1050bd
faderport8.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
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_surface_faderport8_h
20 #define ardour_surface_faderport8_h
21 
22 // allow to undo "mute clear", "solo clear"
23 // eventually this should use some libardour mixer history/undo
24 #define FP8_MUTESOLO_UNDO
25 
26 #include <list>
27 #include <map>
28 
29 #define ABSTRACT_UI_EXPORTS
30 #include "pbd/abstract_ui.h"
31 #include "pbd/properties.h"
32 #include "pbd/controllable.h"
33 
34 #include "ardour/types.h"
35 #include "ardour/async_midi_port.h"
36 #include "ardour/midi_port.h"
37 
39 
40 #include "fp8_base.h"
41 #include "fp8_controls.h"
42 
43 namespace MIDI {
44  class Parser;
45 }
46 
47 namespace ARDOUR {
48  class Bundle;
49  class Session;
50  class Processor;
51  class PluginInsert;
52 }
53 
54 namespace ArdourSurface { namespace FP_NAMESPACE {
55 
56 struct FaderPort8Request : public BaseUI::BaseRequestObject
57 {
58  public:
61 };
62 
63 class FaderPort8 : public FP8Base, public ARDOUR::ControlProtocol, public AbstractUI<FaderPort8Request>
64 {
65 public:
67  virtual ~FaderPort8();
68 
69  static bool probe (std::string&, std::string&);
70 
71  int set_active (bool yn);
72 
73  XMLNode& get_state () const;
74  int set_state (const XMLNode&, int version);
75 
76  /* configuration GUI */
77  bool has_editor () const { return true; }
78  void* get_gui () const;
79  void tear_down_gui ();
81 
82  void set_button_action (FP8Controls::ButtonId, bool, std::string const&);
84  FP8Controls const& control () const { return _ctrls; }
85 
86  void set_clock_mode (uint32_t m) { _clock_mode = m; }
87  void set_scribble_mode (uint32_t m) { _scribble_mode = m; }
88  void set_two_line_text (bool yn) { _two_line_text = yn; }
89  void set_auto_pluginui (bool yn) { _auto_pluginui = yn; }
90 
91  uint32_t clock_mode () const { return _clock_mode; }
92  uint32_t scribble_mode () const { return _scribble_mode; }
93  bool twolinetext () const { return _two_line_text; }
94  bool auto_pluginui () const { return _auto_pluginui; }
95 
96  void stop ();
98  void thread_init ();
99 
100  std::shared_ptr<ARDOUR::Port> input_port() const { return _input_port; }
101  std::shared_ptr<ARDOUR::Port> output_port() const { return _output_port; }
102  std::list<std::shared_ptr<ARDOUR::Bundle> > bundles ();
103 
104  size_t tx_midi (std::vector<uint8_t> const&) const;
105 
107 
108 private:
109  void close ();
110 
113 
114  /* I/O Ports */
116  std::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
117  std::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
118  std::shared_ptr<ARDOUR::Bundle> _input_bundle;
119  std::shared_ptr<ARDOUR::Bundle> _output_bundle;
120 
121  bool midi_input_handler (Glib::IOCondition ioc, std::weak_ptr<ARDOUR::AsyncMIDIPort> port);
122 
123  bool connection_handler (std::string name1, std::string name2);
124  void engine_reset ();
125 
127  InputConnected = 0x1,
128  OutputConnected = 0x2
129  };
130 
131  void connected ();
132  void disconnected ();
135 
136  /* MIDI input message handling */
137  void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
144 
145  /* ***************************************************************************
146  * Control Elements
147  */
152  void assign_stripables (bool select_only = false);
154 
155  void assign_strips ();
156  void bank (bool down, bool page);
158  void select_prev_next (bool next);
159 
160  void assign_sends ();
161  void spill_plugins ();
163  bool assign_plugin_presets (std::shared_ptr<ARDOUR::PluginInsert>);
164  void build_well_known_processor_ctrls (std::shared_ptr<ARDOUR::Stripable>, int);
165  void preset_changed ();
166  void select_plugin (int num);
167  void select_plugin_preset (size_t num);
168 
170  void bank_param (bool down, bool page);
171  /* bank offsets */
172  int get_channel_off (FP8Types::MixMode m) const { return _channel_off [m]; }
173  void set_channel_off (FP8Types::MixMode m, int off) {_channel_off [m] = off ; }
174 
175  int _channel_off[FP8Types::MixModeMax + 1];
178 
179  /* plugin + send mode stripable
180  *
181  * This is used when parameters of one strip are assigned to
182  * individual FP8Strip controls (Edit Send, Edit Plugins).
183  *
184  * When there's one stripable per FP8Strip, FP8Strip itself keeps
185  * track of the object lifetime and these are NULL.
186  */
188 
190  typedef std::map<std::shared_ptr<ARDOUR::Stripable>, uint8_t> StripAssignmentMap;
192 
194 
195  void select_strip (std::weak_ptr<ARDOUR::Stripable>);
196 
198  void notify_stripable_property_changed (std::weak_ptr<ARDOUR::Stripable>, const PBD::PropertyChange&);
201 
205  /* **************************************************************************/
206  struct ProcessorCtrl {
207  ProcessorCtrl (std::string const &n, std::shared_ptr<ARDOUR::AutomationControl> c)
208  : name (n)
209  , ac (c)
210  {}
211  std::string name;
212  std::shared_ptr<ARDOUR::AutomationControl> ac;
213 
214  inline bool operator< (const ProcessorCtrl& other) const;
215  };
216 
217  std::list <ProcessorCtrl> _proc_params;
218  std::weak_ptr<ARDOUR::PluginInsert> _plugin_insert;
221  /* **************************************************************************/
222 
223  /* periodic updates, parameter poll */
224  sigc::connection _periodic_connection;
225  bool periodic ();
226  std::string _timecode;
227  std::string _musical_time;
228  std::string const& timecode () const { return _timecode; }
229  std::string const& musical_time () const { return _musical_time; }
230 
232 
233  bool show_meters () const { return _scribble_mode & 1; }
234  bool show_panner () const { return _scribble_mode & 2; }
235 
236  /* sync button blink -- the FP's blink mode does not work */
237  sigc::connection _blink_connection;
239  bool blink_it ();
240 
241  /* shift key */
242  sigc::connection _shift_connection;
245  bool shift_timeout () { _shift_lock = true; return false; }
246  bool shift_mod () const { return _shift_lock || (_shift_pressed > 0); }
247 
248  /* GUI */
249  void build_gui ();
250  mutable void *gui;
251 
252  /* setup callbacks & actions */
254  void setup_actions ();
256 
257  /* callbacks */
259  void notify_parameter_changed (std::string);
270 
271  /* actions */
273  void button_play ();
274  void button_stop ();
275  void button_record ();
276  void button_loop ();
278  void button_bypass ();
279  void button_open ();
280  void button_link ();
281  void button_lock ();
282  void button_varispeed (bool);
283 #ifdef FP8_MUTESOLO_UNDO
285 #endif
287  void button_arm (bool);
288  void button_arm_all ();
290  void button_prev_next (bool);
291  void button_action (const std::string& group, const std::string& item);
292 
293  void button_chanlock (); /* FP2 only */
294  void button_flip (); /* FP2 only */
295 
296  void button_encoder ();
298  void encoder_navigate (bool, int);
299  void encoder_parameter (bool, int);
300 
301  /* mute undo history */
302 #ifdef FP8_MUTESOLO_UNDO
303  std::vector <std::weak_ptr<ARDOUR::AutomationControl> > _mute_state;
304  std::vector <std::weak_ptr<ARDOUR::AutomationControl> > _solo_state;
305 #endif
306 
307  /* Encoder handlers */
308  void handle_encoder_pan (int steps);
309  void handle_encoder_link (int steps);
310 
311  /* Control Link */
312  void stop_link ();
313  void start_link ();
314  void lock_link ();
315  void unlock_link (bool drop = false);
316  void nofity_focus_control (std::weak_ptr<PBD::Controllable>);
319  std::weak_ptr<PBD::Controllable> _link_control;
321  bool _link_locked; // can only be true if _link_enabled
322 
323  bool _chan_locked; /* FP2 only */
324 
325  /* user prefs */
326  uint32_t _clock_mode;
327  uint32_t _scribble_mode;
330 
331  /* user bound actions */
333 
334  enum ActionType {
337  // InternalFunction, // unused
338  };
339 
340  struct UserAction {
341  UserAction () : _type (Unset) {}
342 
344  std::string _action_name;
345  //std::function<void()> function; // unused
346 
347  void clear ()
348  {
349  _type = Unset;
350  _action_name.clear();
351  }
352 
353  void assign_action (std::string const& action_name)
354  {
355  if (action_name.empty ()) {
356  _type = Unset;
357  _action_name.clear();
358  } else {
359  _type = NamedAction;
360  _action_name = action_name;
361  }
362  }
363 
364  bool empty () const
365  {
366  return _type == Unset;
367  }
368 
369  void call (FaderPort8& _base) const
370  {
371  switch (_type) {
372  case NamedAction:
373  _base.access_action (_action_name);
374  break;
375  default:
376  break;
377  }
378  }
379  };
380 
381  struct ButtonAction {
384 
386  {
387  return press ? on_press : on_release;
388  }
389 
390  UserAction const& action (bool press) const
391  {
392  return press ? on_press : on_release;
393  }
394 
395  void call (FaderPort8& _base, bool press) const
396  {
397  action (press).call (_base);
398  }
399  bool empty () const
400  {
401  return on_press.empty () && on_release.empty();
402  }
403  };
404 
405  typedef std::map<FP8Controls::ButtonId, ButtonAction> UserActionMap;
407 };
408 
409 } } /* namespace */
410 
411 #endif /* ardour_surface_faderport8_h */
uint32_t clock_mode() const
Definition: faderport8.h:91
std::shared_ptr< ARDOUR::Bundle > _output_bundle
Definition: faderport8.h:119
PBD::ScopedConnection link_connection
Definition: faderport8.h:317
void sysex_handler(MIDI::Parser &p, MIDI::byte *, size_t)
PBD::ScopedConnectionList processor_connections
Definition: faderport8.h:187
std::shared_ptr< ARDOUR::AsyncMIDIPort > _input_port
Definition: faderport8.h:116
void set_scribble_mode(uint32_t m)
Definition: faderport8.h:87
FP8Controls const & control() const
Definition: faderport8.h:84
void nofity_focus_control(std::weak_ptr< PBD::Controllable >)
bool assign_plugin_presets(std::shared_ptr< ARDOUR::PluginInsert >)
void pitchbend_handler(MIDI::Parser &, uint8_t chan, MIDI::pitchbend_t pb)
void notify_stripable_property_changed(std::weak_ptr< ARDOUR::Stripable >, const PBD::PropertyChange &)
std::map< FP8Controls::ButtonId, ButtonAction > UserActionMap
Definition: faderport8.h:405
void select_plugin_preset(size_t num)
FaderPort8(ARDOUR::Session &)
PBD::Signal< void()> ConnectionChange
Definition: faderport8.h:80
PBD::ScopedConnectionList assigned_stripable_connections
Definition: faderport8.h:189
std::list< std::shared_ptr< ARDOUR::Bundle > > bundles()
static bool probe(std::string &, std::string &)
PBD::ScopedConnectionList port_connections
Definition: faderport8.h:115
PBD::ScopedConnection link_locked_connection
Definition: faderport8.h:318
std::weak_ptr< ARDOUR::PluginInsert > _plugin_insert
Definition: faderport8.h:218
void notify_parameter_changed(std::string)
sigc::connection _periodic_connection
Definition: faderport8.h:224
int get_channel_off(FP8Types::MixMode m) const
Definition: faderport8.h:172
std::shared_ptr< ARDOUR::Port > input_port() const
Definition: faderport8.h:100
std::map< std::shared_ptr< ARDOUR::Stripable >, uint8_t > StripAssignmentMap
Definition: faderport8.h:190
PBD::ScopedConnectionList midi_connections
Definition: faderport8.h:143
std::shared_ptr< ARDOUR::AsyncMIDIPort > _output_port
Definition: faderport8.h:117
void select_strip(std::weak_ptr< ARDOUR::Stripable >)
void bank(bool down, bool page)
sigc::connection _blink_connection
Definition: faderport8.h:237
PBD::ScopedConnectionList modechange_connections
Definition: faderport8.h:204
PBD::ScopedConnectionList route_state_connections
Definition: faderport8.h:203
void filter_stripables(ARDOUR::StripableList &strips) const
void set_periodic_display_mode(FP8Strip::DisplayMode)
bool connection_handler(std::string name1, std::string name2)
void set_auto_pluginui(bool yn)
Definition: faderport8.h:89
std::shared_ptr< ARDOUR::Port > output_port() const
Definition: faderport8.h:101
void assign_stripables(bool select_only=false)
void set_channel_off(FP8Types::MixMode m, int off)
Definition: faderport8.h:173
void button_automation(ARDOUR::AutoState)
void encoder_navigate(bool, int)
void build_well_known_processor_ctrls(std::shared_ptr< ARDOUR::Stripable >, int)
void set_two_line_text(bool yn)
Definition: faderport8.h:88
void set_button_action(FP8Controls::ButtonId, bool, std::string const &)
void set_clock_mode(uint32_t m)
Definition: faderport8.h:86
bool midi_input_handler(Glib::IOCondition ioc, std::weak_ptr< ARDOUR::AsyncMIDIPort > port)
void handle_encoder_link(int steps)
void do_request(FaderPort8Request *)
StripAssignmentMap _assigned_strips
Definition: faderport8.h:191
void bank_param(bool down, bool page)
void polypressure_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
PBD::ScopedConnectionList session_connections
Definition: faderport8.h:258
PBD::ScopedConnectionList button_connections
Definition: faderport8.h:272
void button_action(const std::string &group, const std::string &item)
sigc::connection _shift_connection
Definition: faderport8.h:242
size_t tx_midi(std::vector< uint8_t > const &) const
uint32_t scribble_mode() const
Definition: faderport8.h:92
std::shared_ptr< ARDOUR::Bundle > _input_bundle
Definition: faderport8.h:118
void handle_encoder_pan(int steps)
void note_on_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
void button_user(bool, FP8Controls::ButtonId)
void unlock_link(bool drop=false)
PBD::ScopedConnection selection_connection
Definition: faderport8.h:202
std::string const & timecode() const
Definition: faderport8.h:228
int set_state(const XMLNode &, int version)
std::list< ProcessorCtrl > _proc_params
Definition: faderport8.h:217
void notify_pi_property_changed(const PBD::PropertyChange &)
void encoder_parameter(bool, int)
std::weak_ptr< PBD::Controllable > _link_control
Definition: faderport8.h:319
std::vector< std::weak_ptr< ARDOUR::AutomationControl > > _solo_state
Definition: faderport8.h:304
void controller_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
std::vector< std::weak_ptr< ARDOUR::AutomationControl > > _mute_state
Definition: faderport8.h:303
void select_prev_next(bool next)
std::string get_button_action(FP8Controls::ButtonId, bool)
std::string const & musical_time() const
Definition: faderport8.h:229
void note_off_handler(MIDI::Parser &, MIDI::EventTwoBytes *tb)
void access_action(std::string action_path)
Definition: xml++.h:114
#define FP_NAMESPACE
Definition: fp8_base.h:32
GtkImageIconNameData name
Definition: gtkimage.h:6
std::list< std::shared_ptr< Stripable > > StripableList
unsigned short pitchbend_t
void call(FaderPort8 &_base, bool press) const
Definition: faderport8.h:395
UserAction const & action(bool press) const
Definition: faderport8.h:390
ProcessorCtrl(std::string const &n, std::shared_ptr< ARDOUR::AutomationControl > c)
Definition: faderport8.h:207
std::shared_ptr< ARDOUR::AutomationControl > ac
Definition: faderport8.h:212
void assign_action(std::string const &action_name)
Definition: faderport8.h:353
void call(FaderPort8 &_base) const
Definition: faderport8.h:369