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

midi file does not sound

Jul 24, 2010 at 2:03 PM

Hi Mark,

I'm trying to create a simple Type 0 Midifile (=one Track).  I have tested the code that you posted  a few years ago (http://naudio.codeplex.com/Thread/View.aspx?ThreadId=17633)

       

   MidiEventCollection collection = new MidiEventCollection(0, 120);
           collection.AddEvent(new NoteOnEvent(0, 1, 60, 100, 150), 1);
           collection.AddEvent(new NoteOnEvent(15, 1, 64, 100, 150), 1);
           collection.AddEvent(new NoteOnEvent(30, 1, 67, 100, 150), 1);
    
           collection.PrepareForExport();
           MidiFile.Export(txtFile.Text, collection);

But the resulting file does not produce any sound when played back in winamp. And other midi players won't even open it  !  (i'm using win7 64 bit, naudio 1.3.5)

Can you help ?

henrik

Coordinator
Aug 11, 2010 at 10:57 AM

MIDI files tend to have a bit more to them, such as specifying tempo, setting up patches etc. Use the audio file inspector to look at an existing MIDI file and see what is typically in there.

Mark

Aug 12, 2010 at 8:17 PM
Edited Aug 12, 2010 at 8:20 PM
The problem seems to be that "NoteOnEvent" does not write the "OffEvent" to the file. If you use "NoteEvent" instead it works:

The following code produces a valid and playable Midi-File:

MidiEventCollection collection = new MidiEventCollection(0, 120);
collection.AddEvent(new NoteEvent(1, 1, MidiCommandCode.NoteOn, 60, 100), 0);
collection.AddEvent(new NoteEvent(300, 1, MidiCommandCode.NoteOff, 60, 0), 0);

collection.PrepareForExport();

MidiFile.Export(txtFile.Text, collection);


henrik
Dec 1, 2010 at 3:26 PM

Mrs. Heath,

There seem to be a problem when I submit a tempo change in a midi collection. Is there an order in add midievents? Or do I have to add a tempo change on every instruments?

Dec 2, 2010 at 8:06 PM

I tryied to add tempo change to every tracks and the problem is remaining. The file is not exported correctly.

Help! Please Mr. Heath!

Coordinator
Dec 4, 2010 at 12:15 PM

how are you adding the tempo change event?

Again, I would recommed using AudioFileInspector to compare your MIDI file with one that works

Mark