diff --git a/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp b/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp index ea0028e477..fc76d407a3 100644 --- a/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp @@ -42,13 +42,16 @@ MPESynthesiser::~MPESynthesiser() void MPESynthesiser::startVoice (MPESynthesiserVoice* voice, MPENote noteToStart) { jassert (voice != nullptr); + voice->currentlyPlayingNote = noteToStart; + voice->noteOnTime = lastNoteOnCounter++; voice->noteStarted(); } void MPESynthesiser::stopVoice (MPESynthesiserVoice* voice, MPENote noteToStop, bool allowTailOff) { jassert (voice != nullptr); + voice->currentlyPlayingNote = noteToStop; voice->noteStopped (allowTailOff); } @@ -197,7 +200,7 @@ MPESynthesiserVoice* MPESynthesiser::findVoiceToSteal (MPENote noteToStealVoiceF // compilers generating code containing heap allocations.. struct Sorter { - bool operator() (const MPESynthesiserVoice* a, const MPESynthesiserVoice* b) const noexcept { return a->wasStartedBefore (*b); } + bool operator() (const MPESynthesiserVoice* a, const MPESynthesiserVoice* b) const noexcept { return a->noteOnTime < b->noteOnTime; } }; std::sort (usableVoices.begin(), usableVoices.end(), Sorter()); diff --git a/modules/juce_audio_basics/mpe/juce_MPESynthesiser.h b/modules/juce_audio_basics/mpe/juce_MPESynthesiser.h index d30269375f..c49bbcdeb6 100644 --- a/modules/juce_audio_basics/mpe/juce_MPESynthesiser.h +++ b/modules/juce_audio_basics/mpe/juce_MPESynthesiser.h @@ -304,6 +304,7 @@ protected: private: //============================================================================== bool shouldStealVoices = false; + uint32 lastNoteOnCounter = 0; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPESynthesiser) }; diff --git a/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.cpp b/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.cpp index 5cb03eee50..b20e13d661 100644 --- a/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.cpp @@ -42,11 +42,6 @@ bool MPESynthesiserVoice::isPlayingButReleased() const noexcept return isActive() && currentlyPlayingNote.keyState == MPENote::off; } -bool MPESynthesiserVoice::wasStartedBefore (const MPESynthesiserVoice& other) const noexcept -{ - return noteStartTime < other.noteStartTime; -} - void MPESynthesiserVoice::clearCurrentNote() noexcept { currentlyPlayingNote = MPENote(); diff --git a/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.h b/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.h index f1603d5f44..6414e8d397 100644 --- a/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.h +++ b/modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.h @@ -156,9 +156,6 @@ public: */ double getSampleRate() const noexcept { return currentSampleRate; } - /** Returns true if this voice started playing its current note before the other voice did. */ - bool wasStartedBefore (const MPESynthesiserVoice& other) const noexcept; - protected: //============================================================================== /** Resets the state of this voice after a sound has finished playing. @@ -182,7 +179,8 @@ protected: private: //============================================================================== friend class MPESynthesiser; - uint32 noteStartTime = 0; + + uint32 noteOnTime = 0; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPESynthesiserVoice) };