-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeString.h
More file actions
110 lines (90 loc) · 2.74 KB
/
ModeString.h
File metadata and controls
110 lines (90 loc) · 2.74 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#pragma once
#include "IEngine.h"
#include <math.h> // for tanhf
class ModeString : public IEngine {
public:
void Init(float sample_rate) override {
str_.Init(sample_rate);
filter_.Init(sample_rate);
filter_.SetRes(0.2f);
filter_.SetDrive(0.3f); // Warmth
damping_ = 0.5f;
brightness_ = 0.5f;
structure_ = 0.5f;
reverb_send_ = 0.2f;
delay_send_ = 0.0f;
knob_brightness_.Init(0.5f);
knob_cutoff_.Init(0.5f);
knob_delay_.Init(0.0f);
knob_structure_.Init(0.5f);
}
void Process(float in_l, float in_r, float *out_l, float *out_r) override {
str_.SetFreq(freq_ * octave_mult_);
str_.SetBrightness(brightness_);
str_.SetDamping(damping_);
str_.SetStructure(structure_);
float sig = str_.Process();
filter_.Process(sig);
float f_out = (filter_mode_ == 1)
? filter_.Low()
: ((filter_mode_ == 2) ? filter_.High() : filter_.Band());
// Warm Limiter / Compressor
float limit_out = tanhf(f_out * 1.5f);
*out_l = *out_r = limit_out;
}
void UpdateControls(float enc_inc, float k_top, float k_bot, int s1, int s2,
bool secondary) override {
filter_mode_ = s2;
// Octave Switch
float octave_map[] = {1.0f, 0.5f, 2.0f};
if (s1 >= 0 && s1 < 3)
octave_mult_ = octave_map[s1];
else
octave_mult_ = 1.0f;
if (!secondary) {
knob_delay_.Unlatch();
knob_structure_.Unlatch();
// Enc: Damping (Accumulate)
damping_ += enc_inc;
if (damping_ < 0.0f)
damping_ = 0.0f;
else if (damping_ > 1.0f)
damping_ = 1.0f;
// Top: Brightness
brightness_ = knob_brightness_.Process(k_top);
// Bot: Cutoff
float raw_cut = knob_cutoff_.Process(k_bot);
filter_.SetFreq(fmap(raw_cut, 20.0f, 12000.0f, Mapping::LOG));
} else {
knob_brightness_.Unlatch();
knob_cutoff_.Unlatch();
reverb_send_ += enc_inc;
if (reverb_send_ < 0.0f)
reverb_send_ = 0.0f;
else if (reverb_send_ > 1.0f)
reverb_send_ = 1.0f;
delay_send_ = knob_delay_.Process(k_top);
structure_ = knob_structure_.Process(k_bot);
filter_.SetRes(0.2f);
}
}
void Trigger() { str_.Trig(); }
void SetFreq(float f) override { freq_ = f; }
float GetReverbAmount() override { return reverb_send_; }
float GetDelayAmount() override { return delay_send_; }
private:
StringVoice str_;
Svf filter_;
float freq_;
float octave_mult_ = 1.0f;
float damping_ = 0.5f;
float brightness_ = 0.5f;
float structure_ = 0.5f;
float reverb_send_ = 0.2f;
float delay_send_ = 0.0f;
int filter_mode_ = 0;
SoftKnob knob_brightness_;
SoftKnob knob_cutoff_;
SoftKnob knob_delay_;
SoftKnob knob_structure_;
};