1/*
2
3SynthFile.h
4
5Copyright (c) 2002 Haiku.
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_H
31#define _SYNTH_FILE_H
32
33#include "SynthFileReader.h"
34#include <ObjectList.h>
35
36
37class SSound {
38	uint32  fOffset;
39	uint16  fId;
40	BString fName;
41	void*   fSamples;
42	int32   fFrameCount;
43	int16   fSampleSize;
44	int16   fChannelCount;
45
46	SSound() { }
47public:
48	SSound(uint16 id);
49
50	uint16 Id() const               { return fId; }
51
52	void        SetName(const char* name) { fName = name; }
53	const char* Name() const              { return fName.String(); }
54
55	void   SetSample(void* samples, int32 frameCount, int16 sampleSize, int16 channelCount);
56	void*  Samples() const          { return fSamples; }
57	int32  FrameCount() const       { return fFrameCount; }
58	int16  SampleSize() const       { return fSampleSize; }
59	int16  ChannelCount() const     { return fChannelCount; }
60
61	bool   HasSamples() const       { return fSamples != NULL; }
62
63	void   SetOffset(uint32 offset) { fOffset = offset; }
64	uint32 Offset() const           { return fOffset; }
65};
66
67
68class SSoundInRange {
69	uint8   fNoteStart;
70	uint8   fNoteEnd;
71	SSound* fSound;
72
73	SSoundInRange() { }
74public:
75	SSoundInRange(uint8 start, uint8 end, SSound* sound);
76
77	uint8  Start() const    { return fNoteStart; }
78	uint8  End() const      { return fNoteEnd; }
79	SSound* Sound() const   { return fSound; }
80};
81
82
83class SInstrument {
84	uint32               fOffset;
85	uint8                fId;
86	BString              fName;
87	SSound*              fDefaultSound;
88	BObjectList<SSoundInRange> fSounds;
89
90public:
91	SInstrument(uint8 instrument);
92
93	void SetOffset(uint32 offset)              { fOffset = offset; }
94	uint32 Offset() const                      { return fOffset; }
95
96	uint8 Id() const                           { return fId; }
97
98	void SetName(const char* name)             { fName = name; }
99	const char* Name() const                   { return fName.String(); }
100
101	void SetDefaultSound(SSound* sound)        { fDefaultSound = sound; }
102	SSound*               DefaultSound() const { return fDefaultSound; }
103
104	BObjectList<SSoundInRange>* Sounds()       { return &fSounds; }
105};
106
107
108class SSynthFile;
109
110class SSynthFile {
111	BObjectList<SInstrument> fInstruments;
112	BObjectList<SSound>      fSounds;
113	SSynthFileReader   fReader;
114	status_t           fStatus;
115
116	void InstrumentAtPut(int i, SInstrument* instr);
117	SSound* FindSound(uint16 sound);
118
119public:
120	SSynthFile(const char* fileName);
121	status_t InitCheck() const { return fReader.InitCheck(); }
122
123
124	SSound*      GetSound(uint16 sound);
125	bool         HasInstrument(uint8 instrument) const;
126	SInstrument* GetInstrument(uint8 instrument);
127
128	void Dump();
129};
130
131#endif
132