2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2011 Grigor Iliev * |
* Copyright (C) 2011 - 2012 Grigor Iliev * |
6 |
* * |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
8 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
142 |
f = GetInfluence(egInfo.node[i].time_oncc); |
f = GetInfluence(egInfo.node[i].time_oncc); |
143 |
egInfo.node[i].time = std::min(egInfo.node[i].time + f, 100.0f); |
egInfo.node[i].time = std::min(egInfo.node[i].time + f, 100.0f); |
144 |
} |
} |
145 |
EG.trigger(egInfo, GetSampleRate(), pVoice->MIDIVelocity); |
EG.trigger(egInfo, GetSampleRate(), pVoice->MIDIVelocity()); |
146 |
} |
} |
147 |
|
|
148 |
|
|
151 |
depth = pRegion->pitcheg_depth + GetInfluence(pRegion->pitcheg_depth_oncc); |
depth = pRegion->pitcheg_depth + GetInfluence(pRegion->pitcheg_depth_oncc); |
152 |
|
|
153 |
// the length of the decay and release curves are dependent on the velocity |
// the length of the decay and release curves are dependent on the velocity |
154 |
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity()); |
155 |
|
|
156 |
// set the delay trigger |
// set the delay trigger |
157 |
float delay = pRegion->pitcheg_delay + pRegion->pitcheg_vel2delay * velrelease; |
float delay = pRegion->pitcheg_delay + pRegion->pitcheg_vel2delay * velrelease; |
177 |
|
|
178 |
EG.trigger ( |
EG.trigger ( |
179 |
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
180 |
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() |
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate(), true |
181 |
); |
); |
182 |
} |
} |
183 |
|
|
187 |
depth = pRegion->fileg_depth + GetInfluence(pRegion->fileg_depth_oncc); |
depth = pRegion->fileg_depth + GetInfluence(pRegion->fileg_depth_oncc); |
188 |
|
|
189 |
// the length of the decay and release curves are dependent on the velocity |
// the length of the decay and release curves are dependent on the velocity |
190 |
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity()); |
191 |
|
|
192 |
// set the delay trigger |
// set the delay trigger |
193 |
float delay = pRegion->fileg_delay + pRegion->fileg_vel2delay * velrelease; |
float delay = pRegion->fileg_delay + pRegion->fileg_vel2delay * velrelease; |
213 |
|
|
214 |
EG.trigger ( |
EG.trigger ( |
215 |
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
216 |
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() |
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate(), true |
217 |
); |
); |
218 |
} |
} |
219 |
|
|
222 |
::sfz::Region* const pRegion = pVoice->pRegion; |
::sfz::Region* const pRegion = pVoice->pRegion; |
223 |
|
|
224 |
// the length of the decay and release curves are dependent on the velocity |
// the length of the decay and release curves are dependent on the velocity |
225 |
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity()); |
226 |
|
|
227 |
// set the delay trigger |
// set the delay trigger |
228 |
float delay = pRegion->ampeg_delay + pRegion->ampeg_vel2delay * velrelease; |
float delay = pRegion->ampeg_delay + pRegion->ampeg_vel2delay * velrelease; |
242 |
|
|
243 |
float sustain = pRegion->ampeg_sustain + pRegion->ampeg_vel2sustain * velrelease; |
float sustain = pRegion->ampeg_sustain + pRegion->ampeg_vel2sustain * velrelease; |
244 |
sustain = 10 * (sustain + GetInfluence(pRegion->ampeg_sustaincc)); |
sustain = 10 * (sustain + GetInfluence(pRegion->ampeg_sustaincc)); |
245 |
|
if (pVoice->pNote) { |
246 |
|
pVoice->pNote->Override.Sustain.applyTo(sustain); |
247 |
|
} |
248 |
|
|
249 |
float release = pRegion->ampeg_release + pRegion->ampeg_vel2release * velrelease; |
float release = pRegion->ampeg_release + pRegion->ampeg_vel2release * velrelease; |
250 |
release = std::max(0.0f, release + GetInfluence(pRegion->ampeg_releasecc)); |
release = std::max(0.0f, release + GetInfluence(pRegion->ampeg_releasecc)); |
251 |
|
|
252 |
EG.trigger ( |
EG.trigger ( |
253 |
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
254 |
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() |
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate(), false |
255 |
); |
); |
256 |
} |
} |
257 |
|
|
258 |
|
|
259 |
LFOUnit::LFOUnit(SfzSignalUnitRack* rack) |
LFOUnit::LFOUnit(SfzSignalUnitRack* rack) |
260 |
: SfzSignalUnit(rack), pLfoInfo(NULL), pLFO(NULL), |
: SfzSignalUnit(rack), pLfoInfo(NULL), pLFO(NULL), |
261 |
suFadeEG(rack), suFreqOnCC(rack, this), suDepthOnCC(rack) |
suFadeEG(rack), suDepthOnCC(rack), suFreqOnCC(rack, this) |
262 |
{ } |
{ } |
263 |
|
|
264 |
LFOUnit::LFOUnit(const LFOUnit& Unit) |
LFOUnit::LFOUnit(const LFOUnit& Unit) |
265 |
: SfzSignalUnit(Unit), suFadeEG(static_cast<SfzSignalUnitRack*>(Unit.pRack)), |
: SfzSignalUnit(Unit), suFadeEG(static_cast<SfzSignalUnitRack*>(Unit.pRack)), |
266 |
suFreqOnCC(static_cast<SfzSignalUnitRack*>(Unit.pRack), this), |
suDepthOnCC(static_cast<SfzSignalUnitRack*>(Unit.pRack)), |
267 |
suDepthOnCC(static_cast<SfzSignalUnitRack*>(Unit.pRack)) |
suFreqOnCC(static_cast<SfzSignalUnitRack*>(Unit.pRack), this) |
268 |
{ |
{ |
269 |
Copy(Unit); |
Copy(Unit); |
270 |
} |
} |
290 |
|
|
291 |
if (f != 0) { |
if (f != 0) { |
292 |
suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
293 |
suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate()); |
suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate(), false); |
294 |
} |
} |
295 |
} |
} |
296 |
} |
} |
309 |
start_level_mid, |
start_level_mid, |
310 |
1, 0, false, GetSampleRate() |
1, 0, false, GetSampleRate() |
311 |
); |
); |
312 |
lfo.update(0); |
lfo.updateByMIDICtrlValue(0); |
313 |
} |
} |
314 |
|
|
315 |
|
|
331 |
void LFOv2Unit::Trigger() { |
void LFOv2Unit::Trigger() { |
332 |
LFOUnit::Trigger(); |
LFOUnit::Trigger(); |
333 |
|
|
334 |
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
if (/*pLfoInfo->wave < 0 ||*/ pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
335 |
else pLFO = lfos[pLfoInfo->wave]; |
else pLFO = lfos[pLfoInfo->wave]; |
336 |
|
|
337 |
pLFO->Trigger ( |
pLFO->Trigger ( |
486 |
|
|
487 |
|
|
488 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack) |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack) |
489 |
: EndpointSignalUnit(rack), suXFInCC(rack), suXFOutCC(rack), suPanOnCC(rack), pitchVeltrackRatio(0) |
: EndpointSignalUnit(rack), pitchVeltrackRatio(0), suXFInCC(rack), suXFOutCC(rack), suPanOnCC(rack) |
490 |
{ |
{ |
491 |
|
|
492 |
} |
} |
493 |
|
|
494 |
float EndpointUnit::GetInfluence(::sfz::Array< ::sfz::optional<float> >& cc) { |
float EndpointUnit::GetInfluence(::sfz::Array< optional<float> >& cc) { |
495 |
float f = 0; |
float f = 0; |
496 |
for (int i = 0; i < 128; i++) { |
for (int i = 0; i < 128; i++) { |
497 |
if (cc[i]) { |
if (cc[i]) { |
501 |
return f; |
return f; |
502 |
} |
} |
503 |
|
|
504 |
float EndpointUnit::GetInfluence(::sfz::Array< ::sfz::optional<int> >& cc) { |
float EndpointUnit::GetInfluence(::sfz::Array< optional<int> >& cc) { |
505 |
float f = 0; |
float f = 0; |
506 |
for (int i = 0; i < 128; i++) { |
for (int i = 0; i < 128; i++) { |
507 |
if (cc[i]) { |
if (cc[i]) { |
533 |
|
|
534 |
float xfInVelCoeff = 1; |
float xfInVelCoeff = 1; |
535 |
|
|
536 |
if (pVoice->MIDIVelocity <= pVoice->pRegion->xfin_lovel) { |
if (pVoice->MIDIVelocity() <= pVoice->pRegion->xfin_lovel) { |
537 |
xfInVelCoeff = 0; |
xfInVelCoeff = 0; |
538 |
} else if (pVoice->MIDIVelocity >= pVoice->pRegion->xfin_hivel) { |
} else if (pVoice->MIDIVelocity() >= pVoice->pRegion->xfin_hivel) { |
539 |
xfInVelCoeff = 1; |
xfInVelCoeff = 1; |
540 |
} else { |
} else { |
541 |
float xfVelSize = pVoice->pRegion->xfin_hivel - pVoice->pRegion->xfin_lovel; |
float xfVelSize = pVoice->pRegion->xfin_hivel - pVoice->pRegion->xfin_lovel; |
542 |
float velPos = pVoice->MIDIVelocity - pVoice->pRegion->xfin_lovel; |
float velPos = pVoice->MIDIVelocity() - pVoice->pRegion->xfin_lovel; |
543 |
xfInVelCoeff = velPos / xfVelSize; |
xfInVelCoeff = velPos / xfVelSize; |
544 |
if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { |
if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { |
545 |
xfInVelCoeff = sin(xfInVelCoeff * M_PI / 2.0); |
xfInVelCoeff = sin(xfInVelCoeff * M_PI / 2.0); |
548 |
|
|
549 |
float xfOutVelCoeff = 1; |
float xfOutVelCoeff = 1; |
550 |
|
|
551 |
if (pVoice->MIDIVelocity >= pVoice->pRegion->xfout_hivel) { |
if (pVoice->MIDIVelocity() >= pVoice->pRegion->xfout_hivel) { |
552 |
if (pVoice->pRegion->xfout_lovel < 127 /* is set */) xfOutVelCoeff = 0; |
if (pVoice->pRegion->xfout_lovel < 127 /* is set */) xfOutVelCoeff = 0; |
553 |
} else if (pVoice->MIDIVelocity <= pVoice->pRegion->xfout_lovel) { |
} else if (pVoice->MIDIVelocity() <= pVoice->pRegion->xfout_lovel) { |
554 |
xfOutVelCoeff = 1; |
xfOutVelCoeff = 1; |
555 |
} else { |
} else { |
556 |
float xfVelSize = pVoice->pRegion->xfout_hivel - pVoice->pRegion->xfout_lovel; |
float xfVelSize = pVoice->pRegion->xfout_hivel - pVoice->pRegion->xfout_lovel; |
557 |
float velPos = pVoice->MIDIVelocity - pVoice->pRegion->xfout_lovel; |
float velPos = pVoice->MIDIVelocity() - pVoice->pRegion->xfout_lovel; |
558 |
xfOutVelCoeff = 1.0f - velPos / xfVelSize; |
xfOutVelCoeff = 1.0f - velPos / xfVelSize; |
559 |
if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { |
if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { |
560 |
xfOutVelCoeff = sin(xfOutVelCoeff * M_PI / 2.0); |
xfOutVelCoeff = sin(xfOutVelCoeff * M_PI / 2.0); |
563 |
|
|
564 |
float xfInKeyCoeff = 1; |
float xfInKeyCoeff = 1; |
565 |
|
|
566 |
if (pVoice->MIDIKey <= pVoice->pRegion->xfin_lokey) { |
if (pVoice->MIDIKey() <= pVoice->pRegion->xfin_lokey) { |
567 |
if (pVoice->pRegion->xfin_hikey > 0 /* is set */) xfInKeyCoeff = 0; |
if (pVoice->pRegion->xfin_hikey > 0 /* is set */) xfInKeyCoeff = 0; |
568 |
} else if (pVoice->MIDIKey >= pVoice->pRegion->xfin_hikey) { |
} else if (pVoice->MIDIKey() >= pVoice->pRegion->xfin_hikey) { |
569 |
xfInKeyCoeff = 1; |
xfInKeyCoeff = 1; |
570 |
} else { |
} else { |
571 |
float xfKeySize = pVoice->pRegion->xfin_hikey - pVoice->pRegion->xfin_lokey; |
float xfKeySize = pVoice->pRegion->xfin_hikey - pVoice->pRegion->xfin_lokey; |
572 |
float keyPos = pVoice->MIDIKey - pVoice->pRegion->xfin_lokey; |
float keyPos = pVoice->MIDIKey() - pVoice->pRegion->xfin_lokey; |
573 |
xfInKeyCoeff = keyPos / xfKeySize; |
xfInKeyCoeff = keyPos / xfKeySize; |
574 |
if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { |
if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { |
575 |
xfInKeyCoeff = sin(xfInKeyCoeff * M_PI / 2.0); |
xfInKeyCoeff = sin(xfInKeyCoeff * M_PI / 2.0); |
578 |
|
|
579 |
float xfOutKeyCoeff = 1; |
float xfOutKeyCoeff = 1; |
580 |
|
|
581 |
if (pVoice->MIDIKey >= pVoice->pRegion->xfout_hikey) { |
if (pVoice->MIDIKey() >= pVoice->pRegion->xfout_hikey) { |
582 |
if (pVoice->pRegion->xfout_lokey < 127 /* is set */) xfOutKeyCoeff = 0; |
if (pVoice->pRegion->xfout_lokey < 127 /* is set */) xfOutKeyCoeff = 0; |
583 |
} else if (pVoice->MIDIKey <= pVoice->pRegion->xfout_lokey) { |
} else if (pVoice->MIDIKey() <= pVoice->pRegion->xfout_lokey) { |
584 |
xfOutKeyCoeff = 1; |
xfOutKeyCoeff = 1; |
585 |
} else { |
} else { |
586 |
float xfKeySize = pVoice->pRegion->xfout_hikey - pVoice->pRegion->xfout_lokey; |
float xfKeySize = pVoice->pRegion->xfout_hikey - pVoice->pRegion->xfout_lokey; |
587 |
float keyPos = pVoice->MIDIKey - pVoice->pRegion->xfout_lokey; |
float keyPos = pVoice->MIDIKey() - pVoice->pRegion->xfout_lokey; |
588 |
xfOutKeyCoeff = 1.0f - keyPos / xfKeySize; |
xfOutKeyCoeff = 1.0f - keyPos / xfKeySize; |
589 |
if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { |
if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { |
590 |
xfOutKeyCoeff = sin(xfOutKeyCoeff * M_PI / 2.0); |
xfOutKeyCoeff = sin(xfOutKeyCoeff * M_PI / 2.0); |
598 |
|
|
599 |
suPanOnCC.SetCCs(pVoice->pRegion->pan_oncc); |
suPanOnCC.SetCCs(pVoice->pRegion->pan_oncc); |
600 |
|
|
601 |
pitchVeltrackRatio = RTMath::CentsToFreqRatioUnlimited((pVoice->MIDIVelocity / 127.0f) * pVoice->pRegion->pitch_veltrack); |
pitchVeltrackRatio = RTMath::CentsToFreqRatioUnlimited((pVoice->MIDIVelocity() / 127.0f) * pVoice->pRegion->pitch_veltrack); |
602 |
} |
} |
603 |
|
|
604 |
bool EndpointUnit::Active() { |
bool EndpointUnit::Active() { |
774 |
pan += lfo->GetLevel() * (lfo->pLfoInfo->pan + f); |
pan += lfo->GetLevel() * (lfo->pLfoInfo->pan + f); |
775 |
} |
} |
776 |
|
|
|
if(pan < -100) return -100; |
|
|
if(pan > 100) return 100; |
|
|
|
|
777 |
return pan; |
return pan; |
778 |
} |
} |
779 |
|
|
780 |
|
|
781 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
782 |
: SignalUnitRack(MaxUnitCount), EqUnitSupport(this, voice), pVoice(voice), |
: SignalUnitRack(MaxUnitCount), EqUnitSupport(this, voice), |
783 |
suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
784 |
|
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
785 |
|
suVolOnCC(this), suPitchOnCC(this), suCutoffOnCC(this), suResOnCC(this), |
786 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), |
787 |
resEGs(maxEgCount), panEGs(maxEgCount), eqEGs(maxEgCount), |
resEGs(maxEgCount), panEGs(maxEgCount), eqEGs(maxEgCount), |
|
suVolOnCC(this), suPitchOnCC(this), suCutoffOnCC(this), suResOnCC(this), |
|
|
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
|
788 |
LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount), |
LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount), |
789 |
filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount), eqLFOs(maxLfoCount) |
filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount), eqLFOs(maxLfoCount), |
790 |
|
pVoice(voice) |
791 |
{ |
{ |
792 |
suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice; |
suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice; |
793 |
suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
1126 |
volEGs[i]->EG.enterFadeOutStage(); |
volEGs[i]->EG.enterFadeOutStage(); |
1127 |
} |
} |
1128 |
} |
} |
1129 |
|
|
1130 |
|
void SfzSignalUnitRack::EnterFadeOutStage(int maxFadeOutSteps) { |
1131 |
|
suVolEG.EG.enterFadeOutStage(maxFadeOutSteps); |
1132 |
|
for (int i = 0; i < volEGs.size(); i++) { |
1133 |
|
volEGs[i]->EG.enterFadeOutStage(maxFadeOutSteps); |
1134 |
|
} |
1135 |
|
} |
1136 |
|
|
1137 |
void SfzSignalUnitRack::Reset() { |
void SfzSignalUnitRack::Reset() { |
1138 |
EqUnitSupport::ResetUnits(); |
EqUnitSupport::ResetUnits(); |
1139 |
|
|
1173 |
LFOs[i]->ResetUnits(); // class EqUnitSupport |
LFOs[i]->ResetUnits(); // class EqUnitSupport |
1174 |
} |
} |
1175 |
} |
} |
1176 |
|
|
1177 |
|
void SfzSignalUnitRack::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) { |
1178 |
|
suVolEG.EG.CalculateFadeOutCoeff(FadeOutTime, SampleRate); |
1179 |
|
for (int i = 0; i < EGs.capacity(); i++) { |
1180 |
|
EGs[i]->EG.CalculateFadeOutCoeff(FadeOutTime, SampleRate); |
1181 |
|
} |
1182 |
|
} |
1183 |
|
|
1184 |
void SfzSignalUnitRack::UpdateEqSettings(EqSupport* pEqSupport) { |
void SfzSignalUnitRack::UpdateEqSettings(EqSupport* pEqSupport) { |
1185 |
if (!pEqSupport->HasSupport()) return; |
if (!pEqSupport->HasSupport()) return; |
1202 |
float bw2 = (suEq2BwOnCC.Active() ? suEq2BwOnCC.GetLevel() : 0) + pRegion->eq2_bw; |
float bw2 = (suEq2BwOnCC.Active() ? suEq2BwOnCC.GetLevel() : 0) + pRegion->eq2_bw; |
1203 |
float bw3 = (suEq3BwOnCC.Active() ? suEq3BwOnCC.GetLevel() : 0) + pRegion->eq3_bw; |
float bw3 = (suEq3BwOnCC.Active() ? suEq3BwOnCC.GetLevel() : 0) + pRegion->eq3_bw; |
1204 |
|
|
1205 |
const float vel = pVoice->MIDIVelocity / 127.0f; |
const float vel = pVoice->MIDIVelocity() / 127.0f; |
1206 |
|
|
1207 |
dB1 += pRegion->eq1_vel2gain * vel; |
dB1 += pRegion->eq1_vel2gain * vel; |
1208 |
dB2 += pRegion->eq2_vel2gain * vel; |
dB2 += pRegion->eq2_vel2gain * vel; |