diff options
author | Paul Gilbert | 2017-02-03 22:40:15 -0500 |
---|---|---|
committer | Paul Gilbert | 2017-02-03 22:40:15 -0500 |
commit | 529680e6f87a6d541635e9761b6ad234dea7094a (patch) | |
tree | cd48d0f57dc09f988be96c1f2463df3c80fdf5d1 | |
parent | 9e0959265e81775cb228c179febf29302b70067c (diff) | |
download | scummvm-rg350-529680e6f87a6d541635e9761b6ad234dea7094a.tar.gz scummvm-rg350-529680e6f87a6d541635e9761b6ad234dea7094a.tar.bz2 scummvm-rg350-529680e6f87a6d541635e9761b6ad234dea7094a.zip |
TITANIC: Beginnings of music object and parser classes
-rw-r--r-- | engines/titanic/module.mk | 1 | ||||
-rw-r--r-- | engines/titanic/sound/music_object.cpp | 175 | ||||
-rw-r--r-- | engines/titanic/sound/music_object.h | 65 | ||||
-rw-r--r-- | engines/titanic/sound/music_room_handler.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/sound/music_room_handler.h | 9 |
5 files changed, 245 insertions, 9 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index d805f11fb8..08a65a23b5 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -409,6 +409,7 @@ MODULE_OBJS := \ sound/dome_from_top_of_well.o \ sound/enter_view_toggles_other_music.o \ sound/gondolier_song.o \ + sound/music_object.o \ sound/music_room.o \ sound/music_room_handler.o \ sound/music_player.o \ diff --git a/engines/titanic/sound/music_object.cpp b/engines/titanic/sound/music_object.cpp new file mode 100644 index 0000000000..06915cbfdb --- /dev/null +++ b/engines/titanic/sound/music_object.cpp @@ -0,0 +1,175 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "titanic/sound/music_object.h" +#include "common/util.h" + +namespace Titanic { + +static const char *const DATA[4] = { + "64,^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|8,^^^^ 5:A///|64,/|/|/|/|/|/|/" + "|/|/|/|/|/|/|/|/|/|^|^|^|^|^|^|^|^|^|16, ^B//|64,/|/|/|/|^|16,^C/" + "/|64,/|/|/|/|", + "2:8,^^^^B//a|//g//B//|g///B//a|//g//A//|B//^C//b|//a//a//|BCb/b//" + "a|//g//A//|g/+f/D//c|//b//gA/|g/^^C//C|//C//a//|BCb////a|//g//g//" + "|g/g//B/a|/g//////|//^^B//a|//g//B//|g///B//a|//g//B//|g//^C//b|/" + "/a//a//|BCb/b//a|//g//B//|g/+f/D//c|//b//gA/|g/^^C//C|//C//a//|BC" + "b////a|//g//g//|g/g//B/a|/g//////|3:^^B//a//|g//A//g/|/^B//a//|g/" + "/A//B/|b^ 3:C//b//|a//g//+f/|+fG/G/GA/|B/a/g///|B///+f//G|G/G/+f/" + "G/|^^e//d//|c//b//gA|g/B//a//|g//g//g/|g//B/a/g|//////^^|^^Ga///G" + "|////////|////////|////////|", + "2:8,^^^^^^D/|/E//E//E|/d//^^d/|/E//E//E|/E//^^G/|/d//d//d|/^^^^^d" + "/|/E//E//E|/d/^^^E/|/E//d/+F/|bD^^^^G/|/e//e//e|^^^^^^d/|/E//E//E" + "|//d///d/|//b/////|^^^^^^D/|/E//E//E|/d//^^d/|/E//E//E|/E//^^G/|/" + "d//d//d|/^^^^^d/|/E//E//E|/d/^^^E/|/E//d/d/|d/^^^^G/|/e//e//e|^^^" + "^^^d/|/E//E//E|//d///d/|//b/////|3:D///c//b|//b//b//|D///c//b|//b" + "//g//|E///d//c|//b//a//|aB/B/BC/|D/c/b///|^^^D//DE|/E/E/d/d|//E/g" + "//g|//g//d//|^^^^g//E|//E//E//|d///d///|b///////|// 3:Db///C|///b" + "/// 5:A|64,/|/|/|/|/|/|/|/|", + "2:8,^^G//+f//|e//e//e/|//G//+f//|e//e//+F/|G/a//g//|+f//+f//+f/|/" + "/G//+F//|e//e//e/|//B//a//|g//e///d|//c//b//|a//a//a/|+f/G// 2:+F" + "//|e//e//C/|//b/g/+f/|//G/////|^^G//+f//|e//e//e/|//G//+f//|e//e/" + "/e/|//a//g//|+f//+f//+f/|//G//+F//|e//e//e/|//B//a//|g//e///d|/ " + "2:dC//b//|a//a//a/|+f/G//+F//|e//e//C/|//b/g/+f/|//G/////|d//d//d" + "/|/E//E//d|d//d//E/|/+F//G//b|a//a//a/|/D//D// 3:D|//g/g//D|/d/G/" + "///|^^b//b//|b//ba/B/|c//B//a/|/g//+f//+f|G//+F//e/|/c//C///|b/g/" + "+f///|G///////|G///////|C///////|////////|////////|" +}; + +/*------------------------------------------------------------------------*/ + +CMusicObject::CMusicObject(int index) : _data(nullptr), _field4(0) { + +} + +CMusicObject::~CMusicObject() { + delete[] _data; +} + +/*------------------------------------------------------------------------*/ + +#define FETCH_CHAR _currentChar = _str[_strIndex++] + +CMusicParser::CMusicParser(const char *str) : _str(str), _strIndex(0), + _field8(0), _priorChar('A'), _field10(32), _field14(0), _flag(false), + _field1C(0), _currentChar(' '), _numValue(1) { +} + +bool CMusicParser::step(Result &r) { + const int INDEXES[8] = { 0, 2, 3, 5, 7, 8, 10, 0 }; + + while (_currentChar) { + skipSpaces(); + + if (Common::isDigit(_currentChar)) { + // Parse the number + Common::String numStr; + do { + numStr += _currentChar; + FETCH_CHAR; + } while (_currentChar && Common::isDigit(_currentChar)); + + _numValue = atoi(numStr.c_str()); + } else if (_currentChar == ',') { + _field10 = _numValue; + FETCH_CHAR; + } else if (_currentChar == ':') { + _priorChar = 'A'; + _field8 = _numValue * 12; + FETCH_CHAR; + } else if (_currentChar == '//') { + r._field4 += _field10; + _field1C += _field10; + FETCH_CHAR; + } else if (_currentChar == '+') { + ++_field14; + FETCH_CHAR; + } else if (_currentChar == '-') { + --_field14; + FETCH_CHAR; + } else if (_currentChar == '^') { + if (_flag) + break; + + r._field0 = 0x7FFFFFFF; + r._field4 = _field10; + _field14 = 0; + _field1C += _field10; + _field10 = 1; + FETCH_CHAR; + } else if (_currentChar == '|') { + _field1C = 0; + FETCH_CHAR; + } else if (Common::isAlpha(_currentChar)) { + if (_flag) + break; + + int val1 = INDEXES[tolower(_currentChar) - 'a']; + int val2 = INDEXES[tolower(_priorChar) - 'a']; + bool flag = true; + + if (_currentChar == _priorChar) { + r._field0 = _field8; + } else if (_currentChar >= 'a' && _currentChar <= 'g') { + val1 -= val2; + if (val1 < 0) + val1 = 12; + r._field0 = _field8 + val1; + } else if (_currentChar >= 'A' && _currentChar <= 'G') { + val1 -= val2; + if (val1 <= 0) + val1 = 12; + r._field0 = _field8 + val1; + } else { + flag = false; + } + + if (flag) { + r._field4 = _field10; + _field1C += _field10; + _field8 = r._field0; + _priorChar = _currentChar; + r._field0 += _field14; + _field14 = 0; + _flag = true; + } + + FETCH_CHAR; + } else { + FETCH_CHAR; + } + } + + if (!_flag) + return false; + + _flag = false; + return true; +} + +void CMusicParser::skipSpaces() { + while (_currentChar && Common::isSpace(_currentChar)) { + FETCH_CHAR; + } +} + +} // End of namespace Titanic diff --git a/engines/titanic/sound/music_object.h b/engines/titanic/sound/music_object.h new file mode 100644 index 0000000000..5687951a17 --- /dev/null +++ b/engines/titanic/sound/music_object.h @@ -0,0 +1,65 @@ +/* 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. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef TITANIC_MUSIC_OBJECT_H +#define TITANIC_MUSIC_OBJECT_H + +#include "common/scummsys.h" + +namespace Titanic { + +class CMusicObject { +public: + double *_data; + int _field4; +public: + CMusicObject(int index); + ~CMusicObject(); +}; + +class CMusicParser { + struct Result { + int _field0; + int _field4; + }; +private: + const char *_str; + uint _strIndex; + int _field8; + char _priorChar; + int _field10; + int _field14; + bool _flag; + int _field1C; + char _currentChar; + int _numValue; +private: + void skipSpaces(); +public: + CMusicParser(const char *str); + + bool step(Result &r); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_MUSIC_OBJECT_H */ diff --git a/engines/titanic/sound/music_room_handler.cpp b/engines/titanic/sound/music_room_handler.cpp index 4a76def5f4..2a6a438aa8 100644 --- a/engines/titanic/sound/music_room_handler.cpp +++ b/engines/titanic/sound/music_room_handler.cpp @@ -35,7 +35,7 @@ CMusicRoomHandler::CMusicRoomHandler(CProjectItem *project, CSoundManager *sound _startTicks = _soundStartTicks = 0; Common::fill(&_musicWaves[0], &_musicWaves[4], (CMusicWave *)nullptr); for (int idx = 0; idx < 4; ++idx) - _array3[idx] = new Object3(); + _array3[idx] = new CMusicObject(idx); Common::fill(&_array4[0], &_array4[4], 0); Common::fill(&_array5[0], &_array5[4], 0.0); Common::fill(&_array6[0], &_array6[4], 0); @@ -251,7 +251,7 @@ void CMusicRoomHandler::fn1() { if (val >= musicWave->_floatVal) { _array5[idx] += fn3(idx, _array6[idx]); - // TODO + //_array3[idx]->_data[_array6[idx]]; } } } diff --git a/engines/titanic/sound/music_room_handler.h b/engines/titanic/sound/music_room_handler.h index ed8c7f59db..52495bc7d7 100644 --- a/engines/titanic/sound/music_room_handler.h +++ b/engines/titanic/sound/music_room_handler.h @@ -24,6 +24,7 @@ #define TITANIC_MUSIC_ROOM_HANDLER_H #include "titanic/sound/audio_buffer.h" +#include "titanic/sound/music_object.h" #include "titanic/sound/music_wave.h" #include "titanic/sound/wave_file.h" @@ -45,19 +46,13 @@ struct MusicRoomInstrument { }; class CMusicRoomHandler { - struct Object3 { - byte *_field0; - int _field4; - Object3() : _field0(nullptr), _field4(0) {} - ~Object3() { delete[] _field0; } - }; private: CProjectItem *_project; CSoundManager *_soundManager; CMusicWave *_musicWaves[4]; MusicRoomInstrument _array1[4]; MusicRoomInstrument _array2[4]; - Object3 *_array3[4]; + CMusicObject *_array3[4]; int _array4[4]; double _array5[4]; int _array6[4]; |