FA2: bounded-schematic Gate envelope (15% sustain reserve, in-bounds release) + zero-fade-out grabbable via nearest-node hit-test; all nodes clamp in-canvas
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
// 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; first-match determinism); resolveNodeDrag Gate
|
||||
// (each cumulative node edits its OWN segment; X->time, sustain node's Y->level; lower clamp at 0;
|
||||
// upper clamp at the caller's max; only the dragged param changes); 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); degenerate area/duration + non-draggable node ->
|
||||
// no motion.
|
||||
// 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.
|
||||
|
||||
#include "../src/vst/envelope_edit.h"
|
||||
|
||||
@@ -24,9 +26,12 @@ static int g_fail = 0;
|
||||
|
||||
static bool near(double a, double b, double eps = 1e-9) { return std::fabs(a - b) <= eps; }
|
||||
|
||||
// 1000px wide, 100px tall, offset origin. 2.0s total => 500 px/s => 0.002 s/px.
|
||||
// 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.
|
||||
static Rect wideArea() { return Rect{20, 10, 1020, 110}; }
|
||||
static constexpr double kTotal = 2.0;
|
||||
static constexpr double kGateSecPerPx = kTotal / 850.0;
|
||||
|
||||
static AmpEnvelope gateEnv() {
|
||||
AmpEnvelope e;
|
||||
@@ -53,18 +58,18 @@ static AmpEnvelope triggerEnv() {
|
||||
static void testHitGrabsDrawnHandle() {
|
||||
const AmpEnvelope e = gateEnv();
|
||||
const Rect a = wideArea();
|
||||
// AttackEnd draws at x = left+100 (0.2s), y = top (level 1). A grab there hits it.
|
||||
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 100, a.top);
|
||||
// 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);
|
||||
CHECK(h.hit && h.node == EnvNode::AttackEnd);
|
||||
// The sustain node (DecayEnd) at 0.6s -> left+300, level 0.5 -> ~top+50.
|
||||
NodeHit s = nodeAtPoint(e, a, kTotal, a.left + 300, a.top + 50);
|
||||
// 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);
|
||||
CHECK(s.hit && s.node == EnvNode::DecayEnd);
|
||||
}
|
||||
|
||||
static void testHitMissesOffEveryNode() {
|
||||
const AmpEnvelope e = gateEnv();
|
||||
const Rect a = wideArea();
|
||||
// A point far from any drawn handle (mid plateau, well away from a node).
|
||||
// A point far from any drawn handle (right of the release ramp, well away from a node).
|
||||
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 700, a.top + 5);
|
||||
CHECK(!h.hit);
|
||||
}
|
||||
@@ -75,22 +80,42 @@ 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 (right, sustain level). It is drawing-only -> not grabbable. But
|
||||
// ReleaseEnd is elsewhere, so a grab exactly at ReleaseStart's point must miss.
|
||||
// ReleaseStart x == right (plateau to sample end), y == sustain (~top+50).
|
||||
NodeHit rs = nodeAtPoint(e, a, kTotal, a.right, a.top + 50);
|
||||
// ReleaseStart draws at (left+405, 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);
|
||||
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.
|
||||
AmpEnvelope e = gateEnv();
|
||||
e.holdSeconds = 0.01; // hold end at 0.21s -> x@round(89.25)=89
|
||||
const Rect a = wideArea();
|
||||
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 90, 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;
|
||||
const Rect a = wideArea();
|
||||
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 85, a.top);
|
||||
CHECK(h.hit && h.node == EnvNode::AttackEnd);
|
||||
}
|
||||
|
||||
// --- resolveNodeDrag Gate -----------------------------------------------------
|
||||
|
||||
static void testGateAttackDragMovesOnlyAttack() {
|
||||
const AmpEnvelope e = gateEnv();
|
||||
const Rect a = wideArea();
|
||||
EnvClampBounds b; // default maxima 4.0s
|
||||
// +50px at 0.002 s/px = +0.1s on attack (0.2 -> 0.3). Nothing else moves.
|
||||
// +50px at the GATE timed-region scale (2/850 s/px) on attack. Nothing else moves.
|
||||
AmpEnvelope out = resolveNodeDrag(e, EnvNode::AttackEnd, a, kTotal, b, 50, 0);
|
||||
CHECK(near(out.attackSeconds, 0.3));
|
||||
CHECK(near(out.attackSeconds, 0.2 + 50.0 * kGateSecPerPx));
|
||||
CHECK(near(out.holdSeconds, e.holdSeconds));
|
||||
CHECK(near(out.decaySeconds, e.decaySeconds));
|
||||
CHECK(near(out.sustainLevel, e.sustainLevel));
|
||||
@@ -101,8 +126,8 @@ static void testGateTimeLowerClampAtZero() {
|
||||
const AmpEnvelope e = gateEnv();
|
||||
const Rect a = wideArea();
|
||||
EnvClampBounds b;
|
||||
// Drag attack far LEFT (-500px = -1.0s) from 0.2s: clamps to 0, never negative (monotonic:
|
||||
// the segment cannot go below zero).
|
||||
// Drag attack far LEFT (-500px ~= -1.18s 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));
|
||||
}
|
||||
@@ -112,8 +137,8 @@ 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.0s) from 0.3s: clamps to the slider max 1.0, NOT beyond
|
||||
// (the drag can't produce a param the slider couldn't).
|
||||
// Drag decay far RIGHT (+2000px ~= +4.7s 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));
|
||||
}
|
||||
@@ -122,10 +147,10 @@ static void testGateSustainNodeBothAxes() {
|
||||
const AmpEnvelope e = gateEnv();
|
||||
const Rect a = wideArea();
|
||||
EnvClampBounds b;
|
||||
// DecayEnd: +100px X = +0.2s decay (0.3 -> 0.5); +bottom-ward Y LOWERS the level. Level span is
|
||||
// 99 px for [0,1]; drag DOWN by ~10px (positive dy) lowers sustain by ~10/99 ~= 0.101.
|
||||
// DecayEnd: +100px X at the gate timed scale on decay; +bottom-ward Y LOWERS the level. Level
|
||||
// span is 99 px for [0,1]; drag DOWN by ~10px (positive dy) lowers sustain by ~10/99 ~= 0.101.
|
||||
AmpEnvelope out = resolveNodeDrag(e, EnvNode::DecayEnd, a, kTotal, b, 100, 10);
|
||||
CHECK(near(out.decaySeconds, 0.5));
|
||||
CHECK(near(out.decaySeconds, 0.3 + 100.0 * kGateSecPerPx));
|
||||
CHECK(out.sustainLevel < e.sustainLevel); // dragged DOWN -> lower sustain
|
||||
CHECK(near(out.sustainLevel, 0.5 - 10.0 / 99.0, 1e-6));
|
||||
}
|
||||
@@ -152,6 +177,26 @@ static void testGateTimeOnlyNodeIgnoresY() {
|
||||
CHECK(near(out.sustainLevel, e.sustainLevel)); // Y ignored for a time-only node
|
||||
}
|
||||
|
||||
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).
|
||||
const AmpEnvelope e = gateEnv();
|
||||
const Rect a = wideArea();
|
||||
EnvClampBounds b;
|
||||
NodeHit h = nodeAtPoint(e, a, kTotal, a.left + 575, 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);
|
||||
CHECK(near(out.releaseSeconds, 0.4 + 85.0 * kGateSecPerPx));
|
||||
CHECK(near(out.sustainLevel, e.sustainLevel));
|
||||
CHECK(near(out.decaySeconds, e.decaySeconds));
|
||||
// Far LEFT clamps to 0; far RIGHT clamps to the slider max.
|
||||
AmpEnvelope lo = resolveNodeDrag(e, EnvNode::ReleaseEnd, a, kTotal, b, -2000, 0);
|
||||
CHECK(near(lo.releaseSeconds, 0.0));
|
||||
AmpEnvelope hi = resolveNodeDrag(e, EnvNode::ReleaseEnd, a, kTotal, b, 5000, 0);
|
||||
CHECK(near(hi.releaseSeconds, b.maxReleaseSeconds));
|
||||
}
|
||||
|
||||
// --- resolveNodeDrag Trigger --------------------------------------------------
|
||||
|
||||
static void testTriggerFadeInIsFractionOfPlaySpan() {
|
||||
@@ -188,6 +233,28 @@ static void testTriggerFadeOutMovesOppositePixelDelta() {
|
||||
CHECK(near(out.fadeInFraction, e.fadeInFraction));
|
||||
}
|
||||
|
||||
static void testTriggerZeroFadeOutGrabbableAtRightEdge() {
|
||||
// The FA2 fix: at fade-out == 0 and full length, FadeOutStart draws AT the right edge
|
||||
// (right-1, level 1). It must be grabbable there and draggable INWARD to grow the fade from
|
||||
// zero (drag LEFT -> longer fade-out, opposite the pixel delta).
|
||||
AmpEnvelope e;
|
||||
e.mode = EnvMode::Trigger;
|
||||
e.lengthFraction = 1.0; // played span = full 2.0s -> 1000px
|
||||
e.fadeInFraction = 0.1;
|
||||
e.fadeOutFraction = 0.0;
|
||||
const Rect a = wideArea();
|
||||
EnvClampBounds b;
|
||||
NodeHit h = nodeAtPoint(e, a, kTotal, a.right - 1, a.top);
|
||||
CHECK(h.hit && h.node == EnvNode::FadeOutStart);
|
||||
// -100px = -0.2s on the 2.0s played span, applied OPPOSITE -> fadeOut 0.0 -> 0.1.
|
||||
AmpEnvelope out = resolveNodeDrag(e, EnvNode::FadeOutStart, a, kTotal, b, -100, 0);
|
||||
CHECK(near(out.fadeOutFraction, 0.1));
|
||||
CHECK(near(out.lengthFraction, e.lengthFraction)); // length untouched
|
||||
// LengthEnd sits at the same x but level 0 (bottom row) — grabbable at ITS drawn point.
|
||||
NodeHit le = nodeAtPoint(e, a, kTotal, a.right - 1, a.bottom - 1);
|
||||
CHECK(le.hit && le.node == EnvNode::LengthEnd);
|
||||
}
|
||||
|
||||
static void testTriggerLengthClampsAtMax() {
|
||||
const AmpEnvelope e = triggerEnv(); // length 0.5
|
||||
const Rect a = wideArea();
|
||||
@@ -226,6 +293,8 @@ int main() {
|
||||
testHitGrabsDrawnHandle();
|
||||
testHitMissesOffEveryNode();
|
||||
testHitSkipsNonDraggableAnchors();
|
||||
testHitNearestNodeWinsOverDrawOrder();
|
||||
testHitCoincidentNodesTieToEarlierDrawOrder();
|
||||
|
||||
testGateAttackDragMovesOnlyAttack();
|
||||
testGateTimeLowerClampAtZero();
|
||||
@@ -233,10 +302,12 @@ int main() {
|
||||
testGateSustainNodeBothAxes();
|
||||
testGateSustainLevelClamps01();
|
||||
testGateTimeOnlyNodeIgnoresY();
|
||||
testGateReleaseEndGrabAndDrag();
|
||||
|
||||
testTriggerFadeInIsFractionOfPlaySpan();
|
||||
testTriggerFadesCannotCross();
|
||||
testTriggerFadeOutMovesOppositePixelDelta();
|
||||
testTriggerZeroFadeOutGrabbableAtRightEdge();
|
||||
testTriggerLengthClampsAtMax();
|
||||
|
||||
testNonDraggableNodeNoMotion();
|
||||
|
||||
+139
-33
@@ -1,14 +1,15 @@
|
||||
// Standalone tests for reasampler::vst::envelope_overlay — no VST3, no REAPER, no framework.
|
||||
// Same fast assert loop as the sibling pure tests. Assert the S-VIEW-3 amp-envelope -> polyline
|
||||
// FORWARD map: the Gate AHDSR shape (attack ramp / hold plateau / decay-to-sustain / plateau /
|
||||
// release) and the Trigger fade/%-length shape, at the waveform time base (so the drawn curve
|
||||
// lines up with the PCM under it).
|
||||
// Same fast assert loop as the sibling pure tests. Assert the S-VIEW-3/FA2 amp-envelope ->
|
||||
// polyline FORWARD map: the Gate BOUNDED-SCHEMATIC AHDSR shape (attack ramp / hold plateau /
|
||||
// decay-to-sustain / fixed-width sustain plateau / in-bounds release) and the Trigger
|
||||
// fade/%-length shape at the waveform time base.
|
||||
//
|
||||
// Covers: timeToX / levelToY (linear maps, edge clamps, release-past-end NOT clamped, degenerate
|
||||
// area/duration); buildEnvelopePolyline Gate (node order, levels, cumulative time placement,
|
||||
// sustain plateau to sample end, release past end, collapsed plateau when stages overrun);
|
||||
// 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); degenerate flat baseline.
|
||||
// clamp, full-length/zero-fade-out nodes in-bounds at right-1); degenerate flat baseline.
|
||||
|
||||
#include "../src/vst/envelope_overlay.h"
|
||||
|
||||
@@ -37,8 +38,8 @@ static bool findNode(const std::vector<EnvVertex>& poly, EnvNode node, EnvVertex
|
||||
|
||||
static void testTimeToXEndpoints() {
|
||||
const Rect a = wideArea();
|
||||
CHECK(timeToX(a, 2.0, 0.0) == a.left); // t=0 -> left
|
||||
CHECK(timeToX(a, 2.0, 2.0) == a.right); // t=total -> right
|
||||
CHECK(timeToX(a, 2.0, 0.0) == a.left); // t=0 -> left
|
||||
CHECK(timeToX(a, 2.0, 2.0) == a.right - 1); // t=total -> last in-bounds column
|
||||
CHECK(timeToX(a, 2.0, 1.0) == a.left + 500); // midpoint
|
||||
}
|
||||
|
||||
@@ -47,11 +48,19 @@ static void testTimeToXNegativePinsLeft() {
|
||||
CHECK(timeToX(a, 2.0, -0.5) == a.left); // t<0 pins left
|
||||
}
|
||||
|
||||
static void testTimeToXPastEndNotClamped() {
|
||||
// The Gate release tail is drawn past the sample end BY DESIGN: t past total maps past right.
|
||||
static void testTimeToXPastEndClamps() {
|
||||
// FA2 bounds invariant: t past total pins to the last in-bounds column, never past right.
|
||||
const Rect a = wideArea();
|
||||
CHECK(timeToX(a, 2.0, 3.0) > a.right); // t=1.5x total -> past the right edge
|
||||
CHECK(timeToX(a, 2.0, 3.0) == a.left + 1500);
|
||||
CHECK(timeToX(a, 2.0, 3.0) == a.right - 1);
|
||||
CHECK(timeToX(a, 2.0, 1000.0) == a.right - 1);
|
||||
}
|
||||
|
||||
static void testGateTimedWidth() {
|
||||
// 15% of the 1000px canvas is reserved for the sustain plateau -> 850px timed region.
|
||||
CHECK(gateTimedWidth(wideArea()) == 850);
|
||||
// Zero-width area -> 0; a tiny area still yields >= 1 so the px<->s scale never degenerates.
|
||||
CHECK(gateTimedWidth(Rect{5, 5, 5, 45}) == 0);
|
||||
CHECK(gateTimedWidth(Rect{0, 0, 1, 10}) == 1);
|
||||
}
|
||||
|
||||
static void testTimeToXDegenerate() {
|
||||
@@ -108,35 +117,81 @@ static void testGateNodeOrderAndLevels() {
|
||||
CHECK(poly[5].level == 0.0);
|
||||
}
|
||||
|
||||
static void testGateCumulativeTimePlacement() {
|
||||
// total 2.0s over 1000px => 500 px/s. attack .2 -> x@100, hold end .3 -> x@150, decay end .6
|
||||
// -> x@300. Sustain plateau runs to the sample END (2.0 -> right). Release .4 trails past.
|
||||
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.
|
||||
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.sustainLevel = 0.5;
|
||||
env.releaseSeconds = 0.4; // release end at 2.4s (past the 2.0s end)
|
||||
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 + 100);
|
||||
CHECK(findNode(poly, EnvNode::HoldEnd, v) && v.x == a.left + 150);
|
||||
CHECK(findNode(poly, EnvNode::DecayEnd, v) && v.x == a.left + 300);
|
||||
CHECK(findNode(poly, EnvNode::ReleaseStart, v) && v.x == a.right); // plateau to end
|
||||
CHECK(findNode(poly, EnvNode::ReleaseEnd, v) && v.x == a.left + 1200); // 2.4s -> 1200px past
|
||||
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);
|
||||
}
|
||||
|
||||
static void testGatePlateauCollapsesWhenStagesOverrun() {
|
||||
// A/H/D sum to 3.0s > the 2.0s sample: the plateau collapses (ReleaseStart clamps to DecayEnd's
|
||||
// time), and the release still trails past.
|
||||
static void testGateSustainPlateauFixedWidth() {
|
||||
// The sustain plateau is ALWAYS the reserved width (canvas - timed region), independent of
|
||||
// the AHDSR times — the bounded region that replaces the old plateau-to-sample-end.
|
||||
AmpEnvelope env;
|
||||
env.mode = EnvMode::Gate;
|
||||
env.attackSeconds = 0.1;
|
||||
env.holdSeconds = 0.0;
|
||||
env.decaySeconds = 0.2;
|
||||
env.sustainLevel = 0.6;
|
||||
env.releaseSeconds = 0.3;
|
||||
const Rect a = wideArea();
|
||||
const int plateauPx = a.width() - gateTimedWidth(a); // 150
|
||||
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, a, 2.0);
|
||||
|
||||
EnvVertex decay, plateauEnd;
|
||||
CHECK(findNode(poly, EnvNode::DecayEnd, decay));
|
||||
CHECK(findNode(poly, EnvNode::ReleaseStart, plateauEnd));
|
||||
CHECK(plateauEnd.x - decay.x == plateauPx);
|
||||
CHECK(plateauEnd.level == 0.6); // plateau holds the sustain level
|
||||
}
|
||||
|
||||
static void testGateReleaseVisibleInBounds() {
|
||||
// The FA2 fix: Release is a VISIBLE, in-bounds segment — ReleaseEnd sits strictly right of
|
||||
// the plateau end and strictly inside the canvas (pre-FA2 it mapped past area.right and the
|
||||
// shell clipped its handle away).
|
||||
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.4;
|
||||
const Rect a = wideArea();
|
||||
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, a, 2.0);
|
||||
|
||||
EnvVertex plateauEnd, rel;
|
||||
CHECK(findNode(poly, EnvNode::ReleaseStart, plateauEnd));
|
||||
CHECK(findNode(poly, EnvNode::ReleaseEnd, rel));
|
||||
CHECK(rel.x > plateauEnd.x); // a visible ramp, not a collapsed point
|
||||
CHECK(rel.x < a.right); // strictly in-bounds
|
||||
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).
|
||||
AmpEnvelope env;
|
||||
env.mode = EnvMode::Gate;
|
||||
env.attackSeconds = 1.0;
|
||||
env.holdSeconds = 1.0;
|
||||
env.decaySeconds = 1.0; // decay end at 3.0s
|
||||
env.decaySeconds = 1.0; // decay end at 3.0s -> already past the timed span
|
||||
env.sustainLevel = 0.7;
|
||||
env.releaseSeconds = 0.5;
|
||||
const Rect a = wideArea();
|
||||
@@ -146,11 +201,37 @@ static void testGatePlateauCollapsesWhenStagesOverrun() {
|
||||
CHECK(findNode(poly, EnvNode::DecayEnd, decay));
|
||||
CHECK(findNode(poly, EnvNode::ReleaseStart, plateauEnd));
|
||||
CHECK(findNode(poly, EnvNode::ReleaseEnd, rel));
|
||||
CHECK(plateauEnd.x == decay.x); // collapsed: plateau has zero width
|
||||
CHECK(rel.x > decay.x); // release trails past
|
||||
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(plateauEnd.level == 0.7); // still at sustain
|
||||
}
|
||||
|
||||
static void testGateAllVerticesInBounds() {
|
||||
// The FA2 bounds invariant, swept over representative param sets (including extremes): every
|
||||
// vertex of every polyline stays inside the canvas rect.
|
||||
const Rect a = wideArea();
|
||||
const AmpEnvelope base; // defaults
|
||||
AmpEnvelope big = base;
|
||||
big.mode = EnvMode::Gate;
|
||||
big.attackSeconds = 4.0; big.holdSeconds = 4.0; big.decaySeconds = 4.0;
|
||||
big.sustainLevel = 1.0; big.releaseSeconds = 4.0;
|
||||
AmpEnvelope zero = base;
|
||||
zero.mode = EnvMode::Gate;
|
||||
zero.attackSeconds = 0.0; zero.holdSeconds = 0.0; zero.decaySeconds = 0.0;
|
||||
zero.sustainLevel = 0.0; zero.releaseSeconds = 0.0;
|
||||
AmpEnvelope trig = base;
|
||||
trig.mode = EnvMode::Trigger;
|
||||
trig.lengthFraction = 1.0; trig.fadeInFraction = 0.0; trig.fadeOutFraction = 0.0;
|
||||
|
||||
for (const AmpEnvelope& env : {base, big, zero, trig}) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Trigger polyline ---------------------------------------------------------
|
||||
|
||||
static void testTriggerShape() {
|
||||
@@ -193,6 +274,26 @@ static void testTriggerFadeOverlapClamp() {
|
||||
CHECK(fin.x == a.left + 800);
|
||||
}
|
||||
|
||||
static void testTriggerFullLengthZeroFadeOutInBounds() {
|
||||
// The FA2 fix: at full length + zero fade-out, FadeOutStart and LengthEnd land AT the last
|
||||
// in-bounds column (right-1), NOT at the half-open right edge — so the shell draws their
|
||||
// handles and the fade-out node is grabbable even when fade-out == 0.
|
||||
AmpEnvelope env;
|
||||
env.mode = EnvMode::Trigger;
|
||||
env.lengthFraction = 1.0;
|
||||
env.fadeInFraction = 0.1;
|
||||
env.fadeOutFraction = 0.0;
|
||||
const Rect a = wideArea();
|
||||
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, a, 2.0);
|
||||
|
||||
EnvVertex fout, lend;
|
||||
CHECK(findNode(poly, EnvNode::FadeOutStart, fout));
|
||||
CHECK(findNode(poly, EnvNode::LengthEnd, lend));
|
||||
CHECK(fout.x == a.right - 1); // present + in-bounds at zero fade-out
|
||||
CHECK(lend.x == a.right - 1);
|
||||
CHECK(fout.level == 1.0 && lend.level == 0.0);
|
||||
}
|
||||
|
||||
// --- Degenerate ---------------------------------------------------------------
|
||||
|
||||
static void testDegenerateFlatBaseline() {
|
||||
@@ -206,23 +307,28 @@ static void testDegenerateFlatBaseline() {
|
||||
const std::vector<EnvVertex> p2 = buildEnvelopePolyline(env, ok, 0.0); // no duration
|
||||
CHECK(p2.size() == 2);
|
||||
CHECK(p2.front().level == 0.0 && p2.back().level == 0.0);
|
||||
CHECK(p2.front().x == ok.left && p2.back().x == ok.right); // spans the whole area flat
|
||||
CHECK(p2.front().x == ok.left && p2.back().x == ok.right - 1); // spans the area, in-bounds
|
||||
}
|
||||
|
||||
int main() {
|
||||
testTimeToXEndpoints();
|
||||
testTimeToXNegativePinsLeft();
|
||||
testTimeToXPastEndNotClamped();
|
||||
testTimeToXPastEndClamps();
|
||||
testTimeToXDegenerate();
|
||||
testGateTimedWidth();
|
||||
testLevelToYEndpoints();
|
||||
testLevelToYClamps();
|
||||
|
||||
testGateNodeOrderAndLevels();
|
||||
testGateCumulativeTimePlacement();
|
||||
testGatePlateauCollapsesWhenStagesOverrun();
|
||||
testGateSchematicPlacement();
|
||||
testGateSustainPlateauFixedWidth();
|
||||
testGateReleaseVisibleInBounds();
|
||||
testGateOverrunClampsToCanvas();
|
||||
testGateAllVerticesInBounds();
|
||||
|
||||
testTriggerShape();
|
||||
testTriggerFadeOverlapClamp();
|
||||
testTriggerFullLengthZeroFadeOutInBounds();
|
||||
|
||||
testDegenerateFlatBaseline();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user