-
Notifications
You must be signed in to change notification settings - Fork 13
/
ui_utils.h
73 lines (63 loc) · 2.16 KB
/
ui_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include "vital/common/synth_parameters.h"
struct UIUtils {
static double getAdjustedValue(double value, vital::ValueDetails details) {
double adjusted_value = value;
switch (details.value_scale) {
case vital::ValueDetails::kQuadratic:
adjusted_value *= adjusted_value;
break;
case vital::ValueDetails::kCubic:
adjusted_value *= adjusted_value * adjusted_value;
break;
case vital::ValueDetails::kQuartic:
adjusted_value *= adjusted_value;
adjusted_value *= adjusted_value;
break;
case vital::ValueDetails::kExponential:
adjusted_value = powf(2.0, adjusted_value);
break;
case vital::ValueDetails::kSquareRoot:
adjusted_value = sqrtf(std::max(adjusted_value, 0.0));
break;
default:
break;
}
float display_multiply_ = details.display_multiply;
adjusted_value += details.post_offset;
if (details.display_invert)
adjusted_value = 1.0 / adjusted_value;
if (display_multiply_)
adjusted_value *= display_multiply_;
else
adjusted_value *= details.display_multiply;
return adjusted_value;
}
static juce::String formatValue(float value, vital::ValueDetails details) {
int max_decimal_places = details.decimal_places;
juce::String format;
if (details.value_scale == vital::ValueDetails::kIndexed)
format = juce::String(value);
else {
if (max_decimal_places == 0)
format = juce::String(std::roundf(value));
else
format = juce::String(value, 3);
int display_characters = 5;
if (format[0] == '-')
display_characters += 1;
format = format.substring(0, display_characters);
if (format.getLastCharacter() == '.')
format = format.removeCharacters(".");
}
return format + details.display_units;
}
static juce::String getSliderTextFromValue(double value, vital::ValueDetails details) {
if (details.string_lookup) {
int lookup = vital::utils::iclamp(value, 0, details.max);
return details.string_lookup[lookup];
}
double adjusted_value = getAdjustedValue(value, details);
return formatValue(adjusted_value, details);
}
};