// trigger_seam — the shared Trigger play-span formula: how a %-length becomes the source-frame
// span the voice plays, the overlay draws over, and the bake's window holds. One home so those
// cannot disagree about where a Trigger note ends.
//
// playLengthFrames = round(clamp01(lengthFraction) * (frameCount - startFrame))

#pragma once

#include <cstdint>

namespace reasampler::instrument::map {

// `startFrame` is the effective start point (0 when absent), `lengthFraction` the EFFECTIVE one
// — fold it through effectiveLengthFraction (play_params.h) first, or a stored-but-inert %-knob
// shortens the span. Returns 0 for an empty post-start span and for any fraction that is not
// above zero, NaN included; the fraction is clamped to 1.0 and the result to the span, so a
// corrupt stored value cannot reach past the source.
//
// Voice::start evaluates this same clamped formula inline rather than calling it: the engine
// does not depend on `map/`, in either direction.
std::int64_t triggerPlayLength(double lengthFraction,
                               std::int64_t frameCount,
                               std::int64_t startFrame);

}  // namespace reasampler::instrument::map
