fix: close round-3 review findings — smallest-target-first, residue test fix, extraction

Waveform overlay now resolves node/tab/marker click collisions by target area instead of check order; residue test now uses a distinguishing fixture; Gate-unavailable-while-drawn logic extracted to one pure helper shared by resolvePlay and applyControl.
This commit is contained in:
2026-07-31 23:44:05 -04:00
parent c3d67bc3da
commit 757e1585d6
11 changed files with 255 additions and 87 deletions
+103 -1
View File
@@ -13,6 +13,7 @@
// stacked height, grabs reaching the lower lane); laneEnvelope (per-lane channel split).
#include "../src/core/instrument/ui/waveform_view.h"
#include "../src/core/instrument/engine/velocity_curve.h" // kCurveNodeGrabRadius, VelocityCurve::pointAtPixel
#include "../src/core/instrument/ui/sample_bands.h" // kWaveformMinHeight, kLaneGap
#include <cstddef>
@@ -21,6 +22,7 @@
using namespace reasampler;
using namespace reasampler::instrument::ui;
using namespace reasampler::instrument::engine;
using reasampler::audio::AudioSample;
static int g_fail = 0;
@@ -379,10 +381,107 @@ static void testStartMarkerSharesTheHandleStripWhenItSitsAtTheFadeEdge() {
// column to the start marker (index 0) at this x/y...
CHECK(markerAtPoint(overlayOf(a), 1000, markers, 3, mx, topY) == 0);
// ...and the fade handle's rect claims the exact same pixel — the ambiguity the shell
// resolves by asking the handle first, same as it does for the zero-fade/loop-start case.
// resolves by smallest-target-first (the handle's clipped tab is always the narrower
// target), same as it does for the zero-fade/loop-start case.
CHECK(contains(markerHandleRect(overlayOf(a), 1000, fadeEdge), mx, topY));
}
// --- Smallest-target-first: the three-way coincidence with a spline contour node -------
//
// editor_input_waveform.cpp's mouseDownWaveform resolves a click among a contour node (a fixed
// pick box), the crossfade tab, and a marker's full-height column by measuring each candidate's
// own target area and letting the smallest win — this module can't exercise the shell's
// arbitration itself (no shell test target wraps the editor), but it can pin the geometric facts
// that arbitration depends on, over the pure primitives it composes. A realistic band height
// (kWaveformMinHeight, the product's own floor) is used throughout so these numbers are the
// worst case for the node, not a favourable one.
static VelocityCurve::Box boxOf(const Rect& r) { return VelocityCurve::Box{r.x, r.y, r.width, r.height}; }
// Case (a): a fresh Spline default (rampDown) puts its endpoint 0 at (box.left, box.top) — the
// exact pixel the start marker draws at frame 0. The node's fixed 169px pick box is far smaller
// than a kWaveformMinHeight-tall marker column, so the endpoint stays reachable.
static void testFreshRampDownEndpointBeatsTheStartMarkerAtFrameZero() {
const Rect a = Rect{20, 10, 1000, kWaveformMinHeight};
const OverlayArea overlay = overlayOf(a);
const std::int64_t frames = 100000;
const VelocityCurve contour = VelocityCurve::rampDown();
const VelocityCurve::Box box = boxOf(a);
CHECK(contour.pointAtPixel(box, a.x, a.y) == 0); // endpoint 0 sits at (box.left, box.top)
const std::int64_t markers[1] = {0};
CHECK(markerAtPoint(overlay, frames, markers, 1, a.x, a.y) == 0); // the coincidence
constexpr std::int64_t nodeSide = 2 * kCurveNodeGrabRadius + 1;
constexpr std::int64_t nodeArea = nodeSide * nodeSide; // 169, fixed
const std::int64_t markerArea =
static_cast<std::int64_t>(2 * kMarkerGrabWidth + 1) * a.height; // 11 * band height
CHECK(nodeArea < markerArea); // the node wins: the endpoint stays a genuine grab target
}
// Case (b): the crossfade tab at zero crossfade sits on loopStart's own pixel column; a node
// dragged to value ~0.98 lands a couple of rows below the box top — inside the tab's own
// top-strip band, where the review found the tab fully shadowed by a node-first pass.
static void testCrossfadeTabBeatsAContourNodeNearItsTopStrip() {
const Rect a = Rect{20, 10, 1000, kWaveformMinHeight};
const OverlayArea overlay = overlayOf(a);
const std::int64_t frames = 100000;
const std::int64_t loopStart = 40000, crossfade = 0; // zero crossfade -> tab sits on loopStart
const int mx = frameToX(overlay, frames, loopStart - crossfade);
const Rect tabRect = markerHandleRect(overlay, frames, loopStart - crossfade);
CHECK(!tabRect.empty());
const VelocityCurve::Box box = boxOf(a);
const int ny = a.y + 3; // ~0.98 up a kWaveformMinHeight-tall box; inside the tab's top strip
VelocityCurve c = VelocityCurve::flat();
const VelocityPoint p = c.pointFromPixel(box, mx, ny);
c.addPoint(p.velocity, p.value);
CHECK(c.pointAtPixel(box, mx, ny) >= 0);
CHECK(contains(tabRect, mx, ny)); // the coincidence: both claim the same pixel
constexpr std::int64_t nodeSide = 2 * kCurveNodeGrabRadius + 1;
constexpr std::int64_t nodeArea = nodeSide * nodeSide; // 169, fixed
const std::int64_t tabArea = static_cast<std::int64_t>(tabRect.width) * tabRect.height; // <= 110
CHECK(tabArea < nodeArea); // the tab wins: it stays the only affordance at zero crossfade
// The residual the review names: the node keeps its OUTER columns, one pixel past the tab's
// clipped edge but still inside its own pick radius.
const int outerX = mx + kMarkerHandleHalfWidth + 1;
CHECK(!contains(tabRect, outerX, ny));
CHECK(c.pointAtPixel(box, outerX, ny) >= 0);
}
// Case (c): a contour node coincident with a loop marker. At kWaveformMinHeight (the product's
// own floor) the column is already an order of magnitude larger than the node's fixed pick box,
// so the node wins the shared pixel while the column stays reachable everywhere the node isn't.
static void testContourNodeBeatsALoopMarkerAtTheirSharedPixelButNotElsewhere() {
const Rect a = Rect{20, 10, 1000, kWaveformMinHeight};
const OverlayArea overlay = overlayOf(a);
const std::int64_t frames = 100000;
const std::int64_t loopEnd = 70000;
const int mx = frameToX(overlay, frames, loopEnd);
const std::int64_t markers[1] = {loopEnd};
const VelocityCurve::Box box = boxOf(a);
const int ny = a.y + a.height / 2; // mid-height, well clear of any tab
VelocityCurve c = VelocityCurve::flat();
const VelocityPoint p = c.pointFromPixel(box, mx, ny);
c.addPoint(p.velocity, p.value);
CHECK(c.pointAtPixel(box, mx, ny) >= 0);
CHECK(markerAtPoint(overlay, frames, markers, 1, mx, ny) == 0); // the coincidence
constexpr std::int64_t nodeSide = 2 * kCurveNodeGrabRadius + 1;
constexpr std::int64_t nodeArea = nodeSide * nodeSide; // 169, fixed
const std::int64_t markerArea =
static_cast<std::int64_t>(2 * kMarkerGrabWidth + 1) * a.height; // 11 * band height
CHECK(nodeArea < markerArea); // the node wins the shared pixel
// A few rows clear of the node (outside its 13px pick box, still on the marker's column)
// the marker alone claims the click.
const int farY = ny + kCurveNodeGrabRadius + 4;
CHECK(c.pointAtPixel(box, mx, farY) < 0);
CHECK(markerAtPoint(overlay, frames, markers, 1, mx, farY) == 0);
}
// --- Per-lane envelope content -------------------------------------------------
static void testAsymmetricStereoLanesCarryDifferentContent() {
@@ -458,6 +557,9 @@ int main() {
testMarkerHandleClipsIntoTheArea();
testMarkerHandleOnDegenerateAreas();
testStartMarkerSharesTheHandleStripWhenItSitsAtTheFadeEdge();
testFreshRampDownEndpointBeatsTheStartMarkerAtFrameZero();
testCrossfadeTabBeatsAContourNodeNearItsTopStrip();
testContourNodeBeatsALoopMarkerAtTheirSharedPixelButNotElsewhere();
testAsymmetricStereoLanesCarryDifferentContent();
testLaneEnvelopeRejectsOutOfRangeLane();