1 |
iliev |
2218 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
|
|
* LinuxSampler - modular, streaming capable sampler * |
4 |
|
|
* * |
5 |
|
|
* Copyright (C) 2011 Grigor Iliev * |
6 |
|
|
* * |
7 |
|
|
* 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 * |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
10 |
|
|
* (at your option) any later version. * |
11 |
|
|
* * |
12 |
|
|
* This program is distributed in the hope that it will be useful, * |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
15 |
|
|
* GNU General Public License for more details. * |
16 |
|
|
* * |
17 |
|
|
* You should have received a copy of the GNU General Public License * |
18 |
|
|
* along with this program; if not, write to the Free Software * |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
20 |
|
|
* MA 02111-1307 USA * |
21 |
|
|
***************************************************************************/ |
22 |
|
|
|
23 |
|
|
#include "SfzSignalUnitRack.h" |
24 |
|
|
#include "Voice.h" |
25 |
iliev |
2221 |
#include <SF.h> |
26 |
iliev |
2218 |
|
27 |
|
|
namespace LinuxSampler { namespace sfz { |
28 |
|
|
|
29 |
|
|
SfzSignalUnit::SfzSignalUnit(SfzSignalUnitRack* rack): SignalUnit(rack), pVoice(rack->pVoice) { |
30 |
|
|
|
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
double SfzSignalUnit::GetSampleRate() { |
34 |
|
|
return pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
|
38 |
|
|
void EGv1Unit::Trigger() { |
39 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
40 |
iliev |
2220 |
|
41 |
iliev |
2218 |
// the length of the decay and release curves are dependent on the velocity |
42 |
|
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
43 |
|
|
|
44 |
iliev |
2220 |
// set the delay trigger |
45 |
|
|
uiDelayTrigger = (pRegion->ampeg_delay + pRegion->ampeg_vel2delay * velrelease) * GetSampleRate(); |
46 |
|
|
|
47 |
iliev |
2218 |
EG.trigger(uint(pRegion->ampeg_start * 10), |
48 |
|
|
std::max(0.0, pRegion->ampeg_attack + pRegion->ampeg_vel2attack * velrelease), |
49 |
|
|
std::max(0.0, pRegion->ampeg_hold + pRegion->ampeg_vel2hold * velrelease), |
50 |
|
|
std::max(0.0, pRegion->ampeg_decay + pRegion->ampeg_vel2decay * velrelease), |
51 |
|
|
uint(std::min(std::max(0.0, 10 * (pRegion->ampeg_sustain + pRegion->ampeg_vel2sustain * velrelease)), 1000.0)), |
52 |
|
|
std::max(0.0, pRegion->ampeg_release + pRegion->ampeg_vel2release * velrelease), |
53 |
|
|
GetSampleRate()); |
54 |
|
|
} |
55 |
|
|
|
56 |
iliev |
2220 |
|
57 |
iliev |
2218 |
void EGv2Unit::Trigger() { |
58 |
|
|
EG.trigger(*pEGInfo, GetSampleRate(), pVoice->MIDIVelocity); |
59 |
|
|
} |
60 |
iliev |
2219 |
|
61 |
iliev |
2220 |
|
62 |
|
|
void PitchEGUnit::Trigger() { |
63 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
64 |
|
|
depth = pRegion->pitcheg_depth; |
65 |
|
|
|
66 |
|
|
// the length of the decay and release curves are dependent on the velocity |
67 |
|
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
68 |
iliev |
2218 |
|
69 |
iliev |
2220 |
// set the delay trigger |
70 |
|
|
uiDelayTrigger = (pRegion->pitcheg_delay + pRegion->pitcheg_vel2delay * velrelease) * GetSampleRate(); |
71 |
|
|
|
72 |
|
|
EG.trigger(uint(pRegion->pitcheg_start * 10), |
73 |
|
|
std::max(0.0, pRegion->pitcheg_attack + pRegion->pitcheg_vel2attack * velrelease), |
74 |
|
|
std::max(0.0, pRegion->pitcheg_hold + pRegion->pitcheg_vel2hold * velrelease), |
75 |
|
|
std::max(0.0, pRegion->pitcheg_decay + pRegion->pitcheg_vel2decay * velrelease), |
76 |
|
|
uint(std::min(std::max(0.0, 10 * (pRegion->pitcheg_sustain + pRegion->pitcheg_vel2sustain * velrelease)), 1000.0)), |
77 |
|
|
std::max(0.0, pRegion->pitcheg_release + pRegion->pitcheg_vel2release * velrelease), |
78 |
|
|
GetSampleRate()); |
79 |
|
|
} |
80 |
|
|
|
81 |
iliev |
2222 |
|
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 |
iliev |
2220 |
|
89 |
iliev |
2222 |
// 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 |
iliev |
2226 |
|
102 |
|
|
LFOUnit::LFOUnit(const LFOUnit& Unit): SfzSignalUnit(Unit), suFadeEG(static_cast<SfzSignalUnitRack*>(Unit.pRack)) { |
103 |
|
|
Copy(Unit); |
104 |
|
|
} |
105 |
iliev |
2222 |
|
106 |
iliev |
2219 |
void LFOUnit::Increment() { |
107 |
|
|
if (DelayStage()) return; |
108 |
|
|
|
109 |
|
|
SignalUnit::Increment(); |
110 |
|
|
|
111 |
iliev |
2223 |
Level = pLFO->Render(); |
112 |
iliev |
2226 |
if (suFadeEG.Active()) Level *= suFadeEG.GetLevel(); |
113 |
iliev |
2219 |
} |
114 |
|
|
|
115 |
|
|
void LFOUnit::Trigger() { |
116 |
|
|
//reset |
117 |
|
|
Level = 0; |
118 |
|
|
|
119 |
|
|
// set the delay trigger |
120 |
iliev |
2220 |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
121 |
iliev |
2226 |
if(pLfoInfo->fade != 0 || !pLfoInfo->fade_oncc.empty()) { |
122 |
|
|
float f = pLfoInfo->fade; |
123 |
|
|
for (int i = 0; i < pLfoInfo->fade_oncc.size(); i++) { |
124 |
|
|
int val = pVoice->GetControllerValue(pLfoInfo->fade_oncc[i].Controller); |
125 |
|
|
f += (val / 127.0f) * pLfoInfo->fade_oncc[i].Influence; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
if (f != 0) { |
129 |
|
|
suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
130 |
|
|
suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate()); |
131 |
|
|
} |
132 |
|
|
} |
133 |
iliev |
2219 |
} |
134 |
|
|
|
135 |
iliev |
2221 |
void LFOv1Unit::Trigger() { |
136 |
|
|
LFOUnit::Trigger(); |
137 |
|
|
|
138 |
|
|
lfo.trigger ( |
139 |
|
|
pLfoInfo->freq, |
140 |
|
|
start_level_mid, |
141 |
|
|
1, 0, false, GetSampleRate() |
142 |
|
|
); |
143 |
|
|
lfo.update(0); |
144 |
|
|
} |
145 |
|
|
|
146 |
iliev |
2223 |
|
147 |
|
|
LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack) |
148 |
|
|
: LFOUnit(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f), |
149 |
iliev |
2225 |
lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f), |
150 |
|
|
suPitchOnCC(rack) |
151 |
iliev |
2223 |
{ |
152 |
|
|
lfos.add(&lfo0); |
153 |
|
|
lfos.add(&lfo1); |
154 |
|
|
lfos.add(&lfo2); |
155 |
|
|
lfos.add(&lfo3); |
156 |
|
|
lfos.add(&lfo4); |
157 |
|
|
lfos.add(&lfo5); |
158 |
|
|
lfos.add(&lfo6); |
159 |
|
|
lfos.add(&lfo7); |
160 |
|
|
} |
161 |
|
|
|
162 |
iliev |
2219 |
void LFOv2Unit::Trigger() { |
163 |
|
|
LFOUnit::Trigger(); |
164 |
|
|
|
165 |
iliev |
2223 |
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
166 |
|
|
else pLFO = lfos[pLfoInfo->wave]; |
167 |
|
|
|
168 |
|
|
pLFO->Trigger ( |
169 |
iliev |
2219 |
pLfoInfo->freq, |
170 |
|
|
start_level_mid, |
171 |
|
|
1, 0, false, GetSampleRate() |
172 |
|
|
); |
173 |
iliev |
2223 |
pLFO->Update(0); |
174 |
iliev |
2225 |
|
175 |
|
|
float phase = pLfoInfo->phase; |
176 |
|
|
for (int i = 0; i < pLfoInfo->phase_oncc.size(); i++) { |
177 |
|
|
int val = pVoice->GetControllerValue(pLfoInfo->phase_oncc[i].Controller); |
178 |
|
|
phase += (val / 127.0f) * pLfoInfo->phase_oncc[i].Influence; |
179 |
|
|
} |
180 |
|
|
if (phase != 0) pLFO->SetPhase(phase); |
181 |
iliev |
2219 |
} |
182 |
iliev |
2221 |
|
183 |
|
|
void AmpLFOUnit::Trigger() { |
184 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
185 |
iliev |
2226 |
pLfoInfo->delay = pRegion->amplfo_delay; |
186 |
|
|
pLfoInfo->freq = pRegion->amplfo_freq; |
187 |
|
|
pLfoInfo->fade = pRegion->amplfo_fade; |
188 |
iliev |
2221 |
pLfoInfo->volume = pRegion->amplfo_depth; |
189 |
|
|
|
190 |
|
|
LFOv1Unit::Trigger(); |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
void PitchLFOUnit::Trigger() { |
194 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
195 |
|
|
pLfoInfo->delay = pRegion->pitchlfo_delay; |
196 |
iliev |
2226 |
pLfoInfo->freq = pRegion->pitchlfo_freq; |
197 |
|
|
pLfoInfo->fade = pRegion->pitchlfo_fade; |
198 |
iliev |
2221 |
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
199 |
|
|
|
200 |
|
|
LFOv1Unit::Trigger(); |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
void FilLFOUnit::Trigger() { |
204 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
205 |
iliev |
2226 |
pLfoInfo->delay = pRegion->fillfo_delay; |
206 |
|
|
pLfoInfo->freq = pRegion->fillfo_freq; |
207 |
|
|
pLfoInfo->fade = pRegion->fillfo_fade; |
208 |
iliev |
2221 |
pLfoInfo->cutoff = pRegion->fillfo_depth; |
209 |
|
|
|
210 |
|
|
LFOv1Unit::Trigger(); |
211 |
|
|
} |
212 |
iliev |
2224 |
|
213 |
|
|
CCUnit::CCUnit(SfzSignalUnitRack* rack): CCSignalUnit(rack) { } |
214 |
|
|
|
215 |
|
|
void CCUnit::Trigger() { |
216 |
|
|
for (int i = 0; i < Ctrls.size(); i++) { |
217 |
|
|
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
218 |
|
|
} |
219 |
|
|
CCSignalUnit::Trigger(); |
220 |
|
|
} |
221 |
|
|
|
222 |
|
|
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
223 |
|
|
RemoveAllCCs(); |
224 |
|
|
for (int i = 0; i < 128; i++) { |
225 |
|
|
if (cc[i] != 0) AddCC(i, cc[i]); |
226 |
|
|
} |
227 |
|
|
} |
228 |
iliev |
2225 |
|
229 |
|
|
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
230 |
|
|
RemoveAllCCs(); |
231 |
|
|
for (int i = 0; i < cc.size(); i++) { |
232 |
|
|
if (cc[i].Influence != 0) AddCC(cc[i].Controller, cc[i].Influence); |
233 |
|
|
} |
234 |
|
|
} |
235 |
iliev |
2218 |
|
236 |
iliev |
2219 |
|
237 |
iliev |
2218 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
238 |
|
|
|
239 |
|
|
} |
240 |
|
|
|
241 |
|
|
SfzSignalUnitRack* const EndpointUnit::GetRack() { |
242 |
|
|
return static_cast<SfzSignalUnitRack* const>(pRack); |
243 |
|
|
} |
244 |
|
|
|
245 |
|
|
void EndpointUnit::Trigger() { |
246 |
|
|
|
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
bool EndpointUnit::Active() { |
250 |
|
|
if (GetRack()->suVolEG.Active()) return true; |
251 |
|
|
|
252 |
|
|
bool b = false; |
253 |
|
|
for (int i = 0; i < GetRack()->volEGs.size(); i++) { |
254 |
|
|
if (GetRack()->volEGs[i]->Active()) { b = true; break; } |
255 |
|
|
} |
256 |
|
|
|
257 |
|
|
return b; |
258 |
|
|
} |
259 |
|
|
|
260 |
|
|
float EndpointUnit::GetVolume() { |
261 |
|
|
float vol = GetRack()->suVolEG.Active() ? GetRack()->suVolEG.GetLevel() : 0; |
262 |
|
|
|
263 |
|
|
for (int i = 0; i < GetRack()->volEGs.size(); i++) { |
264 |
|
|
EGv2Unit* eg = GetRack()->volEGs[i]; |
265 |
|
|
if (!eg->Active()) continue; |
266 |
|
|
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
267 |
|
|
} |
268 |
|
|
|
269 |
iliev |
2221 |
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
270 |
|
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
271 |
|
|
|
272 |
iliev |
2218 |
return vol; |
273 |
|
|
} |
274 |
|
|
|
275 |
|
|
float EndpointUnit::GetFilterCutoff() { |
276 |
iliev |
2221 |
float val; |
277 |
iliev |
2219 |
|
278 |
iliev |
2221 |
FilLFOUnit* u = &(GetRack()->suFilLFO); |
279 |
|
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
280 |
|
|
|
281 |
iliev |
2222 |
FilEGUnit* u2 = &(GetRack()->suFilEG); |
282 |
|
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
283 |
|
|
|
284 |
iliev |
2219 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
285 |
|
|
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
286 |
|
|
if (!lfo->Active()) continue; |
287 |
|
|
|
288 |
|
|
float f = lfo->GetLevel() * lfo->pLfoInfo->cutoff; |
289 |
|
|
val *= RTMath::CentsToFreqRatioUnlimited(f); |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
return val; |
293 |
iliev |
2218 |
} |
294 |
|
|
|
295 |
|
|
float EndpointUnit::GetPitch() { |
296 |
iliev |
2221 |
double p; |
297 |
iliev |
2220 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
298 |
iliev |
2221 |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
299 |
|
|
|
300 |
|
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
301 |
iliev |
2224 |
CCSignalUnit* u3 = &(GetRack()->suPitchLFO.suDepthCC); |
302 |
|
|
float f = u3->Active() ? u3->GetLevel() : 0; |
303 |
|
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * (u2->pLfoInfo->pitch + f)) : 1; |
304 |
iliev |
2225 |
|
305 |
|
|
for (int i = 0; i < GetRack()->pitchLFOs.size(); i++) { |
306 |
|
|
LFOv2Unit* lfo = GetRack()->pitchLFOs[i]; |
307 |
|
|
if (!lfo->Active()) continue; |
308 |
|
|
|
309 |
|
|
float f = lfo->suPitchOnCC.Active() ? lfo->suPitchOnCC.GetLevel() : 0; |
310 |
|
|
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
311 |
|
|
} |
312 |
|
|
|
313 |
iliev |
2221 |
return p; |
314 |
iliev |
2218 |
} |
315 |
|
|
|
316 |
|
|
float EndpointUnit::GetResonance() { |
317 |
iliev |
2219 |
float val = 0; |
318 |
|
|
|
319 |
|
|
for (int i = 0; i < GetRack()->resLFOs.size(); i++) { |
320 |
|
|
LFOv2Unit* lfo = GetRack()->resLFOs[i]; |
321 |
|
|
if (!lfo->Active()) continue; |
322 |
|
|
|
323 |
|
|
val += lfo->GetLevel() * lfo->pLfoInfo->resonance; |
324 |
|
|
} |
325 |
|
|
|
326 |
|
|
return val; |
327 |
iliev |
2218 |
} |
328 |
|
|
|
329 |
iliev |
2219 |
float EndpointUnit::GetPan() { |
330 |
|
|
float pan = 0; |
331 |
|
|
|
332 |
|
|
for (int i = 0; i < GetRack()->panLFOs.size(); i++) { |
333 |
|
|
LFOv2Unit* lfo = GetRack()->panLFOs[i]; |
334 |
|
|
if (!lfo->Active()) continue; |
335 |
|
|
|
336 |
|
|
pan += lfo->GetLevel() * lfo->pLfoInfo->pan; |
337 |
|
|
} |
338 |
|
|
|
339 |
|
|
if(pan < -100) return -100; |
340 |
|
|
if(pan > 100) return 100; |
341 |
|
|
|
342 |
|
|
return pan; |
343 |
|
|
} |
344 |
iliev |
2218 |
|
345 |
iliev |
2219 |
|
346 |
iliev |
2218 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
347 |
iliev |
2222 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
348 |
iliev |
2219 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
349 |
iliev |
2221 |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
350 |
iliev |
2225 |
LFOs(maxLfoCount), pitchLFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
351 |
iliev |
2218 |
{ |
352 |
iliev |
2222 |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
353 |
iliev |
2221 |
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
354 |
iliev |
2226 |
suPitchLFO.suDepthCC.pVoice = suPitchLFO.suFadeEG.pVoice = voice; |
355 |
|
|
suFilLFO.suFadeEG.pVoice = voice; |
356 |
|
|
suAmpLFO.suFadeEG.pVoice = voice; |
357 |
iliev |
2218 |
|
358 |
|
|
for (int i = 0; i < EGs.capacity(); i++) { |
359 |
|
|
EGs[i] = new EGv2Unit(this); |
360 |
|
|
EGs[i]->pVoice = voice; |
361 |
|
|
} |
362 |
iliev |
2219 |
|
363 |
|
|
for (int i = 0; i < LFOs.capacity(); i++) { |
364 |
|
|
LFOs[i] = new LFOv2Unit(this); |
365 |
|
|
LFOs[i]->pVoice = voice; |
366 |
iliev |
2226 |
LFOs[i]->suFadeEG.pVoice = voice; |
367 |
iliev |
2225 |
LFOs[i]->suPitchOnCC.pVoice = voice; |
368 |
iliev |
2219 |
} |
369 |
iliev |
2218 |
} |
370 |
|
|
|
371 |
|
|
SfzSignalUnitRack::~SfzSignalUnitRack() { |
372 |
iliev |
2219 |
for (int i = 0; i < EGs.capacity(); i++) { |
373 |
iliev |
2218 |
delete EGs[i]; EGs[i] = NULL; |
374 |
|
|
} |
375 |
iliev |
2219 |
|
376 |
|
|
for (int i = 0; i < LFOs.capacity(); i++) { |
377 |
|
|
delete LFOs[i]; LFOs[i] = NULL; |
378 |
|
|
} |
379 |
iliev |
2218 |
} |
380 |
|
|
|
381 |
|
|
void SfzSignalUnitRack::Trigger() { |
382 |
|
|
EGs.clear(); |
383 |
|
|
volEGs.clear(); |
384 |
|
|
pitchEGs.clear(); |
385 |
|
|
|
386 |
iliev |
2219 |
LFOs.clear(); |
387 |
iliev |
2225 |
pitchLFOs.clear(); |
388 |
iliev |
2219 |
filLFOs.clear(); |
389 |
|
|
resLFOs.clear(); |
390 |
|
|
panLFOs.clear(); |
391 |
|
|
|
392 |
iliev |
2218 |
::sfz::Region* const pRegion = pVoice->pRegion; |
393 |
|
|
|
394 |
iliev |
2219 |
for (int i = 0; i < pRegion->eg.size(); i++) { |
395 |
iliev |
2218 |
if (pRegion->eg[i].node.size() == 0) continue; |
396 |
|
|
|
397 |
|
|
if(EGs.size() < EGs.capacity()) { |
398 |
|
|
EGv2Unit eg(this); |
399 |
|
|
eg.pEGInfo = &(pRegion->eg[i]); |
400 |
|
|
EGs.increment()->Copy(eg); |
401 |
|
|
} else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; } |
402 |
|
|
|
403 |
|
|
if (pRegion->eg[i].amplitude > 0) { |
404 |
|
|
if(volEGs.size() < volEGs.capacity()) volEGs.add(EGs[EGs.size() - 1]); |
405 |
|
|
else std::cerr << "Maximum number of EGs reached!" << std::endl; |
406 |
|
|
} |
407 |
|
|
} |
408 |
|
|
|
409 |
|
|
if (pRegion->ampeg_sustain == -1) { |
410 |
|
|
if (volEGs.size() > 0) pRegion->ampeg_sustain = 0; |
411 |
|
|
else pRegion->ampeg_sustain = 100; |
412 |
|
|
} |
413 |
|
|
|
414 |
iliev |
2219 |
// LFO |
415 |
|
|
for (int i = 0; i < pRegion->lfos.size(); i++) { |
416 |
|
|
if (pRegion->lfos[i].freq == -1) continue; // Not initialized |
417 |
|
|
|
418 |
|
|
if(LFOs.size() < LFOs.capacity()) { |
419 |
|
|
LFOv2Unit lfo(this); |
420 |
|
|
lfo.pLfoInfo = &(pRegion->lfos[i]); |
421 |
|
|
LFOs.increment()->Copy(lfo); |
422 |
iliev |
2225 |
LFOs[LFOs.size() - 1]->suPitchOnCC.SetCCs(pRegion->lfos[i].pitch_oncc); |
423 |
iliev |
2219 |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
424 |
|
|
|
425 |
iliev |
2225 |
if (pRegion->lfos[i].pitch != 0 || !pRegion->lfos[i].pitch_oncc.empty()) { |
426 |
|
|
if(pitchLFOs.size() < pitchLFOs.capacity()) pitchLFOs.add(LFOs[LFOs.size() - 1]); |
427 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
428 |
|
|
} |
429 |
|
|
|
430 |
iliev |
2219 |
if (pRegion->lfos[i].cutoff != 0) { |
431 |
|
|
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
432 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
if (pRegion->lfos[i].resonance != 0) { |
436 |
|
|
if(resLFOs.size() < resLFOs.capacity()) resLFOs.add(LFOs[LFOs.size() - 1]); |
437 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
438 |
|
|
} |
439 |
|
|
|
440 |
|
|
if (pRegion->lfos[i].pan != 0) { |
441 |
|
|
if(panLFOs.size() < panLFOs.capacity()) panLFOs.add(LFOs[LFOs.size() - 1]); |
442 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
443 |
|
|
} |
444 |
|
|
} |
445 |
|
|
|
446 |
iliev |
2224 |
suPitchLFO.suDepthCC.SetCCs(pRegion->pitchlfo_depthcc); |
447 |
|
|
|
448 |
iliev |
2218 |
Units.clear(); |
449 |
|
|
|
450 |
|
|
Units.add(&suVolEG); |
451 |
iliev |
2222 |
Units.add(&suFilEG); |
452 |
iliev |
2220 |
Units.add(&suPitchEG); |
453 |
iliev |
2221 |
Units.add(&suPitchLFO); |
454 |
iliev |
2224 |
Units.add(&suPitchLFO.suDepthCC); |
455 |
iliev |
2226 |
Units.add(&suPitchLFO.suFadeEG); |
456 |
iliev |
2221 |
Units.add(&suAmpLFO); |
457 |
iliev |
2226 |
Units.add(&suAmpLFO.suFadeEG); |
458 |
iliev |
2221 |
Units.add(&suFilLFO); |
459 |
iliev |
2226 |
Units.add(&suFilLFO.suFadeEG); |
460 |
iliev |
2218 |
|
461 |
iliev |
2219 |
for (int i = 0; i < EGs.size(); i++) { |
462 |
iliev |
2218 |
Units.add(EGs[i]); |
463 |
|
|
} |
464 |
|
|
|
465 |
iliev |
2219 |
for (int i = 0; i < LFOs.size(); i++) { |
466 |
|
|
Units.add(LFOs[i]); |
467 |
iliev |
2226 |
Units.add(&(LFOs[i]->suFadeEG)); |
468 |
iliev |
2225 |
Units.add(&(LFOs[i]->suPitchOnCC)); |
469 |
iliev |
2219 |
} |
470 |
|
|
|
471 |
iliev |
2218 |
Units.add(&suEndpoint); |
472 |
|
|
|
473 |
|
|
SignalUnitRack::Trigger(); |
474 |
|
|
} |
475 |
|
|
|
476 |
|
|
EndpointSignalUnit* SfzSignalUnitRack::GetEndpointUnit() { |
477 |
|
|
return &suEndpoint; |
478 |
|
|
} |
479 |
|
|
|
480 |
|
|
void SfzSignalUnitRack::EnterFadeOutStage() { |
481 |
|
|
suVolEG.EG.enterFadeOutStage(); |
482 |
|
|
|
483 |
|
|
for (int i = 0; i < volEGs.size(); i++) { |
484 |
|
|
volEGs[i]->EG.enterFadeOutStage(); |
485 |
|
|
} |
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
}} // namespace LinuxSampler::sfz |