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(); masterOpcodes.clear();
groupOpcodes.clear(); groupOpcodes.clear();
unknownOpcodes.clear(); unknownOpcodes.clear();
groupPolyphony.clear();
groupMaxPolyphony.clear(); groupMaxPolyphony.clear();
groupMaxPolyphony.push_back(config::maxVoices);
modificationTime = fs::file_time_type::min(); 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); const auto randValue = randNoteDistribution(Random::randomGenerator);
for (auto& region : noteActivationLists[noteNumber]) { for (auto& region : noteActivationLists[noteNumber]) {
if (region->registerNoteOn(noteNumber, velocity, randValue)) { if (region->registerNoteOn(noteNumber, velocity, randValue)) {
auto activeNotesInGroup = 0;
for (auto& voice : voices) { for (auto& voice : voices) {
if (voice->getRegion()->group == region->group)
activeNotesInGroup += 1;
if (voice->checkOffGroup(delay, region->group)) if (voice->checkOffGroup(delay, region->group))
noteOffDispatch(delay, voice->getTriggerNumber(), voice->getTriggerValue()); noteOffDispatch(delay, voice->getTriggerNumber(), voice->getTriggerValue());
} }
if (activeNotesInGroup >= groupMaxPolyphony[region->group])
continue;
auto voice = findFreeVoice(); auto voice = findFreeVoice();
if (voice == nullptr) if (voice == nullptr)
continue; continue;
@ -1039,8 +1047,5 @@ void sfz::Synth::setGroupPolyphony(unsigned groupIdx, unsigned polyphony) noexce
if (groupIdx >= groupMaxPolyphony.size()) if (groupIdx >= groupMaxPolyphony.size())
groupMaxPolyphony.resize(groupIdx + 1); groupMaxPolyphony.resize(groupIdx + 1);
if (groupIdx >= groupPolyphony.size())
groupPolyphony.resize(groupIdx + 1);
groupMaxPolyphony[groupIdx] = polyphony; groupMaxPolyphony[groupIdx] = polyphony;
} }

View file

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