DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/mt32/Structures.h
00001 /* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
00002  * Copyright (C) 2011, 2012, 2013 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
00003  *
00004  *  This program is free software: you can redistribute it and/or modify
00005  *  it under the terms of the GNU Lesser General Public License as published by
00006  *  the Free Software Foundation, either version 2.1 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU Lesser General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Lesser General Public License
00015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef MT32EMU_STRUCTURES_H
00019 #define MT32EMU_STRUCTURES_H
00020 
00021 namespace MT32Emu {
00022 
00023 // MT32EMU_MEMADDR() converts from sysex-padded, MT32EMU_SYSEXMEMADDR converts to it
00024 // Roland provides documentation using the sysex-padded addresses, so we tend to use that in code and output
00025 #define MT32EMU_MEMADDR(x) ((((x) & 0x7f0000) >> 2) | (((x) & 0x7f00) >> 1) | ((x) & 0x7f))
00026 #define MT32EMU_SYSEXMEMADDR(x) ((((x) & 0x1FC000) << 2) | (((x) & 0x3F80) << 1) | ((x) & 0x7f))
00027 
00028 #ifdef _MSC_VER
00029 #define  MT32EMU_ALIGN_PACKED __declspec(align(1))
00030 #else
00031 #define MT32EMU_ALIGN_PACKED __attribute__((packed))
00032 #endif
00033 
00034 typedef unsigned int       Bit32u;
00035 typedef   signed int       Bit32s;
00036 typedef unsigned short int Bit16u;
00037 typedef   signed short int Bit16s;
00038 typedef unsigned char      Bit8u;
00039 typedef   signed char      Bit8s;
00040 
00041 // The following structures represent the MT-32's memory
00042 // Since sysex allows this memory to be written to in blocks of bytes,
00043 // we keep this packed so that we can copy data into the various
00044 // banks directly
00045 #if defined(_MSC_VER) || defined(__MINGW32__)
00046 #pragma pack(push, 1)
00047 #else
00048 #pragma pack(1)
00049 #endif
00050 
00051 struct TimbreParam {
00052         struct CommonParam {
00053                 char name[10];
00054                 Bit8u partialStructure12;  // 1 & 2  0-12 (1-13)
00055                 Bit8u partialStructure34;  // 3 & 4  0-12 (1-13)
00056                 Bit8u partialMute;  // 0-15 (0000-1111)
00057                 Bit8u noSustain; // ENV MODE 0-1 (Normal, No sustain)
00058         } MT32EMU_ALIGN_PACKED common;
00059 
00060         struct PartialParam {
00061                 struct WGParam {
00062                         Bit8u pitchCoarse;  // 0-96 (C1,C#1-C9)
00063                         Bit8u pitchFine;  // 0-100 (-50 to +50 (cents - confirmed by Mok))
00064                         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)
00065                         Bit8u pitchBenderEnabled;  // 0-1 (OFF, ON)
00066                         Bit8u waveform; // MT-32: 0-1 (SQU/SAW); LAPC-I: WG WAVEFORM/PCM BANK 0 - 3 (SQU/1, SAW/1, SQU/2, SAW/2)
00067                         Bit8u pcmWave; // 0-127 (1-128)
00068                         Bit8u pulseWidth; // 0-100
00069                         Bit8u pulseWidthVeloSensitivity; // 0-14 (-7 - +7)
00070                 } MT32EMU_ALIGN_PACKED wg;
00071 
00072                 struct PitchEnvParam {
00073                         Bit8u depth; // 0-10
00074                         Bit8u veloSensitivity; // 0-100
00075                         Bit8u timeKeyfollow; // 0-4
00076                         Bit8u time[4]; // 0-100
00077                         Bit8u level[5]; // 0-100 (-50 - +50) // [3]: SUSTAIN LEVEL, [4]: END LEVEL
00078                 } MT32EMU_ALIGN_PACKED pitchEnv;
00079 
00080                 struct PitchLFOParam {
00081                         Bit8u rate; // 0-100
00082                         Bit8u depth; // 0-100
00083                         Bit8u modSensitivity; // 0-100
00084                 } MT32EMU_ALIGN_PACKED pitchLFO;
00085 
00086                 struct TVFParam {
00087                         Bit8u cutoff; // 0-100
00088                         Bit8u resonance; // 0-30
00089                         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
00090                         Bit8u biasPoint; // 0-127 (<1A-<7C >1A-7C)
00091                         Bit8u biasLevel; // 0-14 (-7 - +7)
00092                         Bit8u envDepth; // 0-100
00093                         Bit8u envVeloSensitivity; // 0-100
00094                         Bit8u envDepthKeyfollow; // DEPTH KEY FOLL0W 0-4
00095                         Bit8u envTimeKeyfollow; // TIME KEY FOLLOW 0-4
00096                         Bit8u envTime[5]; // 0-100
00097                         Bit8u envLevel[4]; // 0-100 // [3]: SUSTAIN LEVEL
00098                 } MT32EMU_ALIGN_PACKED tvf;
00099 
00100                 struct TVAParam {
00101                         Bit8u level; // 0-100
00102                         Bit8u veloSensitivity; // 0-100
00103                         Bit8u biasPoint1; // 0-127 (<1A-<7C >1A-7C)
00104                         Bit8u biasLevel1; // 0-12 (-12 - 0)
00105                         Bit8u biasPoint2; // 0-127 (<1A-<7C >1A-7C)
00106                         Bit8u biasLevel2; // 0-12 (-12 - 0)
00107                         Bit8u envTimeKeyfollow; // TIME KEY FOLLOW 0-4
00108                         Bit8u envTimeVeloSensitivity; // VELOS KEY FOLL0W 0-4
00109                         Bit8u envTime[5]; // 0-100
00110                         Bit8u envLevel[4]; // 0-100 // [3]: SUSTAIN LEVEL
00111                 } MT32EMU_ALIGN_PACKED tva;
00112         } MT32EMU_ALIGN_PACKED partial[4];
00113 } MT32EMU_ALIGN_PACKED;
00114 
00115 struct PatchParam {
00116         Bit8u timbreGroup; // TIMBRE GROUP  0-3 (group A, group B, Memory, Rhythm)
00117         Bit8u timbreNum; // TIMBRE NUMBER 0-63
00118         Bit8u keyShift; // KEY SHIFT 0-48 (-24 - +24 semitones)
00119         Bit8u fineTune; // FINE TUNE 0-100 (-50 - +50 cents)
00120         Bit8u benderRange; // BENDER RANGE 0-24
00121         Bit8u assignMode;  // ASSIGN MODE 0-3 (POLY1, POLY2, POLY3, POLY4)
00122         Bit8u reverbSwitch;  // REVERB SWITCH 0-1 (OFF,ON)
00123         Bit8u dummy; // (DUMMY)
00124 } MT32EMU_ALIGN_PACKED;
00125 
00126 const unsigned int SYSTEM_MASTER_TUNE_OFF = 0;
00127 const unsigned int SYSTEM_REVERB_MODE_OFF = 1;
00128 const unsigned int SYSTEM_REVERB_TIME_OFF = 2;
00129 const unsigned int SYSTEM_REVERB_LEVEL_OFF = 3;
00130 const unsigned int SYSTEM_RESERVE_SETTINGS_START_OFF = 4;
00131 const unsigned int SYSTEM_RESERVE_SETTINGS_END_OFF = 12;
00132 const unsigned int SYSTEM_CHAN_ASSIGN_START_OFF = 13;
00133 const unsigned int SYSTEM_CHAN_ASSIGN_END_OFF = 21;
00134 const unsigned int SYSTEM_MASTER_VOL_OFF = 22;
00135 
00136 struct MemParams {
00137         // NOTE: The MT-32 documentation only specifies PatchTemp areas for parts 1-8.
00138         // The LAPC-I documentation specified an additional area for rhythm at the end,
00139         // where all parameters but fine tune, assign mode and output level are ignored
00140         struct PatchTemp {
00141                 PatchParam patch;
00142                 Bit8u outputLevel; // OUTPUT LEVEL 0-100
00143                 Bit8u panpot; // PANPOT 0-14 (R-L)
00144                 Bit8u dummyv[6];
00145         } MT32EMU_ALIGN_PACKED patchTemp[9];
00146 
00147         struct RhythmTemp {
00148                 Bit8u timbre; // TIMBRE  0-94 (M1-M64,R1-30,OFF); LAPC-I: 0-127 (M01-M64,R01-R63)
00149                 Bit8u outputLevel; // OUTPUT LEVEL 0-100
00150                 Bit8u panpot; // PANPOT 0-14 (R-L)
00151                 Bit8u reverbSwitch;  // REVERB SWITCH 0-1 (OFF,ON)
00152         } MT32EMU_ALIGN_PACKED rhythmTemp[85];
00153 
00154         TimbreParam timbreTemp[8];
00155 
00156         PatchParam patches[128];
00157 
00158         // NOTE: There are only 30 timbres in the "rhythm" bank for MT-32; the additional 34 are for LAPC-I and above
00159         struct PaddedTimbre {
00160                 TimbreParam timbre;
00161                 Bit8u padding[10];
00162         } MT32EMU_ALIGN_PACKED timbres[64 + 64 + 64 + 64]; // Group A, Group B, Memory, Rhythm
00163 
00164         struct System {
00165                 Bit8u masterTune; // MASTER TUNE 0-127 432.1-457.6Hz
00166                 Bit8u reverbMode; // REVERB MODE 0-3 (room, hall, plate, tap delay)
00167                 Bit8u reverbTime; // REVERB TIME 0-7 (1-8)
00168                 Bit8u reverbLevel; // REVERB LEVEL 0-7 (1-8)
00169                 Bit8u reserveSettings[9]; // PARTIAL RESERVE (PART 1) 0-32
00170                 Bit8u chanAssign[9]; // MIDI CHANNEL (PART1) 0-16 (1-16,OFF)
00171                 Bit8u masterVol; // MASTER VOLUME 0-100
00172         } MT32EMU_ALIGN_PACKED system;
00173 };
00174 
00175 #if defined(_MSC_VER) || defined(__MINGW32__)
00176 #pragma pack(pop)
00177 #else
00178 #pragma pack()
00179 #endif
00180 
00181 struct ControlROMPCMStruct;
00182 
00183 struct PCMWaveEntry {
00184         Bit32u addr;
00185         Bit32u len;
00186         bool loop;
00187         ControlROMPCMStruct *controlROMPCMStruct;
00188 };
00189 
00190 // This is basically a per-partial, pre-processed combination of timbre and patch/rhythm settings
00191 struct PatchCache {
00192         bool playPartial;
00193         bool PCMPartial;
00194         int pcm;
00195         char waveform;
00196 
00197         Bit32u structureMix;
00198         int structurePosition;
00199         int structurePair;
00200 
00201         // The following fields are actually common to all partials in the timbre
00202         bool dirty;
00203         Bit32u partialCount;
00204         bool sustain;
00205         bool reverb;
00206 
00207         TimbreParam::PartialParam srcPartial;
00208 
00209         // The following directly points into live sysex-addressable memory
00210         const TimbreParam::PartialParam *partialParam;
00211 };
00212 
00213 class Partial; // Forward reference for class defined in partial.h
00214 
00215 }
00216 
00217 #endif