ScummVM API documentation
vgmitem.h
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 modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (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, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 /*
22  * VGMTrans (c) 2002-2019
23  * Licensed under the zlib license,
24  * refer to the included VGMTrans_LICENSE.txt file
25  */
26 #ifndef AUDIO_SOUNDFONT_VGMITEM_H
27 #define AUDIO_SOUNDFONT_VGMITEM_H
28 
29 #include "common/scummsys.h"
30 #include "common/str.h"
31 #include "common/array.h"
32 #include "rawfile.h"
33 #include "synthfile.h"
34 
35 class RawFile;
36 
37 //template <class T>
38 class VGMFile;
39 class VGMItem;
40 class VGMHeader;
41 
42 class VGMItem {
43 public:
44  VGMItem();
45  VGMItem(VGMFile *thevgmfile, uint32 theOffset, uint32 theLength = 0,
46  const Common::String theName = "");
47  virtual ~VGMItem(void);
48 
49 public:
50  RawFile *GetRawFile();
51 
52 protected:
53  // TODO make inline
54  uint32 GetBytes(uint32 nIndex, uint32 nCount, void *pBuffer);
55  uint8 GetByte(uint32 offset);
56  uint16 GetShort(uint32 offset);
57 
58 public:
59  VGMFile *_vgmfile;
60  Common::String _name;
61  uint32 _dwOffset; // offset in the pDoc data buffer
62  uint32 _unLength; // num of bytes the event engulfs
63 };
64 
65 class VGMContainerItem : public VGMItem {
66 public:
68  VGMContainerItem(VGMFile *thevgmfile, uint32 theOffset, uint32 theLength = 0,
69  const Common::String theName = "");
70  virtual ~VGMContainerItem(void);
71 
72  VGMHeader *AddHeader(uint32 offset, uint32 length, const Common::String &name = "Header");
73 
74  void AddSimpleItem(uint32 offset, uint32 length, const Common::String &theName);
75 
76  template<class T>
77  void AddContainer(Common::Array<T *> &container) {
78  _containers.push_back(reinterpret_cast<Common::Array<VGMItem *> *>(&container));
79  }
80 
81 public:
84  Common::Array<VGMItem *> _localitems;
85 };
86 
87 class VGMColl;
88 
89 class VGMFile : public VGMContainerItem {
90 public:
91 
92 public:
93  VGMFile(RawFile *theRawFile, uint32 offset, uint32 length = 0,
94  Common::String theName = "VGM File");
95  virtual ~VGMFile();
96 
97  bool LoadVGMFile();
98  virtual bool Load() = 0;
99 
100  RawFile *GetRawFile();
101 
102  size_t size() const { return _unLength; }
103  Common::String name() const { return _name; }
104 
105  uint32 GetBytes(uint32 nIndex, uint32 nCount, void *pBuffer);
106 
107  inline uint8 GetByte(uint32 offset) const { return _rawfile->GetByte(offset); }
108  inline uint16 GetShort(uint32 offset) const { return _rawfile->GetShort(offset); }
109  inline uint32 GetWord(uint32 offset) const { return _rawfile->GetWord(offset); }
110  /*
111  * For whatever reason, you can create null-length VGMItems.
112  * The only safe way for now is to
113  * assume maximum length
114  */
115  size_t GetEndOffset() { return _rawfile->size(); }
116 
117  const char *data() const { return _rawfile->data() + _dwOffset; }
118 
119  RawFile *_rawfile;
120 };
121 
122 // *********
123 // VGMHeader
124 // *********
125 
126 class VGMHeader : public VGMContainerItem {
127 public:
128  VGMHeader(VGMItem *parItem, uint32 offset = 0, uint32 length = 0,
129  const Common::String &name = "Header");
130  virtual ~VGMHeader();
131 };
132 
133 class VGMInstr;
134 class VGMRgnItem;
135 class VGMSampColl;
136 
137 // ******
138 // VGMRgn
139 // ******
140 
141 class VGMRgn : public VGMContainerItem {
142 public:
143  VGMRgn(VGMInstr *instr, uint32 offset, uint32 length = 0, Common::String name = "Region");
144  ~VGMRgn();
145 
146  virtual bool LoadRgn() { return true; }
147 
148  void AddGeneralItem(uint32 offset, uint32 length, const Common::String &name);
149  void SetFineTune(int16 relativePitchCents) { _fineTune = relativePitchCents; }
150  void SetPan(uint8 pan);
151  void AddPan(uint8 pan, uint32 offset, uint32 length = 1);
152  void AddVolume(double volume, uint32 offset, uint32 length = 1);
153  void AddUnityKey(int8 unityKey, uint32 offset, uint32 length = 1);
154  void AddKeyLow(uint8 keyLow, uint32 offset, uint32 length = 1);
155  void AddKeyHigh(uint8 keyHigh, uint32 offset, uint32 length = 1);
156  void AddSampNum(int sampNum, uint32 offset, uint32 length = 1);
157 
158  VGMInstr *_parInstr;
159  uint8 _keyLow;
160  uint8 _keyHigh;
161  uint8 _velLow;
162  uint8 _velHigh;
163 
164  int8 _unityKey;
165  short _fineTune;
166 
167  Loop _loop;
168 
169  int _sampNum;
170  VGMSampColl *_sampCollPtr;
171 
172  double _volume; /* Percentage of full volume */
173  double _pan; /* Left 0 <- 0.5 Center -> 1 Right */
174  double _attack_time; /* In seconds */
175  double _decay_time; /* In seconds */
176  double _release_time; /* In seconds */
177  double _sustain_level; /* Percentage */
178  double _sustain_time; /* In seconds (no positive rate!) */
179 
180  uint16 _attack_transform;
181  uint16 _release_transform;
182 
184 };
185 
186 // **********
187 // VGMRgnItem
188 // **********
189 
190 class VGMRgnItem : public VGMItem {
191 public:
192  enum RgnItemType {
193  RIT_GENERIC,
194  RIT_UNKNOWN,
195  RIT_UNITYKEY,
196  RIT_FINETUNE,
197  RIT_KEYLOW,
198  RIT_KEYHIGH,
199  RIT_VELLOW,
200  RIT_VELHIGH,
201  RIT_PAN,
202  RIT_VOL,
203  RIT_SAMPNUM
204  };
205 
206  VGMRgnItem(VGMRgn *rgn, RgnItemType theType, uint32 offset, uint32 length,
207  const Common::String &name);
208 
209 public:
210  RgnItemType _type;
211 };
212 
213 #endif // AUDIO_SOUNDFONT_VGMITEM_H
Definition: vgmitem.h:65
Definition: vgmitem.h:141
Definition: str.h:59
Definition: vgminstrset.h:66
Definition: rawfile.h:35
Definition: array.h:52
Definition: vgmsamp.h:77
Definition: vgmitem.h:190
Definition: vgmcoll.h:38
Definition: common.h:36
Definition: vgmitem.h:126
Definition: vgmitem.h:42
Definition: vgmitem.h:89