File tree 7 files changed +54
-57
lines changed
7 files changed +54
-57
lines changed Original file line number Diff line number Diff line change @@ -22,4 +22,4 @@ add_library(plugin SHARED
22
22
src/plugin/dhe-modules.h
23
23
src/stage/stage.cpp
24
24
src/stage/stage.h
25
- src/stage/stage-widget.cpp src/stage/stage-widget.h src/util/range .h src/upstage/upstage.h)
25
+ src/stage/stage-widget.cpp src/stage/stage-widget.h src/util/interval .h src/upstage/upstage.h)
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ void Stage::start_envelope() {
48
48
}
49
49
50
50
float Stage::duration () const {
51
- static const Range range{1e-3 , 10 .0f };
51
+ static const Interval range{1e-3 , 10 .0f };
52
52
static constexpr float curvature{0 .8f }; // Gives ~1s at center position
53
53
54
54
return range.scale (sigmoid (duration_knob_rotation (), curvature));
@@ -63,6 +63,6 @@ float Stage::shape() const {
63
63
float Stage::envelope_voltage () const {
64
64
auto shaped{sigmoid (envelope_ramp.phase (), shape ())};
65
65
66
- return Range ::scale (shaped, stage_input_follower.value (), level_knob_voltage ());
66
+ return Interval ::scale (shaped, stage_input_follower.value (), level_knob_voltage ());
67
67
}
68
68
} // namespace DHE
Original file line number Diff line number Diff line change @@ -45,12 +45,12 @@ struct Stage : rack::Module {
45
45
void start_envelope ();
46
46
float envelope_voltage () const ;
47
47
48
- float active_out_voltage () const { return UNIPOLAR_VOLTAGE .scale (is_active ()); }
48
+ float active_out_voltage () const { return UNIPOLAR_CV .scale (is_active ()); }
49
49
float duration_knob_rotation () const { return params[DURATION_KNOB].value ; }
50
- float eoc_out_voltage () const { return UNIPOLAR_VOLTAGE .scale (end_of_cycle_pulse.is_active ()); }
50
+ float eoc_out_voltage () const { return UNIPOLAR_CV .scale (end_of_cycle_pulse.is_active ()); }
51
51
bool is_active () const { return defer_gate.is_high () || envelope_ramp.is_active (); }
52
52
float level_knob_rotation () const { return params[LEVEL_KNOB].value ; }
53
- float level_knob_voltage () const { return UNIPOLAR_VOLTAGE .scale (level_knob_rotation ()); }
53
+ float level_knob_voltage () const { return UNIPOLAR_CV .scale (level_knob_rotation ()); }
54
54
float out_voltage () const { return defer_gate.is_high () ? stage_input_follower.value () : envelope_voltage (); }
55
55
float shape_knob_rotation () const { return params[SHAPE_KNOB].value ; }
56
56
float shape_position () const { return BIPOLAR_NORMAL.scale (shape_knob_rotation ()); }
Original file line number Diff line number Diff line change 8
8
#include < algorithm>
9
9
#include < engine.hpp>
10
10
11
- #include " util/range .h"
11
+ #include " util/interval .h"
12
12
13
13
namespace DHE {
14
14
@@ -40,10 +40,10 @@ struct Upstage : rack::Module {
40
40
bool is_sending_triggers () const { return wait_port_in () < 1 .0f and not wait_button_is_pressed (); }
41
41
float level_cv_in () const { return inputs[LEVEL_CV_INPUT].value ; }
42
42
float level_knob_rotation () const { return params[LEVEL_KNOB].value ; }
43
- float level_knob_voltage () const { return UNIPOLAR_VOLTAGE .scale (level_knob_rotation ()); }
44
- float level_voltage () const { return UNIPOLAR_VOLTAGE .clamp (level_knob_voltage () + level_cv_in ()); }
43
+ float level_knob_voltage () const { return UNIPOLAR_CV .scale (level_knob_rotation ()); }
44
+ float level_voltage () const { return UNIPOLAR_CV .clamp (level_knob_voltage () + level_cv_in ()); }
45
45
bool trigger_button_is_pressed () const { return params[TRIG_BUTTON].value > 0 .0f ; }
46
- float trigger_button_voltage () const { return UNIPOLAR_VOLTAGE .scale (trigger_button_is_pressed ()); }
46
+ float trigger_button_voltage () const { return UNIPOLAR_CV .scale (trigger_button_is_pressed ()); }
47
47
float trigger_port_in () const { return inputs[TRIG_INPUT].value ; }
48
48
float trigger_out_voltage () const { return is_sending_triggers () ? trigger_voltage () : 0 .0f ; }
49
49
float trigger_voltage () const { return std::max (trigger_port_in (), trigger_button_voltage ()); }
Original file line number Diff line number Diff line change
1
+ #ifndef DHE_UTIL_RANGE_H
2
+ #define DHE_UTIL_RANGE_H
3
+
4
+ namespace DHE {
5
+
6
+ struct Interval {
7
+ const float lower_bound;
8
+ const float upper_bound;
9
+
10
+ constexpr Interval (float lower_bound, float upper_bound) noexcept : lower_bound(lower_bound), upper_bound(upper_bound) {}
11
+
12
+ static float scale (float proportion, float lower_bound, float upper_bound) {
13
+ return proportion*(upper_bound - lower_bound) + lower_bound;
14
+ }
15
+
16
+ float scale (float proportion) const {
17
+ return scale (proportion, lower_bound, upper_bound);
18
+ }
19
+
20
+ float scale (bool state) const {
21
+ return state ? upper_bound : lower_bound;
22
+ }
23
+
24
+ float normalize (float member) const {
25
+ return (member - lower_bound)/(upper_bound - lower_bound);
26
+ }
27
+
28
+ float clamp (float f) const {
29
+ if (f < lower_bound)
30
+ return lower_bound;
31
+ if (f > upper_bound)
32
+ return upper_bound;
33
+ return f;
34
+ }
35
+ };
36
+
37
+ constexpr auto NORMAL = Interval{0 .0f , 1 .0f };
38
+ constexpr auto BIPOLAR_NORMAL = Interval{-1 .0f , 1 .0f };
39
+ constexpr auto UNIPOLAR_CV = Interval{0 .0f , 10 .0f };
40
+ constexpr auto BIPOLAR_CV = Interval{-5 .0f , 5 .0f };
41
+ }
42
+ #endif
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 4
4
#include < cmath>
5
5
#include < functional>
6
6
7
- #include " range .h"
7
+ #include " interval .h"
8
8
9
9
namespace DHE {
10
10
11
11
inline float sigmoid (float x, float curvature) {
12
12
static constexpr auto precision{1e-4f };
13
13
static constexpr auto max_curvature{1 .0f - precision};
14
- static const auto curvature_range = Range {-max_curvature, max_curvature};
14
+ static const auto curvature_range = Interval {-max_curvature, max_curvature};
15
15
16
16
curvature = curvature_range.clamp (curvature);
17
17
x = BIPOLAR_NORMAL.clamp (x);
You can’t perform that action at this time.
0 commit comments