aboutsummaryrefslogtreecommitdiff
path: root/queen/music.cpp
diff options
context:
space:
mode:
authorJoost Peters2003-12-14 00:33:21 +0000
committerJoost Peters2003-12-14 00:33:21 +0000
commit1de28a2931b9f48f7af12595d4e04554d25de578 (patch)
tree3350e7d718f975e02572530fc495d0c608a3c299 /queen/music.cpp
parent80aac33327181ae281ea0d85bfec326583f3b55a (diff)
downloadscummvm-rg350-1de28a2931b9f48f7af12595d4e04554d25de578.tar.gz
scummvm-rg350-1de28a2931b9f48f7af12595d4e04554d25de578.tar.bz2
scummvm-rg350-1de28a2931b9f48f7af12595d4e04554d25de578.zip
Initial (Roland) Music support; a lot of stuff is still missing and/or incomplete.
svn-id: r11621
Diffstat (limited to 'queen/music.cpp')
-rw-r--r--queen/music.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/queen/music.cpp b/queen/music.cpp
new file mode 100644
index 0000000000..592b196c0b
--- /dev/null
+++ b/queen/music.cpp
@@ -0,0 +1,80 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2003 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#include "stdafx.h"
+#include "queen/music.h"
+#include "queen/queen.h"
+#include "queen/resource.h"
+
+#include "sound/mididrv.h"
+#include "sound/midiparser.h"
+
+namespace Queen {
+
+ Music::Music(MidiDriver *driver, QueenEngine *vm) : _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);
+
+ _musicData = vm->resource()->loadFile("AQ.RL", 0, NULL);
+ _musicDataSize = vm->resource()->fileSize("AQ.RL");
+ _numSongs = READ_LE_UINT16(_musicData);
+ }
+
+ Music::~Music() {
+ stopSong();
+ _midi->unloadMusic();
+ delete _midi;
+ delete[] _musicData;
+ }
+
+ void Music::playSong(uint16 songNum) {
+ if (_loop)
+ _midi->property(MidiParser::mpAutoLoop, 1);
+ else
+ _midi->property(MidiParser::mpAutoLoop, 0);
+
+ _midi->loadMusic(_musicData + songOffset(songNum), songLength(songNum));
+ _midi->setTrack(0);
+ _driver->setTimerCallback((void *)_midi, _midi->timerCallback);
+ }
+
+ void Music::stopSong() {
+ _driver->setTimerCallback(NULL, NULL);
+ }
+
+ uint32 Music::songOffset(uint16 songNum) {
+ uint16 offsLo = READ_LE_UINT16(_musicData + (songNum * 4) + 2);
+ uint16 offsHi = READ_LE_UINT16(_musicData + (songNum * 4) + 4);
+ return (offsHi << 4) | offsLo;
+ }
+
+ uint32 Music::songLength(uint16 songNum) {
+ if (songNum < _numSongs)
+ return (songOffset(songNum + 1) - songOffset(songNum));
+ return (_musicDataSize - songOffset(songNum));
+ }
+
+} // End of namespace Queen