1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
|
/* ScummVM - Scumm Interpreter
* Copyright (C) 2001-2004 The ScummVM project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
*/
#include "stdafx.h"
#include "common/scummsys.h"
#include "scumm/scumm.h"
#include "scumm/imuse_digi/dimuse.h"
namespace Scumm {
void IMuseDigital::setDigMusicState(int stateId) {
int l, num = -1;
for (l = 0; _digStateMusicTable[l].soundId != -1; l++) {
if ((_digStateMusicTable[l].soundId == stateId)) {
debug(5, "Set music state: %s, %s", _digStateMusicTable[l].name, _digStateMusicTable[l].filename);
num = l;
break;
}
}
if (num == -1) {
for (l = 0; _digStateMusicMap[l].roomId != -1; l++) {
if ((_digStateMusicMap[l].roomId == stateId)) {
break;
}
}
num = l;
int val2 = _attributesTable[_digStateMusicMap[num].unk1];
if (val2 == 0) {
if (_attributesTable[_digStateMusicMap[num].unk3] != 0) {
num = _digStateMusicMap[num].unk4;
} else {
num = _digStateMusicMap[num].musicTableIndex;
}
} else {
int val = _attributesTable[_digStateMusicMap[num].unk2];
if (val == 0) {
num = _digStateMusicMap[num].musicTableIndex + val2;
} else {
num = val;
}
}
}
debug(5, "Set music state: %s, %s", _digStateMusicTable[num].name, _digStateMusicTable[num].filename);
if (_curMusicState == num)
return;
bool wait = false;
if (_curMusicSeq != 0) {
wait = true;
}
if ((_curMusicSeq == 0) || (wait)) {
if (num == 0)
playDigMusic(NULL, &_digStateMusicTable[num], num, false, wait);
else
playDigMusic(_digStateMusicTable[num].name, &_digStateMusicTable[num], num, false, wait);
}
_curMusicState = num;
}
void IMuseDigital::setDigMusicSequence(int seqId) {
int l, num = -1;
if (seqId == 0)
seqId = 2000;
for (l = 0; _digSeqMusicTable[l].soundId != -1; l++) {
if ((_digSeqMusicTable[l].soundId == seqId)) {
debug(5, "Set music sequence: %s, %s", _digSeqMusicTable[l].name, _digSeqMusicTable[l].filename);
num = l;
break;
}
}
assert(num != -1);
if (_curMusicSeq == num)
return;
if (num != 0) {
if (_curMusicSeq == 0) {
playDigMusic(_digSeqMusicTable[num].name, &_digSeqMusicTable[num], 0, true, false);
_curSeqAtribPos = 0;
_attributesSeq[num] = 1;
} else {
if ((_digSeqMusicTable[_curMusicSeq].opcode == 4) && (_digSeqMusicTable[_curMusicSeq].opcode == 6)) {
_curSeqAtribPos = num;
return;
} else if (_digSeqMusicTable[_curMusicSeq].opcode == 6) {
playDigMusic(_digSeqMusicTable[num].name, &_digSeqMusicTable[num], 0, true, false);
_curSeqAtribPos = 0;
_attributesSeq[num] = 1;
}
}
} else {
if (_curSeqAtribPos != 0) {
playDigMusic(_digSeqMusicTable[_curSeqAtribPos].name, &_digSeqMusicTable[num], 0, true, false);
_attributesSeq[_curSeqAtribPos] = 1;
_curSeqAtribPos = 0;
num = _curSeqAtribPos;
} else {
if (_curMusicState != 0)
playDigMusic(_digStateMusicTable[_curMusicState].name, &_digSeqMusicTable[num], _curMusicState, false, false);
else
playDigMusic(NULL, &_digStateMusicTable[num], _curMusicState, false, false);
num = 0;
}
}
_curMusicSeq = num;
}
void IMuseDigital::playDigMusic(const char *songName, const imuseDigTable *table, int atribPos, bool sequence, bool wait) {
int hookId = 0;
if (songName != NULL) {
if ((_attributesSeq[38] != 0) && (_attributesSeq[41] == _attributesSeq[38])) {
if ((atribPos == 43) || (atribPos == 44))
hookId = 3;
}
if ((_attributesSeq[46] != 0) && (_attributesSeq[48] == 0)) {
if ((atribPos == 38) || (atribPos == 39))
hookId = 3;
}
if ((_attributesSeq[53] != 0)) {
if ((atribPos == 50) || (atribPos == 51))
hookId = 3;
}
if ((atribPos != 0) && (hookId == 0)) {
if (table->param != 0)
atribPos = table->param;
hookId = _attributesSeq[atribPos];
}
}
if (table->filename[0] == 0) {
fadeOutMusic(120);
return;
}
fadeOutMusic(120);
switch(table->opcode) {
case 0:
case 5:
case 6:
break;
case 3:
if ((!sequence) && (table->param != 0)) {
if (table->param == _digStateMusicTable[_curMusicState].param) {
startMusic(table->filename, table->soundId, sequence, 0, 127, wait);
}
} else {
startMusic(table->filename, table->soundId, sequence, hookId, 127, wait);
}
case 4:
startMusic(table->filename, table->soundId, sequence, 0, 127, wait);
break;
}
}
void IMuseDigital::setComiMusicState(int stateId) {
int l, num = -1;
if ((stateId == 0) || (stateId == 4))
stateId = 1000;
for (l = 0; _comiStateMusicTable[l].soundId != -1; l++) {
if ((_comiStateMusicTable[l].soundId == stateId)) {
debug(5, "Set music state: %s, %s", _comiStateMusicTable[l].name, _comiStateMusicTable[l].filename);
num = l;
break;
}
}
assert(num != -1);
if (_curMusicState == num)
return;
bool wait = false;
if (_curMusicSeq != 0) {
wait = true;
}
if ((_curMusicSeq == 0) || (wait)) {
if (num == 0)
playComiMusic(NULL, &_comiStateMusicTable[num], num, false, wait);
else
playComiMusic(_comiStateMusicTable[num].name, &_comiStateMusicTable[num], num, false, wait);
}
_curMusicState = num;
}
void IMuseDigital::setComiMusicSequence(int seqId) {
int l, num = -1;
if (seqId == 0)
seqId = 2000;
for (l = 0; _comiSeqMusicTable[l].soundId != -1; l++) {
if ((_comiSeqMusicTable[l].soundId == seqId)) {
debug(5, "Set music sequence: %s, %s", _comiSeqMusicTable[l].name, _comiSeqMusicTable[l].filename);
num = l;
break;
}
}
assert(num != -1);
if (_curMusicSeq == num)
return;
if (num != 0) {
if (_curMusicSeq == 0) {
playComiMusic(_comiSeqMusicTable[num].name, &_comiSeqMusicTable[num], 0, true, false);
_curSeqAtribPos = 0;
_attributesSeq[num] = 1;
} else {
if ((_comiSeqMusicTable[_curMusicSeq].opcode == 4) && (_comiSeqMusicTable[_curMusicSeq].opcode == 6)) {
_curSeqAtribPos = num;
return;
} else if (_comiSeqMusicTable[_curMusicSeq].opcode == 6) {
playComiMusic(_comiSeqMusicTable[num].name, &_comiSeqMusicTable[num], 0, true, false);
_curSeqAtribPos = 0;
_attributesSeq[num] = 1;
}
}
} else {
if (_curSeqAtribPos != 0) {
playComiMusic(_comiSeqMusicTable[_curSeqAtribPos].name, &_comiSeqMusicTable[num], 0, true, false);
_attributesSeq[_curSeqAtribPos] = 1;
_curSeqAtribPos = 0;
num = _curSeqAtribPos;
} else {
if (_curMusicState != 0)
playComiMusic(_comiStateMusicTable[_curMusicState].name, &_comiSeqMusicTable[num], _curMusicState, false, false);
else
playComiMusic(NULL, &_comiStateMusicTable[num], _curMusicState, false, false);
num = 0;
}
}
_curMusicSeq = num;
}
void IMuseDigital::playComiMusic(const char *songName, const imuseComiTable *table, int atribPos, bool sequence, bool wait) {
int hookId = 0;
if ((songName != NULL) && (atribPos != 0)) {
hookId = _attributesSeq[atribPos];
if (table->hookId != 0) {
if ((hookId != 0) && (table->hookId <= 1)) {
_attributesSeq[atribPos] = hookId + 1;
if (table->hookId < hookId + 1)
_attributesSeq[atribPos] = 1;
} else {
_attributesSeq[atribPos] = 2;
}
}
}
if (table->filename[0] == 0) {
fadeOutMusic(120);
return;
}
switch(table->opcode) {
case 0:
case 8:
case 9:
fadeOutMusic(120);
break;
case 1:
fadeOutMusic(120);
startMusic(table->filename, table->soundId, sequence, 0, 1, wait);
setFade(table->soundId, 127, 120);
break;
case 2:
fadeOutMusic(table->fadeDelay);
startMusic(table->filename, table->soundId, sequence, table->hookId, 127, wait);
break;
case 3:
if ((!sequence) && (table->param != 0)) {
if (table->param == _comiStateMusicTable[_curMusicState].param) {
fadeOutMusic(table->fadeDelay);
startMusic(table->filename, table->soundId, sequence, 0, 127, wait);
}
} else {
fadeOutMusic(table->fadeDelay);
startMusic(table->filename, table->soundId, sequence, table->hookId, 127, wait);
}
case 4:
fadeOutMusic(120);
startMusic(table->filename, table->soundId, sequence, 0, 127, wait);
break;
case 12:
fadeOutMusic(table->fadeDelay);
startMusic(table->filename, table->soundId, sequence, table->hookId, 127, wait);
break;
}
}
void IMuseDigital::setFtMusicState(int stateId) {
if (stateId > 48)
return;
debug(5, "State music: %s, %s", _ftStateMusicTable[stateId].name, _ftStateMusicTable[stateId].audioName);
if (_curMusicState == stateId)
return;
bool wait = false;
if (_curMusicSeq != 0) {
wait = true;
}
if ((_curMusicSeq == 0) || (wait)) {
if (stateId == 0)
playFtMusic(NULL, 0, 0, false, wait);
else
playFtMusic(_ftStateMusicTable[stateId].audioName, _ftStateMusicTable[stateId].opcode, _ftStateMusicTable[stateId].volume, false, wait);
}
_curMusicState = stateId;
}
void IMuseDigital::setFtMusicSequence(int seqId) {
if (seqId > 52)
return;
debug(5, "Sequence music: %s, %s", _ftSeqNames[seqId].name);
if (_curMusicSeq == seqId)
return;
if (seqId == 0) {
if (_curMusicState == 0)
playFtMusic(NULL, 0, 0, true, false);
else
playFtMusic(_ftStateMusicTable[seqId].audioName, _ftStateMusicTable[seqId].opcode, _ftStateMusicTable[seqId].volume, true, false);
} else {
int seq = (seqId - 1) * 4;
playFtMusic(_ftSeqMusicTable[seq].audioName, _ftSeqMusicTable[seq].opcode, _ftSeqMusicTable[seq].volume, false, false);
}
_curMusicSeq = seqId;
_curMusicCue = 0;
}
void IMuseDigital::setFtMusicCuePoint(int cueId) {
if (cueId > 3)
return;
debug(5, "Cue point sequence: %d", cueId);
if (_curMusicSeq == 0)
return;
if (_curMusicCue == cueId)
return;
if (cueId == 0)
playFtMusic(NULL, 0, 0, true, false);
else {
int seq = ((_curMusicSeq - 1) + cueId) * 4;
playFtMusic(_ftSeqMusicTable[seq].audioName, _ftSeqMusicTable[seq].opcode, _ftSeqMusicTable[seq].volume, true, false);
}
_curMusicCue = cueId;
}
int IMuseDigital::getSoundIdByName(const char *soundName) {
if (soundName && soundName[0] != 0) {
for (int r = 0; r < _vm->_numAudioNames; r++) {
if (strcmp(soundName, &_vm->_audioNames[r * 9]) == 0) {
return r;
}
}
}
return -1;
}
void IMuseDigital::playFtMusic(const char *songName, int opcode, int volume, bool sequence, bool wait) {
fadeOutMusic(200);
switch(opcode) {
case 0:
case 4:
break;
case 1:
case 2:
case 3:
{
int soundId = getSoundIdByName(songName);
if (soundId != -1)
startMusic(soundId, sequence, volume, wait);
}
break;
}
}
} // End of namespace Scumm
|