Advanced Strategic Command
sound.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 #ifndef sound_h_included
12 #define sound_h_included
13 
14 #include "../ascstring.h"
15 #include "../music.h"
16 
17 
18 class Sound_InternalData;
19 
20 class Sound {
21  public:
28  Sound( const ASCString& filename, int fadeIn = 0 );
29  Sound( const ASCString& startSoundFilename, const ASCString& continuousSoundFilename, int fadeIn = 0 );
30 
31 
32  void play(void);
33  void playWait(void);
34 
35  void playLoop();
36  void stop();
37 
38  void fadeOut ( int ms );
39 
40  bool load();
41 
42  friend class SoundSystem;
43 
44  ~Sound(void);
45  private:
47  const ASCString name;
48 
50  int startPlaying( bool loop );
51 
52  void finishedSignal( int channelnum );
53 
54  Sound_InternalData* internalData;
55 
56  int fadeIn;
57  bool waitingForMainWave;
58 };
59 
60 
62 
63 class SoundSystem {
64  bool effectsMuted;
65  bool off;
66  bool sdl_initialized;
67  bool mix_initialized;
68  int musicVolume;
69  int effectVolume;
70 
71  static SoundSystem* instance;
72 
73  SoundSystem_InternalData* internalData;
74 
75 
77  static void trackFinished( void );
78 
79  void nextTrack ( void );
80 
81  static void channelFinishedCallback( int channelnum );
82 
83  enum MusicState { uninitialized, init_ready, init_paused, playing, paused } musicState;
84  protected:
85 
87  friend class Sound;
88 
89  public:
95  SoundSystem ( bool muteEffects, bool muteMusic, bool off );
96 
98  void setEffectsMute ( bool mute );
99 
101  bool areEffectsMuted ( ) { return effectsMuted || off; };
102 
104  bool isOff ( ) { return off; };
105 
107  void playMusic ( MusicPlayList* playlist );
108 
110  void pauseMusic();
111 
113  void resumeMusic();
114 
116  void resumePauseMusic();
117 
119  void setMusicVolume( int Volume );
120 
122  void setEffectVolume( int Volume );
123 
125  int getEffectVolume( ) { return effectVolume; };
126 
127  static SoundSystem* getInstance() { return instance; };
128 
130 
131  ~SoundSystem();
132 };
133 
134 #endif
void setEffectsMute(bool mute)
Turns the sound on and off.
Definition: sound.cpp:128
void play(void)
Definition: sound.cpp:453
void playMusic(MusicPlayList *playlist)
plays the pieces of music which are referenced in the playlist
Definition: sound.cpp:220
Definition: sound.h:20
void pauseMusic()
Pauses the music that is currently being played.
Definition: sound.cpp:227
void stop()
Definition: sound.cpp:471
A List containing several tracks of music.
Definition: music.h:19
bool areEffectsMuted()
can sounds be played right now ?
Definition: sound.h:101
~SoundSystem()
Definition: sound.cpp:285
void setMusicVolume(int Volume)
Sets the music volume. Range is 0 .. 100.
Definition: sound.cpp:264
ASCString getDiagnosticText()
Definition: sound.cpp:150
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void resumeMusic()
resumes the music
Definition: sound.cpp:238
SoundSystem(bool muteEffects, bool muteMusic, bool off)
Sets up ASC's sound system.
Definition: sound.cpp:59
static SoundSystem * getInstance()
Definition: sound.h:127
void playWait(void)
Definition: sound.cpp:480
Sound(const ASCString &filename, int fadeIn=0)
Create a Sound from the .wav file specified by filename.
Definition: sound.cpp:384
bool load()
int getEffectVolume()
Returns the sound effect volume. This is already normalized to the 0 .. 128 range of SDL_Mixer ! ...
Definition: sound.h:125
~Sound(void)
Definition: sound.cpp:510
void resumePauseMusic()
resumes or resumes the music, depending whether is music is paused or playing
Definition: sound.cpp:256
bool isOff()
is the soundsystem completely disabled ?
Definition: sound.h:104
void playLoop()
Definition: sound.cpp:462
void fadeOut(int ms)
Definition: sound.cpp:501
void setEffectVolume(int Volume)
Sets the sound effect volume. Range is 0 .. 100.
Definition: sound.cpp:274