Browse Source

MPE: Set the note-on time of MPESynthesiserVoice correctly

tags/2021-05-28
ed 7 years ago
parent
commit
32e6528508
4 changed files with 7 additions and 10 deletions
  1. +4
    -1
      modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp
  2. +1
    -0
      modules/juce_audio_basics/mpe/juce_MPESynthesiser.h
  3. +0
    -5
      modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.cpp
  4. +2
    -4
      modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.h

+ 4
- 1
modules/juce_audio_basics/mpe/juce_MPESynthesiser.cpp View File

@@ -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());


+ 1
- 0
modules/juce_audio_basics/mpe/juce_MPESynthesiser.h View File

@@ -304,6 +304,7 @@ protected:
private:
//==============================================================================
bool shouldStealVoices = false;
uint32 lastNoteOnCounter = 0;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPESynthesiser)
};


+ 0
- 5
modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.cpp View File

@@ -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();


+ 2
- 4
modules/juce_audio_basics/mpe/juce_MPESynthesiserVoice.h View File

@@ -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)
};


Loading…
Cancel
Save