ACCESS: Implement music player (WIP)

This commit is contained in:
Strangerke 2014-12-01 14:07:09 +01:00 committed by Paul Gilbert
parent f364782d05
commit 11870c4144
4 changed files with 84 additions and 16 deletions

View File

@ -353,7 +353,7 @@ void Opening::doTitle() {
} }
_vm->_midi->newMusic(1, 1); _vm->_midi->newMusic(1, 1);
_vm->_midi->_musicRepeat = false; _vm->_midi->setLoop(false);
_vm->_events->zeroKeys(); _vm->_events->zeroKeys();
_vm->_room->loadRoom(0); _vm->_room->loadRoom(0);
_vm->_screen->clearScreen(); _vm->_screen->clearScreen();

View File

@ -184,7 +184,7 @@ void Room::loadRoomData(const byte *roomData) {
if (roomInfo._musicFile._fileNum != -1) { if (roomInfo._musicFile._fileNum != -1) {
_vm->_midi->loadMusic(roomInfo._musicFile); _vm->_midi->loadMusic(roomInfo._musicFile);
_vm->_midi->midiPlay(); _vm->_midi->midiPlay();
_vm->_midi->_musicRepeat = true; _vm->_midi->setLoop(true);
} }
_vm->_scaleH1 = roomInfo._scaleH1; _vm->_scaleH1 = roomInfo._scaleH1;

View File

@ -147,7 +147,20 @@ void SoundManager::freeSounds() {
MusicManager::MusicManager(AccessEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) { MusicManager::MusicManager(AccessEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) {
_music = nullptr; _music = nullptr;
_tempMusic = nullptr; _tempMusic = nullptr;
_musicRepeat = false; _isLooping = false;
MidiPlayer::createDriver();
MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_GM);
int retValue = _driver->open();
if (retValue == 0) {
if (_nativeMT32)
_driver->sendMT32Reset();
else
_driver->sendGMReset();
_driver->setTimerCallback(this, &timerCallback);
}
} }
MusicManager::~MusicManager() { MusicManager::~MusicManager() {
@ -155,46 +168,92 @@ MusicManager::~MusicManager() {
delete _tempMusic; delete _tempMusic;
} }
void MusicManager::send(uint32 b) {
if ((b & 0xF0) == 0xC0 && !_nativeMT32) {
b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8;
}
Audio::MidiPlayer::send(b);
}
void MusicManager::midiPlay() { void MusicManager::midiPlay() {
// TODO warning("MusicManager::midiPlay");
if (_music->_size < 4) {
error("midiPlay() wrong music resource size");
}
if (READ_BE_UINT32(_music->data()) != MKTAG('F', 'O', 'R', 'M'))
error("midiPlay() Unexpected signature");
stop();
_parser = MidiParser::createParser_XMIDI();
if (!_parser->loadMusic(_music->data(), _music->_size))
error("midiPlay() 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, _isLooping);
// _isLooping = loop;
setVolume(127);
_isPlaying = true;
} }
bool MusicManager::checkMidiDone() { bool MusicManager::checkMidiDone() {
// TODO warning("MusicManager::checkMidiDone");
return true; return (!_isPlaying);
} }
void MusicManager::midiRepeat() { void MusicManager::midiRepeat() {
// TODO warning("MusicManager::midiRepeat");
if (!_parser)
return;
_isLooping = true;
_parser->property(MidiParser::mpAutoLoop, _isLooping);
if (!_isPlaying)
_parser->setTrack(0);
} }
void MusicManager::stopSong() { void MusicManager::stopSong() {
// TODO warning("MusicManager::stopSong");
stop();
} }
void MusicManager::loadMusic(int fileNum, int subfile) { void MusicManager::loadMusic(int fileNum, int subfile) {
warning("MusicManager::loadMusic %d %d", fileNum, subfile);
_music = _vm->_files->loadFile(fileNum, subfile); _music = _vm->_files->loadFile(fileNum, subfile);
} }
void MusicManager::loadMusic(FileIdent file) { void MusicManager::loadMusic(FileIdent file) {
warning("MusicManager::loadMusic %d %d", file._fileNum, file._subfile);
_music = _vm->_files->loadFile(file); _music = _vm->_files->loadFile(file);
} }
void MusicManager::newMusic(int musicId, int mode) { void MusicManager::newMusic(int musicId, int mode) {
warning("MusicManager::newMusic %d %d", musicId, mode);
if (mode == 1) { if (mode == 1) {
stopSong(); stopSong();
freeMusic(); freeMusic();
_music = _tempMusic; _music = _tempMusic;
_tempMusic = nullptr; _tempMusic = nullptr;
_musicRepeat = true; _isLooping = true;
if (_music)
midiPlay();
} else { } else {
_musicRepeat = (mode == 2); _isLooping = (mode == 2);
_tempMusic = _music; _tempMusic = _music;
stopSong(); stopSong();
loadMusic(97, musicId); loadMusic(97, musicId);
} }
if (_music)
midiPlay();
} }
void MusicManager::freeMusic() { void MusicManager::freeMusic() {
@ -202,4 +261,9 @@ void MusicManager::freeMusic() {
_music = nullptr; _music = nullptr;
} }
void MusicManager::setLoop(bool loop) {
_isLooping = loop;
if (_parser)
_parser->property(MidiParser::mpAutoLoop, _isLooping);
}
} // End of namespace Access } // End of namespace Access

View File

@ -26,6 +26,8 @@
#include "common/scummsys.h" #include "common/scummsys.h"
#include "audio/mixer.h" #include "audio/mixer.h"
#include "access/files.h" #include "access/files.h"
#include "audio/midiplayer.h"
#include "audio/midiparser.h"
#define MAX_SOUNDS 20 #define MAX_SOUNDS 20
@ -70,17 +72,17 @@ public:
void freeSounds(); void freeSounds();
}; };
class MusicManager { class MusicManager : public Audio::MidiPlayer {
private: private:
AccessEngine *_vm; AccessEngine *_vm;
Audio::Mixer *_mixer; Audio::Mixer *_mixer;
Resource *_tempMusic; Resource *_tempMusic;
public: // MidiDriver_BASE interface implementation
bool _musicRepeat; virtual void send(uint32 b);
bool _playingSound;
public:
Resource *_music; Resource *_music;
public: public:
@ -101,6 +103,8 @@ public:
void loadMusic(int fileNum, int subfile); void loadMusic(int fileNum, int subfile);
void loadMusic(FileIdent file); void loadMusic(FileIdent file);
void setLoop(bool loop);
}; };
} // End of namespace Access } // End of namespace Access