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