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