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/filereadmultitrack.h"
00038
00039 namespace jdkmidi
00040 {
00041
00042
00043 MIDIFileReadMultiTrack::MIDIFileReadMultiTrack( MIDIMultiTrack *mlttrk )
00044 : multitrack( mlttrk ), cur_track(-1)
00045 {
00046
00047 }
00048
00049 MIDIFileReadMultiTrack::~MIDIFileReadMultiTrack()
00050 {
00051
00052 }
00053
00054 void MIDIFileReadMultiTrack::mf_error( char * )
00055 {
00056 }
00057
00058
00059
00060 void MIDIFileReadMultiTrack::mf_starttrack( int trk )
00061 {
00062 cur_track = trk;
00063 }
00064
00065
00066 void MIDIFileReadMultiTrack::mf_endtrack( int trk )
00067 {
00068 cur_track = -1;
00069 }
00070
00071 void MIDIFileReadMultiTrack::AddEventToMultiTrack(
00072 const MIDITimedMessage &msg,
00073 MIDISystemExclusive *sysex,
00074 int dest_track
00075 )
00076 {
00077 if( dest_track!=-1 && dest_track<multitrack->GetNumTracks() )
00078 {
00079 MIDITrack *t = multitrack->GetTrack( dest_track );
00080
00081 if( t )
00082 {
00083 t->PutEvent( msg, sysex );
00084 }
00085 }
00086 }
00087
00088
00089 void MIDIFileReadMultiTrack::mf_header(
00090 int the_format_,
00091 int ntrks_,
00092 int division_
00093 )
00094 {
00095 the_format = the_format_;
00096 num_tracks = ntrks_;
00097 division = division_;
00098
00099 multitrack->SetClksPerBeat( division );
00100
00101 }
00102
00103
00104 void MIDIFileReadMultiTrack::ChanMessage( const MIDITimedMessage &msg )
00105 {
00106 if( the_format == 0 || cur_track==0 )
00107 {
00108
00109
00110
00111 AddEventToMultiTrack( msg, 0, msg.GetChannel()+1 );
00112 }
00113 else
00114 {
00115 AddEventToMultiTrack( msg, 0, cur_track );
00116 }
00117 }
00118
00119
00120
00121
00122 void MIDIFileReadMultiTrack::mf_sysex( MIDIClockTime time, const MIDISystemExclusive &ex )
00123 {
00124 MIDITimedMessage msg;
00125
00126 msg.SetSysEx();
00127 msg.SetTime(time);
00128
00129 MIDISystemExclusive *sysex = new MIDISystemExclusive( ex );
00130
00131 AddEventToMultiTrack( msg, sysex, cur_track );
00132 }
00133
00134
00135
00136 void MIDIFileReadMultiTrack::mf_arbitrary( MIDIClockTime time, int len, unsigned char *data )
00137 {
00138
00139 }
00140
00141
00142 void MIDIFileReadMultiTrack::mf_metamisc( MIDIClockTime time, int, int, unsigned char * )
00143 {
00144
00145 }
00146
00147
00148 void MIDIFileReadMultiTrack::mf_seqnum( MIDIClockTime time, int )
00149 {
00150
00151 }
00152
00153
00154 void MIDIFileReadMultiTrack::mf_smpte( MIDIClockTime time, int, int, int, int, int )
00155 {
00156
00157 }
00158
00159
00160 void MIDIFileReadMultiTrack::mf_timesig(
00161 MIDIClockTime time,
00162 int num,
00163 int denom_power,
00164 int clks_per_metro,
00165 int notated_32nd_per_quarter
00166 )
00167 {
00168 MIDITimedMessage msg;
00169
00170 int denom= 1<<denom_power;
00171
00172 msg.SetTimeSig( (unsigned char)num, (unsigned char)denom );
00173 msg.SetTime( time );
00174
00175 MIDISystemExclusive *sysex = new MIDISystemExclusive( 4 );
00176
00177 sysex->PutByte( (unsigned char)num );
00178 sysex->PutByte( (unsigned char)denom_power );
00179 sysex->PutByte( (unsigned char)clks_per_metro );
00180 sysex->PutByte( (unsigned char)notated_32nd_per_quarter );
00181
00182 AddEventToMultiTrack( msg, sysex, cur_track );
00183 }
00184
00185
00186 void MIDIFileReadMultiTrack::mf_tempo( MIDIClockTime time, unsigned long tempo )
00187 {
00188 unsigned long tempo_bpm_times_32;
00189
00190 if( tempo==0 )
00191 tempo=1;
00192
00193
00194
00195
00196
00197 float beats_per_second = 1e6
00198 / (double)tempo;
00199
00200 float beats_per_minute = beats_per_second * 60;
00201
00202 tempo_bpm_times_32 = (unsigned long) (beats_per_minute * 32.0);
00203
00204 MIDITimedMessage msg;
00205
00206 msg.SetTempo32( tempo_bpm_times_32 );
00207 msg.SetTime( time );
00208
00209 AddEventToMultiTrack( msg, 0, cur_track );
00210 }
00211
00212
00213 void MIDIFileReadMultiTrack::mf_keysig(MIDIClockTime time, int c, int v )
00214 {
00215 MIDITimedMessage msg;
00216
00217 msg.SetKeySig( (unsigned char)c, (unsigned char)v );
00218 msg.SetTime( time );
00219
00220 AddEventToMultiTrack( msg, 0, cur_track );
00221 }
00222
00223
00224 void MIDIFileReadMultiTrack::mf_sqspecific( MIDIClockTime time, int, unsigned char * )
00225 {
00226
00227 }
00228
00229
00230 void MIDIFileReadMultiTrack::mf_text( MIDIClockTime time, int type, int len, unsigned char *s )
00231 {
00232 MIDITimedMessage msg;
00233
00234 msg.SetStatus( META_EVENT );
00235 msg.SetMetaType( (uchar)type );
00236 msg.SetTime( time );
00237
00238 MIDISystemExclusive *sysex = new MIDISystemExclusive(len);
00239
00240 for( int i=0; i<len; ++i )
00241 {
00242 sysex->PutSysByte( s[i] );
00243 }
00244
00245 AddEventToMultiTrack( msg, sysex, cur_track );
00246 }
00247
00248
00249 void MIDIFileReadMultiTrack::mf_eot( MIDIClockTime time )
00250 {
00251 MIDITimedMessage msg;
00252
00253 msg.SetStatus( META_EVENT );
00254 msg.SetMetaType( META_END_OF_TRACK );
00255 msg.SetTime( time );
00256
00257 AddEventToMultiTrack( msg, 0, cur_track );
00258 }
00259
00260
00261
00262 }