infrastructure to allow tracing of all MIDI ports
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 11 Feb 2015 00:48:01 +0000 (19:48 -0500)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 11 Feb 2015 00:48:47 +0000 (19:48 -0500)
libs/ardour/ardour/midi_port.h
libs/ardour/midi_port.cc

index 0053a4dc7269c88825afc13c85787ef309028084..b410f3d5af32c08b2527086a7c2f0ae63618ba7d 100644 (file)
@@ -56,6 +56,8 @@ class LIBARDOUR_API MidiPort : public Port {
        MidiBuffer& get_midi_buffer (pframes_t nframes);
 
        void set_always_parse (bool yn);
+       void set_trace_on (bool yn);
+       
        MIDI::Parser& self_parser() { return _self_parser; }
 
   protected:
@@ -69,7 +71,8 @@ class LIBARDOUR_API MidiPort : public Port {
        bool        _resolve_required;
        bool        _input_active;
        bool        _always_parse;
-
+       bool        _trace_on;
+       
     /* Naming this is tricky. AsyncMIDIPort inherits (for now, aug 2013) from
      * both MIDI::Port, which has _parser, and this (ARDOUR::MidiPort). We
      * need parsing support in this object, independently of what the
index 8dcf4d42fc2f46049ac16560d2c5c400d53a139b..b12999cc9f090305811e4655170b98c192c9ef4d 100644 (file)
@@ -40,6 +40,7 @@ MidiPort::MidiPort (const std::string& name, PortFlags flags)
        , _resolve_required (false)
        , _input_active (true)
        , _always_parse (false)
+       , _trace_on (false)
 {
        _buffer = new MidiBuffer (AudioEngine::instance()->raw_buffer_size (DataType::MIDI));
 }
@@ -62,7 +63,7 @@ MidiPort::cycle_start (pframes_t nframes)
                port_engine.midi_clear (port_engine.get_buffer (_port_handle, nframes));
        }
 
-       if (_always_parse) {
+       if (_always_parse || (receives_input() && _trace_on)) {
                MidiBuffer& mb (get_midi_buffer (nframes));
 
                /* dump incoming MIDI to parser */
@@ -203,10 +204,26 @@ MidiPort::flush_buffers (pframes_t nframes)
                        port_buffer = port_engine.get_buffer (_port_handle, nframes);
                }
 
+
                for (MidiBuffer::iterator i = _buffer->begin(); i != _buffer->end(); ++i) {
 
                        const Evoral::MIDIEvent<MidiBuffer::TimeType> ev (*i, false);
 
+
+                       if (sends_output() && _trace_on) {
+                               uint8_t const * const buf = ev.buffer();
+                               const framepos_t now = AudioEngine::instance()->sample_time_at_cycle_start();                           
+
+                               _self_parser.set_timestamp (now + ev.time());
+                               
+                               uint32_t limit = ev.size();
+                               
+                               for (size_t n = 0; n < limit; ++n) {
+                                       _self_parser.scanner (buf[n]);
+                               }
+                       }
+
+
                        // event times are in frames, relative to cycle start
 
 #ifndef NDEBUG
@@ -287,3 +304,9 @@ MidiPort::set_always_parse (bool yn)
 {
        _always_parse = yn;
 }
+
+void
+MidiPort::set_trace_on (bool yn)
+{
+       _trace_on = yn;
+}