From 6627d24c2b79e62185fe38f0c2e9ec03dbe3c8b6 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 27 Aug 2022 15:53:03 -0600 Subject: [PATCH] push2: add an (x,y) map for pads and use it --- libs/surfaces/push2/buttons.cc | 3 ++- libs/surfaces/push2/cues.cc | 49 +++++++++++++++------------------- libs/surfaces/push2/push2.cc | 18 +++++++++---- libs/surfaces/push2/push2.h | 13 ++++++--- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/libs/surfaces/push2/buttons.cc b/libs/surfaces/push2/buttons.cc index 7ca4f61d2b..44cdcac93e 100644 --- a/libs/surfaces/push2/buttons.cc +++ b/libs/surfaces/push2/buttons.cc @@ -40,7 +40,8 @@ Push2::build_maps () #define MAKE_PAD(x,y,nn) \ pad.reset (new Pad ((x), (y), (nn))); \ - _nn_pad_map.insert (std::make_pair (pad->extra(), pad)); + _nn_pad_map.insert (std::make_pair (pad->extra(), pad)); \ + _xy_pad_map.insert (std::make_pair (y * 8 + x, pad)); MAKE_PAD (0, 0, 92); MAKE_PAD (0, 1, 93); diff --git a/libs/surfaces/push2/cues.cc b/libs/surfaces/push2/cues.cc index 7f2579d29a..7b750c6c93 100644 --- a/libs/surfaces/push2/cues.cc +++ b/libs/surfaces/push2/cues.cc @@ -261,6 +261,7 @@ void CueLayout::button_lower (uint32_t n) { if (_p2.stop_down()) { + std::cerr << "stop trigger in " << n + track_base << std::endl; _p2.unbang (n + track_base); } else { /* select track */ @@ -440,26 +441,23 @@ CueLayout::update_labels () /* total map size is only 64 so iterating over the whole thing is fine */ for (int y = 0; y < 8; ++y) { - for (auto & pad : _p2.nn_pad_map()) { - if (pad.second->y == n && pad.second->x == y) { - if (tb && tb->active()) { - TriggerPtr tp = tb->trigger (y); - if (tp && tp->region()) { - /* trigger in slot */ - pad.second->set_color (color); - } else { - /* no trigger */ - pad.second->set_color (Push2::LED::Black); - } - } else { - /* no active triggerbox */ - pad.second->set_color (Push2::LED::Black); - } - pad.second->set_state (Push2::LED::OneShot24th); - _p2.write (pad.second->state_msg()); - break; + boost::shared_ptr pad = _p2.pad_by_xy (n, y); + if (tb && tb->active()) { + TriggerPtr tp = tb->trigger (y); + if (tp && tp->region()) { + /* trigger in slot */ + pad->set_color (color); + } else { + /* no trigger */ + pad->set_color (Push2::LED::Black); } + } else { + /* no active triggerbox */ + pad->set_color (Push2::LED::Black); } + pad->set_state (Push2::LED::OneShot24th); + _p2.write (pad->state_msg()); + } } else { @@ -467,14 +465,10 @@ CueLayout::update_labels () /* turn this column off */ for (int y = 0; y < 8; ++y) { - for (auto & pad : _p2.nn_pad_map()) { - if (pad.second->y == n && pad.second->x == y) { - pad.second->set_color (Push2::LED::Black); - pad.second->set_state (Push2::LED::OneShot24th); - _p2.write (pad.second->state_msg()); - break; - } - } + boost::shared_ptr pad = _p2.pad_by_xy (n, y); + pad->set_color (Push2::LED::Black); + pad->set_state (Push2::LED::OneShot24th); + _p2.write (pad->state_msg()); } } } @@ -520,7 +514,8 @@ CueLayout::button_stop_press () void CueLayout::pad_press (int x, int y) { - _p2.bang (x + track_base, y + scene_base); + std::cerr << "bang on " << x + track_base << ", " << y + scene_base << std::endl; + _p2.bang (y + scene_base, x + track_base); } void diff --git a/libs/surfaces/push2/push2.cc b/libs/surfaces/push2/push2.cc index bfd165e65e..68237f8982 100644 --- a/libs/surfaces/push2/push2.cc +++ b/libs/surfaces/push2/push2.cc @@ -445,7 +445,7 @@ Push2::init_buttons (bool startup) _current_layout->hide (); } - for (NNPadMap::iterator pi = _nn_pad_map.begin(); pi != _nn_pad_map.end(); ++pi) { + for (PadMap::iterator pi = _nn_pad_map.begin(); pi != _nn_pad_map.end(); ++pi) { boost::shared_ptr pad = pi->second; pad->set_color (LED::Black); @@ -802,7 +802,7 @@ Push2::handle_midi_note_on_message (MIDI::Parser& parser, MIDI::EventTwoBytes* e /* Pad illuminations */ - NNPadMap::const_iterator pm = _nn_pad_map.find (ev->note_number); + PadMap::const_iterator pm = _nn_pad_map.find (ev->note_number); if (pm == _nn_pad_map.end()) { return; @@ -845,7 +845,7 @@ Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev) /* Pad illuminations */ - NNPadMap::const_iterator pm = _nn_pad_map.find (ev->note_number); + PadMap::const_iterator pm = _nn_pad_map.find (ev->note_number); if (pm == _nn_pad_map.end()) { return; @@ -1171,7 +1171,7 @@ Push2::pad_filter (MidiBuffer& in, MidiBuffer& out) const if ((*ev).note() > 10 && (*ev).note() != 12) { const int n = (*ev).note (); - NNPadMap::const_iterator nni = _nn_pad_map.find (n); + PadMap::const_iterator nni = _nn_pad_map.find (n); if (nni != _nn_pad_map.end()) { boost::shared_ptr pad = nni->second; @@ -1314,7 +1314,7 @@ Push2::input_port() int Push2::pad_note (int row, int col) const { - NNPadMap::const_iterator nni = _nn_pad_map.find (36+(row*8)+col); + PadMap::const_iterator nni = _nn_pad_map.find (36+(row*8)+col); if (nni != _nn_pad_map.end()) { return nni->second->filtered; @@ -1902,3 +1902,11 @@ Push2::set_pressure_mode (PressureMode pm) write (msg); } + +boost::shared_ptr +Push2::pad_by_xy (int x, int y) +{ + Push2::PadMap::iterator p = _xy_pad_map.find ((x * 8) +y); + assert (p != _xy_pad_map.end()); + return p->second; +} diff --git a/libs/surfaces/push2/push2.h b/libs/surfaces/push2/push2.h index 4b8fca9908..89c7f005ca 100644 --- a/libs/surfaces/push2/push2.h +++ b/libs/surfaces/push2/push2.h @@ -453,8 +453,11 @@ class Push2 : public ARDOUR::ControlProtocol bool stop_down () const { return _stop_down; } - typedef std::map > NNPadMap; - NNPadMap const & nn_pad_map() const { return _nn_pad_map; } + typedef std::map > PadMap; + PadMap const & nn_pad_map() const { return _nn_pad_map; } + PadMap const & xy_pad_map() const { return _xy_pad_map; } + + boost::shared_ptr pad_by_xy (int x, int y); CONTROL_PROTOCOL_THREADS_NEED_TEMPO_MAP_DECL(); @@ -494,7 +497,11 @@ class Push2 : public ARDOUR::ControlProtocol /* map of Pads by note number (the "fixed" note number sent by the * hardware, not the note number generated if the pad is touched) */ - NNPadMap _nn_pad_map; + PadMap _nn_pad_map; + + /* map of Pads by x,y duple (computed as (x*8) + y */ + + PadMap _xy_pad_map; /* map of Pads by note number they generate (their "filtered" value) */