\section{Midi\-Player Class Reference}
\label{classMidiPlayer}\index{MidiPlayer@{MidiPlayer}}
MIDI file player routines . The MIDI file player engine.  


{\tt \#include $<$player.h$>$}

Collaboration diagram for Midi\-Player:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=312pt]{classMidiPlayer__coll__graph}
\end{center}
\end{figure}
\subsection*{Public Member Functions}
\begin{CompactItemize}
\item 
{\bf Midi\-Player} ({\bf Device\-Manager} $\ast$midi\_\-, {\bf Player\-Controller} $\ast$pctl)
\begin{CompactList}\small\item\em Constructor . \item\end{CompactList}\item 
{\bf $\sim$Midi\-Player} ()
\begin{CompactList}\small\item\em Destructor. \item\end{CompactList}\item 
int {\bf load\-Song} (const  char $\ast$filename)
\begin{CompactList}\small\item\em Loads a Song, and parses it (it the parse wasn't disabled with {\bf set\-Parse\-Song}{\rm (p.\,\pageref{classMidiPlayer_a8})}() ) . \item\end{CompactList}\item 
void {\bf remove\-Song} (void)
\begin{CompactList}\small\item\em Unloads the current song, so that every internal variable is empty and clean for further usage. \item\end{CompactList}\item 
int {\bf is\-Song\-Loaded} (void)
\begin{CompactList}\small\item\em Returns true if there's a song already loaded (with a previous call to {\bf load\-Song}{\rm (p.\,\pageref{classMidiPlayer_a2})}() ) and false if not. \item\end{CompactList}\item 
{\bf Special\-Event} $\ast$ {\bf special\-Events} ()
\begin{CompactList}\small\item\em Returns the linked list of Special\-Events objects . \item\end{CompactList}\item 
{\bf Note\-Array} $\ast$ {\bf note\-Array} (void)
\begin{CompactList}\small\item\em Returns and array with the notes playen through the song . \item\end{CompactList}\item 
void {\bf play} (bool calloutput=false, void output(void)=0)
\begin{CompactList}\small\item\em Plays the song using the {\bf Device\-Manager}{\rm (p.\,\pageref{classDeviceManager})} object supplied in the constructor. \item\end{CompactList}\item 
void {\bf set\-Parse\-Song} (bool b=true)
\begin{CompactList}\small\item\em Enables or disables the parsing of the song when loading it. \item\end{CompactList}\item 
void {\bf set\-Generate\-Beats} (bool b=false)
\begin{CompactList}\small\item\em Enables or disables the generation of beats event in a song when loading it. \item\end{CompactList}\item 
{\bf Midi\-File\-Info} $\ast$ {\bf information} (void)
\begin{CompactList}\small\item\em Returns information about the current MIDI file. \item\end{CompactList}\item 
void {\bf set\-Pos} ({\bf ulong} gotomsec, class {\bf Midi\-Status} $\ast$midistat)
\begin{CompactList}\small\item\em Sets the position in a song. \item\end{CompactList}\item 
void {\bf set\-Tempo\-Ratio} (double ratio)
\begin{CompactList}\small\item\em Changes the speed at which a song is played. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
MIDI file player routines . The MIDI file player engine. 

This class reads a MIDI file and play it using a {\bf Device\-Manager}{\rm (p.\,\pageref{classDeviceManager})} object.

To use it, just call {\bf load\-Song}{\rm (p.\,\pageref{classMidiPlayer_a2})}() with the filename you want to play, and then {\bf play}{\rm (p.\,\pageref{classMidiPlayer_a7})}().

Please have a look at the note in the {\bf play}{\rm (p.\,\pageref{classMidiPlayer_a7})}() documentation.

Midi\-Player will write information about the playing process on a {\bf Player\-Controller}{\rm (p.\,\pageref{structPlayerController})}() 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.

\begin{Desc}
\item[See also:]{\bf KMid\-Simple\-API}{\rm (p.\,\pageref{classKMidSimpleAPI})}\end{Desc}


\begin{Desc}
\item[Version:]0.9.5 17/01/2000 \end{Desc}
\begin{Desc}
\item[Author:]Antonio Larrosa Jimenez $<${\tt larrosa@kde.org}$>$ \end{Desc}




Definition at line 259 of file player.h.

\subsection{Constructor \& Destructor Documentation}
\index{MidiPlayer@{Midi\-Player}!MidiPlayer@{MidiPlayer}}
\index{MidiPlayer@{MidiPlayer}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Midi\-Player::Midi\-Player ({\bf Device\-Manager} $\ast$ {\em midi\_\-}, {\bf Player\-Controller} $\ast$ {\em pctl})}\label{classMidiPlayer_a0}


Constructor . 

You must construct and pass a {\bf Device\-Manager}{\rm (p.\,\pageref{classDeviceManager})} object and a {\bf Player\-Controller}{\rm (p.\,\pageref{structPlayerController})} structure. None of them will be destroyed by this object, so you should do it after destroying the Midi\-Player object. 

Definition at line 46 of file player.cc.\index{MidiPlayer@{Midi\-Player}!~MidiPlayer@{$\sim$MidiPlayer}}
\index{~MidiPlayer@{$\sim$MidiPlayer}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}Midi\-Player::$\sim${\bf Midi\-Player} ()}\label{classMidiPlayer_a1}


