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