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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
ix!();
#[derive(Debug)]
pub struct ControllerModulationSource {
pub output: f64,
pub target: f64,
pub bipolar: bool,
pub changed: bool,
pub enabled: bool,
pub id: i32,
srunit: SampleRateHandle,
}
name![ControllerModulationSource,"ControllerModulationSource"];
impl ModulationSourceControl for ControllerModulationSource {
fn get_type(&self) -> ModSrcType {
ModSrcType::Controller
}
fn get_output(&self) -> f64 {
self.output
}
fn set_output(&mut self, x: f64) {
self.output = x;
}
fn get_output01(&self) -> f64 {
match self.bipolar {
true => 0.5 + 0.5 * self.output,
false => self.output
}
}
fn is_bipolar(&self) -> bool {
self.bipolar
}
fn set_bipolar(&mut self, b: bool) {
self.bipolar = b;
}
fn enabled(&self) -> bool {
self.enabled
}
fn enable(&mut self, v: bool) {
self.enabled = v;
}
fn process_block(&mut self) {
let b: f64 = (self.target - self.output).abs();
let a: f64 = 0.9 * 44100.0 * self.srunit.dsamplerate_inv() * b;
self.output = (1.0 - a) * self.output + a * self.target;
}
fn reset(&mut self) {
self.target = 0.0;
self.output = 0.0;
self.bipolar = false;
}
}
impl ControllerModulationSource {
pub fn new(srunit: SampleRateHandle) -> Self {
Self {
target: 0.0,
output: 0.0,
bipolar: false,
changed: true,
id: -1,
srunit,
enabled: true,
}
}
pub fn process_block_until_close(&mut self, sigma: f64) -> bool
{
let b: f64 = (self.target - self.output).abs();
if b < sigma {
self.output = self.target;
false
} else {
let a: f64 = 0.9 * 44100.0 * self.srunit.dsamplerate_inv() * b;
self.output = (1.0 - a) * self.output + a * self.target;
true
}
}
pub fn init(&mut self, f: f64) {
self.target = f;
self.output = f;
self.changed = true;
}
pub fn set_target(&mut self, f: f64) {
self.target = f;
self.changed = true;
}
pub fn set_target01(&mut self, f: f64, updatechanged: bool) {
if self.bipolar {
self.target = 2.0 * f - 1.0;
} else {
self.target = f;
}
if updatechanged {
self.changed = true;
}
}
pub fn get_target01(&self) -> f64 {
match self.bipolar {
true => 0.5 + 0.5 * self.target,
false => self.target,
}
}
pub fn has_changed(&mut self, reset: bool) -> bool {
match self.changed {
true => {
if reset {
self.changed = false;
}
true
},
false => false,
}
}
}