diff options
author | Filippos Karapetis | 2008-04-24 14:12:08 +0000 |
---|---|---|
committer | Filippos Karapetis | 2008-04-24 14:12:08 +0000 |
commit | 068372ac94ee9cde99df7a8fee64d2c8424bb119 (patch) | |
tree | c68bc762798171219381eb29077dc13beb155aef /engines/made | |
parent | 551bd59fa89fbcb1f460072aaabb20a890266289 (diff) | |
download | scummvm-rg350-068372ac94ee9cde99df7a8fee64d2c8424bb119.tar.gz scummvm-rg350-068372ac94ee9cde99df7a8fee64d2c8424bb119.tar.bz2 scummvm-rg350-068372ac94ee9cde99df7a8fee64d2c8424bb119.zip |
Cleanup and simplification of the music playing code
svn-id: r31691
Diffstat (limited to 'engines/made')
-rw-r--r-- | engines/made/made.cpp | 4 | ||||
-rw-r--r-- | engines/made/made.h | 4 | ||||
-rw-r--r-- | engines/made/music.cpp | 135 | ||||
-rw-r--r-- | engines/made/music.h | 58 |
4 files changed, 44 insertions, 157 deletions
diff --git a/engines/made/made.cpp b/engines/made/made.cpp index 51da50f7d3..1cbb13fc6c 100644 --- a/engines/made/made.cpp +++ b/engines/made/made.cpp @@ -97,9 +97,9 @@ MadeEngine::MadeEngine(OSystem *syst, const MadeGameDescription *gameDesc) : Eng if (native_mt32) driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE); - _music = new Music(driver, _musicVolume); + _music = new MusicPlayer(driver); _music->setNativeMT32(native_mt32); - _music->setAdlib(adlib); + //_music->setAdlib(adlib); _musicVolume = ConfMan.getInt("music_volume"); diff --git a/engines/made/made.h b/engines/made/made.h index 8cf26c0d81..ad4cd78660 100644 --- a/engines/made/made.h +++ b/engines/made/made.h @@ -61,7 +61,7 @@ class PmvPlayer; class Screen; class ScriptInterpreter; class GameDatabase; -class Music; +class MusicPlayer; class MadeEngine : public ::Engine { int _gameId; @@ -94,7 +94,7 @@ public: Screen *_screen; GameDatabase *_dat; ScriptInterpreter *_script; - Music *_music; + MusicPlayer *_music; int _eventMouseX, _eventMouseY; uint16 _eventKey; diff --git a/engines/made/music.cpp b/engines/made/music.cpp index ec9b59c12e..b9a0154093 100644 --- a/engines/made/music.cpp +++ b/engines/made/music.cpp @@ -41,12 +41,15 @@ MusicPlayer::MusicPlayer(MidiDriver *driver) : _parser(0), _driver(driver), _loo memset(_channel, 0, sizeof(_channel)); _masterVolume = 0; this->open(); + _xmidiParser = MidiParser::createParser_XMIDI(); } MusicPlayer::~MusicPlayer() { _driver->setTimerCallback(NULL, NULL); - stopMusic(); + stop(); this->close(); + _xmidiParser->setMidiDriver(NULL); + delete _xmidiParser; } void MusicPlayer::setVolume(int volume) { @@ -78,7 +81,7 @@ int MusicPlayer::open() { } void MusicPlayer::close() { - stopMusic(); + stop(); if (_driver) _driver->close(); _driver = 0; @@ -121,7 +124,7 @@ void MusicPlayer::metaEvent(byte type, byte *data, uint16 length) { if (_looping) _parser->jumpToTick(0); else - stopMusic(); + stop(); break; default: //warning("Unhandled meta event: %02x", type); @@ -137,127 +140,57 @@ void MusicPlayer::onTimer(void *refCon) { music->_parser->onTimer(); } -void MusicPlayer::playMusic() { - _isPlaying = true; -} - -void MusicPlayer::stopMusic() { - Common::StackLock lock(_mutex); - - _isPlaying = false; - if (_parser) { - _parser->unloadMusic(); - _parser = NULL; - } -} - -Music::Music(MidiDriver *driver, int enabled) : _enabled(enabled), _adlib(false) { - _player = new MusicPlayer(driver); - _currentVolume = 0; - - xmidiParser = MidiParser::createParser_XMIDI(); - - _songTableLen = 0; - _songTable = 0; - - _midiMusicData = NULL; -} - -Music::~Music() { - delete _player; - xmidiParser->setMidiDriver(NULL); - delete xmidiParser; - - free(_songTable); - if (_midiMusicData) - delete[] _midiMusicData; -} - -void Music::setVolume(int volume) { - if (volume == -1) // Set Full volume - volume = 255; - - _player->setVolume(volume); - _currentVolume = volume; -} - -bool Music::isPlaying() { - return _player->isPlaying(); -} - -void Music::play(XmidiResource *midiResource, MusicFlags flags) { - MidiParser *parser = 0; +void MusicPlayer::play(XmidiResource *midiResource, MusicFlags flags) { byte *resourceData; size_t resourceSize; - debug(2, "Music::play %d", flags); - - if (!_enabled || isPlaying()) { - return; - } - - _player->stopMusic(); - - /* - if (!_vm->_musicVolume) { + if (_isPlaying) return; - } - */ - if (flags == MUSIC_DEFAULT) { - flags = MUSIC_NORMAL; - } + stop(); // Load MIDI/XMI resource data - _player->setGM(true); + _isGM = true; resourceSize = midiResource->getSize(); resourceData = new byte[resourceSize]; memcpy(resourceData, midiResource->getData(), resourceSize); - if (resourceSize < 4) { - error("Music::play() wrong music resource size"); - } + if (_xmidiParser->loadMusic(resourceData, resourceSize)) { + MidiParser *parser = _xmidiParser; + parser->setTrack(0); + parser->setMidiDriver(this); + parser->setTimerRate(getBaseTempo()); + parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); - if (xmidiParser->loadMusic(resourceData, resourceSize)) { - //_player->setGM(false); - parser = xmidiParser; - } + _parser = parser; - parser->setTrack(0); - parser->setMidiDriver(_player); - parser->setTimerRate(_player->getBaseTempo()); - parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); + setVolume(255); - _player->_parser = parser; - //setVolume(_vm->_musicVolume == 10 ? 255 : _vm->_musicVolume * 25); - setVolume(255); + _looping = flags & MUSIC_LOOP; + _isPlaying = true; + } +} - if (flags & MUSIC_LOOP) - _player->setLoop(true); - else - _player->setLoop(false); +void MusicPlayer::stop() { + Common::StackLock lock(_mutex); - _player->playMusic(); - if (_midiMusicData) - delete[] _midiMusicData; - _midiMusicData = resourceData; + _isPlaying = false; + if (_parser) { + _parser->unloadMusic(); + _parser = NULL; + } } -void Music::pause(void) { - _player->setVolume(-1); - _player->setPlaying(false); +void MusicPlayer::pause() { + setVolume(-1); + _isPlaying = false; } -void Music::resume(void) { - //_player->setVolume(_vm->_musicVolume == 10 ? 255 : _vm->_musicVolume * 25); +void MusicPlayer::resume() { setVolume(255); - _player->setPlaying(true); -} - -void Music::stop(void) { - _player->stopMusic(); + _isPlaying = true; } } // End of namespace Made diff --git a/engines/made/music.h b/engines/made/music.h index 7ca464bbc0..b9fa1004d5 100644 --- a/engines/made/music.h +++ b/engines/made/music.h @@ -28,12 +28,8 @@ #ifndef MADE_MUSIC_H #define MADE_MUSIC_H -#include "sound/audiocd.h" #include "sound/mididrv.h" #include "sound/midiparser.h" -#include "sound/mp3.h" -#include "sound/vorbis.h" -#include "sound/flac.h" #include "common/mutex.h" #include "made/resource.h" @@ -42,8 +38,7 @@ namespace Made { enum MusicFlags { MUSIC_NORMAL = 0, - MUSIC_LOOP = 0x0001, - MUSIC_DEFAULT = 0xffff + MUSIC_LOOP = 1 }; class MusicPlayer : public MidiDriver { @@ -59,8 +54,10 @@ public: void setNativeMT32(bool b) { _nativeMT32 = b; } bool hasNativeMT32() { return _nativeMT32; } - void playMusic(); - void stopMusic(); + void play(XmidiResource *midiResource, MusicFlags flags = MUSIC_NORMAL); + void stop(); + void pause(); + void resume(); void setLoop(bool loop) { _looping = loop; } void setPassThrough(bool b) { _passThrough = b; } @@ -89,6 +86,7 @@ protected: MidiChannel *_channel[16]; MidiDriver *_driver; + MidiParser *_xmidiParser; byte _channelVolume[16]; bool _nativeMT32; bool _isGM; @@ -96,51 +94,7 @@ protected: bool _isPlaying; bool _looping; - bool _randomLoop; byte _masterVolume; - - byte *_musicData; - uint16 *_buf; - size_t _musicDataSize; -}; - -class Music { -public: - - Music(MidiDriver *driver, int enabled); - ~Music(void); - void setNativeMT32(bool b) { _player->setNativeMT32(b); } - bool hasNativeMT32() { return _player->hasNativeMT32(); } - void setAdlib(bool b) { _adlib = b; } - bool hasAdlib() { return _adlib; } - void setPassThrough(bool b) { _player->setPassThrough(b); } - bool isPlaying(void); - - void play(XmidiResource *midiResource, MusicFlags flags = MUSIC_DEFAULT); - void pause(void); - void resume(void); - void stop(void); - - void setVolume(int volume); - int getVolume() { return _currentVolume; } - - int32 *_songTable; - int _songTableLen; - -private: - - MusicPlayer *_player; - uint32 _trackNumber; - - int _enabled; - bool _adlib; - - int _currentVolume; - - MidiParser *xmidiParser; - - byte *_midiMusicData; - }; } // End of namespace Made |