// bake_hold.cpp — see bake_hold.h. Pure math; no host types. #include "core/instrument/ui/bake_hold.h" #include namespace reasampler::instrument::ui { namespace { constexpr int kLastIndex = note::kDivisionCount - 1; } // namespace note::Division bakeHoldFromNorm(double norm) { if (!(norm > 0.0)) return note::divisionAt(0); // also catches NaN if (norm >= 1.0) return note::divisionAt(kLastIndex); // Round to nearest so each rung owns an equal slice of the knob's travel; divisionAt // clamps, so the +0.5 landing on kDivisionCount at norm just under 1 is harmless. return note::divisionAt(static_cast(norm * kLastIndex + 0.5)); } double bakeHoldNorm(note::Division hold) { return static_cast(note::divisionIndex(hold)) / static_cast(kLastIndex); } } // namespace reasampler::instrument::ui