78 |
GetSampleRate()); |
GetSampleRate()); |
79 |
} |
} |
80 |
|
|
81 |
|
|
82 |
|
void FilEGUnit::Trigger() { |
83 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
84 |
|
depth = pRegion->fileg_depth; |
85 |
|
|
86 |
|
// the length of the decay and release curves are dependent on the velocity |
87 |
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
88 |
|
|
89 |
|
// set the delay trigger |
90 |
|
uiDelayTrigger = (pRegion->fileg_delay + pRegion->fileg_vel2delay * velrelease) * GetSampleRate(); |
91 |
|
|
92 |
|
EG.trigger(uint(pRegion->fileg_start * 10), |
93 |
|
std::max(0.0, pRegion->fileg_attack + pRegion->fileg_vel2attack * velrelease), |
94 |
|
std::max(0.0, pRegion->fileg_hold + pRegion->fileg_vel2hold * velrelease), |
95 |
|
std::max(0.0, pRegion->fileg_decay + pRegion->fileg_vel2decay * velrelease), |
96 |
|
uint(std::min(std::max(0.0, 10 * (pRegion->fileg_sustain + pRegion->fileg_vel2sustain * velrelease)), 1000.0)), |
97 |
|
std::max(0.0, pRegion->fileg_release + pRegion->fileg_vel2release * velrelease), |
98 |
|
GetSampleRate()); |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
LFOUnit::LFOUnit(const LFOUnit& Unit): SfzSignalUnit(Unit), suFadeEG(static_cast<SfzSignalUnitRack*>(Unit.pRack)) { |
103 |
|
Copy(Unit); |
104 |
|
} |
105 |
|
|
106 |
void LFOUnit::Increment() { |
void LFOUnit::Increment() { |
107 |
if (DelayStage()) return; |
if (DelayStage()) return; |
108 |
|
|
109 |
SignalUnit::Increment(); |
SignalUnit::Increment(); |
110 |
|
|
111 |
Level = lfo.render(); |
Level = pLFO->Render(); |
112 |
|
if (suFadeEG.Active()) Level *= suFadeEG.GetLevel(); |
113 |
} |
} |
114 |
|
|
115 |
void LFOUnit::Trigger() { |
void LFOUnit::Trigger() { |
118 |
|
|
119 |
// set the delay trigger |
// set the delay trigger |
120 |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
121 |
|
if(pLfoInfo->fade != 0 || !pLfoInfo->fade_oncc.empty()) { |
122 |
|
float f = pLfoInfo->fade; |
123 |
|
for (int i = 0; i < pLfoInfo->fade_oncc.size(); i++) { |
124 |
|
int val = pVoice->GetControllerValue(pLfoInfo->fade_oncc[i].Controller); |
125 |
|
f += (val / 127.0f) * pLfoInfo->fade_oncc[i].Influence; |
126 |
|
} |
127 |
|
|
128 |
|
if (f != 0) { |
129 |
|
suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
130 |
|
suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate()); |
131 |
|
} |
132 |
|
} |
133 |
} |
} |
134 |
|
|
135 |
void LFOv1Unit::Trigger() { |
void LFOv1Unit::Trigger() { |
143 |
lfo.update(0); |
lfo.update(0); |
144 |
} |
} |
145 |
|
|
146 |
|
|
147 |
|
LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack) |
148 |
|
: LFOUnit(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f), |
149 |
|
lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f), |
150 |
|
suPitchOnCC(rack) |
151 |
|
{ |
152 |
|
lfos.add(&lfo0); |
153 |
|
lfos.add(&lfo1); |
154 |
|
lfos.add(&lfo2); |
155 |
|
lfos.add(&lfo3); |
156 |
|
lfos.add(&lfo4); |
157 |
|
lfos.add(&lfo5); |
158 |
|
lfos.add(&lfo6); |
159 |
|
lfos.add(&lfo7); |
160 |
|
} |
161 |
|
|
162 |
void LFOv2Unit::Trigger() { |
void LFOv2Unit::Trigger() { |
163 |
LFOUnit::Trigger(); |
LFOUnit::Trigger(); |
164 |
|
|
165 |
lfo.trigger ( |
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
166 |
|
else pLFO = lfos[pLfoInfo->wave]; |
167 |
|
|
168 |
|
pLFO->Trigger ( |
169 |
pLfoInfo->freq, |
pLfoInfo->freq, |
170 |
start_level_mid, |
start_level_mid, |
171 |
1, 0, false, GetSampleRate() |
1, 0, false, GetSampleRate() |
172 |
); |
); |
173 |
lfo.update(0); |
pLFO->Update(0); |
174 |
|
|
175 |
|
float phase = pLfoInfo->phase; |
176 |
|
for (int i = 0; i < pLfoInfo->phase_oncc.size(); i++) { |
177 |
|
int val = pVoice->GetControllerValue(pLfoInfo->phase_oncc[i].Controller); |
178 |
|
phase += (val / 127.0f) * pLfoInfo->phase_oncc[i].Influence; |
179 |
|
} |
180 |
|
if (phase != 0) pLFO->SetPhase(phase); |
181 |
} |
} |
182 |
|
|
183 |
void AmpLFOUnit::Trigger() { |
void AmpLFOUnit::Trigger() { |
184 |
::sfz::Region* const pRegion = pVoice->pRegion; |
::sfz::Region* const pRegion = pVoice->pRegion; |
185 |
pLfoInfo->delay = pRegion->amplfo_delay; |
pLfoInfo->delay = pRegion->amplfo_delay; |
186 |
pLfoInfo->freq = pRegion->amplfo_freq; |
pLfoInfo->freq = pRegion->amplfo_freq; |
187 |
|
pLfoInfo->fade = pRegion->amplfo_fade; |
188 |
pLfoInfo->volume = pRegion->amplfo_depth; |
pLfoInfo->volume = pRegion->amplfo_depth; |
189 |
|
|
190 |
LFOv1Unit::Trigger(); |
LFOv1Unit::Trigger(); |
193 |
void PitchLFOUnit::Trigger() { |
void PitchLFOUnit::Trigger() { |
194 |
::sfz::Region* const pRegion = pVoice->pRegion; |
::sfz::Region* const pRegion = pVoice->pRegion; |
195 |
pLfoInfo->delay = pRegion->pitchlfo_delay; |
pLfoInfo->delay = pRegion->pitchlfo_delay; |
196 |
pLfoInfo->freq = pRegion->pitchlfo_freq; |
pLfoInfo->freq = pRegion->pitchlfo_freq; |
197 |
|
pLfoInfo->fade = pRegion->pitchlfo_fade; |
198 |
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
199 |
|
|
200 |
LFOv1Unit::Trigger(); |
LFOv1Unit::Trigger(); |
202 |
|
|
203 |
void FilLFOUnit::Trigger() { |
void FilLFOUnit::Trigger() { |
204 |
::sfz::Region* const pRegion = pVoice->pRegion; |
::sfz::Region* const pRegion = pVoice->pRegion; |
205 |
pLfoInfo->delay = pRegion->fillfo_delay; |
pLfoInfo->delay = pRegion->fillfo_delay; |
206 |
pLfoInfo->freq = pRegion->fillfo_freq; |
pLfoInfo->freq = pRegion->fillfo_freq; |
207 |
|
pLfoInfo->fade = pRegion->fillfo_fade; |
208 |
pLfoInfo->cutoff = pRegion->fillfo_depth; |
pLfoInfo->cutoff = pRegion->fillfo_depth; |
209 |
|
|
210 |
LFOv1Unit::Trigger(); |
LFOv1Unit::Trigger(); |
211 |
} |
} |
212 |
|
|
213 |
|
CCUnit::CCUnit(SfzSignalUnitRack* rack): CCSignalUnit(rack) { } |
214 |
|
|
215 |
|
void CCUnit::Trigger() { |
216 |
|
for (int i = 0; i < Ctrls.size(); i++) { |
217 |
|
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
218 |
|
} |
219 |
|
CCSignalUnit::Trigger(); |
220 |
|
} |
221 |
|
|
222 |
|
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
223 |
|
RemoveAllCCs(); |
224 |
|
for (int i = 0; i < 128; i++) { |
225 |
|
if (cc[i] != 0) AddCC(i, cc[i]); |
226 |
|
} |
227 |
|
} |
228 |
|
|
229 |
|
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
230 |
|
RemoveAllCCs(); |
231 |
|
for (int i = 0; i < cc.size(); i++) { |
232 |
|
if (cc[i].Influence != 0) AddCC(cc[i].Controller, cc[i].Influence); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
278 |
FilLFOUnit* u = &(GetRack()->suFilLFO); |
FilLFOUnit* u = &(GetRack()->suFilLFO); |
279 |
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
280 |
|
|
281 |
|
FilEGUnit* u2 = &(GetRack()->suFilEG); |
282 |
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
283 |
|
|
284 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
285 |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
286 |
if (!lfo->Active()) continue; |
if (!lfo->Active()) continue; |
298 |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
299 |
|
|
300 |
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
301 |
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->pLfoInfo->pitch) : 1; |
CCSignalUnit* u3 = &(GetRack()->suPitchLFO.suDepthCC); |
302 |
|
float f = u3->Active() ? u3->GetLevel() : 0; |
303 |
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * (u2->pLfoInfo->pitch + f)) : 1; |
304 |
|
|
305 |
|
for (int i = 0; i < GetRack()->pitchLFOs.size(); i++) { |
306 |
|
LFOv2Unit* lfo = GetRack()->pitchLFOs[i]; |
307 |
|
if (!lfo->Active()) continue; |
308 |
|
|
309 |
|
float f = lfo->suPitchOnCC.Active() ? lfo->suPitchOnCC.GetLevel() : 0; |
310 |
|
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
311 |
|
} |
312 |
|
|
313 |
return p; |
return p; |
314 |
} |
} |
344 |
|
|
345 |
|
|
346 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
347 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
348 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
349 |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
350 |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
LFOs(maxLfoCount), pitchLFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
351 |
{ |
{ |
352 |
suEndpoint.pVoice = suVolEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
353 |
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
354 |
|
suPitchLFO.suDepthCC.pVoice = suPitchLFO.suFadeEG.pVoice = voice; |
355 |
|
suFilLFO.suFadeEG.pVoice = voice; |
356 |
|
suAmpLFO.suFadeEG.pVoice = voice; |
357 |
|
|
358 |
for (int i = 0; i < EGs.capacity(); i++) { |
for (int i = 0; i < EGs.capacity(); i++) { |
359 |
EGs[i] = new EGv2Unit(this); |
EGs[i] = new EGv2Unit(this); |
363 |
for (int i = 0; i < LFOs.capacity(); i++) { |
for (int i = 0; i < LFOs.capacity(); i++) { |
364 |
LFOs[i] = new LFOv2Unit(this); |
LFOs[i] = new LFOv2Unit(this); |
365 |
LFOs[i]->pVoice = voice; |
LFOs[i]->pVoice = voice; |
366 |
|
LFOs[i]->suFadeEG.pVoice = voice; |
367 |
|
LFOs[i]->suPitchOnCC.pVoice = voice; |
368 |
} |
} |
369 |
} |
} |
370 |
|
|
384 |
pitchEGs.clear(); |
pitchEGs.clear(); |
385 |
|
|
386 |
LFOs.clear(); |
LFOs.clear(); |
387 |
|
pitchLFOs.clear(); |
388 |
filLFOs.clear(); |
filLFOs.clear(); |
389 |
resLFOs.clear(); |
resLFOs.clear(); |
390 |
panLFOs.clear(); |
panLFOs.clear(); |
419 |
LFOv2Unit lfo(this); |
LFOv2Unit lfo(this); |
420 |
lfo.pLfoInfo = &(pRegion->lfos[i]); |
lfo.pLfoInfo = &(pRegion->lfos[i]); |
421 |
LFOs.increment()->Copy(lfo); |
LFOs.increment()->Copy(lfo); |
422 |
|
LFOs[LFOs.size() - 1]->suPitchOnCC.SetCCs(pRegion->lfos[i].pitch_oncc); |
423 |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
424 |
|
|
425 |
|
if (pRegion->lfos[i].pitch != 0 || !pRegion->lfos[i].pitch_oncc.empty()) { |
426 |
|
if(pitchLFOs.size() < pitchLFOs.capacity()) pitchLFOs.add(LFOs[LFOs.size() - 1]); |
427 |
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
428 |
|
} |
429 |
|
|
430 |
if (pRegion->lfos[i].cutoff != 0) { |
if (pRegion->lfos[i].cutoff != 0) { |
431 |
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
432 |
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
443 |
} |
} |
444 |
} |
} |
445 |
|
|
446 |
|
suPitchLFO.suDepthCC.SetCCs(pRegion->pitchlfo_depthcc); |
447 |
|
|
448 |
Units.clear(); |
Units.clear(); |
449 |
|
|
450 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
451 |
|
Units.add(&suFilEG); |
452 |
Units.add(&suPitchEG); |
Units.add(&suPitchEG); |
453 |
Units.add(&suPitchLFO); |
Units.add(&suPitchLFO); |
454 |
|
Units.add(&suPitchLFO.suDepthCC); |
455 |
|
Units.add(&suPitchLFO.suFadeEG); |
456 |
Units.add(&suAmpLFO); |
Units.add(&suAmpLFO); |
457 |
|
Units.add(&suAmpLFO.suFadeEG); |
458 |
Units.add(&suFilLFO); |
Units.add(&suFilLFO); |
459 |
|
Units.add(&suFilLFO.suFadeEG); |
460 |
|
|
461 |
for (int i = 0; i < EGs.size(); i++) { |
for (int i = 0; i < EGs.size(); i++) { |
462 |
Units.add(EGs[i]); |
Units.add(EGs[i]); |
464 |
|
|
465 |
for (int i = 0; i < LFOs.size(); i++) { |
for (int i = 0; i < LFOs.size(); i++) { |
466 |
Units.add(LFOs[i]); |
Units.add(LFOs[i]); |
467 |
|
Units.add(&(LFOs[i]->suFadeEG)); |
468 |
|
Units.add(&(LFOs[i]->suPitchOnCC)); |
469 |
} |
} |
470 |
|
|
471 |
Units.add(&suEndpoint); |
Units.add(&suEndpoint); |