43 |
return f; |
return f; |
44 |
} |
} |
45 |
|
|
46 |
|
void XFInCCUnit::SetCrossFadeCCs(::sfz::Array<int>& loCCs, ::sfz::Array<int>& hiCCs) { |
47 |
|
RemoveAllCCs(); |
48 |
|
|
49 |
|
for (int cc = 0; cc < 128; cc++) { |
50 |
|
if (loCCs[cc] == 0 && hiCCs[cc] == 0) continue; |
51 |
|
int i = loCCs[cc]; |
52 |
|
int j = hiCCs[cc]; |
53 |
|
if (j == 0) j = 127; |
54 |
|
i += j << 8; // workaround to keep both values in the Influence parameter |
55 |
|
AddCC(cc, i); |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
|
void XFInCCUnit::Calculate() { |
60 |
|
float l = 1; |
61 |
|
|
62 |
|
for (int i = 0; i < Ctrls.size(); i++) { |
63 |
|
float c = 1; |
64 |
|
int influence = Ctrls[i].Influence; |
65 |
|
int lo = influence & 0xff; |
66 |
|
int hi = influence >> 8; |
67 |
|
if (Ctrls[i].Value <= lo) { |
68 |
|
c = 0; |
69 |
|
} else if (Ctrls[i].Value >= hi) { |
70 |
|
c = 1; |
71 |
|
} else { |
72 |
|
float xfVelSize = hi - lo; |
73 |
|
float velPos = Ctrls[i].Value - lo; |
74 |
|
c = velPos / xfVelSize; |
75 |
|
if (pVoice->pRegion->xf_cccurve == ::sfz::POWER) { |
76 |
|
c = sin(c * M_PI / 2.0); |
77 |
|
} |
78 |
|
} |
79 |
|
|
80 |
|
l *= c; |
81 |
|
} |
82 |
|
|
83 |
|
if (Level != l) { |
84 |
|
Level = l; |
85 |
|
if (pListener != NULL) pListener->ValueChanged(this); |
86 |
|
} |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
void XFOutCCUnit::Calculate() { |
91 |
|
float l = 1; |
92 |
|
|
93 |
|
for (int i = 0; i < Ctrls.size(); i++) { |
94 |
|
float c = 1; |
95 |
|
int influence = Ctrls[i].Influence; |
96 |
|
int lo = influence & 0xff; |
97 |
|
int hi = influence >> 8; |
98 |
|
if (Ctrls[i].Value >= hi) { |
99 |
|
c = 0; |
100 |
|
} else if (Ctrls[i].Value <= lo) { |
101 |
|
c = 1; |
102 |
|
} else { |
103 |
|
float xfVelSize = hi - lo; |
104 |
|
float velPos = Ctrls[i].Value - lo; |
105 |
|
c = 1.0f - velPos / xfVelSize; |
106 |
|
if (pVoice->pRegion->xf_cccurve == ::sfz::POWER) { |
107 |
|
c = sin(c * M_PI / 2.0); |
108 |
|
} |
109 |
|
} |
110 |
|
|
111 |
|
l *= c; |
112 |
|
} |
113 |
|
|
114 |
|
if (Level != l) { |
115 |
|
Level = l; |
116 |
|
if (pListener != NULL) pListener->ValueChanged(this); |
117 |
|
} |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
EGv2Unit::EGv2Unit(SfzSignalUnitRack* rack) |
EGv2Unit::EGv2Unit(SfzSignalUnitRack* rack) |
122 |
: EGUnit< ::LinuxSampler::sfz::EG>(rack), |
: EGUnit< ::LinuxSampler::sfz::EG>(rack), suAmpOnCC(rack), suVolOnCC(rack), |
123 |
suAmpOnCC(rack), suVolOnCC(rack), suPitchOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack) |
suPitchOnCC(rack), suCutoffOnCC(rack), suResOnCC(rack), suPanOnCC(rack) |
124 |
{ } |
{ } |
125 |
|
|
126 |
void EGv2Unit::Trigger() { |
void EGv2Unit::Trigger() { |
377 |
|
|
378 |
void SmoothCCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { |
void SmoothCCUnit::AddSmoothCC(uint8_t Controller, float Influence, short int Curve, float Smooth) { |
379 |
if (Smooth > 0) { |
if (Smooth > 0) { |
380 |
Smoothers[Controller].trigger(Smooth / 1000.0f, GetSampleRate()); |
if (Smoothers.size() >= Smoothers.capacity()) { |
381 |
AddCC(Controller, Influence, Curve, &Smoothers[Controller]); |
std::cerr << "Maximum number of smoothers reached" << std::endl; |
382 |
|
return; |
383 |
|
} |
384 |
|
|
385 |
|
Smoothers.increment().trigger(Smooth / 1000.0f, GetSampleRate()); |
386 |
|
AddCC(Controller, Influence, Curve, &Smoothers[Smoothers.size() - 1]); |
387 |
} else { |
} else { |
388 |
AddCC(Controller, Influence, Curve); |
AddCC(Controller, Influence, Curve); |
389 |
} |
} |
390 |
} |
} |
391 |
|
|
392 |
|
|
393 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack) |
394 |
|
: EndpointSignalUnit(rack), suXFInCC(rack), suXFOutCC(rack), suPanOnCC(rack), pitchVeltrackRatio(0) |
395 |
|
{ |
396 |
|
|
397 |
} |
} |
398 |
|
|
401 |
} |
} |
402 |
|
|
403 |
void EndpointUnit::Trigger() { |
void EndpointUnit::Trigger() { |
404 |
|
float xfInVelCoeff = 1; |
405 |
|
|
406 |
|
if (pVoice->MIDIVelocity <= pVoice->pRegion->xfin_lovel) { |
407 |
|
xfInVelCoeff = 0; |
408 |
|
} else if (pVoice->MIDIVelocity >= pVoice->pRegion->xfin_hivel) { |
409 |
|
xfInVelCoeff = 1; |
410 |
|
} else { |
411 |
|
float xfVelSize = pVoice->pRegion->xfin_hivel - pVoice->pRegion->xfin_lovel; |
412 |
|
float velPos = pVoice->MIDIVelocity - pVoice->pRegion->xfin_lovel; |
413 |
|
xfInVelCoeff = velPos / xfVelSize; |
414 |
|
if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { |
415 |
|
xfInVelCoeff = sin(xfInVelCoeff * M_PI / 2.0); |
416 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
float xfOutVelCoeff = 1; |
420 |
|
|
421 |
|
if (pVoice->MIDIVelocity >= pVoice->pRegion->xfout_hivel) { |
422 |
|
if (pVoice->pRegion->xfout_lovel < 127 /* is set */) xfOutVelCoeff = 0; |
423 |
|
} else if (pVoice->MIDIVelocity <= pVoice->pRegion->xfout_lovel) { |
424 |
|
xfOutVelCoeff = 1; |
425 |
|
} else { |
426 |
|
float xfVelSize = pVoice->pRegion->xfout_hivel - pVoice->pRegion->xfout_lovel; |
427 |
|
float velPos = pVoice->MIDIVelocity - pVoice->pRegion->xfout_lovel; |
428 |
|
xfOutVelCoeff = 1.0f - velPos / xfVelSize; |
429 |
|
if (pVoice->pRegion->xf_velcurve == ::sfz::POWER) { |
430 |
|
xfOutVelCoeff = sin(xfOutVelCoeff * M_PI / 2.0); |
431 |
|
} |
432 |
|
} |
433 |
|
|
434 |
|
float xfInKeyCoeff = 1; |
435 |
|
|
436 |
|
if (pVoice->MIDIKey <= pVoice->pRegion->xfin_lokey) { |
437 |
|
if (pVoice->pRegion->xfin_hikey > 0 /* is set */) xfInKeyCoeff = 0; |
438 |
|
} else if (pVoice->MIDIKey >= pVoice->pRegion->xfin_hikey) { |
439 |
|
xfInKeyCoeff = 1; |
440 |
|
} else { |
441 |
|
float xfKeySize = pVoice->pRegion->xfin_hikey - pVoice->pRegion->xfin_lokey; |
442 |
|
float keyPos = pVoice->MIDIKey - pVoice->pRegion->xfin_lokey; |
443 |
|
xfInKeyCoeff = keyPos / xfKeySize; |
444 |
|
if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { |
445 |
|
xfInKeyCoeff = sin(xfInKeyCoeff * M_PI / 2.0); |
446 |
|
} |
447 |
|
} |
448 |
|
|
449 |
|
float xfOutKeyCoeff = 1; |
450 |
|
|
451 |
|
if (pVoice->MIDIKey >= pVoice->pRegion->xfout_hikey) { |
452 |
|
if (pVoice->pRegion->xfout_lokey < 127 /* is set */) xfOutKeyCoeff = 0; |
453 |
|
} else if (pVoice->MIDIKey <= pVoice->pRegion->xfout_lokey) { |
454 |
|
xfOutKeyCoeff = 1; |
455 |
|
} else { |
456 |
|
float xfKeySize = pVoice->pRegion->xfout_hikey - pVoice->pRegion->xfout_lokey; |
457 |
|
float keyPos = pVoice->MIDIKey - pVoice->pRegion->xfout_lokey; |
458 |
|
xfOutKeyCoeff = 1.0f - keyPos / xfKeySize; |
459 |
|
if (pVoice->pRegion->xf_keycurve == ::sfz::POWER) { |
460 |
|
xfOutKeyCoeff = sin(xfOutKeyCoeff * M_PI / 2.0); |
461 |
|
} |
462 |
|
} |
463 |
|
|
464 |
|
xfCoeff = xfInVelCoeff * xfOutVelCoeff * xfInKeyCoeff * xfOutKeyCoeff; |
465 |
|
|
466 |
|
suXFInCC.SetCrossFadeCCs(pVoice->pRegion->xfin_locc, pVoice->pRegion->xfin_hicc); |
467 |
|
suXFOutCC.SetCrossFadeCCs(pVoice->pRegion->xfout_locc, pVoice->pRegion->xfout_hicc); |
468 |
|
|
469 |
|
suPanOnCC.SetCCs(pVoice->pRegion->pan_oncc); |
470 |
|
|
471 |
|
pitchVeltrackRatio = RTMath::CentsToFreqRatioUnlimited((pVoice->MIDIVelocity / 127.0f) * pVoice->pRegion->pitch_veltrack); |
472 |
} |
} |
473 |
|
|
474 |
bool EndpointUnit::Active() { |
bool EndpointUnit::Active() { |
519 |
vol *= ::sf2::ToRatio(lfo->GetLevel() * (lfo->pLfoInfo->volume + f) * 10.0); |
vol *= ::sf2::ToRatio(lfo->GetLevel() * (lfo->pLfoInfo->volume + f) * 10.0); |
520 |
} |
} |
521 |
|
|
522 |
return vol; |
if (suXFInCC.Active()) vol *= suXFInCC.GetLevel(); |
523 |
|
if (suXFOutCC.Active()) vol *= suXFOutCC.GetLevel(); |
524 |
|
return vol * xfCoeff; |
525 |
} |
} |
526 |
|
|
527 |
float EndpointUnit::GetFilterCutoff() { |
float EndpointUnit::GetFilterCutoff() { |
588 |
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
589 |
} |
} |
590 |
|
|
591 |
return p; |
return p * pitchVeltrackRatio; |
592 |
} |
} |
593 |
|
|
594 |
float EndpointUnit::GetResonance() { |
float EndpointUnit::GetResonance() { |
614 |
} |
} |
615 |
|
|
616 |
float EndpointUnit::GetPan() { |
float EndpointUnit::GetPan() { |
617 |
float pan = 0; |
float pan = suPanOnCC.Active() ? suPanOnCC.GetLevel() : 0; |
618 |
|
|
619 |
|
for (int i = 0; i < GetRack()->panEGs.size(); i++) { |
620 |
|
EGv2Unit* eg = GetRack()->panEGs[i]; |
621 |
|
if (!eg->Active()) continue; |
622 |
|
|
623 |
|
float f = eg->suPanOnCC.Active() ? eg->suPanOnCC.GetLevel() : 0; |
624 |
|
|
625 |
|
if (eg->pEGInfo->pan_curve >= 0 && eg->pEGInfo->pan_curve < suPanOnCC.GetCurveCount()) { |
626 |
|
uint8_t val = eg->GetLevel() * 127; |
627 |
|
if (val > 127) val = 127; |
628 |
|
pan += eg->pEGInfo->pan * suPanOnCC.GetCurve(eg->pEGInfo->pan_curve)->v[val] + eg->GetLevel() * f; |
629 |
|
} else { |
630 |
|
pan += eg->GetLevel() * (eg->pEGInfo->pan + f); |
631 |
|
} |
632 |
|
} |
633 |
|
|
634 |
for (int i = 0; i < GetRack()->panLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->panLFOs.size(); i++) { |
635 |
LFOv2Unit* lfo = GetRack()->panLFOs[i]; |
LFOv2Unit* lfo = GetRack()->panLFOs[i]; |
648 |
|
|
649 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
650 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
651 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), resEGs(maxEgCount), suVolOnCC(this), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), filEGs(maxEgCount), resEGs(maxEgCount), panEGs(maxEgCount), suVolOnCC(this), |
652 |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
653 |
LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount), |
LFOs(maxLfoCount), volLFOs(maxLfoCount), pitchLFOs(maxLfoCount), |
654 |
filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
655 |
{ |
{ |
656 |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suEndpoint.suXFInCC.pVoice = suEndpoint.suXFOutCC.pVoice = suEndpoint.suPanOnCC.pVoice = voice; |
657 |
|
suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
658 |
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = suVolOnCC.pVoice = voice; |
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = suVolOnCC.pVoice = voice; |
659 |
suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice; |
suPitchLFO.suDepthOnCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice; |
660 |
suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice; |
suFilLFO.suFadeEG.pVoice = suFilLFO.suDepthOnCC.pVoice = suFilLFO.suFreqOnCC.pVoice = voice; |
668 |
EGs[i]->suPitchOnCC.pVoice = voice; |
EGs[i]->suPitchOnCC.pVoice = voice; |
669 |
EGs[i]->suCutoffOnCC.pVoice = voice; |
EGs[i]->suCutoffOnCC.pVoice = voice; |
670 |
EGs[i]->suResOnCC.pVoice = voice; |
EGs[i]->suResOnCC.pVoice = voice; |
671 |
|
EGs[i]->suPanOnCC.pVoice = voice; |
672 |
} |
} |
673 |
|
|
674 |
for (int i = 0; i < LFOs.capacity(); i++) { |
for (int i = 0; i < LFOs.capacity(); i++) { |
700 |
pitchEGs.clear(); |
pitchEGs.clear(); |
701 |
filEGs.clear(); |
filEGs.clear(); |
702 |
resEGs.clear(); |
resEGs.clear(); |
703 |
|
panEGs.clear(); |
704 |
|
|
705 |
LFOs.clear(); |
LFOs.clear(); |
706 |
volLFOs.clear(); |
volLFOs.clear(); |
725 |
EGs[EGs.size() - 1]->suPitchOnCC.SetCCs(pRegion->eg[i].pitch_oncc); |
EGs[EGs.size() - 1]->suPitchOnCC.SetCCs(pRegion->eg[i].pitch_oncc); |
726 |
EGs[EGs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->eg[i].cutoff_oncc); |
EGs[EGs.size() - 1]->suCutoffOnCC.SetCCs(pRegion->eg[i].cutoff_oncc); |
727 |
EGs[EGs.size() - 1]->suResOnCC.SetCCs(pRegion->eg[i].resonance_oncc); |
EGs[EGs.size() - 1]->suResOnCC.SetCCs(pRegion->eg[i].resonance_oncc); |
728 |
|
EGs[EGs.size() - 1]->suPanOnCC.SetCCs(pRegion->eg[i].pan_oncc); |
729 |
} else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; } |
} else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; } |
730 |
|
|
731 |
if ( pRegion->eg[i].amplitude > 0 || !pRegion->eg[i].amplitude_oncc.empty() || |
if ( pRegion->eg[i].amplitude > 0 || !pRegion->eg[i].amplitude_oncc.empty() || |
749 |
if(pitchEGs.size() < pitchEGs.capacity()) pitchEGs.add(EGs[EGs.size() - 1]); |
if(pitchEGs.size() < pitchEGs.capacity()) pitchEGs.add(EGs[EGs.size() - 1]); |
750 |
else std::cerr << "Maximum number of EGs reached!" << std::endl; |
else std::cerr << "Maximum number of EGs reached!" << std::endl; |
751 |
} |
} |
752 |
|
|
753 |
|
if (pRegion->eg[i].pan != 0 || !pRegion->eg[i].pan_oncc.empty()) { |
754 |
|
if(panEGs.size() < panEGs.capacity()) panEGs.add(EGs[EGs.size() - 1]); |
755 |
|
else std::cerr << "Maximum number of EGs reached!" << std::endl; |
756 |
|
} |
757 |
} |
} |
758 |
|
|
759 |
if (pRegion->ampeg_sustain == -1) { |
if (pRegion->ampeg_sustain == -1) { |
842 |
Units.add(&(EGs[i]->suPitchOnCC)); |
Units.add(&(EGs[i]->suPitchOnCC)); |
843 |
Units.add(&(EGs[i]->suCutoffOnCC)); |
Units.add(&(EGs[i]->suCutoffOnCC)); |
844 |
Units.add(&(EGs[i]->suResOnCC)); |
Units.add(&(EGs[i]->suResOnCC)); |
845 |
|
Units.add(&(EGs[i]->suPanOnCC)); |
846 |
} |
} |
847 |
|
|
848 |
for (int i = 0; i < LFOs.size(); i++) { |
for (int i = 0; i < LFOs.size(); i++) { |
857 |
} |
} |
858 |
|
|
859 |
Units.add(&suEndpoint); |
Units.add(&suEndpoint); |
860 |
|
Units.add(&suEndpoint.suXFInCC); |
861 |
|
Units.add(&suEndpoint.suXFOutCC); |
862 |
|
Units.add(&suEndpoint.suPanOnCC); |
863 |
|
|
864 |
SignalUnitRack::Trigger(); |
SignalUnitRack::Trigger(); |
865 |
} |
} |