From f4da0ff76d17a2b3ed50f0e4ceb46121e07a0400 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 6 Aug 2025 04:56:01 +0200 Subject: [PATCH] Fix MIDI panic timestamp at cycle-end Previousy stopping, locating or looping in the middle of an active MIDI note would generate unordered MIDI events on the port. "it's too late for this event". Usually caused by the MIDI state tracker adding a Note-Off at cycle end and then MidiPort::resolve_notes adding a panic message at cycle-start... --- libs/ardour/midi_port.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index 2d7d82833e..ed93667b75 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -273,10 +273,13 @@ MidiPort::flush_buffers (pframes_t nframes) void* port_buffer = 0; - if (_resolve_required) { + if (_resolve_required && (_global_port_buffer_offset + nframes) > 0) { port_buffer = port_engine.get_buffer (_port_handle, nframes); - /* resolve all notes at the start of the buffer */ - resolve_notes (port_buffer, _global_port_buffer_offset); + /* This is called from ARDOUR::PortManager::cycle_end() at which + * point other MIDI data has already been written to the port. + * So we "resolve notes" (panic) at the end of he buffer. + */ + resolve_notes (port_buffer, _global_port_buffer_offset + nframes -1); _resolve_required = false; }