**C# Midi Creation Library Specification**
What is needed is a C# (.NET 2.0 or higher) library with which general midi files can be created. The target use is for automatic music composition. A C# class offers a way for applications to create midi song classes, add notes, and save to a standard midi file.
## Deliverables
**C# Midi Creation Library Specification
**
***Abstract***: what is needed is a C# (.NET 2.0 or higher) library with which general midi files can be created. The target use is for automatic music composition. A C# class offers a way for applications to create midi song classes, add notes, and save to a standard midi file.
All C# code must be thoroughly commented. A sample program using the library/classes must be provided. The delivery format should be a sample project with the Midi-creation classes and code that uses them to create a standard midi file.
Code format with regards to braces should be as follows:
retvalue methodname( args )
{
}
if( condition )
{
}
for( int i=0; i<4; i++ )
{
}
It is suggested to use two classes: MidiSong and MidiTrack. A MidiSong class contains any number of MidiTracks.
**MidiSong specifications
**
Methods
AddTrack(string strName)
SetTimeSignature(int nTrack, int nTimeSignatureNumerator,
int nTimeSignatureDenominator )
Note: The default value should be 4/4
Set Tempo( int nTrack, int nBeatsPerSecond )
Note: The default value should be 100
Set ChannelInstrument( int nTrack, int nChannel, int nGeneralMidiNumber )
Note: The general midi number value should default to piano
(The general midi instrument numbers can be seen at [login to view URL])
AddNote(int nTrack, int nChannel, int nMidiNoteNumber, int nDuration)
(The general midi notes can be seen at [login to view URL])
Duration (independent of tempo) as follows:
1/4 note = 12
1/8 note = 6
Tripolet note = 4
1/16 note = 3
Other note values such as half notes are based on these. For instance a half note duration
value is 24
A note value of -1 is a rest
Save(string strFilePath)
Play( string strFilePath )
**MidiTrack specifications**
(This is suggested and can change if deemed necessary by the developer)
Methods ( accessible from the MidiSong class)
MidiTrack(string strName, int nTrackNumber,
int nBeatsPerMinute, int nTimeSignatureNumerator, int nTimeSignatureDenominator)
AddNote( int nChannel, int nMidiNoteNumber, int nDuraction)
The track number has already been stored in the MidiTrack class when the constructor is called.
(The general midi notes can be seen at [login to view URL])
Duration (independent of tempo) as follows:
1/4 note = 12
1/8 note = 6
Tripolet note = 4
1/16 note = 3
Other note values such as half notes are based on these. For instance a half note duration
value is 24
A note value of -1 is a rest
Save(FileStream objWriter )
There are private methods such as SaveDeltaValue(), SaveTimeSignature(), SaveTempo(), etc. left to the discretion of the developer.
**Example**
An application wants to create the following in 4/4 time (all quarter notes) as a midi file:
Piano:
C D E F | G A B C
Cello
E F G A | B C D E
Trumpet
G A B C | D E F G
A MidiSong class is created. The time signature of 4/4 is specified. The tempo of 100 beats per minute is specified. The application creates one track. Each instrument is one channel. The midi instrument number is given for each channel. Each channel has eight quarter notes that are added via the [login to view URL]() method. The [login to view URL]() method is called and a standard midi file is created.
Midi note values are passed as the actual midi values such as 60 for middle C.