aboutsummaryrefslogtreecommitdiff
path: root/queen
diff options
context:
space:
mode:
authorJoost Peters2003-12-28 03:31:05 +0000
committerJoost Peters2003-12-28 03:31:05 +0000
commitdbe01121eb387ee6696e196a3187d3f7675adfb0 (patch)
tree2ccfe47aeee4cafb06d24d41dcb703c535e12e70 /queen
parente8cddcbda0fafb09806814568b7e68aa3f6c13a6 (diff)
downloadscummvm-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')
-rw-r--r--queen/music.cpp21
-rw-r--r--queen/music.h4
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);
};