26namespace MidiBufferHelpers
28 inline int getEventTime (
const void* d)
noexcept
30 return readUnaligned<int32> (d);
33 inline uint16 getEventDataSize (
const void* d)
noexcept
35 return readUnaligned<uint16> (
static_cast<const char*
> (d) +
sizeof (int32));
38 inline uint16 getEventTotalSize (
const void* d)
noexcept
40 return (uint16) (getEventDataSize (d) +
sizeof (int32) +
sizeof (uint16));
43 static int findActualEventLength (
const uint8* data,
int maxBytes)
noexcept
45 auto byte = (
unsigned int) *data;
47 if (
byte == 0xf0 ||
byte == 0xf7)
52 if (data[i++] == 0xf7)
65 return jmin (maxBytes, n + 2 + bytesLeft);
74 static uint8* findEventAfter (uint8* d, uint8* endData,
int samplePosition)
noexcept
76 while (d < endData && getEventTime (d) <= samplePosition)
77 d += getEventTotalSize (d);
97 addEvent (message, 0);
107 auto start = MidiBufferHelpers::findEventAfter (
data.
begin(),
data.
end(), startSample - 1);
108 auto end = MidiBufferHelpers::findEventAfter (start,
data.
end(), startSample + numSamples - 1);
120 auto numBytes = MidiBufferHelpers::findActualEventLength (
static_cast<const uint8*
> (
newData),
maxBytes);
148 && (position < startSample + numSamples || numSamples < 0))
159 for (
auto d =
data.
begin(); d < end; ++n)
160 d += MidiBufferHelpers::getEventTotalSize (d);
179 auto nextOne = d + MidiBufferHelpers::getEventTotalSize (d);
182 return MidiBufferHelpers::getEventTime (d);
190 : buffer (
b), data (
b.
data.begin())
202 data += MidiBufferHelpers::getEventTotalSize (
data);
211 auto itemSize = MidiBufferHelpers::getEventDataSize (
data);
225 auto itemSize = MidiBufferHelpers::getEventDataSize (
data);
void swapWith(OtherArrayType &otherArray) noexcept
void ensureStorageAllocated(int minNumElements)
int size() const noexcept
void removeRange(int startIndex, int numberToRemove)
ElementType * begin() noexcept
ElementType * end() noexcept
void insertMultiple(int indexToInsertAt, ParameterType newElement, int numberOfTimesToInsertIt)
ElementType * data() noexcept
void setNextSamplePosition(int samplePosition) noexcept
Iterator(const MidiBuffer &) noexcept
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
int getFirstEventTime() const noexcept
MidiBuffer & operator=(const MidiBuffer &) noexcept
void addEvent(const MidiMessage &midiMessage, int sampleNumber)
int getLastEventTime() const noexcept
void ensureSize(size_t minimumNumBytes)
int getNumEvents() const noexcept
bool isEmpty() const noexcept
void swapWith(MidiBuffer &) noexcept
void addEvents(const MidiBuffer &otherBuffer, int startSample, int numSamples, int sampleDeltaToAdd)
static int readVariableLengthVal(const uint8 *data, int &numBytesUsed) noexcept
const uint8 * getRawData() const noexcept
static int getMessageLengthFromFirstByte(uint8 firstByte) noexcept
int getRawDataSize() const noexcept