X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fmidi_port.cc;h=55280eb9428e82aed7fc611a53d866991f0b0b82;hb=f372a661286bac38ec93a4c90cb8da056d856a0c;hp=eb6759f3086d4b7f49ef579570abc553ee13c5a7;hpb=d074bc586e494d7dd83d415a487195a477095a4f;p=ardour.git diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index eb6759f308..55280eb942 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -88,7 +88,7 @@ MidiPort::get_midi_buffer (pframes_t nframes) void* buffer = port_engine.get_buffer (_port_handle, nframes); const pframes_t event_count = port_engine.get_midi_event_count (buffer); - + /* suck all relevant MIDI events from the MIDI port buffer into our MidiBuffer */ @@ -158,13 +158,13 @@ MidiPort::resolve_notes (void* port_buffer, MidiBuffer::TimeType when) */ if (port_engine.midi_event_put (port_buffer, when, ev, 3) != 0) { - cerr << "failed to deliver sustain-zero on channel " << channel << " on port " << name() << endl; + cerr << "failed to deliver sustain-zero on channel " << (int)channel << " on port " << name() << endl; } ev[1] = MIDI_CTL_ALL_NOTES_OFF; if (port_engine.midi_event_put (port_buffer, 0, ev, 3) != 0) { - cerr << "failed to deliver ALL NOTES OFF on channel " << channel << " on port " << name() << endl; + cerr << "failed to deliver ALL NOTES OFF on channel " << (int)channel << " on port " << name() << endl; } } } @@ -174,12 +174,21 @@ MidiPort::flush_buffers (pframes_t nframes) { if (sends_output ()) { - void* port_buffer = port_engine.get_buffer (_port_handle, nframes); + void* port_buffer = 0; if (_resolve_required) { + port_buffer = port_engine.get_buffer (_port_handle, nframes); /* resolve all notes at the start of the buffer */ resolve_notes (port_buffer, 0); _resolve_required = false; + } + + if (_buffer->empty()) { + return; + } + + if (!port_buffer) { + port_buffer = port_engine.get_buffer (_port_handle, nframes); } for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) { @@ -196,11 +205,16 @@ MidiPort::flush_buffers (pframes_t nframes) << ev.time() << " > " << _global_port_buffer_offset + _port_buffer_offset << endl; } } else { - cerr << "drop flushed event on the floor, time " << ev + cerr << "drop flushed event on the floor, time " << ev.time() << " to early for " << _global_port_buffer_offset << " + " << _port_buffer_offset << endl; } } + + /* done.. the data has moved to the port buffer, mark it so + */ + + _buffer->clear (); } }