Question

I'm writing a program in Objective C to generate a MIDI file. As a test, I'm asking it to write a file which plays one note and stops it a delta tick afterwards.

But I'm trying to open it with Logic and Sibelius, and they both say that the file is corrupted.

Here's the hex readout of the file..

4D 54 68 64   00 00 00 06   00 01 00 01   00 40   - MThd header

4D 54 72 6B   00 00 00 0D      - MTrk - with length of 13 as 32bit hex [00 00 00 0D]


81 00   90 48 64   82 00    80 48 64  - the track
delta    noteOn    delta    noteOff 


FF 2F 00                       - end of file

And here's my routines to write the delta time, and write the note -

- (void) appendNote:(int)note state:(BOOL)on isMelody:(BOOL)melodyNote{           // generate a MIDI note and add it to the 'track' NSData object
char c[3];

if( on ){
    c[0] = 0x90;
    c[2] = volume;
} else {
    c[0] = 0x80;
    c[2] = lastVolume;
}
c[1] = note;

[track appendBytes:&c length:3];

}

- (void) writeVarTime:(int)value{                       // generate a MIDI delta time and add it to the 'track' NSData object
char c[2];
if( value < 128 ){
    c[0] = value;
    [track appendBytes:&c length:1];
} else {
    c[0] = value/128 | 0x80;
    c[1] = value % 128;
    [track appendBytes:&c length:2];
}

}

are there any clever MIDI gurus out there who can tell what's wrong with this MIDI file?

Was it helpful?

Solution

The delta time of the EOF event is missing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top