Skip to content

Commit d124a1a

Browse files
Update MidiMessageSequence::updateMatchedPairs to deal with note-on messages with velocity 0
1 parent 5179f4e commit d124a1a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

modules/juce_audio_basics/midi/juce_MidiMessageSequence.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ void MidiMessageSequence::sort() noexcept
235235
[] (const MidiEventHolder* a, const MidiEventHolder* b) { return a->message.getTimeStamp() < b->message.getTimeStamp(); });
236236
}
237237

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

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

257257
if (m.getNoteNumber() == note && m.getChannel() == chan)
258258
{
259-
if (m.isNoteOff())
259+
if (m.isNoteOff(regardNoteOnEventsWithVel0AsNoteOff))
260260
{
261261
meh->noteOffObject = meh2;
262262
break;
263263
}
264264

265-
if (m.isNoteOn())
265+
if (m.isNoteOn(!regardNoteOnEventsWithVel0AsNoteOff))
266266
{
267267
auto newEvent = new MidiEventHolder (MidiMessage::noteOff (chan, note));
268268
list.insert (j, newEvent);

modules/juce_audio_basics/midi/juce_MidiMessageSequence.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,11 @@ class JUCE_API MidiMessageSequence
230230
Call this after re-ordering messages or deleting/adding messages, and it
231231
will scan the list and make sure all the note-offs in the MidiEventHolder
232232
structures are pointing at the correct ones.
233+
234+
@param regardNoteOnEventWithVel0AsNoteOff if true, note-on events with velocity 0
235+
will be regarded as note-off
233236
*/
234-
void updateMatchedPairs() noexcept;
237+
void updateMatchedPairs(bool regardNoteOnEventsWithVel0AsNoteOff = true) noexcept;
235238

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

0 commit comments

Comments
 (0)