OpenTTD Source  20241108-master-g80f628063a
midi.h
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
8 /* @file midi.h Declarations for MIDI data */
9 
10 #ifndef MUSIC_MIDI_H
11 #define MUSIC_MIDI_H
12 
13 #include "../stdafx.h"
14 
16 struct SMFHeader {
17  uint16_t format;
18  uint16_t tracks;
19  uint16_t tickdiv;
20 };
21 
23 enum MidiStatus {
24  /* Bytes with top bit unset are data bytes i.e. not status bytes */
25  /* Channel status messages, require channel number in lower nibble */
26  MIDIST_NOTEOFF = 0x80,
27  MIDIST_NOTEON = 0x90,
28  MIDIST_POLYPRESS = 0xA0,
29  MIDIST_CONTROLLER = 0xB0,
30  MIDIST_PROGCHG = 0xC0,
31  MIDIST_CHANPRESS = 0xD0,
32  MIDIST_PITCHBEND = 0xE0,
33  /* Full byte status messages */
34  MIDIST_SYSEX = 0xF0,
35  MIDIST_TC_QFRAME = 0xF1,
36  MIDIST_SONGPOSPTR = 0xF2,
37  MIDIST_SONGSEL = 0xF3,
38  /* not defined: 0xF4, */
39  /* not defined: 0xF5, */
40  MIDIST_TUNEREQ = 0xF6,
41  MIDIST_ENDSYSEX = 0xF7,
42  MIDIST_SMF_ESCAPE = 0xF7,
43  MIDIST_RT_CLOCK = 0xF8,
44  /* not defined: 0xF9, */
45  MIDIST_RT_START = 0xFA,
46  MIDIST_RT_CONTINUE = 0xFB,
47  MIDIST_RT_STOP = 0xFC,
48  /* not defined: 0xFD, */
49  MIDIST_RT_ACTSENS = 0xFE,
50  MIDIST_SYSRESET = 0xFF,
51  MIDIST_SMF_META = 0xFF,
52 };
53 
58 enum MidiController {
59  /* Standard continuous controllers (MSB control) */
60  MIDICT_BANKSELECT = 0,
61  MIDICT_MODWHEEL = 1,
62  MIDICT_BREATH = 2,
63  MIDICT_FOOT = 4,
64  MIDICT_PORTAMENTO = 5,
65  MIDICT_DATAENTRY = 6,
66  MIDICT_CHANVOLUME = 7,
67  MIDICT_BALANCE = 8,
68  MIDICT_PAN = 10,
69  MIDICT_EXPRESSION = 11,
70  MIDICT_EFFECT1 = 12,
71  MIDICT_EFFECT2 = 13,
72  MIDICT_GENERAL1 = 16,
73  MIDICT_GENERAL2 = 17,
74  MIDICT_GENERAL3 = 18,
75  MIDICT_GENERAL4 = 19,
76  /* Offset from MSB to LSB of continuous controllers */
77  MIDICTOFS_HIGHRES = 32,
78  /* Stanard continuous controllers (LSB control) */
79  MIDICT_BANKSELECT_LO = MIDICTOFS_HIGHRES + MIDICT_BANKSELECT,
80  MIDICT_MODWHEEL_LO = MIDICTOFS_HIGHRES + MIDICT_MODWHEEL,
81  MIDICT_BREATH_LO = MIDICTOFS_HIGHRES + MIDICT_BREATH,
82  MIDICT_FOOT_LO = MIDICTOFS_HIGHRES + MIDICT_FOOT,
83  MIDICT_PORTAMENTO_LO = MIDICTOFS_HIGHRES + MIDICT_PORTAMENTO,
84  MIDICT_DATAENTRY_LO = MIDICTOFS_HIGHRES + MIDICT_DATAENTRY,
85  MIDICT_CHANVOLUME_LO = MIDICTOFS_HIGHRES + MIDICT_CHANVOLUME,
86  MIDICT_BALANCE_LO = MIDICTOFS_HIGHRES + MIDICT_BALANCE,
87  MIDICT_PAN_LO = MIDICTOFS_HIGHRES + MIDICT_PAN,
88  MIDICT_EXPRESSION_LO = MIDICTOFS_HIGHRES + MIDICT_EXPRESSION,
89  MIDICT_EFFECT1_LO = MIDICTOFS_HIGHRES + MIDICT_EFFECT1,
90  MIDICT_EFFECT2_LO = MIDICTOFS_HIGHRES + MIDICT_EFFECT2,
91  MIDICT_GENERAL1_LO = MIDICTOFS_HIGHRES + MIDICT_GENERAL1,
92  MIDICT_GENERAL2_LO = MIDICTOFS_HIGHRES + MIDICT_GENERAL2,
93  MIDICT_GENERAL3_LO = MIDICTOFS_HIGHRES + MIDICT_GENERAL3,
94  MIDICT_GENERAL4_LO = MIDICTOFS_HIGHRES + MIDICT_GENERAL4,
95  /* Switch controllers */
96  MIDICT_SUSTAINSW = 64,
97  MIDICT_PORTAMENTOSW = 65,
98  MIDICT_SOSTENUTOSW = 66,
99  MIDICT_SOFTPEDALSW = 67,
100  MIDICT_LEGATOSW = 68,
101  MIDICT_HOLD2SW = 69,
102  /* Standard low-resolution controllers */
103  MIDICT_SOUND1 = 70,
104  MIDICT_SOUND2 = 71,
105  MIDICT_SOUND3 = 72,
106  MIDICT_SOUND4 = 73,
107  MIDICT_SOUND5 = 74,
108  MIDICT_SOUND6 = 75,
109  MIDICT_SOUND7 = 76,
110  MIDICT_SOUND8 = 77,
111  MIDICT_SOUND9 = 78,
112  MIDICT_SOUND10 = 79,
113  MIDICT_GENERAL5 = 80,
114  MIDICT_GENERAL6 = 81,
115  MIDICT_GENERAL7 = 82,
116  MIDICT_GENERAL8 = 83,
117  MIDICT_PORTAMENTOCTL = 84,
118  MIDICT_PRF_HIGHRESVEL = 88,
119  MIDICT_EFFECTS1 = 91,
120  MIDICT_EFFECTS2 = 92,
121  MIDICT_EFFECTS3 = 93,
122  MIDICT_EFFECTS4 = 94,
123  MIDICT_EFFECTS5 = 95,
124  /* Registered/unregistered parameters control */
125  MIDICT_DATA_INCREMENT = 96,
126  MIDICT_DATA_DECREMENT = 97,
127  MIDICT_NRPN_SELECT_LO = 98,
128  MIDICT_NRPN_SELECT_HI = 99,
129  MIDICT_RPN_SELECT_LO = 100,
130  MIDICT_RPN_SELECT_HI = 101,
131  /* Channel mode messages */
132  MIDICT_MODE_ALLSOUNDOFF = 120,
133  MIDICT_MODE_RESETALLCTRL = 121,
134  MIDICT_MODE_LOCALCTL = 122,
135  MIDICT_MODE_ALLNOTESOFF = 123,
136  MIDICT_MODE_OMNI_OFF = 124,
137  MIDICT_MODE_OMNI_ON = 125,
138  MIDICT_MODE_MONO = 126,
139  MIDICT_MODE_POLY = 127,
140 };
141 
142 
144 enum class MidiSysexMessage {
146  ResetGM,
148  ResetGS,
150  ResetXG,
152  RolandSetReverb,
153 };
154 
155 const uint8_t *MidiGetStandardSysexMessage(MidiSysexMessage msg, size_t &length);
156 
157 #endif /* MUSIC_MIDI_H */
Header of a Stanard MIDI File.
Definition: midi.h:16