push2: when playing pads, flash all pad LEDs for the same note number for the pressed pad

This commit is contained in:
Paul Davis 2016-09-22 10:27:21 -05:00
parent 0add64d4ab
commit cb340bf190
2 changed files with 63 additions and 24 deletions

View File

@ -793,24 +793,37 @@ Push2::handle_midi_note_on_message (MIDI::Parser& parser, MIDI::EventTwoBytes* e
return; return;
} }
/* Pad */ /* Pad illuminations */
NNPadMap::iterator pi = nn_pad_map.find (ev->note_number); NNPadMap::const_iterator pm = nn_pad_map.find (ev->note_number);
if (pi == nn_pad_map.end()) { if (pm == nn_pad_map.end()) {
return; return;
} }
Pad* pad = pi->second; const Pad * const pad_pressed = pm->second;
if (pad->do_when_pressed == Pad::FlashOn) { pair<FNPadMap::iterator,FNPadMap::iterator> pads_with_note = fn_pad_map.equal_range (pad_pressed->filtered);
pad->set_color (LED::White);
pad->set_state (LED::OneShot24th); if (pads_with_note.first == fn_pad_map.end()) {
write (pad->state_msg()); return;
} else if (pad->do_when_pressed == Pad::FlashOff) { }
pad->set_color (LED::Black);
pad->set_state (LED::OneShot24th); for (FNPadMap::iterator pi = pads_with_note.first; pi != pads_with_note.second; ++pi) {
write (pad->state_msg()); Pad* pad = pi->second;
if (pad->do_when_pressed == Pad::FlashOn) {
pad->set_color (LED::White);
pad->set_state (LED::OneShot24th);
write (pad->state_msg());
} else if (pad->do_when_pressed == Pad::FlashOff) {
/* XXX really need to pick a contrasting color from
selection color here.
*/
pad->set_color (LED::Green);
pad->set_state (LED::OneShot24th);
write (pad->state_msg());
}
} }
} }
@ -827,22 +840,34 @@ Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
return; return;
} }
NNPadMap::iterator pi = nn_pad_map.find (ev->note_number); /* Pad illuminations */
if (pi == nn_pad_map.end()) { NNPadMap::const_iterator pm = nn_pad_map.find (ev->note_number);
if (pm == nn_pad_map.end()) {
return; return;
} }
Pad* pad = pi->second; const Pad * const pad_pressed = pm->second;
if (pad->do_when_pressed == Pad::FlashOn) { pair<FNPadMap::iterator,FNPadMap::iterator> pads_with_note = fn_pad_map.equal_range (pad_pressed->filtered);
pad->set_color (LED::Black);
pad->set_state (LED::OneShot24th); if (pads_with_note.first == fn_pad_map.end()) {
write (pad->state_msg()); return;
} else if (pad->do_when_pressed == Pad::FlashOff) { }
pad->set_color (pad->perma_color);
pad->set_state (LED::OneShot24th); for (FNPadMap::iterator pi = pads_with_note.first; pi != pads_with_note.second; ++pi) {
write (pad->state_msg()); Pad* pad = pi->second;
if (pad->do_when_pressed == Pad::FlashOn) {
pad->set_color (LED::Black);
pad->set_state (LED::OneShot24th);
write (pad->state_msg());
} else if (pad->do_when_pressed == Pad::FlashOff) {
pad->set_color (pad->perma_color);
pad->set_state (LED::OneShot24th);
write (pad->state_msg());
}
} }
} }
@ -1298,10 +1323,13 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey)
} }
} }
fn_pad_map.clear ();
if (inkey) { if (inkey) {
vector<int>::iterator notei; vector<int>::iterator notei;
int row_offset = 0; int row_offset = 0;
for (int row = 0; row < 8; ++row) { for (int row = 0; row < 8; ++row) {
/* Ableton's grid layout wraps the available notes in the scale /* Ableton's grid layout wraps the available notes in the scale
@ -1321,6 +1349,8 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey)
notenum = *notei; notenum = *notei;
pad->filtered = notenum; pad->filtered = notenum;
fn_pad_map.insert (make_pair (notenum, pad));
if ((notenum % 12) == original_root) { if ((notenum % 12) == original_root) {
pad->set_color (selection_color); pad->set_color (selection_color);
pad->perma_color = selection_color; pad->perma_color = selection_color;
@ -1358,6 +1388,8 @@ Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey)
pad->filtered = root_start + (note - 36); pad->filtered = root_start + (note - 36);
fn_pad_map.insert (make_pair (pad->filtered, pad));
if (mode_map.find (note) != mode_map.end()) { if (mode_map.find (note) != mode_map.end()) {
if ((note % 12) == original_root) { if ((note % 12) == original_root) {

View File

@ -392,10 +392,17 @@ class Push2 : public ARDOUR::ControlProtocol
void init_buttons (bool startup); void init_buttons (bool startup);
void init_touch_strip (); void init_touch_strip ();
/* map of Pads by note number */ /* map of Pads by note number (the "fixed" note number sent by the
* hardware, not the note number generated if the pad is touched)
*/
typedef std::map<int,Pad*> NNPadMap; typedef std::map<int,Pad*> NNPadMap;
NNPadMap nn_pad_map; NNPadMap nn_pad_map;
/* map of Pads by note number they generate (their "filtered" value)
*/
typedef std::multimap<int,Pad*> FNPadMap;
FNPadMap fn_pad_map;
void set_button_color (ButtonID, uint8_t color_index); void set_button_color (ButtonID, uint8_t color_index);
void set_button_state (ButtonID, LED::State); void set_button_state (ButtonID, LED::State);
void set_led_color (ButtonID, uint8_t color_index); void set_led_color (ButtonID, uint8_t color_index);