diff options
Diffstat (limited to 'queen')
-rw-r--r-- | queen/music.cpp | 21 | ||||
-rw-r--r-- | queen/music.h | 4 |
2 files changed, 15 insertions, 10 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) { diff --git a/queen/music.h b/queen/music.h index 57e85820bf..2e98b54d11 100644 --- a/queen/music.h +++ b/queen/music.h @@ -40,13 +40,15 @@ public: void loop(bool val) { _loop = val; } protected: + bool _isPlaying; bool _loop; byte *_musicData; uint16 _numSongs; uint32 _musicDataSize; MidiDriver *_driver; MidiParser *_midi; - + + static void myTimerProc(void *refCon); uint32 songOffset(uint16 songNum); uint32 songLength(uint16 songNum); }; |