Destructor. 



Definition at line 59 of file player.cc.

References remove\-Song().

\subsection{Member Function Documentation}
\index{MidiPlayer@{Midi\-Player}!loadSong@{loadSong}}
\index{loadSong@{loadSong}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Midi\-Player::load\-Song (const char $\ast$ {\em filename})}\label{classMidiPlayer_a2}


Loads a Song, and parses it (it the parse wasn't disabled with {\bf set\-Parse\-Song}{\rm (p.\,\pageref{classMidiPlayer_a8})}() ) . 

It also generates the Beat events (see {\bf Special\-Event::type}{\rm (p.\,\pageref{structSpecialEvent_o4})}() ) if you enabled this by using {\bf set\-Generate\-Beats}{\rm (p.\,\pageref{classMidiPlayer_a9})}() . 

Definition at line 89 of file player.cc.

References Player\-Controller::ratio\-Tempo, and remove\-Song().\index{MidiPlayer@{Midi\-Player}!removeSong@{removeSong}}
\index{removeSong@{removeSong}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Midi\-Player::remove\-Song (void)}\label{classMidiPlayer_a3}


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 Midi\-File\-Info::ntracks.

Referenced by load\-Song(), and $\sim$Midi\-Player().\index{MidiPlayer@{Midi\-Player}!isSongLoaded@{isSongLoaded}}
\index{isSongLoaded@{isSongLoaded}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}int Midi\-Player::is\-Song\-Loaded (void)\hspace{0.3cm}{\tt  [inline]}}\label{classMidiPlayer_a4}


Returns true if there's a song already loaded (with a previous call to {\bf load\-Song}{\rm (p.\,\pageref{classMidiPlayer_a2})}() ) and false if not. 



Definition at line 316 of file player.h.\index{MidiPlayer@{Midi\-Player}!specialEvents@{specialEvents}}
\index{specialEvents@{specialEvents}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Special\-Event}$\ast$ Midi\-Player::special\-Events ()\hspace{0.3cm}{\tt  [inline]}}\label{classMidiPlayer_a5}


Returns the linked list of Special\-Events objects . 

For this to work, the parse should be enabled (the default), by using {\bf set\-Parse\-Song}{\rm (p.\,\pageref{classMidiPlayer_a8})}(). 

Definition at line 322 of file player.h.\index{MidiPlayer@{Midi\-Player}!noteArray@{noteArray}}
\index{noteArray@{noteArray}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Note\-Array}$\ast$ Midi\-Player::note\-Array (void)\hspace{0.3cm}{\tt  [inline]}}\label{classMidiPlayer_a6}


