Changeset - r24179:6c07aba301a5
[Not reviewed]
master
0 1 0
Niels Martin Hansen - 4 years ago 2020-05-08 19:35:52
nielsm@indvikleren.dk
Fix: Two issues in MIDI file writer

Variable-length values would write threshold values with a byte too many.
System Exclusive messages would cause write to fail since the end byte was treated as part of next message.
1 file changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/music/midifile.cpp
Show inline comments
 
@@ -886,21 +886,21 @@ void MidiFile::MoveFrom(MidiFile &other)
 

	
 
static void WriteVariableLen(FILE *f, uint32 value)
 
{
 
	if (value < 0x7F) {
 
	if (value <= 0x7F) {
 
		byte tb = value;
 
		fwrite(&tb, 1, 1, f);
 
	} else if (value < 0x3FFF) {
 
	} else if (value <= 0x3FFF) {
 
		byte tb[2];
 
		tb[1] =  value & 0x7F;         value >>= 7;
 
		tb[0] = (value & 0x7F) | 0x80; value >>= 7;
 
		fwrite(tb, 1, sizeof(tb), f);
 
	} else if (value < 0x1FFFFF) {
 
	} else if (value <= 0x1FFFFF) {
 
		byte tb[3];
 
		tb[2] =  value & 0x7F;         value >>= 7;
 
		tb[1] = (value & 0x7F) | 0x80; value >>= 7;
 
		tb[0] = (value & 0x7F) | 0x80; value >>= 7;
 
		fwrite(tb, 1, sizeof(tb), f);
 
	} else if (value < 0x0FFFFFFF) {
 
	} else if (value <= 0x0FFFFFFF) {
 
		byte tb[4];
 
		tb[3] =  value & 0x7F;         value >>= 7;
 
		tb[2] = (value & 0x7F) | 0x80; value >>= 7;
 
@@ -1013,7 +1013,7 @@ bool MidiFile::WriteSMF(const char *file
 
				ptrdiff_t sysexlen = sysexend - dp;
 
				WriteVariableLen(f, sysexlen);
 
				fwrite(dp, 1, sysexend - dp, f);
 
				dp = sysexend;
 
				dp = sysexend + 1;
 
				continue;
 
			}
 

	
0 comments (0 inline, 0 general)