diff --git a/src/sfizz/PolyphonyGroup.cpp b/src/sfizz/PolyphonyGroup.cpp index 7ac1e3d6..d5b1615c 100644 --- a/src/sfizz/PolyphonyGroup.cpp +++ b/src/sfizz/PolyphonyGroup.cpp @@ -16,3 +16,10 @@ void sfz::PolyphonyGroup::removeVoice(const Voice* voice) noexcept { 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(); + }); +} diff --git a/src/sfizz/PolyphonyGroup.h b/src/sfizz/PolyphonyGroup.h index d3e1413b..7a4281af 100644 --- a/src/sfizz/PolyphonyGroup.h +++ b/src/sfizz/PolyphonyGroup.h @@ -40,6 +40,10 @@ public: * @return unsigned */ unsigned getPolyphonyLimit() const noexcept { return polyphonyLimit; } + /** + * @brief Returns the number of playing (unreleased) voices + */ + unsigned numPlayingVoices() const noexcept; /** * @brief Get the active voices * diff --git a/src/sfizz/RegionSet.cpp b/src/sfizz/RegionSet.cpp index d6f8a585..1387438a 100644 --- a/src/sfizz/RegionSet.cpp +++ b/src/sfizz/RegionSet.cpp @@ -46,3 +46,10 @@ void sfz::RegionSet::removeVoiceFromHierarchy(const Region* region, const Voice* parent = parent->getParent(); } } + +unsigned sfz::RegionSet::numPlayingVoices() const noexcept +{ + return absl::c_count_if(voices, [](const Voice* v) { + return !v->releasedOrFree(); + }); +} diff --git a/src/sfizz/RegionSet.h b/src/sfizz/RegionSet.h index 24120173..bbfadce0 100644 --- a/src/sfizz/RegionSet.h +++ b/src/sfizz/RegionSet.h @@ -79,6 +79,10 @@ public: * @param 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 *