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:
+43
-21
@@ -23,13 +23,14 @@ double secondsPerPixel(const Rect& area, double totalSeconds) {
|
||||
return totalSeconds / static_cast<double>(w);
|
||||
}
|
||||
|
||||
// Seconds per pixel in the GATE timed region (FA2): the Gate schematic maps A/H/D/R onto
|
||||
// gateTimedWidth(area) px, not the full canvas, so a Gate time-node drag must use this scale for
|
||||
// the handle to track the cursor. Matches envelope_overlay::gatePolyline.
|
||||
double gateSecondsPerPixel(const Rect& area, double totalSeconds) {
|
||||
const int w = gateTimedWidth(area);
|
||||
if (w <= 0 || totalSeconds <= 0.0) return 0.0;
|
||||
return totalSeconds / static_cast<double>(w);
|
||||
// Seconds per pixel for a GATE time-node drag (FA2): the reciprocal of the overlay's
|
||||
// param-domain gatePxPerSecond(area) scale — sample-length-free, matching
|
||||
// envelope_overlay::gatePolyline exactly so the dragged handle tracks the cursor 1:1 (each
|
||||
// node's x is affine in its own segment duration with slope gatePxPerSecond). Zero when the
|
||||
// area is degenerate.
|
||||
double gateSecondsPerPixel(const Rect& area) {
|
||||
const double pps = gatePxPerSecond(area);
|
||||
return pps > 0.0 ? 1.0 / pps : 0.0;
|
||||
}
|
||||
|
||||
// Level (0..1) represented by one vertical pixel. levelToY spans (height-1) rows for [0,1], so one
|
||||
@@ -51,20 +52,42 @@ bool isDraggable(EnvNode n) {
|
||||
}
|
||||
}
|
||||
|
||||
// True when the node belongs to the envelope's active mode. Guards the degenerate cross-mode
|
||||
// write: the degenerate baseline polyline carries a ReleaseEnd vertex regardless of mode, so a
|
||||
// zero-height Trigger-mode grab of it must not write releaseSeconds (and vice versa for Gate
|
||||
// nodes vs Trigger fields). Applied by BOTH the hit-test and the drag resolver so they agree.
|
||||
bool nodeInMode(EnvNode n, EnvMode m) {
|
||||
switch (n) {
|
||||
case EnvNode::AttackEnd:
|
||||
case EnvNode::HoldEnd:
|
||||
case EnvNode::DecayEnd:
|
||||
case EnvNode::ReleaseEnd:
|
||||
return m == EnvMode::Gate;
|
||||
case EnvNode::FadeInEnd:
|
||||
case EnvNode::FadeOutStart:
|
||||
case EnvNode::LengthEnd:
|
||||
return m == EnvMode::Trigger;
|
||||
case EnvNode::Origin:
|
||||
case EnvNode::ReleaseStart:
|
||||
return false; // never draggable in any mode (isDraggable filters these anyway)
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
NodeHit nodeAtPoint(const AmpEnvelope& env, const Rect& area, double totalSeconds, int x, int y) {
|
||||
const std::vector<EnvVertex> poly = buildEnvelopePolyline(env, area, totalSeconds);
|
||||
// NEAREST draggable node within the pick radius wins (Chebyshev distance — the square grab
|
||||
// box); ties break to the earlier draw-order node (FA2). Nearest-wins keeps every handle
|
||||
// grabbable when nodes sit close (e.g. a short hold), while the draw-order tie-break makes
|
||||
// exactly-coincident nodes deterministic: at zero fade-out, FadeOutStart overlays LengthEnd
|
||||
// and WINS the tie, so the fade-out handle is grabbable at the right edge and can be dragged
|
||||
// inward from zero.
|
||||
// NEAREST draggable, mode-matching node within the pick radius wins (Chebyshev distance —
|
||||
// the square grab box); ties break to the earlier draw-order node (FA2). Gate nodes never
|
||||
// coincide (the forward map enforces kGateNodeSepPx separation), so the tie-break only
|
||||
// matters for Trigger's zero-fade-out coincidence: FadeOutStart overlays LengthEnd, WINS the
|
||||
// tie, and can be dragged inward from the right edge. The mode filter keeps the degenerate
|
||||
// baseline's ReleaseEnd vertex from registering as a grabbable node in Trigger mode.
|
||||
NodeHit best;
|
||||
int bestDist = kNodeGrabRadius + 1;
|
||||
for (const EnvVertex& v : poly) {
|
||||
if (!isDraggable(v.node)) continue;
|
||||
if (!isDraggable(v.node) || !nodeInMode(v.node, env.mode)) continue;
|
||||
const int dist = std::max(std::abs(x - v.x), std::abs(y - v.y));
|
||||
if (dist < bestDist) { // strictly closer only: earlier draw order keeps ties
|
||||
bestDist = dist;
|
||||
@@ -78,17 +101,16 @@ AmpEnvelope resolveNodeDrag(const AmpEnvelope& grabEnv, EnvNode node, const Rect
|
||||
double totalSeconds, const EnvClampBounds& bounds,
|
||||
int dxPixels, int dyPixels) {
|
||||
AmpEnvelope out = grabEnv;
|
||||
if (!isDraggable(node)) return out;
|
||||
if (!isDraggable(node) || !nodeInMode(node, grabEnv.mode)) return out;
|
||||
|
||||
const double secPerPx = secondsPerPixel(area, totalSeconds);
|
||||
if (secPerPx <= 0.0) return out; // degenerate area / duration — no motion
|
||||
const double dSec = static_cast<double>(dxPixels) * secPerPx;
|
||||
// Gate time nodes live in the TIMED region of the Gate schematic (FA2), which is narrower
|
||||
// than the canvas by the sustain-plateau reserve — their px->seconds scale differs so the
|
||||
// dragged handle tracks the cursor 1:1. gateTimedWidth >= 1 whenever the area is non-empty,
|
||||
// so gateDSec is well-defined past the degenerate guard above.
|
||||
const double gateDSec =
|
||||
static_cast<double>(dxPixels) * gateSecondsPerPixel(area, totalSeconds);
|
||||
// Gate time nodes use the schematic's PARAM-DOMAIN px->seconds scale (FA2) — the reciprocal
|
||||
// of the overlay's gatePxPerSecond, sample-length-free — so the dragged handle tracks the
|
||||
// cursor 1:1. gateTimedWidth >= 1 whenever the area is non-empty, so gateDSec is
|
||||
// well-defined past the degenerate guard above.
|
||||
const double gateDSec = static_cast<double>(dxPixels) * gateSecondsPerPixel(area);
|
||||
|
||||
switch (node) {
|
||||
// --- Gate: each cumulative-time node edits its OWN segment duration. Non-negative
|
||||
|
||||
Reference in New Issue
Block a user