Browse Source

Midi fixes for reading/writing variable-length sysexes.

tags/2021-05-28
jules 13 years ago
parent
commit
e74219b736
2 changed files with 19 additions and 3 deletions
  1. +9
    -0
      modules/juce_audio_basics/midi/juce_MidiFile.cpp
  2. +10
    -3
      modules/juce_audio_basics/midi/juce_MidiMessage.cpp

+ 9
- 0
modules/juce_audio_basics/midi/juce_MidiFile.cpp View File

@@ -403,6 +403,15 @@ void MidiFile::writeTrack (OutputStream& mainOut, const int trackNum)
++data; ++data;
--dataSize; --dataSize;
} }
else if ((statusByte & 0xf0) == 0xf0) // Write sysex message with length bytes.
{
out.writeByte ((char) statusByte);
++data;
--dataSize;
MidiFileHelpers::writeVariableLengthInt (out, dataSize);
}
out.write (data, dataSize); out.write (data, dataSize);
lastStatusByte = statusByte; lastStatusByte = statusByte;


+ 10
- 3
modules/juce_audio_basics/midi/juce_MidiMessage.cpp View File

@@ -216,6 +216,7 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin
{ {
const uint8* d = src; const uint8* d = src;
bool haveReadAllLengthBytes = false; bool haveReadAllLengthBytes = false;
int numVariableLengthSysexBytes = 0;
while (d < src + sz) while (d < src + sz)
{ {
@@ -230,19 +231,25 @@ MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uin
if (haveReadAllLengthBytes) // if we see a 0x80 bit set after the initial data length if (haveReadAllLengthBytes) // if we see a 0x80 bit set after the initial data length
break; // bytes, assume it's the end of the sysex break; // bytes, assume it's the end of the sysex
++numVariableLengthSysexBytes;
++d; ++d;
continue; continue;
} }
haveReadAllLengthBytes = true;
if (! haveReadAllLengthBytes)
{
haveReadAllLengthBytes = true;
++numVariableLengthSysexBytes;
}
++d; ++d;
} }
size = 1 + (int) (d - src); size = 1 + (int) (d - src);
data = new uint8 [size];
data = new uint8 [size - numVariableLengthSysexBytes];
*data = (uint8) byte; *data = (uint8) byte;
memcpy (data + 1, src, size - 1);
memcpy (data + 1, src + numVariableLengthSysexBytes, size - numVariableLengthSysexBytes - 1);
} }
else if (byte == 0xff) else if (byte == 0xff)
{ {


Loading…
Cancel
Save