1 /* Tower Toppler - Nebulus
2  * Copyright (C) 2000-2012  Andreas Röver
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  */
18 
19 #ifndef SOUNDSYS_H
20 #define SOUNDSYS_H
21 
22 #ifdef HAVE_LIBSDL_MIXER
23 #include <SDL_mixer.h>
24 #else
25 #define MIX_MAX_VOLUME 0
26 #endif
27 
28 #ifdef HAVE_LIBSDL_MIXER
29 struct ttsnddat {
30   bool in_use; //is this datablock in use (sndfile is loaded)
31   bool play;   //is this block goind to get played next time?
32   int id_num;  //unique ID # of this sound
33   int channel; //sound channel
34   int volume;  //sound volume
35   int loops;   //how many times to loop this sound?
36   Mix_Chunk *sound; //sound data
37 };
38 #endif
39 
40 class ttsounds {
41 public:
42   ~ttsounds(void);
43 
44   void addsound(const char *fname, int id, int vol, int loops);
45 
46   void play(void); //play all active sounds
47   void stop(void); //stop all sounds
48 
49   void stopsound(int snd); //stop the sound from playing
50   void startsound(int snd); //the sound will play in the next update
51   void setsoundvol(int snd, int vol); //set sound volume
52 
53   void playmusic(const char * file); //start playing a background music
54   void stopmusic(void);            // stop playing the background music
55   void fadeToVol(int vol);
56 
57   /* tries to open and initialize the sound device */
58   void opensound(void);
59   /* closes the sound device */
60   void closesound(void);
61 
62   /* singleton function, use this function to access the one and only
63    * instance of this class
64    */
65   static ttsounds * instance(void);
66 
67 private:
68   ttsounds(void);
69 
70 #ifdef HAVE_LIBSDL_MIXER
71   /* this var is only true, if we the user wants sound, and wa
72    * can init it
73    */
74   bool useSound;
75 
76   int n_sounds; // # of sounds allocated
77   struct ttsnddat *sounds;
78 
79   Mix_Music * title;
80   int musicVolume;
81 #endif
82 
83   static class ttsounds *inst;
84 
85 };
86 
87 #endif
88