Ardour  9.10-25-gb111bf379e
lpx.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_lpx_h__
20 #define __ardour_lpx_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 #ifdef LAUNCHPAD_MINI
59 #define LAUNCHPAD_NAMESPACE LP_MINI
60 #else
61 #define LAUNCHPAD_NAMESPACE LP_X
62 #endif
63 
64 namespace ArdourSurface { namespace LAUNCHPAD_NAMESPACE {
65 
66 class LPX_GUI;
67 
68 class LaunchPadX : public MIDISurface
69 {
70  public:
71  /* use hex for these constants, because we'll see them (as note numbers
72  and CC numbers) in hex within MIDI messages when debugging.
73  */
74  enum PadID {
75  /* top */
76  Up = 0x5b,
77  Down = 0x5c,
78  Left = 0x5d,
79  Right = 0x5e,
80  Session = 0x5f,
81  Note = 0x60,
82  Custom = 0x61,
83  CaptureMIDI = 0x62,
84  /* right side */
85  Volume = 0x59,
86  Pan = 0x4f,
87  SendA = 0x45,
88  SendB = 0x3b,
89  StopClip = 0x31,
90  Mute = 0x27,
91  Solo = 0x1d,
92  RecordArm = 0x13,
93  Logo = 0x63
94  };
95 
96  bool light_logo();
97  void all_pads_out ();
98 
101 
102  static bool available ();
103  static bool match_usb (uint16_t, uint16_t);
104  static bool probe (std::string&, std::string&);
105 
106  std::string input_port_name () const;
107  std::string output_port_name () const;
108 
109  bool has_editor () const { return true; }
110  void* get_gui () const;
111  void tear_down_gui ();
112 
113  int set_active (bool yn);
114  XMLNode& get_state() const;
115  int set_state (const XMLNode & node, int version);
116 
117  private:
118  enum DeviceMode {
121  Programmer
122  };
123 
124  enum Layout {
128  };
129 
130  enum FaderBank {
135  };
136 
137  struct Pad {
138 
139  enum ColorMode {
140  Static = 0x0,
141  Flashing = 0x1,
142  Pulsing = 0x2
143  };
144 
145  typedef void (LaunchPadX::*ButtonMethod)(Pad&);
146  typedef void (LaunchPadX::*PadMethod)(Pad&, int velocity);
147 
148  Pad (PadID pid, ButtonMethod press_method, ButtonMethod long_press_method = &LaunchPadX::relax, ButtonMethod release_method = &LaunchPadX::relax)
149  : id (pid)
150  , x (-1)
151  , y (-1)
152  {
153  on_press = press_method;
154  on_release = release_method;
155  on_long_press = long_press_method;
156  }
157 
158  Pad (int pid, int xx, int yy, PadMethod press_method, ButtonMethod long_press_method = &LaunchPadX::relax, ButtonMethod release_method = &LaunchPadX::relax)
159  : id (pid)
160  , x (xx)
161  , y (yy)
162  {
163  on_pad_press = press_method;
164  on_release = release_method;
165  on_long_press = long_press_method;
166  }
167 
168  MIDI::byte status_byte() const { if (x < 0) return 0xb0; return 0x90; }
169  bool is_pad () const { return x >= 0; }
170  bool is_button () const { return x < 0; }
171 
172  int id;
173  int x;
174  int y;
175 
176  /* It's either a button (CC number) or a pad (note number
177  * w/velocity info), never both.
178  */
179  union {
180  ButtonMethod on_press;
181  PadMethod on_pad_press;
182  };
183 
184  ButtonMethod on_release;
185  ButtonMethod on_long_press;
186 
187  sigc::connection timeout_connection;
188  };
189 
190  void relax (Pad& p);
191 
192  std::set<int> consumed;
193 
195 
198  typedef std::pair<int32_t,int32_t> StripableSlot;
199  typedef std::vector<StripableSlot> StripableSlotRow;
200  typedef std::vector<StripableSlotRow> StripableSlotColumn;
202 
203  StripableSlot get_stripable_slot (int x, int y) const;
204 
205  typedef std::map<int,Pad> PadMap;
208  Pad* pad_by_id (int pid);
209 
210  typedef std::map<int,uint32_t> ColorMap;
214 
215  typedef std::map<uint32_t,int> NearestMap;
217 
220  int device_acquire () { return 0; }
221  void device_release () { }
222  void run_event_loop ();
224 
226  void select_stripable (int col);
227  std::weak_ptr<ARDOUR::MidiTrack> _current_pad_target;
228 
229  void light_pad (int pad_id, int color, int mode = 0);
230  void pad_off (int pad_id);
231  void all_pads_off ();
232  void all_pads_on (int color);
233 
237  void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
238 
241  std::shared_ptr<ARDOUR::Port> _daw_in;
242  std::shared_ptr<ARDOUR::Port> _daw_out;
243 
246  void ports_release ();
248 
249  void daw_write (const MidiByteArray&);
250  void daw_write (MIDI::byte const *, size_t);
251 
254 
255  void scroll_text (std::string const &, int color, bool loop, float speed = 0);
256 
257  mutable LPX_GUI* _gui;
258  void build_gui ();
259 
261 
264  bool long_press_timeout (int pad_id);
265 
268  MixerMode
269  };
270 
272  void set_session_mode (SessionState, bool clear_pending);
274  set_session_mode (sm, true);
275  }
276 
278 
279  void cue_press (Pad&, int row);
280 
281  void rh0_press (Pad&);
282  void rh1_press (Pad&);
283  void rh2_press (Pad&);
284  void rh3_press (Pad&);
285  void rh4_press (Pad&);
287  void rh5_press (Pad&);
288  void rh6_press (Pad&);
290  void rh7_press (Pad&);
292 
293  /* named pad methods */
294  void down_press (Pad&);
295  void down_release (Pad&) {}
296  void down_long_press (Pad&) {}
297  void up_press (Pad&);
298  void up_release (Pad&) {}
299  void up_long_press (Pad&) {}
300  void left_press (Pad&);
301  void left_release (Pad&) {}
302  void left_long_press (Pad&) {}
303  void right_press (Pad&);
304  void right_release (Pad&) {}
309  void note_press (Pad&);
310  void note_release (Pad&) {}
311  void note_long_press (Pad&) {}
312  void custom_press (Pad&);
313  void custom_release (Pad&) {}
315 
316  void send_a_press (Pad&);
317  void send_a_release (Pad&) {}
318  void send_b_press (Pad&);
319  void send_b_release (Pad&) {}
320  void pan_press (Pad&);
321  void pan_release (Pad&) {}
322  void pan_long_press (Pad&) {}
323  void volume_press (Pad&);
324  void volume_release (Pad&) {}
326  void solo_press (Pad&);
327  void solo_release (Pad&) {}
331  void mute_press (Pad&);
332  void mute_release (Pad&) {}
333  void mute_long_press (Pad&) {}
340 
341  void pad_press (Pad&, int velocity);
343  void pad_release (Pad&);
344 
347 
351 
352  void map_triggers ();
353  void map_triggerbox (int col);
354 
358 
360  void map_faders ();
361  void fader_move (int cc, int val);
362  void automation_control_change (int n, std::weak_ptr<ARDOUR::AutomationControl>);
367 
373  PendingRecArm
374  };
375 
378  void handle_pending_mixer_op (int col);
379 };
380 
381 
382 } } /* namespaces */
383 
384 #endif /* __ardour_lpx_h__ */
void right_release(Pad &)
Definition: lpx.h:304
StripableSlot get_stripable_slot(int x, int y) const
FaderBank current_fader_bank
Definition: lpx.h:364
void volume_release(Pad &)
Definition: lpx.h:324
void send_a_release(Pad &)
Definition: lpx.h:317
void record_arm_long_press(Pad &)
Definition: lpx.h:336
void custom_long_press(Pad &)
Definition: lpx.h:314
void down_long_press(Pad &)
Definition: lpx.h:296
std::vector< StripableSlotRow > StripableSlotColumn
Definition: lpx.h:200
void set_session_mode(SessionState sm)
Definition: lpx.h:273
void maybe_start_press_timeout(Pad &pad)
void volume_long_press(Pad &)
Definition: lpx.h:325
void up_long_press(Pad &)
Definition: lpx.h:299
std::map< int, uint32_t > ColorMap
Definition: lpx.h:210
void set_pending_mixer_op(PendingMixerOp)
void handle_midi_note_off_message(MIDI::Parser &, MIDI::EventTwoBytes *)
PBD::ScopedConnectionList route_connections
Definition: lpx.h:357
void note_long_press(Pad &)
Definition: lpx.h:311
void cue_press(Pad &, int row)
std::vector< StripableSlot > StripableSlotRow
Definition: lpx.h:199
void automation_control_change(int n, std::weak_ptr< ARDOUR::AutomationControl >)
void stop_clip_release(Pad &)
Definition: lpx.h:330
static bool match_usb(uint16_t, uint16_t)
void route_property_change(PBD::PropertyChange const &, int x)
void left_release(Pad &)
Definition: lpx.h:301
std::map< int, Pad > PadMap
Definition: lpx.h:205
MIDI::Port * _daw_out_port
Definition: lpx.h:240
MIDI::Port * _daw_in_port
Definition: lpx.h:239
void left_long_press(Pad &)
Definition: lpx.h:302
void send_b_release(Pad &)
Definition: lpx.h:319
void custom_release(Pad &)
Definition: lpx.h:313
std::weak_ptr< ARDOUR::MidiTrack > _current_pad_target
Definition: lpx.h:227
std::map< uint32_t, int > NearestMap
Definition: lpx.h:215
void scroll_text(std::string const &, int color, bool loop, float speed=0)
void down_release(Pad &)
Definition: lpx.h:295
void pad_press(Pad &, int velocity)
void fader_move(int cc, int val)
void set_session_mode(SessionState, bool clear_pending)
SessionState _session_mode
Definition: lpx.h:277
void light_pad(int pad_id, int color, int mode=0)
void pan_long_press(Pad &)
Definition: lpx.h:322
bool long_press_timeout(int pad_id)
std::string output_port_name() const
void daw_write(const MidiByteArray &)
void daw_write(MIDI::byte const *, size_t)
PBD::ScopedConnectionList trigger_connections
Definition: lpx.h:346
void solo_release(Pad &)
Definition: lpx.h:327
LaunchPadX(ARDOUR::Session &)
void handle_midi_note_on_message(MIDI::Parser &, MIDI::EventTwoBytes *)
std::pair< int32_t, int32_t > StripableSlot
Definition: lpx.h:198
PendingMixerOp pending_mixer_op
Definition: lpx.h:376
void set_device_mode(DeviceMode)
void mute_release(Pad &)
Definition: lpx.h:332
void capture_midi_release(Pad &)
Definition: lpx.h:338
static bool probe(std::string &, std::string &)
void note_release(Pad &)
Definition: lpx.h:310
PBD::ScopedConnectionList control_connections
Definition: lpx.h:363
void handle_midi_sysex(MIDI::Parser &, MIDI::byte *, size_t count)
std::shared_ptr< ARDOUR::Port > _daw_out
Definition: lpx.h:242
void right_long_press(Pad &)
Definition: lpx.h:305
std::shared_ptr< ARDOUR::Port > _daw_in
Definition: lpx.h:241
bool has_editor() const
Definition: lpx.h:109
int set_state(const XMLNode &node, int version)
void capture_midi_long_press(Pad &)
Definition: lpx.h:339
void handle_midi_controller_message(MIDI::Parser &, MIDI::EventTwoBytes *)
StripableSlotColumn stripable_slots
Definition: lpx.h:201
void mute_long_press(Pad &)
Definition: lpx.h:333
int find_closest_palette_color(uint32_t)
std::string input_port_name() const
std::set< int > consumed
Definition: lpx.h:192
void session_long_press(Pad &)
Definition: lpx.h:308
void trigger_property_change(PBD::PropertyChange, ARDOUR::Trigger *)
void record_arm_release(Pad &)
Definition: lpx.h:335
Definition: xml++.h:114
#define LAUNCHPAD_NAMESPACE
Definition: lpx.h:61
PBD::PropertyDescriptor< uint32_t > color
DebugBits Solo
MIDI::byte status_byte() const
Definition: lpx.h:168
Pad(PadID pid, ButtonMethod press_method, ButtonMethod long_press_method=&LaunchPadX::relax, ButtonMethod release_method=&LaunchPadX::relax)
Definition: lpx.h:148
Pad(int pid, int xx, int yy, PadMethod press_method, ButtonMethod long_press_method=&LaunchPadX::relax, ButtonMethod release_method=&LaunchPadX::relax)
Definition: lpx.h:158
sigc::connection timeout_connection
Definition: lpx.h:187