00001 #ifndef __CMidi__
00002 #define __CMidi__
00003
00004
00005
00006 #include <MathTools/CMathTools.hpp>
00007 #include <Basics/CString.hpp>
00008
00009
00010
00011 using Exponent::MathTools::CMathTools;
00012 using Exponent::Basics::CString;
00013
00014
00015
00016 namespace Exponent
00017 {
00018 namespace Midi
00019 {
00037 class CMidi
00038 {
00039 public:
00040
00041
00042
00048 FORCEINLINE static double midiToFloat(const long midiValue)
00049 {
00050 const static double midiScalar = 0.00787401574803149606299212598425197;
00051 return CMathTools::clamp(midiValue * midiScalar);
00052 }
00053
00059 FORCEINLINE static long floatToMidi(const double value)
00060 {
00061 const static double floatScalar = 127.0;
00062 return (long)(value * floatScalar);
00063 }
00064
00070 static void getMidiNoteString(const long midiNote, CString &theString)
00071 {
00072 if (midiNote >= 0 && midiNote < 128)
00073 {
00074 const static char *CMIDI_NOTE_STRINGS[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "Bb", "B" };
00075 theString.setStringWithFormat("%s%li", CMIDI_NOTE_STRINGS[midiNote % 12], (midiNote / 12) - 1);
00076 }
00077 else
00078 {
00079 theString = "Range Error";
00080 }
00081 }
00082
00088 static bool isWhiteNote(const long midiNote)
00089 {
00090 const long index = midiNote % 12;
00091 return (!(index == 1 || index == 3 || index == 5 || index == 8 || index == 10));
00092 }
00093
00099 static bool isBlackNote(const long midiNote)
00100 {
00101 const long index = midiNote % 12;
00102 return (index == 1 || index == 3 || index == 5 || index == 8 || index == 10);
00103 }
00104
00105
00106
00107 const static long CMIDI_MIDI_NONE = 0x0;
00109
00110
00111 const static long CMIDI_NOTE_OFF = 0x80;
00112 const static long CMIDI_NOTE_ON = 0x90;
00113 const static long CMIDI_POLY_PRESSURE = 0xA0;
00114 const static long CMIDI_CONTROL_CHANGE = 0xB0;
00115 const static long CMIDI_PROGRAM_CHANGE = 0xC0;
00116 const static long CMIDI_CHANNEL_PRESSURE = 0xD0;
00117 const static long CMIDI_PITCH_BEND = 0xE0;
00119
00120
00121
00122 const static long CMIDI_SYSEX = 0xF0;
00123 const static long CMIDI_SYSTEM_COMMON = 0xF1;
00124 const static long CMIDI_SONG_POSITION = 0xF2;
00125 const static long CMIDI_SONG_SELECT = 0xF3;
00126 const static long CMIDI_F4 = 0xF4;
00127 const static long CMIDI_F5 = 0xF5;
00128 const static long CMIDI_TUNER_QUEST = 0xF6;
00129 const static long CMIDI_EOX = 0xF7;
00130 const static long CMIDI_TIMING_CLOCK = 0xF8;
00131 const static long CMIDI_F9 = 0xF9;
00132 const static long CMIDI_START = 0xFA;
00133 const static long CMIDI_CONTINUE = 0xFB;
00134 const static long CMIDI_STOP = 0xFC;
00135 const static long CMIDI_FD = 0xFD;
00136 const static long CMIDI_ACTIVE_SENSING = 0xFE;
00137 const static long CMIDI_SYSTEM_RESET = 0xFF;
00139
00140
00141
00142
00143
00144 const static long CMIDI_BACK_CHANGE = 0x00;
00145 const static long CMIDI_MODULATION_WHEEL = 0x01;
00146 const static long CMIDI_BREATH_CONTROL = 0x02;
00147 const static long CMIDI_UNDEFINED_CC03 = 0x03;
00148 const static long CMIDI_FOOT_CONTROLLER = 0x04;
00149 const static long CMIDI_PORTAMENTO_TIME = 0x05;
00150 const static long CMIDI_DATA_ENTRY = 0x06;
00151 const static long CMIDI_CHANNEL_VOLUME = 0x07;
00152 const static long CMIDI_BALANCE = 0x08;
00153 const static long CMIDI_UNDEFINED_CC09 = 0x09;
00154 const static long CMIDI_PAN = 0x0A;
00155 const static long CMIDI_EXPRESSION = 0x0B;
00156 const static long CMIDI_EFFECT_CONTROL1 = 0x0C;
00157 const static long CMIDI_EFFECT_CONTROL2 = 0x0D;
00158 const static long CMIDI_UNDEFINED_CC0E = 0x0E;
00159 const static long CMIDI_UNDEFINED_CC0F = 0x0F;
00160 const static long CMIDI_GENERAL_PURPOSE1 = 0x10;
00161 const static long CMIDI_GENERAL_PURPOSE2 = 0x11;
00162 const static long CMIDI_GENERAL_PURPOSE3 = 0x12;
00163 const static long CMIDI_GENERAL_PURPOSE4 = 0x13;
00164 const static long CMIDI_UNDEFINED_CC14 = 0x14;
00165 const static long CMIDI_UNDEFINED_CC15 = 0x15;
00166 const static long CMIDI_UNDEFINED_CC16 = 0x16;
00167 const static long CMIDI_UNDEFINED_CC17 = 0x17;
00168 const static long CMIDI_UNDEFINED_CC18 = 0x18;
00169 const static long CMIDI_UNDEFINED_CC19 = 0x19;
00170 const static long CMIDI_UNDEFINED_CC1A = 0x1A;
00171 const static long CMIDI_UNDEFINED_CC1B = 0x1B;
00172 const static long CMIDI_UNDEFINED_CC1C = 0x1C;
00173 const static long CMIDI_UNDEFINED_CC1D = 0x1D;
00174 const static long CMIDI_UNDEFINED_CC1E = 0x1E;
00175 const static long CMIDI_UNDEFINED_CC1F = 0x1F;
00177
00178
00179
00180
00181 const static long CMIDI_SUSTAIN = 0x40;
00182 const static long CMIDI_PORTAMENTO = 0x41;
00183 const static long CMIDI_SOSTENUTO = 0x42;
00184 const static long CMIDI_SOFT = 0x43;
00185 const static long CMIDI_HOLD2 = 0x45;
00186 const static long CMIDI_GENERAL_PURPOSE5 = 0x50;
00187 const static long CMIDI_GENERAL_PURPOSE6 = 0x51;
00188 const static long CMIDI_GENERAL_PURPOSE7 = 0x52;
00189 const static long CMIDI_GENERAL_PURPOSE8 = 0x53;
00191
00192
00193 const static long CMIDI_EXTERNAL_EFFECTS_DEPTH = 0x5B;
00194 const static long CMIDI_TREMELO_DEPTH = 0x5C;
00195 const static long CMIDI_CHORUS_DEPTH = 0x5D;
00196 const static long CMIDI_CELESTE_DEPTH = 0x5E;
00197 const static long CMIDI_PHASE_DEPTH = 0x5F;
00198 const static long CMIDI_DATA_INCREMENT = 0x60;
00199 const static long CMIDI_DATA_DECREMENT = 0x61;
00200 const static long CMIDI_NON_REG_PARAM_NUMBER_MSB = 0x62;
00201 const static long CMIDI_NON_REG_PARAM_NUMBER_LSB = 0x63;
00202 const static long CMIDI_REG_PARAM_NUMBER_MSB = 0x64;
00203 const static long CMIDI_REG_PARAM_NUMBER_LSB = 0x65;
00205
00206
00207 const static long CMIDI_ALL_SOUNDS_OFF = 0x78;
00208 const static long CMIDI_RESET_ALL_CONTROLLERS = 0x79;
00209 const static long CMIDI_LOCAL_CONTROL = 0x7A;
00210 const static long CMIDI_ALL_NOTES_OFF = 0x7B;
00211 const static long CMIDI_OMNI_MODE_OFF = 0x7C;
00212 const static long CMIDI_OMNI_MODE_ON = 0x7D;
00213 const static long CMIDI_MONO_MODE_ON = 0x7E;
00214 const static long CMIDI_POLY_MODE_ON = 0x7F;
00216
00217
00218
00219 const static long CMIDI_MAX_NOTES = 128;
00220 const static long CMIDI_MAX_CC = 128;
00221 const static long CMIDI_MAX_NUMBER_OF_NOTES = 127;
00223
00224
00225 const static long CMIDI_STATUS_MASK = 0xF0;
00226 const static long CMIDI_CHANNEL_MASK = 0x08;
00227 const static long CMIDI_VALUE_MASK = 0x7F;
00229
00230
00231
00232 const static long CMIDI_MIDIFILE_TRACK_NUM = 0x20;
00233 const static long CMIDI_MIDIFILE_TEMPO = 0x51;
00234 const static long CMIDI_MIDIFILE_TIME_SIGNATURE = 0x58;
00235 const static long CMIDI_MIDIFILE_TRACK_NAME = 0x03;
00237 };
00238 }
00239 }
00240 #endif // End of CMidi.hpp