2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2003-05-25 03:19:21 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2003-05-25 03:19:21 +00:00
|
|
|
*
|
2006-02-11 12:46:41 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2003-05-25 03:19:21 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-01-30 05:25:17 +00:00
|
|
|
#include "common/debug.h"
|
2003-05-25 03:19:21 +00:00
|
|
|
#include "common/util.h"
|
|
|
|
|
2006-04-29 14:23:16 +00:00
|
|
|
#include "sound/mididrv.h"
|
|
|
|
#include "sound/midiparser.h"
|
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
namespace AGOS {
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2003-10-03 23:34:06 +00:00
|
|
|
/**
|
|
|
|
* Simon 1 Demo version of MidiParser.
|
|
|
|
*
|
|
|
|
* This parser is the result of eyeballing the one MUS file that's included
|
|
|
|
* with simon1demo. So there might be some things missing. I've tried to notate
|
|
|
|
* question-mark areas where they occur.
|
|
|
|
*/
|
2003-05-25 03:19:21 +00:00
|
|
|
class MidiParser_S1D : public MidiParser {
|
|
|
|
protected:
|
|
|
|
byte *_data;
|
|
|
|
bool _no_delta;
|
|
|
|
|
|
|
|
protected:
|
2006-10-21 12:22:30 +00:00
|
|
|
void parseNextEvent(EventInfo &info);
|
2003-05-25 03:19:21 +00:00
|
|
|
void resetTracking();
|
2003-09-24 06:33:59 +00:00
|
|
|
uint32 readVLQ2(byte * &data);
|
2003-05-25 03:19:21 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
MidiParser_S1D() : _data(0), _no_delta(false) {}
|
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
bool loadMusic(byte *data, uint32 size);
|
2003-05-25 03:19:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// The VLQs for simon1demo seem to be
|
|
|
|
// in Little Endian format.
|
2003-09-24 06:33:59 +00:00
|
|
|
uint32 MidiParser_S1D::readVLQ2(byte * &data) {
|
2003-05-25 03:19:21 +00:00
|
|
|
byte str;
|
|
|
|
uint32 value = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; ++i) {
|
|
|
|
str = data[0];
|
|
|
|
++data;
|
|
|
|
value |= (str & 0x7F) << (i * 7);
|
|
|
|
if (!(str & 0x80))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
void MidiParser_S1D::parseNextEvent(EventInfo &info) {
|
2003-05-25 03:19:21 +00:00
|
|
|
info.start = _position._play_pos;
|
2003-09-24 06:33:59 +00:00
|
|
|
info.delta = _no_delta ? 0 : readVLQ2(_position._play_pos);
|
2003-05-25 03:19:21 +00:00
|
|
|
|
|
|
|
_no_delta = false;
|
|
|
|
info.event = *(_position._play_pos++);
|
|
|
|
if (info.command() < 0x8) {
|
|
|
|
_no_delta = true;
|
|
|
|
info.event += 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info.command()) {
|
|
|
|
case 0x8:
|
|
|
|
info.basic.param1 = *(_position._play_pos++);
|
|
|
|
info.basic.param2 = 0;
|
|
|
|
info.length = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x9:
|
|
|
|
info.basic.param1 = *(_position._play_pos++);
|
|
|
|
info.basic.param2 = *(_position._play_pos++); // I'm ASSUMING this byte is velocity!
|
|
|
|
info.length = 0;
|
|
|
|
break;
|
|
|
|
|
2006-10-21 12:22:30 +00:00
|
|
|
case 0xA:
|
|
|
|
case 0xB:
|
|
|
|
// I'm not sure what these are meant to do, or what the
|
|
|
|
// parameter is. Elvira 1 needs them, though, and who am I to
|
|
|
|
// argue with her?
|
|
|
|
info.basic.param1 = *(_position._play_pos++);
|
|
|
|
info.basic.param2 = 0;
|
|
|
|
break;
|
|
|
|
|
2003-05-25 03:19:21 +00:00
|
|
|
case 0xC:
|
|
|
|
info.basic.param1 = *(_position._play_pos++);
|
|
|
|
info.basic.param2 = 0;
|
|
|
|
++_position._play_pos; // I have NO IDEA what the second byte is for.
|
|
|
|
break;
|
|
|
|
|
2008-03-23 00:34:39 +00:00
|
|
|
case 0xD:
|
|
|
|
// Triggered by MOD0/MOD1/MOD2/MOD3/MOD4/MOD6/MOD7/MOD8/MOD9 in Elvira 2
|
|
|
|
// Triggered by MOD0/MOD2/MOD3/MOD5/MOD6/MOD7/MOD8/MOD9/MOD10/MOD12/MOD14/MOD15/MOD20 in Waxworks
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xE:
|
|
|
|
// Triggered by MOD9 in Elvira 1
|
|
|
|
// Triggered by MOD3/MOD5 in Elvira 2
|
|
|
|
// Triggered by MOD3/MOD7/MOD8/MOD13 in Waxworks
|
|
|
|
break;
|
|
|
|
|
2003-05-25 03:19:21 +00:00
|
|
|
case 0xF:
|
2006-10-21 12:59:23 +00:00
|
|
|
switch (info.event & 0x0F) {
|
2008-03-23 00:34:39 +00:00
|
|
|
case 0x0:
|
|
|
|
// Trigged by MOD2/MOD6/MOD15 in Waxworks
|
2009-07-19 09:09:56 +00:00
|
|
|
// Pure guesswork
|
|
|
|
info.ext.type = *(_position._play_pos++);
|
|
|
|
info.length = readVLQ(_position._play_pos);
|
|
|
|
info.ext.data = _position._play_pos;
|
2006-10-21 12:59:23 +00:00
|
|
|
break;
|
|
|
|
|
2008-03-23 00:34:39 +00:00
|
|
|
case 0x3: // Not sure, Song Select?
|
|
|
|
// Trigged by MOD1/MOD7/MOD10 in Elvira 1
|
2006-10-21 12:59:23 +00:00
|
|
|
info.basic.param1 = *(_position._play_pos++);
|
|
|
|
info.basic.param2 = 0;
|
|
|
|
break;
|
|
|
|
|
2008-03-23 00:34:39 +00:00
|
|
|
case 0x4:
|
|
|
|
// Trigged by MOD8 in Elvira 1
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x7:
|
|
|
|
// Trigged by MOD6 in Elvira 2
|
|
|
|
// Trigged by MOD5 in Waxworks
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x8: // Not sure, ?
|
|
|
|
// Trigged by MOD19 in Waxworks
|
2006-10-21 12:59:23 +00:00
|
|
|
info.basic.param1 = info.basic.param2 = 0;
|
|
|
|
break;
|
|
|
|
|
2008-03-23 00:34:39 +00:00
|
|
|
case 0xA:
|
|
|
|
// Trigged by MOD5 in Elvira 2
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xC:
|
|
|
|
// This means End of Track.
|
|
|
|
// Rewrite in SMF (MIDI transmission) form.
|
|
|
|
info.event = 0xFF;
|
|
|
|
info.ext.type = 0x2F;
|
|
|
|
info.length = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0xF: // Not sure, META event?
|
|
|
|
// Trigged by MOD8/MOD9/MOD11/MOD12/MOD13 in Waxworks
|
2006-10-21 12:59:23 +00:00
|
|
|
info.ext.type = *(_position._play_pos++);
|
|
|
|
info.length = readVLQ(_position._play_pos);
|
|
|
|
info.ext.data = _position._play_pos;
|
|
|
|
_position._play_pos += info.length;
|
|
|
|
break;
|
2008-03-23 00:34:39 +00:00
|
|
|
|
2006-10-21 12:59:23 +00:00
|
|
|
default:
|
2008-03-23 00:34:39 +00:00
|
|
|
error("MidiParser_S1D: Unexpected type 0x%02X found", (int) info.event);
|
2006-10-21 12:59:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2003-05-25 03:19:21 +00:00
|
|
|
default:
|
2008-03-23 00:34:39 +00:00
|
|
|
error("MidiParser_S1D: Unexpected event 0x%02X found", (int) info.command());
|
2006-09-19 11:59:13 +00:00
|
|
|
break;
|
2003-05-25 03:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-24 06:33:59 +00:00
|
|
|
bool MidiParser_S1D::loadMusic(byte *data, uint32 size) {
|
2003-05-25 03:19:21 +00:00
|
|
|
unloadMusic();
|
|
|
|
|
|
|
|
byte *pos = data;
|
2006-08-27 05:02:48 +00:00
|
|
|
if (*(pos++) != 0xFC)
|
2006-10-03 00:31:24 +00:00
|
|
|
debug(1, "Expected 0xFC header but found 0x%02X instead", (int) *pos);
|
2003-05-25 03:19:21 +00:00
|
|
|
|
|
|
|
// The next 3 bytes MIGHT be tempo, but we skip them and use the default.
|
|
|
|
// setTempo (*(pos++) | (*(pos++) << 8) | (*(pos++) << 16));
|
|
|
|
pos += 3;
|
|
|
|
|
|
|
|
// And now we're at the actual data. Only one track.
|
|
|
|
_num_tracks = 1;
|
|
|
|
_data = pos;
|
|
|
|
_tracks[0] = pos;
|
|
|
|
|
|
|
|
// Note that we assume the original data passed in
|
|
|
|
// will persist beyond this call, i.e. we do NOT
|
|
|
|
// copy the data to our own buffer. Take warning....
|
|
|
|
resetTracking();
|
2005-04-19 06:25:35 +00:00
|
|
|
setTempo(666667);
|
2003-09-24 06:33:59 +00:00
|
|
|
setTrack(0);
|
2003-05-25 03:19:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MidiParser_S1D::resetTracking() {
|
|
|
|
MidiParser::resetTracking();
|
|
|
|
_no_delta = false;
|
|
|
|
}
|
|
|
|
|
2003-05-25 03:35:20 +00:00
|
|
|
MidiParser *MidiParser_createS1D() { return new MidiParser_S1D; }
|
2003-10-03 19:42:27 +00:00
|
|
|
|
2006-09-29 09:44:30 +00:00
|
|
|
} // End of namespace AGOS
|