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/ardour/mididm.h | 4 ++-- libs/ardour/ardour/port_engine.h | 2 +- libs/ardour/midi_port.cc | 27 ++++++++++++++++----------- libs/ardour/mididm.cc | 6 +++--- 4 files changed, 22 insertions(+), 17 deletions(-) (limited to 'libs/ardour') diff --git a/libs/ardour/ardour/mididm.h b/libs/ardour/ardour/mididm.h index 65ed15ab72..5ee964c8e0 100644 --- a/libs/ardour/ardour/mididm.h +++ b/libs/ardour/ardour/mididm.h @@ -41,8 +41,8 @@ public: bool have_signal (void) { return (_monotonic_cnt - _last_signal_tme) < (uint64_t) _sample_rate ; } private: - int64_t parse_mclk (uint8_t* buf, pframes_t timestamp) const; - int64_t parse_mtc (uint8_t* buf, pframes_t timestamp) const; + int64_t parse_mclk (uint8_t const * const buf, pframes_t timestamp) const; + int64_t parse_mtc (uint8_t const * const buf, pframes_t timestamp) const; framecnt_t _sample_rate; diff --git a/libs/ardour/ardour/port_engine.h b/libs/ardour/ardour/port_engine.h index a6fa2a5c84..647253baea 100644 --- a/libs/ardour/ardour/port_engine.h +++ b/libs/ardour/ardour/port_engine.h @@ -245,7 +245,7 @@ class LIBARDOUR_API PortEngine { * of the current process cycle, in samples) will be stored in @param * timestamp */ - virtual int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index) = 0; + virtual int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index) = 0; /** Place a MIDI event consisting of @param size bytes copied from the data * at @param buf into the port buffer referred to by @param 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); } } diff --git a/libs/ardour/mididm.cc b/libs/ardour/mididm.cc index 0888d154e9..0b95fc1bd5 100644 --- a/libs/ardour/mididm.cc +++ b/libs/ardour/mididm.cc @@ -37,7 +37,7 @@ MIDIDM::MIDIDM (framecnt_t sample_rate) } int64_t -MIDIDM::parse_mclk (uint8_t* buf, pframes_t timestamp) const +MIDIDM::parse_mclk (uint8_t const * const buf, pframes_t timestamp) const { /* calculate time difference */ #define MODCLK (16384) // 1<<(2*7) @@ -52,7 +52,7 @@ MIDIDM::parse_mclk (uint8_t* buf, pframes_t timestamp) const } int64_t -MIDIDM::parse_mtc (uint8_t* buf, pframes_t timestamp) const +MIDIDM::parse_mtc (uint8_t const * const buf, pframes_t timestamp) const { #define MODTC (2097152) // 1<<(3*7) const int64_t tc = (_monotonic_cnt + timestamp) & 0x001FFFFF; @@ -101,7 +101,7 @@ int MIDIDM::process (pframes_t nframes, PortEngine &pe, void *midi_in, void *mid for (pframes_t n = 0; n < nevents; ++n) { pframes_t timestamp; size_t size; - uint8_t* buf; + uint8_t const* buf; int64_t tdiff; pe.midi_event_get (timestamp, size, &buf, midi_in, n); -- cgit v1.2.3