MIDIEvents.h 5.1 KB

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