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