feat(bank_panel): audition, multi-select, and keyboard nav (M5 Wave B)
Pure bank_grid gains hit-test, selection-update, and arrow-nav math with tests; the panel wires mouse multi-select, keyboard nav via an accelerator hook, and stock PlayPreview/StopPreview audition with a leak-free preview lifecycle. Read-only: no arrange insertion, no project/bank mutation.
This commit is contained in:
@@ -85,4 +85,82 @@ struct ThumbnailKey {
|
||||
// length-prefixed so an id containing the delimiter cannot collide with another).
|
||||
std::string thumbnailKeyString(const ThumbnailKey& key);
|
||||
|
||||
// --- Interaction (M5 Wave B): hit-test, selection, keyboard nav --------------
|
||||
//
|
||||
// All REAPER-free so the panel's interaction LOGIC is unit-tested outside the DAW,
|
||||
// exactly as the layout math is. The panel shell (bank_panel.cpp) reads live mouse
|
||||
// coordinates / key codes / modifier state via SWELL and calls into these; it owns
|
||||
// no selection arithmetic of its own.
|
||||
|
||||
// Hit-tests a point (SWELL/LICE top-left client coords) against a cell-rect list.
|
||||
// Returns the index of the FIRST rect that contains the point, or -1 for a miss
|
||||
// (a click in the inter-cell gap, the margin, or below the last row). Half-open
|
||||
// bounds [x, x+width) x [y, y+height) so adjacent rects never both claim a pixel.
|
||||
int hitTestCell(int px, int py, const std::vector<CellRect>& rects);
|
||||
|
||||
// The panel's selection state. `indices` is the selected set as a SORTED, unique
|
||||
// ascending vector (deterministic for tests and for highlight iteration). `focus`
|
||||
// is the cell the caret sits on — the audition/extend target — or -1 when nothing
|
||||
// is focused. `anchor` is the fixed end of a shift-range (the cell a range extends
|
||||
// FROM); -1 when there is no active range origin. An empty selection has focus and
|
||||
// anchor both -1.
|
||||
//
|
||||
// Invariants (upheld by the pure mutators below, asserted in tests):
|
||||
// * indices is sorted ascending with no duplicates;
|
||||
// * every index (and focus/anchor when >= 0) is in [0, itemCount);
|
||||
// * focus, when >= 0, is a member of indices.
|
||||
struct Selection {
|
||||
std::vector<int> indices;
|
||||
int focus = -1;
|
||||
int anchor = -1;
|
||||
|
||||
bool operator==(const Selection& o) const {
|
||||
return indices == o.indices && focus == o.focus && anchor == o.anchor;
|
||||
}
|
||||
bool contains(int index) const;
|
||||
bool empty() const { return indices.empty(); }
|
||||
};
|
||||
|
||||
// Applies a mouse click on cell `index` to `current`, returning the new selection.
|
||||
// Modifier semantics (standard multi-select, matching file-manager conventions):
|
||||
// * plain (no modifier): select ONLY `index`; focus = anchor = index.
|
||||
// * ctrl: TOGGLE `index` in/out of the set; focus = index. Anchor moves to
|
||||
// index on add, and to index on remove too (a ctrl-click reseeds the
|
||||
// range origin at the clicked cell). If the toggle empties the set,
|
||||
// focus stays at index (the caret) but the set is empty.
|
||||
// * shift: select the inclusive RANGE from `anchor` to `index` (replacing the
|
||||
// set); focus = index, anchor unchanged. With no prior anchor (anchor
|
||||
// == -1) shift behaves like a plain click (anchor seeds at index).
|
||||
// `index` out of [0, itemCount) or itemCount <= 0 returns `current` unchanged.
|
||||
// ctrl and shift together: shift takes precedence (range select), matching common
|
||||
// UI; documented so the panel need not special-case it.
|
||||
Selection applyClick(const Selection& current, int index, bool ctrl, bool shift,
|
||||
int itemCount);
|
||||
|
||||
// A directional key for keyboard navigation. REAPER-free (the shell maps VK_* to
|
||||
// these) so nav math is testable without SWELL. Enter/Space/Esc are NOT here: they
|
||||
// drive audition, which is a shell concern (no selection math), so the shell reads
|
||||
// those key codes directly.
|
||||
enum class NavKey { Left, Right, Up, Down, Home, End };
|
||||
|
||||
// Moves the focus by one step for `key` in a grid of `cols` columns holding
|
||||
// `itemCount` cells, returning the new selection. `cols` >= 1.
|
||||
// * Left/Right move by one cell in linear (row-major) order; Up/Down move by
|
||||
// `cols`. Movement CLAMPS at the grid ends (no wrap): Right on the last cell,
|
||||
// Left on the first, Up on the top row, Down past the last cell all stay put.
|
||||
// (Clamp, not wrap: wrap on a partial last row is surprising and error-prone;
|
||||
// clamp is the predictable choice — flagged as the deliberate decision.)
|
||||
// * Down from the second-to-last row into a column with no cell in the last row
|
||||
// clamps to the last cell rather than overshooting past itemCount.
|
||||
// * Without shift: the moved-to cell becomes the sole selection; focus = anchor
|
||||
// = newIndex (a plain arrow reseeds the range origin).
|
||||
// * With shift: focus moves to newIndex and the selection becomes the inclusive
|
||||
// range from anchor to newIndex (anchor unchanged); a first shift-arrow with no
|
||||
// anchor seeds the anchor at the ORIGIN cell before moving.
|
||||
// * Empty selection (focus == -1): the first arrow focuses cell 0 (Home-like),
|
||||
// so an arrow press on a fresh panel starts navigation predictably.
|
||||
// itemCount <= 0 returns `current` unchanged.
|
||||
Selection navigate(const Selection& current, NavKey key, int cols, int itemCount,
|
||||
bool shift);
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
Reference in New Issue
Block a user