coreaudio: correctly clear MIDI port buffers

This commit is contained in:
Paul Davis 2016-01-07 18:11:36 -05:00
parent c615e26f3c
commit 9d3cbe44a3
2 changed files with 16 additions and 15 deletions

View file

@ -1707,7 +1707,9 @@ CoreAudioBackend::process_callback (const uint32_t n_samples, const uint64_t hos
uint64_t time_ns; uint64_t time_ns;
uint8_t data[128]; // matches CoreMidi's MIDIPacket uint8_t data[128]; // matches CoreMidi's MIDIPacket
size_t size = sizeof(data); size_t size = sizeof(data);
port->clear_events ();
while (_midiio->recv_event (i, nominal_time, time_ns, data, size)) { while (_midiio->recv_event (i, nominal_time, time_ns, data, size)) {
pframes_t time = floor((float) time_ns * _samplerate * 1e-9); pframes_t time = floor((float) time_ns * _samplerate * 1e-9);
assert (time < n_samples); assert (time < n_samples);
@ -2079,6 +2081,9 @@ void* CoreMidiPort::get_buffer (pframes_t /* nframes */)
i != get_connections ().end (); i != get_connections ().end ();
++i) { ++i) {
const CoreMidiBuffer * src = static_cast<const CoreMidiPort*>(*i)->const_buffer (); const CoreMidiBuffer * src = static_cast<const CoreMidiPort*>(*i)->const_buffer ();
if (!src->empty()) {
fprintf (stderr, "Copying %d events from %s\n", src->size(), (*i)->name().c_str());
}
for (CoreMidiBuffer::const_iterator it = src->begin (); it != src->end (); ++it) { for (CoreMidiBuffer::const_iterator it = src->begin (); it != src->end (); ++it) {
(_buffer[_bufperiod]).push_back (boost::shared_ptr<CoreMidiEvent>(new CoreMidiEvent (**it))); (_buffer[_bufperiod]).push_back (boost::shared_ptr<CoreMidiEvent>(new CoreMidiEvent (**it)));
} }
@ -2097,21 +2102,16 @@ CoreMidiPort::queue_event (
pframes_t timestamp, pframes_t timestamp,
const uint8_t* buffer, size_t size) const uint8_t* buffer, size_t size)
{ {
if (!buffer || !port_buffer) return -1; return CoreAudioBackend::_midi_event_put (port_buffer, timestamp, buffer, size);
_event._pending = false;
CoreMidiBuffer& dst = * static_cast<CoreMidiBuffer*>(port_buffer);
if (dst.size () && (pframes_t)dst.back ()->timestamp () > timestamp) {
#ifndef NDEBUG
// nevermind, ::get_buffer() sorts events
fprintf (stderr, "CoreMidiBuffer: unordered event: %d > %d\n",
(pframes_t)dst.back ()->timestamp (), timestamp);
#endif
}
fprintf (stderr, "coremidi: queue event/buffer size %d @ %d\n", size, timestamp);
dst.push_back (boost::shared_ptr<CoreMidiEvent>(new CoreMidiEvent (timestamp, buffer, size)));
return 0;
} }
void
CoreMidiPort::clear_events ()
{
CoreMidiBuffer* mbuf = static_cast<CoreMidiBuffer*>(get_buffer(0));
mbuf->clear();
}
void void
CoreMidiPort::parse_events (const uint64_t time, const uint8_t *data, const size_t size) CoreMidiPort::parse_events (const uint64_t time, const uint8_t *data, const size_t size)
{ {

View file

@ -150,6 +150,7 @@ class CoreMidiPort : public CoreBackendPort {
void set_n_periods(int n) { if (n > 0 && n < 3) { _n_periods = n; } } void set_n_periods(int n) { if (n > 0 && n < 3) { _n_periods = n; } }
void parse_events (const uint64_t time, const uint8_t *data, const size_t size); void parse_events (const uint64_t time, const uint8_t *data, const size_t size);
void clear_events ();
private: private:
CoreMidiBuffer _buffer[2]; CoreMidiBuffer _buffer[2];
@ -158,7 +159,7 @@ class CoreMidiPort : public CoreBackendPort {
int queue_event (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size); int queue_event (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size);
bool process_byte (const uint64_t, const uint8_t); bool process_byte (const uint64_t, const uint8_t);
void record_byte(uint8_t byte) { void record_byte(uint8_t byte) {
if (_total_bytes < sizeof(_parser_buffer)) { if (_total_bytes < sizeof(_parser_buffer)) {
_parser_buffer[_total_bytes] = byte; _parser_buffer[_total_bytes] = byte;