Add support for group polyphony

This commit is contained in:
Paul Ferrand 2020-03-29 00:23:26 +01:00
parent 5c5dd07da1
commit fbb1cc9efc
2 changed files with 10 additions and 6 deletions

View file

@ -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;
}

View file

@ -417,8 +417,7 @@ private:
* @param polyphone the max polyphony
*/
void setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexcept;
std::vector<unsigned> groupPolyphony;
std::vector<unsigned> groupMaxPolyphony;
std::vector<unsigned> groupMaxPolyphony { config::maxVoices };
/**
* @brief Reset all CCs; to be used on CC 121