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 |
iliev |
2229 |
float SfzSignalUnit::GetInfluence(ArrayList< ::sfz::CC>& cc) { |
38 |
|
|
float f = 0; |
39 |
|
|
for (int i = 0; i < cc.size(); i++) { |
40 |
|
|
int val = pVoice->GetControllerValue(cc[i].Controller); |
41 |
|
|
f += (val / 127.0f) * cc[i].Influence; |
42 |
|
|
} |
43 |
|
|
return f; |
44 |
iliev |
2218 |
} |
45 |
|
|
|
46 |
iliev |
2220 |
|
47 |
iliev |
2218 |
void EGv2Unit::Trigger() { |
48 |
iliev |
2229 |
egInfo = *pEGInfo; |
49 |
|
|
for (int i = 0; i < egInfo.node.size(); i++) { |
50 |
|
|
float f = GetInfluence(egInfo.node[i].level_oncc); |
51 |
|
|
egInfo.node[i].level = std::min(egInfo.node[i].level + f, 1.0f); |
52 |
|
|
|
53 |
|
|
f = GetInfluence(egInfo.node[i].time_oncc); |
54 |
|
|
egInfo.node[i].time = std::min(egInfo.node[i].time + f, 100.0f); |
55 |
|
|
} |
56 |
|
|
EG.trigger(egInfo, GetSampleRate(), pVoice->MIDIVelocity); |
57 |
iliev |
2218 |
} |
58 |
iliev |
2219 |
|
59 |
iliev |
2220 |
|
60 |
|
|
void PitchEGUnit::Trigger() { |
61 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
62 |
|
|
depth = pRegion->pitcheg_depth; |
63 |
|
|
|
64 |
|
|
// the length of the decay and release curves are dependent on the velocity |
65 |
|
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
66 |
iliev |
2218 |
|
67 |
iliev |
2220 |
// set the delay trigger |
68 |
|
|
uiDelayTrigger = (pRegion->pitcheg_delay + pRegion->pitcheg_vel2delay * velrelease) * GetSampleRate(); |
69 |
|
|
|
70 |
|
|
EG.trigger(uint(pRegion->pitcheg_start * 10), |
71 |
|
|
std::max(0.0, pRegion->pitcheg_attack + pRegion->pitcheg_vel2attack * velrelease), |
72 |
|
|
std::max(0.0, pRegion->pitcheg_hold + pRegion->pitcheg_vel2hold * velrelease), |
73 |
|
|
std::max(0.0, pRegion->pitcheg_decay + pRegion->pitcheg_vel2decay * velrelease), |
74 |
|
|
uint(std::min(std::max(0.0, 10 * (pRegion->pitcheg_sustain + pRegion->pitcheg_vel2sustain * velrelease)), 1000.0)), |
75 |
|
|
std::max(0.0, pRegion->pitcheg_release + pRegion->pitcheg_vel2release * velrelease), |
76 |
|
|
GetSampleRate()); |
77 |
|
|
} |
78 |
|
|
|
79 |
iliev |
2222 |
|
80 |
|
|
void FilEGUnit::Trigger() { |
81 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
82 |
|
|
depth = pRegion->fileg_depth; |
83 |
|
|
|
84 |
|
|
// the length of the decay and release curves are dependent on the velocity |
85 |
|
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
86 |
iliev |
2220 |
|
87 |
iliev |
2222 |
// set the delay trigger |
88 |
|
|
uiDelayTrigger = (pRegion->fileg_delay + pRegion->fileg_vel2delay * velrelease) * GetSampleRate(); |
89 |
|
|
|
90 |
|
|
EG.trigger(uint(pRegion->fileg_start * 10), |
91 |
|
|
std::max(0.0, pRegion->fileg_attack + pRegion->fileg_vel2attack * velrelease), |
92 |
|
|
std::max(0.0, pRegion->fileg_hold + pRegion->fileg_vel2hold * velrelease), |
93 |
|
|
std::max(0.0, pRegion->fileg_decay + pRegion->fileg_vel2decay * velrelease), |
94 |
|
|
uint(std::min(std::max(0.0, 10 * (pRegion->fileg_sustain + pRegion->fileg_vel2sustain * velrelease)), 1000.0)), |
95 |
|
|
std::max(0.0, pRegion->fileg_release + pRegion->fileg_vel2release * velrelease), |
96 |
|
|
GetSampleRate()); |
97 |
|
|
} |
98 |
|
|
|
99 |
iliev |
2226 |
|
100 |
iliev |
2229 |
void AmpEGUnit::Trigger() { |
101 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
102 |
|
|
|
103 |
|
|
// the length of the decay and release curves are dependent on the velocity |
104 |
|
|
const double velrelease = 1 / pVoice->GetVelocityRelease(pVoice->MIDIVelocity); |
105 |
|
|
|
106 |
|
|
// set the delay trigger |
107 |
|
|
float delay = pRegion->ampeg_delay + pRegion->ampeg_vel2delay * velrelease; |
108 |
|
|
delay += GetInfluence(pRegion->ampeg_delaycc); |
109 |
|
|
uiDelayTrigger = std::max(0.0f, delay) * GetSampleRate(); |
110 |
|
|
|
111 |
|
|
float start = (pRegion->ampeg_start + GetInfluence(pRegion->ampeg_startcc)) * 10; |
112 |
|
|
|
113 |
|
|
float attack = pRegion->ampeg_attack + pRegion->ampeg_vel2attack * velrelease; |
114 |
|
|
attack = std::max(0.0f, attack + GetInfluence(pRegion->ampeg_attackcc)); |
115 |
|
|
|
116 |
|
|
float hold = pRegion->ampeg_hold + pRegion->ampeg_vel2hold * velrelease; |
117 |
|
|
hold = std::max(0.0f, hold + GetInfluence(pRegion->ampeg_holdcc)); |
118 |
|
|
|
119 |
|
|
float decay = pRegion->ampeg_decay + pRegion->ampeg_vel2decay * velrelease; |
120 |
|
|
decay = std::max(0.0f, decay + GetInfluence(pRegion->ampeg_decaycc)); |
121 |
|
|
|
122 |
|
|
float sustain = pRegion->ampeg_sustain + pRegion->ampeg_vel2sustain * velrelease; |
123 |
|
|
sustain = 10 * (sustain + GetInfluence(pRegion->ampeg_sustaincc)); |
124 |
|
|
|
125 |
|
|
float release = pRegion->ampeg_release + pRegion->ampeg_vel2release * velrelease; |
126 |
|
|
release = std::max(0.0f, release + GetInfluence(pRegion->ampeg_releasecc)); |
127 |
|
|
|
128 |
|
|
EG.trigger ( |
129 |
|
|
uint(std::min(std::max(0.0f, start), 1000.0f)), attack, hold, decay, |
130 |
|
|
uint(std::min(std::max(0.0f, sustain), 1000.0f)), release, GetSampleRate() |
131 |
|
|
); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
|
135 |
iliev |
2227 |
LFOUnit::LFOUnit(SfzSignalUnitRack* rack) |
136 |
|
|
: SfzSignalUnit(rack), pLfoInfo(NULL), pLFO(NULL), |
137 |
|
|
suFadeEG(rack), suFreqOnCC(rack, this) |
138 |
|
|
{ } |
139 |
|
|
|
140 |
|
|
LFOUnit::LFOUnit(const LFOUnit& Unit) |
141 |
|
|
: SfzSignalUnit(Unit), suFadeEG(static_cast<SfzSignalUnitRack*>(Unit.pRack)), |
142 |
|
|
suFreqOnCC(static_cast<SfzSignalUnitRack*>(Unit.pRack), this) |
143 |
|
|
{ |
144 |
iliev |
2226 |
Copy(Unit); |
145 |
|
|
} |
146 |
iliev |
2222 |
|
147 |
iliev |
2219 |
void LFOUnit::Increment() { |
148 |
|
|
if (DelayStage()) return; |
149 |
|
|
|
150 |
|
|
SignalUnit::Increment(); |
151 |
|
|
|
152 |
iliev |
2223 |
Level = pLFO->Render(); |
153 |
iliev |
2226 |
if (suFadeEG.Active()) Level *= suFadeEG.GetLevel(); |
154 |
iliev |
2219 |
} |
155 |
|
|
|
156 |
|
|
void LFOUnit::Trigger() { |
157 |
|
|
//reset |
158 |
|
|
Level = 0; |
159 |
|
|
|
160 |
|
|
// set the delay trigger |
161 |
iliev |
2220 |
uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
162 |
iliev |
2226 |
if(pLfoInfo->fade != 0 || !pLfoInfo->fade_oncc.empty()) { |
163 |
|
|
float f = pLfoInfo->fade; |
164 |
iliev |
2229 |
f += GetInfluence(pLfoInfo->fade_oncc); |
165 |
iliev |
2226 |
|
166 |
|
|
if (f != 0) { |
167 |
|
|
suFadeEG.uiDelayTrigger = pLfoInfo->delay * GetSampleRate(); |
168 |
|
|
suFadeEG.EG.trigger(0, f, 0, 0, 1000, 0, GetSampleRate()); |
169 |
|
|
} |
170 |
|
|
} |
171 |
iliev |
2219 |
} |
172 |
|
|
|
173 |
iliev |
2227 |
void LFOUnit::ValueChanged(CCSignalUnit* pUnit) { |
174 |
iliev |
2229 |
pLFO->SetFrequency(std::max(0.0f, suFreqOnCC.GetLevel() + pLfoInfo->freq), GetSampleRate()); |
175 |
iliev |
2227 |
} |
176 |
|
|
|
177 |
|
|
|
178 |
iliev |
2221 |
void LFOv1Unit::Trigger() { |
179 |
|
|
LFOUnit::Trigger(); |
180 |
|
|
|
181 |
|
|
lfo.trigger ( |
182 |
iliev |
2227 |
pLfoInfo->freq + suFreqOnCC.GetLevel(), |
183 |
iliev |
2221 |
start_level_mid, |
184 |
|
|
1, 0, false, GetSampleRate() |
185 |
|
|
); |
186 |
|
|
lfo.update(0); |
187 |
|
|
} |
188 |
|
|
|
189 |
iliev |
2223 |
|
190 |
|
|
LFOv2Unit::LFOv2Unit(SfzSignalUnitRack* rack) |
191 |
|
|
: LFOUnit(rack), lfos(8), lfo0(1200.0f), lfo1(1200.0f), lfo2(1200.0f), |
192 |
iliev |
2225 |
lfo3(1200.0f), lfo4(1200.0f), lfo5(1200.0f), lfo6(1200.0f), lfo7(1200.0f), |
193 |
|
|
suPitchOnCC(rack) |
194 |
iliev |
2223 |
{ |
195 |
|
|
lfos.add(&lfo0); |
196 |
|
|
lfos.add(&lfo1); |
197 |
|
|
lfos.add(&lfo2); |
198 |
|
|
lfos.add(&lfo3); |
199 |
|
|
lfos.add(&lfo4); |
200 |
|
|
lfos.add(&lfo5); |
201 |
|
|
lfos.add(&lfo6); |
202 |
|
|
lfos.add(&lfo7); |
203 |
|
|
} |
204 |
|
|
|
205 |
iliev |
2219 |
void LFOv2Unit::Trigger() { |
206 |
|
|
LFOUnit::Trigger(); |
207 |
|
|
|
208 |
iliev |
2223 |
if (pLfoInfo->wave < 0 || pLfoInfo->wave >= lfos.size()) pLFO = &lfo0; |
209 |
|
|
else pLFO = lfos[pLfoInfo->wave]; |
210 |
|
|
|
211 |
|
|
pLFO->Trigger ( |
212 |
iliev |
2227 |
pLfoInfo->freq + suFreqOnCC.GetLevel(), |
213 |
iliev |
2219 |
start_level_mid, |
214 |
|
|
1, 0, false, GetSampleRate() |
215 |
|
|
); |
216 |
iliev |
2223 |
pLFO->Update(0); |
217 |
iliev |
2225 |
|
218 |
iliev |
2229 |
float phase = pLfoInfo->phase + GetInfluence(pLfoInfo->phase_oncc); |
219 |
iliev |
2225 |
if (phase != 0) pLFO->SetPhase(phase); |
220 |
iliev |
2219 |
} |
221 |
iliev |
2221 |
|
222 |
|
|
void AmpLFOUnit::Trigger() { |
223 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
224 |
iliev |
2226 |
pLfoInfo->delay = pRegion->amplfo_delay; |
225 |
|
|
pLfoInfo->freq = pRegion->amplfo_freq; |
226 |
|
|
pLfoInfo->fade = pRegion->amplfo_fade; |
227 |
iliev |
2221 |
pLfoInfo->volume = pRegion->amplfo_depth; |
228 |
|
|
|
229 |
|
|
LFOv1Unit::Trigger(); |
230 |
|
|
} |
231 |
|
|
|
232 |
|
|
void PitchLFOUnit::Trigger() { |
233 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
234 |
|
|
pLfoInfo->delay = pRegion->pitchlfo_delay; |
235 |
iliev |
2226 |
pLfoInfo->freq = pRegion->pitchlfo_freq; |
236 |
|
|
pLfoInfo->fade = pRegion->pitchlfo_fade; |
237 |
iliev |
2221 |
pLfoInfo->pitch = pRegion->pitchlfo_depth; |
238 |
|
|
|
239 |
|
|
LFOv1Unit::Trigger(); |
240 |
|
|
} |
241 |
|
|
|
242 |
|
|
void FilLFOUnit::Trigger() { |
243 |
|
|
::sfz::Region* const pRegion = pVoice->pRegion; |
244 |
iliev |
2226 |
pLfoInfo->delay = pRegion->fillfo_delay; |
245 |
|
|
pLfoInfo->freq = pRegion->fillfo_freq; |
246 |
|
|
pLfoInfo->fade = pRegion->fillfo_fade; |
247 |
iliev |
2221 |
pLfoInfo->cutoff = pRegion->fillfo_depth; |
248 |
|
|
|
249 |
|
|
LFOv1Unit::Trigger(); |
250 |
|
|
} |
251 |
iliev |
2224 |
|
252 |
iliev |
2227 |
CCUnit::CCUnit(SfzSignalUnitRack* rack, Listener* l): CCSignalUnit(rack, l) { |
253 |
|
|
pVoice = NULL; |
254 |
|
|
} |
255 |
iliev |
2224 |
|
256 |
|
|
void CCUnit::Trigger() { |
257 |
|
|
for (int i = 0; i < Ctrls.size(); i++) { |
258 |
|
|
Ctrls[i].Value = pVoice->GetControllerValue(Ctrls[i].Controller); |
259 |
|
|
} |
260 |
|
|
CCSignalUnit::Trigger(); |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
void CCUnit::SetCCs(::sfz::Array<int>& cc) { |
264 |
|
|
RemoveAllCCs(); |
265 |
|
|
for (int i = 0; i < 128; i++) { |
266 |
|
|
if (cc[i] != 0) AddCC(i, cc[i]); |
267 |
|
|
} |
268 |
|
|
} |
269 |
iliev |
2225 |
|
270 |
|
|
void CCUnit::SetCCs(ArrayList< ::sfz::CC>& cc) { |
271 |
|
|
RemoveAllCCs(); |
272 |
|
|
for (int i = 0; i < cc.size(); i++) { |
273 |
|
|
if (cc[i].Influence != 0) AddCC(cc[i].Controller, cc[i].Influence); |
274 |
|
|
} |
275 |
|
|
} |
276 |
iliev |
2218 |
|
277 |
iliev |
2219 |
|
278 |
iliev |
2218 |
EndpointUnit::EndpointUnit(SfzSignalUnitRack* rack): EndpointSignalUnit(rack) { |
279 |
|
|
|
280 |
|
|
} |
281 |
|
|
|
282 |
|
|
SfzSignalUnitRack* const EndpointUnit::GetRack() { |
283 |
|
|
return static_cast<SfzSignalUnitRack* const>(pRack); |
284 |
|
|
} |
285 |
|
|
|
286 |
|
|
void EndpointUnit::Trigger() { |
287 |
|
|
|
288 |
|
|
} |
289 |
|
|
|
290 |
|
|
bool EndpointUnit::Active() { |
291 |
|
|
if (GetRack()->suVolEG.Active()) return true; |
292 |
|
|
|
293 |
|
|
bool b = false; |
294 |
|
|
for (int i = 0; i < GetRack()->volEGs.size(); i++) { |
295 |
|
|
if (GetRack()->volEGs[i]->Active()) { b = true; break; } |
296 |
|
|
} |
297 |
|
|
|
298 |
|
|
return b; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
float EndpointUnit::GetVolume() { |
302 |
|
|
float vol = GetRack()->suVolEG.Active() ? GetRack()->suVolEG.GetLevel() : 0; |
303 |
|
|
|
304 |
|
|
for (int i = 0; i < GetRack()->volEGs.size(); i++) { |
305 |
|
|
EGv2Unit* eg = GetRack()->volEGs[i]; |
306 |
|
|
if (!eg->Active()) continue; |
307 |
|
|
vol += eg->GetLevel() * (eg->pEGInfo->amplitude / 100.0f); |
308 |
iliev |
2229 |
|
309 |
iliev |
2218 |
} |
310 |
|
|
|
311 |
iliev |
2221 |
AmpLFOUnit* u = &(GetRack()->suAmpLFO); |
312 |
|
|
vol *= u->Active() ? ::sf2::ToRatio((u->GetLevel() * u->pLfoInfo->volume) * 10.0) : 1; |
313 |
|
|
|
314 |
iliev |
2218 |
return vol; |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
float EndpointUnit::GetFilterCutoff() { |
318 |
iliev |
2221 |
float val; |
319 |
iliev |
2219 |
|
320 |
iliev |
2221 |
FilLFOUnit* u = &(GetRack()->suFilLFO); |
321 |
|
|
val = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->pLfoInfo->cutoff) : 1; |
322 |
|
|
|
323 |
iliev |
2222 |
FilEGUnit* u2 = &(GetRack()->suFilEG); |
324 |
|
|
val *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * u2->depth) : 1; |
325 |
|
|
|
326 |
iliev |
2219 |
for (int i = 0; i < GetRack()->filLFOs.size(); i++) { |
327 |
|
|
LFOv2Unit* lfo = GetRack()->filLFOs[i]; |
328 |
|
|
if (!lfo->Active()) continue; |
329 |
|
|
|
330 |
|
|
float f = lfo->GetLevel() * lfo->pLfoInfo->cutoff; |
331 |
|
|
val *= RTMath::CentsToFreqRatioUnlimited(f); |
332 |
|
|
} |
333 |
|
|
|
334 |
|
|
return val; |
335 |
iliev |
2218 |
} |
336 |
|
|
|
337 |
|
|
float EndpointUnit::GetPitch() { |
338 |
iliev |
2221 |
double p; |
339 |
iliev |
2220 |
EGv1Unit* u = &(GetRack()->suPitchEG); |
340 |
iliev |
2221 |
p = u->Active() ? RTMath::CentsToFreqRatioUnlimited(u->GetLevel() * u->depth) : 1; |
341 |
|
|
|
342 |
|
|
PitchLFOUnit* u2 = &(GetRack()->suPitchLFO); |
343 |
iliev |
2224 |
CCSignalUnit* u3 = &(GetRack()->suPitchLFO.suDepthCC); |
344 |
|
|
float f = u3->Active() ? u3->GetLevel() : 0; |
345 |
|
|
p *= u2->Active() ? RTMath::CentsToFreqRatioUnlimited(u2->GetLevel() * (u2->pLfoInfo->pitch + f)) : 1; |
346 |
iliev |
2225 |
|
347 |
|
|
for (int i = 0; i < GetRack()->pitchLFOs.size(); i++) { |
348 |
|
|
LFOv2Unit* lfo = GetRack()->pitchLFOs[i]; |
349 |
|
|
if (!lfo->Active()) continue; |
350 |
|
|
|
351 |
|
|
float f = lfo->suPitchOnCC.Active() ? lfo->suPitchOnCC.GetLevel() : 0; |
352 |
|
|
p *= RTMath::CentsToFreqRatioUnlimited(lfo->GetLevel() * (lfo->pLfoInfo->pitch + f)); |
353 |
|
|
} |
354 |
|
|
|
355 |
iliev |
2221 |
return p; |
356 |
iliev |
2218 |
} |
357 |
|
|
|
358 |
|
|
float EndpointUnit::GetResonance() { |
359 |
iliev |
2219 |
float val = 0; |
360 |
|
|
|
361 |
|
|
for (int i = 0; i < GetRack()->resLFOs.size(); i++) { |
362 |
|
|
LFOv2Unit* lfo = GetRack()->resLFOs[i]; |
363 |
|
|
if (!lfo->Active()) continue; |
364 |
|
|
|
365 |
|
|
val += lfo->GetLevel() * lfo->pLfoInfo->resonance; |
366 |
|
|
} |
367 |
|
|
|
368 |
|
|
return val; |
369 |
iliev |
2218 |
} |
370 |
|
|
|
371 |
iliev |
2219 |
float EndpointUnit::GetPan() { |
372 |
|
|
float pan = 0; |
373 |
|
|
|
374 |
|
|
for (int i = 0; i < GetRack()->panLFOs.size(); i++) { |
375 |
|
|
LFOv2Unit* lfo = GetRack()->panLFOs[i]; |
376 |
|
|
if (!lfo->Active()) continue; |
377 |
|
|
|
378 |
|
|
pan += lfo->GetLevel() * lfo->pLfoInfo->pan; |
379 |
|
|
} |
380 |
|
|
|
381 |
|
|
if(pan < -100) return -100; |
382 |
|
|
if(pan > 100) return 100; |
383 |
|
|
|
384 |
|
|
return pan; |
385 |
|
|
} |
386 |
iliev |
2218 |
|
387 |
iliev |
2219 |
|
388 |
iliev |
2218 |
SfzSignalUnitRack::SfzSignalUnitRack(Voice* voice) |
389 |
iliev |
2222 |
: SignalUnitRack(MaxUnitCount), pVoice(voice), suEndpoint(this), suVolEG(this), suFilEG(this), suPitchEG(this), |
390 |
iliev |
2219 |
EGs(maxEgCount), volEGs(maxEgCount), pitchEGs(maxEgCount), |
391 |
iliev |
2221 |
suAmpLFO(this), suPitchLFO(this), suFilLFO(this), |
392 |
iliev |
2225 |
LFOs(maxLfoCount), pitchLFOs(maxLfoCount), filLFOs(maxLfoCount), resLFOs(maxLfoCount), panLFOs(maxLfoCount) |
393 |
iliev |
2218 |
{ |
394 |
iliev |
2222 |
suEndpoint.pVoice = suVolEG.pVoice = suFilEG.pVoice = suPitchEG.pVoice = voice; |
395 |
iliev |
2221 |
suAmpLFO.pVoice = suPitchLFO.pVoice = suFilLFO.pVoice = voice; |
396 |
iliev |
2227 |
suPitchLFO.suDepthCC.pVoice = suPitchLFO.suFadeEG.pVoice = suPitchLFO.suFreqOnCC.pVoice = voice; |
397 |
|
|
suFilLFO.suFadeEG.pVoice = suFilLFO.suFreqOnCC.pVoice = voice; |
398 |
|
|
suAmpLFO.suFadeEG.pVoice = suAmpLFO.suFreqOnCC.pVoice = voice; |
399 |
iliev |
2218 |
|
400 |
|
|
for (int i = 0; i < EGs.capacity(); i++) { |
401 |
|
|
EGs[i] = new EGv2Unit(this); |
402 |
|
|
EGs[i]->pVoice = voice; |
403 |
|
|
} |
404 |
iliev |
2219 |
|
405 |
|
|
for (int i = 0; i < LFOs.capacity(); i++) { |
406 |
|
|
LFOs[i] = new LFOv2Unit(this); |
407 |
|
|
LFOs[i]->pVoice = voice; |
408 |
iliev |
2226 |
LFOs[i]->suFadeEG.pVoice = voice; |
409 |
iliev |
2225 |
LFOs[i]->suPitchOnCC.pVoice = voice; |
410 |
iliev |
2227 |
LFOs[i]->suFreqOnCC.pVoice = voice; |
411 |
iliev |
2219 |
} |
412 |
iliev |
2218 |
} |
413 |
|
|
|
414 |
|
|
SfzSignalUnitRack::~SfzSignalUnitRack() { |
415 |
iliev |
2219 |
for (int i = 0; i < EGs.capacity(); i++) { |
416 |
iliev |
2218 |
delete EGs[i]; EGs[i] = NULL; |
417 |
|
|
} |
418 |
iliev |
2219 |
|
419 |
|
|
for (int i = 0; i < LFOs.capacity(); i++) { |
420 |
|
|
delete LFOs[i]; LFOs[i] = NULL; |
421 |
|
|
} |
422 |
iliev |
2218 |
} |
423 |
|
|
|
424 |
|
|
void SfzSignalUnitRack::Trigger() { |
425 |
|
|
EGs.clear(); |
426 |
|
|
volEGs.clear(); |
427 |
|
|
pitchEGs.clear(); |
428 |
|
|
|
429 |
iliev |
2219 |
LFOs.clear(); |
430 |
iliev |
2225 |
pitchLFOs.clear(); |
431 |
iliev |
2219 |
filLFOs.clear(); |
432 |
|
|
resLFOs.clear(); |
433 |
|
|
panLFOs.clear(); |
434 |
|
|
|
435 |
iliev |
2218 |
::sfz::Region* const pRegion = pVoice->pRegion; |
436 |
|
|
|
437 |
iliev |
2219 |
for (int i = 0; i < pRegion->eg.size(); i++) { |
438 |
iliev |
2218 |
if (pRegion->eg[i].node.size() == 0) continue; |
439 |
|
|
|
440 |
|
|
if(EGs.size() < EGs.capacity()) { |
441 |
|
|
EGv2Unit eg(this); |
442 |
|
|
eg.pEGInfo = &(pRegion->eg[i]); |
443 |
|
|
EGs.increment()->Copy(eg); |
444 |
|
|
} else { std::cerr << "Maximum number of EGs reached!" << std::endl; break; } |
445 |
|
|
|
446 |
|
|
if (pRegion->eg[i].amplitude > 0) { |
447 |
|
|
if(volEGs.size() < volEGs.capacity()) volEGs.add(EGs[EGs.size() - 1]); |
448 |
|
|
else std::cerr << "Maximum number of EGs reached!" << std::endl; |
449 |
|
|
} |
450 |
|
|
} |
451 |
|
|
|
452 |
|
|
if (pRegion->ampeg_sustain == -1) { |
453 |
|
|
if (volEGs.size() > 0) pRegion->ampeg_sustain = 0; |
454 |
|
|
else pRegion->ampeg_sustain = 100; |
455 |
|
|
} |
456 |
|
|
|
457 |
iliev |
2219 |
// LFO |
458 |
|
|
for (int i = 0; i < pRegion->lfos.size(); i++) { |
459 |
|
|
if (pRegion->lfos[i].freq == -1) continue; // Not initialized |
460 |
|
|
|
461 |
|
|
if(LFOs.size() < LFOs.capacity()) { |
462 |
|
|
LFOv2Unit lfo(this); |
463 |
|
|
lfo.pLfoInfo = &(pRegion->lfos[i]); |
464 |
|
|
LFOs.increment()->Copy(lfo); |
465 |
iliev |
2225 |
LFOs[LFOs.size() - 1]->suPitchOnCC.SetCCs(pRegion->lfos[i].pitch_oncc); |
466 |
iliev |
2227 |
LFOs[LFOs.size() - 1]->suFreqOnCC.SetCCs(pRegion->lfos[i].freq_oncc); |
467 |
iliev |
2219 |
} else { std::cerr << "Maximum number of LFOs reached!" << std::endl; break; } |
468 |
|
|
|
469 |
iliev |
2225 |
if (pRegion->lfos[i].pitch != 0 || !pRegion->lfos[i].pitch_oncc.empty()) { |
470 |
|
|
if(pitchLFOs.size() < pitchLFOs.capacity()) pitchLFOs.add(LFOs[LFOs.size() - 1]); |
471 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
472 |
|
|
} |
473 |
|
|
|
474 |
iliev |
2219 |
if (pRegion->lfos[i].cutoff != 0) { |
475 |
|
|
if(filLFOs.size() < filLFOs.capacity()) filLFOs.add(LFOs[LFOs.size() - 1]); |
476 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
477 |
|
|
} |
478 |
|
|
|
479 |
|
|
if (pRegion->lfos[i].resonance != 0) { |
480 |
|
|
if(resLFOs.size() < resLFOs.capacity()) resLFOs.add(LFOs[LFOs.size() - 1]); |
481 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
482 |
|
|
} |
483 |
|
|
|
484 |
|
|
if (pRegion->lfos[i].pan != 0) { |
485 |
|
|
if(panLFOs.size() < panLFOs.capacity()) panLFOs.add(LFOs[LFOs.size() - 1]); |
486 |
|
|
else std::cerr << "Maximum number of LFOs reached!" << std::endl; |
487 |
|
|
} |
488 |
|
|
} |
489 |
|
|
|
490 |
iliev |
2224 |
suPitchLFO.suDepthCC.SetCCs(pRegion->pitchlfo_depthcc); |
491 |
iliev |
2227 |
suPitchLFO.suFreqOnCC.SetCCs(pRegion->pitchlfo_freqcc); |
492 |
iliev |
2224 |
|
493 |
iliev |
2227 |
suFilLFO.suFreqOnCC.SetCCs(pRegion->fillfo_freqcc); |
494 |
|
|
|
495 |
|
|
suAmpLFO.suFreqOnCC.SetCCs(pRegion->amplfo_freqcc); |
496 |
|
|
|
497 |
iliev |
2218 |
Units.clear(); |
498 |
|
|
|
499 |
|
|
Units.add(&suVolEG); |
500 |
iliev |
2222 |
Units.add(&suFilEG); |
501 |
iliev |
2220 |
Units.add(&suPitchEG); |
502 |
iliev |
2227 |
|
503 |
|
|
Units.add(&suPitchLFO.suFreqOnCC); // Don't change order! (should be triggered before the LFO) |
504 |
iliev |
2221 |
Units.add(&suPitchLFO); |
505 |
iliev |
2224 |
Units.add(&suPitchLFO.suDepthCC); |
506 |
iliev |
2226 |
Units.add(&suPitchLFO.suFadeEG); |
507 |
iliev |
2227 |
|
508 |
|
|
Units.add(&suAmpLFO.suFreqOnCC); // Don't change order! (should be triggered before the LFO) |
509 |
iliev |
2221 |
Units.add(&suAmpLFO); |
510 |
iliev |
2226 |
Units.add(&suAmpLFO.suFadeEG); |
511 |
iliev |
2227 |
|
512 |
|
|
Units.add(&suFilLFO.suFreqOnCC); // Don't change order! (should be triggered before the LFO) |
513 |
iliev |
2221 |
Units.add(&suFilLFO); |
514 |
iliev |
2226 |
Units.add(&suFilLFO.suFadeEG); |
515 |
iliev |
2218 |
|
516 |
iliev |
2219 |
for (int i = 0; i < EGs.size(); i++) { |
517 |
iliev |
2218 |
Units.add(EGs[i]); |
518 |
|
|
} |
519 |
|
|
|
520 |
iliev |
2219 |
for (int i = 0; i < LFOs.size(); i++) { |
521 |
iliev |
2227 |
Units.add(&(LFOs[i]->suFreqOnCC)); // Don't change order! (should be triggered before the LFO) |
522 |
iliev |
2219 |
Units.add(LFOs[i]); |
523 |
iliev |
2226 |
Units.add(&(LFOs[i]->suFadeEG)); |
524 |
iliev |
2225 |
Units.add(&(LFOs[i]->suPitchOnCC)); |
525 |
iliev |
2219 |
} |
526 |
|
|
|
527 |
iliev |
2218 |
Units.add(&suEndpoint); |
528 |
|
|
|
529 |
|
|
SignalUnitRack::Trigger(); |
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
EndpointSignalUnit* SfzSignalUnitRack::GetEndpointUnit() { |
533 |
|
|
return &suEndpoint; |
534 |
|
|
} |
535 |
|
|
|
536 |
|
|
void SfzSignalUnitRack::EnterFadeOutStage() { |
537 |
|
|
suVolEG.EG.enterFadeOutStage(); |
538 |
|
|
|
539 |
|
|
for (int i = 0; i < volEGs.size(); i++) { |
540 |
|
|
volEGs[i]->EG.enterFadeOutStage(); |
541 |
|
|
} |
542 |
|
|
} |
543 |
|
|
|
544 |
|
|
}} // namespace LinuxSampler::sfz |