Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get note data from MIDI file

Is there a way to get the note data from a MIDI file? That is, I want to break down the MIDI file into its constituent parts so they are in the form of a unique word (or any other data type). What I want to do in the end is take in a MIDI file and find patterns in the notes. Get in each note, find it's frequency (of being played) and note how likely other notes are to be played after it.

It would be nice to do this in C/C++, but any language would be fine.

like image 519
Bill Avatar asked Sep 07 '10 17:09

Bill


People also ask

What information is stored in a MIDI file?

MIDI Files contain one or more MIDI streams, with time information for each event. Song, sequence, and track structures, tempo and time signature information, are all supported. Track names and other descriptive information may be stored with the MIDI data.

What are MIDI notes?

MIDI (Musical Instrument Digital Interface) is a protocol developed in the 1980's which allows electronic instruments and other digital musical tools to communicate with each other. MIDI itself does not make sound, it is just a series of messages like "note on," "note off," "note/pitch," "pitchbend," and many more.

How many notes are there in MIDI?

Why Does MIDI Offer 127 Notes.

How do I view a MIDI file?

If you want to just play MIDI files on your PC, you can use media player software like VLC. Thankfully, Windows Media Player also supports MIDI as input format. So, you don't need third-party software to play MIDI files. Just import a MIDI file into it and play it.


2 Answers

Nik Reisman - sorry, but I don't agree with you...parsing midi in C#, C++ is something about 400 rows of code..It's nothing hard and it is nothing difficult.

I will advise you start with this link: https://web.archive.org/web/20141227205754/http://www.sonicspot.com:80/guide/midifiles.html
There is everything you need to know about midi and how to read it..

In the short description how the parser will work:
1)Open midi in byte mode
2)Read the header chunk where there is info about size, number of tracks and IMPORTANT file format!!
- There are 3 types of formats: 0,1,2 (type 2 is really "valuable", there are only few midi files with this type, so you don't need to read the midi if there is type 2)
- if there is not written: "MThd" (0x4D546864), end with error (it's a bad midi file)
3)Read track chunk
- if there is not written: "MTrk" (0x4D54726B) end with error (it's a bad midi file)
4)Read the midi events.. - There are very many events, you can read them all with if-else commands, or you can read only the events what you want to know, for example NOTE ON, NOTE OFF - Sometimes in some midi files are not NOTE OFF..this event is changed with NOTE ON and velocity 0

On the websites everything is explained really nicely. If you open the midi file in byte mode you will have only a few methods and everything is then only about if-else commands and there you will catch what is stored right now.
It is important to understand VARIABLE LENGTH, but on the websites it is also explained. It's not hard. You can google many sites where VARIABLE LENGTH is explained too, with some images and examples. So I don't think that it is hard to explain it in here.

If you want a bit more advice, write me, I will try it. But parsing midi is not as hard as how it looks. If you have some problems, write me..

like image 154
tomdelahaba Avatar answered Sep 29 '22 11:09

tomdelahaba


Parsing MIDI files by hand is no fun, take my word on this. ;) The format, although well documented, is difficult to deal with since you are always on the raw byte level. Since you are interested in extracting some meaningful information from MIDI files themselves, I'd recommend using a framework such as Juce, which is written in C++ and has support for reading MIDI files.

Juce is pretty large, but the API is good and well-documented. The class for parsing MIDI files, for instance, is pretty straightforward and easy to use.

like image 30
Nik Reiman Avatar answered Sep 29 '22 10:09

Nik Reiman