FA2: param-domain Gate schematic + 8px node min-sep (all nodes grabbable at defaults); cross-mode drag guard; double-clamp px overflow fix

This commit is contained in:
2026-07-27 19:09:47 -04:00
parent d5d1902ea4
commit 99f377db28
6 changed files with 360 additions and 142 deletions
+100 -35
View File
@@ -4,19 +4,22 @@
// boundaries (the load-bearing "a drag can never produce a param a slider couldn't" invariant).
//
// Covers: nodeAtPoint (grabs a drawn handle within the pick radius; misses off every node; skips
// the non-draggable Origin/ReleaseStart anchors; NEAREST-node-wins with draw-order tie-break —
// FA2); resolveNodeDrag Gate (each cumulative node edits its OWN segment at the TIMED-region px
// scale; X->time, sustain node's Y->level; lower clamp at 0; upper clamp at the caller's max;
// only the dragged param changes; ReleaseEnd grabbable + draggable — FA2); resolveNodeDrag
// Trigger (fades as fractions of the played span; fadeIn/fadeOut mutual clamp so they never
// cross; length clamp; FadeOutStart moves OPPOSITE the pixel delta; zero-fade-out node grabbable
// at the right edge and draggable inward — FA2); degenerate area/duration + non-draggable node
// -> no motion.
// the non-draggable Origin/ReleaseStart anchors AND other-mode nodes; NEAREST-node-wins with
// draw-order tie-break; EVERY Gate node individually grabbable at the tier-0 defaults — FA2);
// resolveNodeDrag Gate (each cumulative node edits its OWN segment at the PARAM-DOMAIN px scale;
// X->time, sustain node's Y->level; lower clamp at 0; upper clamp at the caller's max; only the
// dragged param changes; ReleaseEnd grabbable + draggable; per-node drag round-trip tracks the
// cursor ~1:1 — FA2); resolveNodeDrag Trigger (fades as fractions of the played span;
// fadeIn/fadeOut mutual clamp so they never cross; length clamp; FadeOutStart moves OPPOSITE the
// pixel delta; zero-fade-out node grabbable at the right edge and draggable inward — FA2);
// degenerate area/duration + non-draggable node + cross-mode node -> no motion.
#include "../src/vst/envelope_edit.h"
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace reasampler::vst;
@@ -26,12 +29,21 @@ static int g_fail = 0;
static bool near(double a, double b, double eps = 1e-9) { return std::fabs(a - b) <= eps; }
// Find the first vertex with a given node in a polyline; asserts presence via the returned bool.
static bool findNode(const std::vector<EnvVertex>& poly, EnvNode node, EnvVertex& out) {
for (const EnvVertex& v : poly) {
if (v.node == node) { out = v; return true; }
}
return false;
}
// 1000px wide, 100px tall, offset origin. Trigger scale: 2.0s over 1000px => 0.002 s/px. Gate
// scale (FA2 schematic): 2.0s over the 850px TIMED region (150px sustain-plateau reserve) =>
// 2/850 s/px, and the gateEnv() nodes draw at A x@85, H x@128, D x@255, RS x@405, RE x@575.
// scale (FA2 param-domain schematic — sample-length-free): (850-1-32)px over the 8.0s schematic
// domain => 102.125 px/s, each segment prefixed by the 8px separation base; the gateEnv() nodes
// draw at A x@28, H x@47, D x@85, RS x@235, RE x@284.
static Rect wideArea() { return Rect{20, 10, 1020, 110}; }
static constexpr double kTotal = 2.0;
static constexpr double kGateSecPerPx = kTotal / 850.0;
static const double kGateSecPerPx = 1.0 / gatePxPerSecond(wideArea());
static AmpEnvelope gateEnv() {
AmpEnvelope e;
@@ -58,11 +70,11 @@ static AmpEnvelope triggerEnv() {
static void testHitGrabsDrawnHandle() {
const AmpEnvelope e = gateEnv();
const Rect a = wideArea();
// AttackEnd draws at x = left+85 (0.2s * 425 px/s in the timed region), y = top (level 1).
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 85, a.top);
// AttackEnd draws at x = left+28 (8px base + 0.2s * 102.125 px/s), y = top (level 1).
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 28, a.top);
CHECK(h.hit && h.node == EnvNode::AttackEnd);
// The sustain node (DecayEnd) at 0.6s -> left+255, level 0.5 -> ~top+50.
NodeHit s = nodeAtPoint(e, a, kTotal, a.left + 255, a.top + 50);
// The sustain node (DecayEnd) at left+85, level 0.5 -> ~top+50.
NodeHit s = nodeAtPoint(e, a, kTotal, a.left + 85, a.top + 50);
CHECK(s.hit && s.node == EnvNode::DecayEnd);
}
@@ -80,31 +92,39 @@ static void testHitSkipsNonDraggableAnchors() {
// Origin draws at (left, bottom-1). Even a pixel-perfect grab there is NOT a draggable node.
NodeHit o = nodeAtPoint(e, a, kTotal, a.left, a.bottom - 1);
CHECK(!o.hit);
// ReleaseStart draws at (left+405, sustain level ~top+50) — the fixed plateau end. It is
// ReleaseStart draws at (left+235, sustain level ~top+50) — the fixed plateau end. It is
// drawing-only -> not grabbable; no other node is within the radius, so this grab misses.
NodeHit rs = nodeAtPoint(e, a, kTotal, a.left + 405, a.top + 50);
NodeHit rs = nodeAtPoint(e, a, kTotal, a.left + 235, a.top + 50);
CHECK(!rs.hit);
}
static void testHitNearestNodeWinsOverDrawOrder() {
// FA2 nearest-wins: with a SHORT hold, AttackEnd (x@85) and HoldEnd (x@89) both fall within
// the grab radius of a point at x@90 — the NEAREST (HoldEnd, 1px) must win, not the earlier
// draw-order AttackEnd (5px), so tightly packed handles stay individually grabbable.
// FA2 nearest-wins: with a SHORT hold, AttackEnd (x@28) and HoldEnd (x@37 — the 8px base
// plus 0.01s ~= 1px) both fall within the grab radius of a point at x@33 — the NEAREST
// (HoldEnd, 4px) must win, not the earlier draw-order AttackEnd (5px), so tightly packed
// handles stay individually grabbable.
AmpEnvelope e = gateEnv();
e.holdSeconds = 0.01; // hold end at 0.21s -> x@round(89.25)=89
e.holdSeconds = 0.01;
const Rect a = wideArea();
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 90, a.top);
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 33, a.top);
CHECK(h.hit && h.node == EnvNode::HoldEnd);
}
static void testHitCoincidentNodesTieToEarlierDrawOrder() {
// Zero hold: AttackEnd and HoldEnd draw at the SAME pixel. The tie goes to the earlier
// draw-order node (AttackEnd) — deterministic, mirroring the pre-FA2 first-match rule.
AmpEnvelope e = gateEnv();
e.holdSeconds = 0.0;
static void testGateDefaultsEveryNodeGrabbable() {
// THE FA2 headline regression: at the tier-0 Gate defaults (attack 3ms, hold 0, decay 0,
// sustain 1.0, release 60ms) the forward map's kGateNodeSepPx separation keeps every
// draggable node distinct, and a grab AT each drawn vertex resolves to THAT node — HoldEnd
// and DecayEnd are no longer shadowed by AttackEnd (pre-fix they were permanently
// ungrabbable in the default state).
const AmpEnvelope e; // struct defaults ARE the tier-0 Gate defaults
const Rect a = wideArea();
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 85, a.top);
CHECK(h.hit && h.node == EnvNode::AttackEnd);
const std::vector<EnvVertex> poly = buildEnvelopePolyline(e, a, kTotal);
CHECK(poly.size() == 6);
for (const EnvVertex& v : poly) {
if (v.node == EnvNode::Origin || v.node == EnvNode::ReleaseStart) continue;
const NodeHit h = nodeAtPoint(e, a, kTotal, v.x, v.y);
CHECK(h.hit && h.node == v.node);
}
}
// --- resolveNodeDrag Gate -----------------------------------------------------
@@ -113,7 +133,7 @@ static void testGateAttackDragMovesOnlyAttack() {
const AmpEnvelope e = gateEnv();
const Rect a = wideArea();
EnvClampBounds b; // default maxima 4.0s
// +50px at the GATE timed-region scale (2/850 s/px) on attack. Nothing else moves.
// +50px at the GATE param-domain scale (~0.0098 s/px) on attack. Nothing else moves.
AmpEnvelope out = resolveNodeDrag(e, EnvNode::AttackEnd, a, kTotal, b, 50, 0);
CHECK(near(out.attackSeconds, 0.2 + 50.0 * kGateSecPerPx));
CHECK(near(out.holdSeconds, e.holdSeconds));
@@ -126,7 +146,7 @@ static void testGateTimeLowerClampAtZero() {
const AmpEnvelope e = gateEnv();
const Rect a = wideArea();
EnvClampBounds b;
// Drag attack far LEFT (-500px ~= -1.18s at the gate scale) from 0.2s: clamps to 0, never
// Drag attack far LEFT (-500px ~= -4.9s at the gate scale) from 0.2s: clamps to 0, never
// negative (monotonic: the segment cannot go below zero).
AmpEnvelope out = resolveNodeDrag(e, EnvNode::AttackEnd, a, kTotal, b, -500, 0);
CHECK(near(out.attackSeconds, 0.0));
@@ -137,7 +157,7 @@ static void testGateTimeUpperClampAtSliderMax() {
const Rect a = wideArea();
EnvClampBounds b;
b.maxDecaySeconds = 1.0; // the shell's decay slider tops out at 1.0s
// Drag decay far RIGHT (+2000px ~= +4.7s at the gate scale) from 0.3s: clamps to the slider
// Drag decay far RIGHT (+2000px ~= +19.6s at the gate scale) from 0.3s: clamps to the slider
// max 1.0, NOT beyond (the drag can't produce a param the slider couldn't).
AmpEnvelope out = resolveNodeDrag(e, EnvNode::DecayEnd, a, kTotal, b, 2000, 0);
CHECK(near(out.decaySeconds, 1.0));
@@ -179,11 +199,11 @@ static void testGateTimeOnlyNodeIgnoresY() {
static void testGateReleaseEndGrabAndDrag() {
// The FA2 fix: ReleaseEnd is a drawn, IN-BOUNDS, grabbable handle (pre-FA2 it mapped past
// area.right and could never be grabbed). gateEnv() draws it at x@575, level 0 (bottom row).
// area.right and could never be grabbed). gateEnv() draws it at x@284, level 0 (bottom row).
const AmpEnvelope e = gateEnv();
const Rect a = wideArea();
EnvClampBounds b;
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 575, a.bottom - 1);
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 284, a.bottom - 1);
CHECK(h.hit && h.node == EnvNode::ReleaseEnd);
// Dragging it RIGHT lengthens the release at the gate timed scale; only release changes.
AmpEnvelope out = resolveNodeDrag(e, EnvNode::ReleaseEnd, a, kTotal, b, 85, 0);
@@ -197,6 +217,31 @@ static void testGateReleaseEndGrabAndDrag() {
CHECK(near(hi.releaseSeconds, b.maxReleaseSeconds));
}
static void testGateDragRoundTripTracksPixels() {
// 1:1 tracking (FA2): drag a Gate node by N px, rebuild the polyline from the edited params,
// and the node's drawn vertex has moved by ~N px (rounding may shift the landing by 1). The
// forward map is affine in each node's own segment duration with slope gatePxPerSecond and
// the inverse uses exactly the reciprocal, so the handle follows the cursor.
const AmpEnvelope e = gateEnv();
const Rect a = wideArea();
EnvClampBounds b;
const int dx = 25;
for (EnvNode n : {EnvNode::AttackEnd, EnvNode::HoldEnd, EnvNode::DecayEnd,
EnvNode::ReleaseEnd}) {
EnvVertex before, after;
CHECK(findNode(buildEnvelopePolyline(e, a, kTotal), n, before));
const AmpEnvelope edited = resolveNodeDrag(e, n, a, kTotal, b, dx, 0);
CHECK(findNode(buildEnvelopePolyline(edited, a, kTotal), n, after));
CHECK(std::abs((after.x - before.x) - dx) <= 1);
}
// The sustain node's Y axis tracks too: +10px down moves the drawn vertex ~10px down.
EnvVertex before, after;
CHECK(findNode(buildEnvelopePolyline(e, a, kTotal), EnvNode::DecayEnd, before));
const AmpEnvelope edited = resolveNodeDrag(e, EnvNode::DecayEnd, a, kTotal, b, 0, 10);
CHECK(findNode(buildEnvelopePolyline(edited, a, kTotal), EnvNode::DecayEnd, after));
CHECK(std::abs((after.y - before.y) - 10) <= 1);
}
// --- resolveNodeDrag Trigger --------------------------------------------------
static void testTriggerFadeInIsFractionOfPlaySpan() {
@@ -289,12 +334,30 @@ static void testDegenerateAreaNoMotion() {
CHECK(near(o2.attackSeconds, e.attackSeconds));
}
static void testCrossModeNodeNoMotion() {
// A node from the OTHER mode never writes (FA2 guard): the degenerate baseline polyline
// carries a ReleaseEnd vertex regardless of mode, so a Trigger-mode grab of it (e.g. over a
// zero-height canvas) must NOT write releaseSeconds — and symmetrically a Trigger node is
// inert on a Gate envelope.
EnvClampBounds b;
const AmpEnvelope t = triggerEnv();
AmpEnvelope out = resolveNodeDrag(t, EnvNode::ReleaseEnd, wideArea(), kTotal, b, 50, 0);
CHECK(near(out.releaseSeconds, t.releaseSeconds));
const AmpEnvelope g = gateEnv();
out = resolveNodeDrag(g, EnvNode::FadeInEnd, wideArea(), kTotal, b, 50, 0);
CHECK(near(out.fadeInFraction, g.fadeInFraction));
// And the zero-height baseline's ReleaseEnd is not even reported grabbable in Trigger mode.
const Rect flat = Rect{0, 0, 100, 0};
const NodeHit h = nodeAtPoint(t, flat, kTotal, 99, 0);
CHECK(!h.hit);
}
int main() {
testHitGrabsDrawnHandle();
testHitMissesOffEveryNode();
testHitSkipsNonDraggableAnchors();
testHitNearestNodeWinsOverDrawOrder();
testHitCoincidentNodesTieToEarlierDrawOrder();
testGateDefaultsEveryNodeGrabbable();
testGateAttackDragMovesOnlyAttack();
testGateTimeLowerClampAtZero();
@@ -303,6 +366,7 @@ int main() {
testGateSustainLevelClamps01();
testGateTimeOnlyNodeIgnoresY();
testGateReleaseEndGrabAndDrag();
testGateDragRoundTripTracksPixels();
testTriggerFadeInIsFractionOfPlaySpan();
testTriggerFadesCannotCross();
@@ -312,6 +376,7 @@ int main() {
testNonDraggableNodeNoMotion();
testDegenerateAreaNoMotion();
testCrossModeNodeNoMotion();
if (g_fail == 0) std::printf("envelope_edit: all tests passed\n");
else std::printf("envelope_edit: %d FAILED\n", g_fail);
+87 -31
View File
@@ -5,11 +5,14 @@
// fade/%-length shape at the waveform time base.
//
// Covers: timeToX / levelToY (linear maps, edge clamps, past-end CLAMPED to right-1 — the FA2
// bounds invariant, degenerate area/duration); gateTimedWidth; buildEnvelopePolyline Gate (node
// order, levels, timed-region placement, fixed sustain-plateau reserve, release visible
// in-bounds, overrun pile-up clamped at the right edge, every vertex in-bounds);
// buildEnvelopePolyline Trigger (fade-in/unity/fade-out at fractions of the played span, overlap
// clamp, full-length/zero-fade-out nodes in-bounds at right-1); degenerate flat baseline.
// bounds invariant, no 32-bit overflow on huge times, degenerate area/duration); gateTimedWidth
// + gatePxPerSecond; buildEnvelopePolyline Gate (node order, levels, PARAM-DOMAIN timed-region
// placement independent of sample duration, per-segment kGateNodeSepPx separation — every node
// distinct even at the tier-0 zero-hold/zero-decay defaults, fixed sustain-plateau reserve,
// release visible in-bounds, overrun compressed from the right preserving the minimum gaps,
// every vertex in-bounds); buildEnvelopePolyline Trigger (fade-in/unity/fade-out at fractions of
// the played span, overlap clamp, full-length/zero-fade-out nodes in-bounds at right-1);
// degenerate flat baseline.
#include "../src/vst/envelope_overlay.h"
@@ -53,6 +56,9 @@ static void testTimeToXPastEndClamps() {
const Rect a = wideArea();
CHECK(timeToX(a, 2.0, 3.0) == a.right - 1);
CHECK(timeToX(a, 2.0, 1000.0) == a.right - 1);
// A HUGE t must clamp in double space, not overflow the integer cast (32-bit long on
// Windows would wrap to LONG_MIN and pin to the WRONG edge).
CHECK(timeToX(a, 2.0, 1e15) == a.right - 1);
}
static void testGateTimedWidth() {
@@ -63,6 +69,15 @@ static void testGateTimedWidth() {
CHECK(gateTimedWidth(Rect{0, 0, 1, 10}) == 1);
}
static void testGatePxPerSecond() {
// PARAM-DOMAIN scale: (timedW - 1 - 4*sep) px spread over 4 x kGateStageMaxSeconds. For the
// 1000px canvas: (850 - 1 - 32) / 8.0s = 817/8 px/s. Independent of any sample duration.
const double expected = 817.0 / (4.0 * kGateStageMaxSeconds);
CHECK(gatePxPerSecond(wideArea()) == expected);
CHECK(gatePxPerSecond(Rect{5, 5, 5, 45}) == 0.0); // zero-width area -> 0
CHECK(gatePxPerSecond(Rect{0, 0, 10, 10}) > 0.0); // tiny area: usable floors at 1px, > 0
}
static void testTimeToXDegenerate() {
const Rect a = wideArea();
CHECK(timeToX(a, 0.0, 1.0) == a.left); // no duration -> left
@@ -118,26 +133,55 @@ static void testGateNodeOrderAndLevels() {
}
static void testGateSchematicPlacement() {
// FA2 bounded schematic: timed region = 850px (150px reserved plateau), total 2.0s =>
// 425 px/s in the timed region. attack .2 -> x@85, hold end .3 -> x@round(127.5)=128, decay
// end .6 -> x@255. Plateau is the FIXED 150px reserve -> ReleaseStart x@405. Release .4 ->
// 170px ramp -> ReleaseEnd x@575, well inside the canvas.
// FA2 bounded schematic at the PARAM-DOMAIN scale: timed region = 850px (150px reserved
// plateau), pps = (850-1-32)/8s = 102.125 px/s, each segment prefixed by the 8px separation
// base. attack .2 -> x@round(8+20.425)=28; hold .1 -> x@round(28.425+8+10.2125)=47; decay
// .3 -> x@round(46.6375+8+30.6375)=85; plateau is the FIXED 150px reserve -> ReleaseStart
// x@235; release .4 -> x@round(235.275+8+40.85)=284, well inside the canvas.
AmpEnvelope env;
env.mode = EnvMode::Gate;
env.attackSeconds = 0.2;
env.holdSeconds = 0.1; // hold end at 0.3s
env.decaySeconds = 0.3; // decay end at 0.6s
env.holdSeconds = 0.1;
env.decaySeconds = 0.3;
env.sustainLevel = 0.5;
env.releaseSeconds = 0.4;
const Rect a = wideArea();
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, a, 2.0);
EnvVertex v;
CHECK(findNode(poly, EnvNode::AttackEnd, v) && v.x == a.left + 85);
CHECK(findNode(poly, EnvNode::HoldEnd, v) && v.x == a.left + 128);
CHECK(findNode(poly, EnvNode::DecayEnd, v) && v.x == a.left + 255);
CHECK(findNode(poly, EnvNode::ReleaseStart, v) && v.x == a.left + 405);
CHECK(findNode(poly, EnvNode::ReleaseEnd, v) && v.x == a.left + 575);
CHECK(findNode(poly, EnvNode::AttackEnd, v) && v.x == a.left + 28);
CHECK(findNode(poly, EnvNode::HoldEnd, v) && v.x == a.left + 47);
CHECK(findNode(poly, EnvNode::DecayEnd, v) && v.x == a.left + 85);
CHECK(findNode(poly, EnvNode::ReleaseStart, v) && v.x == a.left + 235);
CHECK(findNode(poly, EnvNode::ReleaseEnd, v) && v.x == a.left + 284);
}
static void testGateLayoutIndependentOfSampleDuration() {
// The Gate schematic is scaled by the PARAM domain, NOT the capture length: the same params
// produce the SAME polyline over a 0.3s and a 10s sample (pre-fix, a 60ms release on a 10s
// capture collapsed to ~5px while 2s stages on a 0.3s capture pinned to the right edge).
AmpEnvelope env;
env.mode = EnvMode::Gate;
env.attackSeconds = 0.2;
env.holdSeconds = 0.1;
env.decaySeconds = 0.3;
env.sustainLevel = 0.5;
env.releaseSeconds = 0.06;
const Rect a = wideArea();
CHECK(buildEnvelopePolyline(env, a, 0.3) == buildEnvelopePolyline(env, a, 10.0));
}
static void testGateMinSeparationAtDefaults() {
// THE FA2 headline: at the tier-0 Gate defaults (attack 3ms, hold 0, decay 0, sustain 1.0,
// release 60ms) every consecutive node pair is at least kGateNodeSepPx apart — no node ever
// renders on top of its neighbour, so each is individually grabbable.
const AmpEnvelope env; // struct defaults ARE the tier-0 Gate defaults
const Rect a = wideArea();
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, a, 2.0);
CHECK(poly.size() == 6);
for (size_t i = 1; i < poly.size(); ++i) {
CHECK(poly[i].x - poly[i - 1].x >= kGateNodeSepPx);
}
}
static void testGateSustainPlateauFixedWidth() {
@@ -183,28 +227,32 @@ static void testGateReleaseVisibleInBounds() {
CHECK(rel.level == 0.0);
}
static void testGateOverrunClampsToCanvas() {
// A/H/D/R overrun the visible span (sum 3.5s > 2.0s total): the trailing nodes pile up at
// the last in-bounds column — monotonic, in-bounds, still individually draggable back left.
// NOTHING maps past area.right (the pre-FA2 release tail is gone).
static void testGateOverrunCompressesFromRight() {
// Stages BEYOND the schematic domain (4.0s each > kGateStageMaxSeconds): the layout
// compresses from the right preserving the minimum gaps — ReleaseEnd pins to the last
// in-bounds column, but the trailing nodes stay strictly increasing and individually
// separated (>= kGateNodeSepPx), NOT piled on one pixel. NOTHING maps past area.right.
AmpEnvelope env;
env.mode = EnvMode::Gate;
env.attackSeconds = 1.0;
env.holdSeconds = 1.0;
env.decaySeconds = 1.0; // decay end at 3.0s -> already past the timed span
env.attackSeconds = 4.0;
env.holdSeconds = 4.0;
env.decaySeconds = 4.0;
env.sustainLevel = 0.7;
env.releaseSeconds = 0.5;
env.releaseSeconds = 4.0;
const Rect a = wideArea();
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, a, 2.0);
CHECK(poly.size() == 6);
EnvVertex decay, plateauEnd, rel;
CHECK(findNode(poly, EnvNode::DecayEnd, decay));
EnvVertex plateauEnd, rel;
CHECK(findNode(poly, EnvNode::ReleaseStart, plateauEnd));
CHECK(findNode(poly, EnvNode::ReleaseEnd, rel));
CHECK(decay.x == a.right - 1); // pinned to the last in-bounds column
CHECK(plateauEnd.x == a.right - 1);
CHECK(rel.x == a.right - 1);
CHECK(rel.x == a.right - 1); // pinned to the last in-bounds column
CHECK(plateauEnd.level == 0.7); // still at sustain
for (size_t i = 1; i < poly.size(); ++i) {
CHECK(poly[i].x > poly[i - 1].x); // strictly monotonic
CHECK(poly[i].x - poly[i - 1].x >= kGateNodeSepPx - 1); // min gaps survive compression
CHECK(poly[i].x >= a.left && poly[i].x < a.right); // in-bounds
}
}
static void testGateAllVerticesInBounds() {
@@ -223,8 +271,13 @@ static void testGateAllVerticesInBounds() {
AmpEnvelope trig = base;
trig.mode = EnvMode::Trigger;
trig.lengthFraction = 1.0; trig.fadeInFraction = 0.0; trig.fadeOutFraction = 0.0;
// ABSURD stage values must clamp in double space, not overflow the integer cast (32-bit
// long on Windows would wrap negative and land on the WRONG edge).
AmpEnvelope huge = base;
huge.mode = EnvMode::Gate;
huge.releaseSeconds = 1e12;
for (const AmpEnvelope& env : {base, big, zero, trig}) {
for (const AmpEnvelope& env : {base, big, zero, trig, huge}) {
for (const EnvVertex& v : buildEnvelopePolyline(env, a, 2.0)) {
CHECK(v.x >= a.left && v.x < a.right);
CHECK(v.y >= a.top && v.y < a.bottom);
@@ -316,14 +369,17 @@ int main() {
testTimeToXPastEndClamps();
testTimeToXDegenerate();
testGateTimedWidth();
testGatePxPerSecond();
testLevelToYEndpoints();
testLevelToYClamps();
testGateNodeOrderAndLevels();
testGateSchematicPlacement();
testGateLayoutIndependentOfSampleDuration();
testGateMinSeparationAtDefaults();
testGateSustainPlateauFixedWidth();
testGateReleaseVisibleInBounds();
testGateOverrunClampsToCanvas();
testGateOverrunCompressesFromRight();
testGateAllVerticesInBounds();
testTriggerShape();