diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index fd25c42e..18a82f8d 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -157,8 +157,8 @@ void sfz::Synth::clear() masterOpcodes.clear(); groupOpcodes.clear(); unknownOpcodes.clear(); - groupPolyphony.clear(); groupMaxPolyphony.clear(); + groupMaxPolyphony.push_back(config::maxVoices); modificationTime = fs::file_time_type::min(); } @@ -682,11 +682,19 @@ 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; + for (auto& voice : voices) { + if (voice->getRegion()->group == region->group) + activeNotesInGroup += 1; + if (voice->checkOffGroup(delay, region->group)) noteOffDispatch(delay, voice->getTriggerNumber(), voice->getTriggerValue()); } + if (activeNotesInGroup >= groupMaxPolyphony[region->group]) + continue; + auto voice = findFreeVoice(); if (voice == nullptr) continue; @@ -1039,8 +1047,5 @@ void sfz::Synth::setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexce if (groupIdx >= groupMaxPolyphony.size()) groupMaxPolyphony.resize(groupIdx + 1); - if (groupIdx >= groupPolyphony.size()) - groupPolyphony.resize(groupIdx + 1); - groupMaxPolyphony[groupIdx] = polyphony; } diff --git a/src/sfizz/Synth.h b/src/sfizz/Synth.h index e0c5390e..2eded30a 100644 --- a/src/sfizz/Synth.h +++ b/src/sfizz/Synth.h @@ -417,8 +417,7 @@ private: * @param polyphone the max polyphony */ void setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexcept; - std::vector groupPolyphony; - std::vector groupMaxPolyphony; + std::vector groupMaxPolyphony { config::maxVoices }; /** * @brief Reset all CCs; to be used on CC 121