, MIDI::Port (name, MIDI::Port::Flags (0))
, _currently_in_cycle (false)
, _last_write_timestamp (0)
+ , _flush_at_cycle_start (false)
, have_timer (false)
, output_fifo (2048)
, input_fifo (1024)
if (ARDOUR::Port::sends_output()) {
flush_output_fifo (nframes);
+ if (_flush_at_cycle_start) {
+ flush_buffers (nframes);
+ }
}
/* copy incoming data from the port buffer into the input FIFO
if (!have_timer) {
when += (*b).time();
}
- input_fifo.write (when, (Evoral::EventType) 0, (*b).size(), (*b).buffer());
+ input_fifo.write (when, Evoral::NO_EVENT, (*b).size(), (*b).buffer());
}
if (!mb.empty()) {
_xthread.wakeup ();
}
+
}
}
void
AsyncMIDIPort::cycle_end (MIDI::pframes_t nframes)
{
- if (ARDOUR::Port::sends_output()) {
+ if (ARDOUR::Port::sends_output() && !_flush_at_cycle_start) {
/* move any additional data from output FIFO into the port
buffer.
*/
* Cannot be called from a processing thread.
*/
void
-AsyncMIDIPort::drain (int check_interval_usecs)
+AsyncMIDIPort::drain (int check_interval_usecs, int total_usecs_to_wait)
{
RingBuffer< Evoral::Event<double> >::rw_vector vec = { { 0, 0 }, { 0, 0} };
return;
}
- while (1) {
+ microseconds_t now = get_microseconds ();
+ microseconds_t end = now + total_usecs_to_wait;
+
+ while (now < end) {
output_fifo.get_write_vector (&vec);
if (vec.len[0] + vec.len[1] >= output_fifo.bufsize() - 1) {
break;
}
Glib::usleep (check_interval_usecs);
+ now = get_microseconds();
}
}
necessary.
*/
if (!vec.buf[0]->owns_buffer()) {
- vec.buf[0]->set_buffer (0, 0, true);
- }
+ vec.buf[0]->set_buffer (0, 0, true);
+ }
vec.buf[0]->set (msg, msglen, timestamp);
} else {
/* see comment in previous branch of if() statement */
if (!vec.buf[1]->owns_buffer()) {
- vec.buf[1]->set_buffer (0, 0, true);
- }
+ vec.buf[1]->set_buffer (0, 0, true);
+ }
vec.buf[1]->set (msg, msglen, timestamp);
}