00001 #include "asset.h"
00002 #include "assets.h"
00003 #include "atrack.h"
00004 #include "autoconf.h"
00005 #include "automation.h"
00006 #include "awindowgui.inc"
00007 #include "bcsignals.h"
00008 #include "clip.h"
00009 #include "colormodels.h"
00010 #include "bchash.h"
00011 #include "edl.h"
00012 #include "edlsession.h"
00013 #include "filexml.h"
00014 #include "guicast.h"
00015 #include "labels.h"
00016 #include "localsession.h"
00017 #include "mutex.h"
00018 #include "panauto.h"
00019 #include "panautos.h"
00020 #include "playbackconfig.h"
00021 #include "plugin.h"
00022 #include "preferences.h"
00023 #include "recordconfig.h"
00024 #include "recordlabel.h"
00025 #include "sharedlocation.h"
00026 #include "theme.h"
00027 #include "tracks.h"
00028 #include "transportque.inc"
00029 #include "vtrack.h"
00030
00031
00032
00033
00034 Mutex* EDL::id_lock = 0;
00035
00036
00037
00038 EDL::EDL(EDL *parent_edl)
00039 {
00040 this->parent_edl = parent_edl;
00041 tracks = 0;
00042 labels = 0;
00043 local_session = 0;
00044 vwindow_edl = 0;
00045 vwindow_edl_shared = 0;
00046
00047
00048 folders.set_array_delete();
00049
00050 new_folder(CLIP_FOLDER);
00051
00052 new_folder(MEDIA_FOLDER);
00053
00054 id = next_id();
00055 project_path[0] = 0;
00056 }
00057
00058
00059 EDL::~EDL()
00060 {
00061
00062 if(tracks)
00063 {
00064 delete tracks;
00065 }
00066 if(labels)
00067 {
00068 delete labels;
00069 }
00070
00071 if(local_session)
00072 {
00073 delete local_session;
00074 }
00075
00076 if(vwindow_edl && !vwindow_edl_shared)
00077 delete vwindow_edl;
00078
00079 if(!parent_edl)
00080 {
00081 delete assets;
00082 delete session;
00083 }
00084
00085
00086 folders.remove_all_objects();
00087 clips.remove_all_objects();
00088 }
00089
00090
00091 int EDL::create_objects()
00092 {
00093 tracks = new Tracks(this);
00094 if(!parent_edl)
00095 {
00096 assets = new Assets(this);
00097 session = new EDLSession(this);
00098 }
00099 else
00100 {
00101 assets = parent_edl->assets;
00102 session = parent_edl->session;
00103 }
00104
00105 local_session = new LocalSession(this);
00106 labels = new Labels(this, "LABELS");
00107
00108 return 0;
00109 }
00110
00111 EDL& EDL::operator=(EDL &edl)
00112 {
00113 printf("EDL::operator= 1\n");
00114 copy_all(&edl);
00115 return *this;
00116 }
00117
00118 int EDL::load_defaults(BC_Hash *defaults)
00119 {
00120 if(!parent_edl)
00121 session->load_defaults(defaults);
00122
00123 local_session->load_defaults(defaults);
00124 return 0;
00125 }
00126
00127 int EDL::save_defaults(BC_Hash *defaults)
00128 {
00129 if(!parent_edl)
00130 session->save_defaults(defaults);
00131
00132 local_session->save_defaults(defaults);
00133 return 0;
00134 }
00135
00136 void EDL::boundaries()
00137 {
00138 session->boundaries();
00139 local_session->boundaries();
00140 }
00141
00142 int EDL::create_default_tracks()
00143 {
00144
00145 for(int i = 0; i < session->video_tracks; i++)
00146 {
00147 tracks->add_video_track(0, 0);
00148 }
00149 for(int i = 0; i < session->audio_tracks; i++)
00150 {
00151 tracks->add_audio_track(0, 0);
00152 }
00153 return 0;
00154 }
00155
00156 int EDL::load_xml(ArrayList<PluginServer*> *plugindb,
00157 FileXML *file,
00158 uint32_t load_flags)
00159 {
00160 int result = 0;
00161
00162 int track_offset = 0;
00163
00164
00165 folders.remove_all_objects();
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 if(!parent_edl)
00176 {
00177 do{
00178 result = file->read_tag();
00179 }while(!result &&
00180 !file->tag.title_is("XML") &&
00181 !file->tag.title_is("EDL"));
00182 }
00183
00184 if(!result)
00185 {
00186
00187 project_path[0] = 0;
00188 file->tag.get_property("PROJECT_PATH", project_path);
00189
00190
00191 if((load_flags & LOAD_ALL) == LOAD_ALL ||
00192 (load_flags & LOAD_EDITS) == LOAD_EDITS)
00193 {
00194 while(tracks->last) delete tracks->last;
00195 }
00196
00197 if((load_flags & LOAD_ALL) == LOAD_ALL)
00198 {
00199 clips.remove_all_objects();
00200 }
00201
00202 if(load_flags & LOAD_TIMEBAR)
00203 {
00204 while(labels->last) delete labels->last;
00205 local_session->unset_inpoint();
00206 local_session->unset_outpoint();
00207 }
00208
00209 do{
00210 result = file->read_tag();
00211
00212 if(!result)
00213 {
00214 if(file->tag.title_is("/XML") ||
00215 file->tag.title_is("/EDL") ||
00216 file->tag.title_is("/CLIP_EDL") ||
00217 file->tag.title_is("/VWINDOW_EDL"))
00218 {
00219 result = 1;
00220 }
00221 else
00222 if(file->tag.title_is("CLIPBOARD"))
00223 {
00224 local_session->clipboard_length = file->tag.get_property("LENGTH", 0);
00225 }
00226 else
00227 if(file->tag.title_is("VIDEO"))
00228 {
00229 if((load_flags & LOAD_VCONFIG) &&
00230 (load_flags & LOAD_SESSION))
00231 session->load_video_config(file, 0, load_flags);
00232 }
00233 else
00234 if(file->tag.title_is("AUDIO"))
00235 {
00236 if((load_flags & LOAD_ACONFIG) &&
00237 (load_flags & LOAD_SESSION))
00238 session->load_audio_config(file, 0, load_flags);
00239 }
00240 else
00241 if(file->tag.title_is("FOLDER"))
00242 {
00243 char folder[BCTEXTLEN];
00244 strcpy(folder, file->read_text());
00245 new_folder(folder);
00246 }
00247 else
00248 if(file->tag.title_is("ASSETS"))
00249 {
00250 if(load_flags & LOAD_ASSETS)
00251 assets->load(plugindb, file, load_flags);
00252 }
00253 else
00254 if(file->tag.title_is(labels->xml_tag))
00255 {
00256 if(load_flags & LOAD_TIMEBAR)
00257 labels->load(file, load_flags);
00258 }
00259 else
00260 if(file->tag.title_is("LOCALSESSION"))
00261 {
00262 if((load_flags & LOAD_SESSION) ||
00263 (load_flags & LOAD_TIMEBAR))
00264 local_session->load_xml(file, load_flags);
00265 }
00266 else
00267 if(file->tag.title_is("SESSION"))
00268 {
00269 if((load_flags & LOAD_SESSION) &&
00270 !parent_edl)
00271 session->load_xml(file, 0, load_flags);
00272 }
00273 else
00274 if(file->tag.title_is("TRACK"))
00275 {
00276 tracks->load(file, track_offset, load_flags);
00277 }
00278 else
00279
00280
00281 if(file->tag.title_is("CLIP_EDL") && !parent_edl)
00282 {
00283 EDL *new_edl = new EDL(this);
00284 new_edl->create_objects();
00285 new_edl->load_xml(plugindb, file, LOAD_ALL);
00286
00287 if((load_flags & LOAD_ALL) == LOAD_ALL)
00288 clips.append(new_edl);
00289 else
00290 delete new_edl;
00291 }
00292 else
00293 if(file->tag.title_is("VWINDOW_EDL") && !parent_edl)
00294 {
00295 EDL *new_edl = new EDL(this);
00296 new_edl->create_objects();
00297 new_edl->load_xml(plugindb, file, LOAD_ALL);
00298
00299
00300 if((load_flags & LOAD_ALL) == LOAD_ALL)
00301 {
00302 if(vwindow_edl && !vwindow_edl_shared) delete vwindow_edl;
00303 vwindow_edl = new_edl;
00304 vwindow_edl_shared = 0;
00305 }
00306 else
00307 {
00308 delete new_edl;
00309 new_edl = 0;
00310 }
00311 }
00312 }
00313 }while(!result);
00314 }
00315 boundaries();
00316
00317
00318 return 0;
00319 }
00320
00321
00322
00323
00324
00325 int EDL::save_xml(ArrayList<PluginServer*> *plugindb,
00326 FileXML *file,
00327 char *output_path,
00328 int is_clip,
00329 int is_vwindow)
00330 {
00331 copy(0,
00332 tracks->total_length(),
00333 1,
00334 is_clip,
00335 is_vwindow,
00336 file,
00337 plugindb,
00338 output_path,
00339 0);
00340 return 0;
00341 }
00342
00343 int EDL::copy_all(EDL *edl)
00344 {
00345 copy_session(edl);
00346 copy_assets(edl);
00347 copy_clips(edl);
00348 tracks->copy_from(edl->tracks);
00349 labels->copy_from(edl->labels);
00350 return 0;
00351 }
00352
00353 void EDL::copy_clips(EDL *edl)
00354 {
00355 if(vwindow_edl && !vwindow_edl_shared) delete vwindow_edl;
00356 vwindow_edl = 0;
00357 vwindow_edl_shared = 0;
00358 if(edl->vwindow_edl)
00359 {
00360 vwindow_edl = new EDL(this);
00361 vwindow_edl->create_objects();
00362 vwindow_edl->copy_all(edl->vwindow_edl);
00363 }
00364 clips.remove_all_objects();
00365 for(int i = 0; i < edl->clips.total; i++)
00366 {
00367 add_clip(edl->clips.values[i]);
00368 }
00369 }
00370
00371 void EDL::copy_assets(EDL *edl)
00372 {
00373 if(!parent_edl)
00374 {
00375 assets->copy_from(edl->assets);
00376 }
00377 }
00378
00379 void EDL::copy_session(EDL *edl, int session_only)
00380 {
00381 if(!session_only)
00382 {
00383 strcpy(this->project_path, edl->project_path);
00384
00385 folders.remove_all_objects();
00386 for(int i = 0; i < edl->folders.total; i++)
00387 {
00388 char *new_folder;
00389 folders.append(new_folder = new char[strlen(edl->folders.values[i]) + 1]);
00390 strcpy(new_folder, edl->folders.values[i]);
00391 }
00392 }
00393
00394 if(!parent_edl)
00395 {
00396 session->copy(edl->session);
00397 }
00398
00399 if(!session_only)
00400 {
00401 local_session->copy_from(edl->local_session);
00402 }
00403 }
00404
00405 int EDL::copy_assets(double start,
00406 double end,
00407 FileXML *file,
00408 int all,
00409 ArrayList<PluginServer*> *plugindb,
00410 char *output_path)
00411 {
00412 ArrayList<Asset*> asset_list;
00413 Track* current;
00414
00415 file->tag.set_title("ASSETS");
00416 file->append_tag();
00417 file->append_newline();
00418
00419
00420 if(all)
00421 {
00422 for(Asset *asset = assets->first;
00423 asset;
00424 asset = asset->next)
00425 {
00426 asset_list.append(asset);
00427 }
00428 }
00429 else
00430
00431 {
00432 for(current = tracks->first;
00433 current;
00434 current = NEXT)
00435 {
00436 if(current->record)
00437 {
00438 current->copy_assets(start,
00439 end,
00440 &asset_list);
00441 }
00442 }
00443 }
00444
00445
00446 for(int i = 0; i < asset_list.total; i++)
00447 {
00448 asset_list.values[i]->write(file,
00449 0,
00450 output_path);
00451 }
00452
00453 file->tag.set_title("/ASSETS");
00454 file->append_tag();
00455 file->append_newline();
00456 file->append_newline();
00457 return 0;
00458 }
00459
00460 int EDL::copy(double start,
00461 double end,
00462 int all,
00463 int is_clip,
00464 int is_vwindow,
00465 FileXML *file,
00466 ArrayList<PluginServer*> *plugindb,
00467 char *output_path,
00468 int rewind_it)
00469 {
00470
00471
00472 if(is_clip)
00473 file->tag.set_title("CLIP_EDL");
00474 else
00475 if(is_vwindow)
00476 file->tag.set_title("VWINDOW_EDL");
00477 else
00478 {
00479 file->tag.set_title("EDL");
00480 file->tag.set_property("VERSION", CINELERRA_VERSION);
00481
00482 if(this->project_path[0])
00483 {
00484 file->tag.set_property("PROJECT_PATH", project_path);
00485 }
00486 }
00487
00488 file->append_tag();
00489 file->append_newline();
00490
00491
00492 if(!all)
00493 {
00494 file->tag.set_title("CLIPBOARD");
00495 file->tag.set_property("LENGTH", end - start);
00496 file->append_tag();
00497 file->tag.set_title("/CLIPBOARD");
00498 file->append_tag();
00499 file->append_newline();
00500 file->append_newline();
00501 }
00502
00503
00504
00505 local_session->save_xml(file, start);
00506
00507
00508
00509
00510
00511 {
00512
00513
00514 session->save_xml(file);
00515 session->save_video_config(file);
00516 session->save_audio_config(file);
00517
00518
00519 for(int i = 0; i < folders.total; i++)
00520 {
00521 file->tag.set_title("FOLDER");
00522 file->append_tag();
00523 file->append_text(folders.values[i]);
00524 file->tag.set_title("/FOLDER");
00525 file->append_tag();
00526 file->append_newline();
00527 }
00528
00529
00530
00531
00532 if(!is_clip)
00533 copy_assets(start,
00534 end,
00535 file,
00536 all,
00537 plugindb,
00538 output_path);
00539
00540
00541
00542 if(all)
00543 {
00544 if(vwindow_edl)
00545 {
00546
00547 vwindow_edl->save_xml(plugindb,
00548 file,
00549 output_path,
00550 0,
00551 1);
00552 }
00553
00554 for(int i = 0; i < clips.total; i++)
00555 clips.values[i]->save_xml(plugindb,
00556 file,
00557 output_path,
00558 1,
00559 0);
00560 }
00561
00562 file->append_newline();
00563 file->append_newline();
00564 }
00565
00566
00567
00568
00569 labels->copy(start, end, file);
00570
00571 tracks->copy(start, end, all, file, output_path);
00572
00573
00574
00575 if(is_clip)
00576 file->tag.set_title("/CLIP_EDL");
00577 else
00578 if(is_vwindow)
00579 file->tag.set_title("/VWINDOW_EDL");
00580 else
00581 file->tag.set_title("/EDL");
00582 file->append_tag();
00583 file->append_newline();
00584
00585
00586
00587
00588 if(rewind_it)
00589 {
00590 file->terminate_string();
00591 file->rewind();
00592 }
00593 return 0;
00594 }
00595
00596 void EDL::rechannel()
00597 {
00598 for(Track *current = tracks->first; current; current = NEXT)
00599 {
00600 if(current->data_type == TRACK_AUDIO)
00601 {
00602 PanAutos *autos = (PanAutos*)current->automation->autos[AUTOMATION_PAN];
00603 ((PanAuto*)autos->default_auto)->rechannel();
00604 for(PanAuto *keyframe = (PanAuto*)autos->first;
00605 keyframe;
00606 keyframe = (PanAuto*)keyframe->next)
00607 {
00608 keyframe->rechannel();
00609 }
00610 }
00611 }
00612 }
00613
00614 void EDL::resample(double old_rate, double new_rate, int data_type)
00615 {
00616 for(Track *current = tracks->first; current; current = NEXT)
00617 {
00618 if(current->data_type == data_type)
00619 {
00620 current->resample(old_rate, new_rate);
00621 }
00622 }
00623 }
00624
00625
00626 void EDL::synchronize_params(EDL *edl)
00627 {
00628 local_session->synchronize_params(edl->local_session);
00629 for(Track *this_track = tracks->first, *that_track = edl->tracks->first;
00630 this_track && that_track;
00631 this_track = this_track->next,
00632 that_track = that_track->next)
00633 {
00634 this_track->synchronize_params(that_track);
00635 }
00636 }
00637
00638 int EDL::trim_selection(double start,
00639 double end,
00640 int edit_labels,
00641 int edit_plugins)
00642 {
00643 if(start != end)
00644 {
00645
00646 clear(0,
00647 start,
00648 edit_labels,
00649 edit_plugins);
00650 clear(end - start,
00651 tracks->total_length(),
00652 edit_labels,
00653 edit_plugins);
00654 }
00655 return 0;
00656 }
00657
00658
00659 int EDL::equivalent(double position1, double position2)
00660 {
00661 double threshold = (double).5 / session->frame_rate;
00662 if(session->cursor_on_frames)
00663 threshold = (double).5 / session->frame_rate;
00664 else
00665 threshold = (double)1 / session->sample_rate;
00666
00667 if(fabs(position2 - position1) < threshold)
00668 return 1;
00669 else
00670 return 0;
00671 }
00672
00673 double EDL::equivalent_output(EDL *edl)
00674 {
00675 double result = -1;
00676 session->equivalent_output(edl->session, &result);
00677 tracks->equivalent_output(edl->tracks, &result);
00678 return result;
00679 }
00680
00681
00682 void EDL::set_project_path(char *path)
00683 {
00684 strcpy(this->project_path, path);
00685 }
00686
00687 void EDL::set_inpoint(double position)
00688 {
00689 if(equivalent(local_session->get_inpoint(), position) &&
00690 local_session->get_inpoint() >= 0)
00691 {
00692 local_session->unset_inpoint();
00693 }
00694 else
00695 {
00696 local_session->set_inpoint(align_to_frame(position, 0));
00697 if(local_session->get_outpoint() <= local_session->get_inpoint())
00698 local_session->unset_outpoint();
00699 }
00700 }
00701
00702 void EDL::set_outpoint(double position)
00703 {
00704 if(equivalent(local_session->get_outpoint(), position) &&
00705 local_session->get_outpoint() >= 0)
00706 {
00707 local_session->unset_outpoint();
00708 }
00709 else
00710 {
00711 local_session->set_outpoint(align_to_frame(position, 0));
00712 if(local_session->get_inpoint() >= local_session->get_outpoint())
00713 local_session->unset_inpoint();
00714 }
00715 }
00716
00717
00718 int EDL::clear(double start,
00719 double end,
00720 int clear_labels,
00721 int clear_plugins)
00722 {
00723 if(start == end)
00724 {
00725 double distance = 0;
00726 tracks->clear_handle(start,
00727 end,
00728 distance,
00729 clear_labels,
00730 clear_plugins);
00731 if(clear_labels && distance > 0)
00732 labels->paste_silence(start,
00733 start + distance);
00734 }
00735 else
00736 {
00737 tracks->clear(start,
00738 end,
00739 clear_plugins);
00740 if(clear_labels)
00741 labels->clear(start,
00742 end,
00743 1);
00744 }
00745
00746
00747
00748 double position = local_session->get_selectionstart();
00749 local_session->set_selectionend(position);
00750 local_session->set_selectionstart(position);
00751 return 0;
00752 }
00753
00754 void EDL::modify_edithandles(double oldposition,
00755 double newposition,
00756 int currentend,
00757 int handle_mode,
00758 int edit_labels,
00759 int edit_plugins)
00760 {
00761 tracks->modify_edithandles(oldposition,
00762 newposition,
00763 currentend,
00764 handle_mode,
00765 edit_labels,
00766 edit_plugins);
00767 labels->modify_handles(oldposition,
00768 newposition,
00769 currentend,
00770 handle_mode,
00771 edit_labels);
00772 }
00773
00774 void EDL::modify_pluginhandles(double oldposition,
00775 double newposition,
00776 int currentend,
00777 int handle_mode,
00778 int edit_labels,
00779 Edits *trim_edits)
00780 {
00781 tracks->modify_pluginhandles(oldposition,
00782 newposition,
00783 currentend,
00784 handle_mode,
00785 edit_labels,
00786 trim_edits);
00787 optimize();
00788 }
00789
00790 void EDL::paste_silence(double start,
00791 double end,
00792 int edit_labels,
00793 int edit_plugins)
00794 {
00795 if(edit_labels)
00796 labels->paste_silence(start, end);
00797 tracks->paste_silence(start,
00798 end,
00799 edit_plugins);
00800 }
00801
00802
00803 void EDL::remove_from_project(ArrayList<EDL*> *clips)
00804 {
00805 for(int i = 0; i < clips->total; i++)
00806 {
00807 for(int j = 0; j < this->clips.total; j++)
00808 {
00809 if(this->clips.values[j] == clips->values[i])
00810 {
00811 this->clips.remove_object(clips->values[i]);
00812 }
00813 }
00814 }
00815 }
00816
00817 void EDL::remove_from_project(ArrayList<Asset*> *assets)
00818 {
00819
00820 if(!parent_edl)
00821 for(int j = 0; j < clips.total; j++)
00822 {
00823 clips.values[j]->remove_from_project(assets);
00824 }
00825
00826
00827 if(vwindow_edl)
00828 vwindow_edl->remove_from_project(assets);
00829
00830 for(int i = 0; i < assets->total; i++)
00831 {
00832
00833 for(Track *track = tracks->first; track; track = track->next)
00834 {
00835 track->remove_asset(assets->values[i]);
00836 }
00837
00838
00839 if(!parent_edl)
00840 {
00841 this->assets->remove_asset(assets->values[i]);
00842 }
00843 }
00844 }
00845
00846 void EDL::update_assets(EDL *src)
00847 {
00848 for(Asset *current = src->assets->first;
00849 current;
00850 current = NEXT)
00851 {
00852 assets->update(current);
00853 }
00854 }
00855
00856 int EDL::get_tracks_height(Theme *theme)
00857 {
00858 int total_pixels = 0;
00859 for(Track *current = tracks->first;
00860 current;
00861 current = NEXT)
00862 {
00863 total_pixels += current->vertical_span(theme);
00864 }
00865 return total_pixels;
00866 }
00867
00868 int64_t EDL::get_tracks_width()
00869 {
00870 int64_t total_pixels = 0;
00871 for(Track *current = tracks->first;
00872 current;
00873 current = NEXT)
00874 {
00875 int64_t pixels = current->horizontal_span();
00876 if(pixels > total_pixels) total_pixels = pixels;
00877 }
00878
00879 return total_pixels;
00880 }
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
00908 {
00909 w = session->output_w;
00910 h = session->output_h;
00911
00912 if((float)session->output_w / session->output_h > get_aspect_ratio())
00913 {
00914 h = (float)h *
00915 (session->output_w / get_aspect_ratio() / session->output_h);
00916 }
00917 else
00918 {
00919 w = (float)w *
00920 (h * get_aspect_ratio() / session->output_w);
00921 }
00922 }
00923
00924 float EDL::get_aspect_ratio()
00925 {
00926 return session->aspect_w / session->aspect_h;
00927 }
00928
00929 int EDL::dump()
00930 {
00931 if(parent_edl)
00932 printf("CLIP\n");
00933 else
00934 printf("EDL\n");
00935 printf("clip_title: %s parent_edl: %p\n", local_session->clip_title, parent_edl);
00936 printf("selectionstart %f selectionend %f loop_start %f loop_end %f\n",
00937 local_session->get_selectionstart(1),
00938 local_session->get_selectionend(1),
00939 local_session->loop_start,
00940 local_session->loop_end);
00941
00942 if(!parent_edl)
00943 {
00944 printf("audio_channels: %d "
00945 "audio_tracks: %d \n"
00946 "sample_rate: %d\n",
00947 session->audio_channels,
00948 session->audio_tracks,
00949 session->sample_rate);
00950 printf("video_channels: %d "
00951 "video_tracks: %d "
00952 "frame_rate: %.2f "
00953 "frames_per_foot: %.2f\n"
00954 "output_w: %d "
00955 "output_h: %d "
00956 "aspect_w: %f "
00957 "aspect_h %f "
00958 "color_model %d\n",
00959 session->video_channels,
00960 session->video_tracks,
00961 session->frame_rate,
00962 session->frames_per_foot,
00963 session->output_w,
00964 session->output_h,
00965 session->aspect_w,
00966 session->aspect_h,
00967 session->color_model);
00968
00969 printf(" EDLS\n");
00970 printf(" total: %d\n", clips.total);
00971
00972 for(int i = 0; i < clips.total; i++)
00973 {
00974 printf("\n\n");
00975 clips.values[i]->dump();
00976 printf("\n\n");
00977 }
00978
00979 printf(" ASSETS\n");
00980 assets->dump();
00981 }
00982 printf(" LABELS\n");
00983 labels->dump();
00984 printf(" TRACKS\n");
00985 tracks->dump();
00986
00987 return 0;
00988 }
00989
00990 EDL* EDL::add_clip(EDL *edl)
00991 {
00992
00993 EDL *new_edl = new EDL(this);
00994 new_edl->create_objects();
00995 new_edl->copy_all(edl);
00996 clips.append(new_edl);
00997 return new_edl;
00998 }
00999
01000 void EDL::insert_asset(Asset *asset,
01001 double position,
01002 Track *first_track,
01003 RecordLabels *labels)
01004 {
01005
01006 Asset *new_asset = assets->update(asset);
01007
01008
01009
01010 int vtrack = 0;
01011 Track *current = first_track ? first_track : tracks->first;
01012
01013
01014
01015 double length;
01016
01017
01018 if(new_asset->video_length < 0)
01019 {
01020 if(session->si_useduration)
01021 length = session->si_duration;
01022 else
01023 length = 1.0 / session->frame_rate;
01024 }
01025 else
01026 if(new_asset->frame_rate > 0)
01027 length = ((double)new_asset->video_length / new_asset->frame_rate);
01028 else
01029 length = 1.0 / session->frame_rate;
01030
01031 for( ;
01032 current && vtrack < new_asset->layers;
01033 current = NEXT)
01034 {
01035 if(!current->record ||
01036 current->data_type != TRACK_VIDEO)
01037 continue;
01038
01039 current->insert_asset(new_asset,
01040 length,
01041 position,
01042 vtrack);
01043
01044 vtrack++;
01045 }
01046
01047 int atrack = 0;
01048 for(current = tracks->first;
01049 current && atrack < new_asset->channels;
01050 current = NEXT)
01051 {
01052 if(!current->record ||
01053 current->data_type != TRACK_AUDIO)
01054 continue;
01055
01056 current->insert_asset(new_asset,
01057 (double)new_asset->audio_length /
01058 new_asset->sample_rate,
01059 position,
01060 atrack);
01061
01062
01063 atrack++;
01064 }
01065
01066 if(labels)
01067 {
01068 for(RecordLabel *label = labels->first; label; label = label->next)
01069 {
01070 this->labels->toggle_label(label->position, label->position);
01071 }
01072 }
01073 }
01074
01075
01076
01077 void EDL::set_index_file(Asset *asset)
01078 {
01079 assets->update_index(asset);
01080 }
01081
01082 void EDL::optimize()
01083 {
01084
01085 double length = tracks->total_length();
01086 if(local_session->preview_end > length) local_session->preview_end = length;
01087 if(local_session->preview_start > length ||
01088 local_session->preview_start < 0) local_session->preview_start = 0;
01089 for(Track *current = tracks->first; current; current = NEXT)
01090 current->optimize();
01091 }
01092
01093 int EDL::next_id()
01094 {
01095 id_lock->lock("EDL::next_id");
01096 int result = EDLSession::current_id++;
01097 id_lock->unlock();
01098 return result;
01099 }
01100
01101 void EDL::get_shared_plugins(Track *source,
01102 ArrayList<SharedLocation*> *plugin_locations)
01103 {
01104 for(Track *track = tracks->first; track; track = track->next)
01105 {
01106 if(track != source &&
01107 track->data_type == source->data_type)
01108 {
01109 for(int i = 0; i < track->plugin_set.total; i++)
01110 {
01111 Plugin *plugin = track->get_current_plugin(
01112 local_session->get_selectionstart(1),
01113 i,
01114 PLAY_FORWARD,
01115 1,
01116 0);
01117 if(plugin && plugin->plugin_type == PLUGIN_STANDALONE)
01118 {
01119 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
01120 }
01121 }
01122 }
01123 }
01124 }
01125
01126 void EDL::get_shared_tracks(Track *track, ArrayList<SharedLocation*> *module_locations)
01127 {
01128 for(Track *current = tracks->first; current; current = NEXT)
01129 {
01130 if(current != track &&
01131 current->data_type == track->data_type)
01132 {
01133 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
01134 }
01135 }
01136 }
01137
01138
01139 double EDL::align_to_frame(double position, int round)
01140 {
01141
01142 if(session->cursor_on_frames)
01143 {
01144
01145 double temp = (double)position * session->frame_rate;
01146
01147
01148
01149 if(session->sample_rate == 0)
01150 printf("EDL::align_to_frame: sample_rate == 0\n");
01151
01152 if(session->frame_rate == 0)
01153 printf("EDL::align_to_frame: frame_rate == 0\n");
01154
01155
01156
01157
01158 if(round)
01159 {
01160 temp = Units::round(temp);
01161 }
01162 else
01163 {
01164
01165
01166
01167
01168
01169 temp = Units::to_int64(temp);
01170 }
01171
01172
01173
01174 temp /= session->frame_rate;
01175
01176
01177
01178 return temp;
01179 }
01180
01181
01182
01183 return position;
01184 }
01185
01186
01187 void EDL::new_folder(char *folder)
01188 {
01189 for(int i = 0; i < folders.total; i++)
01190 {
01191 if(!strcasecmp(folders.values[i], folder)) return;
01192 }
01193
01194 char *new_folder;
01195 folders.append(new_folder = new char[strlen(folder) + 1]);
01196 strcpy(new_folder, folder);
01197 }
01198
01199 void EDL::delete_folder(char *folder)
01200 {
01201 int i;
01202 for(i = 0; i < folders.total; i++)
01203 {
01204 if(!strcasecmp(folders.values[i], folder))
01205 {
01206 break;
01207 }
01208 }
01209
01210 if(i < folders.total) delete folders.values[i];
01211
01212 for( ; i < folders.total - 1; i++)
01213 {
01214 folders.values[i] = folders.values[i + 1];
01215 }
01216 }