sdlfilesound.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 SDLFILESOUND_H
00023 #define SDLFILESOUND_H
00024 
00025 #include <list>
00026 #include "sdlaudio.h"
00027 #include "SDL/SDL_mixer.h"
00028 
00029 using namespace std;
00030 
00045 class DECLSPEC SdlSound : public SdlAudio
00046 {
00047 public:
00053     DECLSPEC SdlSound( const char *name );
00054     virtual DECLSPEC ~SdlSound();
00055 
00056     virtual DECLSPEC int play( int loops = 0 );
00057     virtual DECLSPEC int fadeIn( int ms, int loops = 0 );
00058     virtual DECLSPEC bool isPlaying();
00059     virtual DECLSPEC void pause();
00060     virtual DECLSPEC bool isPaused();
00061     virtual DECLSPEC void resume();
00062     virtual DECLSPEC void stop();
00063     virtual DECLSPEC int fadeOut( int ms );
00064     virtual DECLSPEC Mix_Fading fadeStatus();
00065 
00066     virtual DECLSPEC void setVolume( int v );
00067     virtual int getVolume() { return nVolume; }
00068 
00069     virtual DECLSPEC int getChannel();
00070 
00071     virtual bool isMusic()  { return false; }
00072 
00079     static DECLSPEC void setGlbVolume( int v );
00080 protected:
00086     DECLSPEC void destroy();
00087 
00089     Mix_Chunk *mixSound;
00091     int nChannel;
00093     int nVolume;
00094 
00096     static int g_nVolume;
00098     static list<SdlSound*> lPlayingSounds;
00104     static void onChannelFinished( int channel )
00105     {
00106         for( list<SdlSound*>::iterator i = lPlayingSounds.begin(); i != lPlayingSounds.end(); ++i )
00107             if( !(*i)->nChannel == channel )    {
00108                 (*i)->nChannel = -1;
00109                 if( (*i)->cb )
00110                     (*(*i)->cb)( *i, (*i)->cbData );
00111 
00112                 lPlayingSounds.erase( i );
00113                 break;
00114             }
00115     }
00116 };
00117 
00118 
00127 class DECLSPEC SdlFileSound : public SdlSound
00128 {
00129 public:
00138     DECLSPEC SdlFileSound( const char *fn, const char *name = 0 );
00139     virtual DECLSPEC ~SdlFileSound();
00140 
00147     DECLSPEC bool load( const char *fn );
00148 };
00149 
00150 #endif

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