change API of MIDI::Port::drain() to include a maximum blocking time
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 1 Feb 2016 18:26:30 +0000 (13:26 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 1 Feb 2016 18:26:30 +0000 (13:26 -0500)
libs/ardour/ardour/async_midi_port.h
libs/ardour/async_midi_port.cc
libs/midi++2/midi++/port.h
libs/surfaces/mackie/surface_port.cc

index e28c6922d2c92d43a47047bc0a1c3975de533720..96a50ab198df1c18136d396197e768e30be55af3 100644 (file)
@@ -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 () {
index 3dfb5610d9958153363fb219b0b392d5f88737f7..bbcc0aab85e7e086d9a081e6d062e15df18bda2a 100644 (file)
@@ -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<double> >::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();
        }
 }
 
index 6d933f6a6d2daee8b2dfd235da4375e7f4d1d10e..02cc340194b89f3a81be9dff8a85013b595c9816 100644 (file)
@@ -75,7 +75,7 @@ class LIBMIDIPP_API Port {
         * executes any part of a JACK process callback (will
         * simply return immediately in that situation).
         */
-       virtual void drain (int /* check_interval_usecs */) {}
+       virtual void drain (int /* check_interval_usecs */, int /* total_usecs_to_wait */) {}
 
        /** Write a message to port.
         * @return true on success.
index 009f45d136fdc27d13ae012a035acdc4d0d77ab6..6f6500ffa3899255c7b1f9dc2ea89a64d2726023 100644 (file)
@@ -99,7 +99,7 @@ SurfacePort::~SurfacePort()
                }
 
                if (_async_out) {
-                       _output_port->drain (10000);
+                       _output_port->drain (10000, 250000);
                        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unregistering output port %1\n", _async_out->name()));
                        AudioEngine::instance()->unregister_port (_async_out);
                        _async_out.reset ((ARDOUR::Port*) 0);