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 |
|
CCUnit::CCUnit(SfzSignalUnitRack* rack): CCSignalUnit(rack) { } |
186 |
|
|
187 |
|
void CCUnit::Trigger() { |
188 |
|
for (int i = 0; i < Ctrls.size(); i++) { |
189 |
|
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
190 |
|
} |
191 |
|
CCSignalUnit::Trigger(); |
192 |
|
} |
193 |
|
|
194 |
|
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
195 |
|
RemoveAllCCs(); |
196 |
|
for (int i = 0; i < 128; i++) { |
197 |
|
if (cc[i] != 0) AddCC(i, cc[i]); |
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
231 |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
232 |
} |
} |
233 |
|
|
234 |
|
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
235 |
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
236 |
|
|
237 |
return vol; |
return vol; |
238 |
} |
} |
239 |
|
|
240 |
float EndpointUnit::GetFilterCutoff() { |
float EndpointUnit::GetFilterCutoff() { |
241 |
float val = 1; |
float val; |
242 |
|
|
243 |
|
FilLFOUnit* u = &(GetRack()->suFilLFO); |
244 |
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
245 |
|
|
246 |
|
FilEGUnit* u2 = &(GetRack()->suFilEG); |
247 |
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
248 |
|
|
249 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
250 |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
258 |
} |
} |
259 |
|
|
260 |
float EndpointUnit::GetPitch() { |
float EndpointUnit::GetPitch() { |
261 |
|
double p; |
262 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
EGv1Unit* u = &(GetRack()->suPitchEG); |
263 |
double pitchEg = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
264 |
return pitchEg; |
|
265 |
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
266 |
|
CCSignalUnit* u3 = &(GetRack()->suPitchLFO.suDepthCC); |
267 |
|
float f = u3->Active() ? u3->GetLevel() : 0; |
268 |
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * (u2->pLfoInfo->pitch + f)) : 1; |
269 |
|
return p; |
270 |
} |
} |
271 |
|
|
272 |
float EndpointUnit::GetResonance() { |
float EndpointUnit::GetResonance() { |
300 |
|
|
301 |
|
|
302 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
303 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suPitchEG(this), |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
304 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
305 |
|
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
306 |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
LFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
307 |
{ |
{ |
308 |
suEndpoint.pVoice = suVolEG.pVoice = suPitchEG.pVoice = voice; |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
309 |
|
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
310 |
|
suPitchLFO.suDepthCC.pVoice = voice; |
311 |
|
|
312 |
for (int i = 0; i < EGs.capacity(); i++) { |
for (int i = 0; i < EGs.capacity(); i++) { |
313 |
EGs[i] = new EGv2Unit(this); |
EGs[i] = new EGv2Unit(this); |
388 |
} |
} |
389 |
} |
} |
390 |
|
|
391 |
|
suPitchLFO.suDepthCC.SetCCs(pRegion->pitchlfo_depthcc); |
392 |
|
|
393 |
Units.clear(); |
Units.clear(); |
394 |
|
|
395 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
396 |
|
Units.add(&suFilEG); |
397 |
Units.add(&suPitchEG); |
Units.add(&suPitchEG); |
398 |
|
Units.add(&suPitchLFO); |
399 |
|
Units.add(&suPitchLFO.suDepthCC); |
400 |
|
Units.add(&suAmpLFO); |
401 |
|
Units.add(&suFilLFO); |
402 |
|
|
403 |
for (int i = 0; i < EGs.size(); i++) { |
for (int i = 0; i < EGs.size(); i++) { |
404 |
Units.add(EGs[i]); |
Units.add(EGs[i]); |