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 |
); |
); |
59 |
} |
} |
60 |
|
|
82 |
if (active()) { |
if (active()) { |
83 |
|
|
84 |
// 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 |
85 |
/*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) { |
86 |
update(EG::event_hold_end, pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
update(EG::event_hold_end, pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
87 |
}*/ |
}*/ |
88 |
// TODO: ^^^ |
// TODO: ^^^ |
89 |
|
|
90 |
increment(1); |
increment(1); |
91 |
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); |
92 |
} |
} |
93 |
} |
} |
94 |
|
|
95 |
void ModEGUnit::Trigger() { |
void ModEGUnit::Trigger() { |
96 |
double d = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double d = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
97 |
uiDelayTrigger = pOwner->pRegion->GetEG2PreAttackDelay(pOwner->pPresetRegion) * d; |
uiDelayTrigger = pVoice->pRegion->GetEG2PreAttackDelay(pVoice->pPresetRegion) * d; |
98 |
|
|
99 |
trigger ( |
trigger ( |
100 |
0, // should be in permille |
0, // should be in permille |
101 |
pOwner->pRegion->GetEG2Attack(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Attack(pVoice->pPresetRegion), |
102 |
pOwner->pRegion->GetEG2Hold(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Hold(pVoice->pPresetRegion), |
103 |
pOwner->pRegion->GetEG2Decay(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Decay(pVoice->pPresetRegion), |
104 |
uint(1000 - pOwner->pRegion->GetEG2Sustain(pOwner->pPresetRegion)), |
uint(1000 - pVoice->pRegion->GetEG2Sustain(pVoice->pPresetRegion)), |
105 |
pOwner->pRegion->GetEG2Release(pOwner->pPresetRegion), |
pVoice->pRegion->GetEG2Release(pVoice->pPresetRegion), |
106 |
pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
107 |
); |
); |
108 |
} |
} |
109 |
|
|
130 |
|
|
131 |
if (active()) { |
if (active()) { |
132 |
increment(1); |
increment(1); |
133 |
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); |
134 |
} |
} |
135 |
} |
} |
136 |
|
|
140 |
Level = 0; |
Level = 0; |
141 |
|
|
142 |
// set the delay trigger |
// set the delay trigger |
143 |
double samplerate = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double samplerate = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
144 |
uiDelayTrigger = pOwner->pRegion->GetDelayModLfo(pOwner->pPresetRegion) * samplerate; |
uiDelayTrigger = pVoice->pRegion->GetDelayModLfo(pVoice->pPresetRegion) * samplerate; |
145 |
//////////// |
//////////// |
146 |
|
|
147 |
trigger ( |
trigger ( |
148 |
pOwner->pRegion->GetFreqModLfo(pOwner->pPresetRegion), |
pVoice->pRegion->GetFreqModLfo(pVoice->pPresetRegion), |
149 |
start_level_min, |
start_level_min, |
150 |
1, 0, false, samplerate |
1, 0, false, samplerate |
151 |
); |
); |
155 |
void ModLfoUnit::Increment() { |
void ModLfoUnit::Increment() { |
156 |
if (DelayStage()) return; |
if (DelayStage()) return; |
157 |
|
|
158 |
SignalUnitBase<Voice>::Increment(); |
SignalUnit::Increment(); |
159 |
|
|
160 |
Level = render(); |
Level = render(); |
161 |
} |
} |
166 |
Level = 0; |
Level = 0; |
167 |
|
|
168 |
// set the delay trigger |
// set the delay trigger |
169 |
double samplerate = pOwner->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
double samplerate = pVoice->GetSampleRate() / CONFIG_DEFAULT_SUBFRAGMENT_SIZE; |
170 |
uiDelayTrigger = pOwner->pRegion->GetDelayVibLfo(pOwner->pPresetRegion) * samplerate; |
uiDelayTrigger = pVoice->pRegion->GetDelayVibLfo(pVoice->pPresetRegion) * samplerate; |
171 |
//////////// |
//////////// |
172 |
|
|
173 |
trigger ( |
trigger ( |
174 |
pOwner->pRegion->GetFreqVibLfo(pOwner->pPresetRegion), |
pVoice->pRegion->GetFreqVibLfo(pVoice->pPresetRegion), |
175 |
start_level_min, |
start_level_min, |
176 |
pOwner->pRegion->GetVibLfoToPitch(pOwner->pPresetRegion), |
pVoice->pRegion->GetVibLfoToPitch(pVoice->pPresetRegion), |
177 |
0, false, samplerate |
0, false, samplerate |
178 |
); |
); |
179 |
update(0); |
update(0); |
182 |
void VibLfoUnit::Increment() { |
void VibLfoUnit::Increment() { |
183 |
if (DelayStage()) return; |
if (DelayStage()) return; |
184 |
|
|
185 |
SignalUnitBase<Voice>::Increment(); |
SignalUnit::Increment(); |
186 |
|
|
187 |
Level = render(); |
Level = render(); |
188 |
} |
} |
189 |
|
|
190 |
|
|
191 |
EndpointUnit::EndpointUnit() { |
EndpointUnit::EndpointUnit(SF2SignalUnitRack* rack): EndpointSignalUnit(rack), pVoice(rack->pVoice) { |
192 |
|
|
193 |
} |
} |
194 |
|
|
195 |
void EndpointUnit::Trigger() { |
void EndpointUnit::Trigger() { |
196 |
prmModEgPitch->Coeff = pOwner->pRegion->GetModEnvToPitch(pOwner->pPresetRegion); |
prmModEgPitch->Coeff = pVoice->pRegion->GetModEnvToPitch(pVoice->pPresetRegion); |
197 |
if (prmModEgPitch->Coeff == ::sf2::NONE) prmModEgPitch->Coeff = 0; |
if (prmModEgPitch->Coeff == ::sf2::NONE) prmModEgPitch->Coeff = 0; |
198 |
|
|
199 |
prmModEgCutoff->Coeff = pOwner->pRegion->GetModEnvToFilterFc(pOwner->pPresetRegion); // cents |
prmModEgCutoff->Coeff = pVoice->pRegion->GetModEnvToFilterFc(pVoice->pPresetRegion); // cents |
200 |
if (prmModEgCutoff->Coeff == ::sf2::NONE) prmModEgCutoff->Coeff = 0; |
if (prmModEgCutoff->Coeff == ::sf2::NONE) prmModEgCutoff->Coeff = 0; |
201 |
|
|
202 |
prmModLfoVol->Coeff = pOwner->pRegion->GetModLfoToVolume(pOwner->pPresetRegion); // centibels |
prmModLfoVol->Coeff = pVoice->pRegion->GetModLfoToVolume(pVoice->pPresetRegion); // centibels |
203 |
if (prmModLfoVol->Coeff == ::sf2::NONE) prmModLfoVol->Coeff = 0; |
if (prmModLfoVol->Coeff == ::sf2::NONE) prmModLfoVol->Coeff = 0; |
204 |
|
|
205 |
prmModLfoCutoff->Coeff = pOwner->pRegion->GetModLfoToFilterFc(pOwner->pPresetRegion); |
prmModLfoCutoff->Coeff = pVoice->pRegion->GetModLfoToFilterFc(pVoice->pPresetRegion); |
206 |
if (prmModLfoCutoff->Coeff == ::sf2::NONE) prmModLfoCutoff->Coeff = 0; |
if (prmModLfoCutoff->Coeff == ::sf2::NONE) prmModLfoCutoff->Coeff = 0; |
207 |
|
|
208 |
prmModLfoPitch->Coeff = pOwner->pRegion->GetModLfoToPitch(pOwner->pPresetRegion); |
prmModLfoPitch->Coeff = pVoice->pRegion->GetModLfoToPitch(pVoice->pPresetRegion); |
209 |
if (prmModLfoPitch->Coeff == ::sf2::NONE) prmModLfoPitch->Coeff = 0; |
if (prmModLfoPitch->Coeff == ::sf2::NONE) prmModLfoPitch->Coeff = 0; |
210 |
} |
} |
211 |
|
|
244 |
return 1; |
return 1; |
245 |
} |
} |
246 |
|
|
247 |
SF2SignalUnitRack::SF2SignalUnitRack(Voice* pVoice): SignalUnitRackBase<Voice>(pVoice) { |
SF2SignalUnitRack::SF2SignalUnitRack(Voice* voice) |
248 |
|
: pVoice(voice), suVolEG(this), suModEG(this), suModLfo(this), suVibLfo(this), suEndpoint(this) { |
249 |
|
|
250 |
|
suVolEG.pVoice = suModEG.pVoice = suModLfo.pVoice = suVibLfo.pVoice = suEndpoint.pVoice = voice; |
251 |
Units.add(&suVolEG); |
Units.add(&suVolEG); |
252 |
Units.add(&suModEG); |
Units.add(&suModEG); |
253 |
Units.add(&suModLfo); |
Units.add(&suModLfo); |
277 |
suEndpoint.prmVibLfo = &suEndpoint.Params[6]; |
suEndpoint.prmVibLfo = &suEndpoint.Params[6]; |
278 |
} |
} |
279 |
|
|
|
void SF2SignalUnitRack::Trigger() { |
|
|
// The region settings are available after the voice is triggered |
|
|
|
|
|
SignalUnitRackBase<Voice>::Trigger(); |
|
|
} |
|
|
|
|
280 |
EndpointSignalUnit* SF2SignalUnitRack::GetEndpointUnit() { |
EndpointSignalUnit* SF2SignalUnitRack::GetEndpointUnit() { |
281 |
return static_cast<EndpointSignalUnit*> (&suEndpoint); |
return static_cast<EndpointSignalUnit*> (&suEndpoint); |
282 |
} |
} |