26 lines
863 B
C++
26 lines
863 B
C++
// bake_hold.cpp — see bake_hold.h. Pure math; no host types.
|
|
|
|
#include "core/instrument/ui/bake_hold.h"
|
|
|
|
#include <algorithm>
|
|
|
|
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<int>(norm * kLastIndex + 0.5));
|
|
}
|
|
|
|
double bakeHoldNorm(note::Division hold) {
|
|
return static_cast<double>(note::divisionIndex(hold)) / static_cast<double>(kLastIndex);
|
|
}
|
|
|
|
} // namespace reasampler::instrument::ui
|