This project has moved. For the latest updates, please go here.

Any sample code snippet of recording MIDI using CannedBytes.Midi.RecordToFile?

Topics: Getting Started, Midi File, Midi IO, Samples
Jul 8, 2013 at 10:46 PM
I am an undergratuate student who is making a basic OMR application, where the notes ideitification is done for now. the next challenge left for me is to convert the idetified notes to a MIDI file.

Therefore, when looking at CannedBytes.Midi.RecordToFile, is there any sample code which i can take a look at and have a idea of how to get my small task done, using MIDI.NET?

Awaiting for your kind reply, please. (Consider me an an ameature, not a expert in programming field)

Thank You.
Jul 9, 2013 at 5:29 AM

That should not be hard. You need the note number (0-127) which is played, how long it is played (duration) and how hard it was played (velocity). If you have those three things for every note, you're good to go.

Important to note is that Midi works with note-on and note-off messages. So you have to transform the duration of a note into a note-off event at the correct time interval.

For each note you can create a Message object (CannedBytes.Midi.Message namespace) with the correct values. Note that you can also create MetaEvent for Midi files that contain extra information on the file content.

Each entry into the midi file is represented by a MidiFileEvent class. That class couples a (I)MidiMessage to a time indication. Make sure you set the DeltaTime for each event. The delta time is the time THIS event occurs after the previous event. A delta time of 0 (zero) means the events take place at the exact same time. How much time each increment of delta time actually represents is dependent on the TimeDevision value used in the MidiHeader.

For more info on standard Midi files see:

A lot of the code in the RecordToFile sample can be reused, I suspect.

Hope it helps,