Files
reasampler/src/core/instrument/ui/spline_edit.h
T

43 lines
2.3 KiB
C++

// spline_edit.h — THE point-editing grammar, and the one place it is written down. Both spline
// consumers route their mouse-down through it — the velocity-curve popup and the spline EG
// overlay — so the two cannot drift into two grammars. Mirror of envelope_edit: decision logic
// only, no host types, no drawing.
#pragma once
#include "core/instrument/engine/velocity_curve.h"
#include "core/instrument/ui/editor_geometry.h" // Rect / OverlayArea
namespace reasampler::instrument::ui {
using engine::VelocityCurve;
// The gesture, in the pure module's own vocabulary (the shell maps its modifier state onto it).
enum class SplineGesture { kLeft, kRight, kControlLeft };
// What the gesture resolves to. Left-click adds a point in empty space and grabs an existing
// one; right-click deletes; control-click toggles hard/smooth. Points are smooth by default.
enum class SplineEditKind { kNone, kGrab, kAdd, kDelete, kToggleHard };
struct SplineEdit {
SplineEditKind kind = SplineEditKind::kNone;
int index = -1; // the point the action targets; -1 for kAdd (it has none yet) and kNone
};
// Resolves a click at (x, y) over `box` into an edit. The endpoint and point-count rules are
// NOT re-stated here — kDelete on an endpoint and kAdd at the ceiling are refused by
// VelocityCurve::deletePoint / addPoint, which the caller applies, so there is exactly one home
// for each. A click outside the mapping box resolves to kNone unless it lands on a node's pick
// radius: the drawn inset ring must not ADD (the new point would clamp onto an endpoint's x and
// stack an undeletable duplicate) but must still be able to grab.
SplineEdit resolveSplineEdit(const VelocityCurve& curve, const VelocityCurve::Box& box,
SplineGesture gesture, int x, int y);
// The contour's mapping box inside the waveform overlay: the FULL area, so the drawn contour
// spans the whole sample width 1:1 with its time axis. No inset — unlike the popup's box, which
// insets to keep endpoint handles clear of the sheet border, this one must stay 1:1 with the
// waveform beneath it. Takes the overlay (not a lane) — see waveform_view.h's overlay contract.
VelocityCurve::Box splineOverlayBox(const OverlayArea& area);
} // namespace reasampler::instrument::ui