1 /**
2  * @file handler_audio.h
3  * @brief Handler of the sound and music
4  * @created 2004-03-22
5  * @date 2012-09-06
6  * @copyright 1991-2014 TLK Games
7  * @author Bruno Ethvignot
8  * @version $Revision: 24 $
9  */
10 /*
11  * copyright (c) 1991-2014 TLK Games all rights reserved
12  * $Id: handler_audio.h 24 2014-09-28 15:30:04Z bruno.ethvignot@gmail.com $
13  *
14  * TecnoballZ is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * TecnoballZ is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  * MA  02110-1301, USA.
28  */
29 //#define SOUNDISOFF if define, don't compile handler_audio.cc
30 #ifndef SOUNDISOFF
31 #ifndef __AUDIOMIXER__
32 #define __AUDIOMIXER__
33 #include <SDL/SDL.h>
34 #include <SDL/SDL_mixer.h>
35 #include <mikmod.h>
36 class handler_audio;
37 #include "tecnoballz.h"
38 
39 /** Module's positions in a area music */
40 typedef struct
41 {
42   /** First music of a bricks level */
43   Uint32 music_1;
44   /** Restart first music */
45   Uint32 music_1_loop;
46   /** Second music of a bricks level */
47   Uint32 music_2;
48   /** Restart second music */
49   Uint32 music_2_loop;
50   /** bricks level completed */
51   Uint32 level_completed;
52   /** Lost ball in bricks level */
53   Uint32 pos_losing;
54   /** Shop music */
55   Uint32 shop_music;
56 } musics_pos;
57 
58 class handler_audio:public virtual tecnoballz
59 {
60 private:
61     static const Uint32 VOLUME_INC = MIX_MAX_VOLUME / 16;
62 public:
63 
64 /* Differents portions in a area music */
65 typedef enum
66 { MUSIC_UNDIVIDED,
67   GAME_PORTION,
68   WIN_PORTION,
69   LOST_PORTION,
70   SHOP_PORTION,
71   MUSIC_IS_OFF
72 } MUSIC_PORTIONS;
73 
74 /** Enumeration of all the musics */
75 typedef enum
76 {
77   MUSICAREA1,
78   MUSICAREA2,
79   MUSICAREA3,
80   MUSICAREA4,
81   MUSICAREA5,
82   MUSICGUARD,
83   MUSICSCORE,
84   MUSICGOVER,
85   MUSICINTRO,
86   MUSICCONGR,
87   TERMIGATOR_MUSIC,
88   IN_GAME_MUSIC,
89   FRIDGE_IN_SPACE_MUSIC,
90   MON_LAPIN_MUSIC
91 } MUSIC_ENUM;
92 
93 /** Enumeration of all the sound effects */
94 typedef enum
95 { LOST_LIFE,
96   PADDLE_EXPLOSION,
97   EXTRA_LIFE,
98   /** Collect money or gem */
99   COLLECT_MONEY,
100   TILT_ALARM,
101   /** Collect penalty or bonus capsule */
102   COLLECT_CAPSULE,
103   /** Vocal "tecnoball" */
104   TECNOBALL,
105   SHIP_APPEAR,
106   /** Paddle transformation */
107   PADDLE_TRANSFORMATION,
108   GUARDIAN_FIRE,
109   PADDLE_FIRE,
110   /** Guardian's explosion */
111   BIG_EXPLOSION,
112   DESTROY_INDESTRUCTIBLE_BRICK,
113   SHIP_EXPLODE,
114   HIT_GUARDIAN,
115   HIT_SHIP,
116   HIT_INDESTRUCTIBLE_BRICK1,
117   HIT_INDESTRUCTIBLE_BRICK2,
118   BALL_HIT_PADDLE,
119   BALL_HIT_SIDE,
120   BALL_HIT_BRICK1,
121   BALL_HIT_BRICK2,
122   BALL_HIT_BRICK3,
123   BALL_HIT_BRICK4,
124   BALL_HIT_BRICK5,
125   EJECTOR_OUT,
126   ECJECTOR_IN,
127   NUM_OF_SOUNDS
128 } SOUNDS_ENUM;
129 
130 public:
131   /* true if SDL_mixer is enable */
132   static bool is_audio_enable;
133 
134 private:
135     handler_audio ();
136 public:
137    ~handler_audio ();
138   static handler_audio *get_instance ();
139   void stop_music ();
140   void play_music (Uint32 music_id);
141   void run ();
142   void play_level_music (Uint32 area_num, Uint32 level_num);
143   void play_shop_music (Uint32 area_num);
144   void play_win_music ();
145   void play_lost_music ();
146   void stop_lost_music ();
147   bool is_win_music_finished ();
148   Uint32 get_portion_music_played ();
149   void play_sound (Uint32 sound_num);
150   void disable_sound ();
151   void enable_sound ();
152 
153 private:
154   void sound_volume_ctrl ();
155   void query_spec ();
156   Uint32 area_music (Uint32);
157   void initialize ();
158   void control_music_position ();
159   void play_requested_sounds ();
160 
161 private:
162   static handler_audio *audio_singleton;
163   static char sounds_play[NUM_OF_SOUNDS];
164   static Mix_Chunk *sound_list[];
165   static const musics_pos ptMusicpos[];
166 
167 private:
168   /** Current area number (1 to 5) */
169   Uint32 area_number;
170   /** Current level number (1 to 12) */
171   Uint32 level_number;
172   /** Position of the first music of a bricks level
173    * in the Protraker module */
174   Sint32 music_1_position;
175   /** Position of the restart of the current music in
176    * the Protraker module */
177   Sint32 restart_position;
178   /** Position of the second music of a bricks level
179    * in the Protraker module */
180   Sint32 music_2_position;
181   /** Part of the music module currently played: GAME_PORTION,
182    * WIN_PORTION, LOST_PORTION or SHOP_PORTION */
183   Uint32 current_portion_music;
184   /** True if only the music must be played,
185    * and not the sound effects, during the phases of intro,
186    * shop and game over */
187   bool is_only_music;
188   /* True if the music is enabled
189    * [Ctrl] + [D] or [Ctrl +[S] keys toggle the music on and off */
190   bool is_music_enable;
191   /** True if sound effect are enabled. [Ctrl] + [F] or
192    * [Ctrl] + [S] keys toggle the sound effects on and off */
193   bool is_sound_enable;
194   /** Current music volume */
195   Uint32 music_volume;
196   /** Current audio channel volume */
197   Uint32 channels_volume;
198   /** Identifier of the current music loaded and played */
199   Sint32 current_music_id;
200   /** Pointer to the current music loaded and played */
201   Mix_Music *current_music;
202   /** Pointer to the Amiga song module (Protracker format) */
203   MODULE *song_module;
204   /** Size of all waves used for sounds effect */
205   Uint32 waves_size;
206   /** Current position in the Protraker module */
207   Sint32 song_pos;
208 
209 };
210 #endif
211 #endif
212