From a6cd0a3f6e34ed350e59ec4f98d29c6fba767b74 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 19 Jun 2021 16:32:43 -0400 Subject: [PATCH] Push2: Ensure every pad is set up once when the grid layout changes This juggles the implementation slightly in a way that's more resilient to mistakes: the representation of pads in the surfaces is always fully reset before setting up the grid, and a state message is sent for every single pad once after the scale algorithm sets things up. This means that scale algorithms don't need to deal with hairy edge cases like running off the end of the scale or the valid range of MIDI notes. --- libs/surfaces/push2/push2.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index 5087ecabbf..b725aa50ba 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -1342,7 +1342,6 @@ Push2::set_pad_note_kind (Pad& pad, const PadNoteKind kind) } pad.set_state (LED::OneShot24th); - write (pad.state_msg ()); } /** Return a bitset of notes in a musical mode. @@ -1516,9 +1515,21 @@ Push2::set_pad_scale (const int scale_root, const RowInterval row_interval, const bool inkey) { - // Clear the pad map and call the appropriate method to set them up again + // Clear the pad map and reset all pad state (in memory, not on the device yet) _fn_pad_map.clear (); + for (int row = 0; row < 8; ++row) { + for (int col = 0; col < 8; ++col) { + const int index = 36 + (row * 8) + col; + const boost::shared_ptr& pad = _nn_pad_map[index]; + + pad->set_color (LED::Black); + pad->filtered = -1; + pad->do_when_pressed = Pad::FlashOn; + } + } + + // Call the appropriate method to set up active pads const int vertical_semitones = row_interval_semitones(row_interval); if (inkey) { @@ -1527,6 +1538,17 @@ Push2::set_pad_scale (const int scale_root, set_pad_scale_chromatic(scale_root, octave, mode, origin, vertical_semitones); } + // Write the state message for every pad + + for (int row = 0; row < 8; ++row) { + for (int col = 0; col < 8; ++col) { + const int index = 36 + (row * 8) + col; + const boost::shared_ptr& pad = _nn_pad_map[index]; + + write (pad->state_msg ()); + } + } + // Store state bool changed = false;