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