1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GRIM_IMUSE_H
24 #define GRIM_IMUSE_H
25 
26 #include "common/mutex.h"
27 
28 #include "engines/grim/imuse/imuse_track.h"
29 
30 namespace Grim {
31 
32 #define MAX_IMUSE_TRACKS 16
33 #define MAX_IMUSE_FADETRACKS 16
34 
35 struct ImuseTable;
36 class SaveGame;
37 
38 class Imuse {
39 private:
40 
41 	int _callbackFps;
42 
43 	Track *_track[MAX_IMUSE_TRACKS + MAX_IMUSE_FADETRACKS];
44 
45 	Common::Mutex _mutex;
46 	ImuseSndMgr *_sound;
47 
48 	bool _pause;
49 	bool _demo;
50 
51 	int32 _attributes[185];
52 	int32 _curMusicState;
53 	int32 _curMusicSeq;
54 
55 	const ImuseTable *_stateMusicTable;
56 	const ImuseTable *_seqMusicTable;
57 
58 	int32 makeMixerFlags(int32 flags);
59 	static void timerHandler(void *refConf);
60 	void callback();
61 	void switchToNextRegion(Track *track);
62 	int allocSlot(int priority);
63 	void selectVolumeGroup(const char *soundName, int volGroupId);
64 
65 	void fadeOutMusic(int fadeDelay);
66 	void fadeOutMusicAndStartNew(int fadeDelay, const char *filename, int hookId, int vol, int pan);
67 	Track *cloneToFadeOutTrack(Track *track, int fadeDelay);
68 
69 	void playMusic(const ImuseTable *table, int atribPos, bool sequence);
70 
71 	void flushTrack(Track *track);
72 
73 public:
74 	Imuse(int fps, bool demo);
75 	~Imuse();
76 
77 	bool startSound(const char *soundName, int volGroupId, int hookId, int volume, int pan, int priority, Track *otherTrack);
78 	bool startVoice(const char *soundName, int volume = 127, int pan = 64);
79 	void startMusic(const char *soundName, int hookId, int volume, int pan);
80 	void startMusicWithOtherPos(const char *soundName, int hookId, int volume, int pan, Track *otherTrack);
81 	void startSfx(const char *soundName, int priority = 127);
82 
83 	void restoreState(SaveGame *savedState);
84 	void saveState(SaveGame *savedState);
85 	void resetState();
86 
87 	Track *findTrack(const char *soundName);
88 	void setPriority(const char *soundName, int priority);
89 	void setVolume(const char *soundName, int volume);
90 	int getVolume(const char *soundName);
91 	void setPan(const char *soundName, int pan); /* pan: 0 .. 127 */
92 	void setFadePan(const char *soundName, int destPan, int duration);
93 	void setFadeVolume(const char *soundName, int destVolume, int duration);
94 	void setHookId(const char *soundName, int hookId);
95 	int getCountPlayedTracks(const char *soundName);
96 	void stopSound(const char *soundName);
97 	void stopAllSounds();
98 	void pause(bool pause);
99 	void setMusicState(int stateId);
100 	int setMusicSequence(int seqId);
101 	void refreshScripts();
102 	void flushTracks();
103 	bool isVoicePlaying();
104 	char *getCurMusicSoundName();
105 	int getCurMusicPan();
106 	int getCurMusicVol();
107 	bool getSoundStatus(const char *soundName);
108 	int32 getPosIn16msTicks(const char *soundName);
109 };
110 
111 extern Imuse *g_imuse;
112 
113 } // end of namespace Grim
114 
115 #endif
116