Writing MIDI Files
Posted
by Andreas Jdger
on November 14th, 1998
The class library I wrote illustrates the structure of MIDI-Files.
There is a class CMidiFile, which consists of some header information
and a collection of Tracks, objects of class CMidiTrack. Each track itself
is a collection of Events, with some header information, too. Events are
such as NoteOn, NoteOff or Meta-Events like SetTempo, TrackName or Copyright.
A collection is polymorph, i.e. I can declare CMidiTrack as a collection
of CMidiEventCommand's. CMidiEvent is a base class, and for each type of
Event there is a special class. The overridden methods are the constructor,
the GetLength()-method and the WriteToFile(ostream& )-method, more is not
neccasary.
CMidiTrack has some methods to simplify some operations. The most impor-
tant member-function is the PlayString function, which takes a string you
know from the BASIC-PLAY-function. Then these few lines are enough to
create your own MIDI-file:
CMidiFile midifile(96);
CMidiTrack* miditrack = new CMidiTrack;
miditrack->Copyright(_T("Copyright (C) 1997 Andreas Jaeger"));
miditrack->TimeSignature(0x04, 0x02, 0x18, 0x08);
miditrack->Tempo(120);
miditrack->Insert
(new CMidiEventCommandProgramChange (MIDI_CHANNEL_2, 0, 70));
miditrack->PlayString(MIDI_CHANNEL_2, "MBT120O3T120l8dl4gl8bd"
"l4gl8bgl4al8a.l16al4aP8l8bO4l4cl8ccdcO3bal4bl8g.l16gl4gP8l8g"
"O4c.l16cl8ccl4ecO3l8bbgbO4l4dO3l8bgl4dl8f#aO4l4cO3l8af#l4ggg"
"P8l8gO4c.l16cl8ccl4ecO3l8bbgbO4l4dO3l8bgl4dl8f#aO4l4cO3l8af#l4gggP8");
miditrack->EndOfTrack();
midifile.Insert(miditrack);
midifile.WriteToFile(_T("Fr|htau.mid"));
You see you do not have to deal with Events, only with tracks.

Comments
How is wave format file convert to midi format file?
Posted by evy_ooi on 03/23/2004 03:22amMay I know who know how wave format is convert into midiformat. What is the sharing format they using? May I have the source code please? Thank you.
ReplyHow to read from midi device?
Posted by Legacy on 09/29/2003 12:00amOriginally posted by: Yves
Does anybody know how you can read the midi instruction from a keyboard connected to the soundcard midi-interface?
I'm looking for that info.
Thanks
ReplyYves
How to read mmf file?
Posted by Legacy on 09/12/2003 12:00amOriginally posted by: leebaozhong
thanks!
Replyhow to convert wave to midi
Posted by Legacy on 08/11/2003 12:00amOriginally posted by: brio
Who know how to convert a wave file to midi.
I wanna the source code. thanks.
-
Reply
-
ReplyMISSION IMPOSSIBLE!!
Posted by Leonardtlhoe on 03/28/2005 02:38amMe too..
Posted by winbets on 10/28/2004 09:23amIf any one know , help me ,please.
Replyhow to write our own wav files
Posted by Legacy on 01/07/2003 12:00amOriginally posted by: javax
any one, how to write our own wav files?
Replydon't know how
How to read midi file?
Posted by Legacy on 06/05/2002 12:00amOriginally posted by: roger
Please!
Replyhow to rase pitch (c->c#,g->f#) while playing midi?
Posted by Legacy on 11/23/2000 12:00amOriginally posted by: vietfuong
how to rase pitch (c->c#,g->f#) while playing midi?
Replyhow to raise pitch (c->C#,,..g->f#)while playing midi ?
Posted by Legacy on 11/20/2000 12:00amOriginally posted by: vietfuong
how to raise pitch (c->C#,,..g->f#)while playing midi ?
Replyhow to raise pitch (c->c#,g->f#,...)while playing midi (*.mid)
Posted by Legacy on 11/13/2000 12:00amOriginally posted by: vietfuong
how to raise pitch (c->c#,g->f#,...)while playing midi (*.mid)
ReplyProblems in opening generated midi with Windows Media Player and Winamp
Posted by Legacy on 12/12/1999 12:00amOriginally posted by: Tan Hung Teck
Nice codes u have there in ur MidiGenerator for writing a midi file. However, I do have some problems with opening the resultant midi file. Commercial player like Windows Media Player and Winamp both failed to open the generated files.
However they do work for midi files i got from windows\media. Although I am still able to open the midi using some C++ developer programs, I am still baffled by why the generated files cannot be opened by the mentioned players.
Is there something in the header not set by MidiGenerator that is checked by the players?
Reply