Skip to content
Snippets Groups Projects
Commit 5390df8c authored by jsiegle's avatar jsiegle
Browse files

Update MidiBuffer code to handle spike events

parent 354dd8e9
Branches
Tags
No related merge requests found
......@@ -114,20 +114,42 @@ void MidiBuffer::addEvent (const MidiMessage& m, const int sampleNumber)
void MidiBuffer::addEvent (const void* const newData, const int maxBytes, const int sampleNumber)
{
const int numBytes = MidiBufferHelpers::findActualEventLength (static_cast<const uint8*> (newData), maxBytes);
const int numBytes = maxBytes;
if (numBytes > 0)
{
const size_t newItemSize = (size_t) numBytes + sizeof (int32) + sizeof (uint16);
const int offset = (int) (MidiBufferHelpers::findEventAfter (data.begin(), data.end(), sampleNumber) - data.begin());
int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16); // factor in timestamp and size indicator
data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7); // make sure there's enough size in the MemoryBlock
uint8* d = getData() + bytesUsed;
data.insertMultiple (offset, 0, (int) newItemSize);
*reinterpret_cast <int*> (d) = sampleNumber;
d += sizeof (int);
*reinterpret_cast <uint16*> (d) = (uint16) numBytes;
d += sizeof (uint16);
uint8* const d = data.begin() + offset;
*reinterpret_cast<int32*> (d) = sampleNumber;
*reinterpret_cast<uint16*> (d + 4) = (uint16) numBytes;
memcpy (d + 6, newData, (size_t) numBytes);
memcpy (d, newData, numBytes);
bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
}
// Original JUCE library code:
//
// const int numBytes = MidiBufferHelpers::findActualEventLength (static_cast<const uint8*> (newData), maxBytes);
// if (numBytes > 0)
// {
// const size_t newItemSize = (size_t) numBytes + sizeof (int32) + sizeof (uint16);
// const int offset = (int) (MidiBufferHelpers::findEventAfter (data.begin(), data.end(), sampleNumber) - data.begin());
// data.insertMultiple (offset, 0, (int) newItemSize);
// uint8* const d = data.begin() + offset;
// *reinterpret_cast<int32*> (d) = sampleNumber;
// *reinterpret_cast<uint16*> (d + 4) = (uint16) numBytes;
// memcpy (d + 6, newData, (size_t) numBytes);
// }
}
void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment