Browse Source

Fix MPEChannelAssigner sometimes deregistering the wrong note

tags/2021-05-28
Agnieszka Janowicz ed 6 years ago
parent
commit
66bda18649
2 changed files with 23 additions and 6 deletions
  1. +19
    -5
      modules/juce_audio_basics/mpe/juce_MPEUtils.cpp
  2. +4
    -1
      modules/juce_audio_basics/mpe/juce_MPEUtils.h

+ 19
- 5
modules/juce_audio_basics/mpe/juce_MPEUtils.cpp View File

@@ -84,15 +84,29 @@ int MPEChannelAssigner::findMidiChannelForNewNote (int noteNumber) noexcept
return midiChannelLastAssigned;
}
void MPEChannelAssigner::noteOff (int noteNumber)
void MPEChannelAssigner::noteOff (int noteNumber, int midiChannel)
{
for (auto& ch : midiChannels)
const auto removeNote = [] (MidiChannel& ch, int noteNum)
{
if (ch.notes.removeAllInstancesOf (noteNumber) > 0)
if (ch.notes.removeAllInstancesOf (noteNum) > 0)
{
ch.lastNotePlayed = noteNumber;
return;
ch.lastNotePlayed = noteNum;
return true;
}
return false;
};
if (midiChannel >= 0 && midiChannel < 17)
{
removeNote (midiChannels[midiChannel], noteNumber);
return;
}
for (auto& ch : midiChannels)
{
if (removeNote (ch, noteNumber))
return;
}
}


+ 4
- 1
modules/juce_audio_basics/mpe/juce_MPEUtils.h View File

@@ -65,8 +65,11 @@ public:
/** You must call this method for all note-offs that you receive so that this class
can keep track of the currently playing notes internally.
You can specify the channel number the note off happened on. If you don't, it will
look through all channels to find the registered midi note matching the given note number.
*/
void noteOff (int noteNumber);
void noteOff (int noteNumber, int midiChannel = -1);
/** Call this to clear all currently playing notes. */
void allNotesOff();


Loading…
Cancel
Save