# libkmid Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# MidiPlayer Class Reference

MIDI file player routines . The MIDI file player engine. More...

`#include <player.h>`

Collaboration diagram for MidiPlayer:

[legend]
List of all members.

## Public Member Functions

| MidiPlayer (DeviceManager *midi_, PlayerController *pctl)
| Constructor .
| ~MidiPlayer ()
| Destructor.
int | loadSong (const char *filename)
| Loads a Song, and parses it (it the parse wasn't disabled with setParseSong() ) .
void | removeSong (void)
| Unloads the current song, so that every internal variable is empty and clean for further usage.
int | isSongLoaded (void)
| Returns true if there's a song already loaded (with a previous call to loadSong() ) and false if not.
SpecialEvent * | specialEvents ()
| Returns the linked list of SpecialEvents objects .
NoteArray * | noteArray (void)
| Returns and array with the notes playen through the song .
void | play (bool calloutput=false, void output(void)=0)
| Plays the song using the DeviceManager object supplied in the constructor.
void | setParseSong (bool b=true)
| Enables or disables the parsing of the song when loading it.
void | setGenerateBeats (bool b=false)
| Enables or disables the generation of beats event in a song when loading it.
MidiFileInfo * | information (void)
| Returns information about the current MIDI file.
void | setPos (ulong gotomsec, class MidiStatus *midistat)
| Sets the position in a song.
void | setTempoRatio (double ratio)
| Changes the speed at which a song is played.

## Detailed Description

MIDI file player routines . The MIDI file player engine.

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

Version:
  0.9.5 17/01/2000

Author:
  Antonio Larrosa Jimenez <larrosa@kde.org>

Definition at line 259 of file player.h.

## Constructor & Destructor Documentation

MidiPlayer::MidiPlayer | ( | DeviceManager * | midi_,
|  | PlayerController * | pctl
| ) |

| 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. Definition at line 46 of file player.cc.

MidiPlayer::~MidiPlayer | ( |  | ) |

| Destructor. Definition at line 59 of file player.cc. References removeSong().

## Member Function Documentation

int MidiPlayer::loadSong | ( | const char * | filename | ) |

| 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() . Definition at line 89 of file player.cc. References PlayerController::ratioTempo, and removeSong().

void MidiPlayer::removeSong | ( | void |  | ) |

| Unloads the current song, so that every internal variable is empty and clean for further usage. Definition at line 65 of file player.cc. References MidiFileInfo::ntracks. Referenced by loadSong(), and ~MidiPlayer().

int MidiPlayer::isSongLoaded | ( | void |  | ) | `[inline]`

| Returns true if there's a song already loaded (with a previous call to loadSong() ) and false if not. Definition at line 316 of file player.h.

SpecialEvent* MidiPlayer::specialEvents | ( |  | ) | `[inline]`

| Returns the linked list of SpecialEvents objects . For this to work, the parse should be enabled (the default), by using setParseSong(). Definition at line 322 of file player.h.

NoteArray* MidiPlayer::noteArray | ( | void |  | ) | `[inline]`

| 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 Definition at line 332 of file player.h.

void MidiPlayer::play | ( | bool | calloutput = false,
|  | void | output(void) = 0
| ) |

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:
  KMidSimpleAPI::kMidInit

  KMidSimpleAPI::kMidPlay

  KMidSimpleAPI::kMidStop

  KMidSimpleAPI::kMidDestruct

Definition at line 531 of file player.cc.

References MidiTrack::absMsOfNextEvent(), DeviceManager::allNotesOff(), PlayerController::beginmillisec, MidiTrack::changeTempo(), MidiEvent::chn, DeviceManager::chnController(), DeviceManager::chnPatchChange(), DeviceManager::chnPitchBender(), DeviceManager::chnPressure(), DeviceManager::closeDev(), MidiEvent::command, MidiEvent::ctl, MidiTrack::currentMs(), MidiEvent::d1, MidiEvent::d2, MidiEvent::d3, MidiEvent::data, PlayerController::den, PlayerController::error, PlayerController::ev, PlayerController::finished, PlayerController::forcepgm, PlayerController::gm, PlayerController::gotomsec, MidiTrack::init(), DeviceManager::initDev(), DeviceManager::keyPressure(), PlayerController::message, DeviceManager::midiPorts(), PlayerController::moving, MidiEvent::note, DeviceManager::noteOff(), DeviceManager::noteOn(), MidiFileInfo::ntracks, PlayerController::num, PlayerController::OK, DeviceManager::ok(), DeviceManager::openDev(), MidiEvent::patch, MidiFileInfo::patchesUsed, PlayerController::paused, PlayerController::pgm, PlayerController::playing, PlayerController::ratioTempo, MidiTrack::readEvent(), MidiStatus::sendData(), DeviceManager::setPatchesToUse(), setPos(), DeviceManager::setVolumePercentage(), PlayerController::SPEVplayed, DeviceManager::sync(), DeviceManager::synthDevices(), PlayerController::tempo, MidiFileInfo::ticksPerCuarterNote, PlayerController::ticksPlayed, MidiFileInfo::ticksTotal, PlayerController::ticksTotal, DeviceManager::tmrSetTempo(), DeviceManager::tmrStart(), DeviceManager::tmrStop(), MidiEvent::vel, PlayerController::volumepercentage, and DeviceManager::wait().

void MidiPlayer::setParseSong | ( | bool | b = true | ) |

| Enables or disables the parsing of the song when loading it. This affects the SpecialEvents (specialEvents() ) and the NoteArray (noteArray() ). Definition at line 927 of file player.cc.

void MidiPlayer::setGenerateBeats | ( | bool | b = false | ) |

| Enables or disables the generation of beats event in a song when loading it. Definition at line 932 of file player.cc.

MidiFileInfo* MidiPlayer::information | ( | void |  | ) | `[inline]`

Returns information about the current MIDI file.

See also:
  loadSong

Definition at line 374 of file player.h.

void MidiPlayer::setPos | ( | ulong | gotomsec,
|  | class MidiStatus * | midistat
| ) |

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.

Definition at line 795 of file player.cc.

References MidiTrack::absMsOfNextEvent(), MidiTrack::changeTempo(), MidiEvent::chn, MidiStatus::chnController(), MidiStatus::chnPatchChange(), MidiStatus::chnPitchBender(), MidiStatus::chnPressure(), MidiEvent::command, MidiEvent::ctl, MidiTrack::currentMs(), MidiEvent::d1, MidiEvent::d2, MidiEvent::d3, MidiEvent::data, PlayerController::den, PlayerController::forcepgm, MidiTrack::init(), MidiFileInfo::ntracks, PlayerController::num, MidiEvent::patch, PlayerController::pgm, PlayerController::ratioTempo, MidiTrack::readEvent(), PlayerController::SPEVplayed, PlayerController::tempo, MidiStatus::tmrSetTempo(), and MidiEvent::vel.

Referenced by play().

void MidiPlayer::setTempoRatio | ( | double | ratio | ) |

| Changes the speed at which a song is played. The song's tempo is multiplied by the specified ratio. Definition at line 937 of file player.cc. References PlayerController::ratioTempo, and PlayerController::tempo.

The documentation for this class was generated from the following files:

- player.h
- player.cc

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:28:39 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001