Wwise 版本

include/AK/SoundEngine/Common/AkMidiTypes.h

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright (c) 2006 Audiokinetic Inc. / All Rights Reserved
00004 //
00006 
00007 // AkMidiTypes.h
00008 
00011 
00012 #ifndef _AK_MIDI_TYPES_H_
00013 #define _AK_MIDI_TYPES_H_
00014 
00015 // Include standard types
00016 #include <AK/SoundEngine/Common/AkTypes.h>
00017 
00018 //-----------------------------------------------------------------------------
00019 // Types.
00020 //-----------------------------------------------------------------------------
00021 
00022 typedef AkUInt8         AkMidiChannelNo;            
00023 typedef AkUInt8         AkMidiNoteNo;               
00024 
00025 
00026 //-----------------------------------------------------------------------------
00027 // Constants.
00028 //-----------------------------------------------------------------------------
00029 
00030 // Invalid values
00031 static const AkMidiChannelNo            AK_INVALID_MIDI_CHANNEL             =  (AkMidiChannelNo)-1;     
00032 static const AkMidiNoteNo               AK_INVALID_MIDI_NOTE                =  (AkUInt8)-1;             
00033 
00034 // List of event types
00035 #define AK_MIDI_EVENT_TYPE_INVALID                  0x00
00036 #define AK_MIDI_EVENT_TYPE_NOTE_OFF                 0x80
00037 #define AK_MIDI_EVENT_TYPE_NOTE_ON                  0x90
00038 #define AK_MIDI_EVENT_TYPE_NOTE_AFTERTOUCH          0xa0
00039 #define AK_MIDI_EVENT_TYPE_CONTROLLER               0xb0
00040 #define AK_MIDI_EVENT_TYPE_PROGRAM_CHANGE           0xc0
00041 #define AK_MIDI_EVENT_TYPE_CHANNEL_AFTERTOUCH       0xd0
00042 #define AK_MIDI_EVENT_TYPE_PITCH_BEND               0xe0
00043 #define AK_MIDI_EVENT_TYPE_SYSEX                    0xf0
00044 #define AK_MIDI_EVENT_TYPE_ESCAPE                   0xf7
00045 #define AK_MIDI_EVENT_TYPE_META                     0xff
00046 
00047 // Macros to convert 32-bit MIDI event to 8-bit components
00048 #define AK_MIDI_EVENT_GET_TYPE( in_dwEvent ) (AkUInt8)((in_dwEvent >> 0) & 0xf0)
00049 #define AK_MIDI_EVENT_GET_CHANNEL( in_dwEvent ) (AkUInt8)((in_dwEvent >> 0) & 0x0f)
00050 #define AK_MIDI_EVENT_GET_PARAM1( in_dwEvent ) (AkUInt8)(in_dwEvent >> 8)
00051 #define AK_MIDI_EVENT_GET_PARAM2( in_dwEvent ) (AkUInt8)(in_dwEvent >> 16)
00052 
00053 // List of Continuous Controller (cc) values
00054 #define AK_MIDI_CC_BANK_SELECT_COARSE       0
00055 #define AK_MIDI_CC_MOD_WHEEL_COARSE         1
00056 #define AK_MIDI_CC_BREATH_CTRL_COARSE       2
00057 #define AK_MIDI_CC_CTRL_3_COARSE            3
00058 #define AK_MIDI_CC_FOOT_PEDAL_COARSE        4
00059 #define AK_MIDI_CC_PORTAMENTO_COARSE        5
00060 #define AK_MIDI_CC_DATA_ENTRY_COARSE        6
00061 #define AK_MIDI_CC_VOLUME_COARSE            7
00062 #define AK_MIDI_CC_BALANCE_COARSE           8
00063 #define AK_MIDI_CC_CTRL_9_COARSE            9
00064 #define AK_MIDI_CC_PAN_POSITION_COARSE      10
00065 #define AK_MIDI_CC_EXPRESSION_COARSE        11
00066 #define AK_MIDI_CC_EFFECT_CTRL_1_COARSE     12
00067 #define AK_MIDI_CC_EFFECT_CTRL_2_COARSE     13
00068 #define AK_MIDI_CC_CTRL_14_COARSE           14
00069 #define AK_MIDI_CC_CTRL_15_COARSE           15
00070 #define AK_MIDI_CC_GEN_SLIDER_1             16
00071 #define AK_MIDI_CC_GEN_SLIDER_2             17
00072 #define AK_MIDI_CC_GEN_SLIDER_3             18
00073 #define AK_MIDI_CC_GEN_SLIDER_4             19
00074 #define AK_MIDI_CC_CTRL_20_COARSE           20
00075 #define AK_MIDI_CC_CTRL_21_COARSE           21
00076 #define AK_MIDI_CC_CTRL_22_COARSE           22
00077 #define AK_MIDI_CC_CTRL_23_COARSE           23
00078 #define AK_MIDI_CC_CTRL_24_COARSE           24
00079 #define AK_MIDI_CC_CTRL_25_COARSE           25
00080 #define AK_MIDI_CC_CTRL_26_COARSE           26
00081 #define AK_MIDI_CC_CTRL_27_COARSE           27
00082 #define AK_MIDI_CC_CTRL_28_COARSE           28
00083 #define AK_MIDI_CC_CTRL_29_COARSE           29
00084 #define AK_MIDI_CC_CTRL_30_COARSE           30
00085 #define AK_MIDI_CC_CTRL_31_COARSE           31
00086 #define AK_MIDI_CC_BANK_SELECT_FINE         32
00087 #define AK_MIDI_CC_MOD_WHEEL_FINE           33
00088 #define AK_MIDI_CC_BREATH_CTRL_FINE         34
00089 #define AK_MIDI_CC_CTRL_3_FINE              35
00090 #define AK_MIDI_CC_FOOT_PEDAL_FINE          36
00091 #define AK_MIDI_CC_PORTAMENTO_FINE          37
00092 #define AK_MIDI_CC_DATA_ENTRY_FINE          38
00093 #define AK_MIDI_CC_VOLUME_FINE              39
00094 #define AK_MIDI_CC_BALANCE_FINE             40
00095 #define AK_MIDI_CC_CTRL_9_FINE              41
00096 #define AK_MIDI_CC_PAN_POSITION_FINE        42
00097 #define AK_MIDI_CC_EXPRESSION_FINE          43
00098 #define AK_MIDI_CC_EFFECT_CTRL_1_FINE       44
00099 #define AK_MIDI_CC_EFFECT_CTRL_2_FINE       45
00100 #define AK_MIDI_CC_CTRL_14_FINE             46
00101 #define AK_MIDI_CC_CTRL_15_FINE             47
00102 
00103 #define AK_MIDI_CC_CTRL_20_FINE             52
00104 #define AK_MIDI_CC_CTRL_21_FINE             53
00105 #define AK_MIDI_CC_CTRL_22_FINE             54
00106 #define AK_MIDI_CC_CTRL_23_FINE             55
00107 #define AK_MIDI_CC_CTRL_24_FINE             56
00108 #define AK_MIDI_CC_CTRL_25_FINE             57
00109 #define AK_MIDI_CC_CTRL_26_FINE             58
00110 #define AK_MIDI_CC_CTRL_27_FINE             59
00111 #define AK_MIDI_CC_CTRL_28_FINE             60
00112 #define AK_MIDI_CC_CTRL_29_FINE             61
00113 #define AK_MIDI_CC_CTRL_30_FINE             62
00114 #define AK_MIDI_CC_CTRL_31_FINE             63
00115 
00116 #define AK_MIDI_CC_HOLD_PEDAL               64
00117 #define AK_MIDI_CC_PORTAMENTO_ON_OFF        65
00118 #define AK_MIDI_CC_SUSTENUTO_PEDAL          66
00119 #define AK_MIDI_CC_SOFT_PEDAL               67
00120 #define AK_MIDI_CC_LEGATO_PEDAL             68
00121 #define AK_MIDI_CC_HOLD_PEDAL_2             69
00122 
00123 #define AK_MIDI_CC_SOUND_VARIATION          70
00124 #define AK_MIDI_CC_SOUND_TIMBRE             71
00125 #define AK_MIDI_CC_SOUND_RELEASE_TIME       72
00126 #define AK_MIDI_CC_SOUND_ATTACK_TIME        73
00127 #define AK_MIDI_CC_SOUND_BRIGHTNESS         74
00128 #define AK_MIDI_CC_SOUND_CTRL_6             75
00129 #define AK_MIDI_CC_SOUND_CTRL_7             76
00130 #define AK_MIDI_CC_SOUND_CTRL_8             77
00131 #define AK_MIDI_CC_SOUND_CTRL_9             78
00132 #define AK_MIDI_CC_SOUND_CTRL_10            79
00133 
00134 #define AK_MIDI_CC_GENERAL_BUTTON_1         80
00135 #define AK_MIDI_CC_GENERAL_BUTTON_2         81
00136 #define AK_MIDI_CC_GENERAL_BUTTON_3         82
00137 #define AK_MIDI_CC_GENERAL_BUTTON_4         83
00138 
00139 #define AK_MIDI_CC_REVERB_LEVEL             91
00140 #define AK_MIDI_CC_TREMOLO_LEVEL            92
00141 #define AK_MIDI_CC_CHORUS_LEVEL             93
00142 #define AK_MIDI_CC_CELESTE_LEVEL            94
00143 #define AK_MIDI_CC_PHASER_LEVEL             95
00144 #define AK_MIDI_CC_DATA_BUTTON_P1           96
00145 #define AK_MIDI_CC_DATA_BUTTON_M1           97
00146 
00147 #define AK_MIDI_CC_NON_REGISTER_COARSE      98
00148 #define AK_MIDI_CC_NON_REGISTER_FINE        99
00149 
00150 #define AK_MIDI_CC_ALL_SOUND_OFF            120
00151 #define AK_MIDI_CC_ALL_CONTROLLERS_OFF      121
00152 #define AK_MIDI_CC_LOCAL_KEYBOARD           122
00153 #define AK_MIDI_CC_ALL_NOTES_OFF            123
00154 #define AK_MIDI_CC_OMNI_MODE_OFF            124
00155 #define AK_MIDI_CC_OMNI_MODE_ON             125
00156 #define AK_MIDI_CC_OMNI_MONOPHONIC_ON       126
00157 #define AK_MIDI_CC_OMNI_POLYPHONIC_ON       127
00158 
00159 
00160 
00161 struct AkMidiNoteChannelPair
00162 {
00163     AkMidiNoteChannelPair(): note(AK_INVALID_MIDI_NOTE), channel(AK_INVALID_MIDI_CHANNEL) {}
00164 
00165     bool operator == ( const AkMidiNoteChannelPair& in_rhs ) const { return note == in_rhs.note && channel == in_rhs.channel; }
00166     bool operator < ( const AkMidiNoteChannelPair& in_rhs ) const { return channel < in_rhs.channel || (channel == in_rhs.channel && note < in_rhs.note ); }
00167     bool operator > ( const AkMidiNoteChannelPair& in_rhs ) const { return channel > in_rhs.channel || (channel == in_rhs.channel && note > in_rhs.note ); }
00168 
00169     bool IsChannelValid() const { return channel != AK_INVALID_MIDI_CHANNEL; }
00170     bool IsNoteValid() const    { return note != AK_INVALID_MIDI_NOTE; }
00171 
00172     AkMidiNoteNo        note;
00173     AkMidiChannelNo     channel;
00174 };
00175 
00176 struct AkMidiEvent
00177 {
00178     inline AkMidiEvent()
00179         : byType( AK_MIDI_EVENT_TYPE_INVALID )
00180         , byChan( AK_INVALID_MIDI_CHANNEL )
00181     {}
00182 
00183     inline bool IsValid() const { return byType != AK_MIDI_EVENT_TYPE_INVALID; }
00184     inline void MakeInvalid()   { *this = AkMidiEvent(); }
00185 
00186     inline bool IsTypeOk() const { return ( (byType & 0x80) == 0x80 ) && ( (byType & 0xf0) != 0xf0 ); }
00187 
00188     inline bool IsSameChannel ( const AkMidiEvent& in_other ) const 
00189     {
00190         return byChan == in_other.byChan; 
00191     }
00192 
00193     inline bool IsNoteEvent () const
00194     {
00195         return byType == AK_MIDI_EVENT_TYPE_NOTE_ON ||
00196             byType == AK_MIDI_EVENT_TYPE_NOTE_OFF ||
00197             byType == AK_MIDI_EVENT_TYPE_NOTE_AFTERTOUCH;
00198     }
00199 
00200     inline bool IsCcEvent() const
00201     {
00202         return byType == AK_MIDI_EVENT_TYPE_CONTROLLER;
00203     }
00204 
00205     inline bool IsSameCc( const AkMidiEvent& in_other ) const
00206     { 
00207         return IsCcEvent() && in_other.IsCcEvent() && 
00208             Cc.byCc == in_other.Cc.byCc; 
00209     }
00210 
00211     inline bool IsSameNote ( const AkMidiEvent& in_other ) const
00212     { 
00213         return IsNoteEvent() && in_other.IsNoteEvent() && 
00214             NoteOnOff.byNote == in_other.NoteOnOff.byNote; 
00215     }
00216 
00217     inline bool IsSameChannelAndNote ( const AkMidiEvent& in_other ) const
00218     {
00219         return IsSameChannel( in_other ) && IsSameNote( in_other );
00220     }
00221 
00222     inline bool IsNoteOn() const
00223     {
00224         return ( byType == AK_MIDI_EVENT_TYPE_NOTE_ON && NoteOnOff.byVelocity > 0 );
00225     }
00226 
00227     inline bool IsNoteOff() const
00228     {
00229         return byType == AK_MIDI_EVENT_TYPE_NOTE_OFF || 
00230             (byType == AK_MIDI_EVENT_TYPE_NOTE_ON && NoteOnOff.byVelocity == 0 );
00231     }
00232 
00233     inline bool IsNoteOnOff() const
00234     {
00235         return IsNoteOn() || IsNoteOff();
00236     }
00237 
00238     bool IsPitchBend() const
00239     {
00240         return byType == AK_MIDI_EVENT_TYPE_PITCH_BEND;
00241     }
00242 
00243     inline AkMidiNoteChannelPair GetNoteAndChannel() const
00244     {
00245         AkMidiNoteChannelPair noteAndCh;
00246         noteAndCh.channel = byChan;
00247         noteAndCh.note =  IsNoteEvent() ? NoteOnOff.byNote : AK_INVALID_MIDI_NOTE;
00248         return noteAndCh;
00249     }
00250 
00251     inline void MakeSustainPedalOff( AkUInt32 in_uChan )
00252     {
00253         byType = AK_MIDI_EVENT_TYPE_CONTROLLER;
00254         byChan = (AkUInt8)in_uChan;
00255         Cc.byCc = AK_MIDI_CC_HOLD_PEDAL;
00256         Cc.byValue = 0;
00257     }
00258 
00259     inline void MakeNoteOn()
00260     {
00261         byType = AK_MIDI_EVENT_TYPE_NOTE_ON;
00262         NoteOnOff.byVelocity = 0;
00263     }
00264 
00265     inline void MakeNoteOff()
00266     {
00267         byType = AK_MIDI_EVENT_TYPE_NOTE_OFF;
00268         NoteOnOff.byVelocity = 0;
00269     }
00270 
00271     inline void SetNoteNumber( const AkMidiNoteNo in_note )
00272     {
00273         AKASSERT( IsNoteOnOff() );
00274         NoteOnOff.byNote = in_note;
00275     }
00276 
00277     inline AkMidiNoteNo GetNoteNumber() const
00278     {
00279         AKASSERT( IsNoteOnOff() );
00280         return (AkMidiNoteNo)NoteOnOff.byNote;
00281     }
00282 
00283     AkUInt8         byType;     // (Ak_MIDI_EVENT_TYPE_)
00284     AkMidiChannelNo byChan;
00285 
00286     struct tGen
00287     {
00288         AkUInt8     byParam1;
00289         AkUInt8     byParam2;
00290     };
00291     struct tNoteOnOff
00292     {
00293         AkMidiNoteNo    byNote;
00294         AkUInt8         byVelocity;
00295     };
00296     struct tCc
00297     {
00298         AkUInt8     byCc;
00299         AkUInt8     byValue;
00300     };
00301     struct tPitchBend
00302     {
00303         AkUInt8     byValueLsb;
00304         AkUInt8     byValueMsb;
00305     };
00306     struct tNoteAftertouch
00307     {
00308         AkUInt8     byNote;
00309         AkUInt8     byValue;
00310     };
00311     struct tChanAftertouch
00312     {
00313         AkUInt8     byValue;
00314     };
00315     struct tProgramChange
00316     {
00317         AkUInt8     byProgramNum;
00318     };
00319 
00320     union
00321     {
00322         tGen Gen;
00323         tCc Cc;
00324         tNoteOnOff NoteOnOff;
00325         tPitchBend PitchBend;
00326         tNoteAftertouch NoteAftertouch;
00327         tChanAftertouch ChanAftertouch;
00328         tProgramChange ProgramChange;
00329     };
00330 };
00331 
00332 #endif  //_AK_MIDI_TYPES_H_