diff --git a/stepmania/src/RageMusic.cpp b/stepmania/src/RageMusic.cpp new file mode 100644 index 0000000000..c46fa2b34a --- /dev/null +++ b/stepmania/src/RageMusic.cpp @@ -0,0 +1,65 @@ +/* This is just a simple wrapper to handle a single music track conveniently. */ +#include "global.h" +#include "RageMusic.h" +#include "RageSound.h" + +RageMusic::RageMusic() +{ + music = new RageSound; +} + +RageMusic::~RageMusic() +{ + delete music; +} + + +CString RageMusic::GetPath() const +{ + return music->GetLoadedFilePath(); +} + +void RageMusic::Play(CString file, bool force_loop, float start_sec, float length_sec, float fade_len) +{ +// LOG->Trace("play '%s' (current '%s')", file.c_str(), music->GetLoadedFilePath().c_str()); + if(music->IsPlaying()) + { + if( music->GetLoadedFilePath() == file ) + return; // do nothing + + music->StopPlaying(); + } + + /* If file is blank, just stop. */ + if(file.empty()) + { + music->Unload(); + return; + } + + music->Load( file, false ); + if( force_loop ) + music->SetStopMode( RageSound::M_LOOP ); + + if(start_sec == -1) + music->SetStartSeconds(); + else + music->SetStartSeconds(start_sec); + + if(length_sec == -1) + music->SetLengthSeconds(); + else + music->SetLengthSeconds(length_sec); + + music->SetFadeLength(fade_len); + music->SetPositionSeconds(); + music->StartPlaying(); +} + +/* +----------------------------------------------------------------------------- + Copyright (c) 2002-2003 by the person(s) listed below. All rights reserved. + Glenn Maynard +----------------------------------------------------------------------------- +*/ + diff --git a/stepmania/src/RageMusic.h b/stepmania/src/RageMusic.h new file mode 100644 index 0000000000..37b7c6fbfe --- /dev/null +++ b/stepmania/src/RageMusic.h @@ -0,0 +1,18 @@ +#ifndef RAGE_MUSIC_H + +class RageSound; +class RageMusic +{ + RageSound *music; + +public: + RageMusic(); + ~RageMusic(); + + void Play(CString file, bool force_loop = false, float start_sec = -1, float length_sec = -1, float fade_len = 0); + void Stop() { Play(""); } + CString GetPath() const; +}; + +extern RageMusic *MUSIC; +#endif