Skip to content

Commit 21e6f64

Browse files
committed
dded a bulk push_back to Deque and switched readControlPackets/readDataPackets to use it
1 parent 836f4de commit 21e6f64

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/AppleMIDI.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,7 @@ void AppleMIDISession<UdpClass, Settings, Platform>::writeRtpMidiBuffer(Particip
724724
}
725725

726726
// write out the MIDI Section
727-
for (size_t i = 0; i < bufferLen; i++)
728-
packet[offset++] = outMidiBuffer[i];
727+
offset += outMidiBuffer.copy_out(packet + offset, bufferLen);
729728

730729
// *No* journal section (Not supported)
731730
dataPort.write(packet, offset);

src/utility/Deque.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Deque {
2828
void push_front(const T &);
2929
void push_back(const T &);
3030
size_t push_back(const T *, size_t);
31+
size_t copy_out(T *, size_t) const;
3132
void pop_front();
3233
void pop_back();
3334

@@ -159,6 +160,32 @@ size_t Deque<T, Size>::push_back(const T *values, size_t count)
159160
return toWrite;
160161
}
161162

163+
template<typename T, size_t Size>
164+
size_t Deque<T, Size>::copy_out(T *dest, size_t count) const
165+
{
166+
if (dest == nullptr || count == 0)
167+
return 0;
168+
169+
const size_t available = size();
170+
if (available == 0)
171+
return 0;
172+
173+
const size_t toCopy = (count < available) ? count : available;
174+
const size_t start = (size_t)_tail;
175+
176+
size_t first = toCopy;
177+
if (start + first > Size)
178+
first = Size - start;
179+
180+
memcpy(dest, &_data[start], first * sizeof(T));
181+
182+
const size_t remaining = toCopy - first;
183+
if (remaining > 0)
184+
memcpy(dest + first, &_data[0], remaining * sizeof(T));
185+
186+
return toCopy;
187+
}
188+
162189
template<typename T, size_t Size>
163190
void Deque<T, Size>::pop_front() {
164191
if (empty()) // if empty, do nothing.

0 commit comments

Comments
 (0)