move findFreeVoice to the voiceList
This commit is contained in:
parent
1fcfbdbaf7
commit
4aeb12446e
2 changed files with 24 additions and 22 deletions
|
|
@ -170,14 +170,6 @@ struct Synth::Impl: public Parser::Listener {
|
||||||
*/
|
*/
|
||||||
void ccDispatch(int delay, int ccNumber, float value) noexcept;
|
void ccDispatch(int delay, int ccNumber, float value) noexcept;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Find a voice that is not currently playing
|
|
||||||
*
|
|
||||||
* @return Voice*
|
|
||||||
*/
|
|
||||||
|
|
||||||
Voice* findFreeVoice() noexcept;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start a voice for a specific region.
|
* @brief Start a voice for a specific region.
|
||||||
* This will do the needed polyphony checks and voice stealing.
|
* This will do the needed polyphony checks and voice stealing.
|
||||||
|
|
@ -1056,19 +1048,6 @@ void Synth::loadStretchTuningByRatio(float ratio)
|
||||||
impl.resources_.stretch.reset();
|
impl.resources_.stretch.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Voice* Synth::Impl::findFreeVoice() noexcept
|
|
||||||
{
|
|
||||||
auto freeVoice = absl::c_find_if(voiceList_, [](const Voice& voice) {
|
|
||||||
return voice.isFree();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (freeVoice != voiceList_.end())
|
|
||||||
return &*freeVoice;
|
|
||||||
|
|
||||||
DBG("Engine hard polyphony reached");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
int Synth::getNumActiveVoices() const noexcept
|
int Synth::getNumActiveVoices() const noexcept
|
||||||
{
|
{
|
||||||
Impl& impl = *impl_;
|
Impl& impl = *impl_;
|
||||||
|
|
@ -1279,7 +1258,7 @@ void Synth::noteOff(int delay, int noteNumber, uint8_t velocity) noexcept
|
||||||
void Synth::Impl::startVoice(Region* region, int delay, const TriggerEvent& triggerEvent, SisterVoiceRingBuilder& ring) noexcept
|
void Synth::Impl::startVoice(Region* region, int delay, const TriggerEvent& triggerEvent, SisterVoiceRingBuilder& ring) noexcept
|
||||||
{
|
{
|
||||||
voiceList_.checkPolyphony(region, delay, triggerEvent);
|
voiceList_.checkPolyphony(region, delay, triggerEvent);
|
||||||
Voice* selectedVoice = findFreeVoice();
|
Voice* selectedVoice = voiceList_.findFreeVoice();
|
||||||
if (selectedVoice == nullptr)
|
if (selectedVoice == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,11 +155,34 @@ struct VoiceList : public Voice::StateListener
|
||||||
checkEnginePolyphony(delay);
|
checkEnginePolyphony(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the number of active voices
|
||||||
|
*
|
||||||
|
* @return unsigned
|
||||||
|
*/
|
||||||
unsigned getNumActiveVoices() const
|
unsigned getNumActiveVoices() const
|
||||||
{
|
{
|
||||||
return activeVoices_.size();
|
return activeVoices_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Find a voice that is not currently playing
|
||||||
|
*
|
||||||
|
* @return Voice*
|
||||||
|
*/
|
||||||
|
Voice* findFreeVoice() noexcept
|
||||||
|
{
|
||||||
|
auto freeVoice = absl::c_find_if(list_, [](const Voice& voice) {
|
||||||
|
return voice.isFree();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (freeVoice != list_.end())
|
||||||
|
return &*freeVoice;
|
||||||
|
|
||||||
|
DBG("Engine hard polyphony reached");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Voice> list_;
|
std::vector<Voice> list_;
|
||||||
std::vector<Voice*> activeVoices_;
|
std::vector<Voice*> activeVoices_;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue