22 |
|
|
23 |
#include "SfzSignalUnitRack.h" |
#include "SfzSignalUnitRack.h" |
24 |
#include "Voice.h" |
#include "Voice.h" |
25 |
|
#include <SF.h> |
26 |
|
|
27 |
namespace LinuxSampler { namespace sfz { |
namespace LinuxSampler { namespace sfz { |
28 |
|
|
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(SfzSignalUnitRack* rack) |
103 |
|
: SfzSignalUnit(rack), pLfoInfo(NULL), pLFO(NULL), |
104 |
|
suFadeEG(rack), suFreqOnCC(rack, this) |
105 |
|
{ } |
106 |
|
|
107 |
|
LFOUnit::LFOUnit(const LFOUnit& Unit) |
108 |
|
: SfzSignalUnit(Unit), suFadeEG(static_cast<SfzSignalUnitRack*>(Unit.pRack)), |
109 |
|
suFreqOnCC(static_cast<SfzSignalUnitRack*>(Unit.pRack), this) |
110 |
|
{ |
111 |
|
Copy(Unit); |
112 |
|
} |
113 |
|
|
114 |
void LFOUnit::Increment() { |
void LFOUnit::Increment() { |
115 |
if (DelayStage()) return; |
if (DelayStage()) return; |
116 |
|
|
117 |
SignalUnit::Increment(); |
SignalUnit::Increment(); |
118 |
|
|
119 |
Level = lfo.render(); |
Level = pLFO->Render(); |
120 |
|
if (suFadeEG.Active()) Level *= suFadeEG.GetLevel(); |
121 |
} |
} |
122 |
|
|
123 |
void LFOUnit::Trigger() { |
void LFOUnit::Trigger() { |
126 |
|
|
127 |
// set the delay trigger |
// set the delay trigger |
128 |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
129 |
|
if(pLfoInfo->fade != 0 || !pLfoInfo->fade_oncc.empty()) { |
130 |
|
float f = pLfoInfo->fade; |
131 |
|
for (int i = 0; i < pLfoInfo->fade_oncc.size(); i++) { |
132 |
|
int val = pVoice->GetControllerValue(pLfoInfo->fade_oncc[i].Controller); |
133 |
|
f += (val / 127.0f) * pLfoInfo->fade_oncc[i].Influence; |
134 |
|
} |
135 |
|
|
136 |
|
if (f != 0) { |
137 |
|
suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
138 |
|
suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate()); |
139 |
|
} |
140 |
|
} |
141 |
} |
} |
142 |
|
|
143 |
void LFOv2Unit::Trigger() { |
void LFOUnit::ValueChanged(CCSignalUnit* pUnit) { |
144 |
|
pLFO->SetFrequency(suFreqOnCC.GetLevel() + pLfoInfo->freq, GetSampleRate()); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
void LFOv1Unit::Trigger() { |
149 |
LFOUnit::Trigger(); |
LFOUnit::Trigger(); |
150 |
|
|
151 |
lfo.trigger ( |
lfo.trigger ( |
152 |
pLfoInfo->freq, |
pLfoInfo->freq + suFreqOnCC.GetLevel(), |
153 |
start_level_mid, |
start_level_mid, |
154 |
1, 0, false, GetSampleRate() |
1, 0, false, GetSampleRate() |
155 |
); |
); |
156 |
lfo.update(0); |
lfo.update(0); |
157 |
} |
} |
158 |
|
|
159 |
|
|
160 |
|
LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack) |
161 |
|
: LFOUnit(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f), |
162 |
|
lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f), |
163 |
|
suPitchOnCC(rack) |
164 |
|
{ |
165 |
|
lfos.add(&lfo0); |
166 |
|
lfos.add(&lfo1); |
167 |
|
lfos.add(&lfo2); |
168 |
|
lfos.add(&lfo3); |
169 |
|
lfos.add(&lfo4); |
170 |
|
lfos.add(&lfo5); |
171 |
|
lfos.add(&lfo6); |
172 |
|
lfos.add(&lfo7); |
173 |
|
} |
174 |
|
|
175 |
|
void LFOv2Unit::Trigger() { |
176 |
|
LFOUnit::Trigger(); |
177 |
|
|
178 |
|
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
179 |
|
else pLFO = lfos[pLfoInfo->wave]; |
180 |
|
|
181 |
|
pLFO->Trigger ( |
182 |
|
pLfoInfo->freq + suFreqOnCC.GetLevel(), |
183 |
|
start_level_mid, |
184 |
|
1, 0, false, GetSampleRate() |
185 |
|
); |
186 |
|
pLFO->Update(0); |
187 |
|
|
188 |
|
float phase = pLfoInfo->phase; |
189 |
|
for (int i = 0; i < pLfoInfo->phase_oncc.size(); i++) { |
190 |
|
int val = pVoice->GetControllerValue(pLfoInfo->phase_oncc[i].Controller); |
191 |
|
phase += (val / 127.0f) * pLfoInfo->phase_oncc[i].Influence; |
192 |
|
} |
193 |
|
if (phase != 0) pLFO->SetPhase(phase); |
194 |
|
} |
195 |
|
|
196 |
|
void AmpLFOUnit::Trigger() { |
197 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
198 |
|
pLfoInfo->delay = pRegion->amplfo_delay; |
199 |
|
pLfoInfo->freq = pRegion->amplfo_freq; |
200 |
|
pLfoInfo->fade = pRegion->amplfo_fade; |
201 |
|
pLfoInfo->volume = pRegion->amplfo_depth; |
202 |
|
|
203 |
|
LFOv1Unit::Trigger(); |
204 |
|
} |
205 |
|
|
206 |
|
void PitchLFOUnit::Trigger() { |
207 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
208 |
|
pLfoInfo->delay = pRegion->pitchlfo_delay; |
209 |
|
pLfoInfo->freq = pRegion->pitchlfo_freq; |
210 |
|
pLfoInfo->fade = pRegion->pitchlfo_fade; |
211 |
|
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
212 |
|
|
213 |
|
LFOv1Unit::Trigger(); |
214 |
|
} |
215 |
|
|
216 |
|
void FilLFOUnit::Trigger() { |
217 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
218 |
|
pLfoInfo->delay = pRegion->fillfo_delay; |
219 |
|
pLfoInfo->freq = pRegion->fillfo_freq; |
220 |
|
pLfoInfo->fade = pRegion->fillfo_fade; |
221 |
|
pLfoInfo->cutoff = pRegion->fillfo_depth; |
222 |
|
|
223 |
|
LFOv1Unit::Trigger(); |
224 |
|
} |
225 |
|
|
226 |
|
CCUnit::CCUnit(SfzSignalUnitRack* rack, Listener* l): CCSignalUnit(rack, l) { |
227 |
|
pVoice = NULL; |
228 |
|
} |
229 |
|
|
230 |
|
void CCUnit::Trigger() { |
231 |
|
for (int i = 0; i < Ctrls.size(); i++) { |
232 |
|
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
233 |
|
} |
234 |
|
CCSignalUnit::Trigger(); |
235 |
|
} |
236 |
|
|
237 |
|
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
238 |
|
RemoveAllCCs(); |
239 |
|
for (int i = 0; i < 128; i++) { |
240 |
|
if (cc[i] != 0) AddCC(i, cc[i]); |
241 |
|
} |
242 |
|
} |
243 |
|
|
244 |
|
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
245 |
|
RemoveAllCCs(); |
246 |
|
for (int i = 0; i < cc.size(); i++) { |
247 |
|
if (cc[i].Influence != 0) AddCC(cc[i].Controller, cc[i].Influence); |
248 |
|
} |
249 |
|
} |
250 |
|
|
251 |
|
|
252 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
281 |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
282 |
} |
} |
283 |
|
|
284 |
|
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
285 |
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
286 |
|
|
287 |
return vol; |
return vol; |
288 |
} |
} |
289 |
|
|
290 |
float EndpointUnit::GetFilterCutoff() { |
float EndpointUnit::GetFilterCutoff() { |
291 |
float val = 1; |
float val; |
292 |
|
|
293 |
|
FilLFOUnit* u = &(GetRack()->suFilLFO); |
294 |
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
295 |
|
|
296 |
|
FilEGUnit* u2 = &(GetRack()->suFilEG); |
297 |
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
298 |
|
|
299 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
300 |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
308 |
} |
} |
309 |
|
|
310 |
float EndpointUnit::GetPitch() { |
float EndpointUnit::GetPitch() { |
311 |
|
double p; |
312 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
EGv1Unit* u = &(GetRack()->suPitchEG); |
313 |
double pitchEg = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
314 |
return pitchEg; |
|
315 |
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
316 |
|
CCSignalUnit* u3 = &(GetRack()->suPitchLFO.suDepthCC); |
317 |
|
float f = u3->Active() ? u3->GetLevel() : 0; |
318 |
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * (u2->pLfoInfo->pitch + f)) : 1; |
319 |
|
|
320 |
|
for (int i = 0; i < GetRack()->pitchLFOs.size(); i++) { |
321 |
|
LFOv2Unit* lfo = GetRack()->pitchLFOs[i]; |
322 |
|
if (!lfo->Active()) continue; |
323 |
|
|
324 |
|
float f = lfo->suPitchOnCC.Active() ? lfo->suPitchOnCC.GetLevel() : 0; |
325 |
|
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
326 |
|
} |
327 |
|
|
328 |
|
return p; |
329 |
} |
} |
330 |
|
|
331 |
float EndpointUnit::GetResonance() { |
float EndpointUnit::GetResonance() { |
359 |
|
|
360 |
|
|
361 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
362 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
363 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
364 |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
365 |
|
LFOs(maxLfoCount), pitchLFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
366 |
{ |
{ |
367 |
suEndpoint.pVoice = suVolEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
368 |
|
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
369 |
|
suPitchLFO.suDepthCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice; |
370 |
|
suFilLFO.suFadeEG.pVoice = suFilLFO.suFreqOnCC.pVoice = voice; |
371 |
|
suAmpLFO.suFadeEG.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice; |
372 |
|
|
373 |
for (int i = 0; i < EGs.capacity(); i++) { |
for (int i = 0; i < EGs.capacity(); i++) { |
374 |
EGs[i] = new EGv2Unit(this); |
EGs[i] = new EGv2Unit(this); |
378 |
for (int i = 0; i < LFOs.capacity(); i++) { |
for (int i = 0; i < LFOs.capacity(); i++) { |
379 |
LFOs[i] = new LFOv2Unit(this); |
LFOs[i] = new LFOv2Unit(this); |
380 |
LFOs[i]->pVoice = voice; |
LFOs[i]->pVoice = voice; |
381 |
|
LFOs[i]->suFadeEG.pVoice = voice; |
382 |
|
LFOs[i]->suPitchOnCC.pVoice = voice; |
383 |
|
LFOs[i]->suFreqOnCC.pVoice = voice; |
384 |
} |
} |
385 |
} |
} |
386 |
|
|
400 |
pitchEGs.clear(); |
pitchEGs.clear(); |
401 |
|
|
402 |
LFOs.clear(); |
LFOs.clear(); |
403 |
|
pitchLFOs.clear(); |
404 |
filLFOs.clear(); |
filLFOs.clear(); |
405 |
resLFOs.clear(); |
resLFOs.clear(); |
406 |
panLFOs.clear(); |
panLFOs.clear(); |
435 |
LFOv2Unit lfo(this); |
LFOv2Unit lfo(this); |
436 |
lfo.pLfoInfo = &(pRegion->lfos[i]); |
lfo.pLfoInfo = &(pRegion->lfos[i]); |
437 |
LFOs.increment()->Copy(lfo); |
LFOs.increment()->Copy(lfo); |
438 |
|
LFOs[LFOs.size() - 1]->suPitchOnCC.SetCCs(pRegion->lfos[i].pitch_oncc); |
439 |
|
LFOs[LFOs.size() - 1]->suFreqOnCC.SetCCs(pRegion->lfos[i].freq_oncc); |
440 |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
441 |
|
|
442 |
|
if (pRegion->lfos[i].pitch != 0 || !pRegion->lfos[i].pitch_oncc.empty()) { |
443 |
|
if(pitchLFOs.size() < pitchLFOs.capacity()) pitchLFOs.add(LFOs[LFOs.size() - 1]); |
444 |
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
445 |
|
} |
446 |
|
|
447 |
if (pRegion->lfos[i].cutoff != 0) { |
if (pRegion->lfos[i].cutoff != 0) { |
448 |
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
449 |
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
460 |
} |
} |
461 |
} |
} |
462 |
|
|
463 |
|
suPitchLFO.suDepthCC.SetCCs(pRegion->pitchlfo_depthcc); |
464 |
|
suPitchLFO.suFreqOnCC.SetCCs(pRegion->pitchlfo_freqcc); |
465 |
|
|
466 |
|
suFilLFO.suFreqOnCC.SetCCs(pRegion->fillfo_freqcc); |
467 |
|
|
468 |
|
suAmpLFO.suFreqOnCC.SetCCs(pRegion->amplfo_freqcc); |
469 |
|
|
470 |
Units.clear(); |
Units.clear(); |
471 |
|
|
472 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
473 |
|
Units.add(&suFilEG); |
474 |
Units.add(&suPitchEG); |
Units.add(&suPitchEG); |
475 |
|
|
476 |
|
Units.add(&suPitchLFO.suFreqOnCC); // Don't change order! (should be triggered before the LFO) |
477 |
|
Units.add(&suPitchLFO); |
478 |
|
Units.add(&suPitchLFO.suDepthCC); |
479 |
|
Units.add(&suPitchLFO.suFadeEG); |
480 |
|
|
481 |
|
Units.add(&suAmpLFO.suFreqOnCC); // Don't change order! (should be triggered before the LFO) |
482 |
|
Units.add(&suAmpLFO); |
483 |
|
Units.add(&suAmpLFO.suFadeEG); |
484 |
|
|
485 |
|
Units.add(&suFilLFO.suFreqOnCC); // Don't change order! (should be triggered before the LFO) |
486 |
|
Units.add(&suFilLFO); |
487 |
|
Units.add(&suFilLFO.suFadeEG); |
488 |
|
|
489 |
for (int i = 0; i < EGs.size(); i++) { |
for (int i = 0; i < EGs.size(); i++) { |
490 |
Units.add(EGs[i]); |
Units.add(EGs[i]); |
491 |
} |
} |
492 |
|
|
493 |
for (int i = 0; i < LFOs.size(); i++) { |
for (int i = 0; i < LFOs.size(); i++) { |
494 |
|
Units.add(&(LFOs[i]->suFreqOnCC)); // Don't change order! (should be triggered before the LFO) |
495 |
Units.add(LFOs[i]); |
Units.add(LFOs[i]); |
496 |
|
Units.add(&(LFOs[i]->suFadeEG)); |
497 |
|
Units.add(&(LFOs[i]->suPitchOnCC)); |
498 |
} |
} |
499 |
|
|
500 |
Units.add(&suEndpoint); |
Units.add(&suEndpoint); |