diff --git a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp index 6a889b4b32..81110ed9f8 100644 --- a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp +++ b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.cpp @@ -50,6 +50,11 @@ void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate) currentSampleRate = newRate; } +bool SynthesiserVoice::isVoiceActive() const +{ + return getCurrentlyPlayingNote() >= 0; +} + void SynthesiserVoice::clearCurrentNote() { currentlyPlayingNote = -1; @@ -426,7 +431,7 @@ SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay, { SynthesiserVoice* const voice = voices.getUnchecked (i); - if (voice->getCurrentlyPlayingNote() < 0 && voice->canPlaySound (soundToPlay)) + if ((! voice->isVoiceActive()) && voice->canPlaySound (soundToPlay)) return voice; } diff --git a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h index 6a32cedaa0..3c20a85302 100644 --- a/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h +++ b/modules/juce_audio_basics/synthesisers/juce_Synthesiser.h @@ -140,6 +140,12 @@ public: */ virtual void stopNote (float velocity, bool allowTailOff) = 0; + /** Returns true if this voice is currently busy playing a sound. + By default this just checks the getCurrentlyPlayingNote() value, but can + be overridden for more advanced checking. + */ + virtual bool isVoiceActive() const; + /** Called to let the voice know that the pitch wheel has been moved. This will be called during the rendering callback, so must be fast and thread-safe. */