ScummVM API documentation
Structures.h
1 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
2  * Copyright (C) 2011-2022 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef MT32EMU_STRUCTURES_H
19 #define MT32EMU_STRUCTURES_H
20 
21 #include "globals.h"
22 #include "Types.h"
23 
24 namespace MT32Emu {
25 
26 // MT32EMU_MEMADDR() converts from sysex-padded, MT32EMU_SYSEXMEMADDR converts to it
27 // Roland provides documentation using the sysex-padded addresses, so we tend to use that in code and output
28 #define MT32EMU_MEMADDR(x) ((((x) & 0x7f0000) >> 2) | (((x) & 0x7f00) >> 1) | ((x) & 0x7f))
29 #define MT32EMU_SYSEXMEMADDR(x) ((((x) & 0x1FC000) << 2) | (((x) & 0x3F80) << 1) | ((x) & 0x7f))
30 
31 #ifdef _MSC_VER
32 #define MT32EMU_ALIGN_PACKED __declspec(align(1))
33 #else
34 #define MT32EMU_ALIGN_PACKED __attribute__((packed))
35 #endif
36 
37 // The following structures represent the MT-32's memory
38 // Since sysex allows this memory to be written to in blocks of bytes,
39 // we keep this packed so that we can copy data into the various
40 // banks directly
41 #if defined(_MSC_VER) || defined(__MINGW32__)
42 #pragma pack(push, 1)
43 #else
44 #pragma pack(1)
45 #endif
46 
47 struct TimbreParam {
48  struct CommonParam {
49  char name[10];
50  Bit8u partialStructure12; // 1 & 2 0-12 (1-13)
51  Bit8u partialStructure34; // 3 & 4 0-12 (1-13)
52  Bit8u partialMute; // 0-15 (0000-1111)
53  Bit8u noSustain; // ENV MODE 0-1 (Normal, No sustain)
54  } MT32EMU_ALIGN_PACKED common;
55 
56  struct PartialParam {
57  struct WGParam {
58  Bit8u pitchCoarse; // 0-96 (C1,C#1-C9)
59  Bit8u pitchFine; // 0-100 (-50 to +50 (cents - confirmed by Mok))
60  Bit8u pitchKeyfollow; // 0-16 (-1, -1/2, -1/4, 0, 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, 1, 5/4, 3/2, 2, s1, s2)
61  Bit8u pitchBenderEnabled; // 0-1 (OFF, ON)
62  Bit8u waveform; // MT-32: 0-1 (SQU/SAW); LAPC-I: WG WAVEFORM/PCM BANK 0 - 3 (SQU/1, SAW/1, SQU/2, SAW/2)
63  Bit8u pcmWave; // 0-127 (1-128)
64  Bit8u pulseWidth; // 0-100
65  Bit8u pulseWidthVeloSensitivity; // 0-14 (-7 - +7)
66  } MT32EMU_ALIGN_PACKED wg;
67 
68  struct PitchEnvParam {
69  Bit8u depth; // 0-10
70  Bit8u veloSensitivity; // 0-100
71  Bit8u timeKeyfollow; // 0-4
72  Bit8u time[4]; // 0-100
73  Bit8u level[5]; // 0-100 (-50 - +50) // [3]: SUSTAIN LEVEL, [4]: END LEVEL
74  } MT32EMU_ALIGN_PACKED pitchEnv;
75 
76  struct PitchLFOParam {
77  Bit8u rate; // 0-100
78  Bit8u depth; // 0-100
79  Bit8u modSensitivity; // 0-100
80  } MT32EMU_ALIGN_PACKED pitchLFO;
81 
82  struct TVFParam {
83  Bit8u cutoff; // 0-100
84  Bit8u resonance; // 0-30
85  Bit8u keyfollow; // -1, -1/2, -1/4, 0, 1/8, 1/4, 3/8, 1/2, 5/8, 3/4, 7/8, 1, 5/4, 3/2, 2
86  Bit8u biasPoint; // 0-127 (<1A-<7C >1A-7C)
87  Bit8u biasLevel; // 0-14 (-7 - +7)
88  Bit8u envDepth; // 0-100
89  Bit8u envVeloSensitivity; // 0-100
90  Bit8u envDepthKeyfollow; // DEPTH KEY FOLL0W 0-4
91  Bit8u envTimeKeyfollow; // TIME KEY FOLLOW 0-4
92  Bit8u envTime[5]; // 0-100
93  Bit8u envLevel[4]; // 0-100 // [3]: SUSTAIN LEVEL
94  } MT32EMU_ALIGN_PACKED tvf;
95 
96  struct TVAParam {
97  Bit8u level; // 0-100
98  Bit8u veloSensitivity; // 0-100
99  Bit8u biasPoint1; // 0-127 (<1A-<7C >1A-7C)
100  Bit8u biasLevel1; // 0-12 (-12 - 0)
101  Bit8u biasPoint2; // 0-127 (<1A-<7C >1A-7C)
102  Bit8u biasLevel2; // 0-12 (-12 - 0)
103  Bit8u envTimeKeyfollow; // TIME KEY FOLLOW 0-4
104  Bit8u envTimeVeloSensitivity; // VELOS KEY FOLL0W 0-4
105  Bit8u envTime[5]; // 0-100
106  Bit8u envLevel[4]; // 0-100 // [3]: SUSTAIN LEVEL
107  } MT32EMU_ALIGN_PACKED tva;
108  } MT32EMU_ALIGN_PACKED partial[4]; // struct PartialParam
109 } MT32EMU_ALIGN_PACKED; // struct TimbreParam
110 
111 struct PatchParam {
112  Bit8u timbreGroup; // TIMBRE GROUP 0-3 (group A, group B, Memory, Rhythm)
113  Bit8u timbreNum; // TIMBRE NUMBER 0-63
114  Bit8u keyShift; // KEY SHIFT 0-48 (-24 - +24 semitones)
115  Bit8u fineTune; // FINE TUNE 0-100 (-50 - +50 cents)
116  Bit8u benderRange; // BENDER RANGE 0-24
117  Bit8u assignMode; // ASSIGN MODE 0-3 (POLY1, POLY2, POLY3, POLY4)
118  Bit8u reverbSwitch; // REVERB SWITCH 0-1 (OFF,ON)
119  Bit8u dummy; // (DUMMY)
120 } MT32EMU_ALIGN_PACKED;
121 
122 const unsigned int SYSTEM_MASTER_TUNE_OFF = 0;
123 const unsigned int SYSTEM_REVERB_MODE_OFF = 1;
124 const unsigned int SYSTEM_REVERB_TIME_OFF = 2;
125 const unsigned int SYSTEM_REVERB_LEVEL_OFF = 3;
126 const unsigned int SYSTEM_RESERVE_SETTINGS_START_OFF = 4;
127 const unsigned int SYSTEM_RESERVE_SETTINGS_END_OFF = 12;
128 const unsigned int SYSTEM_CHAN_ASSIGN_START_OFF = 13;
129 const unsigned int SYSTEM_CHAN_ASSIGN_END_OFF = 21;
130 const unsigned int SYSTEM_MASTER_VOL_OFF = 22;
132 struct MemParams {
133  // NOTE: The MT-32 documentation only specifies PatchTemp areas for parts 1-8.
134  // The LAPC-I documentation specified an additional area for rhythm at the end,
135  // where all parameters but fine tune, assign mode and output level are ignored
136  struct PatchTemp {
137  PatchParam patch;
138  Bit8u outputLevel; // OUTPUT LEVEL 0-100
139  Bit8u panpot; // PANPOT 0-14 (R-L)
140  Bit8u dummyv[6];
141  } MT32EMU_ALIGN_PACKED patchTemp[9];
143  struct RhythmTemp {
144  Bit8u timbre; // TIMBRE 0-94 (M1-M64,R1-30,OFF); LAPC-I: 0-127 (M01-M64,R01-R63)
145  Bit8u outputLevel; // OUTPUT LEVEL 0-100
146  Bit8u panpot; // PANPOT 0-14 (R-L)
147  Bit8u reverbSwitch; // REVERB SWITCH 0-1 (OFF,ON)
148  } MT32EMU_ALIGN_PACKED rhythmTemp[85];
149 
150  TimbreParam timbreTemp[8];
151 
152  PatchParam patches[128];
153 
154  // NOTE: There are only 30 timbres in the "rhythm" bank for MT-32; the additional 34 are for LAPC-I and above
155  struct PaddedTimbre {
156  TimbreParam timbre;
157  Bit8u padding[10];
158  } MT32EMU_ALIGN_PACKED timbres[64 + 64 + 64 + 64]; // Group A, Group B, Memory, Rhythm
159 
160  struct System {
161  Bit8u masterTune; // MASTER TUNE 0-127 432.1-457.6Hz
162  Bit8u reverbMode; // REVERB MODE 0-3 (room, hall, plate, tap delay)
163  Bit8u reverbTime; // REVERB TIME 0-7 (1-8)
164  Bit8u reverbLevel; // REVERB LEVEL 0-7 (1-8)
165  Bit8u reserveSettings[9]; // PARTIAL RESERVE (PART 1) 0-32
166  Bit8u chanAssign[9]; // MIDI CHANNEL (PART1) 0-16 (1-16,OFF)
167  Bit8u masterVol; // MASTER VOLUME 0-100
168  } MT32EMU_ALIGN_PACKED system;
169 }; // struct MemParams
171 struct SoundGroup {
172  Bit8u timbreNumberTableAddrLow;
173  Bit8u timbreNumberTableAddrHigh;
174  Bit8u displayPosition;
175  Bit8u name[9];
176  Bit8u timbreCount;
177  Bit8u pad;
178 } MT32EMU_ALIGN_PACKED;
179 
180 #if defined(_MSC_VER) || defined(__MINGW32__)
181 #pragma pack(pop)
182 #else
183 #pragma pack()
184 #endif
185 
187  unsigned int quirkBasePitchOverflow : 1;
188  unsigned int quirkPitchEnvelopeOverflow : 1;
189  unsigned int quirkRingModulationNoMix : 1;
190  unsigned int quirkTVAZeroEnvLevels : 1;
191  unsigned int quirkPanMult : 1;
192  unsigned int quirkKeyShift : 1;
193  unsigned int quirkTVFBaseCutoffLimit : 1;
194  unsigned int quirkFastPitchChanges : 1;
195  unsigned int quirkDisplayCustomMessagePriority : 1;
196  unsigned int oldMT32DisplayFeatures : 1;
197 
198  // Features below don't actually depend on control ROM version, which is used to identify hardware model
199  unsigned int defaultReverbMT32Compatible : 1;
200  unsigned int oldMT32AnalogLPF : 1;
201 };
202 
204  const char *shortName;
205  const ControlROMFeatureSet &featureSet;
206  Bit16u pcmTable; // 4 * pcmCount bytes
207  Bit16u pcmCount;
208  Bit16u timbreAMap; // 128 bytes
209  Bit16u timbreAOffset;
210  bool timbreACompressed;
211  Bit16u timbreBMap; // 128 bytes
212  Bit16u timbreBOffset;
213  bool timbreBCompressed;
214  Bit16u timbreRMap; // 2 * timbreRCount bytes
215  Bit16u timbreRCount;
216  Bit16u rhythmSettings; // 4 * rhythmSettingsCount bytes
217  Bit16u rhythmSettingsCount;
218  Bit16u reserveSettings; // 9 bytes
219  Bit16u panSettings; // 8 bytes
220  Bit16u programSettings; // 8 bytes
221  Bit16u rhythmMaxTable; // 4 bytes
222  Bit16u patchMaxTable; // 16 bytes
223  Bit16u systemMaxTable; // 23 bytes
224  Bit16u timbreMaxTable; // 72 bytes
225  Bit16u soundGroupsTable; // 14 bytes each entry
226  Bit16u soundGroupsCount;
227  Bit16u startupMessage; // 20 characters + NULL terminator
228  Bit16u sysexErrorMessage; // 20 characters + NULL terminator
229 };
230 
232  Bit8u pos;
233  Bit8u len;
234  Bit8u pitchLSB;
235  Bit8u pitchMSB;
236 };
237 
238 struct PCMWaveEntry {
239  Bit32u addr;
240  Bit32u len;
241  bool loop;
242  ControlROMPCMStruct *controlROMPCMStruct;
243 };
244 
245 // This is basically a per-partial, pre-processed combination of timbre and patch/rhythm settings
246 struct PatchCache {
247  bool playPartial;
248  bool PCMPartial;
249  int pcm;
250  Bit8u waveform;
251 
252  Bit32u structureMix;
253  int structurePosition;
254  int structurePair;
255 
256  // The following fields are actually common to all partials in the timbre
257  bool dirty;
258  Bit32u partialCount;
259  bool sustain;
260  bool reverb;
261 
262  TimbreParam::PartialParam srcPartial;
263 
264  // The following directly points into live sysex-addressable memory
265  const TimbreParam::PartialParam *partialParam;
266 };
267 
268 } // namespace MT32Emu
269 
270 #endif // #ifndef MT32EMU_STRUCTURES_H
Definition: Structures.h:47
Definition: Structures.h:111
Definition: Analog.h:26
Definition: Structures.h:132
Definition: Structures.h:231
Definition: Structures.h:186
Definition: Structures.h:238
Definition: Structures.h:136
Definition: Structures.h:171
Definition: Structures.h:60
Definition: Structures.h:246
Definition: Structures.h:160
Definition: Structures.h:143
Definition: Structures.h:40
Definition: Structures.h:203
Definition: Structures.h:155
Definition: Structures.h:56