Ardour  9.10-64-g004f398107
lppro.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2018 Paul Davis <paul@linuxaudiosystems.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_lppro_h__
20 #define __ardour_lppro_h__
21 
22 #include <vector>
23 #include <map>
24 #include <stack>
25 #include <list>
26 #include <set>
27 
28 #include <libusb.h>
29 
30 #define ABSTRACT_UI_EXPORTS
31 #include "pbd/abstract_ui.h"
32 
33 #include "midi++/types.h"
34 
35 #include "ardour/types.h"
36 
38 #include "control_protocol/types.h"
39 
40 #include "gtkmm2ext/colors.h"
41 
44 
45 namespace MIDI {
46  class Parser;
47  class Port;
48 }
49 
50 namespace ARDOUR {
51  class AutomationControl;
52  class Port;
53  class MidiBuffer;
54  class MidiTrack;
55  class Trigger;
56 }
57 
58 namespace ArdourSurface {
59 
60 class LPPRO_GUI;
61 
62 class LaunchPadPro : public MIDISurface
63 {
64  public:
65  /* use hex for these constants, because we'll see them (as note numbers
66  and CC numbers) in hex within MIDI messages when debugging.
67  */
68  enum PadID {
69  /* top */
70  Shift = 0x5a,
71  Left = 0x5b,
72  Right = 0x5c,
73  Session = 0x5d,
74  Note = 0x5e,
75  Chord = 0x5f,
76  Custom = 0x60,
77  Sequencer = 0x61,
78  Projects = 0x62,
79  /* right side */
80  Patterns = 0x59,
81  Steps = 0x4f,
83  Velocity = 0x3b,
84  Probability = 0x31,
85  Mutation = 0x27,
86  MicroStep = 0x1d,
87  PrintToClip = 0x13,
88  /* lower bottom */
89  StopClip = 0x8,
90  Device = 0x7,
91  Sends = 0x6,
92  Pan = 0x5,
93  Volume = 0x4,
94  Solo = 0x3,
95  Mute = 0x2,
96  RecordArm = 0x1,
97  /* left side */
98  CaptureMIDI = 0xa,
99  Play = 0x14,
100  FixedLength = 0x1e,
101  Quantize = 0x28,
102  Duplicate = 0x32,
103  Clear = 0x3c,
104  Down = 0x46,
105  Up = 0x50,
106  /* upper bottom */
107  Lower1 = 0x65,
108  Lower2 = 0x66,
109  Lower3 = 0x67,
110  Lower4 = 0x68,
111  Lower5 = 0x69,
112  Lower6 = 0x6a,
113  Lower7 = 0x6b,
114  Lower8 = 0x6c,
115  /* Logo */
116  Logo = 0x63
117  };
118 
119  bool light_logo();
120  void all_pads_out ();
121 
122  static const PadID all_pad_ids[];
123 
126 
127  static bool available ();
128  static bool match_usb (uint16_t, uint16_t);
129  static bool probe (std::string&, std::string&);
130 
131  std::string input_port_name () const;
132  std::string output_port_name () const;
133 
134  bool has_editor () const { return true; }
135  void* get_gui () const;
136  void tear_down_gui ();
137 
138  int set_active (bool yn);
139  XMLNode& get_state() const;
140  int set_state (const XMLNode & node, int version);
141 
142  private:
143  enum DeviceMode {
146  Programmer
147  };
148 
149  enum Layout {
170  };
171 
172  enum FaderBank {
177  };
178 
179  static const Layout AllLayouts[];
180 
181  struct Pad {
182 
183  enum ColorMode {
184  Static = 0x0,
185  Flashing = 0x1,
186  Pulsing = 0x2
187  };
188 
189  typedef void (LaunchPadPro::*ButtonMethod)(Pad&);
190  typedef void (LaunchPadPro::*PadMethod)(Pad&, int velocity);
191 
192  Pad (PadID pid, ButtonMethod press_method, ButtonMethod long_press_method = &LaunchPadPro::relax, ButtonMethod release_method = &LaunchPadPro::relax)
193  : id (pid)
194  , x (-1)
195  , y (-1)
196  {
197  on_press = press_method;
198  on_release = release_method;
199  on_long_press = long_press_method;
200  }
201 
202  Pad (int pid, int xx, int yy, PadMethod press_method, ButtonMethod long_press_method = &LaunchPadPro::relax, ButtonMethod release_method = &LaunchPadPro::relax)
203  : id (pid)
204  , x (xx)
205  , y (yy)
206  {
207  on_pad_press = press_method;
208  on_release = release_method;
209  on_long_press = long_press_method;
210  }
211 
212  MIDI::byte status_byte() const { if (x < 0) return 0xb0; return 0x90; }
213  bool is_pad () const { return x >= 0; }
214  bool is_button () const { return x < 0; }
215 
216  int id;
217  int x;
218  int y;
219 
220  /* It's either a button (CC number) or a pad (note number
221  * w/velocity info), never both.
222  */
223  union {
226  };
227 
230 
231  sigc::connection timeout_connection;
232  };
233 
234  void relax (Pad& p);
235 
236  std::set<int> consumed;
237 
239 
242  typedef std::pair<int32_t,int32_t> StripableSlot;
243  typedef std::vector<StripableSlot> StripableSlotRow;
244  typedef std::vector<StripableSlotRow> StripableSlotColumn;
246 
247  StripableSlot get_stripable_slot (int x, int y) const;
248 
249  typedef std::map<int,Pad> PadMap;
252  Pad* pad_by_id (int pid);
253 
254  typedef std::map<int,uint32_t> ColorMap;
258 
259  typedef std::map<uint32_t,int> NearestMap;
261 
264  int device_acquire () { return 0; }
265  void device_release () { }
266  void run_event_loop ();
268 
270  void select_stripable (int col);
271  std::weak_ptr<ARDOUR::MidiTrack> _current_pad_target;
272 
273  void light_pad (int pad_id, int color, int mode = 0);
274  void pad_off (int pad_id);
275  void all_pads_off ();
276  void all_pads_on (int color);
277 
279  void set_layout (Layout, int page = 0);
280 
284  void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
285 
288  std::shared_ptr<ARDOUR::Port> _daw_in;
289  std::shared_ptr<ARDOUR::Port> _daw_out;
290 
293  void ports_release ();
295 
296  void daw_write (const MidiByteArray&);
297  void daw_write (MIDI::byte const *, size_t);
298 
301 
302  void scroll_text (std::string const &, int color, bool loop, float speed = 0);
303 
304  mutable LPPRO_GUI* _gui;
305  void build_gui ();
306 
308 
310 
313  bool long_press_timeout (int pad_id);
314 
319 
320  void cue_press (Pad&, int row);
321 
322  /* named pad methods */
323  void shift_press (Pad&);
326  void left_press (Pad&);
327  void left_release (Pad&) {}
328  void left_long_press (Pad&) {}
329  void right_press (Pad&);
330  void right_release (Pad&) {}
335  void note_press (Pad&);
336  void note_release (Pad&) {}
337  void note_long_press (Pad&) {}
338  void chord_press (Pad&);
339  void chord_release (Pad&) {}
341  void custom_press (Pad&);
342  void custom_release (Pad&) {}
353  void steps_press (Pad&);
354  void steps_release (Pad&) {}
377  void device_press (Pad&);
378  void device_release (Pad&) {}
380  void sends_press (Pad&);
381  void sends_release (Pad&) {}
383  void pan_press (Pad&);
384  void pan_release (Pad&) {}
385  void pan_long_press (Pad&) {}
386  void volume_press (Pad&);
387  void volume_release (Pad&) {}
389  void solo_press (Pad&);
390  void solo_release (Pad&) {}
392  void mute_press (Pad&);
393  void mute_release (Pad&) {}
394  void mute_long_press (Pad&) {}
401  void play_press (Pad&);
402  void play_release (Pad&) {}
403  void play_long_press (Pad&) {}
413  void clear_press (Pad&);
416  void down_press (Pad&);
417  void down_release (Pad&) {}
418  void down_long_press (Pad&) {}
419  void up_press (Pad&);
420  void up_release (Pad&) {}
421  void up_long_press (Pad&) {}
422  void lower1_press (Pad&);
423  void lower1_release (Pad&) {}
425  void lower2_press (Pad&);
426  void lower2_release (Pad&) {}
428  void lower3_press (Pad&);
429  void lower3_release (Pad&) {}
431  void lower4_press (Pad&);
432  void lower4_release (Pad&) {}
434  void lower5_press (Pad&);
435  void lower5_release (Pad&) {}
437  void lower6_press (Pad&);
438  void lower6_release (Pad&) {}
440  void lower7_press (Pad&);
441  void lower7_release (Pad&) {}
443  void lower8_press (Pad&);
444  void lower8_release (Pad&) {}
446 
449 
450  void pad_press (Pad&, int velocity);
452  void pad_release (Pad&);
453 
456 
461 
462  void map_triggers ();
463  void map_triggerbox (int col);
464 
468 
470  void map_faders ();
471  void fader_move (int cc, int val);
472  void automation_control_change (int n, std::weak_ptr<ARDOUR::AutomationControl>);
477 };
478 
479 
480 } /* namespace */
481 
482 #endif /* __ardour_lppro_h__ */
void fader_move(int cc, int val)
void pad_off(int pad_id)
int set_state(const XMLNode &node, int version)
void play_long_press(Pad &)
Definition: lppro.h:403
void up_long_press(Pad &)
Definition: lppro.h:421
std::map< int, uint32_t > ColorMap
Definition: lppro.h:254
void light_pad(int pad_id, int color, int mode=0)
void quantize_long_press(Pad &)
Definition: lppro.h:409
void session_long_press(Pad &)
Definition: lppro.h:334
void right_long_press(Pad &)
Definition: lppro.h:331
void left_long_press(Pad &)
Definition: lppro.h:328
void sequencer_long_press(Pad &)
Definition: lppro.h:346
void sends_release(Pad &)
Definition: lppro.h:381
void note_long_press(Pad &)
Definition: lppro.h:337
void mutation_release(Pad &)
Definition: lppro.h:366
std::shared_ptr< ARDOUR::Port > _daw_in
Definition: lppro.h:288
void lower2_long_press(Pad &)
Definition: lppro.h:427
std::vector< StripableSlotRow > StripableSlotColumn
Definition: lppro.h:244
static bool probe(std::string &, std::string &)
std::pair< int32_t, int32_t > StripableSlot
Definition: lppro.h:242
XMLNode & get_state() const
PBD::ScopedConnectionList route_connections
Definition: lppro.h:467
void handle_midi_note_off_message(MIDI::Parser &, MIDI::EventTwoBytes *)
void lower5_long_press(Pad &)
Definition: lppro.h:436
void volume_release(Pad &)
Definition: lppro.h:387
std::vector< StripableSlot > StripableSlotRow
Definition: lppro.h:243
void route_property_change(PBD::PropertyChange const &, int x)
bool pad_filter(ARDOUR::MidiBuffer &in, ARDOUR::MidiBuffer &out) const
FaderBank current_fader_bank
Definition: lppro.h:474
void patterns_release(Pad &)
Definition: lppro.h:351
void trigger_property_change(PBD::PropertyChange, ARDOUR::Trigger *)
void lower6_long_press(Pad &)
Definition: lppro.h:439
void steps_long_press(Pad &)
Definition: lppro.h:355
void quantize_release(Pad &)
Definition: lppro.h:408
void pan_long_press(Pad &)
Definition: lppro.h:385
std::set< int > consumed
Definition: lppro.h:236
void custom_long_press(Pad &)
Definition: lppro.h:343
PBD::ScopedConnectionList control_connections
Definition: lppro.h:473
void automation_control_change(int n, std::weak_ptr< ARDOUR::AutomationControl >)
void daw_write(MIDI::byte const *, size_t)
void capture_midi_long_press(Pad &)
Definition: lppro.h:400
MIDI::Port * _daw_out_port
Definition: lppro.h:287
void device_release(Pad &)
Definition: lppro.h:378
static const PadID all_pad_ids[]
Definition: lppro.h:122
void velocity_long_press(Pad &)
Definition: lppro.h:361
void projects_release(Pad &)
Definition: lppro.h:348
void setup_faders(FaderBank)
void lower8_long_press(Pad &)
Definition: lppro.h:445
void stop_clip_long_press(Pad &)
Definition: lppro.h:376
void steps_release(Pad &)
Definition: lppro.h:354
void print_to_clip_release(Pad &)
Definition: lppro.h:372
void lower3_long_press(Pad &)
Definition: lppro.h:430
void record_arm_long_press(Pad &)
Definition: lppro.h:397
void lower3_release(Pad &)
Definition: lppro.h:429
void lower5_release(Pad &)
Definition: lppro.h:435
std::string input_port_name() const
void patterns_long_press(Pad &)
Definition: lppro.h:352
void mute_release(Pad &)
Definition: lppro.h:393
std::map< uint32_t, int > NearestMap
Definition: lppro.h:259
std::string output_port_name() const
NearestMap nearest_map
Definition: lppro.h:260
StripableSlot get_stripable_slot(int x, int y) const
void chord_long_press(Pad &)
Definition: lppro.h:340
void microstep_release(Pad &)
Definition: lppro.h:369
void set_device_mode(DeviceMode)
bool has_editor() const
Definition: lppro.h:134
void select_stripable(int col)
void lower1_long_press(Pad &)
Definition: lppro.h:424
LaunchPadPro(ARDOUR::Session &)
void sends_long_press(Pad &)
Definition: lppro.h:382
void play_release(Pad &)
Definition: lppro.h:402
void all_pads_on(int color)
void lower4_long_press(Pad &)
Definition: lppro.h:433
void pattern_settings_release(Pad &)
Definition: lppro.h:357
void projects_long_press(Pad &)
Definition: lppro.h:349
void device_long_press(Pad &)
Definition: lppro.h:379
void handle_midi_controller_message(MIDI::Parser &, MIDI::EventTwoBytes *)
std::shared_ptr< ARDOUR::Port > _daw_out
Definition: lppro.h:289
void maybe_start_press_timeout(Pad &pad)
void note_release(Pad &)
Definition: lppro.h:336
StripableSlotColumn stripable_slots
Definition: lppro.h:245
void lower2_release(Pad &)
Definition: lppro.h:426
void handle_midi_note_on_message(MIDI::Parser &, MIDI::EventTwoBytes *)
void capture_midi_release(Pad &)
Definition: lppro.h:399
MIDI::Port * _daw_in_port
Definition: lppro.h:286
void duplicate_long_press(Pad &)
Definition: lppro.h:412
void duplicate_release(Pad &)
Definition: lppro.h:411
void velocity_release(Pad &)
Definition: lppro.h:360
void stop_clip_release(Pad &)
Definition: lppro.h:375
void pad_press(Pad &, int velocity)
std::map< int, Pad > PadMap
Definition: lppro.h:249
void fixed_length_long_press(Pad &)
Definition: lppro.h:406
void record_arm_release(Pad &)
Definition: lppro.h:396
void solo_release(Pad &)
Definition: lppro.h:390
void print_to_clip_long_press(Pad &)
Definition: lppro.h:373
void lower4_release(Pad &)
Definition: lppro.h:432
void daw_write(const MidiByteArray &)
void pan_release(Pad &)
Definition: lppro.h:384
void pattern_settings_long_press(Pad &)
Definition: lppro.h:358
void custom_release(Pad &)
Definition: lppro.h:342
PBD::ScopedConnectionList trigger_connections
Definition: lppro.h:455
void sequencer_release(Pad &)
Definition: lppro.h:345
void right_release(Pad &)
Definition: lppro.h:330
void mutation_long_press(Pad &)
Definition: lppro.h:367
void left_release(Pad &)
Definition: lppro.h:327
void lower8_release(Pad &)
Definition: lppro.h:444
void microstep_long_press(Pad &)
Definition: lppro.h:370
void lower7_release(Pad &)
Definition: lppro.h:441
void down_release(Pad &)
Definition: lppro.h:417
void shift_long_press(Pad &)
Definition: lppro.h:325
static const Layout AllLayouts[]
Definition: lppro.h:179
void handle_midi_sysex(MIDI::Parser &, MIDI::byte *, size_t count)
void probability_long_press(Pad &)
Definition: lppro.h:364
void scroll_text(std::string const &, int color, bool loop, float speed=0)
void clear_long_press(Pad &)
Definition: lppro.h:415
void down_long_press(Pad &)
Definition: lppro.h:418
void lower1_release(Pad &)
Definition: lppro.h:423
static bool match_usb(uint16_t, uint16_t)
void pattern_settings_press(Pad &)
bool revert_layout_on_fader_release
Definition: lppro.h:475
void cue_press(Pad &, int row)
void lower6_release(Pad &)
Definition: lppro.h:438
std::weak_ptr< ARDOUR::MidiTrack > _current_pad_target
Definition: lppro.h:271
void fixed_length_release(Pad &)
Definition: lppro.h:405
void lower7_long_press(Pad &)
Definition: lppro.h:442
void set_layout(Layout, int page=0)
void volume_long_press(Pad &)
Definition: lppro.h:388
void start_press_timeout(Pad &pad)
void chord_release(Pad &)
Definition: lppro.h:339
void probability_release(Pad &)
Definition: lppro.h:363
void mute_long_press(Pad &)
Definition: lppro.h:394
int find_closest_palette_color(uint32_t)
void up_release(Pad &)
Definition: lppro.h:420
bool long_press_timeout(int pad_id)
Definition: xml++.h:114
PBD::PropertyDescriptor< uint32_t > color
Pad(PadID pid, ButtonMethod press_method, ButtonMethod long_press_method=&LaunchPadPro::relax, ButtonMethod release_method=&LaunchPadPro::relax)
Definition: lppro.h:192
void(LaunchPadPro::* PadMethod)(Pad &, int velocity)
Definition: lppro.h:190
sigc::connection timeout_connection
Definition: lppro.h:231
MIDI::byte status_byte() const
Definition: lppro.h:212
Pad(int pid, int xx, int yy, PadMethod press_method, ButtonMethod long_press_method=&LaunchPadPro::relax, ButtonMethod release_method=&LaunchPadPro::relax)
Definition: lppro.h:202
void(LaunchPadPro::* ButtonMethod)(Pad &)
Definition: lppro.h:189