00001 #include "atrack.h"
00002 #include "automation.h"
00003 #include "cursor.h"
00004 #include "defaults.h"
00005 #include "edit.h"
00006 #include "edits.h"
00007 #include "edl.h"
00008 #include "edlsession.h"
00009 #include "file.h"
00010 #include "filexml.h"
00011 #include "intauto.h"
00012 #include "intautos.h"
00013 #include "localsession.h"
00014 #include "module.h"
00015 #include "panauto.h"
00016 #include "panautos.h"
00017 #include "patchbay.h"
00018 #include "mainsession.h"
00019 #include "theme.h"
00020 #include "track.h"
00021 #include "trackcanvas.h"
00022 #include "tracks.h"
00023 #include "transportque.inc"
00024 #include "vtrack.h"
00025 #include <string.h>
00026
00027 Tracks::Tracks(EDL *edl)
00028 : List<Track>()
00029 {
00030 this->edl = edl;
00031 }
00032
00033 Tracks::Tracks()
00034 : List<Track>()
00035 {
00036 }
00037
00038
00039 Tracks::~Tracks()
00040 {
00041 delete_all_tracks();
00042 }
00043
00044
00045
00046
00047
00048
00049 void Tracks::equivalent_output(Tracks *tracks, double *result)
00050 {
00051 if(total_playable_vtracks() != tracks->total_playable_vtracks())
00052 {
00053 *result = 0;
00054 }
00055 else
00056 {
00057 Track *current = first;
00058 Track *that_current = tracks->first;
00059 while(current || that_current)
00060 {
00061
00062 while(current && current->data_type != TRACK_VIDEO)
00063 current = NEXT;
00064
00065 while(that_current && that_current->data_type != TRACK_VIDEO)
00066 that_current = that_current->next;
00067
00068
00069 if((!current && that_current) ||
00070 (current && !that_current))
00071 {
00072 *result = 0;
00073 break;
00074 }
00075 else
00076
00077 if(current && that_current)
00078 {
00079 current->equivalent_output(that_current, result);
00080 current = NEXT;
00081 that_current = that_current->next;
00082 }
00083 }
00084 }
00085 }
00086
00087
00088
00089
00090 void Tracks::get_affected_edits(ArrayList<Edit*> *drag_edits, double position, Track *start_track)
00091 {
00092 drag_edits->remove_all();
00093
00094 for(Track *track = start_track;
00095 track;
00096 track = track->next)
00097 {
00098
00099 if(track->record)
00100 {
00101 for(Edit *edit = track->edits->first; edit; edit = edit->next)
00102 {
00103 double startproject = track->from_units(edit->startproject);
00104
00105 if(edl->equivalent(startproject, position))
00106 {
00107 drag_edits->append(edit);
00108 break;
00109 }
00110 }
00111 }
00112 }
00113
00114 }
00115
00116 void Tracks::get_automation_extents(float *min,
00117 float *max,
00118 double start,
00119 double end)
00120 {
00121 *min = 0;
00122 *max = 0;
00123 int coords_undefined = 1;
00124 for(Track *current = first; current; current = NEXT)
00125 {
00126 if(current->record)
00127 {
00128 current->automation->get_extents(min,
00129 max,
00130 &coords_undefined,
00131 current->to_units(start, 1),
00132 current->to_units(end, 1));
00133 }
00134 }
00135 }
00136
00137
00138 void Tracks::copy_from(Tracks *tracks)
00139 {
00140 Track *new_track;
00141
00142 delete_all_tracks();
00143 for(Track *current = tracks->first; current; current = NEXT)
00144 {
00145 switch(current->data_type)
00146 {
00147 case TRACK_AUDIO:
00148 new_track = add_audio_track(0, 0);
00149 break;
00150 case TRACK_VIDEO:
00151 new_track = add_video_track(0, 0);
00152 break;
00153 }
00154 new_track->copy_from(current);
00155 }
00156 }
00157
00158 Tracks& Tracks::operator=(Tracks &tracks)
00159 {
00160 printf("Tracks::operator= 1\n");
00161 copy_from(&tracks);
00162 return *this;
00163 }
00164
00165 int Tracks::load(FileXML *xml, int &track_offset, uint32_t load_flags)
00166 {
00167
00168 char string[BCTEXTLEN];
00169 Track *track = 0;
00170 sprintf(string, "");
00171
00172 xml->tag.get_property("TYPE", string);
00173
00174 if((load_flags & LOAD_ALL) == LOAD_ALL ||
00175 (load_flags & LOAD_EDITS))
00176 {
00177 if(!strcmp(string, "VIDEO"))
00178 {
00179 add_video_track(0, 0);
00180 }
00181 else
00182 {
00183 add_audio_track(0, 0);
00184 }
00185 track = last;
00186 }
00187 else
00188 {
00189 track = get_item_number(track_offset);
00190 track_offset++;
00191 }
00192
00193
00194 if(track) track->load(xml, track_offset, load_flags);
00195
00196 return 0;
00197 }
00198
00199 Track* Tracks::add_audio_track(int above, Track *dst_track)
00200 {
00201 int pixel;
00202 ATrack* new_track = new ATrack(edl, this);
00203 if(!dst_track)
00204 {
00205 dst_track = (above ? first : last);
00206 }
00207
00208 if(above)
00209 {
00210 insert_before(dst_track, (Track*)new_track);
00211 }
00212 else
00213 {
00214 insert_after(dst_track, (Track*)new_track);
00215
00216 }
00217
00218
00219 for(Track *track = last;
00220 track && track != new_track;
00221 track = track->previous)
00222 {
00223 change_modules(number_of(track) - 1, number_of(track), 0);
00224 }
00225
00226
00227 new_track->create_objects();
00228 new_track->set_default_title();
00229
00230 int current_pan = 0;
00231 for(Track *current = first;
00232 current != (Track*)new_track;
00233 current = NEXT)
00234 {
00235 if(current->data_type == TRACK_AUDIO) current_pan++;
00236 if(current_pan >= edl->session->audio_channels) current_pan = 0;
00237 }
00238
00239
00240
00241 PanAuto* pan_auto =
00242 (PanAuto*)new_track->automation->autos[AUTOMATION_PAN]->default_auto;
00243 pan_auto->values[current_pan] = 1.0;
00244
00245 BC_Pan::calculate_stick_position(edl->session->audio_channels,
00246 edl->session->achannel_positions,
00247 pan_auto->values,
00248 1,
00249 50,
00250 pan_auto->handle_x,
00251 pan_auto->handle_y);
00252 return new_track;
00253 }
00254
00255 Track* Tracks::add_video_track(int above, Track *dst_track)
00256 {
00257 int pixel;
00258 VTrack* new_track = new VTrack(edl, this);
00259 if(!dst_track)
00260 dst_track = (above ? first : last);
00261
00262 if(above)
00263 {
00264 insert_before(dst_track, (Track*)new_track);
00265 }
00266 else
00267 {
00268 insert_after(dst_track, (Track*)new_track);
00269 }
00270
00271
00272
00273
00274 for(Track *track = last;
00275 track && track != new_track;
00276 track = track->previous)
00277 {
00278 change_modules(number_of(track) - 1, number_of(track), 0);
00279 }
00280
00281
00282
00283 new_track->create_objects();
00284 new_track->set_default_title();
00285 return new_track;
00286 }
00287
00288
00289 int Tracks::delete_track(Track *track)
00290 {
00291 if (!track)
00292 return 0;
00293
00294 int old_location = number_of(track);
00295 detach_shared_effects(old_location);
00296
00297
00298 for(Track *current = track;
00299 current;
00300 current = NEXT)
00301 {
00302 change_modules(number_of(current), number_of(current) - 1, 0);
00303 }
00304 if(track) delete track;
00305
00306 return 0;
00307 }
00308
00309 int Tracks::detach_shared_effects(int module)
00310 {
00311 for(Track *current = first; current; current = NEXT)
00312 {
00313 current->detach_shared_effects(module);
00314 }
00315
00316 return 0;
00317 }
00318
00319 int Tracks::total_of(int type)
00320 {
00321 int result = 0;
00322 IntAuto *mute_keyframe = 0;
00323
00324 for(Track *current = first; current; current = NEXT)
00325 {
00326 long unit_start = current->to_units(edl->local_session->get_selectionstart(1), 0);
00327 mute_keyframe =
00328 (IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
00329 unit_start,
00330 PLAY_FORWARD,
00331 (Auto* &)mute_keyframe);
00332
00333 result +=
00334 (current->play && type == PLAY) ||
00335 (current->record && type == RECORD) ||
00336 (current->gang && type == GANG) ||
00337 (current->draw && type == DRAW) ||
00338 (mute_keyframe->value && type == MUTE) ||
00339 (current->expand_view && type == EXPAND);
00340 }
00341 return result;
00342 }
00343
00344 int Tracks::recordable_audio_tracks()
00345 {
00346 int result = 0;
00347 for(Track *current = first; current; current = NEXT)
00348 if(current->data_type == TRACK_AUDIO && current->record) result++;
00349 return result;
00350 }
00351
00352 int Tracks::recordable_video_tracks()
00353 {
00354 int result = 0;
00355 for(Track *current = first; current; current = NEXT)
00356 {
00357 if(current->data_type == TRACK_VIDEO && current->record) result++;
00358 }
00359 return result;
00360 }
00361
00362
00363 int Tracks::playable_audio_tracks()
00364 {
00365 int result = 0;
00366
00367 for(Track *current = first; current; current = NEXT)
00368 {
00369 if(current->data_type == TRACK_AUDIO && current->play)
00370 {
00371 result++;
00372 }
00373 }
00374
00375 return result;
00376 }
00377
00378 int Tracks::playable_video_tracks()
00379 {
00380 int result = 0;
00381
00382 for(Track *current = first; current; current = NEXT)
00383 {
00384 if(current->data_type == TRACK_VIDEO && current->play)
00385 {
00386 result++;
00387 }
00388 }
00389 return result;
00390 }
00391
00392 int Tracks::total_audio_tracks()
00393 {
00394 int result = 0;
00395 for(Track *current = first; current; current = NEXT)
00396 if(current->data_type == TRACK_AUDIO) result++;
00397 return result;
00398 }
00399
00400 int Tracks::total_video_tracks()
00401 {
00402 int result = 0;
00403 for(Track *current = first; current; current = NEXT)
00404 if(current->data_type == TRACK_VIDEO) result++;
00405 return result;
00406 }
00407
00408 double Tracks::total_playable_length()
00409 {
00410 double total = 0;
00411 for(Track *current = first; current; current = NEXT)
00412 {
00413 double length = current->get_length();
00414 if(length > total) total = length;
00415 }
00416 return total;
00417 }
00418
00419 double Tracks::total_recordable_length()
00420 {
00421 double total = 0;
00422 for(Track *current = first; current; current = NEXT)
00423 {
00424 if(current->record)
00425 {
00426 double length = current->get_length();
00427 if(length > total) total = length;
00428 }
00429 }
00430 return total;
00431 }
00432
00433 double Tracks::total_length()
00434 {
00435 double total = 0;
00436 for(Track *current = first; current; current = NEXT)
00437 {
00438 if(current->get_length() > total) total = current->get_length();
00439 }
00440 return total;
00441 }
00442
00443 double Tracks::total_video_length()
00444 {
00445 double total = 0;
00446 for(Track *current = first; current; current = NEXT)
00447 {
00448 if(current->data_type == TRACK_VIDEO &&
00449 current->get_length() > total) total = current->get_length();
00450 }
00451 return total;
00452 }
00453
00454
00455 void Tracks::translate_camera(float offset_x, float offset_y)
00456 {
00457 for(Track *current = first; current; current = NEXT)
00458 {
00459 if(current->data_type == TRACK_VIDEO)
00460 {
00461 ((VTrack*)current)->translate(offset_x, offset_y, 1);
00462 }
00463 }
00464 }
00465 void Tracks::translate_projector(float offset_x, float offset_y)
00466 {
00467 for(Track *current = first; current; current = NEXT)
00468 {
00469 if(current->data_type == TRACK_VIDEO)
00470 {
00471 ((VTrack*)current)->translate(offset_x, offset_y, 0);
00472 }
00473 }
00474 }
00475
00476 void Tracks::update_y_pixels(Theme *theme)
00477 {
00478 int y = -edl->local_session->track_start;
00479 for(Track *current = first; current; current = NEXT)
00480 {
00481
00482 current->y_pixel = y;
00483 y += current->vertical_span(theme);
00484 }
00485 }
00486
00487 int Tracks::dump()
00488 {
00489 for(Track* current = first; current; current = NEXT)
00490 {
00491 printf(" Track: %x\n", current);
00492 current->dump();
00493 printf("\n");
00494 }
00495 return 0;
00496 }
00497
00498 void Tracks::select_all(int type,
00499 int value)
00500 {
00501 for(Track* current = first; current; current = NEXT)
00502 {
00503 double position = edl->local_session->get_selectionstart(1);
00504
00505 if(type == PLAY) current->play = value;
00506 if(type == RECORD) current->record = value;
00507 if(type == GANG) current->gang = value;
00508 if(type == DRAW) current->draw = value;
00509
00510 if(type == MUTE)
00511 {
00512 ((IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_auto_for_editing(position))->value = value;
00513 }
00514
00515 if(type == EXPAND) current->expand_view = value;
00516 }
00517 }
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562 int Tracks::popup_transition(int cursor_x, int cursor_y)
00563 {
00564 int result = 0;
00565 for(Track* current = first; current && !result; current = NEXT)
00566 {
00567 result = current->popup_transition(cursor_x, cursor_y);
00568 }
00569 return result;
00570 }
00571
00572
00573 int Tracks::change_channels(int oldchannels, int newchannels)
00574 {
00575 for(Track *current = first; current; current = NEXT)
00576 { current->change_channels(oldchannels, newchannels); }
00577 return 0;
00578 }
00579
00580
00581
00582 int Tracks::totalpixels()
00583 {
00584 int result = 0;
00585 for(Track* current = first; current; current = NEXT)
00586 {
00587 result += edl->local_session->zoom_track;
00588 }
00589 return result;
00590 }
00591
00592 int Tracks::number_of(Track *track)
00593 {
00594 int i = 0;
00595 for(Track *current = first; current && current != track; current = NEXT)
00596 {
00597 i++;
00598 }
00599 return i;
00600 }
00601
00602 Track* Tracks::number(int number)
00603 {
00604 Track *current;
00605 int i = 0;
00606 for(current = first; current && i < number; current = NEXT)
00607 {
00608 i++;
00609 }
00610 return current;
00611 }
00612
00613
00614 int Tracks::total_playable_vtracks()
00615 {
00616 int result = 0;
00617 for(Track *current = first; current; current = NEXT)
00618 {
00619 if(current->data_type == TRACK_VIDEO && current->play) result++;
00620 }
00621 return result;
00622 }