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