diff options
author | Joost Peters | 2003-12-28 03:31:05 +0000 |
---|---|---|
committer | Joost Peters | 2003-12-28 03:31:05 +0000 |
commit | dbe01121eb387ee6696e196a3187d3f7675adfb0 (patch) | |
tree | 2ccfe47aeee4cafb06d24d41dcb703c535e12e70 /queen/music.cpp | |
parent | e8cddcbda0fafb09806814568b7e68aa3f6c13a6 (diff) | |
download | scummvm-rg350-dbe01121eb387ee6696e196a3187d3f7675adfb0.tar.gz scummvm-rg350-dbe01121eb387ee6696e196a3187d3f7675adfb0.tar.bz2 scummvm-rg350-dbe01121eb387ee6696e196a3187d3f7675adfb0.zip |
Improved music code a bit. still has 'hanging notes' when stopping music, though.
svn-id: r11988
Diffstat (limited to 'queen/music.cpp')
-rw-r--r-- | queen/music.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/queen/music.cpp b/queen/music.cpp index 6c383d15d6..94b6857947 100644 --- a/queen/music.cpp +++ b/queen/music.cpp @@ -29,26 +29,23 @@ namespace Queen { - Music::Music(MidiDriver *driver, QueenEngine *vm) : _loop(false), _driver(driver) { + Music::Music(MidiDriver *driver, QueenEngine *vm) : _isPlaying(false), _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); - + _driver->setTimerCallback(this, myTimerProc); + _musicData = vm->resource()->loadFile("AQ.RL", 0, NULL); _musicDataSize = vm->resource()->fileSize("AQ.RL"); _numSongs = READ_LE_UINT16(_musicData); } Music::~Music() { - stopSong(); + _driver->setTimerCallback(NULL, NULL); _midi->unloadMusic(); - // Send All Notes Off - for (int i = 0; i < 16; ++i) - _driver->send((123 << 8) | 0xB0 | i); _driver->close(); delete _midi; delete[] _musicData; @@ -60,13 +57,19 @@ namespace Queen { else _midi->property(MidiParser::mpAutoLoop, 0); + _isPlaying = true; _midi->loadMusic(_musicData + songOffset(songNum), songLength(songNum)); _midi->setTrack(0); - _driver->setTimerCallback((void *)_midi, _midi->timerCallback); } void Music::stopSong() { - _driver->setTimerCallback(NULL, NULL); + _isPlaying = false; + } + + void Music::myTimerProc(void *refCon) { + Music *music = (Music *)refCon; + if (music->_isPlaying) + music->_midi->onTimer(); } uint32 Music::songOffset(uint16 songNum) { |