ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

imuse_music.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/grim/debug.h"
00024 
00025 #include "engines/grim/imuse/imuse.h"
00026 #include "engines/grim/imuse/imuse_tables.h"
00027 
00028 namespace Grim {
00029 
00030 void Imuse::setMusicState(int stateId) {
00031     int l, num = -1;
00032 
00033     if (stateId == 0)
00034         stateId = 1000;
00035 
00036     for (l = 0; _stateMusicTable[l].soundId != -1; l++) {
00037         if (_stateMusicTable[l].soundId == stateId) {
00038             num = l;
00039             break;
00040         }
00041     }
00042     assert(num != -1);
00043 
00044     Debug::debug(Debug::Sound, "Imuse::setMusicState(): SoundId %d, filename: %s", _stateMusicTable[l].soundId, _stateMusicTable[l].filename);
00045 
00046     if (_curMusicState == num)
00047         return;
00048 
00049     if (!_curMusicSeq) {
00050         playMusic(&_stateMusicTable[num], num, false);
00051     }
00052 
00053     _curMusicState = num;
00054 }
00055 
00056 int Imuse::setMusicSequence(int seqId) {
00057     int l, num = -1;
00058 
00059     if (seqId == -1)
00060         return _seqMusicTable[_curMusicSeq].soundId;
00061 
00062     if (seqId == 0)
00063         seqId = 2000;
00064 
00065     for (l = 0; _seqMusicTable[l].soundId != -1; l++) {
00066         if (_seqMusicTable[l].soundId == seqId) {
00067             num = l;
00068             break;
00069         }
00070     }
00071 
00072     assert(num != -1);
00073 
00074     Debug::debug(Debug::Sound, "Imuse::setMusicSequence(): SoundId %d, filename: %s", _seqMusicTable[l].soundId, _seqMusicTable[l].filename);
00075 
00076     if (_curMusicSeq == num)
00077         return _seqMusicTable[_curMusicSeq].soundId;
00078 
00079     if (num) {
00080         playMusic(&_seqMusicTable[num], 0, true);
00081     } else {
00082         playMusic(&_stateMusicTable[_curMusicState], _curMusicState, true);
00083         num = 0;
00084     }
00085 
00086     _curMusicSeq = num;
00087     return _seqMusicTable[_curMusicSeq].soundId;
00088 }
00089 
00090 void Imuse::playMusic(const ImuseTable *table, int atribPos, bool sequence) {
00091     int hookId = 0;
00092 
00093     if (atribPos) {
00094         if (table->atribPos)
00095             atribPos = table->atribPos;
00096         hookId = _attributes[atribPos];
00097         if (table->hookId) {
00098             if (hookId && table->hookId > 1) {
00099                 _attributes[atribPos] = 2;
00100             } else {
00101                 _attributes[atribPos] = hookId + 1;
00102                 if (table->hookId < hookId + 1)
00103                     _attributes[atribPos] = 1;
00104             }
00105         }
00106     }
00107     if (hookId == 0)
00108         hookId = 100;
00109 
00110     if (table->opcode == 0) {
00111         fadeOutMusic(120);
00112         return;
00113     }
00114 
00115     if (table->opcode == 2 || table->opcode == 3) {
00116         if (table->filename[0] == 0) {
00117             fadeOutMusic(60);
00118             return;
00119         }
00120         char *soundName = getCurMusicSoundName();
00121         int pan;
00122 
00123         if (table->pan == 0)
00124             pan = 64;
00125         else
00126             pan = table->pan;
00127         if (!soundName) {
00128             startMusic(table->filename, hookId, 0, pan);
00129             setVolume(table->filename, 0);
00130             setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
00131             return;
00132         }
00133         int old_pan = getCurMusicPan();
00134         int old_vol = getCurMusicVol();
00135         if (old_pan == -1)
00136             old_pan = 64;
00137         if (old_vol == -1)
00138             old_vol = 127;
00139 
00140         if (table->opcode == 2) {
00141             fadeOutMusic(table->fadeOut60TicksDelay);
00142             startMusic(table->filename, hookId, table->volume, pan);
00143             setVolume(table->filename, 0);
00144             setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
00145             setFadePan(table->filename, pan, table->fadeOut60TicksDelay);
00146             return;
00147         }
00148         if (strcmp(soundName, table->filename) == 0) {
00149             setFadeVolume(soundName, table->volume, table->fadeOut60TicksDelay);
00150             setFadePan(soundName, pan, table->fadeOut60TicksDelay);
00151             return;
00152         }
00153 
00154         if (!sequence && table->atribPos && table->atribPos == _stateMusicTable[_curMusicState].atribPos) {
00155             fadeOutMusicAndStartNew(table->fadeOut60TicksDelay, table->filename, hookId, old_vol, old_pan);
00156             setVolume(table->filename, 0);
00157             setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
00158             setFadePan(table->filename, pan, table->fadeOut60TicksDelay);
00159         } else {
00160             fadeOutMusic(table->fadeOut60TicksDelay);
00161             startMusic(table->filename, hookId, table->volume, pan);
00162             setVolume(table->filename, 0);
00163             setFadeVolume(table->filename, table->volume, table->fadeOut60TicksDelay);
00164         }
00165     }
00166 }
00167 
00168 } // end of namespace Grim


Generated on Sat Aug 24 2019 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge