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_MUSIC_ROOM_HANDLER_H 24 #define TITANIC_MUSIC_ROOM_HANDLER_H 25 26 #include "titanic/sound/audio_buffer.h" 27 #include "titanic/sound/music_room_instrument.h" 28 #include "titanic/sound/music_song.h" 29 #include "titanic/sound/wave_file.h" 30 31 namespace Titanic { 32 33 class CProjectItem; 34 class CSoundManager; 35 36 enum MusicInstrument { BELLS = 0, SNAKE = 1, PIANO = 2, BASS = 3 }; 37 38 struct MusicRoomInstrument { 39 int _pitchControl; 40 int _speedControl; 41 bool _directionControl; 42 bool _inversionControl; 43 bool _muteControl; MusicRoomInstrumentMusicRoomInstrument44 MusicRoomInstrument() : _pitchControl(0), _speedControl(0), _directionControl(false), 45 _inversionControl(false), _muteControl(false) {} 46 }; 47 48 class CMusicRoomHandler { 49 private: 50 CProjectItem *_project; 51 CSoundManager *_soundManager; 52 CMusicRoomInstrument *_instruments[4]; 53 MusicRoomInstrument _array1[4]; 54 MusicRoomInstrument _array2[4]; 55 CMusicSong *_songs[4]; 56 int _startPos[4]; 57 int _position[4]; 58 double _animExpiryTime[4]; 59 60 bool _active; 61 CWaveFile *_waveFile; 62 int _soundHandle; 63 int _instrumentsActive; 64 CAudioBuffer *_audioBuffer; 65 bool _isPlaying; 66 uint _soundStartTicks; 67 uint _startTicks; 68 int _volume; 69 private: 70 /** 71 * Starts music room instruments animation 72 */ 73 void start(); 74 75 /** 76 * Handles updating the raw audio being played for all the instruments 77 */ 78 void updateAudio(); 79 80 /** 81 * Handles updating the instruments themselves, and keeping them animating 82 */ 83 void updateInstruments(); 84 85 /** 86 * Polls a specified instrument for any updates to see if it's still active. 87 * @returns Returns true if a given instrument is still active.. 88 * that is, that there is still more data that can be read from it to play 89 */ 90 bool pollInstrument(MusicInstrument instrument); 91 92 /** 93 * Gets the duration for a given fragment of an instrument to play 94 * out, so that animations of the instruments can be synchronized 95 * to the actual music 96 */ 97 double getAnimDuration(MusicInstrument instrument, int arrIndex); 98 99 /** 100 * Figures out a pitch value (of some sort) for use in determining 101 * which wave file the music instruments will use. 102 */ 103 int getPitch(MusicInstrument instrument, int arrIndex); 104 public: 105 CMusicRoomHandler(CProjectItem *project, CSoundManager *soundManager); 106 ~CMusicRoomHandler(); 107 108 /** 109 * Creates a new music room instrument class to handle the operation of one 110 * of the instruments in the music room. 111 * @param instrument Which instrument to create for 112 * @param count Number of Wave files the new instance will contain 113 */ 114 CMusicRoomInstrument *createInstrument(MusicInstrument instrument, int count); 115 116 /** 117 * Main setup for the music room handler 118 */ 119 void setup(int volume); 120 121 /** 122 * Flags whether the music handler is active 123 */ setActive(bool flag)124 void setActive(bool flag) { _active = flag; } 125 126 /** 127 * Stop playing the music 128 */ 129 void stop(); 130 131 /** 132 * Checks the specified instrument to see if it's settings are "correct" 133 */ 134 bool checkInstrument(MusicInstrument instrument) const; 135 136 /** 137 * Sets the speed control value 138 */ 139 void setSpeedControl2(MusicInstrument instrument, int value); 140 141 /** 142 * Sets the pitch control value 143 */ 144 void setPitchControl2(MusicInstrument instrument, int value); 145 146 /** 147 * Sets the inversion control value 148 */ 149 void setInversionControl2(MusicInstrument instrument, bool value); 150 151 /** 152 * Sets the direction control value 153 */ 154 void setDirectionControl2(MusicInstrument instrument, bool value); 155 156 /** 157 * Sets the pitch control value 158 */ 159 void setPitchControl(MusicInstrument instrument, int value); 160 161 /** 162 * Sets the speed control value 163 */ 164 void setSpeedControl(MusicInstrument instrument, int value); 165 166 /** 167 * Sets the direction control value 168 */ 169 void setDirectionControl(MusicInstrument instrument, bool value); 170 171 /** 172 * Sets the inversion control value 173 */ 174 void setInversionControl(MusicInstrument instrument, bool value); 175 176 /** 177 * Sets the mute control value 178 */ 179 void setMuteControl(MusicInstrument instrument, bool value); 180 181 /** 182 * Handles regular updates 183 * @returns True if the music is still playing 184 */ 185 bool update(); 186 }; 187 188 } // End of namespace Titanic 189 190 #endif /* TITANIC_MUSIC_ROOM_HANDLER_H */ 191