Move the voice ordering as a free function
This commit is contained in:
parent
6df5b217c9
commit
59c25dccf1
2 changed files with 30 additions and 27 deletions
|
|
@ -482,27 +482,7 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
|||
return freeVoice->get();
|
||||
|
||||
// Find voices that can be stolen
|
||||
absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) {
|
||||
if (lhs->getAge() > rhs->getAge())
|
||||
return true;
|
||||
if (lhs->getAge() < rhs->getAge())
|
||||
return false;
|
||||
|
||||
if (lhs->getTriggerNumber() > rhs->getTriggerNumber())
|
||||
return true;
|
||||
if (lhs->getTriggerNumber() < rhs->getTriggerNumber())
|
||||
return false;
|
||||
|
||||
if (lhs->getTriggerValue() > rhs->getTriggerValue())
|
||||
return true;
|
||||
if (lhs->getTriggerValue() < rhs->getTriggerValue())
|
||||
return false;
|
||||
|
||||
if (lhs->getTriggerType() > rhs->getTriggerType())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
});
|
||||
absl::c_sort(voiceViewArray, voiceOrdering);
|
||||
|
||||
const auto sumEnvelope = absl::c_accumulate(voiceViewArray, 0.0f, [](float sum, const Voice* v) {
|
||||
return sum + v->getAverageEnvelope();
|
||||
|
|
|
|||
|
|
@ -162,13 +162,13 @@ public:
|
|||
*
|
||||
* @return float
|
||||
*/
|
||||
float getTriggerValue() const noexcept { return triggerValue; }
|
||||
float getTriggerValue() const noexcept { return triggerValue; }
|
||||
/**
|
||||
* @brief Get the type of trigger
|
||||
*
|
||||
* @return TriggerType
|
||||
*/
|
||||
TriggerType getTriggerType() const noexcept { return triggerType; }
|
||||
TriggerType getTriggerType() const noexcept { return triggerType; }
|
||||
|
||||
/**
|
||||
* @brief Reset the voice to its initial values
|
||||
|
|
@ -271,7 +271,7 @@ private:
|
|||
|
||||
float speedRatio { 1.0 };
|
||||
float pitchRatio { 1.0 };
|
||||
float baseVolumedB{ 0.0 };
|
||||
float baseVolumedB { 0.0 };
|
||||
float baseGain { 1.0 };
|
||||
float baseFrequency { 440.0 };
|
||||
|
||||
|
|
@ -298,9 +298,9 @@ private:
|
|||
|
||||
// unison of oscillators
|
||||
unsigned waveUnisonSize { 0 };
|
||||
float waveDetuneRatio[config::oscillatorsPerVoice] { };
|
||||
float waveLeftGain[config::oscillatorsPerVoice] { };
|
||||
float waveRightGain[config::oscillatorsPerVoice] { };
|
||||
float waveDetuneRatio[config::oscillatorsPerVoice] {};
|
||||
float waveLeftGain[config::oscillatorsPerVoice] {};
|
||||
float waveRightGain[config::oscillatorsPerVoice] {};
|
||||
|
||||
Duration dataDuration;
|
||||
Duration amplitudeDuration;
|
||||
|
|
@ -322,4 +322,27 @@ inline bool sisterVoices(const Voice* lhs, const Voice* rhs)
|
|||
&& lhs->getTriggerType() == rhs->getTriggerType();
|
||||
}
|
||||
|
||||
inline bool voiceOrdering(const Voice* lhs, const Voice* rhs)
|
||||
{
|
||||
if (lhs->getAge() > rhs->getAge())
|
||||
return true;
|
||||
if (lhs->getAge() < rhs->getAge())
|
||||
return false;
|
||||
|
||||
if (lhs->getTriggerNumber() > rhs->getTriggerNumber())
|
||||
return true;
|
||||
if (lhs->getTriggerNumber() < rhs->getTriggerNumber())
|
||||
return false;
|
||||
|
||||
if (lhs->getTriggerValue() > rhs->getTriggerValue())
|
||||
return true;
|
||||
if (lhs->getTriggerValue() < rhs->getTriggerValue())
|
||||
return false;
|
||||
|
||||
if (lhs->getTriggerType() > rhs->getTriggerType())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace sfz
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue