src/engine/eSoundMixer.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "aa_config.h"
00029 
00030 #ifndef ArmageTron_SOUNDMIXER_H
00031 #define ArmageTron_SOUNDMIXER_H
00032 
00033 #include "rSDL.h"
00034 //#include "defs.h"
00035 // #include "eGrid.h"
00036 #include "tString.h"
00037 #include "tSafePTR.h"
00038 //#include "tLinkedList.h"
00039 #ifndef DEDICATED
00040 #include <SDL_mixer.h>
00041 #else
00042 // dummy types
00043 typedef int Mix_Chunk;
00044 typedef int Mix_Music;
00045 #endif
00046 #include "tPlayList.h"
00047 
00048 #include "sdl_mixer/eChannelSDLMixer.h"
00049 
00050 #include <deque>
00051 
00052 void se_SoundMenu();
00053 
00054 // This enum is likely temporary, and should be replaced with a proper map
00055 enum MusicMode {
00056     TITLE_TRACK, GUI_TRACK, GRID_TRACK
00057 };
00058 
00059 enum SoundEffect {
00060     CYCLE_TURN,
00061     CYCLE_EXPLOSION,
00062     ANNOUNCER_1,
00063     ANNOUNCER_2,
00064     ANNOUNCER_3,
00065     ANNOUNCER_GO,
00066     NEW_MATCH,
00067     NEW_ROUND,
00068     ROUND_WINNER,
00069     MATCH_WINNER,
00070     ZONE_SPAWN,
00071     CYCLE_MOTOR,
00072     CYCLE_GRIND_WALL
00073 };
00074 
00075 extern char const * MusicModeString[];
00076 extern char const * SoundEffectString[];
00077 
00078 // Forward declarations from other files
00079 class eGameObject;
00080 class eCoord;
00081 
00082 // Forward declarations from this file
00083 class eMusicTrack;
00084 class eChannel;
00085 
00086 /*******************************************************************************
00087  *
00088  * eSoundMixer
00089  *      The sound mixer.  Use this to play all sounds and music.  It should
00090  *      only ever be created once, and it does that automatically.
00091  *
00092  *******************************************************************************
00093  *
00094  *  Use this class with a simple construct:
00095  *     eSoundMixer* mixer = eSoundMixer::GetMixer();
00096  *     mixer->DoWhatEverYouWant();
00097  *
00098  *******************************************************************************/
00099 
00100 class eSoundMixer {
00101 
00102 public:
00103     ~eSoundMixer();
00104     // Use this function to get the instance of the sound mixer object
00105     //   If it doesn't exist, it will be created
00106     static eSoundMixer* GetMixer();
00107 
00108     static void ShutDown();
00109     void Init();
00110     // SetMode sets what music mode we're in.  Modes are TITLE_TRACK, GUI_TRACK,
00111     //    or GAME_TRACK
00112     static void SetMode(MusicMode newMode);
00113     void PushButton(int soundEffect);
00114     void PushButton(int soundEffect, eCoord location);
00115     // What type is velocity likely to be passed in as?  Do we need it for a pushbutton
00116     //   effect?  'velocity' is meant to be the velocity of the object making the sound,
00117     //   so we can doppler shift it.
00118     // void PushButton(int soundEffect, eCoord* location, velocity);
00119 
00120     void SetMicrophoneOwner(eGameObject* newOwner);
00121 
00122     void PlayContinuous(int soundEffect, eGameObject* owner);
00123     void RemoveContinuous(int soundEffect, eGameObject* owner);
00124 
00125     // Callback for SDL_Mixer to call when a file is finished playing
00126     // It just passes down the line to the current track
00127     static void SDLMusicFinished();
00128 
00129     // Callback for an eMusicTrack to call when a song is finished playing
00130     // This is where the real work is done to handle when a song is finished
00131     static void SongFinished();
00132 
00133     static bool Music_play(REAL x);
00134     static bool Music_next_song(REAL x);
00135     static bool Music_previous_song(REAL x);
00136     static bool Music_stop(REAL x);
00137     static bool Music_pause(REAL x);
00138     static bool Music_volume_up(REAL x);
00139     static bool Music_volume_down(REAL x);
00140 
00141     void LoadPlaylist();
00142 
00143     tString GetCurrentSong();
00144 
00145     // Callback for SDL_Mixer to call when any channel is finished playing
00146     static void ChannelFinished(int channel);
00147 private:
00148     void __channelFinished(int channel);
00149 
00150 public:
00151     // Call this method from the game loop to check if the mixer needs to do anything
00152     void Update();
00153 private:
00154     // Gets the first available channel
00155     int FirstAvailableChannel();
00156 
00157     static eSoundMixer* _instance;
00158     bool sound_is_there;
00159     SDL_AudioSpec audio;
00160 
00161     static int m_Mode;
00162     tJUST_CONTROLLED_PTR< eGameObject > m_Owner;
00163 
00164     // Use m_isDirty to indicate a mode change.  The update() method will pick up the
00165     //    change.  This should be handled automatically by SetMode()
00166     static bool m_isDirty;
00167     // m_PlayMusic is a flag to disable music specifically
00168     bool m_PlayMusic;
00169     // m_active is a flag to disable sound effects specifically
00170     bool m_active;
00171 
00172     tSong m_CurrentSong;
00173     tPlayList* m_Playlist;
00174 
00175     std::deque<eWavData> m_SoundEffects;
00176     std::deque<eChannel> m_Channels;
00177     int m_numChannels;
00178 
00179     static eMusicTrack* m_TitleTrack;
00180     static eMusicTrack* m_GuiTrack;
00181     static eMusicTrack* m_GameTrack;
00182 
00183     // Used for the music track, when a song ends, mark m_isDirty true.  Then, when
00184     //   you start playing a new song, mark it false.
00185     static bool m_musicIsPlaying;
00186 
00187     // Nobody should ever construct this thing on its own
00188     eSoundMixer();
00189 };
00190 
00191 #endif
00192 
00193 
00194 

Generated on Sat Mar 15 22:55:47 2008 for Armagetron Advanced by  doxygen 1.5.4