Sign in to follow this  

MIDI file experts needed!

This topic is 812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey dudes.  I've sent this in an email to the MMA, but really didn't know where else to post it.  Pretty desperate for some insight...

 I have written some code in C++ that uses this open source parsing library:  http://midifile.sapp.org/

The code takes a MIDI file as an input and is able to return the number of tracks and the number of events in each track, as well as the timestamps for any of these events.  In some cases however, the input MIDI file causes an error, as the code interprets the MIDI file as having zero tracks and zero events.  The functions reporting this info are part of the external library.   Any MIDI files that have caused this error in my code are not corrupted, as they are still playable in other software.  

I've discovered that by importing a MIDI file that works correctly with my code into external software (such as power tab editor, muse score etc.), and then exporting from said software to a new MIDI file, that the new MIDI file will cause the error.  So in other words, I have two MIDI files; one works in my code, and one doesn't.  They are exactly the same except for whatever change occurred in the file during the import/export process of the external software.  I can send these files by email to anyone who'd know what to do with them.  

I've opened the two MIDI files side by side in notepad; the only difference I can spot straight away is the absence of square brackets used in the error prone file.  That said, it's all gibberish to me...

Any ideas what is going on?  




 

Edited by Olliepm

Share this post


Link to post
Share on other sites
Well, given MIDI's history, I wouldn't be surprised if an older MIDI file used a non-standard extension or behavior that is supported in your tool but not in craigsapp/midifile.


... ?___?
Also, please don't use windows notepad to compare binary files. You may get better results with a hex editor such as HxD.

Share this post


Link to post
Share on other sites

I would offhand guess that this parsing library is incapabe of properly parsing Type 0 MIDI files, which means you probably shouldn't use it.

 

For background, there are two common types of MIDI file: Type 0 and Type 1. (There's also Type 2, but you're not likely to see that.) Type 1 is a multi-track format, with an arbitrary number of tracks (up to 65535) that are played simultaneously. Type 0, on the other hand, is a single track format, with all the data shoved into a single data track - this is possible because MIDI messages implicitly indicate which channel they're meant for.

 

Type 1 is widely seen because the multi-track structure makes editing easier, so most MIDI trackers normally save in this format (it also allows for editor-specific extensions, like sending each track to a different devce). Type 0 is more convenient for playback, however, as it only requires single file pointer.

 

Remember that "track" and "channel" are independent concepts - any track in a Type 1 file can include messages for any and every MIDI channel. In fact, it's possible to have a Type 1 MIDI file that has all the data in a single track just like a Type 0 file - such a file would be exactly 1 byte different from the corresponding Type 0 file.

Share this post


Link to post
Share on other sites

I have a feeling that lib can't handle multiple events without repeated status byte.

In midi it's ok to specify multiple events within same channel with just one status byte (e.g. NoteOff/note/velocity/note/velocity), it's easily handled by checking next byte's msb. But I can't see any loops in function extracting data for event.

I forgot delta time is written in front of every event, so omitted status byte is handled in outer loop.

Edited by vstrakh

Share this post


Link to post
Share on other sites

Sigh...I don't know how else to say it so I'll just say it.  I forgot to put .mid after the file names, and for some reason the code ran anyway, and I got tunnel vision on the whole thing.  I feel quite silly indeed...  

 



... ?___?
Also, please don't use windows notepad to compare binary files. You may get better results with a hex editor such as HxD.

Pretty new to coding so making all kinds of stupid mistakes. Thanks for this though - sounds good!

Share this post


Link to post
Share on other sites

This topic is 812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this