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