2 |
* * |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2011 Grigor Iliev * |
* Copyright (C) 2011 - 2012 Grigor Iliev * |
6 |
* * |
* * |
7 |
* This program is free software; you can redistribute it and/or modify * |
* 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 * |
* it under the terms of the GNU General Public License as published by * |
25 |
|
|
26 |
namespace LinuxSampler { namespace sf2 { |
namespace LinuxSampler { namespace sf2 { |
27 |
|
|
28 |
|
SFSignalUnit::SFSignalUnit(SF2SignalUnitRack* rack): SignalUnit(rack), pVoice(NULL) { |
29 |
|
|
30 |
|
} |
31 |
|
|
32 |
void EGUnit::EnterReleaseStage() { |
void EGUnit::EnterReleaseStage() { |
33 |
update(EG::event_release, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
update(EG::event_release, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
34 |
} |
} |
35 |
|
|
36 |
void EGUnit::CancelRelease() { |
void EGUnit::CancelRelease() { |
37 |
update(EG::event_cancel_release, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
update(EG::event_cancel_release, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
38 |
} |
} |
39 |
|
|
40 |
|
|
41 |
void VolEGUnit::Trigger() { |
void VolEGUnit::Trigger() { |
42 |
// set the delay trigger |
// set the delay trigger |
43 |
double d = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double d = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
44 |
uiDelayTrigger = pOwner->pRegion->GetEG1PreAttackDelay(pOwner->pPresetRegion) * d; |
uiDelayTrigger = pVoice->pRegion->GetEG1PreAttackDelay(pVoice->pPresetRegion) * d; |
45 |
//////////// |
//////////// |
46 |
|
|
47 |
// GetEG1Sustain gets the decrease in level in centibels |
// GetEG1Sustain gets the decrease in level in centibels |
48 |
uint sustain = ::sf2::ToRatio(-1 * pOwner->pRegion->GetEG1Sustain(pOwner->pPresetRegion)) * 1000; // in permille |
uint sustain = ::sf2::ToRatio(-1 * pVoice->pRegion->GetEG1Sustain(pVoice->pPresetRegion)) * 1000; // in permille |
49 |
|
|
50 |
trigger ( |
trigger ( |
51 |
0, // should be in permille |
0, // should be in permille |
52 |
pOwner->pRegion->GetEG1Attack(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG1Attack(pVoice->pPresetRegion), |
53 |
pOwner->pRegion->GetEG1Hold(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG1Hold(pVoice->pPresetRegion), |
54 |
pOwner->pRegion->GetEG1Decay(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG1Decay(pVoice->pPresetRegion), |
55 |
sustain, |
sustain, |
56 |
pOwner->pRegion->GetEG1Release(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG1Release(pVoice->pPresetRegion), |
57 |
pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE, |
58 |
|
false |
59 |
); |
); |
60 |
} |
} |
61 |
|
|
83 |
if (active()) { |
if (active()) { |
84 |
|
|
85 |
// if sample has a loop and loop start has been reached in this subfragment, send a special event to EG1 to let it finish the attack hold stage |
// if sample has a loop and loop start has been reached in this subfragment, send a special event to EG1 to let it finish the attack hold stage |
86 |
/*if (pOwner->SmplInfo.HasLoops && pOwner->Pos <= pOwner->SmplInfo.LoopStart && pOwner->SmplInfo.LoopStart < newPos) { |
/*if (pVoice->SmplInfo.HasLoops && pVoice->Pos <= pVoice->SmplInfo.LoopStart && pVoice->SmplInfo.LoopStart < newPos) { |
87 |
update(EG::event_hold_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
update(EG::event_hold_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
88 |
}*/ |
}*/ |
89 |
// TODO: ^^^ |
// TODO: ^^^ |
90 |
|
|
91 |
increment(1); |
increment(1); |
92 |
if (!toStageEndLeft()) update(EG::event_stage_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
if (!toStageEndLeft()) update(EG::event_stage_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
93 |
} |
} |
94 |
} |
} |
95 |
|
|
96 |
void ModEGUnit::Trigger() { |
void ModEGUnit::Trigger() { |
97 |
double d = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double d = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
98 |
uiDelayTrigger = pOwner->pRegion->GetEG2PreAttackDelay(pOwner->pPresetRegion) * d; |
uiDelayTrigger = pVoice->pRegion->GetEG2PreAttackDelay(pVoice->pPresetRegion) * d; |
99 |
|
|
100 |
trigger ( |
trigger ( |
101 |
0, // should be in permille |
0, // should be in permille |
102 |
pOwner->pRegion->GetEG2Attack(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Attack(pVoice->pPresetRegion), |
103 |
pOwner->pRegion->GetEG2Hold(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Hold(pVoice->pPresetRegion), |
104 |
pOwner->pRegion->GetEG2Decay(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Decay(pVoice->pPresetRegion), |
105 |
uint(1000 - pOwner->pRegion->GetEG2Sustain(pOwner->pPresetRegion)), |
uint(1000 - pVoice->pRegion->GetEG2Sustain(pVoice->pPresetRegion)), |
106 |
pOwner->pRegion->GetEG2Release(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Release(pVoice->pPresetRegion), |
107 |
pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE, |
108 |
|
true |
109 |
); |
); |
110 |
} |
} |
111 |
|
|
132 |
|
|
133 |
if (active()) { |
if (active()) { |
134 |
increment(1); |
increment(1); |
135 |
if (!toStageEndLeft()) update(EG::event_stage_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
if (!toStageEndLeft()) update(EG::event_stage_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
136 |
} |
} |
137 |
} |
} |
138 |
|
|
139 |
|
|
142 |
Level = 0; |
Level = 0; |
143 |
|
|
144 |
// set the delay trigger |
// set the delay trigger |
145 |
double samplerate = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double samplerate = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
146 |
uiDelayTrigger = pOwner->pRegion->GetDelayModLfo(pOwner->pPresetRegion) * samplerate; |
uiDelayTrigger = pVoice->pRegion->GetDelayModLfo(pVoice->pPresetRegion) * samplerate; |
147 |
//////////// |
//////////// |
148 |
|
|
149 |
trigger ( |
trigger ( |
150 |
pOwner->pRegion->GetFreqModLfo(pOwner->pPresetRegion), |
pVoice->pRegion->GetFreqModLfo(pVoice->pPresetRegion), |
151 |
start_level_min, |
start_level_min, |
152 |
1, 0, false, samplerate |
1, 0, false, samplerate |
153 |
); |
); |
157 |
void ModLfoUnit::Increment() { |
void ModLfoUnit::Increment() { |
158 |
if (DelayStage()) return; |
if (DelayStage()) return; |
159 |
|
|
160 |
SignalUnitBase<Voice>::Increment(); |
SignalUnit::Increment(); |
161 |
|
|
162 |
Level = render(); |
Level = render(); |
163 |
} |
} |
168 |
Level = 0; |
Level = 0; |
169 |
|
|
170 |
// set the delay trigger |
// set the delay trigger |
171 |
double samplerate = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double samplerate = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
172 |
uiDelayTrigger = pOwner->pRegion->GetDelayVibLfo(pOwner->pPresetRegion) * samplerate; |
uiDelayTrigger = pVoice->pRegion->GetDelayVibLfo(pVoice->pPresetRegion) * samplerate; |
173 |
//////////// |
//////////// |
174 |
|
|
175 |
trigger ( |
trigger ( |
176 |
pOwner->pRegion->GetFreqVibLfo(pOwner->pPresetRegion), |
pVoice->pRegion->GetFreqVibLfo(pVoice->pPresetRegion), |
177 |
start_level_min, |
start_level_min, |
178 |
pOwner->pRegion->GetVibLfoToPitch(pOwner->pPresetRegion), |
pVoice->pRegion->GetVibLfoToPitch(pVoice->pPresetRegion), |
179 |
0, false, samplerate |
0, false, samplerate |
180 |
); |
); |
181 |
update(0); |
update(0); |
184 |
void VibLfoUnit::Increment() { |
void VibLfoUnit::Increment() { |
185 |
if (DelayStage()) return; |
if (DelayStage()) return; |
186 |
|
|
187 |
SignalUnitBase<Voice>::Increment(); |
SignalUnit::Increment(); |
188 |
|
|
189 |
Level = render(); |
Level = render(); |
190 |
} |
} |
191 |
|
|
192 |
|
|
193 |
EndpointUnit::EndpointUnit() { |
EndpointUnit::EndpointUnit(SF2SignalUnitRack* rack): EndpointSignalUnit(rack) { |
194 |
|
|
195 |
} |
} |
196 |
|
|
197 |
void EndpointUnit::Trigger() { |
void EndpointUnit::Trigger() { |
198 |
prmModEgPitch->Coeff = pOwner->pRegion->GetModEnvToPitch(pOwner->pPresetRegion); |
prmModEgPitch->Coeff = pVoice->pRegion->GetModEnvToPitch(pVoice->pPresetRegion); |
199 |
if (prmModEgPitch->Coeff == ::sf2::NONE) prmModEgPitch->Coeff = 0; |
if (prmModEgPitch->Coeff == ::sf2::NONE) prmModEgPitch->Coeff = 0; |
200 |
|
|
201 |
prmModEgCutoff->Coeff = pOwner->pRegion->GetModEnvToFilterFc(pOwner->pPresetRegion); // cents |
prmModEgCutoff->Coeff = pVoice->pRegion->GetModEnvToFilterFc(pVoice->pPresetRegion); // cents |
202 |
if (prmModEgCutoff->Coeff == ::sf2::NONE) prmModEgCutoff->Coeff = 0; |
if (prmModEgCutoff->Coeff == ::sf2::NONE) prmModEgCutoff->Coeff = 0; |
203 |
|
|
204 |
prmModLfoVol->Coeff = pOwner->pRegion->GetModLfoToVolume(pOwner->pPresetRegion); // centibels |
prmModLfoVol->Coeff = pVoice->pRegion->GetModLfoToVolume(pVoice->pPresetRegion); // centibels |
205 |
if (prmModLfoVol->Coeff == ::sf2::NONE) prmModLfoVol->Coeff = 0; |
if (prmModLfoVol->Coeff == ::sf2::NONE) prmModLfoVol->Coeff = 0; |
206 |
|
|
207 |
prmModLfoCutoff->Coeff = pOwner->pRegion->GetModLfoToFilterFc(pOwner->pPresetRegion); |
prmModLfoCutoff->Coeff = pVoice->pRegion->GetModLfoToFilterFc(pVoice->pPresetRegion); |
208 |
if (prmModLfoCutoff->Coeff == ::sf2::NONE) prmModLfoCutoff->Coeff = 0; |
if (prmModLfoCutoff->Coeff == ::sf2::NONE) prmModLfoCutoff->Coeff = 0; |
209 |
|
|
210 |
prmModLfoPitch->Coeff = pOwner->pRegion->GetModLfoToPitch(pOwner->pPresetRegion); |
prmModLfoPitch->Coeff = pVoice->pRegion->GetModLfoToPitch(pVoice->pPresetRegion); |
211 |
if (prmModLfoPitch->Coeff == ::sf2::NONE) prmModLfoPitch->Coeff = 0; |
if (prmModLfoPitch->Coeff == ::sf2::NONE) prmModLfoPitch->Coeff = 0; |
212 |
} |
} |
213 |
|
|
214 |
bool EndpointUnit::Active() { |
bool EndpointUnit::Active() { |
|
if (Params.size() < 1) return false; |
|
215 |
return prmVolEg->pUnit->Active(); // volEGUnit |
return prmVolEg->pUnit->Active(); // volEGUnit |
216 |
} |
} |
217 |
|
|
245 |
return 1; |
return 1; |
246 |
} |
} |
247 |
|
|
248 |
SF2SignalUnitRack::SF2SignalUnitRack(Voice* pVoice): SignalUnitRackBase<Voice>(pVoice) { |
SF2SignalUnitRack::SF2SignalUnitRack(Voice* voice) |
249 |
|
: SignalUnitRack(MaxUnitCount), suVolEG(this), suModEG(this), suModLfo(this), suVibLfo(this), suEndpoint(this), pVoice(voice) { |
250 |
|
|
251 |
|
suVolEG.pVoice = suModEG.pVoice = suModLfo.pVoice = suVibLfo.pVoice = suEndpoint.pVoice = voice; |
252 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
253 |
Units.add(&suModEG); |
Units.add(&suModEG); |
254 |
Units.add(&suModLfo); |
Units.add(&suModLfo); |
278 |
suEndpoint.prmVibLfo = &suEndpoint.Params[6]; |
suEndpoint.prmVibLfo = &suEndpoint.Params[6]; |
279 |
} |
} |
280 |
|
|
|
void SF2SignalUnitRack::Trigger() { |
|
|
// The region settings are available after the voice is triggered |
|
|
|
|
|
SignalUnitRackBase<Voice>::Trigger(); |
|
|
} |
|
|
|
|
281 |
EndpointSignalUnit* SF2SignalUnitRack::GetEndpointUnit() { |
EndpointSignalUnit* SF2SignalUnitRack::GetEndpointUnit() { |
282 |
return static_cast<EndpointSignalUnit*> (&suEndpoint); |
return static_cast<EndpointSignalUnit*> (&suEndpoint); |
283 |
} |
} |
284 |
|
|
285 |
|
void SF2SignalUnitRack::EnterFadeOutStage() { |
286 |
|
suVolEG.enterFadeOutStage(); |
287 |
|
} |
288 |
|
|
289 |
|
void SF2SignalUnitRack::EnterFadeOutStage(int maxFadeOutSteps) { |
290 |
|
suVolEG.enterFadeOutStage(maxFadeOutSteps); |
291 |
|
} |
292 |
|
|
293 |
|
void SF2SignalUnitRack::CalculateFadeOutCoeff(float FadeOutTime, float SampleRate) { |
294 |
|
suVolEG.CalculateFadeOutCoeff(FadeOutTime, SampleRate); |
295 |
|
} |
296 |
}} // namespace LinuxSampler::sf2 |
}} // namespace LinuxSampler::sf2 |