push2: use a map for direct lookup of pad note
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 7 Jul 2016 04:17:17 +0000 (00:17 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 27 Sep 2016 19:59:30 +0000 (14:59 -0500)
libs/surfaces/push2/push2.cc
libs/surfaces/push2/push2.h

index 17890e30c4b1e7ef57a7cf13bc5ef1b3da0e4a0b..0eb1d6cfc7aa12f02a9dfd81f12bc6245d6538aa 100644 (file)
@@ -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;
index 467fbe83b7626dc5ad8508f343fc4e10884124a5..f987cd63f2899b03f614e56e9de7870accc28a3d 100644 (file)
@@ -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;
 };