mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
MidiBuffer: Allow addEvent to report success or failure
This commit is contained in:
parent
12df164127
commit
a7ce9aab98
2 changed files with 31 additions and 19 deletions
|
|
@ -119,29 +119,37 @@ void MidiBuffer::clear (int startSample, int numSamples)
|
|||
data.removeRange ((int) (start - data.begin()), (int) (end - start));
|
||||
}
|
||||
|
||||
void MidiBuffer::addEvent (const MidiMessage& m, int sampleNumber)
|
||||
bool MidiBuffer::addEvent (const MidiMessage& m, int sampleNumber)
|
||||
{
|
||||
addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
|
||||
return addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
|
||||
}
|
||||
|
||||
void MidiBuffer::addEvent (const void* newData, int maxBytes, int sampleNumber)
|
||||
bool MidiBuffer::addEvent (const void* newData, int maxBytes, int sampleNumber)
|
||||
{
|
||||
auto numBytes = MidiBufferHelpers::findActualEventLength (static_cast<const uint8*> (newData), maxBytes);
|
||||
|
||||
if (numBytes > 0)
|
||||
if (numBytes <= 0)
|
||||
return true;
|
||||
|
||||
if (std::numeric_limits<uint16>::max() < numBytes)
|
||||
{
|
||||
auto newItemSize = (size_t) numBytes + sizeof (int32) + sizeof (uint16);
|
||||
auto offset = (int) (MidiBufferHelpers::findEventAfter (data.begin(), data.end(), sampleNumber) - data.begin());
|
||||
|
||||
data.insertMultiple (offset, 0, (int) newItemSize);
|
||||
|
||||
auto* d = data.begin() + offset;
|
||||
writeUnaligned<int32> (d, sampleNumber);
|
||||
d += sizeof (int32);
|
||||
writeUnaligned<uint16> (d, static_cast<uint16> (numBytes));
|
||||
d += sizeof (uint16);
|
||||
memcpy (d, newData, (size_t) numBytes);
|
||||
// This method only supports messages smaller than (1 << 16) bytes
|
||||
return false;
|
||||
}
|
||||
|
||||
auto newItemSize = (size_t) numBytes + sizeof (int32) + sizeof (uint16);
|
||||
auto offset = (int) (MidiBufferHelpers::findEventAfter (data.begin(), data.end(), sampleNumber) - data.begin());
|
||||
|
||||
data.insertMultiple (offset, 0, (int) newItemSize);
|
||||
|
||||
auto* d = data.begin() + offset;
|
||||
writeUnaligned<int32> (d, sampleNumber);
|
||||
d += sizeof (int32);
|
||||
writeUnaligned<uint16> (d, static_cast<uint16> (numBytes));
|
||||
d += sizeof (uint16);
|
||||
memcpy (d, newData, (size_t) numBytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
|
||||
|
|
|
|||
|
|
@ -184,9 +184,11 @@ public:
|
|||
If an event is added whose sample position is the same as one or more events
|
||||
already in the buffer, the new event will be placed after the existing ones.
|
||||
|
||||
To retrieve events, use a MidiBufferIterator object
|
||||
To retrieve events, use a MidiBufferIterator object.
|
||||
|
||||
Returns true on success, or false on failure.
|
||||
*/
|
||||
void addEvent (const MidiMessage& midiMessage, int sampleNumber);
|
||||
bool addEvent (const MidiMessage& midiMessage, int sampleNumber);
|
||||
|
||||
/** Adds an event to the buffer from raw midi data.
|
||||
|
||||
|
|
@ -202,9 +204,11 @@ public:
|
|||
it'll actually only store 3 bytes. If the midi data is invalid, it might not
|
||||
add an event at all.
|
||||
|
||||
To retrieve events, use a MidiBufferIterator object
|
||||
To retrieve events, use a MidiBufferIterator object.
|
||||
|
||||
Returns true on success, or false on failure.
|
||||
*/
|
||||
void addEvent (const void* rawMidiData,
|
||||
bool addEvent (const void* rawMidiData,
|
||||
int maxBytesOfMidiData,
|
||||
int sampleNumber);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue