From b35796af75a227f335f6ccc43e306092004fc59c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 19 Jun 2021 00:48:55 -0400 Subject: [PATCH] Push2: Factor out set_pad_note_kind() Factors button details out of the scale algorithm, to make it more clear. --- libs/surfaces/push2/push2.cc | 65 ++++++++++++++++++------------------ libs/surfaces/push2/push2.h | 6 ++++ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index 0bfad6a0ce..3ffca29c6c 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -1306,6 +1306,30 @@ Push2::reset_pad_colors () set_pad_scale (_scale_root, _root_octave, _mode, _in_key); } +void +Push2::set_pad_note_kind (Pad& pad, const PadNoteKind kind) +{ + switch (kind) { + case RootNote: + pad.set_color (_selection_color); + pad.perma_color = _selection_color; + pad.do_when_pressed = Pad::FlashOff; + break; + case InScaleNote: + pad.set_color (LED::White); + pad.perma_color = LED::White; + pad.do_when_pressed = Pad::FlashOff; + break; + case OutOfScaleNote: + pad.set_color (LED::Black); + pad.do_when_pressed = Pad::FlashOn; + break; + } + + pad.set_state (LED::OneShot24th); + write (pad.state_msg ()); +} + void Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey) { @@ -1379,25 +1403,17 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey) _fn_pad_map.insert (make_pair (notenum, pad)); if ((notenum % 12) == original_root) { - pad->set_color (_selection_color); - pad->perma_color = _selection_color; + set_pad_note_kind(*pad, RootNote); } else { - pad->set_color (LED::White); - pad->perma_color = LED::White; + set_pad_note_kind(*pad, InScaleNote); } - pad->do_when_pressed = Pad::FlashOff; notei++; } else { - - pad->set_color (LED::Black); - pad->do_when_pressed = Pad::Nothing; pad->filtered = -1; + set_pad_note_kind(*pad, OutOfScaleNote); } - - pad->set_state (LED::OneShot24th); - write (pad->state_msg()); } } @@ -1417,29 +1433,14 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey) _fn_pad_map.insert (make_pair (pad->filtered, pad)); - if (mode_map.find (note) != mode_map.end()) { - - if ((note % 12) == original_root) { - pad->set_color (_selection_color); - pad->perma_color = _selection_color; - } else { - pad->set_color (LED::White); - pad->perma_color = LED::White; - } - - pad->do_when_pressed = Pad::FlashOff; - + if (mode_map.find (note) == mode_map.end()) { + pad->filtered = -1; + set_pad_note_kind(*pad, OutOfScaleNote); + } else if ((note % 12) == original_root) { + set_pad_note_kind(*pad, RootNote); } else { - - /* note is not in mode, turn it off */ - - pad->do_when_pressed = Pad::FlashOn; - pad->set_color (LED::Black); - + set_pad_note_kind(*pad, InScaleNote); } - - pad->set_state (LED::OneShot24th); - write (pad->state_msg()); } } diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index 6ee6a45a20..510da3fd8d 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -325,6 +325,12 @@ class Push2 : public ARDOUR::ControlProtocol void update_selection_color (); + /// "Kind" of pad that plays a note + enum PadNoteKind { RootNote, InScaleNote, OutOfScaleNote }; + + /// Set up a pad to represent a "kind" of note + void set_pad_note_kind(Pad& pad, PadNoteKind kind); + void set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey); PBD::Signal0 ScaleChange;