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 |
|
{ |
134 |
|
lfos.add(&lfo0); |
135 |
|
lfos.add(&lfo1); |
136 |
|
lfos.add(&lfo2); |
137 |
|
lfos.add(&lfo3); |
138 |
|
lfos.add(&lfo4); |
139 |
|
lfos.add(&lfo5); |
140 |
|
lfos.add(&lfo6); |
141 |
|
lfos.add(&lfo7); |
142 |
|
} |
143 |
|
|
144 |
|
void LFOv2Unit::Trigger() { |
145 |
|
LFOUnit::Trigger(); |
146 |
|
|
147 |
|
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
148 |
|
else pLFO = lfos[pLfoInfo->wave]; |
149 |
|
|
150 |
|
pLFO->Trigger ( |
151 |
|
pLfoInfo->freq, |
152 |
|
start_level_mid, |
153 |
|
1, 0, false, GetSampleRate() |
154 |
|
); |
155 |
|
pLFO->Update(0); |
156 |
|
} |
157 |
|
|
158 |
|
void AmpLFOUnit::Trigger() { |
159 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
160 |
|
pLfoInfo->delay = pRegion->amplfo_delay; |
161 |
|
pLfoInfo->freq = pRegion->amplfo_freq; |
162 |
|
pLfoInfo->volume = pRegion->amplfo_depth; |
163 |
|
|
164 |
|
LFOv1Unit::Trigger(); |
165 |
|
} |
166 |
|
|
167 |
|
void PitchLFOUnit::Trigger() { |
168 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
169 |
|
pLfoInfo->delay = pRegion->pitchlfo_delay; |
170 |
|
pLfoInfo->freq = pRegion->pitchlfo_freq; |
171 |
|
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
172 |
|
|
173 |
|
LFOv1Unit::Trigger(); |
174 |
|
} |
175 |
|
|
176 |
|
void FilLFOUnit::Trigger() { |
177 |
|
::sfz::Region* const pRegion = pVoice->pRegion; |
178 |
|
pLfoInfo->delay = pRegion->fillfo_delay; |
179 |
|
pLfoInfo->freq = pRegion->fillfo_freq; |
180 |
|
pLfoInfo->cutoff = pRegion->fillfo_depth; |
181 |
|
|
182 |
|
LFOv1Unit::Trigger(); |
183 |
|
} |
184 |
|
|
185 |
|
|
186 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
215 |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
216 |
} |
} |
217 |
|
|
218 |
|
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
219 |
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
220 |
|
|
221 |
return vol; |
return vol; |
222 |
} |
} |
223 |
|
|
224 |
float EndpointUnit::GetFilterCutoff() { |
float EndpointUnit::GetFilterCutoff() { |
225 |
float val = 1; |
float val; |
226 |
|
|
227 |
|
FilLFOUnit* u = &(GetRack()->suFilLFO); |
228 |
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
229 |
|
|
230 |
|
FilEGUnit* u2 = &(GetRack()->suFilEG); |
231 |
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
232 |
|
|
233 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
234 |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
242 |
} |
} |
243 |
|
|
244 |
float EndpointUnit::GetPitch() { |
float EndpointUnit::GetPitch() { |
245 |
|
double p; |
246 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
EGv1Unit* u = &(GetRack()->suPitchEG); |
247 |
double pitchEg = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
248 |
return pitchEg; |
|
249 |
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
250 |
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->pLfoInfo->pitch) : 1; |
251 |
|
|
252 |
|
return p; |
253 |
} |
} |
254 |
|
|
255 |
float EndpointUnit::GetResonance() { |
float EndpointUnit::GetResonance() { |
283 |
|
|
284 |
|
|
285 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
286 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
287 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
288 |
|
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
289 |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
290 |
{ |
{ |
291 |
suEndpoint.pVoice = suVolEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
292 |
|
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
293 |
|
|
294 |
for (int i = 0; i < EGs.capacity(); i++) { |
for (int i = 0; i < EGs.capacity(); i++) { |
295 |
EGs[i] = new EGv2Unit(this); |
EGs[i] = new EGv2Unit(this); |
373 |
Units.clear(); |
Units.clear(); |
374 |
|
|
375 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
376 |
|
Units.add(&suFilEG); |
377 |
Units.add(&suPitchEG); |
Units.add(&suPitchEG); |
378 |
|
Units.add(&suPitchLFO); |
379 |
|
Units.add(&suAmpLFO); |
380 |
|
Units.add(&suFilLFO); |
381 |
|
|
382 |
for (int i = 0; i < EGs.size(); i++) { |
for (int i = 0; i < EGs.size(); i++) { |
383 |
Units.add(EGs[i]); |
Units.add(EGs[i]); |