From d124a1a17e902f3035a3ca4a47d4e95f92f814aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=84=A1=E5=B8=B8?= <3142324836@qq.com> Date: Thu, 7 Nov 2024 22:55:20 +0800 Subject: [PATCH] Update MidiMessageSequence::updateMatchedPairs to deal with note-on messages with velocity 0 --- .../juce_audio_basics/midi/juce_MidiMessageSequence.cpp | 8 ++++---- modules/juce_audio_basics/midi/juce_MidiMessageSequence.h | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp index fc47e0eb47d1..05874ccf9754 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp +++ b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp @@ -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(); @@ -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); diff --git a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h index 8e19d03d3ec9..1c289a78c587 100644 --- a/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h +++ b/modules/juce_audio_basics/midi/juce_MidiMessageSequence.h @@ -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