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