Returns and array with the notes playen through the song . 

Midi\-Player 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 {\bf Note\-Array}{\rm (p.\,\pageref{classNoteArray})} object 

Definition at line 332 of file player.h.\index{MidiPlayer@{Midi\-Player}!play@{play}}
\index{play@{play}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Midi\-Player::play (bool {\em calloutput} = false, void  {\em output}(void) = 0)}\label{classMidiPlayer_a7}


Plays the song using the {\bf Device\-Manager}{\rm (p.\,\pageref{classDeviceManager})} 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 {\bf Player\-Controller}{\rm (p.\,\pageref{structPlayerController})} 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 {\bf KMid\-Simple\-API::k\-Mid\-Play}{\rm (p.\,\pageref{classKMidSimpleAPI_e2})}() function.

\begin{Desc}
\item[See also:]{\bf KMid\-Simple\-API::k\-Mid\-Init}{\rm (p.\,\pageref{classKMidSimpleAPI_e0})} 

{\bf KMid\-Simple\-API::k\-Mid\-Play}{\rm (p.\,\pageref{classKMidSimpleAPI_e2})} 

{\bf KMid\-Simple\-API::k\-Mid\-Stop}{\rm (p.\,\pageref{classKMidSimpleAPI_e3})} 

{\bf KMid\-Simple\-API::k\-Mid\-Destruct}{\rm (p.\,\pageref{classKMidSimpleAPI_e4})} \end{Desc}


Definition at line 531 of file player.cc.

References Midi\-Track::abs\-Ms\-Of\-Next\-Event(), Device\-Manager::all\-Notes\-Off(), Player\-Controller::beginmillisec, Midi\-Track::change\-Tempo(), Midi\-Event::chn, Device\-Manager::chn\-Controller(), Device\-Manager::chn\-Patch\-Change(), Device\-Manager::chn\-Pitch\-Bender(), Device\-Manager::chn\-Pressure(), Device\-Manager::close\-Dev(), Midi\-Event::command, Midi\-Event::ctl, Midi\-Track::current\-Ms(), Midi\-Event::d1, Midi\-Event::d2, Midi\-Event::d3, Midi\-Event::data, Player\-Controller::den, Player\-Controller::error, Player\-Controller::ev, Player\-Controller::finished, Player\-Controller::forcepgm, Player\-Controller::gm, Player\-Controller::gotomsec, Midi\-Track::init(), Device\-Manager::init\-Dev(), Device\-Manager::key\-Pressure(), Player\-Controller::message, Device\-Manager::midi\-Ports(), Player\-Controller::moving, Midi\-Event::note, Device\-Manager::note\-Off(), Device\-Manager::note\-On(), Midi\-File\-Info::ntracks, Player\-Controller::num, Player\-Controller::OK, Device\-Manager::ok(), Device\-Manager::open\-Dev(), Midi\-Event::patch, Midi\-File\-Info::patches\-Used, Player\-Controller::paused, Player\-Controller::pgm, Player\-Controller::playing, Player\-Controller::ratio\-Tempo, Midi\-Track::read\-Event(), Midi\-Status::send\-Data(), Device\-Manager::set\-Patches\-To\-Use(), set\-Pos(), Device\-Manager::set\-Volume\-Percentage(), Player\-Controller::SPEVplayed, Device\-Manager::sync(), Device\-Manager::synth\-Devices(), Player\-Controller::tempo, Midi\-File\-Info::ticks\-Per\-Cuarter\-Note, Player\-Controller::ticks\-Played, Midi\-File\-Info::ticks\-Total, Player\-Controller::ticks\-Total, Device\-Manager::tmr\-Set\-Tempo(), Device\-Manager::tmr\-Start(), Device\-Manager::tmr\-Stop(), Midi\-Event::vel, Player\-Controller::volumepercentage, and Device\-Manager::wait().\index{MidiPlayer@{Midi\-Player}!setParseSong@{setParseSong}}
\index{setParseSong@{setParseSong}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Midi\-Player::set\-Parse\-Song (bool {\em b} = true)}\label{classMidiPlayer_a8}


