ScummVM API documentation
soundrecords.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NANCY_ACTION_SOUNDRECORDS_H
23 #define NANCY_ACTION_SOUNDRECORDS_H
24 
25 #include "engines/nancy/action/actionrecord.h"
26 
27 namespace Nancy {
28 namespace Action {
29 
30 // Sets the volume for a particular channel.
31 class SetVolume : public ActionRecord {
32 public:
33  void readData(Common::SeekableReadStream &stream) override;
34  void execute() override;
35 
36  uint16 channel = 0;
37  byte volume = 0;
38 
39 protected:
40  Common::String getRecordTypeName() const override { return "SetVolume"; }
41 };
42 
43 // Nancy 11+ AR 147. Linearly ramps a channel's volume down to 0 over
44 // the given time, then stops execution.
46 public:
47  void readData(Common::SeekableReadStream &stream) override;
48  void execute() override;
49 
50  uint16 channel = 0;
51  uint32 fadeTimeMs = 0;
52 
53 protected:
54  Common::String getRecordTypeName() const override { return "FadeSoundToSilence"; }
55 
56 private:
57  uint32 _startTime = 0;
58  uint16 _startVolume = 0;
59 };
60 
61 // Nancy 11+ AR 156. Adjusts a playing 3D sound's position and/or its
62 // min/max audible distance. A field set to kNoChange is left untouched.
63 class Update3DSound : public ActionRecord {
64 public:
65  void readData(Common::SeekableReadStream &stream) override;
66  void execute() override;
67 
68  static const int32 kNoChange = 10000;
69 
70  uint16 _channelID = 0;
71  int32 _posX = 0;
72  int32 _posY = 0;
73  int32 _posZ = 0;
74  int32 _minDistance = 0;
75  int32 _maxDistance = 0;
76 
77 protected:
78  Common::String getRecordTypeName() const override { return "Update3DSound"; }
79 };
80 
81 // Added in Nancy12 (AR 168). Sets a 3D-sound position from a set of coordinates,
82 // most likely the global listener position.
84 public:
85  void readData(Common::SeekableReadStream &stream) override;
86  void execute() override;
87 
88  int32 _posX = 0;
89  int32 _posY = 0;
90  int32 _posZ = 0;
91 
92 protected:
93  Common::String getRecordTypeName() const override { return "Set3DSoundListenerPosition"; }
94 };
95 
96 // Used for sound effects. From nancy3 up it includes 3D sound data, which lets
97 // the sound move in 3D space as the player rotates/changes scenes. Also supports
98 // changing the scene and/or setting a flag
99 class PlaySound : public ActionRecord {
100 public:
101  PlaySound() {}
102  ~PlaySound() { delete _soundEffect; }
103 
104  void readData(Common::SeekableReadStream &stream) override;
105  void execute() override;
106 
107  SoundDescription _sound;
108  SoundEffectDescription *_soundEffect = nullptr;
109  bool _changeSceneImmediately = false;
110  SceneChangeDescription _sceneChange;
111  FlagDescription _flag;
112 
113  // Nancy13+: a list of flags (was a single flag) and a multi-name random sound.
115  byte _afterSoundAction = 0; // Nancy13+: 1 dismisses the text box overlay
116 
117  // Subtitle shown in the game textbox while the sound plays. In Nancy13+ this
118  // is resolved from the sound name (see readDataNancy13); earlier games store
119  // it explicitly in the closed-caption records below.
120  Common::String _ccText;
121 
122  Common::String getRecordExtraInfo() const override { return Common::String::format("Scene %d", _sceneChange.sceneID); }
123 
124 protected:
125  Common::String getRecordTypeName() const override;
126 
127  void readDataNancy13(Common::SeekableReadStream &stream);
128  void applyAfterSoundAction();
129 };
130 
131 // The same as PlaySound, but with the addition of captioning text,
132 // which gets displayed inside the Textbox.
133 class PlaySoundCC : public PlaySound {
134 public:
135  void readData(Common::SeekableReadStream &stream) override;
136  void execute() override;
137 
138  void readCCText(Common::SeekableReadStream &stream, Common::String &out);
139 
140 protected:
141  Common::String getRecordTypeName() const override;
142 };
143 
144 // Short version of PlaySoundCC, no event flag
145 class PlaySoundTerse : public PlaySoundCC {
146 public:
147  void readData(Common::SeekableReadStream &stream) override;
148 
149 protected:
150  Common::String getRecordTypeName() const override { return "PlaySoundTerse"; }
151 };
152 
153 // Short version of PlaySoundCC, with event flag
155 public:
156  void readData(Common::SeekableReadStream &stream) override;
157 
158 protected:
159  Common::String getRecordTypeName() const override { return "PlaySoundEventFlagTerse"; }
160 };
161 
162 // Used for sounds that pan left-right depending on the scene background frame.
163 // Only used in The Vampire Diaries; later games use PlaySound's 3D sound capabilities instead
165 public:
166  void readData(Common::SeekableReadStream &stream) override;
167  void execute() override;
168 
169  SoundDescription _sound;
170 
171 protected:
172  Common::String getRecordTypeName() const override;
173 };
174 
175 // Plays a sound effect; has multiple hotspots, one per scene background frame.
176 // Used in exactly two places; one scene in tvd, and one in nancy1
178 public:
179  void readData(Common::SeekableReadStream &stream) override;
180  void execute() override;
181 
182  SoundDescription _sound; // 0x0
183  SceneChangeDescription _sceneChange; // 0x22
184  FlagDescription _flag; // 0x2A
185  Common::Array<HotspotDescription> _hotspots; // 0x31
186 
187  bool canHaveHotspot() const override { return true; }
188 
189  Common::String getRecordExtraInfo() const override { return Common::String::format("Scene %d", _sceneChange.sceneID); }
190 protected:
191  Common::String getRecordTypeName() const override { return "PlaySoundMultiHS"; }
192 };
193 
194 // Stops a sound if it's loaded and playing. Used very rarely, as sounds (usually)
195 // get auto-stopped on a scene change
196 class StopSound : public ActionRecord {
197 public:
198  void readData(Common::SeekableReadStream &stream) override;
199  void execute() override;
200 
201  uint _channelID;
202  SceneChangeWithFlag _sceneChange;
203 
204 protected:
205  Common::String getRecordTypeName() const override { return "StopSound"; }
206 };
207 
208 // Same as PlaySound, except it randomly picks between one of several provided
209 // sound files; all other settings for the sound are shared. The played sound is
210 // chosen when the record is loaded.
211 class PlayRandomSound : public PlaySound {
212 public:
213  void readData(Common::SeekableReadStream &stream) override;
214 
215  Common::Array<Common::String> _soundNames;
216 
217  uint _selectedSound = 0;
218 
219 protected:
220  Common::String getRecordTypeName() const override { return "PlayRandomSound"; }
221 };
222 
223 // Short version of PlayRandomSound, but ALSO supports closed captioning text.
224 // The played sound is chosen at random when the record is loaded.
226 public:
227  void readData(Common::SeekableReadStream &stream) override;
228 
229  Common::Array<Common::String> _soundNames;
231 
232  uint _selectedSound = 0;
233 
234 protected:
235  Common::String getRecordTypeName() const override { return "PlayRandomSoundTerse"; }
236 };
237 
238 // Same as PlaySound, except it discards the filename provided in the data.
239 // Instead, it takes the current value of an item in TableData, and appends that
240 // value to the end of the base filename provided in the TABL chunk. Does not contain
241 // any CC text inside the record data; instead, that also gets copied over from TABL.
243 public:
244  void readData(Common::SeekableReadStream &stream) override;
245  void execute() override;
246 
247 protected:
248  Common::String getRecordTypeName() const override { return "TableIndexPlaySound"; }
249 
250  uint16 _tableIndex = 0;
251  int16 _lastIndexVal = -1;
252 };
253 
254 } // End of namespace Action
255 } // End of namespace Nancy
256 
257 #endif // NANCY_ACTION_NAVIGATIONRECORDS_H
Definition: str.h:59
static String format(MSVC_PRINTF const char *fmt,...) GCC_PRINTF(1
Definition: soundrecords.h:145
Definition: soundrecords.h:31
Definition: commontypes.h:165
Definition: array.h:52
Definition: soundrecords.h:83
Definition: soundrecords.h:63
Definition: soundrecords.h:196
Definition: soundrecords.h:164
Definition: stream.h:745
Definition: commontypes.h:245
Definition: soundrecords.h:99
Definition: commontypes.h:185
Definition: soundrecords.h:133
Definition: actionrecord.h:98
Definition: soundrecords.h:154
Definition: soundrecords.h:242
Definition: soundrecords.h:177
Definition: soundrecords.h:225
Definition: commontypes.h:282
Definition: soundrecords.h:45
Definition: commontypes.h:180
Definition: actionmanager.h:32
Definition: soundrecords.h:211