1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM 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 TITANIC_SOUND_H 24 #define TITANIC_SOUND_H 25 26 #include "titanic/support/simple_file.h" 27 #include "titanic/sound/proximity.h" 28 #include "titanic/sound/sound_manager.h" 29 #include "titanic/sound/wave_file.h" 30 #include "titanic/core/list.h" 31 #include "titanic/core/view_item.h" 32 #include "titanic/true_talk/dialogue_file.h" 33 34 namespace Titanic { 35 36 class CGameManager; 37 38 class CSoundItem : public ListItem { 39 public: 40 CString _name; 41 CWaveFile *_waveFile; 42 File *_dialogueFileHandle; 43 int _speechId; 44 DisposeAfterUse::Flag _disposeAfterUse; 45 bool _active; 46 public: CSoundItem()47 CSoundItem() : ListItem(), _waveFile(nullptr), _dialogueFileHandle(nullptr), 48 _speechId(0), _disposeAfterUse(DisposeAfterUse::NO), _active(false) {} CSoundItem(const CString & name)49 CSoundItem(const CString &name) : ListItem(), _name(name), _waveFile(nullptr), 50 _dialogueFileHandle(nullptr), _disposeAfterUse(DisposeAfterUse::NO), 51 _speechId(0), _active(false) {} CSoundItem(File * dialogueFile,int speechId)52 CSoundItem(File *dialogueFile, int speechId) : ListItem(), _waveFile(nullptr), 53 _dialogueFileHandle(dialogueFile), _speechId(speechId), _active(false), 54 _disposeAfterUse(DisposeAfterUse::NO) {} 55 virtual ~CSoundItem(); 56 }; 57 58 class CSoundItemList : public List<CSoundItem> { 59 }; 60 61 class CSound { 62 private: 63 CGameManager *_gameManager; 64 CSoundItemList _sounds; 65 private: 66 /** 67 * Check whether any sounds are done and can be be removed 68 */ 69 void checkSounds(); 70 71 /** 72 * Removes the oldest sound from the sounds list that isn't 73 * currently playing 74 */ 75 void removeOldest(); 76 public: 77 QSoundManager _soundManager; 78 public: 79 CSound(CGameManager *owner, Audio::Mixer *mixer); 80 ~CSound(); 81 82 /** 83 * Save the data for the class to file 84 */ 85 void save(SimpleFile *file) const; 86 87 /** 88 * Load the data for the class from file 89 */ 90 void load(SimpleFile *file); 91 92 /** 93 * Called when a game is about to be loaded 94 */ 95 void preLoad(); 96 97 /** 98 * Called when loading a game is complete 99 */ postLoad()100 void postLoad() { _soundManager.postLoad(); } 101 102 /** 103 * Called when a game is about to be saved 104 */ preSave()105 void preSave() { _soundManager.preSave(); } 106 107 /** 108 * Called when a game has finished being saved 109 */ postSave()110 void postSave() { _soundManager.postSave(); } 111 112 /** 113 * Called when the view has been changed 114 */ 115 void preEnterView(CViewItem *newView, bool isNewRoom); 116 117 /** 118 * Returns true if a sound with the specified handle is active 119 */ 120 bool isActive(int handle); 121 122 /** 123 * Sets the volume for a sound 124 * @param handle Sound handle 125 * @param volume Volume percentage (0 to 100) 126 * @param seconds Number of seconds to transition to the new volume 127 */ 128 void setVolume(uint handle, uint volume, uint seconds); 129 130 /** 131 * Flags a sound about to be played as activated 132 */ 133 void activateSound(CWaveFile *waveFile, 134 DisposeAfterUse::Flag disposeAfterUse = DisposeAfterUse::NO); 135 136 /** 137 * Stops any sounds attached to a given channel 138 */ 139 void stopChannel(int channel); 140 141 /** 142 * Loads a TrueTalk dialogue 143 * @param dialogueFile Dialogue file reference 144 * @param speechId Speech Id within dialogue 145 * @returns Wave file instance 146 */ 147 CWaveFile *getTrueTalkSound(CDialogueFile *dialogueFile, int index); 148 149 /** 150 * Load a speech resource 151 * @param dialogueFile Dialogue file reference 152 * @param speechId Speech Id within dialogue 153 * @returns Wave file instance 154 */ 155 CWaveFile *loadSpeech(CDialogueFile *dialogueFile, int speechId); 156 157 /** 158 * Play a speech 159 * @param dialogueFile Dialogue file reference 160 * @param speechId Speech Id within dialogue 161 * @param prox Proximity instance 162 */ 163 int playSpeech(CDialogueFile *dialogueFile, int speechId, CProximity &prox); 164 165 /** 166 * Load a sound 167 * @param name Name of sound resource 168 * @returns Sound item record 169 */ 170 CWaveFile *loadSound(const CString &name); 171 172 /** 173 * Play a sound 174 */ 175 int playSound(const CString &name, CProximity &prox); 176 177 /** 178 * Stop a sound 179 */ 180 void stopSound(uint handle); 181 182 /** 183 * Flags that a sound can be freed if a timeout is set 184 */ 185 void setCanFree(int handle); 186 187 /** 188 * Handles regularly updating the mixer 189 */ 190 void updateMixer(); 191 }; 192 193 } // End of namespace Titanic 194 195 #endif /* TITANIC_SOUND_H */ 196