Fixes 7004 - Ardour crash on Just Quit when AudioEngine is stopped. AudioEngine:...
[ardour.git] / libs / ardour / midi_port.cc
index 771bfb979fb530f899f8daaa7b62407f7280d5a8..53e25fee1966ef7ff30868688fe3055f6ed98a82 100644 (file)
@@ -27,6 +27,7 @@
 #include "ardour/debug.h"
 #include "ardour/midi_buffer.h"
 #include "ardour/midi_port.h"
+#include "ardour/session.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -180,7 +181,7 @@ MidiPort::resolve_notes (void* port_buffer, MidiBuffer::TimeType when)
 
                ev[1] = MIDI_CTL_ALL_NOTES_OFF;
 
-               if (port_engine.midi_event_put (port_buffer, 0, ev, 3) != 0) {
+               if (port_engine.midi_event_put (port_buffer, when, ev, 3) != 0) {
                        cerr << "failed to deliver ALL NOTES OFF on channel " << (int)channel << " on port " << name() << endl;
                }
        }
@@ -232,8 +233,11 @@ MidiPort::flush_buffers (pframes_t nframes)
 
 #ifndef NDEBUG
                        if (DEBUG_ENABLED (DEBUG::MidiIO)) {
+                               const Session* s = AudioEngine::instance()->session();
+                               const framepos_t now = (s ? s->transport_frame() : 0);
                                DEBUG_STR_DECL(a);
-                               DEBUG_STR_APPEND(a, string_compose ("MidiPort %1 pop event    @ %2 sz %3 ", _buffer, ev.time(), ev.size()));
+                               DEBUG_STR_APPEND(a, string_compose ("MidiPort %8 %1 pop event    @ %2 (global %4, within %5 gpbo %6 pbo %7 sz %3 ", _buffer, ev.time(), ev.size(),
+                                                                   now + ev.time(), nframes, _global_port_buffer_offset, _port_buffer_offset, name()));
                                for (size_t i=0; i < ev.size(); ++i) {
                                        DEBUG_STR_APPEND(a,hex);
                                        DEBUG_STR_APPEND(a,"0x");