From b440488295cf792d6f71a7bf2a78ae2a991ab12b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 8 Sep 2023 14:41:06 -0600 Subject: [PATCH] launchpad pro: provide velocity info when launching clips/triggers --- libs/surfaces/launchpad_pro/lppro.cc | 8 +++--- libs/surfaces/launchpad_pro/lppro.h | 42 ++++++++++++++++++---------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/libs/surfaces/launchpad_pro/lppro.cc b/libs/surfaces/launchpad_pro/lppro.cc index 717a2ea755..c6940eafdb 100644 --- a/libs/surfaces/launchpad_pro/lppro.cc +++ b/libs/surfaces/launchpad_pro/lppro.cc @@ -810,7 +810,7 @@ LaunchPadPro::handle_midi_note_on_message (MIDI::Parser& parser, MIDI::EventTwoB Pad& pad (p->second); maybe_start_press_timeout (pad); - (this->*pad.on_press) (pad); + (this->*pad.on_pad_press) (pad, ev->velocity); } void @@ -1531,9 +1531,9 @@ LaunchPadPro::lower8_press (Pad& pad) } void -LaunchPadPro::pad_press (Pad& pad) +LaunchPadPro::pad_press (Pad& pad, int velocity) { - DEBUG_TRACE (DEBUG::Launchpad, string_compose ("pad press on %1, %2 => %3\n", pad.x, pad.y, pad.id)); + DEBUG_TRACE (DEBUG::Launchpad, string_compose ("pad press on %1, %2 => %3 vel %4\n", pad.x, pad.y, pad.id, velocity)); if (_clear_pressed) { TriggerPtr tp = session->trigger_at (pad.x, pad.y); @@ -1543,7 +1543,7 @@ LaunchPadPro::pad_press (Pad& pad) return; } - session->bang_trigger_at (pad.x, pad.y); + session->bang_trigger_at (pad.x, pad.y, velocity / 127.0f); start_press_timeout (pad); } diff --git a/libs/surfaces/launchpad_pro/lppro.h b/libs/surfaces/launchpad_pro/lppro.h index f922cdf30e..83d51b20bd 100644 --- a/libs/surfaces/launchpad_pro/lppro.h +++ b/libs/surfaces/launchpad_pro/lppro.h @@ -187,25 +187,28 @@ class LaunchPadPro : public MIDISurface Pulsing = 0x2 }; - typedef void (LaunchPadPro::*PadMethod)(Pad&); + typedef void (LaunchPadPro::*ButtonMethod)(Pad&); + typedef void (LaunchPadPro::*PadMethod)(Pad&, int velocity); - Pad (PadID pid, PadMethod press_method, PadMethod long_press_method = &LaunchPadPro::relax, PadMethod release_method = &LaunchPadPro::relax) + Pad (PadID pid, ButtonMethod press_method, ButtonMethod long_press_method = &LaunchPadPro::relax, ButtonMethod release_method = &LaunchPadPro::relax) : id (pid) , x (-1) , y (-1) - , on_press (press_method) - , on_release (release_method) - , on_long_press (long_press_method) - {} + { + on_press = press_method; + on_release = release_method; + on_long_press = long_press_method; + } - Pad (int pid, int xx, int yy, PadMethod press_method, PadMethod long_press_method = &LaunchPadPro::relax, PadMethod release_method = &LaunchPadPro::relax) + Pad (int pid, int xx, int yy, PadMethod press_method, ButtonMethod long_press_method = &LaunchPadPro::relax, ButtonMethod release_method = &LaunchPadPro::relax) : id (pid) , x (xx) , y (yy) - , on_press (press_method) - , on_release (release_method) - , on_long_press (long_press_method) - {} + { + on_pad_press = press_method; + on_release = release_method; + on_long_press = long_press_method; + } MIDI::byte status_byte() const { if (x < 0) return 0xb0; return 0x90; } bool is_pad () const { return x >= 0; } @@ -214,9 +217,18 @@ class LaunchPadPro : public MIDISurface int id; int x; int y; - PadMethod on_press; - PadMethod on_release; - PadMethod on_long_press; + + /* It's either a button (CC number) or a pad (note number + * w/velocity info), never both. + */ + union { + ButtonMethod on_press; + PadMethod on_pad_press; + }; + + ButtonMethod on_release; + ButtonMethod on_long_press; + sigc::connection timeout_connection; }; @@ -438,7 +450,7 @@ class LaunchPadPro : public MIDISurface void fader_long_press (Pad&); void fader_release (Pad&); - void pad_press (Pad&); + void pad_press (Pad&, int velocity); void pad_long_press (Pad&); void trigger_property_change (PBD::PropertyChange, ARDOUR::Trigger*);