Collect plugin runtime profile statistics.
[ardour.git] / libs / ardour / async_midi_port.cc
index eee585fd96f1603923d5a6fb6aa394b1d8166eb3..c7117429fba9f5064649035ee16b7ee06f9b11be 100644 (file)
@@ -46,6 +46,7 @@ AsyncMIDIPort::AsyncMIDIPort (string const & name, PortFlags flags)
        , 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)
@@ -58,7 +59,7 @@ AsyncMIDIPort::~AsyncMIDIPort ()
 }
 
 void
-AsyncMIDIPort::set_timer (boost::function<MIDI::framecnt_t (void)>& f)
+AsyncMIDIPort::set_timer (boost::function<MIDI::samplecnt_t (void)>& f)
 {
        timer = f;
        have_timer = true;
@@ -119,6 +120,9 @@ AsyncMIDIPort::cycle_start (MIDI::pframes_t nframes)
 
        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
@@ -127,7 +131,7 @@ AsyncMIDIPort::cycle_start (MIDI::pframes_t nframes)
 
        if (ARDOUR::Port::receives_input()) {
                MidiBuffer& mb (get_midi_buffer (nframes));
-               framecnt_t when;
+               samplecnt_t when;
 
                if (have_timer) {
                        when = timer ();
@@ -139,7 +143,7 @@ AsyncMIDIPort::cycle_start (MIDI::pframes_t nframes)
                        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()) {
@@ -152,7 +156,7 @@ AsyncMIDIPort::cycle_start (MIDI::pframes_t nframes)
 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.
                */
@@ -237,14 +241,14 @@ AsyncMIDIPort::write (const MIDI::byte * msg, size_t msglen, MIDI::timestamp_t t
                           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);
                }
 
@@ -322,7 +326,7 @@ AsyncMIDIPort::read (MIDI::byte *, size_t)
 }
 
 void
-AsyncMIDIPort::parse (MIDI::framecnt_t)
+AsyncMIDIPort::parse (MIDI::samplecnt_t)
 {
        MIDI::byte buf[1];