Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MidiMessageSequence::updateMatchedPairs to deal with note-on messages with velocity 0 #1468

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ void MidiMessageSequence::sort() noexcept
[] (const MidiEventHolder* a, const MidiEventHolder* b) { return a->message.getTimeStamp() < b->message.getTimeStamp(); });
}

void MidiMessageSequence::updateMatchedPairs() noexcept
void MidiMessageSequence::updateMatchedPairs(bool regardNoteOnEventsWithVel0AsNoteOff) noexcept
{
for (int i = 0; i < list.size(); ++i)
{
auto* meh = list.getUnchecked (i);
auto& m1 = meh->message;

if (m1.isNoteOn())
if (m1.isNoteOn(!regardNoteOnEventsWithVel0AsNoteOff))
{
meh->noteOffObject = nullptr;
auto note = m1.getNoteNumber();
Expand All @@ -256,13 +256,13 @@ void MidiMessageSequence::updateMatchedPairs() noexcept

if (m.getNoteNumber() == note && m.getChannel() == chan)
{
if (m.isNoteOff())
if (m.isNoteOff(regardNoteOnEventsWithVel0AsNoteOff))
{
meh->noteOffObject = meh2;
break;
}

if (m.isNoteOn())
if (m.isNoteOn(!regardNoteOnEventsWithVel0AsNoteOff))
{
auto newEvent = new MidiEventHolder (MidiMessage::noteOff (chan, note));
list.insert (j, newEvent);
Expand Down
5 changes: 4 additions & 1 deletion modules/juce_audio_basics/midi/juce_MidiMessageSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ class JUCE_API MidiMessageSequence
Call this after re-ordering messages or deleting/adding messages, and it
will scan the list and make sure all the note-offs in the MidiEventHolder
structures are pointing at the correct ones.

@param regardNoteOnEventWithVel0AsNoteOff if true, note-on events with velocity 0
will be regarded as note-off
*/
void updateMatchedPairs() noexcept;
void updateMatchedPairs(bool regardNoteOnEventsWithVel0AsNoteOff = true) noexcept;

/** Forces a sort of the sequence.
You may need to call this if you've manually modified the timestamps of some
Expand Down