|
|
MIDI file player routines . This class reads a MIDI file and play it using a DeviceManager object.
To use it, just call loadSong() with the filename you want to play, and then play().
Please have a look at the note in the play() documentation.
MidiPlayer will write information about the playing process on a PlayerController() structure that you must supply to the constructor
Alternatively, if everything you want is to play a midi file in a game or any other application that doesn't need to fine tune the midi playing, just use the kmidplay() function.
See also: KMidSimpleAPI
MidiPlayer (DeviceManager *midi_,PlayerController *pctl)
| MidiPlayer |
Constructor . You must construct and pass a DeviceManager object and a PlayerController structure. None of them will be destroyed by this object, so you should do it after destroying the MidiPlayer object.
~MidiPlayer ()
| ~MidiPlayer |
Destructor.
int loadSong (const char *filename)
| loadSong |
Loads a Song, and parses it (it the parse wasn't disabled with setParseSong() ) . It also generates the Beat events (see SpecialEvent::type() ) if you enabled this by using setGenerateBeats() .
void removeSong (void)
| removeSong |
Unloads the current song, so that every internal variable is empty and clean for further usage.
int isSongLoaded (void)
| isSongLoaded |
Returns true if there's a song already loaded (with a previous call to loadSong() ) and false if not.
SpecialEvent * specialEvents ()
| specialEvents |
Returns the linked list of SpecialEvents objects . For this to work, the parse should be enabled (the default), by using setParseSong().
NoteArray * noteArray (void)
| noteArray |
Returns and array with the notes playen through the song . MidiPlayer must parse the song to get the notes, so be sure not to disable the parsing of the song.
Returns an array of notes, (just note on and note off events), in the form of a NoteArray object
void play (bool calloutput=false,void output(void) = 0)
| play |
Plays the song using the DeviceManager object supplied in the constructor. It should be already configured, as play doesn't change the volume, nor midi mapper, for example.
Note: Calling this function will block the execution of your application until the song finishes playing. The solution for this is simple, fork before calling it, and create the PlayerController object on shared memory.
As alternative, if everything you want is playing a midi file in a game or any other application that doesn't need to fine tune the midi playing, just use the KMidSimpleAPI::kMidPlay() function.
See also: kMidInit, kMidPlay, kMidStop, kMidDestruct
void setParseSong (bool b = true)
| setParseSong |
Enables or disables the parsing of the song when loading it. This affects the SpecialEvents (specialEvents() ) and the NoteArray (noteArray() ).
void setGenerateBeats (bool b = false)
| setGenerateBeats |
Enables or disables the generation of beats event in a song when loading it.
MidiFileInfo * information (void)
| information |
Returns information about the current MIDI file.
See also: loadSong
void setPos (ulong gotomsec, class MidiStatus *midistat)
| setPos |
Sets the position in a song.
Parameters:
gotomsec | the number of milliseconds to go to . A subsequent call to play() will start playing the song from that moment, instead of the beginning. |
midistat | a MidiStatus object that will contain the status in which the MIDI device would be if it would have arrived to this situation by a normal playing of the song. |
void setTempoRatio (double ratio)
| setTempoRatio |
Changes the speed at which a song is played. The song's tempo is multiplied by the specified ratio.