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