eMusicTrack Class Reference

#include <eMusicTrackSDLMixer.h>

Collaboration diagram for eMusicTrack:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 eMusicTrack ()
 eMusicTrack (const char *filename, bool isinstalled=false)
 ~eMusicTrack ()
void SetVolume (int newVolume)
int GetVolume ()
void Loop ()
tString const & GetFileName ()
bool Play ()
void Stop ()
void Next ()
void Previous ()
void Pause ()
void VolumeUp ()
void VolumeDown ()
void Mute ()
void Update ()
void SetDirty ()
bool LoadSong (tSong thesong)
void LoadPlaylist (const char *filename)
void SetPlaylist (int i)
void FadeOut ()
bool IsPlaying ()
bool HasSong ()
void UnloadSong ()
void MusicFinished ()

Static Public Attributes

static bool musicIsPlaying = 0
static eMusicTrackcurrentMusic = 0

Private Member Functions

void Init (bool isinstalled)
Mix_Music * LoadFile (const char *filename)
void LoadAATrack (tSong &thesong)
void LoadVorbisTrack (tSong &thesong)
void PlayCurrentSequence ()

Private Attributes

bool m_IsInstalled
int m_Volume
bool m_Loop
bool m_IsPlaying
int usePlaylist
bool m_isDirty
bool m_HasSong
bool m_SequenceChange
double m_Pos
std::map< tString, Mix_Music * >
::iterator 
m_SequencePos
Uint32 m_StartTime
tSong m_CurrentSong
std::map< tString, Mix_Music * > m_Tracklist
eSoundMixerm_mixer
tString m_Filename
Mix_Music * m_Music
Mix_MusicType m_MusicType
tPlayListm_Playlist


Detailed Description

Definition at line 60 of file eMusicTrackSDLMixer.h.


Constructor & Destructor Documentation

eMusicTrack::eMusicTrack (  ) 

Definition at line 40 of file eMusicTrackSDLMixer.cpp.

References currentMusic, and Init().

00040                          {
00041 #ifdef HAVE_LIBSDL_MIXER
00042     // Do nothing constructor
00043     if(! currentMusic) currentMusic = this;
00044     Init(true);
00045 #endif // DEDICATED
00046 }

Here is the call graph for this function:

eMusicTrack::eMusicTrack ( const char *  filename,
bool  isinstalled = false 
)

Definition at line 48 of file eMusicTrackSDLMixer.cpp.

References Init(), LoadSong(), and m_CurrentSong.

00048                                                                {
00049 #ifdef HAVE_LIBSDL_MIXER
00050     Init(isinstalled);
00051     // Load file
00052     tString musFile = tString(filename);
00053     m_CurrentSong = tSong(musFile);
00054     LoadSong( m_CurrentSong );
00055 #endif // DEDICATED
00056 }

Here is the call graph for this function:

eMusicTrack::~eMusicTrack (  ) 

Definition at line 71 of file eMusicTrackSDLMixer.cpp.

References m_Playlist, and m_Tracklist.

00071                           {
00072 #ifdef HAVE_LIBSDL_MIXER
00073     // Do nothing destructor
00074     std::map<tString, Mix_Music*>::iterator trackIter;
00075 
00076     for(trackIter = m_Tracklist.begin(); trackIter != m_Tracklist.end(); trackIter++) {
00077         Mix_FreeMusic( (*trackIter).second );
00078     }
00079 
00080     delete m_Playlist;
00081 #endif // DEDICATED
00082 }


Member Function Documentation

void eMusicTrack::SetVolume ( int  newVolume  )  [inline]

Definition at line 66 of file eMusicTrackSDLMixer.h.

00067 { m_Volume = newVolume; };

int eMusicTrack::GetVolume (  )  [inline]

Definition at line 67 of file eMusicTrackSDLMixer.h.

References m_Volume.

00067 { m_Volume = newVolume; };

void eMusicTrack::Loop (  )  [inline]

Definition at line 69 of file eMusicTrackSDLMixer.h.

References m_Loop.

00070 { m_Loop = true; };

tString const& eMusicTrack::GetFileName (  )  [inline]

