00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "jdkmidi/world.h"
00036
00037 #include "jdkmidi/matrix.h"
00038
00039 #ifndef DEBUG_MDMATRIX
00040 # define DEBUG_MDMATRIX 0
00041 #endif
00042
00043 #if DEBUG_MDMATRIX
00044 # undef DBG
00045 # define DBG(a) a
00046 #endif
00047
00048
00049 namespace jdkmidi
00050 {
00051
00052
00053 MIDIMatrix::MIDIMatrix()
00054 {
00055 ENTER("MIDIMatrix::MIDIMatrix()");
00056
00057 for( int channel=0; channel<16; channel++ )
00058 {
00059 channel_count[channel]=0;
00060 hold_pedal[channel]= false;
00061 for( unsigned char note=0; note<128; note++ )
00062 note_on_count[channel][note]=0;
00063 }
00064
00065 total_count=0;
00066 }
00067
00068 MIDIMatrix::~MIDIMatrix()
00069 {
00070 ENTER("MIDIMatrix::~MIDIMatrix()");
00071 }
00072
00073
00074 void MIDIMatrix::DecNoteCount( const MIDIMessage &, int channel, int note )
00075 {
00076 ENTER( "MIDIMatrix::DecNoteCount()" );
00077
00078 if( note_on_count[channel][note]>0 )
00079 {
00080 --note_on_count[channel][note];
00081 --channel_count[channel];
00082 --total_count;
00083 }
00084 }
00085
00086 void MIDIMatrix::IncNoteCount( const MIDIMessage &, int channel, int note )
00087 {
00088 ENTER( "MIDIMatrix::IncNoteCount()" );
00089
00090 ++note_on_count[channel][note];
00091 ++channel_count[channel];
00092 ++total_count;
00093 }
00094
00095 void MIDIMatrix::OtherMessage( const MIDIMessage & )
00096 {
00097 ENTER( "MIDIMatrix::OtherMessage()" );
00098
00099 }
00100
00101
00102 bool MIDIMatrix::Process( const MIDIMessage &m )
00103 {
00104 ENTER( "MIDIMatrix::Process()" );
00105
00106 bool status=false;
00107
00108 if( m.IsChannelMsg() )
00109 {
00110 int channel=m.GetChannel();
00111 int note=m.GetNote();
00112
00113 if( m.IsAllNotesOff() )
00114 {
00115 ClearChannel( channel );
00116 status=true;
00117 }
00118 else
00119 if( m.IsNoteOn() )
00120 {
00121 if( m.GetVelocity()!=0 )
00122 IncNoteCount( m, channel, note );
00123 else
00124 DecNoteCount( m, channel, note );
00125 status=true;
00126 }
00127 else
00128 if( m.IsNoteOff() )
00129 {
00130 DecNoteCount( m, channel, note );
00131 status=true;
00132 }
00133 else
00134 if( m.IsControlChange() && m.GetController()==C_DAMPER )
00135 {
00136 if( m.GetControllerValue() & 0x40 )
00137 {
00138 hold_pedal[channel]=true;
00139 }
00140 else
00141 {
00142 hold_pedal[channel]=false;
00143 }
00144 }
00145 else
00146 OtherMessage( m );
00147 }
00148 return status;
00149 }
00150
00151 void MIDIMatrix::Clear()
00152 {
00153 ENTER( "MIDIMatrix::Clear()" );
00154
00155 for( int channel=0; channel<16; ++channel )
00156 {
00157 ClearChannel( channel );
00158 }
00159 total_count=0;
00160 }
00161
00162 void MIDIMatrix::ClearChannel( int channel )
00163 {
00164 ENTER( "MIDIMatrix::ClearChannel()" );
00165
00166 for( int note=0; note<128; ++note )
00167 {
00168 total_count -= note_on_count[channel][note];
00169 note_on_count[channel][note]=0;
00170 }
00171 channel_count[channel]=0;
00172 hold_pedal[channel]=0;
00173 }
00174
00175
00176
00177 }