views:

99

answers:

3

Hi everyone.

I'm trying to read information from a .mid file, but I keep seeing extra bytes that don't seem to be part of any midi messages. I'm not sure how to predict/deal with these and it's throwing everything else off in my project. Any suggestions? Here's a few examples:

4d 54 72 6b 00 00 04 48           Track Header
00 c0 19                          Program Change
00 ff 03 07 54 72 61 63 6b 20 31  Track Title
00 b0 05 00                       Controller Event
00 64 00 00 06 0c 00 26 00        ????
00 b0 20 00                       Controller Event

00 ff 58 04 0c 03 0c 08           Time Signature
81 89                             ????
50 ff 51 03 0f 42 40              Tempo
00 ff 2f 00                       End of Track

00 ff 21 01 00                    Unknown Meta Event
30 b0 79 00                       Controller Event
00 07 64 01 0a 32 01 5b           ????
14 01 5d 11 01 20 00 00 00        ????
00 c0 23                          Program Change
8c 7c 90 23                       ????

I'm skeptical that I even have the breakdown right here because some of these seem to have non-zero delta times for no reason at all.

+1  A: 

Looks like you're not even starting off right. The first eight bytes should be

4D 54 68 64 00 00 00 06

My guess is that the file's hosed or you're not reading it in correctly?

EDIT: Never mind. You didn't say this was the beginning of the file. The four bytes you have is a chunk header.

John at CashCommons
+1  A: 

Delta times in MIDI events are variable-length, so each event uses 1 or more bytes to encode the time that should elapse from the last event. See this.

Every MIDI event has a delta time that is either 0 (indicating that it occurs at the exact same time as the previous event) or some positive value (indicating that it should occur after the previous event).

MusiGenesis
+1  A: 

MusiGenesis got it half right -- you are not parsing variable length deltas correctly. But the other events that you are seeing are running status, which is a technique used to save bandwidth by omitting the status byte when you are sending multiple messages of the same type.

Here's how that dump should be parsed:

4d 54 72 6b 00 00 04 48           Track Header
00 c0 19                          Program Change
00 ff 03 07 54 72 61 63 6b 20 31  Track Title
00 b0 05 00                       Controller Event
00 64 00                          Running status (controller event)
00 06 0c                          Running status (controller event)
00 26 00                          Running status (controller event)
00 b0 20 00                       Controller Event

and so on. But what I don't understand is why a whole bunch of extra events appear after the end of track message before the next track header? Have you pasted your MIDI file in its entirety?

Nik Reiman
Sorry I should have specified. It's just pieces, the entire file is huge, and there's no way I could post all the bytes in between. There's still some things I'm not understanding though. Here's a continuous piece of the file. 00 ff 21 01 00 (Unknown Meta Event) 30 b0 79 00 (Controller change) 00 07 64 01 0a 32 01 5b 14 01 5d 11 01 20 00 00 00 00 00 c0 23 Program change 8c 7c 90 23 73 0d 23 This is followed by A LOT more bytes which must be controller changes. There are no note on or note off events in the whole track and the few values above 7f only show up in delta time.
Skunkwaffle