diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2016-07-07 00:17:17 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-09-27 14:59:30 -0500 |
commit | afef816a7bc90e46b5f1788c305591d22858ce6e (patch) | |
tree | 8cb74ce80ad6a58209274c28bf81dff60149ee43 /libs/surfaces | |
parent | 66453868cd18704babd08b52d4fd4ee5fcb67322 (diff) |
push2: use a map for direct lookup of pad note
Diffstat (limited to 'libs/surfaces')
-rw-r--r-- | libs/surfaces/push2/push2.cc | 35 | ||||
-rw-r--r-- | libs/surfaces/push2/push2.h | 2 |
2 files changed, 18 insertions, 19 deletions
diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index 17890e30c4..0eb1d6cfc7 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -1512,14 +1512,19 @@ Push2::pad_filter (MidiBuffer& in, MidiBuffer& out) const if ((*ev).note() > 10) { - /* shift for output to the shadow port */ - (*ev).set_note ((*ev).note() + (octave_shift*12)); + int n = (*ev).note (); - out.push_back (*ev); - - /* shift back so that the pads light correctly */ - (*ev).set_note ((*ev).note() - (octave_shift*12)); + map<int,int>::const_iterator ni = pad_map.find (n); + if (ni != pad_map.end()) { + /* shift for output to the shadow port */ + (*ev).set_note (ni->second); + out.push_back (*ev); + /* shift back so that the pads light correctly */ + (*ev).set_note (n); + } else { + out.push_back (*ev); + } matched = true; } @@ -1595,16 +1600,8 @@ Push2::input_port() void Push2::build_pad_table () { - for (int row = 0; row < 8; ++row ) { - for (int col = 0; col < 8; ++col) { - - /* top left pad sends note number 92 by default */ - - int note_number = 92 - (row*8+col); - note_number += (octave_shift * 12); - note_number = max (0, min (127, note_number)); - pad_table[row][col] = note_number; - } + for (int i = 36; i < 99; ++i) { + pad_map[i] = i + (octave_shift*12); } PadChange (); /* emit signal */ @@ -1613,8 +1610,10 @@ Push2::build_pad_table () uint8_t Push2::pad_note (int row, int col) const { - if (row < 8 && col < 8) { - return pad_table[row][col]; + map<int,int>::const_iterator ni = pad_map.find (row*8+col); + + if (ni != pad_map.end()) { + return ni->second; } return 0; diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index 467fbe83b7..f987cd63f2 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -488,7 +488,7 @@ class Push2 : public ARDOUR::ControlProtocol /* pad mapping */ - uint8_t pad_table[8][8]; + std::map<int,int> pad_map; void build_pad_table(); int octave_shift; }; |