00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "jdkmidi/world.h"
00025 #include "jdkmidi/process.h"
00026
00027 namespace jdkmidi
00028 {
00029
00030
00031 MIDIProcessor::MIDIProcessor()
00032 {
00033 }
00034
00035 MIDIProcessor::~MIDIProcessor()
00036 {
00037 }
00038
00039
00040
00041
00042 MIDIMultiProcessor::MIDIMultiProcessor( int num )
00043 :
00044 processors( new MIDIProcessor *[num] ),
00045 num_processors( num )
00046 {
00047 for( int i=0; i<num_processors; ++i )
00048 {
00049 processors[i] = 0;
00050 }
00051 }
00052
00053 MIDIMultiProcessor::~MIDIMultiProcessor()
00054 {
00055 delete [] processors;
00056 }
00057
00058
00059
00060 bool MIDIMultiProcessor::Process( MIDITimedBigMessage *msg )
00061 {
00062 for( int i=0; i<num_processors; ++i )
00063 {
00064 if( processors[i] )
00065 {
00066 if( processors[i]->Process( msg )==false )
00067 {
00068 return false;
00069 }
00070 }
00071
00072 }
00073
00074 return true;
00075 }
00076
00077
00078
00079
00080
00081 MIDIProcessorTransposer::MIDIProcessorTransposer()
00082 {
00083 for( int i=0; i<16; ++i )
00084 {
00085 trans_amount[i] = 0;
00086 }
00087
00088 }
00089
00090 MIDIProcessorTransposer::~MIDIProcessorTransposer()
00091 {
00092 }
00093
00094
00095 void MIDIProcessorTransposer::SetAllTranspose( int val )
00096 {
00097 for( int chan=0; chan<16; ++chan )
00098 {
00099 trans_amount[chan]=val;
00100 }
00101 }
00102
00103 bool MIDIProcessorTransposer::Process( MIDITimedBigMessage *msg )
00104 {
00105 if( msg->IsChannelMsg() )
00106 {
00107 if( msg->IsNoteOn() || msg->IsNoteOff() || msg->IsPolyPressure() )
00108 {
00109 int trans = trans_amount[ msg->GetChannel() ];
00110
00111 int new_note = ((int)msg->GetNote())+trans;
00112
00113 if( trans>127 || trans<0 )
00114 {
00115
00116 return false;
00117 }
00118 else
00119 {
00120
00121 msg->SetNote( (unsigned char)new_note );
00122 }
00123
00124 }
00125 }
00126
00127 return true;
00128 }
00129
00130
00131
00132
00133
00134 MIDIProcessorRechannelizer::MIDIProcessorRechannelizer()
00135 {
00136 for( int i=0; i<16; ++i )
00137 {
00138 rechan_map[i] = i;
00139 }
00140
00141 }
00142
00143 MIDIProcessorRechannelizer::~MIDIProcessorRechannelizer()
00144 {
00145 }
00146
00147
00148 void MIDIProcessorRechannelizer::SetAllRechan( int dest_chan )
00149 {
00150 for( int i=0; i<16; ++i )
00151 {
00152 rechan_map[i] = dest_chan;
00153 }
00154 }
00155
00156 bool MIDIProcessorRechannelizer::Process( MIDITimedBigMessage *msg )
00157 {
00158 if( msg->IsChannelMsg() )
00159 {
00160 int new_chan = rechan_map[ msg->GetChannel() ];
00161
00162 if( new_chan==-1 )
00163 {
00164
00165 return false;
00166 }
00167
00168 msg->SetChannel( (unsigned char)new_chan );
00169 }
00170
00171 return true;
00172 }
00173
00174
00175
00176
00177
00178 }