File: sound.h

package info (click to toggle)
asc 2.1.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 59,052 kB
  • ctags: 25,676
  • sloc: cpp: 145,189; sh: 8,705; ansic: 5,564; makefile: 551; perl: 150
file content (134 lines) | stat: -rw-r--r-- 4,077 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/** This file provides the header for the Sound class */
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef sound_h_included
#define sound_h_included

#include "../ascstring.h"
#include "../music.h"


class Sound_InternalData;

class Sound {
   public:
     /** Create a Sound from the .wav file specified by filename.
      *  If it's not possible to use the wave file for some reason, the
      *  sound is set to silence.
      *  \param filename the file that is loaded
      *  \param fadeIn is a time in milliseconds
      */
     Sound( const ASCString& filename, int fadeIn = 0 );
     Sound( const ASCString& startSoundFilename, const ASCString& continuousSoundFilename, int fadeIn = 0 );


     void play(void);
     void playWait(void);

     void playLoop();
     void stop();

     void fadeOut ( int ms );

     bool load();

     friend class SoundSystem;

     ~Sound(void);
   private:
     /** A name for this sound - mostly for debugging purposes */
     const ASCString name;

     //! returns the channel
     int startPlaying( bool loop ); 

     void finishedSignal( int channelnum );

     Sound_InternalData* internalData;
     
     int fadeIn;
     bool waitingForMainWave;
};


class SoundSystem_InternalData;

class SoundSystem {
      bool effectsMuted;
      bool off;
      bool sdl_initialized;
      bool mix_initialized;
      int musicVolume;
      int effectVolume;

      static SoundSystem* instance;

      SoundSystem_InternalData* internalData;
      

      //! callback for SDL_mixer
      static void trackFinished( void );

      void nextTrack ( void );

      static void channelFinishedCallback( int channelnum );

      enum MusicState { uninitialized, init_ready, init_paused, playing, paused } musicState;
   protected:

      //! loads a sound from the wave file called name to an Mix_buffer.
      friend class Sound;

   public:
      /** Sets up ASC's sound system.
         \param muteEffects The sound is going to be initialized, but no sounds played. Sounds can be enabled at runtime
         \param muteMusic The sound is going to be initialized, but no music played. Music can be enabled at runtime
         \param off  The sound system is not even going to be initiliazed. Can only be restartet by restarting ASC
      */
      SoundSystem ( bool muteEffects, bool muteMusic, bool off );

      //! Turns the sound on and off
      void setEffectsMute ( bool mute );

      //! can sounds be played right now ?
      bool areEffectsMuted ( ) { return effectsMuted || off; };

      //! is the soundsystem completely disabled ?
      bool isOff ( ) { return off; };

      //! plays the pieces of music which are referenced in the playlist
      void playMusic ( MusicPlayList* playlist );

      //! Pauses the music that is currently being played
      void pauseMusic();

      //! resumes the music
      void resumeMusic();

      //! resumes or resumes the music, depending whether is music is paused or playing
      void resumePauseMusic();

      //! Sets the music volume. Range is 0 .. 100
      void setMusicVolume( int Volume );

      //! Sets the sound effect volume. Range is 0 .. 100
      void setEffectVolume( int Volume );

      //! Returns the sound effect volume. This is already normalized to the 0 .. 128 range of SDL_Mixer !
      int getEffectVolume( ) { return effectVolume; };

      static SoundSystem* getInstance() { return instance; };

      ASCString getDiagnosticText();

      ~SoundSystem();
};

#endif