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 |
void LFOUnit::Increment() { |
void LFOUnit::Increment() { |
103 |
if (DelayStage()) return; |
if (DelayStage()) return; |
104 |
|
|
105 |
SignalUnit::Increment(); |
SignalUnit::Increment(); |
106 |
|
|
107 |
Level = lfo.render(); |
Level = pLFO->Render(); |
108 |
} |
} |
109 |
|
|
110 |
void LFOUnit::Trigger() { |
void LFOUnit::Trigger() { |
115 |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
116 |
} |
} |
117 |
|
|
118 |
void LFOv2Unit::Trigger() { |
void LFOv1Unit::Trigger() { |
119 |
LFOUnit::Trigger(); |
LFOUnit::Trigger(); |
120 |
|
|
121 |
lfo.trigger ( |
lfo.trigger ( |
125 |
); |
); |
126 |
lfo.update(0); |
lfo.update(0); |
127 |
} |
} |
128 |
|
|
129 |
|
|
130 |
|
LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack) |
131 |
|
: LFOUnit(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f), |
132 |
|
lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f), |
133 |
|
suPitchOnCC(rack) |
134 |
|
{ |
135 |
|
lfos.add(&lfo0); |
136 |
|
lfos.add(&lfo1); |
137 |
|
lfos.add(&lfo2); |
138 |
|
lfos.add(&lfo3); |
139 |
|
lfos.add(&lfo4); |
140 |
|
lfos.add(&lfo5); |
141 |
|
lfos.add(&lfo6); |
142 |
|
lfos.add(&lfo7); |
143 |
|
} |
144 |
|
|
145 |
|
void LFOv2Unit::Trigger() { |
146 |
|
LFOUnit::Trigger(); |
147 |
|
|
148 |
|
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
149 |
|
else pLFO = lfos[pLfoInfo->wave]; |
150 |
|
|
151 |
|
pLFO->Trigger ( |
152 |
|
pLfoInfo->freq, |
153 |
|
start_level_mid, |
154 |
|
1, 0, false, GetSampleRate() |
155 |
|
); |
156 |
|
pLFO->Update(0); |
157 |
|
|
158 |
|
float phase = pLfoInfo->phase; |
159 |
|
for (int i = 0; i < pLfoInfo->phase_oncc.size(); i++) { |
160 |
|
int val = pVoice->GetControllerValue(pLfoInfo->phase_oncc[i].Controller); |
161 |
|
phase += (val / 127.0f) * pLfoInfo->phase_oncc[i].Influence; |
162 |
|
} |
163 |
|
if (phase != 0) pLFO->SetPhase(phase); |
164 |
|
} |
165 |
|
|
166 |
|
void AmpLFOUnit::Trigger() { |
167 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
168 |
|
pLfoInfo->delay = pRegion->amplfo_delay; |
169 |
|
pLfoInfo->freq = pRegion->amplfo_freq; |
170 |
|
pLfoInfo->volume = pRegion->amplfo_depth; |
171 |
|
|
172 |
|
LFOv1Unit::Trigger(); |
173 |
|
} |
174 |
|
|
175 |
|
void PitchLFOUnit::Trigger() { |
176 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
177 |
|
pLfoInfo->delay = pRegion->pitchlfo_delay; |
178 |
|
pLfoInfo->freq = pRegion->pitchlfo_freq; |
179 |
|
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
180 |
|
|
181 |
|
LFOv1Unit::Trigger(); |
182 |
|
} |
183 |
|
|
184 |
|
void FilLFOUnit::Trigger() { |
185 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
186 |
|
pLfoInfo->delay = pRegion->fillfo_delay; |
187 |
|
pLfoInfo->freq = pRegion->fillfo_freq; |
188 |
|
pLfoInfo->cutoff = pRegion->fillfo_depth; |
189 |
|
|
190 |
|
LFOv1Unit::Trigger(); |
191 |
|
} |
192 |
|
|
193 |
|
CCUnit::CCUnit(SfzSignalUnitRack* rack): CCSignalUnit(rack) { } |
194 |
|
|
195 |
|
void CCUnit::Trigger() { |
196 |
|
for (int i = 0; i < Ctrls.size(); i++) { |
197 |
|
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
198 |
|
} |
199 |
|
CCSignalUnit::Trigger(); |
200 |
|
} |
201 |
|
|
202 |
|
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
203 |
|
RemoveAllCCs(); |
204 |
|
for (int i = 0; i < 128; i++) { |
205 |
|
if (cc[i] != 0) AddCC(i, cc[i]); |
206 |
|
} |
207 |
|
} |
208 |
|
|
209 |
|
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
210 |
|
RemoveAllCCs(); |
211 |
|
for (int i = 0; i < cc.size(); i++) { |
212 |
|
if (cc[i].Influence != 0) AddCC(cc[i].Controller, cc[i].Influence); |
213 |
|
} |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
246 |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
247 |
} |
} |
248 |
|
|
249 |
|
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
250 |
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
251 |
|
|
252 |
return vol; |
return vol; |
253 |
} |
} |
254 |
|
|
255 |
float EndpointUnit::GetFilterCutoff() { |
float EndpointUnit::GetFilterCutoff() { |
256 |
float val = 1; |
float val; |
257 |
|
|
258 |
|
FilLFOUnit* u = &(GetRack()->suFilLFO); |
259 |
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
260 |
|
|
261 |
|
FilEGUnit* u2 = &(GetRack()->suFilEG); |
262 |
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
263 |
|
|
264 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
265 |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
273 |
} |
} |
274 |
|
|
275 |
float EndpointUnit::GetPitch() { |
float EndpointUnit::GetPitch() { |
276 |
|
double p; |
277 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
EGv1Unit* u = &(GetRack()->suPitchEG); |
278 |
double pitchEg = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
279 |
return pitchEg; |
|
280 |
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
281 |
|
CCSignalUnit* u3 = &(GetRack()->suPitchLFO.suDepthCC); |
282 |
|
float f = u3->Active() ? u3->GetLevel() : 0; |
283 |
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * (u2->pLfoInfo->pitch + f)) : 1; |
284 |
|
|
285 |
|
for (int i = 0; i < GetRack()->pitchLFOs.size(); i++) { |
286 |
|
LFOv2Unit* lfo = GetRack()->pitchLFOs[i]; |
287 |
|
if (!lfo->Active()) continue; |
288 |
|
|
289 |
|
float f = lfo->suPitchOnCC.Active() ? lfo->suPitchOnCC.GetLevel() : 0; |
290 |
|
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
291 |
|
} |
292 |
|
|
293 |
|
return p; |
294 |
} |
} |
295 |
|
|
296 |
float EndpointUnit::GetResonance() { |
float EndpointUnit::GetResonance() { |
324 |
|
|
325 |
|
|
326 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
327 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
328 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
329 |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
330 |
|
LFOs(maxLfoCount), pitchLFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
331 |
{ |
{ |
332 |
suEndpoint.pVoice = suVolEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
333 |
|
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
334 |
|
suPitchLFO.suDepthCC.pVoice = voice; |
335 |
|
|
336 |
for (int i = 0; i < EGs.capacity(); i++) { |
for (int i = 0; i < EGs.capacity(); i++) { |
337 |
EGs[i] = new EGv2Unit(this); |
EGs[i] = new EGv2Unit(this); |
341 |
for (int i = 0; i < LFOs.capacity(); i++) { |
for (int i = 0; i < LFOs.capacity(); i++) { |
342 |
LFOs[i] = new LFOv2Unit(this); |
LFOs[i] = new LFOv2Unit(this); |
343 |
LFOs[i]->pVoice = voice; |
LFOs[i]->pVoice = voice; |
344 |
|
LFOs[i]->suPitchOnCC.pVoice = voice; |
345 |
} |
} |
346 |
} |
} |
347 |
|
|
361 |
pitchEGs.clear(); |
pitchEGs.clear(); |
362 |
|
|
363 |
LFOs.clear(); |
LFOs.clear(); |
364 |
|
pitchLFOs.clear(); |
365 |
filLFOs.clear(); |
filLFOs.clear(); |
366 |
resLFOs.clear(); |
resLFOs.clear(); |
367 |
panLFOs.clear(); |
panLFOs.clear(); |
396 |
LFOv2Unit lfo(this); |
LFOv2Unit lfo(this); |
397 |
lfo.pLfoInfo = &(pRegion->lfos[i]); |
lfo.pLfoInfo = &(pRegion->lfos[i]); |
398 |
LFOs.increment()->Copy(lfo); |
LFOs.increment()->Copy(lfo); |
399 |
|
LFOs[LFOs.size() - 1]->suPitchOnCC.SetCCs(pRegion->lfos[i].pitch_oncc); |
400 |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
401 |
|
|
402 |
|
if (pRegion->lfos[i].pitch != 0 || !pRegion->lfos[i].pitch_oncc.empty()) { |
403 |
|
if(pitchLFOs.size() < pitchLFOs.capacity()) pitchLFOs.add(LFOs[LFOs.size() - 1]); |
404 |
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
405 |
|
} |
406 |
|
|
407 |
if (pRegion->lfos[i].cutoff != 0) { |
if (pRegion->lfos[i].cutoff != 0) { |
408 |
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
409 |
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
420 |
} |
} |
421 |
} |
} |
422 |
|
|
423 |
|
suPitchLFO.suDepthCC.SetCCs(pRegion->pitchlfo_depthcc); |
424 |
|
|
425 |
Units.clear(); |
Units.clear(); |
426 |
|
|
427 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
428 |
|
Units.add(&suFilEG); |
429 |
Units.add(&suPitchEG); |
Units.add(&suPitchEG); |
430 |
|
Units.add(&suPitchLFO); |
431 |
|
Units.add(&suPitchLFO.suDepthCC); |
432 |
|
Units.add(&suAmpLFO); |
433 |
|
Units.add(&suFilLFO); |
434 |
|
|
435 |
for (int i = 0; i < EGs.size(); i++) { |
for (int i = 0; i < EGs.size(); i++) { |
436 |
Units.add(EGs[i]); |
Units.add(EGs[i]); |
438 |
|
|
439 |
for (int i = 0; i < LFOs.size(); i++) { |
for (int i = 0; i < LFOs.size(); i++) { |
440 |
Units.add(LFOs[i]); |
Units.add(LFOs[i]); |
441 |
|
Units.add(&(LFOs[i]->suPitchOnCC)); |
442 |
} |
} |
443 |
|
|
444 |
Units.add(&suEndpoint); |
Units.add(&suEndpoint); |