From 5153631d70a3bfa9aec2548a1ae33edcffbebfcb Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 1 Feb 2016 13:26:30 -0500 Subject: change API of MIDI::Port::drain() to include a maximum blocking time --- libs/ardour/ardour/async_midi_port.h | 2 +- libs/ardour/async_midi_port.cc | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/async_midi_port.h b/libs/ardour/ardour/async_midi_port.h index e28c6922d2..96a50ab198 100644 --- a/libs/ardour/ardour/async_midi_port.h +++ b/libs/ardour/ardour/async_midi_port.h @@ -58,7 +58,7 @@ class LIBARDOUR_API AsyncMIDIPort : public ARDOUR::MidiPort, public MIDI::Port { int write (const MIDI::byte *msg, size_t msglen, MIDI::timestamp_t timestamp); int read (MIDI::byte *buf, size_t bufsize); /* waits for output to be cleared */ - void drain (int check_interval_usecs); + void drain (int check_interval_usecs, int total_usecs_to_wait); /* clears async request communication channel */ void clear () { diff --git a/libs/ardour/async_midi_port.cc b/libs/ardour/async_midi_port.cc index 3dfb5610d9..bbcc0aab85 100644 --- a/libs/ardour/async_midi_port.cc +++ b/libs/ardour/async_midi_port.cc @@ -168,7 +168,7 @@ AsyncMIDIPort::cycle_end (MIDI::pframes_t nframes) * 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 >::rw_vector vec = { { 0, 0 }, { 0, 0} }; @@ -183,12 +183,16 @@ AsyncMIDIPort::drain (int check_interval_usecs) 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(); } } -- cgit v1.2.3