From 314e5f7d09a7701ad6f1519342dc8186ec60016d Mon Sep 17 00:00:00 2001 From: Stephane Letz Date: Mon, 12 May 2014 08:16:04 +0200 Subject: [PATCH] Pawel patch for MidiBufferMixdown. --- common/JackMidiPort.cpp | 17 +++++++++-------- common/JackMidiPort.h | 1 - common/JackNetTool.cpp | 2 -- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/common/JackMidiPort.cpp b/common/JackMidiPort.cpp index 83636c55..babee324 100644 --- a/common/JackMidiPort.cpp +++ b/common/JackMidiPort.cpp @@ -34,7 +34,6 @@ SERVER_EXPORT void JackMidiBuffer::Reset(jack_nframes_t nframes) write_pos = 0; event_count = 0; lost_events = 0; - mix_index = 0; } SERVER_EXPORT jack_shmsize_t JackMidiBuffer::MaxEventSize() const @@ -100,6 +99,7 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count } mix->Reset(nframes); + uint32_t mix_index[src_count]; int event_count = 0; for (int i = 0; i < src_count; ++i) { JackMidiBuffer* buf = static_cast(src_buffers[i]); @@ -107,7 +107,7 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count jack_error("Jack::MidiBufferMixdown - invalid source buffer"); return; } - buf->mix_index = 0; + mix_index[i] = 0; event_count += buf->event_count; mix->lost_events += buf->lost_events; } @@ -116,27 +116,28 @@ static void MidiBufferMixdown(void* mixbuffer, void** src_buffers, int src_count for (events_done = 0; events_done < event_count; ++events_done) { JackMidiBuffer* next_buf = 0; JackMidiEvent* next_event = 0; + uint32_t next_buf_index = 0; // find the earliest event for (int i = 0; i < src_count; ++i) { JackMidiBuffer* buf = static_cast(src_buffers[i]); - if (buf->mix_index >= buf->event_count) + if (mix_index[i] >= buf->event_count) continue; - JackMidiEvent* e = &buf->events[buf->mix_index]; + JackMidiEvent* e = &buf->events[mix_index[i]]; if (!next_event || e->time < next_event->time) { next_event = e; next_buf = buf; + next_buf_index = i; } } assert(next_event != 0); // write the event jack_midi_data_t* dest = mix->ReserveEvent(next_event->time, next_event->size); - if (!dest) { - break; - } + if (!dest) break; + memcpy(dest, next_event->GetData(next_buf), next_event->size); - next_buf->mix_index++; + mix_index[next_buf_index]++; } mix->lost_events += event_count - events_done; } diff --git a/common/JackMidiPort.h b/common/JackMidiPort.h index 72fad05b..29e3e4ec 100644 --- a/common/JackMidiPort.h +++ b/common/JackMidiPort.h @@ -82,7 +82,6 @@ struct SERVER_EXPORT JackMidiBuffer jack_shmsize_t write_pos; //!< data write position from the end of the buffer. uint32_t event_count; uint32_t lost_events; - uint32_t mix_index; JackMidiEvent events[1]; // Using 0 size does not compile with older GCC versions, so use 1 here. diff --git a/common/JackNetTool.cpp b/common/JackNetTool.cpp index 7227f38a..7ecdb11d 100644 --- a/common/JackNetTool.cpp +++ b/common/JackNetTool.cpp @@ -1279,7 +1279,6 @@ namespace Jack dst_buffer->write_pos = htonl(src_buffer->write_pos); dst_buffer->event_count = htonl(src_buffer->event_count); dst_buffer->lost_events = htonl(src_buffer->lost_events); - dst_buffer->mix_index = htonl(src_buffer->mix_index); } SERVER_EXPORT void MidiBufferNToH(JackMidiBuffer* src_buffer, JackMidiBuffer* dst_buffer) @@ -1290,7 +1289,6 @@ namespace Jack dst_buffer->write_pos = ntohl(src_buffer->write_pos); dst_buffer->event_count = ntohl(src_buffer->event_count); dst_buffer->lost_events = ntohl(src_buffer->lost_events); - dst_buffer->mix_index = ntohl(src_buffer->mix_index); } SERVER_EXPORT void TransportDataHToN(net_transport_data_t* src_params, net_transport_data_t* dst_params)