Only call MIDI code, in games which use MIDI based music.

svn-id: r27080
This commit is contained in:
Travis Howell 2007-06-04 14:25:02 +00:00
parent 6dd52b592e
commit 64413f9cc8
6 changed files with 78 additions and 56 deletions

View File

@ -1186,8 +1186,10 @@ protected:
virtual void windowNewLine(WindowBlock *window);
void windowDrawChar(WindowBlock *window, uint x, uint y, byte chr);
virtual void loadMusic(uint music);
void loadModule(uint music);
void loadMusic(uint track);
void playModule(uint music);
virtual void playMusic(uint16 track, uint16 track);
void stopMusic();
void checkTimerCallback();
void delay(uint delay);
@ -1478,7 +1480,7 @@ protected:
virtual void userGame(bool load);
virtual int userGameGetKey(bool *b, char *buf, uint maxChar);
virtual void loadMusic(uint music);
virtual void playMusic(uint16 music, uint16 track);
virtual void vcStopAnimation(uint zone, uint sprite);
};
@ -1521,8 +1523,6 @@ protected:
virtual uint setupIconHitArea(WindowBlock *window, uint num, uint x, uint y, Item *item_ptr);
virtual void playSpeech(uint speech_id, uint vga_sprite_id);
virtual void loadMusic(uint music);
};
class AGOSEngine_Feeble : public AGOSEngine_Simon2 {

View File

@ -558,21 +558,33 @@ bool AGOSEngine::processSpecialKeys() {
_speech ^= 1;
}
case '+':
_midi.setVolume(_midi.getVolume() + 16);
if ((getPlatform() == Common::kPlatformAcorn && (getFeatures() & GF_TALKIE)) ||
getPlatform() == Common::kPlatformPC || getPlatform() == Common::kPlatformWindows) {
_midi.setVolume(_midi.getVolume() + 16);
}
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) + 16);
break;
case '-':
_midi.setVolume(_midi.getVolume() - 16);
if ((getPlatform() == Common::kPlatformAcorn && (getFeatures() & GF_TALKIE)) ||
getPlatform() == Common::kPlatformPC || getPlatform() == Common::kPlatformWindows) {
_midi.setVolume(_midi.getVolume() - 16);
}
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) - 16);
break;
case 'm':
_midi.pause(_musicPaused ^= 1);
if ((getPlatform() == Common::kPlatformAcorn && (getFeatures() & GF_TALKIE)) ||
getPlatform() == Common::kPlatformPC || getPlatform() == Common::kPlatformWindows) {
_midi.pause(_musicPaused ^= 1);
} else {
// TODO
}
break;
case 's':
if (getGameId() == GID_SIMON1DOS)
if (getGameId() == GID_SIMON1DOS) {
_midi._enable_sfx ^= 1;
else
} else {
_sound->effectsPause(_effectsPaused ^= 1);
}
break;
case 'b':
_sound->ambientPause(_ambientPaused ^= 1);

View File

