#include <track.h>
Public Member Functions | |
| MIDITrack (int size=0) | |
| MIDITrack (const MIDITrack &t) | |
| ~MIDITrack () | |
| void | Clear () |
| void | Shrink () |
| void | ClearAndMerge (const MIDITrack *src1, const MIDITrack *src2) |
| bool | Expand (int increase_amount=(MIDITrackChunkSize)) |
| MIDITimedBigMessage * | GetEventAddress (int event_num) |
| const MIDITimedBigMessage * | GetEventAddress (int event_num) const |
| const MIDITimedBigMessage * | GetEvent (int event_num) const |
| MIDITimedBigMessage * | GetEvent (int event_num) |
| bool | GetEvent (int event_num, MIDITimedBigMessage *msg) const |
| bool | PutEvent (const MIDITimedBigMessage &msg) |
| bool | PutEvent (const MIDITimedMessage &msg, MIDISystemExclusive *sysex) |
| bool | SetEvent (int event_num, const MIDITimedBigMessage &msg) |
| bool | MakeEventNoOp (int event_num) |
| bool | FindEventNumber (MIDIClockTime time, int *event_num) const |
| int | GetBufferSize () const |
| int | GetNumEvents () const |
Private Attributes | |
| MIDITrackChunk * | chunk [MIDIChunksPerTrack] |
| int | buf_size |
| int | num_events |
|
|
Definition at line 66 of file jdkmidi_track.cpp. References buf_size, chunk, Expand(), jdkmidi::MIDIChunksPerTrack, and num_events.
00067 {
00068 buf_size=0;
00069 num_events=0;
00070
00071 for( int i=0; i<MIDIChunksPerTrack; ++i )
00072 chunk[i]=0;
00073
00074 if( size )
00075 {
00076 Expand( size );
00077 }
00078
00079 }
|
|
|
Definition at line 81 of file jdkmidi_track.cpp. References buf_size, GetEventAddress(), GetNumEvents(), num_events, and PutEvent().
00082 {
00083 buf_size=0;
00084 num_events=0;
00085
00086
00087 for( int i=0; i<t.GetNumEvents(); ++i )
00088 {
00089 const MIDITimedBigMessage *src;
00090 src = t.GetEventAddress( i );
00091 PutEvent(*src);
00092 }
00093 }
|
|
|
Definition at line 95 of file jdkmidi_track.cpp. References buf_size, chunk, and jdkmidi::MIDITrackChunkSize.
00096 {
00097 for( int i=0; i<buf_size/MIDITrackChunkSize; ++i )
00098 delete chunk[i];
00099 }
|
|
|
Definition at line 101 of file jdkmidi_track.cpp. References num_events.
00102 {
00103 num_events = 0;
00104 }
|
|
||||||||||||
|
Definition at line 107 of file jdkmidi_track.cpp. References Clear(), GetEventAddress(), GetNumEvents(), jdkmidi::MIDITimedBigMessage::GetTime(), jdkmidi::MIDIMessage::IsDataEnd(), jdkmidi::MIDIMessage::IsNoOp(), jdkmidi::MIDIClockTime, PutEvent(), jdkmidi::MIDIMessage::SetDataEnd(), and jdkmidi::MIDITimedBigMessage::SetTime().
00111 {
00112 Clear();
00113
00114 const MIDITimedBigMessage *ev1;
00115 int cur_trk1ev=0;
00116 int num_trk1ev = src1->GetNumEvents();
00117
00118 const MIDITimedBigMessage *ev2;
00119 int cur_trk2ev=0;
00120 int num_trk2ev = src2->GetNumEvents();
00121
00122 MIDIClockTime last_data_end_time=0;
00123
00124 while(
00125 cur_trk1ev<num_trk1ev
00126 || cur_trk2ev<num_trk2ev
00127 )
00128 {
00129 // skip any NOPs on track 1
00130
00131 ev1=src1->GetEventAddress( cur_trk1ev );
00132 ev2=src2->GetEventAddress( cur_trk2ev );
00133
00134 bool has_ev1 = (cur_trk1ev<num_trk1ev) && ev1;
00135 bool has_ev2 = (cur_trk2ev<num_trk2ev) && ev2;
00136
00137 if( has_ev1 && ev1->IsNoOp() )
00138 {
00139 cur_trk1ev++;
00140 continue;
00141 }
00142
00143 // skip any NOPs on track 2
00144
00145 if( has_ev2 && ev2->IsNoOp() )
00146 {
00147 cur_trk2ev++;
00148 continue;
00149 }
00150
00151 // skip all data end
00152
00153 if( has_ev1 && ev1->IsDataEnd() )
00154 {
00155 if( ev1->GetTime() > last_data_end_time )
00156 {
00157 last_data_end_time = ev1->GetTime();
00158 }
00159 cur_trk1ev++;
00160 continue;
00161 }
00162
00163 if( has_ev2 && ev2->IsDataEnd() )
00164 {
00165 if( ev2->GetTime() > last_data_end_time )
00166 {
00167 last_data_end_time = ev2->GetTime();
00168 }
00169 cur_trk2ev++;
00170 continue;
00171 }
00172
00173 if( (has_ev1 && !has_ev2) )
00174 {
00175 // nothing left on trk 2
00176
00177 if( !ev1->IsNoOp())
00178 {
00179 if( ev1->GetTime() > last_data_end_time )
00180 {
00181 last_data_end_time = ev1->GetTime();
00182 }
00183
00184 PutEvent( *ev1 );
00185 ++cur_trk1ev;
00186 }
00187 } else if( (!has_ev1 && has_ev2) )
00188 {
00189 // nothing left on trk 1
00190 if( !ev2->IsNoOp() )
00191 {
00192 PutEvent( *ev2 );
00193 ++cur_trk2ev;
00194 }
00195 } else if( has_ev1 && has_ev2 )
00196 {
00197 int trk=1;
00198
00199 if( (ev1->GetTime() <= ev2->GetTime()) )
00200 {
00201 trk=1;
00202 }
00203 else
00204 {
00205 trk=2;
00206 }
00207
00208 if( trk==1 )
00209 {
00210 if( ev1->GetTime() > last_data_end_time )
00211 {
00212 last_data_end_time = ev1->GetTime();
00213 }
00214
00215 PutEvent( *ev1 );
00216
00217 ++cur_trk1ev;
00218 }
00219 else
00220 {
00221 if( ev2->GetTime() > last_data_end_time )
00222 {
00223 last_data_end_time = ev2->GetTime();
00224 }
00225
00226 PutEvent( *ev2 );
00227 ++cur_trk2ev;
00228 }
00229 }
00230 }
00231
00232 // put single final data end event
00233
00234 MIDITimedBigMessage dataend;
00235
00236 dataend.SetTime( last_data_end_time );
00237 dataend.SetDataEnd();
00238
00239 PutEvent( dataend );
00240 }
|
|
|
Definition at line 365 of file jdkmidi_track.cpp. References buf_size, chunk, jdkmidi::MIDIChunksPerTrack, and jdkmidi::MIDITrackChunkSize.
00366 {
00367 int num_chunks_to_expand = (int)((increase_amount/MIDITrackChunkSize)+1);
00368 int num_chunks_alloced = (int)(buf_size/MIDITrackChunkSize);
00369 int new_last_chunk_num= (int)(num_chunks_to_expand + num_chunks_alloced);
00370
00371 if( new_last_chunk_num >= MIDIChunksPerTrack )
00372 {
00373 return false;
00374 }
00375
00376 for( int i=num_chunks_alloced; i<new_last_chunk_num; ++i )
00377 {
00378 chunk[i]=new MIDITrackChunk;
00379
00380 if( !chunk[i] )
00381 {
00382 buf_size=(i-1)*MIDITrackChunkSize;
00383 return false;
00384 }
00385 }
00386
00387 buf_size=new_last_chunk_num * MIDITrackChunkSize;
00388
00389 return true;
00390 }
|
|
||||||||||||
|
Definition at line 480 of file jdkmidi_track.cpp. References ENTER, GetEventAddress(), jdkmidi::MIDITimedBigMessage::GetTime(), jdkmidi::MIDIClockTime, and num_events.
00481 {
00482 ENTER("MIDITrack::FindEventNumber( int , int * )");
00483
00484 // TO DO: try make this a binary search
00485
00486 for( int i=0; i<num_events; ++i )
00487 {
00488 const MIDITimedBigMessage *msg = GetEventAddress( i );
00489
00490 if( msg->GetTime()>=time )
00491 {
00492 *event_num=i;
00493 return true;
00494 }
00495 }
00496
00497 *event_num=num_events;
00498 return false;
00499 }
|
|
|
Definition at line 527 of file jdkmidi_track.cpp. References buf_size.
00528 {
00529 return buf_size;
00530 }
|
|
||||||||||||
|
Definition at line 435 of file jdkmidi_track.cpp. References jdkmidi::MIDITimedBigMessage::Copy(), GetEventAddress(), and num_events.
00436 {
00437 if( event_num >= num_events )
00438 {
00439 return false;
00440 }
00441 else
00442 {
00443 msg->Copy( *GetEventAddress( event_num ) );
00444 return true;
00445 }
00446 }
|
|
|
Definition at line 514 of file jdkmidi_track.cpp. References GetEventAddress(), and num_events.
00515 {
00516 if( event_num >= num_events )
00517 {
00518 return 0;
00519 }
00520 else
00521 {
00522 return GetEventAddress( event_num );
00523 }
00524
00525 }
|
|
|
Definition at line 501 of file jdkmidi_track.cpp. References GetEventAddress(), and num_events.
00502 {
00503 if( event_num >= num_events )
00504 {
00505 return 0;
00506 }
00507 else
00508 {
00509 return GetEventAddress( event_num );
00510 }
00511
00512 }
|
|
|
Definition at line 398 of file jdkmidi_track.cpp. References chunk, jdkmidi::MIDITrackChunk::GetEventAddress(), and jdkmidi::MIDITrackChunkSize.
00399 {
00400 return chunk[ event_num/(MIDITrackChunkSize) ]->GetEventAddress(
00401 (event_num%MIDITrackChunkSize) );
00402 }
|
|
|
Definition at line 392 of file jdkmidi_track.cpp. References chunk, jdkmidi::MIDITrackChunk::GetEventAddress(), and jdkmidi::MIDITrackChunkSize.
00393 {
00394 return chunk[ event_num/(MIDITrackChunkSize) ]->GetEventAddress(
00395 (event_num%MIDITrackChunkSize) );
00396 }
|
|
|
Definition at line 532 of file jdkmidi_track.cpp. References num_events.
00533 {
00534 return num_events;
00535 }
|
|
|
Definition at line 461 of file jdkmidi_track.cpp. References jdkmidi::MIDIBigMessage::ClearSysEx(), GetEventAddress(), num_events, and jdkmidi::MIDIMessage::SetNoOp().
00462 {
00463 if( event_num>=num_events )
00464 {
00465 return false;
00466 }
00467 else
00468 {
00469 MIDITimedBigMessage *ev = GetEventAddress( event_num );
00470
00471 if( ev )
00472 {
00473 ev->ClearSysEx();
00474 ev->SetNoOp();
00475 }
00476 return true;
00477 }
00478 }
|
|
||||||||||||
|
Definition at line 417 of file jdkmidi_track.cpp. References buf_size, jdkmidi::MIDITimedBigMessage::Copy(), jdkmidi::MIDIBigMessage::CopySysEx(), Expand(), GetEventAddress(), and num_events.
00418 {
00419 if( num_events >= buf_size )
00420 {
00421 if( !Expand() )
00422 return false;
00423 }
00424
00425 MIDITimedBigMessage *e = GetEventAddress( num_events );
00426
00427 e->Copy( msg );
00428 e->CopySysEx( sysex );
00429
00430 ++num_events;
00431
00432 return true;
00433 }
|
|
|
Definition at line 404 of file jdkmidi_track.cpp. References buf_size, jdkmidi::MIDITimedBigMessage::Copy(), Expand(), GetEventAddress(), and num_events.
00405 {
00406 if( num_events >= buf_size )
00407 {
00408 if( !Expand() )
00409 return false;
00410 }
00411
00412 GetEventAddress( num_events++ )->Copy( msg );
00413
00414 return true;
00415 }
|
|
||||||||||||
|
Definition at line 448 of file jdkmidi_track.cpp. References jdkmidi::MIDITimedBigMessage::Copy(), GetEventAddress(), and num_events.
00449 {
00450 if( event_num>=num_events )
00451 {
00452 return false;
00453 }
00454 else
00455 {
00456 GetEventAddress( event_num )->Copy( msg );
00457 return true;
00458 }
00459 }
|
|
|
Definition at line 349 of file jdkmidi_track.cpp. References buf_size, chunk, jdkmidi::MIDITrackChunkSize, and num_events.
00350 {
00351 int num_chunks_used = (int)((num_events / MIDITrackChunkSize) +1);
00352 int num_chunks_alloced = (int)(buf_size/MIDITrackChunkSize);
00353
00354 if( num_chunks_used < num_chunks_alloced )
00355 {
00356 for( int i=num_chunks_used; i<num_chunks_alloced; ++i )
00357 {
00358 delete(chunk[i]);
00359 chunk[i]=0;
00360 }
00361 buf_size=num_chunks_used * MIDITrackChunkSize;
00362 }
00363 }
|
|
|
|
|
|
|
|
|
|