Update backend API: read-only MIDI input buffers

This commit is contained in:
Robin Gareus 2017-08-05 15:04:05 +02:00
parent f9aff37623
commit 2b7c585dba
14 changed files with 33 additions and 28 deletions

View File

@ -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;

View File

@ -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

View File

@ -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))) {
_buffer->push_back (timestamp, size, buf);
} else {
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";
<< _global_port_buffer_offset << " limit="
<< (_global_port_buffer_offset + _port_buffer_offset + nframes) << "\n";
continue;
}
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 {
_buffer->push_back (timestamp, size, buf);
}
}

View File

@ -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);

View File

@ -1685,7 +1685,7 @@ AlsaAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std:
int
AlsaAudioBackend::midi_event_get (
pframes_t& timestamp,
size_t& size, uint8_t** buf, void* port_buffer,
size_t& size, uint8_t const** buf, void* port_buffer,
uint32_t event_index)
{
assert (buf && port_buffer);

View File

@ -291,7 +291,7 @@ class AlsaAudioBackend : public AudioBackend {
int get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe);
/* MIDI */
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index);
int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
uint32_t get_midi_event_count (void* port_buffer);
void midi_clear (void* port_buffer);

View File

@ -1407,7 +1407,7 @@ CoreAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std:
int
CoreAudioBackend::midi_event_get (
pframes_t& timestamp,
size_t& size, uint8_t** buf, void* port_buffer,
size_t& size, uint8_t const** buf, void* port_buffer,
uint32_t event_index)
{
if (!buf || !port_buffer) return -1;

View File

@ -352,7 +352,7 @@ class CoreAudioBackend : public AudioBackend {
int get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe);
/* MIDI */
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index);
int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size) {
return _midi_event_put (port_buffer, timestamp, buffer, size);
}

View File

@ -1082,7 +1082,7 @@ DummyAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std
int
DummyAudioBackend::midi_event_get (
pframes_t& timestamp,
size_t& size, uint8_t** buf, void* port_buffer,
size_t& size, uint8_t const** buf, void* port_buffer,
uint32_t event_index)
{
assert (buf && port_buffer);

View File

@ -360,7 +360,7 @@ class DummyAudioBackend : public AudioBackend {
int get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe);
/* MIDI */
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index);
int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
uint32_t get_midi_event_count (void* port_buffer);
void midi_clear (void* port_buffer);

View File

@ -175,7 +175,7 @@ class JACKAudioBackend : public AudioBackend {
return true;
}
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index);
int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
uint32_t get_midi_event_count (void* port_buffer);
void midi_clear (void* port_buffer);

View File

@ -488,7 +488,7 @@ JACKAudioBackend::disconnect_all (PortHandle port)
}
int
JACKAudioBackend::midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index)
JACKAudioBackend::midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index)
{
jack_midi_event_t ev;
int ret;

View File

@ -1610,7 +1610,7 @@ PortAudioBackend::get_connections (PortEngine::PortHandle port, std::vector<std:
int
PortAudioBackend::midi_event_get (
pframes_t& timestamp,
size_t& size, uint8_t** buf, void* port_buffer,
size_t& size, uint8_t const** buf, void* port_buffer,
uint32_t event_index)
{
if (!buf || !port_buffer) return -1;

View File

@ -288,7 +288,7 @@ class PortAudioBackend : public AudioBackend {
int get_connections (PortHandle, std::vector<std::string>&, bool process_callback_safe);
/* MIDI */
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index);
int midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index);
int midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
uint32_t get_midi_event_count (void* port_buffer);
void midi_clear (void* port_buffer);