const MPENote* MPEInstrument::getLastNotePlayedPtr (int midiChannel) const noexcept
{
const ScopedLock sl (lock);
for (auto i = notes.size(); --i >= 0;)
{
auto& note = notes.getReference (i);
if (note.midiChannel == midiChannel
&& (note.keyState == MPENote::keyDown || note.keyState == MPENote::keyDownAndSustained))
return ¬e;
}
return nullptr;
}
This implementation should be looking at MPENote::noteId to make sure that the note it’s returning is actually the last note played on a given channel … but obs it does not.
This will usually work anyway, because having more than one note played per channel is unusual in MPE.
Since new notes are add()-ed at the end of MPEInstrument::notes, this algorithm will (usually) return the first note played on a channel, not the last, if there is more than one.
