Add a helper for playing voices

This commit is contained in:
Paul Ferrand 2020-08-19 00:47:31 +02:00
parent 95165ca650
commit 80aee5a9cd
2 changed files with 20 additions and 0 deletions

View file

@ -51,6 +51,17 @@ const std::vector<const sfz::Voice*> getActiveVoices(const sfz::Synth& synth)
return activeVoices;
}
const std::vector<const sfz::Voice*> getPlayingVoices(const sfz::Synth& synth)
{
std::vector<const sfz::Voice*> playingVoices;
for (int i = 0; i < synth.getNumVoices(); ++i) {
const auto* voice = synth.getVoiceView(i);
if (!voice->releasedOrFree())
playingVoices.push_back(voice);
}
return playingVoices;
}
unsigned numPlayingVoices(const sfz::Synth& synth)
{
return absl::c_count_if(getActiveVoices(synth), [](const sfz::Voice* v) {

View file

@ -49,6 +49,15 @@ void sortAll(C& container, Args&... others)
*/
const std::vector<const sfz::Voice*> getActiveVoices(const sfz::Synth& synth);
/**
* @brief Get playing (unreleased) voices from the synth
*
* @param synth
* @return const std::vector<const sfz::Voice*>
*/
const std::vector<const sfz::Voice*> getPlayingVoices(const sfz::Synth& synth);
/**
* @brief Count the number of playing (unreleased) voices from the synth
*