From 42720109a7df1ce415f089b12d5654526ace9582 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Sun, 29 Mar 2020 00:48:47 +0100 Subject: [PATCH] Correct a bug if a region has a group number but no group-level polyphony setting --- src/sfizz/Synth.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 18a82f8d..34ef2472 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -398,6 +398,10 @@ bool sfz::Synth::loadSfzFile(const fs::path& file) } } + // Some regions had group number but no "group-level" opcodes handled the polyphony + while (groupMaxPolyphony.size() <= region->group) + groupMaxPolyphony.push_back(config::maxVoices); + for (auto note = 0; note < 128; note++) { if (region->keyRange.containsWithEnd(note) || (region->hasKeyswitches() && region->keyswitchRange.containsWithEnd(note))) noteActivationLists[note].push_back(region); @@ -682,10 +686,14 @@ void sfz::Synth::noteOnDispatch(int delay, int noteNumber, float velocity) noexc const auto randValue = randNoteDistribution(Random::randomGenerator); for (auto& region : noteActivationLists[noteNumber]) { if (region->registerNoteOn(noteNumber, velocity, randValue)) { - auto activeNotesInGroup = 0; + unsigned activeNotesInGroup { 0 }; for (auto& voice : voices) { - if (voice->getRegion()->group == region->group) + const auto voiceRegion = voice->getRegion(); + if (voiceRegion == nullptr) + continue; + + if (voiceRegion->group == region->group) activeNotesInGroup += 1; if (voice->checkOffGroup(delay, region->group)) @@ -1044,8 +1052,8 @@ void sfz::Synth::allSoundOff() noexcept void sfz::Synth::setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexcept { - if (groupIdx >= groupMaxPolyphony.size()) - groupMaxPolyphony.resize(groupIdx + 1); + while (groupMaxPolyphony.size() <= groupIdx) + groupMaxPolyphony.push_back(config::maxVoices); groupMaxPolyphony[groupIdx] = polyphony; }