13
0

push2: vector, not map

This commit is contained in:
Paul Davis 2022-08-27 16:03:01 -06:00
parent 6627d24c2b
commit 06abdb4c4e
3 changed files with 10 additions and 7 deletions

View File

@ -38,10 +38,12 @@ Push2::build_maps ()
boost::shared_ptr<Pad> pad; boost::shared_ptr<Pad> pad;
_xy_pad_map.assign (64, boost::shared_ptr<Pad>());
#define MAKE_PAD(x,y,nn) \ #define MAKE_PAD(x,y,nn) \
pad.reset (new 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)); _xy_pad_map[y * 8 + x] = pad;
MAKE_PAD (0, 0, 92); MAKE_PAD (0, 0, 92);
MAKE_PAD (0, 1, 93); MAKE_PAD (0, 1, 93);

View File

@ -1906,7 +1906,9 @@ Push2::set_pressure_mode (PressureMode pm)
boost::shared_ptr<Push2::Pad> boost::shared_ptr<Push2::Pad>
Push2::pad_by_xy (int x, int y) Push2::pad_by_xy (int x, int y)
{ {
Push2::PadMap::iterator p = _xy_pad_map.find ((x * 8) +y); vector<boost::shared_ptr<Pad> >::size_type index = (x * 8) + y;
assert (p != _xy_pad_map.end()); if (index >= _xy_pad_map.size()) {
return p->second; return boost::shared_ptr<Pad>();
}
return _xy_pad_map[index];
} }

View File

@ -455,7 +455,6 @@ class Push2 : public ARDOUR::ControlProtocol
typedef std::map<int,boost::shared_ptr<Pad> > PadMap; typedef std::map<int,boost::shared_ptr<Pad> > PadMap;
PadMap const & nn_pad_map() const { return _nn_pad_map; } 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); boost::shared_ptr<Pad> pad_by_xy (int x, int y);
@ -499,9 +498,9 @@ class Push2 : public ARDOUR::ControlProtocol
*/ */
PadMap _nn_pad_map; PadMap _nn_pad_map;
/* map of Pads by x,y duple (computed as (x*8) + y */ /* array of Pads by x,y duple (indexed as (x*8) + y */
PadMap _xy_pad_map; std::vector<boost::shared_ptr<Pad> > _xy_pad_map;
/* map of Pads by note number they generate (their "filtered" value) /* map of Pads by note number they generate (their "filtered" value)
*/ */