5 #include "automation.h"
6 #include "awindowgui.inc"
8 #include "colormodels.h"
11 #include "edlsession.h"
15 #include "localsession.h"
18 #include "playbackconfig.h"
20 #include "preferences.h"
21 #include "recordconfig.h"
22 #include "recordlabel.h"
23 #include "sharedlocation.h"
26 #include "transportque.inc"
29 EDL::EDL(EDL *parent_edl)
31 this->parent_edl = parent_edl;
38 folders.set_array_delete();
39 new_folder(CLIP_FOLDER);
40 new_folder(MEDIA_FOLDER);
47 //printf("EDL::~EDL 1\n");
76 folders.remove_all_objects();
77 clips.remove_all_objects();
78 //printf("EDL::~EDL 2\n");
82 int EDL::create_objects()
84 tracks = new Tracks(this);
87 assets = new Assets(this);
88 session = new EDLSession(this);
92 assets = parent_edl->assets;
93 session = parent_edl->session;
96 local_session = new LocalSession(this);
97 labels = new Labels(this, "LABELS");
98 presentations = new Presentations(this);
99 // last_playback_position = 0;
103 EDL& EDL::operator=(EDL &edl)
105 //printf("EDL::operator= 1\n");
107 //printf("EDL::operator= 2\n");
111 int EDL::load_defaults(Defaults *defaults)
114 session->load_defaults(defaults);
116 local_session->load_defaults(defaults);
120 int EDL::save_defaults(Defaults *defaults)
123 session->save_defaults(defaults);
125 local_session->save_defaults(defaults);
129 void EDL::boundaries()
131 session->boundaries();
132 local_session->boundaries();
135 int EDL::create_default_tracks()
138 for(int i = 0; i < session->video_tracks; i++)
140 tracks->add_video_track(0, 0);
142 for(int i = 0; i < session->audio_tracks; i++)
144 tracks->add_audio_track(0, 0);
149 int EDL::load_xml(ArrayList<PluginServer*> *plugindb,
154 // Track numbering offset for replacing undo data.
155 int track_offset = 0;
157 folders.remove_all_objects();
159 // Search for start of master EDL.
161 // The parent_edl test caused clip creation to fail since those XML files
162 // contained an EDL tag.
164 // The parent_edl test is required to make EDL loading work because
165 // when loading an EDL the EDL tag is already read by the parent.
167 if(!parent_edl /* && (load_flags & LOAD_ALL) == LOAD_ALL */)
170 result = file->read_tag();
172 !file->tag.title_is("XML") &&
173 !file->tag.title_is("EDL"));
179 if((load_flags & LOAD_ALL) == LOAD_ALL ||
180 (load_flags & LOAD_EDITS) == LOAD_EDITS)
182 while(tracks->last) delete tracks->last;
185 if((load_flags & LOAD_ALL) == LOAD_ALL)
187 clips.remove_all_objects();
190 if(load_flags & LOAD_TIMEBAR)
192 while(labels->last) delete labels->last;
193 local_session->in_point = -1;
194 local_session->out_point = -1;
198 result = file->read_tag();
202 if(file->tag.title_is("/XML") ||
203 file->tag.title_is("/EDL") ||
204 file->tag.title_is("/CLIP_EDL") ||
205 file->tag.title_is("/VWINDOW_EDL"))
210 if(file->tag.title_is("CLIPBOARD"))
212 local_session->clipboard_length = file->tag.get_property("LENGTH", 0);
215 if(file->tag.title_is("VIDEO"))
217 if((load_flags & LOAD_VCONFIG) &&
218 (load_flags & LOAD_SESSION))
219 session->load_video_config(file, 0, load_flags);
222 if(file->tag.title_is("AUDIO"))
224 if((load_flags & LOAD_ACONFIG) &&
225 (load_flags & LOAD_SESSION))
226 session->load_audio_config(file, 0, load_flags);
229 if(file->tag.title_is("FOLDER"))
231 char folder[BCTEXTLEN];
232 strcpy(folder, file->read_text());
236 if(file->tag.title_is("ASSETS"))
238 if(load_flags & LOAD_ASSETS)
239 assets->load(plugindb, file, load_flags);
242 if(file->tag.title_is(labels->xml_tag))
244 if(load_flags & LOAD_TIMEBAR)
245 labels->load(file, load_flags);
248 if(file->tag.title_is(presentations->xml_tag))
250 if(load_flags & LOAD_TIMEBAR)
251 presentations->load(file, load_flags);
254 if(file->tag.title_is("LOCALSESSION"))
256 if((load_flags & LOAD_SESSION) ||
257 (load_flags & LOAD_TIMEBAR))
258 local_session->load_xml(file, load_flags);
261 if(file->tag.title_is("SESSION"))
263 if((load_flags & LOAD_SESSION) &&
265 session->load_xml(file, 0, load_flags);
268 if(file->tag.title_is("TRACK"))
270 tracks->load(file, track_offset, load_flags);
274 // Causes clip creation to fail because that involves an opening EDL tag.
275 if(file->tag.title_is("CLIP_EDL") && !parent_edl)
277 EDL *new_edl = new EDL(this);
278 new_edl->create_objects();
279 new_edl->load_xml(plugindb, file, LOAD_ALL);
281 if((load_flags & LOAD_ALL) == LOAD_ALL)
282 clips.append(new_edl);
287 if(file->tag.title_is("VWINDOW_EDL") && !parent_edl)
289 EDL *new_edl = new EDL(this);
290 new_edl->create_objects();
291 new_edl->load_xml(plugindb, file, LOAD_ALL);
294 if((load_flags & LOAD_ALL) == LOAD_ALL)
296 if(vwindow_edl) delete vwindow_edl;
297 vwindow_edl = new_edl;
307 //printf("EDL::load_xml 4\n");
310 //printf("EDL::load_xml 6 %p\n", parent_edl);
316 // Output path is the path of the output file if name truncation is desired.
317 // It is a "" if complete names should be used.
318 // Called recursively by copy for clips, thus the string can't be terminated.
319 // The string is not terminated in this call.
320 int EDL::save_xml(ArrayList<PluginServer*> *plugindb,
327 tracks->total_length(),
338 int EDL::copy_all(EDL *edl)
343 *this->tracks = *edl->tracks;
344 *this->labels = *edl->labels;
348 void EDL::copy_clips(EDL *edl)
350 if(vwindow_edl) delete vwindow_edl;
354 vwindow_edl = new EDL(this);
355 vwindow_edl->create_objects();
356 vwindow_edl->copy_all(edl->vwindow_edl);
358 clips.remove_all_objects();
359 for(int i = 0; i < edl->clips.total; i++)
361 add_clip(edl->clips.values[i]);
365 void EDL::copy_assets(EDL *edl)
368 *this->assets = *edl->assets;
371 void EDL::copy_session(EDL *edl)
373 folders.remove_all_objects();
374 for(int i = 0; i < edl->folders.total; i++)
377 folders.append(new_folder = new char[strlen(edl->folders.values[i]) + 1]);
378 strcpy(new_folder, edl->folders.values[i]);
383 session->copy(edl->session);
386 local_session->copy_from(edl->local_session);
389 int EDL::copy_assets(double start,
393 ArrayList<PluginServer*> *plugindb,
396 ArrayList<Asset*> asset_list;
399 file->tag.set_title("ASSETS");
401 file->append_newline();
403 // Copy everything for a save
406 for(Asset *asset = assets->first;
410 asset_list.append(asset);
414 // Copy just the ones being used.
416 for(current = tracks->first;
422 current->copy_assets(start,
429 // Paths relativised here
430 for(int i = 0; i < asset_list.total; i++)
432 asset_list.values[i]->write(plugindb,
438 file->tag.set_title("/ASSETS");
440 file->append_newline();
441 file->append_newline();
445 int EDL::copy(double start,
451 ArrayList<PluginServer*> *plugindb,
455 //printf("EDL::copy 1\n");
458 file->tag.set_title("CLIP_EDL");
461 file->tag.set_title("VWINDOW_EDL");
463 file->tag.set_title("EDL");
466 file->append_newline();
468 // Set clipboard samples only if copying to clipboard
471 file->tag.set_title("CLIPBOARD");
472 file->tag.set_property("LENGTH", end - start);
474 file->append_newline();
475 file->append_newline();
477 //printf("EDL::copy 1\n");
480 local_session->save_xml(file, start);
482 //printf("EDL::copy 1\n");
487 // Need to copy all this from child EDL if pasting is desired.
489 session->save_xml(file);
490 session->save_video_config(file);
491 session->save_audio_config(file);
494 for(int i = 0; i < folders.total; i++)
496 file->tag.set_title("FOLDER");
498 file->append_text(folders.values[i]);
499 file->tag.set_title("/FOLDER");
501 file->append_newline();
513 // Don't want this if using clipboard
519 vwindow_edl->save_xml(plugindb,
526 for(int i = 0; i < clips.total; i++)
527 clips.values[i]->save_xml(plugindb,
534 file->append_newline();
535 file->append_newline();
539 //printf("EDL::copy 1\n");
541 labels->copy(start, end, file);
542 //printf("EDL::copy 1\n");
543 presentations->copy(start, end, file);
544 //printf("EDL::copy 1\n");
545 tracks->copy(start, end, all, file, output_path);
546 //printf("EDL::copy 2\n");
550 file->tag.set_title("/CLIP_EDL");
553 file->tag.set_title("/VWINDOW_EDL");
555 file->tag.set_title("/EDL");
557 file->append_newline();
560 // For editing operations we want to rewind it for immediate pasting.
561 // For clips and saving to disk leave it alone.
564 file->terminate_string();
570 void EDL::rechannel()
572 for(Track *current = tracks->first; current; current = NEXT)
574 if(current->data_type == TRACK_AUDIO)
576 PanAutos *autos = current->automation->pan_autos;
577 ((PanAuto*)autos->default_auto)->rechannel();
578 for(PanAuto *keyframe = (PanAuto*)autos->first;
580 keyframe = (PanAuto*)keyframe->next)
582 keyframe->rechannel();
588 void EDL::resample(double old_rate, double new_rate, int data_type)
590 for(Track *current = tracks->first; current; current = NEXT)
592 if(current->data_type == data_type)
594 current->resample(old_rate, new_rate);
600 void EDL::synchronize_params(EDL *edl)
602 local_session->synchronize_params(edl->local_session);
603 for(Track *this_track = tracks->first, *that_track = edl->tracks->first;
604 this_track && that_track;
605 this_track = this_track->next,
606 that_track = that_track->next)
608 this_track->synchronize_params(that_track);
612 int EDL::trim_selection(double start,
625 tracks->total_length(),
633 int EDL::equivalent(double position1, double position2)
635 double half_frame = (double).5 / session->frame_rate;
636 if((session->cursor_on_frames &&
637 fabs(position2 - position1) < half_frame) ||
638 (fabs(position2 - position1) < half_frame))
644 double EDL::equivalent_output(EDL *edl)
647 //printf("EDL::equivalent_output 1 %f\n", result);
648 session->equivalent_output(edl->session, &result);
649 //printf("EDL::equivalent_output 2 %f\n", result);
650 tracks->equivalent_output(edl->tracks, &result);
651 //printf("EDL::equivalent_output 3 %f\n", result);
656 void EDL::set_inpoint(double position)
658 if(equivalent(local_session->in_point, position) && local_session->in_point >= 0)
660 local_session->in_point = -1;
664 local_session->in_point = align_to_frame(position, 0);
665 if(local_session->out_point <= local_session->in_point) local_session->out_point = -1;
669 void EDL::set_outpoint(double position)
671 if(equivalent(local_session->out_point, position) && local_session->out_point >= 0)
673 local_session->out_point = -1;
677 local_session->out_point = align_to_frame(position, 0);
678 if(local_session->in_point >= local_session->out_point) local_session->in_point = -1;
683 int EDL::clear(double start,
691 tracks->clear_handle(start,
696 if(clear_labels && distance > 0)
697 labels->paste_silence(start,
709 presentations->clear(start, end);
712 // Need to put at beginning so a subsequent paste operation starts at the
714 local_session->selectionend =
715 local_session->selectionstart =
716 local_session->get_selectionstart();
720 void EDL::modify_edithandles(double oldposition,
727 tracks->modify_edithandles(oldposition,
733 labels->modify_handles(oldposition,
740 void EDL::modify_pluginhandles(double oldposition,
746 tracks->modify_pluginhandles(oldposition,
754 void EDL::paste_silence(double start,
760 labels->paste_silence(start, end);
761 tracks->paste_silence(start,
767 void EDL::remove_from_project(ArrayList<EDL*> *clips)
769 for(int i = 0; i < clips->total; i++)
771 for(int j = 0; j < this->clips.total; j++)
773 if(this->clips.values[j] == clips->values[i])
775 this->clips.remove_object(clips->values[i]);
781 void EDL::remove_from_project(ArrayList<Asset*> *assets)
785 for(int j = 0; j < clips.total; j++)
787 clips.values[j]->remove_from_project(assets);
790 // Remove from VWindow
792 vwindow_edl->remove_from_project(assets);
794 for(int i = 0; i < assets->total; i++)
796 // Remove from tracks
797 for(Track *track = tracks->first; track; track = track->next)
799 track->remove_asset(assets->values[i]);
802 // Remove from assets
805 this->assets->remove_asset(assets->values[i]);
810 void EDL::update_assets(EDL *src)
812 for(Asset *current = src->assets->first;
816 assets->update(current);
820 int EDL::get_tracks_height(Theme *theme)
822 int total_pixels = 0;
823 for(Track *current = tracks->first;
827 total_pixels += current->vertical_span(theme);
832 int64_t EDL::get_tracks_width()
834 int64_t total_pixels = 0;
835 for(Track *current = tracks->first;
839 int64_t pixels = current->horizontal_span();
840 if(pixels > total_pixels) total_pixels = pixels;
842 //printf("EDL::get_tracks_width %d\n", total_pixels);
846 int EDL::calculate_output_w(int single_channel)
848 if(single_channel) return session->output_w;
851 for(int i = 0; i < session->video_channels; i++)
853 if(session->vchannel_x[i] + session->output_w > widest) widest = session->vchannel_x[i] + session->output_w;
858 int EDL::calculate_output_h(int single_channel)
860 if(single_channel) return session->output_h;
863 for(int i = 0; i < session->video_channels; i++)
865 if(session->vchannel_y[i] + session->output_h > tallest) tallest = session->vchannel_y[i] + session->output_h;
870 // Get the total output size scaled to aspect ratio
871 void EDL::calculate_conformed_dimensions(int single_channel, float &w, float &h)
873 w = calculate_output_w(single_channel);
874 h = calculate_output_h(single_channel);
876 if((float)session->output_w / session->output_h > get_aspect_ratio())
879 (session->output_w / get_aspect_ratio() / session->output_h);
884 (h * get_aspect_ratio() / session->output_w);
888 float EDL::get_aspect_ratio()
890 return session->aspect_w / session->aspect_h;
899 printf("clip_title: %s parent_edl: %p\n", local_session->clip_title, parent_edl);
900 printf("selectionstart %f selectionend %f loop_start %f loop_end %f\n",
901 local_session->selectionstart,
902 local_session->selectionend,
903 local_session->loop_start,
904 local_session->loop_end);
908 printf("audio_channels: %d "
909 "audio_tracks: %d \n"
911 session->audio_channels,
912 session->audio_tracks,
913 session->sample_rate);
914 printf("video_channels: %d "
917 "frames_per_foot: %.2f\n"
923 session->video_channels,
924 session->video_tracks,
926 session->frames_per_foot,
931 session->color_model);
934 printf(" total: %d\n", clips.total);
936 for(int i = 0; i < clips.total; i++)
939 clips.values[i]->dump();
950 //printf("EDL::dump 2\n");
954 EDL* EDL::add_clip(EDL *edl)
956 // Copy argument. New edls are deleted from MWindow::load_filenames.
957 EDL *new_edl = new EDL(this);
958 new_edl->create_objects();
959 new_edl->copy_all(edl);
960 clips.append(new_edl);
964 void EDL::insert_asset(Asset *asset,
967 RecordLabels *labels)
969 // Insert asset into asset table
970 Asset *new_asset = assets->update(asset);
974 Track *current = first_track ? first_track : tracks->first;
976 //printf("EDL::insert_asset 1\n");
978 // Fix length of single frame
982 if(new_asset->video_length < 0)
983 length = 1.0 / session->frame_rate;
985 if(new_asset->frame_rate > 0)
986 length = ((double)new_asset->video_length / new_asset->frame_rate);
988 length = 1.0 / session->frame_rate;
990 //printf("EDL::insert_asset 2 %f\n", length);
992 current && vtrack < new_asset->layers;
995 if(!current->record ||
996 current->data_type != TRACK_VIDEO)
999 //printf("EDL::insert_asset 3\n");
1000 current->insert_asset(new_asset,
1005 //printf("EDL::insert_asset 4\n");
1010 for(current = tracks->first;
1011 current && atrack < new_asset->channels;
1014 if(!current->record ||
1015 current->data_type != TRACK_AUDIO)
1018 //printf("EDL::insert_asset 5\n");
1019 current->insert_asset(new_asset,
1020 (double)new_asset->audio_length /
1021 new_asset->sample_rate,
1025 //printf("EDL::insert_asset 6\n");
1032 for(RecordLabel *label = labels->first; label; label = label->next)
1034 //printf("EDL::insert_asset 1 %f\n", label->position);
1035 this->labels->toggle_label(label->position, label->position);
1044 void EDL::set_index_file(Asset *asset)
1046 assets->update_index(asset);
1049 void EDL::optimize()
1051 //printf("EDL::optimize 1\n");
1052 double length = tracks->total_length();
1053 if(local_session->preview_end > length) local_session->preview_end = length;
1054 if(local_session->preview_start > length ||
1055 local_session->preview_start < 0) local_session->preview_start = 0;
1056 for(Track *current = tracks->first; current; current = NEXT)
1057 current->optimize();
1062 return EDLSession::current_id++;
1065 void EDL::get_shared_plugins(Track *source,
1066 ArrayList<SharedLocation*> *plugin_locations)
1068 for(Track *track = tracks->first; track; track = track->next)
1070 if(track != source &&
1071 track->data_type == source->data_type)
1073 for(int i = 0; i < track->plugin_set.total; i++)
1075 Plugin *plugin = track->get_current_plugin(local_session->selectionstart,
1080 if(plugin && plugin->plugin_type == PLUGIN_STANDALONE)
1082 plugin_locations->append(new SharedLocation(tracks->number_of(track), i));
1089 void EDL::get_shared_tracks(Track *track, ArrayList<SharedLocation*> *module_locations)
1091 for(Track *current = tracks->first; current; current = NEXT)
1093 if(current != track &&
1094 current->data_type == track->data_type)
1096 module_locations->append(new SharedLocation(tracks->number_of(current), 0));
1101 // Convert position to frames if cursor alignment is enabled
1102 double EDL::align_to_frame(double position, int round)
1104 //printf("EDL::align_to_frame 1 %f\n", position);
1105 if(session->cursor_on_frames)
1107 // Seconds -> Frames
1108 double temp = (double)position * session->frame_rate;
1109 //printf("EDL::align_to_frame 2 %f\n", temp);
1111 // Assert some things
1112 if(session->sample_rate == 0)
1113 printf("EDL::align_to_frame: sample_rate == 0\n");
1115 if(session->frame_rate == 0)
1116 printf("EDL::align_to_frame: frame_rate == 0\n");
1119 // Always round down negative numbers
1120 // but round up only if requested
1123 temp = Units::round(temp);
1132 temp = Units::to_int64(temp);
1134 //printf("EDL::align_to_frame 3 %f\n", temp);
1136 // Frames -> Seconds
1137 temp /= session->frame_rate;
1139 //printf("EDL::align_to_frame 5 %f\n", temp);
1143 //printf("EDL::align_to_frame 3 %d\n", position);
1150 void EDL::new_folder(char *folder)
1152 for(int i = 0; i < folders.total; i++)
1154 if(!strcasecmp(folders.values[i], folder)) return;
1158 folders.append(new_folder = new char[strlen(folder) + 1]);
1159 strcpy(new_folder, folder);
1162 void EDL::delete_folder(char *folder)
1165 for(i = 0; i < folders.total; i++)
1167 if(!strcasecmp(folders.values[i], folder))
1173 if(i < folders.total) delete folders.values[i];
1175 for( ; i < folders.total - 1; i++)
1177 folders.values[i] = folders.values[i + 1];