2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-12 21:40:49 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-07-31 18:08:40 +00:00
|
|
|
|
|
|
|
// MIDI and digital music class
|
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-12-22 14:13:15 +00:00
|
|
|
#include "saga/resource.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/music.h"
|
2007-09-23 09:59:10 +00:00
|
|
|
|
2011-02-09 01:09:01 +00:00
|
|
|
#include "audio/audiostream.h"
|
|
|
|
#include "audio/mididrv.h"
|
|
|
|
#include "audio/midiparser.h"
|
|
|
|
#include "audio/decoders/raw.h"
|
2004-04-29 04:24:55 +00:00
|
|
|
#include "common/config-manager.h"
|
2004-04-30 07:13:26 +00:00
|
|
|
#include "common/file.h"
|
2010-11-19 17:03:07 +00:00
|
|
|
#include "common/substream.h"
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-04-29 03:52:59 +00:00
|
|
|
namespace Saga {
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-12 11:45:53 +00:00
|
|
|
#define BUFFER_SIZE 4096
|
2008-05-26 11:10:46 +00:00
|
|
|
#define MUSIC_SUNSPOT 26
|
2004-10-12 11:45:53 +00:00
|
|
|
|
2010-06-12 18:20:22 +00:00
|
|
|
MusicDriver::MusicDriver() : _isGM(false) {
|
|
|
|
|
2011-03-28 16:06:24 +00:00
|
|
|
MidiPlayer::createDriver();
|
2011-03-25 15:59:54 +00:00
|
|
|
|
2011-03-28 16:06:24 +00:00
|
|
|
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
|
2010-09-28 04:53:38 +00:00
|
|
|
_driverType = MidiDriver::getMusicType(dev);
|
2010-06-12 18:20:22 +00:00
|
|
|
|
2011-03-23 15:14:39 +00:00
|
|
|
int retValue = _driver->open();
|
|
|
|
if (retValue == 0) {
|
|
|
|
if (_nativeMT32)
|
|
|
|
_driver->sendMT32Reset();
|
|
|
|
else
|
|
|
|
_driver->sendGMReset();
|
2011-03-25 15:59:54 +00:00
|
|
|
|
|
|
|
_driver->setTimerCallback(this, &timerCallback);
|
2011-03-23 15:14:39 +00:00
|
|
|
}
|
2004-04-29 03:52:59 +00:00
|
|
|
}
|
2004-05-01 13:04:31 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
void MusicDriver::send(uint32 b) {
|
|
|
|
if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) {
|
|
|
|
// Remap MT32 instruments to General Midi
|
|
|
|
b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
|
|
|
|
}
|
|
|
|
Audio::MidiPlayer::send(b);
|
2004-05-01 13:04:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
void MusicDriver::metaEvent(byte type, byte *data, uint16 length) {
|
|
|
|
// TODO: Seems SAGA does not want / need to handle end-of-track events?
|
|
|
|
}
|
2004-04-29 04:24:55 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
void MusicDriver::play(SagaEngine *vm, ByteArray *buffer, bool loop) {
|
|
|
|
if (buffer->size() < 4) {
|
|
|
|
error("Music::play() wrong music resource size");
|
|
|
|
}
|
2008-08-20 09:12:11 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
// Check if the game is using XMIDI or SMF music
|
|
|
|
if (vm->getGameId() == GID_IHNM && vm->isMacResources()) {
|
|
|
|
// Just set an XMIDI parser for Mac IHNM for now
|
|
|
|
_parser = MidiParser::createParser_XMIDI();
|
|
|
|
} else {
|
|
|
|
if (!memcmp(buffer->getBuffer(), "FORM", 4)) {
|
|
|
|
_parser = MidiParser::createParser_XMIDI();
|
|
|
|
// ITE had MT32 mapped instruments
|
|
|
|
_isGM = (vm->getGameId() != GID_ITE);
|
|
|
|
} else {
|
|
|
|
_parser = MidiParser::createParser_SMF();
|
|
|
|
// ITE with standalone MIDI files is General MIDI
|
|
|
|
_isGM = (vm->getGameId() == GID_ITE);
|
2004-04-29 04:24:55 +00:00
|
|
|
}
|
2004-04-29 03:52:59 +00:00
|
|
|
}
|
2011-03-25 15:59:54 +00:00
|
|
|
|
|
|
|
if (!_parser->loadMusic(buffer->getBuffer(), buffer->size()))
|
|
|
|
error("Music::play() wrong music resource");
|
|
|
|
|
|
|
|
_parser->setTrack(0);
|
|
|
|
_parser->setMidiDriver(this);
|
|
|
|
_parser->setTimerRate(_driver->getBaseTempo());
|
|
|
|
_parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1);
|
|
|
|
_parser->property(MidiParser::mpSendSustainOffOnNotesOff, 1);
|
|
|
|
|
|
|
|
// Handle music looping
|
|
|
|
_parser->property(MidiParser::mpAutoLoop, loop);
|
|
|
|
// _isLooping = loop;
|
|
|
|
|
|
|
|
_isPlaying = true;
|
2004-04-29 03:52:59 +00:00
|
|
|
}
|
2004-05-01 13:04:31 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
void MusicDriver::pause() {
|
|
|
|
_isPlaying = false;
|
|
|
|
}
|
2004-05-01 13:04:31 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
void MusicDriver::resume() {
|
|
|
|
_isPlaying = true;
|
2004-04-29 03:52:59 +00:00
|
|
|
}
|
2004-05-01 13:04:31 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
|
2010-06-12 18:20:22 +00:00
|
|
|
Music::Music(SagaEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) {
|
|
|
|
_currentVolume = 0;
|
2010-10-24 22:17:44 +00:00
|
|
|
_currentMusicBuffer = NULL;
|
2011-03-25 15:59:54 +00:00
|
|
|
_player = new MusicDriver();
|
2004-05-01 13:04:31 +00:00
|
|
|
|
2010-06-12 18:20:22 +00:00
|
|
|
_digitalMusicContext = _vm->_resource->getContext(GAME_DIGITALMUSICFILE);
|
2011-03-25 15:59:54 +00:00
|
|
|
if (!_player->isAdlib())
|
2010-06-12 18:20:22 +00:00
|
|
|
_musicContext = _vm->_resource->getContext(GAME_MUSICFILE_GM);
|
|
|
|
else
|
|
|
|
_musicContext = _vm->_resource->getContext(GAME_MUSICFILE_FM);
|
2007-08-22 15:28:31 +00:00
|
|
|
|
2010-06-12 18:20:22 +00:00
|
|
|
if (!_musicContext) {
|
|
|
|
if (_vm->getGameId() == GID_ITE) {
|
|
|
|
_musicContext = _vm->_resource->getContext(GAME_RESOURCEFILE);
|
|
|
|
} else {
|
|
|
|
// I've listened to music from both the FM and the GM
|
|
|
|
// file, and I've tentatively reached the conclusion
|
|
|
|
// that they are both General MIDI. My guess is that
|
|
|
|
// the FM file has been reorchestrated to sound better
|
|
|
|
// on AdLib and other FM synths.
|
|
|
|
//
|
|
|
|
// Sev says the AdLib music does not sound like in the
|
|
|
|
// original, but I still think assuming General MIDI is
|
|
|
|
// the right thing to do. Some music, like the End
|
|
|
|
// Title (song 0) sound absolutely atrocious when piped
|
|
|
|
// through our MT-32 to GM mapping.
|
|
|
|
//
|
|
|
|
// It is, however, quite possible that the original
|
|
|
|
// used a different GM to FM mapping. If the original
|
|
|
|
// sounded markedly better, perhaps we should add some
|
|
|
|
// way of replacing our stock mapping in adlib.cpp?
|
|
|
|
//
|
|
|
|
// For the composer's own recording of the End Title,
|
|
|
|
// see http://www.johnottman.com/
|
|
|
|
|
|
|
|
// Oddly enough, the intro music (song 1) is very
|
|
|
|
// different in the two files. I have no idea why.
|
|
|
|
// Note that the IHNM demo has only got one music file
|
|
|
|
// (music.rsc). It is assumed that it contains FM music
|
|
|
|
_musicContext = _vm->_resource->getContext(GAME_MUSICFILE_FM);
|
|
|
|
}
|
2004-05-31 08:46:36 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-11-11 17:34:52 +00:00
|
|
|
_digitalMusic = false;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-04-29 03:52:59 +00:00
|
|
|
Music::~Music() {
|
2008-12-25 20:53:59 +00:00
|
|
|
_vm->getTimerManager()->removeTimerProc(&musicVolumeGaugeCallback);
|
2005-07-19 21:48:59 +00:00
|
|
|
_mixer->stopHandle(_musicHandle);
|
2011-03-25 15:59:54 +00:00
|
|
|
delete _player;
|
2004-04-29 03:52:59 +00:00
|
|
|
}
|
|
|
|
|
2005-06-19 21:18:00 +00:00
|
|
|
void Music::musicVolumeGaugeCallback(void *refCon) {
|
|
|
|
((Music *)refCon)->musicVolumeGauge();
|
2005-07-29 17:58:00 +00:00
|
|
|
}
|
2005-06-19 21:18:00 +00:00
|
|
|
|
|
|
|
void Music::musicVolumeGauge() {
|
|
|
|
int volume;
|
|
|
|
|
|
|
|
_currentVolumePercent += 10;
|
|
|
|
|
|
|
|
if (_currentVolume - _targetVolume > 0) { // Volume decrease
|
|
|
|
volume = _targetVolume + (_currentVolume - _targetVolume) * (100 - _currentVolumePercent) / 100;
|
|
|
|
} else {
|
|
|
|
volume = _currentVolume + (_targetVolume - _currentVolume) * _currentVolumePercent / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (volume < 0)
|
|
|
|
volume = 1;
|
|
|
|
|
2005-07-19 21:48:59 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->setVolume(volume);
|
2005-06-19 21:18:00 +00:00
|
|
|
|
|
|
|
if (_currentVolumePercent == 100) {
|
2008-12-25 20:53:59 +00:00
|
|
|
_vm->getTimerManager()->removeTimerProc(&musicVolumeGaugeCallback);
|
2005-06-19 21:18:00 +00:00
|
|
|
_currentVolume = _targetVolume;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Music::setVolume(int volume, int time) {
|
2008-09-05 13:02:03 +00:00
|
|
|
_targetVolume = volume;
|
2005-06-19 21:18:00 +00:00
|
|
|
_currentVolumePercent = 0;
|
|
|
|
|
|
|
|
if (volume == -1) // Set Full volume
|
2005-09-02 20:17:52 +00:00
|
|
|
volume = 255;
|
2005-06-19 21:18:00 +00:00
|
|
|
|
|
|
|
if (time == 1) {
|
2011-03-19 14:07:06 +00:00
|
|
|
if (ConfMan.hasKey("mute") && ConfMan.getBool("mute"))
|
|
|
|
volume = 0;
|
|
|
|
|
2005-07-19 21:48:59 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->setVolume(volume);
|
2008-12-25 20:53:59 +00:00
|
|
|
_vm->getTimerManager()->removeTimerProc(&musicVolumeGaugeCallback);
|
2005-06-19 21:18:00 +00:00
|
|
|
_currentVolume = volume;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-05 09:15:20 +00:00
|
|
|
_vm->getTimerManager()->installTimerProc(&musicVolumeGaugeCallback, time * 3000L, this, "sagaMusicVolume");
|
2005-06-19 21:18:00 +00:00
|
|
|
}
|
|
|
|
|
2005-01-17 14:19:17 +00:00
|
|
|
bool Music::isPlaying() {
|
2011-03-25 15:59:54 +00:00
|
|
|
return _mixer->isSoundHandleActive(_musicHandle) || _player->isPlaying();
|
2005-01-17 14:19:17 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
void Music::play(uint32 resourceId, MusicFlags flags) {
|
2010-01-06 00:00:50 +00:00
|
|
|
Audio::SeekableAudioStream *audioStream = NULL;
|
2010-10-22 23:13:17 +00:00
|
|
|
uint32 loopStart = 0;
|
2005-09-20 18:04:26 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
debug(2, "Music::play %d, %d", resourceId, flags);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (isPlaying() && _trackNumber == resourceId) {
|
|
|
|
return;
|
2005-01-17 14:19:17 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_trackNumber = resourceId;
|
2005-03-12 18:56:09 +00:00
|
|
|
_mixer->stopHandle(_musicHandle);
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->stop();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2005-09-21 10:46:20 +00:00
|
|
|
int realTrackNumber;
|
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE) {
|
2005-09-21 10:46:20 +00:00
|
|
|
if (flags == MUSIC_DEFAULT) {
|
|
|
|
if (resourceId == 13 || resourceId == 19) {
|
|
|
|
flags = MUSIC_NORMAL;
|
|
|
|
} else {
|
|
|
|
flags = MUSIC_LOOP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
realTrackNumber = resourceId - 8;
|
|
|
|
} else {
|
|
|
|
realTrackNumber = resourceId + 1;
|
|
|
|
}
|
|
|
|
|
2009-08-17 18:25:51 +00:00
|
|
|
// Try to open standalone digital track
|
|
|
|
char trackName[2][16];
|
|
|
|
sprintf(trackName[0], "track%d", realTrackNumber);
|
|
|
|
sprintf(trackName[1], "track%02d", realTrackNumber);
|
2010-01-06 00:00:50 +00:00
|
|
|
Audio::SeekableAudioStream *stream = 0;
|
2009-08-17 18:25:51 +00:00
|
|
|
for (int i = 0; i < 2; ++i) {
|
2010-01-06 15:23:33 +00:00
|
|
|
stream = Audio::SeekableAudioStream::openStreamFile(trackName[i]);
|
2009-08-17 18:25:51 +00:00
|
|
|
if (stream) {
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle,
|
2010-01-08 16:27:29 +00:00
|
|
|
Audio::makeLoopingAudioStream(stream, (flags == MUSIC_LOOP) ? 0 : 1));
|
2009-08-17 18:25:51 +00:00
|
|
|
_digitalMusic = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_ITE) {
|
2005-07-19 19:05:52 +00:00
|
|
|
if (resourceId >= 9 && resourceId <= 34) {
|
2007-07-12 08:52:07 +00:00
|
|
|
if (_digitalMusicContext != NULL) {
|
2006-03-24 18:15:57 +00:00
|
|
|
loopStart = 0;
|
2009-08-17 18:25:51 +00:00
|
|
|
// Fix ITE sunstatm/sunspot score
|
2009-08-17 13:25:44 +00:00
|
|
|
if (resourceId == MUSIC_SUNSPOT)
|
2010-01-10 15:20:14 +00:00
|
|
|
loopStart = 18727;
|
2006-03-24 18:15:57 +00:00
|
|
|
|
2009-08-17 13:25:44 +00:00
|
|
|
// Digital music
|
|
|
|
ResourceData *resData = _digitalMusicContext->getResourceData(resourceId - 9);
|
|
|
|
Common::File *musicFile = _digitalMusicContext->getFile(resData);
|
2009-12-04 17:52:42 +00:00
|
|
|
int offs = (_digitalMusicContext->isCompressed()) ? 9 : 0;
|
2009-08-17 13:25:44 +00:00
|
|
|
|
2010-01-25 01:39:44 +00:00
|
|
|
Common::SeekableSubReadStream *musicStream = new Common::SeekableSubReadStream(musicFile,
|
2009-08-17 13:25:44 +00:00
|
|
|
(uint32)resData->offset + offs, (uint32)resData->offset + resData->size - offs);
|
|
|
|
|
2009-12-04 17:52:42 +00:00
|
|
|
if (!_digitalMusicContext->isCompressed()) {
|
2010-01-25 01:39:44 +00:00
|
|
|
byte musicFlags = Audio::FLAG_STEREO |
|
2010-01-19 22:30:33 +00:00
|
|
|
Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN;
|
2010-02-26 22:24:48 +00:00
|
|
|
|
|
|
|
if (_vm->isBigEndian())
|
|
|
|
musicFlags &= ~Audio::FLAG_LITTLE_ENDIAN;
|
|
|
|
|
2011-07-09 12:59:30 +00:00
|
|
|
// The newer ITE Mac demo version contains a music file, but it has mono music.
|
|
|
|
// This is the only music file that is about 7MB, whereas all the other ones
|
|
|
|
// are much larger. Thus, we use this simple heuristic to determine if we got
|
|
|
|
// mono music in the ITE demos or not.
|
|
|
|
if (!strcmp(_digitalMusicContext->fileName(), "musicd.rsc") &&
|
|
|
|
_digitalMusicContext->fileSize() < 8000000)
|
2010-02-26 22:24:48 +00:00
|
|
|
musicFlags &= ~Audio::FLAG_STEREO;
|
|
|
|
|
2010-01-30 15:17:57 +00:00
|
|
|
audioStream = Audio::makeRawStream(musicStream, 11025, musicFlags, DisposeAfterUse::YES);
|
2009-08-17 13:25:44 +00:00
|
|
|
} else {
|
|
|
|
// Read compressed header to determine compression type
|
|
|
|
musicFile->seek((uint32)resData->offset, SEEK_SET);
|
|
|
|
byte identifier = musicFile->readByte();
|
|
|
|
|
|
|
|
if (identifier == 0) { // MP3
|
|
|
|
#ifdef USE_MAD
|
2010-01-16 21:36:08 +00:00
|
|
|
audioStream = Audio::makeMP3Stream(musicStream, DisposeAfterUse::YES);
|
2009-08-17 13:25:44 +00:00
|
|
|
#endif
|
|
|
|
} else if (identifier == 1) { // OGG
|
|
|
|
#ifdef USE_VORBIS
|
2010-01-16 21:36:08 +00:00
|
|
|
audioStream = Audio::makeVorbisStream(musicStream, DisposeAfterUse::YES);
|
2009-08-17 13:25:44 +00:00
|
|
|
#endif
|
|
|
|
} else if (identifier == 2) { // FLAC
|
|
|
|
#ifdef USE_FLAC
|
2010-02-03 09:42:11 +00:00
|
|
|
audioStream = Audio::makeFLACStream(musicStream, DisposeAfterUse::YES);
|
2009-08-17 13:25:44 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2010-01-10 15:23:35 +00:00
|
|
|
|
|
|
|
if (!audioStream)
|
|
|
|
delete musicStream;
|
2004-11-15 03:03:48 +00:00
|
|
|
}
|
2004-05-16 12:57:49 +00:00
|
|
|
}
|
2004-04-30 07:13:26 +00:00
|
|
|
}
|
|
|
|
|
2004-10-12 11:45:53 +00:00
|
|
|
if (audioStream) {
|
2005-06-05 09:28:40 +00:00
|
|
|
debug(2, "Playing digitized music");
|
2010-01-10 15:20:14 +00:00
|
|
|
if (loopStart) {
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle,
|
2010-01-10 15:20:14 +00:00
|
|
|
new Audio::SubLoopingAudioStream(audioStream,
|
|
|
|
(flags == MUSIC_LOOP ? 0 : 1),
|
|
|
|
Audio::Timestamp(0, loopStart, audioStream->getRate()),
|
|
|
|
audioStream->getLength()));
|
|
|
|
} else {
|
2010-04-12 09:14:17 +00:00
|
|
|
_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle,
|
2010-01-10 15:20:14 +00:00
|
|
|
Audio::makeLoopingAudioStream(audioStream, (flags == MUSIC_LOOP ? 0 : 1)));
|
|
|
|
}
|
2008-11-11 17:34:52 +00:00
|
|
|
_digitalMusic = true;
|
2005-07-19 19:05:52 +00:00
|
|
|
return;
|
2004-10-12 11:45:53 +00:00
|
|
|
}
|
2004-05-31 08:46:36 +00:00
|
|
|
|
2010-06-12 18:20:22 +00:00
|
|
|
if (flags == MUSIC_DEFAULT)
|
2005-07-19 19:05:52 +00:00
|
|
|
flags = MUSIC_NORMAL;
|
2004-04-30 07:13:26 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
// Load MIDI/XMI resource data
|
2008-12-21 15:59:05 +00:00
|
|
|
if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) {
|
2008-04-05 14:06:50 +00:00
|
|
|
// Load the external music file for Mac IHNM
|
2010-01-23 13:46:43 +00:00
|
|
|
#if 0
|
2008-04-05 14:06:50 +00:00
|
|
|
Common::File musicFile;
|
|
|
|
char musicFileName[40];
|
2008-04-05 14:18:32 +00:00
|
|
|
sprintf(musicFileName, "Music/Music%02x", resourceId);
|
2008-04-05 14:06:50 +00:00
|
|
|
musicFile.open(musicFileName);
|
|
|
|
resourceSize = musicFile.size();
|
|
|
|
resourceData = new byte[resourceSize];
|
|
|
|
musicFile.read(resourceData, resourceSize);
|
|
|
|
musicFile.close();
|
|
|
|
|
2008-05-26 11:10:46 +00:00
|
|
|
// TODO: The Mac music format is unsupported (QuickTime MIDI)
|
2008-04-05 14:06:50 +00:00
|
|
|
// so stop here
|
2010-01-23 13:46:43 +00:00
|
|
|
#endif
|
2008-04-05 14:06:50 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2010-10-24 22:17:44 +00:00
|
|
|
if (_currentMusicBuffer == &_musicBuffer[1]) {
|
|
|
|
_currentMusicBuffer = &_musicBuffer[0];
|
|
|
|
} else {
|
|
|
|
_currentMusicBuffer = &_musicBuffer[1];
|
|
|
|
}
|
|
|
|
_vm->_resource->loadResource(_musicContext, resourceId, *_currentMusicBuffer);
|
2008-04-05 14:06:50 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->play(_vm, _currentMusicBuffer, (flags & MUSIC_LOOP));
|
2008-09-05 13:02:03 +00:00
|
|
|
setVolume(_vm->_musicVolume);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void Music::pause() {
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->pause();
|
2011-07-10 05:39:38 +00:00
|
|
|
_player->setVolume(0);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void Music::resume() {
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->resume();
|
2011-07-10 05:39:38 +00:00
|
|
|
_player->setVolume(_vm->_musicVolume);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2009-11-02 21:54:57 +00:00
|
|
|
void Music::stop() {
|
2011-03-25 15:59:54 +00:00
|
|
|
_player->stop();
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Saga
|