xref: /haiku/src/tests/kits/midi/synth_file_reader/SynthFileReader.h (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2 
3 SynthFileReader.h
4 
5 Copyright (c) 2002 Haiku.
6 
7 Author:
8 	Michael Pfeiffer
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy of
11 this software and associated documentation files (the "Software"), to deal in
12 the Software without restriction, including without limitation the rights to
13 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14 of the Software, and to permit persons to whom the Software is furnished to do
15 so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in all
18 copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE 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 
37 class SSynthFile;
38 
39 class SSynthFileReader {
40 private:
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 
68 public:
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