62 for (uint8_t i = 0; i < segment_count_; ++i) {
63 segments_[i] = segments[i];
65 sustain_index_ = sustain_index;
74 if (segment_count_ == 0)
return;
75 gate_strength_ = 1.0f;
84 if (segment_count_ == 0)
return;
85 gate_strength_ = velocity;
86 prev_gate_ = velocity;
96 gate_strength_ = 0.0f;
99 if (sustain_index_ < 0)
return;
101 uint8_t release_index =
static_cast<uint8_t
>(sustain_index_ + 1);
102 if (release_index >= segment_count_)
return;
106 start_level_ = level_;
108 begin_segment(release_index);
115 if (prev_gate_ == 0.0f && gate > 0.0f) {
116 gate_strength_ = gate;
119 if (segment_count_ == 0)
return;
125 if (prev_gate_ > 0.0f && gate == 0.0f) {
126 gate_strength_ = 0.0f;
129 if (sustain_index_ < 0)
return;
130 uint8_t release_index =
static_cast<uint8_t
>(sustain_index_ + 1);
131 if (release_index >= segment_count_)
return;
134 start_level_ = level_;
136 begin_segment(release_index);
145 if (segment_count_ == 0)
return;
146 start_level_ = level_;
155 for (uint16_t i = 0; i < frames; ++i) {
157 float next_phase = phase_ + phase_increment_;
158 if (next_phase >= 1.0f) {
160 level_ = segments_[current_index_].
target;
161 start_level_ = level_;
165 level_ = compute_level(phase_);
174 float level()
const {
return level_; }
187 uint8_t segment_count_ = 0;
188 int8_t sustain_index_ = -1;
191 uint8_t current_index_ = 0;
194 float start_level_ = 0.0f;
196 float phase_increment_ = 0.0f;
197 float prev_gate_ = 0.0f;
198 float gate_strength_ = 0.0f;
208 phase_increment_ = 0.0f;
210 gate_strength_ = 0.0f;
213 void begin_segment(uint8_t index) {
214 current_index_ = index;
218 if (segments_[index].time_ms <= 0.0f) {
219 level_ = segments_[index].
target;
220 start_level_ = level_;
226 phase_increment_ = 1.0f / time_samples;
229 void advance_to_next() {
231 if (current_index_ == sustain_index_) {
237 uint8_t next = current_index_ + 1;
238 if (next >= segment_count_) {
246 float compute_level(
float phase)
const {
247 float warped = CurveEngine::warp(phase, segments_[current_index_].curve);
248 return start_level_ + (segments_[current_index_].
target - start_level_) * warped;