sdlmusiclist.h

Go to the documentation of this file.
00001 /********************************************************************************/
00002 /*                                                                              */
00003 /*  Netrinjo-Engine - a library for game-development                            */
00004 /*  Copyright (C) 2005 by Tobias Nadler                                         */
00005 /*                                                                              */
00006 /*  This library is free software; you can redistribute it and/or               */
00007 /*  modify it under the terms of the GNU Lesser General Public                  */
00008 /*  License as published by the Free Software Foundation; either                */
00009 /*  version 2.1 of the License, or (at your option) any later version.          */
00010 /*                                                                              */
00011 /*  This library is distributed in the hope that it will be useful,             */
00012 /*  but WITHOUT ANY WARRANTY; without even the implied warranty of              */
00013 /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           */
00014 /*  Lesser General Public License for more details.                             */
00015 /*                                                                              */
00016 /*  You should have received a copy of the GNU Lesser General Public            */
00017 /*  License along with this library; if not, write to the Free Software         */
00018 /*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   */
00019 /*                                                                              */
00020 /********************************************************************************/
00021 
00022 #ifndef SDLMUSICLIST_H
00023 #define SDLMUSICLIST_H
00024 
00025 #include <vector>
00026 #include "SDL/SDL.h"
00027 
00028 using namespace std;
00029 
00030 class SdlMusic;
00031 class SdlAudio;
00032 
00049 class DECLSPEC SdlMusicInfo
00050 {
00051 public:
00060     DECLSPEC SdlMusicInfo( const char *fn, const char *title, const char *author, int secs = -1 );
00061     virtual DECLSPEC ~SdlMusicInfo();
00062 
00067     DECLSPEC void setFileName( const char *n );
00069     const char * getFileName()  { return chName; }
00070 
00075     DECLSPEC void setTitle( const char *t );
00077     const char * getTitle() { return chTitle; }
00078 
00083     DECLSPEC void setAuthor( const char *a );
00085     const char * getAuthor()    { return chAuthor; }
00086 
00091     void setLength( int l ) { nLength = l; }
00092 
00094     int numPlayed() { return nPlayed; }
00099     void played()   { ++nPlayed; }
00103     void reset()    { nPlayed = 0; }
00104 
00105 private:
00106     char *chName;// filename
00107     char *chTitle;
00108     char *chAuthor;
00109     int nPlayed;// how often it was played yet
00110     int nLength;// in seconds
00111 };
00112 
00113 
00114 
00129 class SdlMusicList
00130 {
00131 public:
00139     typedef void ( *CallBack )( SdlMusicList *, void * );
00147     enum PlayTypes{ptForward, ptBackward, ptShuffled/*don't play one twice until everyone has been played*/, ptRandom};
00148 
00153     DECLSPEC SdlMusicList( const char *name );
00154     virtual DECLSPEC ~SdlMusicList();
00155 
00157     const char *getName() const     { return chName; }
00163     DECLSPEC SdlMusic *getSong( unsigned int i );
00169     DECLSPEC SdlMusicInfo *getSongInfo( unsigned int i );
00171     unsigned int numSongs()         { return lSongs.size(); }
00172 
00179     DECLSPEC bool play( PlayTypes t = ptForward );
00181     DECLSPEC void stop();
00182 
00188     DECLSPEC void setVolume( int v );
00189 
00197     void setCallBack( CallBack c, void *data )  { cb = c; cbData = data; }
00198 
00203     bool isFailed()     { return bFailed; }
00204 
00205 protected:
00207     virtual DECLSPEC void failed();
00208 
00210     vector<SdlMusic *> lSongs;
00212     vector<SdlMusicInfo*> lInfos;
00213 
00214 private:
00215     bool playNext();
00216 
00217     bool bFailed;
00218     char *chName;
00219 
00220     PlayTypes ePlayType;
00221     bool bStopped;
00222 
00223     int nVolume;
00224 
00225     CallBack cb;
00226     void *cbData;
00227 
00228     int nCurrentSong;// ID of currently playing song
00229     SdlMusic *musPlaying;
00230     static inline void onFinished( SdlAudio *sender, void *data )
00231     {
00232         ((SdlMusicList*)data)->playNext();
00233     }
00234 };
00235 
00236 #endif

Generated on Wed May 9 17:35:55 2007 for netrinjo by  doxygen 1.5.1