1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GOB_SOUND_MUSPLAYER_H
24 #define GOB_SOUND_MUSPLAYER_H
25 
26 #include "common/str.h"
27 #include "common/array.h"
28 
29 #include "gob/sound/adlib.h"
30 
31 namespace Common {
32 	class SeekableReadStream;
33 }
34 
35 namespace Gob {
36 
37 /** A player for the AdLib MUS format, with the instrument information in SND files.
38  *
39  *  In the Gob engine, those files are usually named .MDY and .TBR instead.
40  */
41 class MUSPlayer : public AdLib {
42 public:
43 	MUSPlayer();
44 	~MUSPlayer();
45 
46 	/** Load the instruments (.SND or .TBR) */
47 	bool loadSND(Common::SeekableReadStream &snd);
48 	/** Load the melody (.MUS or .MDY) */
49 	bool loadMUS(Common::SeekableReadStream &mus);
50 
51 	void unload();
52 
53 	uint32 getSongID() const;
54 	const Common::String &getSongName() const;
55 
56 protected:
57 	// AdLib interface
58 	uint32 pollMusic(bool first);
59 	void rewind();
60 
61 private:
62 	struct Timbre {
63 		Common::String name;
64 
65 		uint16 params[kOperatorsPerVoice * kParamCount];
66 	};
67 
68 	Common::Array<Timbre> _timbres;
69 
70 	byte  *_songData;
71 	uint32 _songDataSize;
72 
73 	const byte *_playPos;
74 
75 	uint32 _songID;
76 	Common::String _songName;
77 
78 	uint8 _ticksPerBeat;
79 	uint8 _beatsPerMeasure;
80 
81 	uint8 _soundMode;
82 	uint8 _pitchBendRange;
83 
84 	uint16 _baseTempo;
85 
86 	uint16 _tempo;
87 
88 	byte _lastCommand;
89 
90 
91 	void unloadSND();
92 	void unloadMUS();
93 
94 	bool readSNDHeader (Common::SeekableReadStream &snd, int &timbreCount, int &timbrePos);
95 	bool readSNDTimbres(Common::SeekableReadStream &snd, int  timbreCount, int  timbrePos);
96 
97 	bool readMUSHeader(Common::SeekableReadStream &mus);
98 	bool readMUSSong  (Common::SeekableReadStream &mus);
99 
100 	void setInstrument(uint8 voice, uint8 instrument);
101 	void skipToTiming();
102 
103 	static bool readString(Common::SeekableReadStream &stream, Common::String &string, byte *buffer, uint size);
104 };
105 
106 } // End of namespace Gob
107 
108 #endif // GOB_SOUND_MUSPLAYER_H
109