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