Definition at line 71 of file eMusicTrackSDLMixer.h.

References m_Filename.

Referenced by eSoundMixer::GetCurrentSong().

00072 { return m_Filename; };

Here is the caller graph for this function:

bool eMusicTrack::Play (  ) 

Definition at line 195 of file eMusicTrackSDLMixer.cpp.

References currentMusic, FadeOut(), m_HasSong, m_IsPlaying, m_SequencePos, m_Tracklist, musicIsPlaying, and PlayCurrentSequence().

Referenced by Next(), Previous(), and eSoundMixer::Update().

00195                        {
00196 #ifdef HAVE_LIBSDL_MIXER
00197     //if(!m_HasSong) return false;
00198 
00199     // Fade out the song, if there's already one playing
00200     if(Mix_PlayingMusic() && !m_IsPlaying) {
00201         currentMusic->FadeOut();
00202     }
00203 
00204     m_SequencePos = m_Tracklist.begin();
00205 
00206     if(m_SequencePos == m_Tracklist.end()) {
00207         std::cout << "For some reason, this song has no tracks in the tracklist\n";
00208         musicIsPlaying = false;
00209         return false;
00210     } else {
00211         std::cout << "Should be playing the first sequence\n";
00212         m_HasSong = true;
00213         PlayCurrentSequence();
00214     }
00215 
00216 #endif
00217     return musicIsPlaying;
00218 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::Stop (  )  [inline]

Definition at line 74 of file eMusicTrackSDLMixer.h.

00075                 {
00076 #ifndef DEDICATED
00077         Mix_HaltMusic();
00078 #endif

void eMusicTrack::Next (  ) 

Definition at line 264 of file eMusicTrackSDLMixer.cpp.

References tPlayList::empty(), tPlayList::GetNextSong(), LoadSong(), m_CurrentSong, m_HasSong, m_isDirty, m_Playlist, m_Pos, and Play().

Referenced by Update(), and eSoundMixer::Update().

00264                        {
00265 #ifdef HAVE_LIBSDL_MIXER
00266     tSong newSong;
00267     tString musFile;
00268     int numTries = 0;
00269     bool foundSong = false;
00270 
00271     if(! m_Playlist->empty() ) {
00272         do {
00273             numTries++;
00274             m_CurrentSong = m_Playlist->GetNextSong();
00275             foundSong = LoadSong( m_CurrentSong );
00276         } while(!foundSong && numTries < 5);
00277         if(foundSong) {
00278             m_Pos = 0.0;
00279             m_HasSong = true;
00280             Play();
00281             m_isDirty = false;
00282         }
00283     }
00284 #endif
00285 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::Previous (  ) 

Definition at line 240 of file eMusicTrackSDLMixer.cpp.

References tPlayList::empty(), tPlayList::GetPreviousSong(), LoadSong(), m_CurrentSong, m_isDirty, m_Playlist, m_Pos, and Play().

00240                            {
00241 #ifdef HAVE_LIBSDL_MIXER
00242     tSong newSong;
00243     tString musFile;
00244     // const tPath& vpath = tDirectories::Data();
00245     int numTries = 0;
00246     bool foundSong = false;
00247 
00248     if(! m_Playlist->empty() ) {
00249         do {
00250             numTries++;
00251             m_CurrentSong = m_Playlist->GetPreviousSong();
00252             foundSong = LoadSong( m_CurrentSong );
00253         } while(!foundSong && numTries < 5);
00254         if(foundSong) {
00255             m_Pos = 0.0;
00256 
00257             Play();
00258             m_isDirty = false;
00259         }
00260     }
00261 #endif
00262 }

Here is the call graph for this function:

void eMusicTrack::Pause (  ) 

Definition at line 287 of file eMusicTrackSDLMixer.cpp.

00287                         {
00288 #ifdef HAVE_LIBSDL_MIXER
00289     if(Mix_PausedMusic()==0) {
00290         Mix_PauseMusic();
00291     } else {
00292         Mix_ResumeMusic();
00293     }
00294 #endif
00295 }

void eMusicTrack::VolumeUp (  ) 

Definition at line 297 of file eMusicTrackSDLMixer.cpp.

References m_Volume.

00297                            {
00298 #ifdef HAVE_LIBSDL_MIXER
00299     m_Volume += 5;
00300     if(m_Volume > MIX_MAX_VOLUME) m_Volume = MIX_MAX_VOLUME;
00301     Mix_VolumeMusic(m_Volume);
00302 #endif
00303 }

void eMusicTrack::VolumeDown (  ) 

Definition at line 305 of file eMusicTrackSDLMixer.cpp.

References m_Volume.

00305                              {
00306 #ifdef HAVE_LIBSDL_MIXER
00307     m_Volume -= 5;
00308     if(m_Volume < 0) m_Volume = 0;
00309     Mix_VolumeMusic(m_Volume);
00310 #endif
00311 }

void eMusicTrack::Mute (  ) 

void eMusicTrack::Update (  ) 

Definition at line 344 of file eMusicTrackSDLMixer.cpp.

References m_HasSong, m_isDirty, m_Playlist, m_SequenceChange, Next(), and PlayCurrentSequence().

Referenced by eSoundMixer::Update().

00344                          {
00345 #ifdef HAVE_LIBSDL_MIXER
00346     if(m_HasSong) {
00347         // First check to see if the sequence position has changed.  If so, start the
00348         // new track for it.
00349         if(m_SequenceChange==true) {
00350             PlayCurrentSequence();
00351             m_SequenceChange = false;
00352             std::cout << "Sequence change updating\n";
00353         }
00354         if(m_Playlist) {
00355             if(m_isDirty) {
00356                 Next();
00357             }
00358         }
00359     }
00360 #endif
00361 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::SetDirty (  ) 

Definition at line 338 of file eMusicTrackSDLMixer.cpp.

References m_isDirty.

Referenced by eSoundMixer::Update().

00338                            {
00339 #ifdef HAVE_LIBSDL_MIXER
00340     m_isDirty = true;
00341 #endif
00342 }

Here is the caller graph for this function:

bool eMusicTrack::LoadSong ( tSong  thesong  ) 

Definition at line 93 of file eMusicTrackSDLMixer.cpp.

References tString::GetFileMimeExtension(), LoadAATrack(), LoadFile(), LoadVorbisTrack(), tSong::location, m_Filename, m_HasSong, m_Music, m_Tracklist, and tSong::tracklist.

Referenced by eMusicTrack(), Next(), and Previous().

00093                                         {
00094 #ifdef HAVE_LIBSDL_MIXER
00095     tString extension;
00096     m_Filename = thesong.location;
00097 
00098     if(m_Music) Mix_FreeMusic(m_Music);
00099 
00100     extension = thesong.location.GetFileMimeExtension();
00101     if(extension == ".aatrack") {
00102         LoadAATrack(thesong);
00103     } else {
00104         LoadVorbisTrack(thesong);
00105     }
00106     std::map<tString, tString>::iterator trackIter;
00107 
00108     // const tPath& vpath = tDirectories::Data();
00109     tString basepath("music/");
00110     // Now load the tracks
00111     for(trackIter = thesong.tracklist.begin(); trackIter != thesong.tracklist.end(); trackIter++) {
00112         //if(m_IsInstalled) {
00113         //    tString tmpFile = (*trackIter).second;
00114         //    basepath = tString("music/") + tmpFile;
00115         //    basepath = vpath.GetReadPath(basepath);
00116         //} else {
00117         basepath = (*trackIter).second;
00118         //}
00119         m_Tracklist[(*trackIter).first] = LoadFile(basepath);
00120     }
00121     m_HasSong = true;
00122 #endif // DEDICATED
00123     return true;
00124 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::LoadPlaylist ( const char *  filename  ) 

Definition at line 325 of file eMusicTrackSDLMixer.cpp.

References tPlayList::empty(), tPlayList::LoadPlaylist(), m_Playlist, NULL, tPlayList::Randomize(), tPlayList::SetPlaylist(), and usePlaylist.

Referenced by eSoundMixer::LoadPlaylist().

00325                                                    {
00326 #ifdef HAVE_LIBSDL_MIXER
00327     if(m_Playlist != NULL) delete m_Playlist;
00328 
00329     m_Playlist = new tPlayList();
00330     m_Playlist->SetPlaylist(usePlaylist);
00331     if ( strlen(filename) > 0 )
00332         m_Playlist->LoadPlaylist(filename);
00333 
00334     if( !m_Playlist->empty()) m_Playlist->Randomize();
00335 #endif
00336 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::SetPlaylist ( int  i  )  [inline]

Definition at line 92 of file eMusicTrackSDLMixer.h.

References m_Playlist, tPlayList::SetPlaylist(), and usePlaylist.

Referenced by eSoundMixer::LoadPlaylist().

00093 { usePlaylist = i; if(m_Playlist) m_Playlist->SetPlaylist(i); };

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::FadeOut (  ) 

Definition at line 313 of file eMusicTrackSDLMixer.cpp.

References m_IsPlaying, m_Pos, and m_StartTime.

Referenced by Play(), and eSoundMixer::Update().

00313                           {
00314 #ifdef HAVE_LIBSDL_MIXER
00315     if(m_IsPlaying) {
00316         if(Mix_PlayingMusic()) {
00317             Mix_FadeOutMusic(200);
00318         }
00319     }
00320     m_Pos = (double) (SDL_GetTicks() - m_StartTime) / 1000.0;
00321     //std::cout << "Fading out music, pos: " << m_Pos << "\n";
00322 #endif // DEDICATED
00323 }

Here is the caller graph for this function:

bool eMusicTrack::IsPlaying (  )  [inline]

Definition at line 95 of file eMusicTrackSDLMixer.h.

Referenced by eSoundMixer::Update().

00096 { return m_IsPlaying; };

Here is the caller graph for this function:

bool eMusicTrack::HasSong (  )  [inline]

Definition at line 96 of file eMusicTrackSDLMixer.h.

References m_IsPlaying.

00096 { return m_IsPlaying; };

void eMusicTrack::UnloadSong (  ) 

Definition at line 84 of file eMusicTrackSDLMixer.cpp.

References m_HasSong, m_Music, m_Pos, and m_StartTime.

00084                              {
00085 #ifdef HAVE_LIBSDL_MIXER
00086     if(m_Music) Mix_FreeMusic(m_Music);
00087     m_Pos = 0.0;
00088     m_StartTime = 0;
00089     m_HasSong = false;
00090 #endif
00091 }

void eMusicTrack::MusicFinished (  ) 

Definition at line 182 of file eMusicTrackSDLMixer.cpp.

References m_mixer, m_SequenceChange, m_SequencePos, m_Tracklist, and eSoundMixer::SongFinished().

Referenced by eSoundMixer::SDLMusicFinished().

00182                                 {
00183 #ifdef HAVE_LIBSDL_MIXER
00184     m_SequencePos++;
00185 
00186     if(m_SequencePos == m_Tracklist.end()) {
00187         m_mixer->SongFinished();
00188         return;
00189     }
00190     m_SequenceChange = true;
00191     std::cout << "Sequence change\n";
00192 #endif
00193 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::Init ( bool  isinstalled  )  [private]

Definition at line 58 of file eMusicTrackSDLMixer.cpp.

References eSoundMixer::GetMixer(), m_HasSong, m_IsInstalled, m_Loop, m_mixer, m_Music, m_Playlist, m_SequencePos, m_Tracklist, m_Volume, NULL, and tNEW.

Referenced by eMusicTrack().

00058                                        {
00059 #ifdef HAVE_LIBSDL_MIXER
00060     m_IsInstalled = isinstalled;
00061     m_Music = NULL;
00062     m_Playlist = tNEW(tPlayList)();
00063     m_Loop = false;
00064     m_Volume = 100;
00065     m_HasSong = false;
00066     m_mixer = eSoundMixer::GetMixer();
00067     m_SequencePos = m_Tracklist.begin();
00068 #endif
00069 }

Here is the call graph for this function:

Here is the caller graph for this function:

Mix_Music * eMusicTrack::LoadFile ( const char *  filename  )  [private]

Definition at line 165 of file eMusicTrackSDLMixer.cpp.

References con, NULL, and tOutput::SetTemplateParameter().

Referenced by LoadSong().

00165                                                      {
00166     Mix_Music* theMusic = NULL;
00167 #ifdef HAVE_LIBSDL_MIXER
00168 
00169     theMusic = Mix_LoadMUS( filename );
00170     if(!theMusic) {
00171         //TODO: move error Handling else where?
00172         tOutput error;
00173         error.SetTemplateParameter(1 , filename );
00174         error.SetTemplateParameter(2 , SDL_GetError() );
00175         error << "$sound_error_unknown";
00176         con << error;
00177     }
00178 #endif // DEDICATED
00179     return theMusic;
00180 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::LoadAATrack ( tSong thesong  )  [private]

Definition at line 126 of file eMusicTrackSDLMixer.cpp.

References tSong::author, tSong::genre, tIniFile::GetGroup(), tIniFile::GetValue(), tSong::location, m_IsInstalled, tSong::record, tSong::sequence, tSong::title, tSong::tracklist, and tSong::year.

Referenced by LoadSong().

00126                                             {
00127 #ifdef HAVE_LIBSDL_MIXER
00128     tIniFile theFile(thesong.location);
00129     //theFile.Dump();
00130 
00131     thesong.author = theFile.GetValue("header", "author");
00132     thesong.year = theFile.GetValue("header", "year");
00133     thesong.record = theFile.GetValue("header", "record");
00134     thesong.title = theFile.GetValue("header", "title");
00135     thesong.genre = theFile.GetValue("header", "genre");
00136 
00137     tString isInstalledS = theFile.GetValue("header", "installed");
00138     if(isInstalledS == "yes") m_IsInstalled = true;
00139     else m_IsInstalled = false;
00140 
00141     std::cout << thesong.title << " by " << thesong.author << "\n";
00142     thesong.tracklist = theFile.GetGroup("tracks");
00143     thesong.sequence = theFile.GetGroup("sequence");
00144 #endif
00145 }

Here is the call graph for this function:

Here is the caller graph for this function:

void eMusicTrack::LoadVorbisTrack ( tSong thesong  )  [private]

Definition at line 148 of file eMusicTrackSDLMixer.cpp.

References tSong::author, tSong::genre, tSong::location, tSong::record, tSong::sequence, tSong::title, tSong::tracklist, and tSong::year.

Referenced by LoadSong().

00148                                                 {
00149 #ifdef HAVE_LIBSDL_MIXER
00150     // We set these so the same code can use tSong to play a song, but this track
00151     // is a single song, probably from the user's own playlist
00152     thesong.author = "Unknown";
00153     thesong.year = "Unknown";
00154     thesong.record = "Unknown";
00155     thesong.title = "Unknown";
00156     thesong.genre = "Unknown";
00157 
00158     thesong.tracklist[tString("only")] = thesong.location;
00159     thesong.sequence[tString("0")] = "only";
00160     std::cout << "Track: " << thesong.location << "\n";
00161     thesong.title = thesong.location;
00162 #endif
00163 }

Here is the caller graph for this function:

void eMusicTrack::PlayCurrentSequence (  )  [private]

Definition at line 220 of file eMusicTrackSDLMixer.cpp.

References currentMusic, m_HasSong, m_IsPlaying, m_Volume, and musicIsPlaying.

Referenced by Play(), and Update().

00220                                       {
00221 #ifdef HAVE_LIBSDL_MIXER
00222     int pmres;
00223     //if(!m_HasSong) return;
00224     pmres = Mix_PlayMusic((*m_SequencePos).second, 1);
00225 
00226     if( pmres == 0) {
00227         Mix_VolumeMusic(m_Volume);
00228         musicIsPlaying = true;
00229         m_IsPlaying = true;
00230         currentMusic = this;
00231         std::cout << "Playing the sequence\n";
00232     } else {
00233         std::cout << "Didn't play the sequence " << (*m_SequencePos).first << "\n";
00234         musicIsPlaying = false;
00235         m_HasSong = false;
00236     }
00237 #endif // DEDICATED
00238 }

Here is the caller graph for this function:


Member Data Documentation

bool eMusicTrack::musicIsPlaying = 0 [static]

Definition at line 99 of file eMusicTrackSDLMixer.h.

Referenced by Play(), and PlayCurrentSequence().

eMusicTrack * eMusicTrack::currentMusic = 0 [static]

Definition at line 102 of file eMusicTrackSDLMixer.h.

Referenced by eMusicTrack(), eSoundMixer::GetCurrentSong(), Play(), PlayCurrentSequence(), eSoundMixer::SDLMusicFinished(), and eSoundMixer::Update().

bool eMusicTrack::m_IsInstalled [private]

Definition at line 112 of file eMusicTrackSDLMixer.h.

Referenced by Init(), and LoadAATrack().

int eMusicTrack::m_Volume [private]

Definition at line 114 of file eMusicTrackSDLMixer.h.

Referenced by GetVolume(), Init(), PlayCurrentSequence(), VolumeDown(), and VolumeUp().

bool eMusicTrack::m_Loop [private]

Definition at line 115 of file eMusicTrackSDLMixer.h.

Referenced by Init(), and Loop().

bool eMusicTrack::m_IsPlaying [private]

Definition at line 117 of file eMusicTrackSDLMixer.h.

Referenced by FadeOut(), HasSong(), Play(), and PlayCurrentSequence().

int eMusicTrack::usePlaylist [private]

Definition at line 119 of file eMusicTrackSDLMixer.h.

Referenced by LoadPlaylist(), and SetPlaylist().

bool eMusicTrack::m_isDirty [private]

Definition at line 121 of file eMusicTrackSDLMixer.h.

Referenced by Next(), Previous(), SetDirty(), and Update().

bool eMusicTrack::m_HasSong [private]

Definition at line 123 of file eMusicTrackSDLMixer.h.

Referenced by Init(), LoadSong(), Next(), Play(), PlayCurrentSequence(), UnloadSong(), and Update().

bool eMusicTrack::m_SequenceChange [private]

Definition at line 125 of file eMusicTrackSDLMixer.h.

Referenced by MusicFinished(), and Update().

double eMusicTrack::m_Pos [private]

Definition at line 127 of file eMusicTrackSDLMixer.h.

Referenced by FadeOut(), Next(), Previous(), and UnloadSong().

std::map<tString, Mix_Music*>::iterator eMusicTrack::m_SequencePos [private]

Definition at line 128 of file eMusicTrackSDLMixer.h.

Referenced by Init(), MusicFinished(), and Play().

Uint32 eMusicTrack::m_StartTime [private]

Definition at line 129 of file eMusicTrackSDLMixer.h.

Referenced by FadeOut(), and UnloadSong().

tSong eMusicTrack::m_CurrentSong [private]

Definition at line 130 of file eMusicTrackSDLMixer.h.

Referenced by eMusicTrack(), Next(), and Previous().

std::map<tString, Mix_Music*> eMusicTrack::m_Tracklist [private]

Definition at line 132 of file eMusicTrackSDLMixer.h.

Referenced by Init(), LoadSong(), MusicFinished(), Play(), and ~eMusicTrack().

eSoundMixer* eMusicTrack::m_mixer [private]

Definition at line 133 of file eMusicTrackSDLMixer.h.

Referenced by Init(), and MusicFinished().

tString eMusicTrack::m_Filename [private]

Definition at line 136 of file eMusicTrackSDLMixer.h.

Referenced by GetFileName(), and LoadSong().

Mix_Music* eMusicTrack::m_Music [private]

Definition at line 137 of file eMusicTrackSDLMixer.h.

Referenced by Init(), LoadSong(), and UnloadSong().

Mix_MusicType eMusicTrack::m_MusicType [private]

Definition at line 138 of file eMusicTrackSDLMixer.h.

tPlayList* eMusicTrack::m_Playlist [private]

Definition at line 140 of file eMusicTrackSDLMixer.h.

Referenced by Init(), LoadPlaylist(), Next(), Previous(), SetPlaylist(), Update(), and ~eMusicTrack().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:26:28 2008 for Armagetron Advanced by  doxygen 1.5.4