1 /*
2  * MIDIEvents.h
3  * ------------
4  * Purpose: MIDI event handling, event lists, ...
5  * Notes  : (currently none)
6  * Authors: OpenMPT Devs
7  * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
8  */
9 
10 
11 #pragma once
12 
13 #include "openmpt/all/BuildSettings.hpp"
14 
15 
16 OPENMPT_NAMESPACE_BEGIN
17 
18 
19 // MIDI related enums and helper functions
20 namespace MIDIEvents
21 {
22 
23 	// MIDI Event Types
24 	enum EventType
25 	{
26 		evNoteOff			= 0x8,	// Note Off event
27 		evNoteOn			= 0x9,	// Note On event
28 		evPolyAftertouch	= 0xA,	// Poly Aftertouch / Poly Pressure event
29 		evControllerChange	= 0xB,	// Controller Change (see MidiCC enum)
30 		evProgramChange		= 0xC,	// Program Change
31 		evChannelAftertouch	= 0xD,	// Channel Aftertouch
32 		evPitchBend			= 0xE,	// Pitchbend event (see PitchBend enum)
33 		evSystem			= 0xF,	// System event (see SystemEvent enum)
34 	};
35 
36 	// System Events (Fx ...)
37 	enum SystemEvent
38 	{
39 		sysExStart			= 0x0,	// Begin of System Exclusive message
40 		sysQuarterFrame		= 0x1,	// Quarter Frame Message
41 		sysPositionPointer	= 0x2,	// Song Position Pointer
42 		sysSongSelect		= 0x3,	// Song Select
43 		sysTuneRequest		= 0x6,	// Tune Request
44 		sysExEnd			= 0x7,	// End of System Exclusive message
45 		sysMIDIClock		= 0x8,	// MIDI Clock event
46 		sysMIDITick			= 0x9,	// MIDI Tick event
47 		sysStart			= 0xA,	// Start Song
48 		sysContinue			= 0xB,	// Continue Song
49 		sysStop				= 0xC,	// Stop Song
50 		sysActiveSense		= 0xE,	// Active Sense Message
51 		sysReset			= 0xF,	// Reset Device
52 	};
53 
54 	// MIDI Pitchbend Constants
55 	enum PitchBend
56 	{
57 		pitchBendMin     = 0x00,
58 		pitchBendCentre  = 0x2000,
59 		pitchBendMax     = 0x3FFF
60 	};
61 
62 	// MIDI Continuous Controller Codes
63 	// http://home.roadrunner.com/~jgglatt/tech/midispec/ctllist.htm
64 	enum MidiCC
65 	{
66 		MIDICC_start = 0,
67 		MIDICC_BankSelect_Coarse = MIDICC_start,
68 		MIDICC_ModulationWheel_Coarse = 1,
69 		MIDICC_Breathcontroller_Coarse = 2,
70 		MIDICC_FootPedal_Coarse = 4,
71 		MIDICC_PortamentoTime_Coarse = 5,
72 		MIDICC_DataEntry_Coarse = 6,
73 		MIDICC_Volume_Coarse = 7,
74 		MIDICC_Balance_Coarse = 8,
75 		MIDICC_Panposition_Coarse = 10,
76 		MIDICC_Expression_Coarse = 11,
77 		MIDICC_EffectControl1_Coarse = 12,
78 		MIDICC_EffectControl2_Coarse = 13,
79 		MIDICC_GeneralPurposeSlider1 = 16,
80 		MIDICC_GeneralPurposeSlider2 = 17,
81 		MIDICC_GeneralPurposeSlider3 = 18,
82 		MIDICC_GeneralPurposeSlider4 = 19,
83 		MIDICC_BankSelect_Fine = 32,
84 		MIDICC_ModulationWheel_Fine = 33,
85 		MIDICC_Breathcontroller_Fine = 34,
86 		MIDICC_FootPedal_Fine = 36,
87 		MIDICC_PortamentoTime_Fine = 37,
88 		MIDICC_DataEntry_Fine = 38,
89 		MIDICC_Volume_Fine = 39,
90 		MIDICC_Balance_Fine = 40,
91 		MIDICC_Panposition_Fine = 42,
92 		MIDICC_Expression_Fine = 43,
93 		MIDICC_EffectControl1_Fine = 44,
94 		MIDICC_EffectControl2_Fine = 45,
95 		MIDICC_HoldPedal_OnOff = 64,
96 		MIDICC_Portamento_OnOff = 65,
97 		MIDICC_SustenutoPedal_OnOff = 66,
98 		MIDICC_SoftPedal_OnOff = 67,
99 		MIDICC_LegatoPedal_OnOff = 68,
100 		MIDICC_Hold2Pedal_OnOff = 69,
101 		MIDICC_SoundVariation = 70,
102 		MIDICC_SoundTimbre = 71,
103 		MIDICC_SoundReleaseTime = 72,
104 		MIDICC_SoundAttackTime = 73,
105 		MIDICC_SoundBrightness = 74,
106 		MIDICC_SoundControl6 = 75,
107 		MIDICC_SoundControl7 = 76,
108 		MIDICC_SoundControl8 = 77,
109 		MIDICC_SoundControl9 = 78,
110 		MIDICC_SoundControl10 = 79,
111 		MIDICC_GeneralPurposeButton1_OnOff = 80,
112 		MIDICC_GeneralPurposeButton2_OnOff = 81,
113 		MIDICC_GeneralPurposeButton3_OnOff = 82,
114 		MIDICC_GeneralPurposeButton4_OnOff = 83,
115 		MIDICC_EffectsLevel = 91,
116 		MIDICC_TremoloLevel = 92,
117 		MIDICC_ChorusLevel = 93,
118 		MIDICC_CelesteLevel = 94,
119 		MIDICC_PhaserLevel = 95,
120 		MIDICC_DataButtonincrement = 96,
121 		MIDICC_DataButtondecrement = 97,
122 		MIDICC_NonRegisteredParameter_Fine = 98,
123 		MIDICC_NonRegisteredParameter_Coarse = 99,
124 		MIDICC_RegisteredParameter_Fine = 100,
125 		MIDICC_RegisteredParameter_Coarse = 101,
126 		MIDICC_AllSoundOff = 120,
127 		MIDICC_AllControllersOff = 121,
128 		MIDICC_LocalKeyboard_OnOff = 122,
129 		MIDICC_AllNotesOff = 123,
130 		MIDICC_OmniModeOff = 124,
131 		MIDICC_OmniModeOn = 125,
132 		MIDICC_MonoOperation = 126,
133 		MIDICC_PolyOperation = 127,
134 		MIDICC_end = MIDICC_PolyOperation,
135 	};
136 
137 	// MIDI CC Names
138 	extern const char* const MidiCCNames[MIDICC_end + 1];  // Charset::UTF8
139 
140 	// Build a generic MIDI event
141 	uint32 Event(EventType eventType, uint8 midiChannel, uint8 dataByte1, uint8 dataByte2);
142 	// Build a MIDI CC event
143 	uint32 CC(MidiCC midiCC, uint8 midiChannel, uint8 param);
144 	// Build a MIDI Pitchbend event
145 	uint32 PitchBend(uint8 midiChannel, uint16 bendAmount);
146 	// Build a MIDI Program Change event
147 	uint32 ProgramChange(uint8 midiChannel, uint8 program);
148 	// Build a MIDI Note Off event
149 	uint32 NoteOff(uint8 midiChannel, uint8 note, uint8 velocity);
150 	// Build a MIDI Note On event
151 	uint32 NoteOn(uint8 midiChannel, uint8 note, uint8 velocity);
152 	// Build a MIDI System Event
153 	uint8 System(SystemEvent eventType);
154 
155 	// Get MIDI channel from a MIDI event
156 	uint8 GetChannelFromEvent(uint32 midiMsg);
157 	// Get MIDI Event type from a MIDI event
158 	EventType GetTypeFromEvent(uint32 midiMsg);
159 	// Get first data byte from a MIDI event
160 	uint8 GetDataByte1FromEvent(uint32 midiMsg);
161 	// Get second data byte from a MIDI event
162 	uint8 GetDataByte2FromEvent(uint32 midiMsg);
163 
164 	// Get the length of a MIDI event in bytes
165 	uint8 GetEventLength(uint8 firstByte);
166 
167 }
168 
169 
170 OPENMPT_NAMESPACE_END
171