Move the delayed release check in a separate method

This commit is contained in:
Paul Ferrand 2020-08-25 21:39:33 +02:00
parent 944373ea83
commit 01c43f03d4
2 changed files with 26 additions and 23 deletions

View file

@ -1044,7 +1044,6 @@ void sfz::Synth::noteOnDispatch(int delay, int noteNumber, float velocity) noexc
for (auto& region : noteActivationLists[noteNumber]) { for (auto& region : noteActivationLists[noteNumber]) {
if (region->registerNoteOn(noteNumber, velocity, randValue)) { if (region->registerNoteOn(noteNumber, velocity, randValue)) {
for (auto& voice : voices) { for (auto& voice : voices) {
if (voice->checkOffGroup(delay, region->group)) { if (voice->checkOffGroup(delay, region->group)) {
const TriggerEvent& event = voice->getTriggerEvent(); const TriggerEvent& event = voice->getTriggerEvent();
@ -1057,6 +1056,28 @@ void sfz::Synth::noteOnDispatch(int delay, int noteNumber, float velocity) noexc
} }
} }
void sfz::Synth::checkDelayedReleases(Region* region, int delay, SisterVoiceRingBuilder& ring) noexcept
{
if (!region->rtDead) {
// check that a voice with compatible trigger is playing
const auto compatibleVoice = [region](const VoicePtr& v) -> bool {
return matchReleaseRegionAndVoice(*region, *v);
};
if (absl::c_find_if(voices, compatibleVoice) == voices.end())
region->delayedReleases.clear();
}
for (auto& note: region->delayedReleases) {
// FIXME: we really need to have some form of common method to find and start voices...
const TriggerEvent noteOffEvent { TriggerEventType::NoteOff, note.first, note.second };
startVoice(region, delay, noteOffEvent, ring);
}
region->delayedReleases.clear();
}
void sfz::Synth::cc(int delay, int ccNumber, uint8_t ccValue) noexcept void sfz::Synth::cc(int delay, int ccNumber, uint8_t ccValue) noexcept
{ {
const auto normalizedCC = normalizeCC(ccValue); const auto normalizedCC = normalizeCC(ccValue);
@ -1092,32 +1113,13 @@ void sfz::Synth::hdcc(int delay, int ccNumber, float normValue) noexcept
SisterVoiceRingBuilder ring; SisterVoiceRingBuilder ring;
const TriggerEvent triggerEvent { TriggerEventType::CC, ccNumber, normValue }; const TriggerEvent triggerEvent { TriggerEventType::CC, ccNumber, normValue };
for (auto& region : ccActivationLists[ccNumber]) { for (auto& region : ccActivationLists[ccNumber]) {
if (ccNumber == region->sustainCC) { if (ccNumber == region->sustainCC)
if (!region->rtDead) { checkDelayedReleases(region, delay, ring);
// check that a voice with compatible trigger is playing
const auto compatibleVoice = [region](const VoicePtr& v) -> bool {
return matchReleaseRegionAndVoice(*region, *v);
};
if (absl::c_find_if(voices, compatibleVoice) == voices.end()) if (region->registerCC(ccNumber, normValue))
region->delayedReleases.clear();
}
for (auto& note: region->delayedReleases) {
// FIXME: we really need to have some form of common method to find and start voices...
const TriggerEvent noteOffEvent { TriggerEventType::NoteOff, note.first, note.second };
startVoice(region, delay, noteOffEvent, ring);
}
region->delayedReleases.clear();
}
if (region->registerCC(ccNumber, normValue)) {
startVoice(region, delay, triggerEvent, ring); startVoice(region, delay, triggerEvent, ring);
} }
}
} }
void sfz::Synth::pitchWheel(int delay, int pitch) noexcept void sfz::Synth::pitchWheel(int delay, int pitch) noexcept

View file

@ -785,6 +785,7 @@ private:
void checkGroupPolyphony(const Region* region, int delay) noexcept; void checkGroupPolyphony(const Region* region, int delay) noexcept;
void checkSetPolyphony(const Region* region, int delay) noexcept; void checkSetPolyphony(const Region* region, int delay) noexcept;
void startVoice(Region* region, int delay, const TriggerEvent& triggerEvent, SisterVoiceRingBuilder& ring) noexcept; void startVoice(Region* region, int delay, const TriggerEvent& triggerEvent, SisterVoiceRingBuilder& ring) noexcept;
void checkDelayedReleases(Region* region, int delay, SisterVoiceRingBuilder& ring) noexcept;
std::array<RegionViewVector, 128> noteActivationLists; std::array<RegionViewVector, 128> noteActivationLists;
std::array<RegionViewVector, config::numCCs> ccActivationLists; std::array<RegionViewVector, config::numCCs> ccActivationLists;