diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index 61a747a62d..603fa35dfa 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -267,98 +267,98 @@ MidiPort::resolve_notes (void* port_buffer, MidiBuffer::TimeType when) void MidiPort::flush_buffers (pframes_t nframes) { - if (sends_output ()) { + if (!sends_output ()) { + return; + } - void* port_buffer = 0; + 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, _global_port_buffer_offset); - _resolve_required = false; - } + 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, _global_port_buffer_offset); + _resolve_required = false; + } - if (_buffer->empty()) { - return; - } + if (_buffer->empty()) { + return; + } - if (!port_buffer) { - port_buffer = port_engine.get_buffer (_port_handle, nframes); - } + if (!port_buffer) { + port_buffer = port_engine.get_buffer (_port_handle, nframes); + } - double speed_ratio = (flags () & TransportGenerator) ? 1.0 : resample_ratio (); + double speed_ratio = (flags () & TransportGenerator) ? 1.0 : resample_ratio (); - for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) { + std::shared_ptr trace_parser = _trace_parser.lock (); - const Evoral::Event ev (*i, false); + for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) { - const samplepos_t adjusted_time = ev.time() + _global_port_buffer_offset; + const Evoral::Event ev (*i, false); - if (sends_output()) { - std::shared_ptr trace_parser = _trace_parser.lock (); - if (trace_parser) { - uint8_t const * const buf = ev.buffer(); - const samplepos_t now = AudioEngine::instance()->sample_time_at_cycle_start(); + /* event times are in samples, relative to cycle start */ + const samplepos_t adjusted_time = ev.time() + _global_port_buffer_offset; - trace_parser->set_timestamp (now + adjusted_time / speed_ratio); + /* MIDI Tracer */ + if (trace_parser) { + uint8_t const * const buf = ev.buffer(); + const samplepos_t now = AudioEngine::instance()->sample_time_at_cycle_start(); - uint32_t limit = ev.size(); + trace_parser->set_timestamp (now + adjusted_time / speed_ratio); - for (size_t n = 0; n < limit; ++n) { - trace_parser->scanner (buf[n]); - } - } + uint32_t limit = ev.size(); + + for (size_t n = 0; n < limit; ++n) { + trace_parser->scanner (buf[n]); } - - // event times are in samples, relative to cycle start + } #ifndef NDEBUG - if (DEBUG_ENABLED (DEBUG::MidiIO)) { - const Session* s = AudioEngine::instance()->session(); - const samplepos_t now = (s ? s->transport_sample() : 0); - DEBUG_STR_DECL(a); - DEBUG_STR_APPEND(a, string_compose ("MidiPort %7 %1 pop event @ %2[%7] (global %4, within %5 gpbo %6 sz %3 ", _buffer, adjusted_time, ev.size(), - now + adjusted_time, nframes, _global_port_buffer_offset, name(), ev.time())); - for (size_t i=0; i < ev.size(); ++i) { - DEBUG_STR_APPEND(a,hex); - DEBUG_STR_APPEND(a,"0x"); - DEBUG_STR_APPEND(a,(int)(ev.buffer()[i])); - DEBUG_STR_APPEND(a,' '); - } - DEBUG_STR_APPEND(a,'\n'); - DEBUG_TRACE (DEBUG::MidiIO, DEBUG_STR(a).str()); + if (DEBUG_ENABLED (DEBUG::MidiIO)) { + const Session* s = AudioEngine::instance()->session(); + const samplepos_t now = (s ? s->transport_sample() : 0); + DEBUG_STR_DECL(a); + DEBUG_STR_APPEND(a, string_compose ("MidiPort %7 %1 pop event @ %2[%7] (global %4, within %5 gpbo %6 sz %3 ", _buffer, adjusted_time, ev.size(), + now + adjusted_time, nframes, _global_port_buffer_offset, name(), ev.time())); + for (size_t i=0; i < ev.size(); ++i) { + DEBUG_STR_APPEND(a,hex); + DEBUG_STR_APPEND(a,"0x"); + DEBUG_STR_APPEND(a,(int)(ev.buffer()[i])); + DEBUG_STR_APPEND(a,' '); } + DEBUG_STR_APPEND(a,'\n'); + DEBUG_TRACE (DEBUG::MidiIO, DEBUG_STR(a).str()); + } #endif - // XXX consider removing this check for optimized builds - // and just send 'em all, at cycle_end - // see AudioEngine::split_cycle (), PortManager::cycle_end() - if ((adjusted_time >= _global_port_buffer_offset) && (adjusted_time < _global_port_buffer_offset + nframes)) { - pframes_t tme = floor (adjusted_time / speed_ratio); - if (port_engine.midi_event_put (port_buffer, tme, ev.buffer(), ev.size()) != 0) { - cerr << "write failed, dropped event, time " << adjusted_time << '/' << ev.time() << endl; - } - } else { - pframes_t tme = floor (adjusted_time / speed_ratio); - cerr << "Dropped outgoing MIDI event. time " << adjusted_time - << " (" << ev.time() << ") @" << speed_ratio << " = " << tme - << " out of range [" << _global_port_buffer_offset - << " .. " << _global_port_buffer_offset + nframes - << "]"; - for (size_t xx = 0; xx < ev.size(); ++xx) { - cerr << ' ' << hex << (int) ev.buffer()[xx]; - } - cerr << dec << endl; + // XXX consider removing this check for optimized builds + // and just send 'em all, at cycle_end + // see AudioEngine::split_cycle (), PortManager::cycle_end() + if ((adjusted_time >= _global_port_buffer_offset) && (adjusted_time < _global_port_buffer_offset + nframes)) { + pframes_t tme = floor (adjusted_time / speed_ratio); + if (port_engine.midi_event_put (port_buffer, tme, ev.buffer(), ev.size()) != 0) { + cerr << "write failed, dropped event, time " << adjusted_time << '/' << ev.time() << endl; } + } else { + pframes_t tme = floor (adjusted_time / speed_ratio); + cerr << "Dropped outgoing MIDI event. time " << adjusted_time + << " (" << ev.time() << ") @" << speed_ratio << " = " << tme + << " out of range [" << _global_port_buffer_offset + << " .. " << _global_port_buffer_offset + nframes + << "]"; + for (size_t xx = 0; xx < ev.size(); ++xx) { + cerr << ' ' << hex << (int) ev.buffer()[xx]; + } + cerr << dec << endl; } + } - /* done.. the data has moved to the port buffer, mark it so, - * unless we're exporting in which PortExportMIDI::read - * needs to read it at the end of a process cycle. - */ - if (!AudioEngine::instance()->session()->exporting ()) { - _buffer->clear (); - } + /* done.. the data has moved to the port buffer, mark it so, + * unless we're exporting in which PortExportMIDI::read + * needs to read it at the end of a process cycle. + */ + if (!AudioEngine::instance()->session()->exporting ()) { + _buffer->clear (); } }