@ -120,9 +120,26 @@ void AGOSEngine::skipSpeech() {
}
}
void AGOSEngine::loadModule(uint music) {
_mixer->stopHandle(_modHandle);
void AGOSEngine::loadMusic(uint music) {
char buf[4];
stopMusic();
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music - 1], SEEK_SET);
_gameFile->read(buf, 4);
if (!memcmp(buf, "FORM", 4)) {
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music - 1], SEEK_SET);
_midi.loadXMIDI(_gameFile);
} else {
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music - 1], SEEK_SET);
_midi.loadMultipleSMF(_gameFile);
}
_lastMusicPlayed = music;
_nextMusicToPlay = -1;
}
void AGOSEngine::playModule(uint music) {
char filename[15];
File f;
@ -135,7 +152,7 @@ void AGOSEngine::loadModule(uint music) {
f.open(filename);
if (f.isOpen() == false) {
error("loadModule: Can't load module from '%s'", filename);
error("playModule: Can't load module from '%s'", filename);
}
Audio::AudioStream *audioStream;
@ -145,7 +162,7 @@ void AGOSEngine::loadModule(uint music) {
uint srcSize = f.size();
byte *srcBuf = (byte *)malloc(srcSize);
if (f.read(srcBuf, srcSize) != srcSize)
error("loadModule: Read failed");
error("playModule: Read failed");
uint dstSize = READ_BE_UINT32(srcBuf + srcSize - 4);
byte *dstBuf = (byte *)malloc(dstSize);
@ -162,29 +179,8 @@ void AGOSEngine::loadModule(uint music) {
_mixer->playInputStream(Audio::Mixer::kMusicSoundType, &_modHandle, audioStream);
}
void AGOSEngine_Simon2::loadMusic(uint music) {
char buf[4];
_midi.stop();
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music - 1], SEEK_SET);
_gameFile->read(buf, 4);
if (!memcmp(buf, "FORM", 4)) {
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music - 1], SEEK_SET);
_midi.loadXMIDI(_gameFile);
} else {
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music - 1], SEEK_SET);
_midi.loadMultipleSMF(_gameFile);
}
_lastMusicPlayed = music;
_nextMusicToPlay = -1;
}
void AGOSEngine_Simon1::loadMusic(uint music) {
char buf[4];
_midi.stop();
_midi.setLoop(true); // Must do this BEFORE loading music. (GMF may have its own override.)
void AGOSEngine_Simon1::playMusic(uint16 music, uint16 track) {
stopMusic();
// Support for compressed music from the ScummVM Music Enhancement Project
AudioCD.stop();
@ -195,14 +191,18 @@ void AGOSEngine_Simon1::loadMusic(uint music) {
if (getGameId() == GID_SIMON1ACORN) {
// TODO: Add support for Desktop Tracker format
} else if (getPlatform() == Common::kPlatformAmiga) {
loadModule(music);
playModule(music);
} else if (getFeatures() & GF_TALKIE) {
char buf[4];
// WORKAROUND: For a script bug in the CD versions
// We skip this music resource, as it was replaced by
// a sound effect, and the script was never updated.
if (music == 35)
return;
_midi.setLoop(true); // Must do this BEFORE loading music. (GMF may have its own override.)
_gameFile->seek(_gameOffsetsPtr[_musicIndexBase + music], SEEK_SET);
_gameFile->read(buf, 4);
if (!memcmp(buf, "GMF\x1", 4)) {
@ -214,13 +214,16 @@ void AGOSEngine_Simon1::loadMusic(uint music) {
}
_midi.startTrack(0);
_midi.startTrack(track);
} else {
char filename[15];
File f;
sprintf(filename, "MOD%d.MUS", music);
f.open(filename);
if (f.isOpen() == false)
error("loadMusic: Can't load music from '%s'", filename);
error("playMusic: Can't load music from '%s'", filename);
_midi.setLoop(true); // Must do this BEFORE loading music. (GMF may have its own override.)
if (getFeatures() & GF_DEMO)
_midi.loadS1D(&f);
@ -228,16 +231,18 @@ void AGOSEngine_Simon1::loadMusic(uint music) {
_midi.loadSMF(&f, music);
_midi.startTrack(0);
_midi.startTrack(track);
}
}
void AGOSEngine::loadMusic(uint music) {
void AGOSEngine::playMusic(uint16 music, uint16 track) {
stopMusic();
if (getPlatform() == Common::kPlatformAmiga) {
loadModule(music);
playModule(music);
} else if (getPlatform() == Common::kPlatformAtariST) {
// TODO: Add support for music formats used
} else {
_midi.stop();
_midi.setLoop(true); // Must do this BEFORE loading music.
char filename[15];
@ -245,10 +250,20 @@ void AGOSEngine::loadMusic(uint music) {
sprintf(filename, "MOD%d.MUS", music);
f.open(filename);
if (f.isOpen() == false)
error("loadMusic: Can't load music from '%s'", filename);
error("playMusic: Can't load music from '%s'", filename);
_midi.loadS1D(&f);
_midi.startTrack(0);
_midi.startTrack(track);
}
}
void AGOSEngine::stopMusic() {
if ((getPlatform() == Common::kPlatformAcorn && (getFeatures() & GF_TALKIE)) ||
getPlatform() == Common::kPlatformPC || getPlatform() == Common::kPlatformWindows) {
_midi.stop();
} else {
_mixer->stopHandle(_modHandle);
}
}

View File

@ -722,13 +722,12 @@ void AGOSEngine::o_doClassIcons() {
void AGOSEngine::o_playTune() {
// 127: play tune
int music = getVarOrWord();
int track = getVarOrWord();
uint16 music = getVarOrWord();
uint16 track = getVarOrWord();
if (music != _lastMusicPlayed) {
_lastMusicPlayed = music;
loadMusic(music);
_midi.startTrack(track);
playMusic(music, track);
}
}

View File

@ -843,20 +843,16 @@ void AGOSEngine_Elvira1::oe1_ifTime() {
void AGOSEngine_Elvira1::oe1_playTune() {
// 264: play tune
int music = getVarOrWord();
int track = getVarOrWord();
uint16 music = getVarOrWord();
uint16 track = getVarOrWord();
if (music != _lastMusicPlayed) {
_lastMusicPlayed = music;
// No tune under water
if (music == 4) {
if (getPlatform() == Common::kPlatformAmiga)
_mixer->stopHandle(_modHandle);
else
_midi.stop();
stopMusic();
} else {
loadMusic(music);
_midi.startTrack(track);
playMusic(music, track);
}
}
}

View File

@ -194,7 +194,7 @@ void AGOSEngine::vc72_segue() {
int16 loop = vcReadNextWord();
if (track == -1 || track == 999) {
_midi.stop();
stopMusic();
} else {
_midi.setLoop(loop != 0);
_midi.startTrack(track);