1/*
2
3SynthFileReader.h
4
5Copyright (c) 2002 OpenBeOS.
6
7Author:
8	Michael Pfeiffer
9
10Permission is hereby granted, free of charge, to any person obtaining a copy of
11this software and associated documentation files (the "Software"), to deal in
12the Software without restriction, including without limitation the rights to
13use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14of the Software, and to permit persons to whom the Software is furnished to do
15so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE SOFTWARE.
27
28*/
29
30#ifndef _SYNTH_FILE_READER_H
31#define _SYNTH_FILE_READER_H
32
33#include <stdio.h>
34#include <SupportDefs.h>
35#include <String.h>
36
37class SSynthFile;
38
39class SSynthFileReader {
40private:
41	FILE*   fFile;
42
43	typedef char tag[4];
44
45	bool TagEquals(const char* tag1, const char* tag2) const;
46	bool Read(void* data, uint32 size);
47	bool Read(BString& s, uint32 size);
48	bool Read(tag &tag);
49	bool Read(uint64 &n, uint32 size);
50	bool Read(uint32 &n);
51	bool Read(uint16 &n);
52	bool Read(uint8  &n);
53	bool Skip(uint32 bytes);
54	uint32 Tell()            { return ftell(fFile); }
55	void   Seek(uint32 pos)  { fseek(fFile, pos, SEEK_SET); }
56
57	bool ReadHeader(uint32& version, uint32& chunks, uint32& nextChunk);
58	bool NextChunk(tag& tag, uint32& nextChunk);
59	bool ReadInstHeader(uint16& inst, uint16& snd, uint16& snds, BString& name, uint32& size);
60	bool ReadSoundInRange(uint8& start, uint8& end, uint16& snd, uint32& size);
61	bool ReadSoundHeader(uint16& inst, BString& name, uint32& size);
62
63	// debugging support
64	void Print(tag tag);
65	void Dump(uint32 bytes);
66	void Play(uint16 rate, uint32 offset, uint32 size);
67
68public:
69	SSynthFileReader(const char* synthFile);
70	~SSynthFileReader();
71	status_t InitCheck() const;
72
73	status_t Initialize(SSynthFile* synth);
74
75	void Dump(bool play, uint32 instrOnly);
76};
77
78#endif
79