5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009 Christian Schoenebeck and Grigor Iliev * |
8 |
* Copyright (C) 2010 - 2016 Christian Schoenebeck and Andreas Persson * |
* Copyright (C) 2010 - 2017 Christian Schoenebeck and Andreas Persson * |
9 |
* * |
* * |
10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
11 |
* 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 * |
33 |
|
|
34 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
35 |
|
|
36 |
|
// sanity checks: fromGigLfoWave() assumes equally mapped enums |
37 |
|
static_assert(::gig::lfo_wave_sine == LFO::wave_sine); |
38 |
|
static_assert(::gig::lfo_wave_triangle == LFO::wave_triangle); |
39 |
|
static_assert(::gig::lfo_wave_saw == LFO::wave_saw); |
40 |
|
static_assert(::gig::lfo_wave_square == LFO::wave_square); |
41 |
|
|
42 |
|
// converts ::gig::lfo_wave_t (libgig) -> LFO::wave_t (LinuxSampler) |
43 |
|
inline LFO::wave_t fromGigLfoWave(::gig::lfo_wave_t wave) { |
44 |
|
// simply assuming equally mapped enums on both sides |
45 |
|
return static_cast<LFO::wave_t>(wave); |
46 |
|
} |
47 |
|
|
48 |
Voice::Voice() { |
Voice::Voice() { |
49 |
pEngine = NULL; |
pEngine = NULL; |
50 |
pEG1 = &EG1; |
pEG1 = &EG1; |
285 |
bLFO1Enabled = false; |
bLFO1Enabled = false; |
286 |
} |
} |
287 |
if (bLFO1Enabled) { |
if (bLFO1Enabled) { |
288 |
pLFO1->trigger(pRegion->LFO1Frequency, |
pLFO1->trigger(fromGigLfoWave(pRegion->LFO1WaveForm), |
289 |
start_level_min, |
pRegion->LFO1Frequency, |
290 |
|
pRegion->LFO1Phase, |
291 |
|
LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029 |
292 |
lfo1_internal_depth, |
lfo1_internal_depth, |
293 |
pRegion->LFO1ControlDepth, |
pRegion->LFO1ControlDepth, |
294 |
pRegion->LFO1FlipPhase, |
pRegion->LFO1FlipPhase, |
295 |
pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
296 |
pLFO1->update(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0); |
pLFO1->updateByMIDICtrlValue(pLFO1->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO1->ExtController] : 0); |
297 |
|
pLFO1->setScriptDepthFactor( |
298 |
|
pNote->Override.AmpLFODepth.Value, |
299 |
|
pNote->Override.AmpLFODepth.Final |
300 |
|
); |
301 |
|
if (pNote->Override.AmpLFOFreq.isFinal()) |
302 |
|
pLFO1->setScriptFrequencyFinal( |
303 |
|
pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
304 |
|
); |
305 |
|
else |
306 |
|
pLFO1->setScriptFrequencyFactor( |
307 |
|
pNote->Override.AmpLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE |
308 |
|
); |
309 |
} |
} |
310 |
} |
} |
311 |
|
|
343 |
bLFO2Enabled = false; |
bLFO2Enabled = false; |
344 |
} |
} |
345 |
if (bLFO2Enabled) { |
if (bLFO2Enabled) { |
346 |
pLFO2->trigger(pRegion->LFO2Frequency, |
pLFO2->trigger(fromGigLfoWave(pRegion->LFO2WaveForm), |
347 |
start_level_max, |
pRegion->LFO2Frequency, |
348 |
|
pRegion->LFO2Phase, |
349 |
|
LFO::start_level_mid, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029 |
350 |
lfo2_internal_depth, |
lfo2_internal_depth, |
351 |
pRegion->LFO2ControlDepth, |
pRegion->LFO2ControlDepth, |
352 |
pRegion->LFO2FlipPhase, |
pRegion->LFO2FlipPhase, |
353 |
pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
354 |
pLFO2->update(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0); |
pLFO2->updateByMIDICtrlValue(pLFO2->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO2->ExtController] : 0); |
355 |
|
pLFO2->setScriptDepthFactor( |
356 |
|
pNote->Override.CutoffLFODepth.Value, |
357 |
|
pNote->Override.CutoffLFODepth.Final |
358 |
|
); |
359 |
|
if (pNote->Override.CutoffLFOFreq.isFinal()) |
360 |
|
pLFO2->setScriptFrequencyFinal(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
361 |
|
else |
362 |
|
pLFO2->setScriptFrequencyFactor(pNote->Override.CutoffLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
363 |
} |
} |
364 |
} |
} |
365 |
|
|
397 |
bLFO3Enabled = false; |
bLFO3Enabled = false; |
398 |
} |
} |
399 |
if (bLFO3Enabled) { |
if (bLFO3Enabled) { |
400 |
pLFO3->trigger(pRegion->LFO3Frequency, |
pLFO3->trigger(fromGigLfoWave(pRegion->LFO3WaveForm), |
401 |
start_level_mid, |
pRegion->LFO3Frequency, |
402 |
|
pRegion->LFO3Phase, |
403 |
|
LFO::start_level_max, // see https://sourceforge.net/p/linuxsampler/mailman/linuxsampler-devel/thread/2189307.cNP0Xbctxq%40silver/#msg36774029 |
404 |
lfo3_internal_depth, |
lfo3_internal_depth, |
405 |
pRegion->LFO3ControlDepth, |
pRegion->LFO3ControlDepth, |
406 |
false, |
pRegion->LFO3FlipPhase, |
407 |
pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
408 |
pLFO3->update(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0); |
pLFO3->updateByMIDICtrlValue(pLFO3->ExtController ? GetGigEngineChannel()->ControllerTable[pLFO3->ExtController] : 0); |
409 |
|
pLFO3->setScriptDepthFactor( |
410 |
|
pNote->Override.PitchLFODepth.Value, |
411 |
|
pNote->Override.PitchLFODepth.Final |
412 |
|
); |
413 |
|
if (pNote->Override.PitchLFOFreq.isFinal()) |
414 |
|
pLFO3->setScriptFrequencyFinal(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
415 |
|
else |
416 |
|
pLFO3->setScriptFrequencyFactor(pNote->Override.PitchLFOFreq.Value, pEngine->SampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
417 |
} |
} |
418 |
} |
} |
419 |
|
|
508 |
} |
} |
509 |
|
|
510 |
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
void Voice::TriggerEG1(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
511 |
|
EG1.setStateOptions( |
512 |
|
pRegion->EG1Options.AttackCancel, |
513 |
|
pRegion->EG1Options.AttackHoldCancel, |
514 |
|
pRegion->EG1Options.Decay1Cancel, |
515 |
|
pRegion->EG1Options.Decay2Cancel, |
516 |
|
pRegion->EG1Options.ReleaseCancel |
517 |
|
); |
518 |
EG1.trigger(pRegion->EG1PreAttack, |
EG1.trigger(pRegion->EG1PreAttack, |
519 |
RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack, |
(pNote && pNote->Override.Attack.isFinal()) ? |
520 |
|
pNote->Override.Attack.Value : |
521 |
|
RTMath::Max(pRegion->EG1Attack, 0.0316) * egInfo.Attack, |
522 |
pRegion->EG1Hold, |
pRegion->EG1Hold, |
523 |
pRegion->EG1Decay1 * egInfo.Decay * velrelease, |
(pNote && pNote->Override.Decay.isFinal()) ? |
524 |
pRegion->EG1Decay2 * egInfo.Decay * velrelease, |
pNote->Override.Decay.Value : |
525 |
|
pRegion->EG1Decay1 * egInfo.Decay * velrelease, |
526 |
|
(pNote && pNote->Override.Decay.isFinal()) ? |
527 |
|
pNote->Override.Decay.Value : |
528 |
|
pRegion->EG1Decay2 * egInfo.Decay * velrelease, |
529 |
pRegion->EG1InfiniteSustain, |
pRegion->EG1InfiniteSustain, |
530 |
pRegion->EG1Sustain, |
(pNote && pNote->Override.Sustain.Final) ? |
531 |
RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release, |
uint(pNote->Override.Sustain.Value * 1000.f) : |
532 |
|
pRegion->EG1Sustain * (pNote ? pNote->Override.Sustain.Value : 1.f), |
533 |
|
(pNote && pNote->Override.Release.isFinal()) ? |
534 |
|
pNote->Override.Release.Value : |
535 |
|
RTMath::Max(pRegion->EG1Release * velrelease, 0.014) * egInfo.Release, |
536 |
velocityAttenuation, |
velocityAttenuation, |
537 |
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
538 |
} |
} |
539 |
|
|
540 |
void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
void Voice::TriggerEG2(const EGInfo& egInfo, double velrelease, double velocityAttenuation, uint sampleRate, uint8_t velocity) { |
541 |
|
EG2.setStateOptions( |
542 |
|
pRegion->EG2Options.AttackCancel, |
543 |
|
pRegion->EG2Options.AttackHoldCancel, |
544 |
|
pRegion->EG2Options.Decay1Cancel, |
545 |
|
pRegion->EG2Options.Decay2Cancel, |
546 |
|
pRegion->EG2Options.ReleaseCancel |
547 |
|
); |
548 |
EG2.trigger(uint(RgnInfo.EG2PreAttack), |
EG2.trigger(uint(RgnInfo.EG2PreAttack), |
549 |
RgnInfo.EG2Attack * egInfo.Attack, |
(pNote && pNote->Override.CutoffAttack.isFinal()) ? |
550 |
|
pNote->Override.CutoffAttack.Value : |
551 |
|
RgnInfo.EG2Attack * egInfo.Attack, |
552 |
false, |
false, |
553 |
RgnInfo.EG2Decay1 * egInfo.Decay * velrelease, |
(pNote && pNote->Override.CutoffDecay.isFinal()) ? |
554 |
RgnInfo.EG2Decay2 * egInfo.Decay * velrelease, |
pNote->Override.CutoffDecay.Value : |
555 |
|
RgnInfo.EG2Decay1 * egInfo.Decay * velrelease, |
556 |
|
(pNote && pNote->Override.CutoffDecay.isFinal()) ? |
557 |
|
pNote->Override.CutoffDecay.Value : |
558 |
|
RgnInfo.EG2Decay2 * egInfo.Decay * velrelease, |
559 |
RgnInfo.EG2InfiniteSustain, |
RgnInfo.EG2InfiniteSustain, |
560 |
uint(RgnInfo.EG2Sustain), |
(pNote && pNote->Override.CutoffSustain.Final) ? |
561 |
RgnInfo.EG2Release * egInfo.Release * velrelease, |
uint(pNote->Override.CutoffSustain.Value * 1000.f) : |
562 |
|
uint(RgnInfo.EG2Sustain), |
563 |
|
(pNote && pNote->Override.CutoffRelease.isFinal()) ? |
564 |
|
pNote->Override.CutoffRelease.Value : |
565 |
|
RgnInfo.EG2Release * egInfo.Release * velrelease, |
566 |
velocityAttenuation, |
velocityAttenuation, |
567 |
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
sampleRate / CONFIG_DEFAULT_SUBFRAGMENT_SIZE); |
568 |
} |
} |
604 |
return p; |
return p; |
605 |
} |
} |
606 |
|
|
607 |
|
release_trigger_t Voice::GetReleaseTriggerFlags() { |
608 |
|
release_trigger_t flags = |
609 |
|
(pRegion->NoNoteOffReleaseTrigger) ? |
610 |
|
release_trigger_none : release_trigger_noteoff; //HACK: currently this method is actually only called by EngineBase if it already knows that this voice requires release trigger, so I took the short way instead of checking (again) the existence of a ::gig::dimension_releasetrigger |
611 |
|
switch (pRegion->SustainReleaseTrigger) { |
612 |
|
case ::gig::sust_rel_trg_none: |
613 |
|
break; |
614 |
|
case ::gig::sust_rel_trg_maxvelocity: |
615 |
|
flags |= release_trigger_sustain_maxvelocity; |
616 |
|
break; |
617 |
|
case ::gig::sust_rel_trg_keyvelocity: |
618 |
|
flags |= release_trigger_sustain_keyvelocity; |
619 |
|
break; |
620 |
|
} |
621 |
|
return flags; |
622 |
|
} |
623 |
|
|
624 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |