Add helpers to count playing voices in polyphony groups

This commit is contained in:
Paul Ferrand 2020-08-10 17:09:58 +02:00
parent 5ef6141c4b
commit 2cdf4f165f
4 changed files with 22 additions and 0 deletions

View file

@ -16,3 +16,10 @@ void sfz::PolyphonyGroup::removeVoice(const Voice* voice) noexcept
{ {
swapAndPopFirst(voices, [voice](const Voice* v) { return v == voice; }); swapAndPopFirst(voices, [voice](const Voice* v) { return v == voice; });
} }
unsigned sfz::PolyphonyGroup::numPlayingVoices() const noexcept
{
return absl::c_count_if(voices, [](const Voice* v) {
return !v->releasedOrFree();
});
}

View file

@ -40,6 +40,10 @@ public:
* @return unsigned * @return unsigned
*/ */
unsigned getPolyphonyLimit() const noexcept { return polyphonyLimit; } unsigned getPolyphonyLimit() const noexcept { return polyphonyLimit; }
/**
* @brief Returns the number of playing (unreleased) voices
*/
unsigned numPlayingVoices() const noexcept;
/** /**
* @brief Get the active voices * @brief Get the active voices
* *

View file

@ -46,3 +46,10 @@ void sfz::RegionSet::removeVoiceFromHierarchy(const Region* region, const Voice*
parent = parent->getParent(); parent = parent->getParent();
} }
} }
unsigned sfz::RegionSet::numPlayingVoices() const noexcept
{
return absl::c_count_if(voices, [](const Voice* v) {
return !v->releasedOrFree();
});
}

View file

@ -79,6 +79,10 @@ public:
* @param parent * @param parent
*/ */
void setParent(RegionSet* parent) noexcept { this->parent = parent; } void setParent(RegionSet* parent) noexcept { this->parent = parent; }
/**
* @brief Returns the number of playing (unreleased) voices
*/
unsigned numPlayingVoices() const noexcept;
/** /**
* @brief Get the active voices * @brief Get the active voices
* *