From 2b7c585dbae9c989d35e2884060aad4b0270f90e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 5 Aug 2017 15:04:05 +0200 Subject: Update backend API: read-only MIDI input buffers --- libs/ardour/midi_port.cc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'libs/ardour/midi_port.cc') diff --git a/libs/ardour/midi_port.cc b/libs/ardour/midi_port.cc index 9a52aef3c6..7a87c4c273 100644 --- a/libs/ardour/midi_port.cc +++ b/libs/ardour/midi_port.cc @@ -129,28 +129,33 @@ MidiPort::get_midi_buffer (pframes_t nframes) pframes_t timestamp; size_t size; - uint8_t* buf; + uint8_t const* buf; port_engine.midi_event_get (timestamp, size, &buf, buffer, i); if (buf[0] == 0xfe) { /* throw away active sensing */ continue; - } else if ((buf[0] & 0xF0) == 0x90 && buf[2] == 0) { - /* normalize note on with velocity 0 to proper note off */ - buf[0] = 0x80 | (buf[0] & 0x0F); /* note off */ - buf[2] = 0x40; /* default velocity */ } /* check that the event is in the acceptable time range */ + if ((timestamp < (_global_port_buffer_offset + _port_buffer_offset)) || + (timestamp >= (_global_port_buffer_offset + _port_buffer_offset + nframes))) { + cerr << "Dropping incoming MIDI at time " << timestamp << "; offset=" + << _global_port_buffer_offset << " limit=" + << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n"; + continue; + } - if ((timestamp >= (_global_port_buffer_offset + _port_buffer_offset)) && - (timestamp < (_global_port_buffer_offset + _port_buffer_offset + nframes))) { - _buffer->push_back (timestamp, size, buf); + if ((buf[0] & 0xF0) == 0x90 && buf[2] == 0) { + /* normalize note on with velocity 0 to proper note off */ + uint8_t ev[3]; + ev[0] = 0x80 | (buf[0] & 0x0F); /* note off */ + ev[1] = buf[1]; + ev[2] = 0x40; /* default velocity */ + _buffer->push_back (timestamp, size, ev); } else { - cerr << "Dropping incoming MIDI at time " << timestamp << "; offset=" - << _global_port_buffer_offset << " limit=" - << (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n"; + _buffer->push_back (timestamp, size, buf); } } -- cgit v1.2.3