Rewrite the ring builder simpler, and add assertion
This commit is contained in:
parent
dafde79560
commit
6d692ba5be
2 changed files with 17 additions and 21 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Voice.h"
|
#include "Voice.h"
|
||||||
|
#include "Debug.h"
|
||||||
#include "absl/meta/type_traits.h"
|
#include "absl/meta/type_traits.h"
|
||||||
|
|
||||||
namespace sfz
|
namespace sfz
|
||||||
|
|
@ -135,31 +136,20 @@ public:
|
||||||
* @param voice
|
* @param voice
|
||||||
*/
|
*/
|
||||||
void addVoiceToRing(Voice* voice) noexcept {
|
void addVoiceToRing(Voice* voice) noexcept {
|
||||||
if (firstStartedVoice == nullptr)
|
ASSERT(!voice->isInSisterRing());
|
||||||
firstStartedVoice = voice;
|
|
||||||
|
|
||||||
firstStartedVoice->setPreviousSisterVoice(voice);
|
Voice* next = head_;
|
||||||
voice->setNextSisterVoice(firstStartedVoice);
|
if (!next)
|
||||||
|
head_ = next = voice;
|
||||||
|
|
||||||
if (lastStartedVoice != nullptr) {
|
Voice* previous = next->getPreviousSisterVoice();
|
||||||
voice->setPreviousSisterVoice(lastStartedVoice);
|
voice->setNextSisterVoice(next);
|
||||||
lastStartedVoice->setNextSisterVoice(voice);
|
voice->setPreviousSisterVoice(previous);
|
||||||
|
next->setPreviousSisterVoice(voice);
|
||||||
|
previous->setNextSisterVoice(voice);
|
||||||
}
|
}
|
||||||
|
|
||||||
lastStartedVoice = voice;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @brief Apply a function to the sister ring, including the current voice.
|
|
||||||
* This function should be safe enough to even reset the sister voices, but
|
|
||||||
* if you mutate the ring significantly you should probably roll your own
|
|
||||||
* iterator.
|
|
||||||
*
|
|
||||||
* @param lambda the function to apply.
|
|
||||||
* @param voice the starting voice
|
|
||||||
*/
|
|
||||||
private:
|
private:
|
||||||
Voice* firstStartedVoice { nullptr };
|
Voice* head_ { nullptr };
|
||||||
Voice* lastStartedVoice { nullptr };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -382,6 +382,12 @@ public:
|
||||||
*/
|
*/
|
||||||
const TriggerEvent& getTriggerEvent();
|
const TriggerEvent& getTriggerEvent();
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Check if the voice already belongs to a sister ring
|
||||||
|
*/
|
||||||
|
bool isInSisterRing() const noexcept { return this != nextSisterVoice_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Impl;
|
struct Impl;
|
||||||
std::unique_ptr<Impl> impl_;
|
std::unique_ptr<Impl> impl_;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue