Ardour  9.0-pre0-582-g084a23a80d
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/mode.h"
37 #include "ardour/types.h"
38 
40 #include "control_protocol/types.h"
41 
42 #include "gtkmm2ext/colors.h"
43 
46 
47 namespace MIDI {
48  class Parser;
49  class Port;
50 }
51 
52 namespace ARDOUR {
53  class AutomationControl;
54  class Plugin;
55  class PluginInsert;
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 LK4_GUI;
71 
72 class LaunchKey4 : 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 
79  enum ButtonID {
80  Button1 = 0x25,
81  Button2 = 0x26,
82  Button3 = 0x27,
83  Button4 = 0x28,
84  Button5 = 0x29,
85  Button6 = 0x2a,
86  Button7 = 0x2b,
87  Button8 = 0x2c,
88  Button9 = 0x2d,
89 
90  Volume = 0x0b,
91  Custom1 = 0x0c,
92  Custom2 = 0x0d,
93  Custom3 = 0x0e,
94  Custom4 = 0x0f,
95  PartA = 0x10,
96  PartB = 0x11,
97  Split = 0x12,
98  Layer = 0x13,
99  Shift = 0x13,
100  // Settings = 0x23,
101  TrackLeft = 0x67,
102  TrackRight =0x66,
103  Up = 0x6a,
104  Down = 0x6b,
105  CaptureMidi = 0x3,
106  Undo = 0x4d,
107  Quantize = 0x4b,
108  Metronome = 0x4c,
109  // Stop = 0x34 .. sends Stop
110  // Play = 0x36 .. sends Play
111  Play = 0x73,
112  Stop = 0x74,
113  RecEnable = 0x75,
114  Loop = 0x76,
115  Function = 0x69,
116  Scene = 0x68,
117  EncUp = 0x33,
118  EncDown = 0x44,
119  };
120 
121  enum KnobID {
122  Knob1 = 0x55,
123  Knob2 = 0x56,
124  Knob3 = 0x57,
125  Knob4 = 0x58,
126  Knob5 = 0x59,
127  Knob6 = 0x5a,
128  Knob7 = 0x5b,
129  Knob8 = 0x5c,
130  };
131 
134 
135  static bool available ();
136  static bool match_usb (uint16_t, uint16_t);
137  static bool probe (std::string&, std::string&);
138 
139  std::string input_port_name () const;
140  std::string output_port_name () const;
141 
142  bool has_editor () const { return true; }
143  void* get_gui () const;
144  void tear_down_gui ();
145 
146  int set_active (bool yn);
147  XMLNode& get_state() const;
148  int set_state (const XMLNode & node, int version);
149 
150  private:
151  enum FaderBank {
156  };
157 
158  struct Pad {
159 
160  enum ColorMode {
161  Static = 0x0,
162  Flashing = 0x1,
163  Pulsing = 0x2
164  };
165 
166  typedef void (LaunchKey4::*PadMethod)(Pad&, int velocity);
167 
168  Pad (int pid, int xx, int yy)
169  : id (pid)
170  , x (xx)
171  , y (yy)
172  {
173  }
174 
175  Pad () : id (-1), x (-1), y (-1)
176  {
177  }
178 
179 
180  int id;
181  int x;
182  int y;
183 
184  sigc::connection timeout_connection;
185  };
186 
187  void relax (Pad& p);
188  void relax (Pad&, int);
189 
190  std::set<int> consumed;
191 
192  Pad pads[16];
193  void build_pad_map ();
194 
195  typedef std::map<int,uint32_t> ColorMap;
199 
200  typedef std::map<uint32_t,int> NearestMap;
202 
205  int device_acquire () { return 0; }
206  void device_release () { }
207  void run_event_loop ();
209 
211 
213  void select_stripable (int col);
214  std::weak_ptr<ARDOUR::MidiTrack> _current_pad_target;
215 
220  void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
221 
224  std::shared_ptr<ARDOUR::Port> _daw_in;
225  std::shared_ptr<ARDOUR::Port> _daw_out;
226 
229  void ports_release ();
231 
232  void daw_write (const MidiByteArray&);
233  void daw_write (MIDI::byte const *, size_t);
234 
237 
238  mutable LK4_GUI* _gui;
239  void build_gui ();
240 
243  bool long_press_timeout (int pad_id);
244 
245  void button_press (int button);
246  void button_release (int button);
247 
249  void trigger_pad_light (Pad& pad, std::shared_ptr<ARDOUR::Route> r, ARDOUR::Trigger* t);
251 
255 
256  void map_selection ();
257  void map_mute_solo ();
258  void map_rec_enable ();
259  void map_triggers ();
260 
261  void map_triggerbox (int col);
262 
265 
266  void fader_move (int which, int val);
267  void automation_control_change (int n, std::weak_ptr<ARDOUR::AutomationControl>);
271 
272  void use_encoders (bool);
273  void encoder (int which, int step);
274  void knob (int which, int value);
275 
278 
279  uint16_t device_pid;
280 
282  StationaryDisplay = 0x20,
283  GlobalTemporaryDisplay = 0x21,
284  DAWPadFunctionDisplay = 0x22,
285  DawDrumrackModeDisplay = 0x23,
286  MixerPotMode = 0x24,
287  PluginPotMode = 0x25,
288  SendPotMode = 0x26,
289  TransportPotMode = 0x27,
290  FaderMode = 0x28,
291  };
292 
294  void set_display_target (DisplayTarget dt, int field, std::string const &, bool display = false);
295  void configure_display (DisplayTarget dt, int config);
296  void set_plugin_encoder_name (int encoder, int field, std::string const &);
297 
298  void set_daw_mode (bool);
300 
301  enum PadFunction {
304  };
305 
309  void pad_trigger (Pad&, int velocity);
310  void pad_release (Pad&);
311 
314 
315  void function_press ();
316  void undo_press ();
318  void quantize_press ();
319  void button_left ();
320  void button_right ();
321  void button_down ();
322  void button_up ();
323 
324  /* stripables */
325 
326  int32_t bank_start;
328  std::shared_ptr<ARDOUR::Stripable> stripable[8];
330  void stripable_property_change (PBD::PropertyChange const& what_changed, uint32_t which);
331  void switch_bank (uint32_t);
332 
333  void solo_changed ();
334  void mute_changed (uint32_t which);
335  void rec_enable_changed (uint32_t which);
336 
342  };
343 
344  void light_button (int which, LightingMode, int color_index);
345  void light_pad (int pid, LightingMode, int color_index);
346 
347  enum ButtonMode {
349  ButtonsSelect
350  };
351 
353 
355  void show_selection (int which);
356  void show_rec_enable (int which);
357  void show_mute (int which);
358  void show_solo (int which);
359 
360  enum EncoderMode {
364  EncoderTransport
365  };
366 
369  void set_encoder_bank (int);
373  void label_encoders ();
374  void show_encoder_value (int which, std::shared_ptr<ARDOUR::Plugin> plugin, int control, std::shared_ptr<ARDOUR::AutomationControl> ac, bool display);
375 
376  void encoder_plugin (int which, int step);
377  void encoder_mixer (int which, int step);
378  void encoder_pan (int which, int step);
379  void encoder_level (int which, int step);
380  void encoder_senda (int which, int step);
381  void encoder_transport (int which, int step);
382 
383  void transport_shuttle (int step);
384  void zoom (int step);
385  void loop_start_move (int step);
386  void loop_end_move (int step);
387  void jump_to_marker (int step);
388 
389  void light_pad (int pad_id, int color_index);
390  void unlight_pad (int pad_id);
391  void all_pads (int color_index);
392  void all_pads_out ();
393 
394  void show_scene_ids ();
395  void scene_press ();
396 
397  void in_msecs (int msecs, std::function<void()> func);
398 
399  std::weak_ptr<ARDOUR::AutomationControl> controls[24];
400  std::weak_ptr<ARDOUR::Plugin> current_plugin;
401  void plugin_selected (std::weak_ptr<ARDOUR::PluginInsert>);
403 };
404 
405 
406 } } /* namespaces */
407 
408 #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:225
void handle_midi_note_off_message(MIDI::Parser &, MIDI::EventTwoBytes *)
PBD::ScopedConnectionList trigger_connections
Definition: launchkey_4.h:250
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:214
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:200
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:195
void maybe_start_press_timeout(Pad &pad)
std::weak_ptr< ARDOUR::Plugin > current_plugin
Definition: launchkey_4.h:400
std::shared_ptr< ARDOUR::Port > _daw_in
Definition: launchkey_4.h:224
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:264
PBD::ScopedConnectionList stripable_connections
Definition: launchkey_4.h:327
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:268
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:65
Pad(int pid, int xx, int yy)
Definition: launchkey_4.h:168
link region and track false waveform clip max inline controls