Ardour  9.2-541-gc1841a13dd
launchkey_4.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_lk4_h__
20 #define __ardour_lk4_h__
21 
22 #include <functional>
23 #include <list>
24 #include <map>
25 #include <stack>
26 #include <set>
27 #include <vector>
28 
29 #ifdef COMPILER_MSVC
30 #define _WINSOCKAPI_
31 #endif
32 
33 #include <libusb.h>
34 
35 #define ABSTRACT_UI_EXPORTS
36 #include "pbd/abstract_ui.h"
37 
38 #include "midi++/types.h"
39 
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 Plugin;
58  class PluginInsert;
59  class Port;
60  class MidiBuffer;
61  class MidiTrack;
62  class Trigger;
63 }
64 
65 #ifdef LAUNCHPAD_MINI
66 #define LAUNCHPAD_NAMESPACE LP_MINI
67 #else
68 #define LAUNCHPAD_NAMESPACE LP_X
69 #endif
70 
71 namespace ArdourSurface { namespace LAUNCHPAD_NAMESPACE {
72 
73 class LK4_GUI;
74 
75 class LaunchKey4 : public MIDISurface
76 {
77  public:
78  /* use hex for these constants, because we'll see them (as note numbers
79  and CC numbers) in hex within MIDI messages when debugging.
80  */
81 
82  enum ButtonID {
83  Button1 = 0x25,
84  Button2 = 0x26,
85  Button3 = 0x27,
86  Button4 = 0x28,
87  Button5 = 0x29,
88  Button6 = 0x2a,
89  Button7 = 0x2b,
90  Button8 = 0x2c,
91  Button9 = 0x2d,
92 
93  Volume = 0x0b,
94  Custom1 = 0x0c,
95  Custom2 = 0x0d,
96  Custom3 = 0x0e,
97  Custom4 = 0x0f,
98  PartA = 0x10,
99  PartB = 0x11,
100  Split = 0x12,
101  Layer = 0x13,
102  Shift = 0x13,
103  // Settings = 0x23,
104  TrackLeft = 0x67,
105  TrackRight =0x66,
106  Up = 0x6a,
107  Down = 0x6b,
108  CaptureMidi = 0x3,
109  Undo = 0x4d,
110  Quantize = 0x4b,
111  Metronome = 0x4c,
112  // Stop = 0x34 .. sends Stop
113  // Play = 0x36 .. sends Play
114  Play = 0x73,
115  Stop = 0x74,
116  RecEnable = 0x75,
117  Loop = 0x76,
118  Function = 0x69,
119  Scene = 0x68,
120  EncUp = 0x33,
121  EncDown = 0x44,
122  };
123 
124  enum KnobID {
125  Knob1 = 0x55,
126  Knob2 = 0x56,
127  Knob3 = 0x57,
128  Knob4 = 0x58,
129  Knob5 = 0x59,
130  Knob6 = 0x5a,
131  Knob7 = 0x5b,
132  Knob8 = 0x5c,
133  };
134 
137 
138  static bool available ();
139  static bool match_usb (uint16_t, uint16_t);
140  static bool probe (std::string&, std::string&);
141 
142  std::string input_port_name () const;
143  std::string output_port_name () const;
144 
145  bool has_editor () const { return true; }
146  void* get_gui () const;
147  void tear_down_gui ();
148 
149  int set_active (bool yn);
150  XMLNode& get_state() const;
151  int set_state (const XMLNode & node, int version);
152 
153  private:
154  enum FaderBank {
159  };
160 
161  struct Pad {
162 
163  enum ColorMode {
164  Static = 0x0,
165  Flashing = 0x1,
166  Pulsing = 0x2
167  };
168 
169  typedef void (LaunchKey4::*PadMethod)(Pad&, int velocity);
170 
171  Pad (int pid, int xx, int yy)
172  : id (pid)
173  , x (xx)
174  , y (yy)
175  {
176  }
177 
178  Pad () : id (-1), x (-1), y (-1)
179  {
180  }
181 
182 
183  int id;
184  int x;
185  int y;
186 
187  sigc::connection timeout_connection;
188  };
189 
190  void relax (Pad& p);
191  void relax (Pad&, int);
192 
193  std::set<int> consumed;
194 
195  Pad pads[16];
196  void build_pad_map ();
197 
198  typedef std::map<int,uint32_t> ColorMap;
202 
203  typedef std::map<uint32_t,int> NearestMap;
205 
208  int device_acquire () { return 0; }
209  void device_release () { }
210  void run_event_loop ();
212 
214 
216  void select_stripable (int col);
217  std::weak_ptr<ARDOUR::MidiTrack> _current_pad_target;
218 
223  void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
224 
227  std::shared_ptr<ARDOUR::Port> _daw_in;
228  std::shared_ptr<ARDOUR::Port> _daw_out;
229 
232  void ports_release ();
234 
235  void daw_write (const MidiByteArray&);
236  void daw_write (MIDI::byte const *, size_t);
237 
240 
241  mutable LK4_GUI* _gui;
242  void build_gui ();
243 
246  bool long_press_timeout (int pad_id);
247 
248  void button_press (int button);
249  void button_release (int button);
250 
252  void trigger_pad_light (Pad& pad, std::shared_ptr<ARDOUR::Route> r, ARDOUR::Trigger* t);
254 
258 
259  void map_selection ();
260  void map_mute_solo ();
261  void map_rec_enable ();
262  void map_triggers ();
263 
264  void map_triggerbox (int col);
265 
268 
269  void fader_move (int which, int val);
270  void automation_control_change (int n, std::weak_ptr<ARDOUR::AutomationControl>);
274 
275  void use_encoders (bool);
276  void encoder (int which, int step);
277  void knob (int which, int value);
278 
281 
282  uint16_t device_pid;
283 
285  StationaryDisplay = 0x20,
286  GlobalTemporaryDisplay = 0x21,
287  DAWPadFunctionDisplay = 0x22,
288  DawDrumrackModeDisplay = 0x23,
289  MixerPotMode = 0x24,
290  PluginPotMode = 0x25,
291  SendPotMode = 0x26,
292  TransportPotMode = 0x27,
293  FaderMode = 0x28,
294  };
295 
297  void set_display_target (DisplayTarget dt, int field, std::string const &, bool display = false);
298  void configure_display (DisplayTarget dt, int config);
299  void set_plugin_encoder_name (int encoder, int field, std::string const &);
300 
301  void set_daw_mode (bool);
303 
304  enum PadFunction {
307  };
308 
312  void pad_trigger (Pad&, int velocity);
313  void pad_release (Pad&);
314 
317 
318  void function_press ();
319  void undo_press ();
321  void quantize_press ();
322  void button_left ();
323  void button_right ();
324  void button_down ();
325  void button_up ();
326 
327  /* stripables */
328 
329  int32_t bank_start;
331  std::shared_ptr<ARDOUR::Stripable> stripable[8];
333  void stripable_property_change (PBD::PropertyChange const& what_changed, uint32_t which);
334  void switch_bank (uint32_t);
335 
336  void solo_changed ();
337  void mute_changed (uint32_t which);
338  void rec_enable_changed (uint32_t which);
339 
345  };
346 
347  void light_button (int which, LightingMode, int color_index);
348  void light_pad (int pid, LightingMode, int color_index);
349 
350  enum ButtonMode {
352  ButtonsSelect
353  };
354 
356 
358  void show_selection (int which);
359  void show_rec_enable (int which);
360  void show_mute (int which);
361  void show_solo (int which);
362 
363  enum EncoderMode {
367  EncoderTransport
368  };
369 
372  void set_encoder_bank (int);
376  void label_encoders ();
377  void show_encoder_value (int which, std::shared_ptr<ARDOUR::Plugin> plugin, int control, std::shared_ptr<ARDOUR::AutomationControl> ac, bool display);
378 
379  void encoder_plugin (int which, int step);
380  void encoder_mixer (int which, int step);
381  void encoder_pan (int which, int step);
382  void encoder_level (int which, int step);
383  void encoder_senda (int which, int step);
384  void encoder_transport (int which, int step);
385 
386  void transport_shuttle (int step);
387  void zoom (int step);
388  void loop_start_move (int step);
389  void loop_end_move (int step);
390  void jump_to_marker (int step);
391 
392  void light_pad (int pad_id, int color_index);
393  void unlight_pad (int pad_id);
394  void all_pads (int color_index);
395  void all_pads_out ();
396 
397  void show_scene_ids ();
398  void scene_press ();
399 
400  void in_msecs (int msecs, std::function<void()> func);
401 
402  std::weak_ptr<ARDOUR::AutomationControl> controls[24];
403  std::weak_ptr<ARDOUR::Plugin> current_plugin;
404  void plugin_selected (std::weak_ptr<ARDOUR::PluginInsert>);
406 };
407 
408 
409 } } /* namespaces */
410 
411 #endif /* __ardour_lk4_h__ */
void show_encoder_value(int which, std::shared_ptr< ARDOUR::Plugin > plugin, int control, std::shared_ptr< ARDOUR::AutomationControl > ac, bool display)
std::shared_ptr< ARDOUR::Port > _daw_out
Definition: launchkey_4.h:228
void handle_midi_note_off_message(MIDI::Parser &, MIDI::EventTwoBytes *)
PBD::ScopedConnectionList trigger_connections
Definition: launchkey_4.h:253
void encoder_plugin(int which, int step)
void rec_enable_changed(uint32_t which)
void encoder_level(int which, int step)
std::weak_ptr< ARDOUR::MidiTrack > _current_pad_target
Definition: launchkey_4.h:217
void stripable_property_change(PBD::PropertyChange const &what_changed, uint32_t which)
void encoder_senda(int which, int step)
void fader_move(int which, int val)
void mute_changed(uint32_t which)
std::map< uint32_t, int > NearestMap
Definition: launchkey_4.h:203
LaunchKey4(ARDOUR::Session &)
void in_msecs(int msecs, std::function< void()> func)
int find_closest_palette_color(uint32_t)
void encoder_transport(int which, int step)
void select_display_target(DisplayTarget dt)
void pad_trigger(Pad &, int velocity)
void set_display_target(DisplayTarget dt, int field, std::string const &, bool display=false)
void trigger_property_change(PBD::PropertyChange, ARDOUR::Trigger *)
void encoder_pan(int which, int step)
std::map< int, uint32_t > ColorMap
Definition: launchkey_4.h:198
void maybe_start_press_timeout(Pad &pad)
std::weak_ptr< ARDOUR::Plugin > current_plugin
Definition: launchkey_4.h:403
std::shared_ptr< ARDOUR::Port > _daw_in
Definition: launchkey_4.h:227
void daw_write(MIDI::byte const *, size_t)
void light_button(int which, LightingMode, int color_index)
void daw_write(const MidiByteArray &)
void trigger_pad_light(Pad &pad, std::shared_ptr< ARDOUR::Route > r, ARDOUR::Trigger *t)
void set_encoder_mode(EncoderMode)
void plugin_selected(std::weak_ptr< ARDOUR::PluginInsert >)
void set_pad_function(PadFunction)
static bool match_usb(uint16_t, uint16_t)
void handle_midi_note_on_message(MIDI::Parser &, MIDI::EventTwoBytes *)
std::string output_port_name() const
int set_state(const XMLNode &node, int version)
PBD::ScopedConnectionList route_connections
Definition: launchkey_4.h:267
PBD::ScopedConnectionList stripable_connections
Definition: launchkey_4.h:330
void route_property_change(PBD::PropertyChange const &, int x)
void all_pads(int color_index)
void automation_control_change(int n, std::weak_ptr< ARDOUR::AutomationControl >)
void handle_midi_sysex(MIDI::Parser &, MIDI::byte *, size_t count)
PBD::ScopedConnectionList control_connections
Definition: launchkey_4.h:271
static bool probe(std::string &, std::string &)
void set_plugin_encoder_name(int encoder, int field, std::string const &)
void encoder(int which, int step)
void handle_midi_controller_message(MIDI::Parser &, MIDI::EventTwoBytes *)
void configure_display(DisplayTarget dt, int config)
void light_pad(int pad_id, int color_index)
std::string input_port_name() const
void encoder_mixer(int which, int step)
void knob(int which, int value)
bool long_press_timeout(int pad_id)
void light_pad(int pid, LightingMode, int color_index)
void handle_midi_controller_message_chnF(MIDI::Parser &, MIDI::EventTwoBytes *)
Definition: xml++.h:114
Function
Definition: gc.h:190
#define LAUNCHPAD_NAMESPACE
Definition: launchkey_4.h:68
Pad(int pid, int xx, int yy)
Definition: launchkey_4.h:171
link region and track false waveform clip max inline controls