diff options
| -rw-r--r-- | queen/module.mk | 1 | ||||
| -rw-r--r-- | queen/music.cpp | 80 | ||||
| -rw-r--r-- | queen/music.h | 57 | ||||
| -rw-r--r-- | queen/queen.cpp | 5 | ||||
| -rw-r--r-- | queen/queen.h | 3 | ||||
| -rw-r--r-- | queen/sound.cpp | 29 | 
6 files changed, 173 insertions, 2 deletions
diff --git a/queen/module.mk b/queen/module.mk index 64f10fc6c0..c3fa7b6659 100644 --- a/queen/module.mk +++ b/queen/module.mk @@ -9,6 +9,7 @@ MODULE_OBJS = \  	queen/input.o \  	queen/journal.o \  	queen/logic.o \ +	queen/music.o \  	queen/musicdata.o \  	queen/queen.o \  	queen/resource.o \ diff --git a/queen/music.cpp b/queen/music.cpp new file mode 100644 index 0000000000..592b196c0b --- /dev/null +++ b/queen/music.cpp @@ -0,0 +1,80 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2003 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 "queen/music.h" +#include "queen/queen.h" +#include "queen/resource.h" + +#include "sound/mididrv.h" +#include "sound/midiparser.h" + +namespace Queen { + +	Music::Music(MidiDriver *driver, QueenEngine *vm) : _loop(false), _driver(driver) { +		_midi = MidiParser::createParser_SMF(); +		_midi->setMidiDriver(_driver); +		int ret = _driver->open(); +		if (ret) +			warning("MIDI Player init failed: \"%s\"", _driver->getErrorName(ret)); +		_midi->setTimerRate(_driver->getBaseTempo()); +		_driver->setTimerCallback((void *)_midi, _midi->timerCallback); +					 +		_musicData = vm->resource()->loadFile("AQ.RL", 0, NULL); +		_musicDataSize = vm->resource()->fileSize("AQ.RL"); +		_numSongs = READ_LE_UINT16(_musicData); +	} + +	Music::~Music() { +		stopSong(); +		_midi->unloadMusic(); +		delete _midi; +		delete[] _musicData;	 +	} + +	void Music::playSong(uint16 songNum) { +		if (_loop) +			_midi->property(MidiParser::mpAutoLoop, 1); +		else +			_midi->property(MidiParser::mpAutoLoop, 0); +		 +		_midi->loadMusic(_musicData + songOffset(songNum), songLength(songNum)); +		_midi->setTrack(0);		 +		_driver->setTimerCallback((void *)_midi, _midi->timerCallback); +	} + +	void Music::stopSong() { +		_driver->setTimerCallback(NULL, NULL); +	} +	 +	uint32 Music::songOffset(uint16 songNum) { +		uint16 offsLo = READ_LE_UINT16(_musicData + (songNum * 4) + 2); +		uint16 offsHi = READ_LE_UINT16(_musicData + (songNum * 4) + 4); +		return (offsHi << 4) | offsLo; +	} + +	uint32 Music::songLength(uint16 songNum) { +		if (songNum < _numSongs) +			return (songOffset(songNum + 1) - songOffset(songNum)); +		return (_musicDataSize - songOffset(songNum)); +	} +	 +} // End of namespace Queen diff --git a/queen/music.h b/queen/music.h new file mode 100644 index 0000000000..e44ddbae97 --- /dev/null +++ b/queen/music.h @@ -0,0 +1,57 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2003 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$ + * + */ + +#ifndef QUEENMUSIC_H +#define QUEENMUSIC_H + +#include "common/util.h" + +class MidiDriver; +class MidiParser; + +namespace Queen { + +class QueenEngine; +	 +class Music { +public: +	Music(MidiDriver *_driver, QueenEngine *vm); +	~Music(); +	void playSong(uint16 songNum); +	void stopSong(); +	void loop(bool val)	{ _loop = val; } +	 +protected: +	bool _loop; +	byte *_musicData; +	uint16 _numSongs; +	uint32 _musicDataSize; +	MidiDriver *_driver; +	MidiParser *_midi; +	QueenEngine *_vm; +	 +	uint32 songOffset(uint16 songNum); +	uint32 songLength(uint16 songNum); +}; + +} // End of namespace Queen + +#endif diff --git a/queen/queen.cpp b/queen/queen.cpp index 7ef927eb5a..3647379260 100644 --- a/queen/queen.cpp +++ b/queen/queen.cpp @@ -37,6 +37,7 @@  #include "queen/graphics.h"  #include "queen/input.h"  #include "queen/logic.h" +#include "queen/music.h"  #include "queen/resource.h"  #include "queen/sound.h"  #include "queen/talk.h" @@ -107,6 +108,7 @@ QueenEngine::~QueenEngine() {  	delete _graphics;  	delete _input;  	delete _logic; +	delete _music;  	delete _sound;  	delete _walk;	  } @@ -119,7 +121,7 @@ void QueenEngine::errorString(const char *buf1, char *buf2) {  void QueenEngine::go() {  	initialise(); - +	  	_logic->registerDefaultSettings();  	_logic->readOptionSettings(); @@ -163,6 +165,7 @@ void QueenEngine::initialise(void) {  	_graphics = new Graphics(this);  	_input = new Input(_resource->getLanguage(), _system);  	_logic = new Logic(this); +	_music = new Music(GameDetector::createMidi(GameDetector::detectMusicDriver(MDT_NATIVE)), this);  	_sound = Sound::giveSound(_mixer, this, _resource->compression());  	_walk = new Walk(this);  	_timer->installTimerProc(&timerHandler, 1000000 / 50, this); //call 50 times per second diff --git a/queen/queen.h b/queen/queen.h index 1fe5ad997f..f8317e1e3c 100644 --- a/queen/queen.h +++ b/queen/queen.h @@ -33,6 +33,7 @@ class Display;  class Graphics;  class Input;  class Logic; +class Music;  class Resource;  class Sound;  class Walk; @@ -48,6 +49,7 @@ public:  	Graphics *graphics() const { return _graphics; }  	Input *input() const { return _input; }  	Logic *logic() const { return _logic; } +	Music *music() const { return _music; }  	Resource *resource() const { return _resource; }  	Sound *sound() const { return _sound; }  	Walk *walk() const { return _walk; } @@ -70,6 +72,7 @@ protected:  	Graphics *_graphics;  	Input *_input;  	Logic *_logic; +	Music *_music;  	Resource *_resource;  	Sound *_sound;  	Walk *_walk; diff --git a/queen/sound.cpp b/queen/sound.cpp index fbc710a711..397891248d 100644 --- a/queen/sound.cpp +++ b/queen/sound.cpp @@ -23,6 +23,7 @@  #include "queen/sound.h"  #include "queen/input.h" +#include "queen/music.h"  #include "queen/queen.h"  #include "queen/resource.h" @@ -135,10 +136,36 @@ void Sound::waitSfxFinished() {  }  void Sound::playSong(int16 songNum) { +	if (songNum == STOP_MUSIC) { +		_vm->music()->stopSong(); +		return; +	} +	  	int16 newTune = _song[songNum - 1].tuneList[0]; -	if (_tune[newTune - 1].sfx[0] && sfxOn()) +	if (_tune[newTune - 1].sfx[0] && sfxOn()) {  		sfxPlay(_sfxName[_tune[newTune - 1].sfx[0] - 1]); +		return; +	} + +	//TODO: Record onto song stack for saving/loading +	 +	switch (_tune[newTune - 1].mode) { +		//Random loop +		case  0: +			warning("Music: Random loop not yet supported (doing sequential loop instead)"); +		//Sequential loop +		case  1: +			_vm->music()->loop(true); +			break; +		//Play once +		case  2: +		default: +			_vm->music()->loop(false); +			break; +	} + +	_vm->music()->playSong(_tune[newTune - 1].tuneNum[0] - 1);  }  | 
