2#include <ossia/detail/math.hpp>
24 {1.f / 64.f,
"1/64"}, {1.f / 48.f,
"1/32T"}, {1.f / 32.f,
"1/32"},
25 {1.f / 24.f,
"1/16T"}, {3.f / 64.f,
"1/32."}, {1.f / 16.f,
"1/16"},
26 {1.f / 12.f,
"1/8T"}, {3.f / 32.f,
"1/16."}, {1.f / 8.f,
"1/8"},
27 {1.f / 6.f,
"1/4T"}, {3.f / 16.f,
"1/8."}, {1.f / 4.f,
"1/4"},
28 {1.f / 3.f,
"1/2T"}, {3.f / 8.f,
"1/4."}, {1.f / 2.f,
"1/2"},
29 {2.f / 3.f,
"1/1T"}, {3.f / 4.f,
"1/2."}, {1.f,
"1/1"},
30 {3.f / 2.f,
"1/1."}, {2.f,
"2/1"}, {3.f,
"2/1."},
33inline constexpr int count = std::ssize(table);
34inline constexpr int eighth = 8;
36enum class Feel : uint8_t
43constexpr Feel feelOf(
int index)
noexcept
45 std::string_view l = table[index].label;
50 return Feel::Straight;
54constexpr double position(
int index)
noexcept
56 return index / double(count - 1);
62 return ossia::clamp(
int(std::lround(v01 * (count - 1))), 0, count - 1);
68inline double snapPosition(
double v01, Feel feel,
bool fullTable)
noexcept
70 const double target = ossia::clamp(v01, 0., 1.) * (count - 1);
72 return std::lround(target) / double(count - 1);
75 for(
int i = 0; i < count; i++)
79 const double d = std::abs(target - i);
80 if(best < 0 || d < bestDist)
86 return best / double(count - 1);
93 float bestDist = std::abs(table[0].fraction - frac);
94 for(
int i = 1; i < count; i++)
96 const float d = std::abs(table[i].fraction - frac);
107inline int nearest(
float frac, Feel feel)
noexcept
110 float bestDist = 0.f;
111 for(
int i = 0; i < count; i++)
113 if(feelOf(i) != feel)
115 const float d = std::abs(table[i].fraction - frac);
116 if(best < 0 || d < bestDist)
128 switch(feelOf(index))
131 return table[index].fraction / 1.5f;
133 return table[index].fraction * 1.5f;
135 return table[index].fraction;
139inline float withFeel(
float straight, Feel feel)
noexcept
144 return straight * 1.5f;
146 return straight / 1.5f;
Definition NoteValues.hpp:13
double snapPosition(double v01, Feel feel, bool fullTable) noexcept
Definition NoteValues.hpp:68
int indexAt(double v01) noexcept
The note value at a knob position.
Definition NoteValues.hpp:60
float straightLength(int index) noexcept
How long the note is, straight: a dotted note is 3/2 of it, a triplet 2/3.
Definition NoteValues.hpp:126
int nearest(float frac) noexcept
The note value nearest to a fraction of a whole note.
Definition NoteValues.hpp:90
Definition NoteValues.hpp:15