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();
|
return freeVoice->get();
|
||||||
|
|
||||||
// Find voices that can be stolen
|
// Find voices that can be stolen
|
||||||
absl::c_sort(voiceViewArray, [](Voice* lhs, Voice* rhs) {
|
absl::c_sort(voiceViewArray, voiceOrdering);
|
||||||
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;
|
|
||||||
});
|
|
||||||
|
|
||||||
const auto sumEnvelope = absl::c_accumulate(voiceViewArray, 0.0f, [](float sum, const Voice* v) {
|
const auto sumEnvelope = absl::c_accumulate(voiceViewArray, 0.0f, [](float sum, const Voice* v) {
|
||||||
return sum + v->getAverageEnvelope();
|
return sum + v->getAverageEnvelope();
|
||||||
|
|
|
||||||
|
|
@ -162,13 +162,13 @@ public:
|
||||||
*
|
*
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
float getTriggerValue() const noexcept { return triggerValue; }
|
float getTriggerValue() const noexcept { return triggerValue; }
|
||||||
/**
|
/**
|
||||||
* @brief Get the type of trigger
|
* @brief Get the type of trigger
|
||||||
*
|
*
|
||||||
* @return TriggerType
|
* @return TriggerType
|
||||||
*/
|
*/
|
||||||
TriggerType getTriggerType() const noexcept { return triggerType; }
|
TriggerType getTriggerType() const noexcept { return triggerType; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reset the voice to its initial values
|
* @brief Reset the voice to its initial values
|
||||||
|
|
@ -271,7 +271,7 @@ private:
|
||||||
|
|
||||||
float speedRatio { 1.0 };
|
float speedRatio { 1.0 };
|
||||||
float pitchRatio { 1.0 };
|
float pitchRatio { 1.0 };
|
||||||
float baseVolumedB{ 0.0 };
|
float baseVolumedB { 0.0 };
|
||||||
float baseGain { 1.0 };
|
float baseGain { 1.0 };
|
||||||
float baseFrequency { 440.0 };
|
float baseFrequency { 440.0 };
|
||||||
|
|
||||||
|
|
@ -298,9 +298,9 @@ private:
|
||||||
|
|
||||||
// unison of oscillators
|
// unison of oscillators
|
||||||
unsigned waveUnisonSize { 0 };
|
unsigned waveUnisonSize { 0 };
|
||||||
float waveDetuneRatio[config::oscillatorsPerVoice] { };
|
float waveDetuneRatio[config::oscillatorsPerVoice] {};
|
||||||
float waveLeftGain[config::oscillatorsPerVoice] { };
|
float waveLeftGain[config::oscillatorsPerVoice] {};
|
||||||
float waveRightGain[config::oscillatorsPerVoice] { };
|
float waveRightGain[config::oscillatorsPerVoice] {};
|
||||||
|
|
||||||
Duration dataDuration;
|
Duration dataDuration;
|
||||||
Duration amplitudeDuration;
|
Duration amplitudeDuration;
|
||||||
|
|
@ -322,4 +322,27 @@ inline bool sisterVoices(const Voice* lhs, const Voice* rhs)
|
||||||
&& lhs->getTriggerType() == rhs->getTriggerType();
|
&& 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
|
} // namespace sfz
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue