push2: add an (x,y) map for pads and use it

This commit is contained in:
Paul Davis 2022-08-27 15:53:03 -06:00
parent a5dd6c1128
commit 6627d24c2b
4 changed files with 47 additions and 36 deletions

View File

@ -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);

View File

@ -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<Push2::Pad> 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<Push2::Pad> 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

View File

@ -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> 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<const Pad> 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>
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;
}

View File

@ -453,8 +453,11 @@ class Push2 : public ARDOUR::ControlProtocol
bool stop_down () const { return _stop_down; }
typedef std::map<int,boost::shared_ptr<Pad> > NNPadMap;
NNPadMap const & nn_pad_map() const { return _nn_pad_map; }
typedef std::map<int,boost::shared_ptr<Pad> > 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> 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)
*/