Enables or disables the parsing of the song when loading it. 

This affects the Special\-Events ({\bf special\-Events}{\rm (p.\,\pageref{classMidiPlayer_a5})}() ) and the {\bf Note\-Array}{\rm (p.\,\pageref{classNoteArray})} ({\bf note\-Array}{\rm (p.\,\pageref{classMidiPlayer_a6})}() ). 

Definition at line 927 of file player.cc.\index{MidiPlayer@{Midi\-Player}!setGenerateBeats@{setGenerateBeats}}
\index{setGenerateBeats@{setGenerateBeats}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Midi\-Player::set\-Generate\-Beats (bool {\em b} = false)}\label{classMidiPlayer_a9}


Enables or disables the generation of beats event in a song when loading it. 



Definition at line 932 of file player.cc.\index{MidiPlayer@{Midi\-Player}!information@{information}}
\index{information@{information}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}{\bf Midi\-File\-Info}$\ast$ Midi\-Player::information (void)\hspace{0.3cm}{\tt  [inline]}}\label{classMidiPlayer_a10}


Returns information about the current MIDI file. 

\begin{Desc}
\item[See also:]{\bf load\-Song}{\rm (p.\,\pageref{classMidiPlayer_a2})} \end{Desc}


Definition at line 374 of file player.h.\index{MidiPlayer@{Midi\-Player}!setPos@{setPos}}
\index{setPos@{setPos}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Midi\-Player::set\-Pos ({\bf ulong} {\em gotomsec}, class {\bf Midi\-Status} $\ast$ {\em midistat})}\label{classMidiPlayer_a11}


Sets the position in a song. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gotomsec}]the number of milliseconds to go to . A subsequent call to {\bf play}{\rm (p.\,\pageref{classMidiPlayer_a7})}() will start playing the song from that moment, instead of the beginning. \item[{\em midistat}]a {\bf Midi\-Status}{\rm (p.\,\pageref{classMidiStatus})} 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. \end{description}
\end{Desc}


Definition at line 795 of file player.cc.

References Midi\-Track::abs\-Ms\-Of\-Next\-Event(), Midi\-Track::change\-Tempo(), Midi\-Event::chn, Midi\-Status::chn\-Controller(), Midi\-Status::chn\-Patch\-Change(), Midi\-Status::chn\-Pitch\-Bender(), Midi\-Status::chn\-Pressure(), Midi\-Event::command, Midi\-Event::ctl, Midi\-Track::current\-Ms(), Midi\-Event::d1, Midi\-Event::d2, Midi\-Event::d3, Midi\-Event::data, Player\-Controller::den, Player\-Controller::forcepgm, Midi\-Track::init(), Midi\-File\-Info::ntracks, Player\-Controller::num, Midi\-Event::patch, Player\-Controller::pgm, Player\-Controller::ratio\-Tempo, Midi\-Track::read\-Event(), Player\-Controller::SPEVplayed, Player\-Controller::tempo, Midi\-Status::tmr\-Set\-Tempo(), and Midi\-Event::vel.

Referenced by play().\index{MidiPlayer@{Midi\-Player}!setTempoRatio@{setTempoRatio}}
\index{setTempoRatio@{setTempoRatio}!MidiPlayer@{Midi\-Player}}
\subsubsection{\setlength{\rightskip}{0pt plus 5cm}void Midi\-Player::set\-Tempo\-Ratio (double {\em ratio})}\label{classMidiPlayer_a12}


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 Player\-Controller::ratio\-Tempo, and Player\-Controller::tempo.

The documentation for this class was generated from the following files:\begin{CompactItemize}
\item 
player.h\item 
player.cc\end{CompactItemize}
