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/driver.h"
00026
00027 namespace jdkmidi
00028 {
00029
00030
00031 MIDIDriver::MIDIDriver( int queue_size )
00032 :
00033 in_queue(queue_size),
00034 out_queue(queue_size),
00035 in_proc(0),
00036 out_proc(0),
00037 thru_proc(0),
00038 thru_enable(false),
00039 tick_proc(0)
00040 {
00041
00042 }
00043
00044 MIDIDriver::~MIDIDriver()
00045 {
00046
00047 }
00048
00049 void MIDIDriver::Reset()
00050 {
00051 in_queue.Clear();
00052 out_queue.Clear();
00053 out_matrix.Clear();
00054 }
00055
00056 void MIDIDriver::AllNotesOff( int chan )
00057 {
00058 MIDITimedBigMessage msg;
00059
00060
00061
00062 if( out_matrix.GetChannelCount(chan)>0 )
00063 {
00064 for( int note=0; note<128; ++note )
00065 {
00066 while( out_matrix.GetNoteCount(chan,note)>0 )
00067 {
00068
00069 msg.SetNoteOn( (unsigned char)chan,
00070 (unsigned char)note, 0 );
00071
00072 OutputMessage( msg );
00073 }
00074 }
00075 }
00076
00077 msg.SetControlChange(chan,C_DAMPER,0 );
00078 OutputMessage( msg );
00079
00080 msg.SetAllNotesOff( (unsigned char)chan );
00081 OutputMessage( msg );
00082
00083 }
00084
00085 void MIDIDriver::AllNotesOff()
00086 {
00087 for( int i=0; i<16; ++i )
00088 {
00089 AllNotesOff(i);
00090 }
00091 }
00092
00093 bool MIDIDriver::HardwareMsgIn( MIDITimedBigMessage &msg )
00094 {
00095
00096
00097 if( in_proc )
00098 {
00099 if( in_proc->Process( &msg )==false )
00100 {
00101
00102 return true;
00103 }
00104 }
00105
00106
00107
00108 if( in_queue.CanPut() )
00109 {
00110 in_queue.Put( msg );
00111 }
00112 else
00113 {
00114 return false;
00115 }
00116
00117
00118
00119
00120 if( thru_proc )
00121 {
00122 if( thru_proc->Process( &msg )==false )
00123 {
00124
00125 return true;
00126 }
00127 }
00128
00129
00130 if( thru_enable )
00131 {
00132
00133
00134
00135 if( out_queue.CanPut() )
00136 {
00137 out_queue.Put( msg );
00138 }
00139 else
00140 {
00141 return false;
00142 }
00143 }
00144
00145 return true;
00146 }
00147
00148 void MIDIDriver::TimeTick( unsigned long sys_time )
00149 {
00150
00151 if( tick_proc )
00152 {
00153 tick_proc->TimeTick( sys_time );
00154 }
00155
00156
00157
00158
00159 while( out_queue.CanGet() )
00160 {
00161
00162
00163
00164 if( HardwareMsgOut( *(out_queue.Peek() ) )==true )
00165 {
00166
00167 out_queue.Next();
00168 }
00169 else
00170 {
00171
00172 break;
00173 }
00174
00175 }
00176
00177 }
00178
00179 }