3 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "automation.h"
24 #include "bcsignals.h"
29 #include "edlsession.h"
31 #include "floatauto.h"
32 #include "floatautos.h"
35 #include "localsession.h"
40 #include "pluginset.h"
41 #include "mainsession.h"
45 #include "trackcanvas.h"
47 #include "transition.h"
48 #include "transportque.inc"
54 Track::Track(EDL *edl, Tracks *tracks) : ListItem<Track>()
57 this->tracks = tracks;
66 track_w = edl->session->output_w;
67 track_h = edl->session->output_h;
76 plugin_set.remove_all_objects();
79 void Track::create_objects()
84 int Track::copy_settings(Track *track)
86 this->expand_view = track->expand_view;
87 this->draw = track->draw;
88 this->gang = track->gang;
89 this->record = track->record;
90 this->nudge = track->nudge;
91 this->mixer_id = track->mixer_id;
92 this->play = track->play;
93 this->track_w = track->track_w;
94 this->track_h = track->track_h;
95 strcpy(this->title, track->title);
105 int Track::load_defaults(BC_Hash *defaults)
110 void Track::equivalent_output(Track *track, double *result)
112 if(data_type != track->data_type ||
113 track_w != track->track_w ||
114 track_h != track->track_h ||
115 play != track->play ||
116 nudge != track->nudge)
119 // Convert result to track units
120 int64_t result2 = -1;
121 automation->equivalent_output(track->automation, &result2);
122 edits->equivalent_output(track->edits, &result2);
124 int plugin_sets = MIN(plugin_set.total, track->plugin_set.total);
125 // Test existing plugin sets
126 for(int i = 0; i < plugin_sets; i++)
128 plugin_set.values[i]->equivalent_output(
129 track->plugin_set.values[i],
133 // New EDL has more plugin sets. Get starting plugin in new plugin sets
134 for(int i = plugin_sets; i < plugin_set.total; i++)
136 Plugin *current = plugin_set.values[i]->get_first_plugin();
139 if(result2 < 0 || current->startproject < result2)
140 result2 = current->startproject;
144 // New EDL has fewer plugin sets. Get starting plugin in old plugin set
145 for(int i = plugin_sets; i < track->plugin_set.total; i++)
147 Plugin *current = track->plugin_set.values[i]->get_first_plugin();
150 if(result2 < 0 || current->startproject < result2)
151 result2 = current->startproject;
155 // Number of plugin sets differs but somehow we didn't find the start of the
157 if(track->plugin_set.total != plugin_set.total && result2 < 0)
161 (*result < 0 || from_units(result2) < *result))
162 *result = from_units(result2);
166 int Track::is_synthesis(int64_t position,
169 int is_synthesis = 0;
170 for(int i = 0; i < plugin_set.total; i++)
172 Plugin *plugin = get_current_plugin(position,
179 // Assume data from a shared track is synthesized
180 if(plugin->plugin_type == PLUGIN_SHAREDMODULE)
183 is_synthesis = plugin->is_synthesis(position,
186 //printf("Track::is_synthesis %d %d\n", __LINE__, is_synthesis);
187 if(is_synthesis) break;
193 void Track::copy_from(Track *track)
195 copy_settings(track);
196 edits->copy_from(track->edits);
197 for(int i = 0; i < this->plugin_set.total; i++)
198 delete this->plugin_set.values[i];
199 this->plugin_set.remove_all_objects();
201 for(int i = 0; i < track->plugin_set.total; i++)
203 PluginSet *new_plugin_set = plugin_set.append(new PluginSet(edl, this));
204 new_plugin_set->copy_from(track->plugin_set.values[i]);
206 automation->copy_from(track->automation);
207 this->track_w = track->track_w;
208 this->track_h = track->track_h;
211 Track& Track::operator=(Track& track)
213 printf("Track::operator= 1\n");
218 int Track::vertical_span(Theme *theme)
222 result = edl->local_session->zoom_track +
224 theme->get_image("plugin_bg_data")->get_h();
226 result = edl->local_session->zoom_track;
228 if(edl->session->show_titles)
229 result += theme->get_image("title_bg_data")->get_h();
234 double Track::get_length()
236 double total_length = 0;
242 length = from_units(edits->last->startproject + edits->last->length);
243 if(length > total_length) total_length = length;
247 for(int i = 0; i < plugin_set.total; i++)
249 if( !plugin_set.values[i]->last ) continue;
250 length = from_units(plugin_set.values[i]->last->startproject +
251 plugin_set.values[i]->last->length);
252 if(length > total_length) total_length = length;
256 length = from_units(automation->get_length());
257 if(length > total_length) total_length = length;
263 int Track::has_speed()
265 FloatAutos *autos = (FloatAutos*)automation->autos[AUTOMATION_SPEED];
270 for(FloatAuto *current = (FloatAuto*)autos->first;
272 current = (FloatAuto*)current->next)
274 if(!EQUIV(current->get_value(), 1.0) ||
275 !EQUIV(current->get_control_in_value(), 0.0) ||
276 !EQUIV(current->get_control_out_value(), 0.0))
289 void Track::get_source_dimensions(double position, int &w, int &h)
291 int64_t native_position = to_units(position, 0);
292 for(Edit *current = edits->first; current; current = NEXT)
294 if(current->startproject <= native_position &&
295 current->startproject + current->length > native_position &&
298 w = current->asset->width;
299 h = current->asset->height;
306 int64_t Track::horizontal_span()
308 return (int64_t)(get_length() *
309 edl->session->sample_rate /
310 edl->local_session->zoom_sample +
315 int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
318 int current_plugin = 0;
321 record = file->tag.get_property("RECORD", record);
322 play = file->tag.get_property("PLAY", play);
323 gang = file->tag.get_property("GANG", gang);
324 draw = file->tag.get_property("DRAW", draw);
325 nudge = file->tag.get_property("NUDGE", nudge);
326 mixer_id = file->tag.get_property("MIXER_ID", mixer_id);
327 expand_view = file->tag.get_property("EXPAND", expand_view);
328 track_w = file->tag.get_property("TRACK_W", track_w);
329 track_h = file->tag.get_property("TRACK_H", track_h);
331 load_header(file, load_flags);
334 result = file->read_tag();
338 if(file->tag.title_is("/TRACK"))
343 if(file->tag.title_is("TITLE"))
345 file->read_text_until("/TITLE", title, BCTEXTLEN);
348 if(load_flags && automation->load(file)
349 /* strstr(file->tag.get_title(), "AUTOS") */)
354 if(file->tag.title_is("EDITS"))
356 if(load_flags & LOAD_EDITS)
357 edits->load(file, track_offset);
359 result = file->skip_tag();
362 if(file->tag.title_is("PLUGINSET"))
364 if(load_flags & LOAD_EDITS)
366 PluginSet *plugin_set = new PluginSet(edl, this);
367 this->plugin_set.append(plugin_set);
368 plugin_set->load(file, load_flags);
371 if(load_flags & LOAD_AUTOMATION)
373 if(current_plugin < this->plugin_set.total)
375 PluginSet *plugin_set = this->plugin_set.values[current_plugin];
376 plugin_set->load(file, load_flags);
381 result = file->skip_tag();
384 load_derived(file, load_flags);
393 void Track::insert_asset(Asset *asset,
399 edits->insert_asset(asset,
402 to_units(position, 0),
408 // Default keyframes: We don't replace default keyframes in pasting but
409 // when inserting the first EDL of a load operation we need to replace
410 // the default keyframes.
412 // Plugins: This is an arbitrary behavior
414 // 1) No plugin in source track: Paste silence into destination
416 // 2) Plugin in source track: plugin in source track is inserted into
417 // existing destination track plugin sets, new sets being added when
420 void Track::insert_track(Track *track,
427 // Calculate minimum length of data to pad.
428 int64_t min_length = to_units(
429 MAX(edl_length, track->get_length()),
431 //printf("Track::insert_track %d %s %jd\n", __LINE__, title, min_length);
433 // Decide whether to copy settings based on load_mode
434 if(replace_default) copy_settings(track);
436 edits->insert_edits(track->edits,
437 to_units(position, 0),
442 insert_plugin_set(track,
443 to_units(position, 0),
448 automation->insert_track(track->automation,
449 to_units(position, 0),
457 // Called by insert_track
458 void Track::insert_plugin_set(Track *track,
463 // Extend plugins if no incoming plugins
464 if(!track->plugin_set.total)
466 shift_effects(position,
471 for(int i = 0; i < track->plugin_set.total; i++)
473 if(i >= plugin_set.total)
474 plugin_set.append(new PluginSet(edl, this));
476 plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
484 Plugin* Track::insert_effect(const char *title,
485 SharedLocation *shared_location,
486 KeyFrame *default_keyframe,
487 PluginSet *plugin_set,
494 plugin_set = new PluginSet(edl, this);
495 this->plugin_set.append(plugin_set);
500 // Position is identical to source plugin
501 if(plugin_type == PLUGIN_SHAREDPLUGIN)
503 Track *source_track = tracks->get_item_number(shared_location->module);
506 Plugin *source_plugin = source_track->get_current_plugin(
507 edl->local_session->get_selectionstart(),
508 shared_location->plugin,
513 // From an attach operation
516 plugin = plugin_set->insert_plugin(title,
517 source_plugin->startproject,
518 source_plugin->length,
525 // From a drag operation
527 plugin = plugin_set->insert_plugin(title,
539 // This should be done in the caller
542 if(edl->local_session->get_selectionend() >
543 edl->local_session->get_selectionstart())
545 start = edl->local_session->get_selectionstart();
546 length = edl->local_session->get_selectionend() - start;
551 length = get_length();
554 //printf("Track::insert_effect %f %f %d %d\n", start, length, to_units(start, 0),
555 // to_units(length, 0));
557 plugin = plugin_set->insert_plugin(title,
565 //printf("Track::insert_effect 2 %f %f\n", start, length);
571 void Track::move_plugins_up(PluginSet *plugin_set)
573 for(int i = 0; i < this->plugin_set.total; i++)
575 if(this->plugin_set.values[i] == plugin_set)
579 PluginSet *temp = this->plugin_set.values[i - 1];
580 this->plugin_set.values[i - 1] = this->plugin_set.values[i];
581 this->plugin_set.values[i] = temp;
583 SharedLocation old_location, new_location;
584 new_location.module = old_location.module = tracks->number_of(this);
585 old_location.plugin = i;
586 new_location.plugin = i - 1;
587 tracks->change_plugins(old_location, new_location, 1);
593 void Track::move_plugins_down(PluginSet *plugin_set)
595 for(int i = 0; i < this->plugin_set.total; i++)
597 if(this->plugin_set.values[i] == plugin_set)
599 if(i == this->plugin_set.total - 1) break;
601 PluginSet *temp = this->plugin_set.values[i + 1];
602 this->plugin_set.values[i + 1] = this->plugin_set.values[i];
603 this->plugin_set.values[i] = temp;
605 SharedLocation old_location, new_location;
606 new_location.module = old_location.module = tracks->number_of(this);
607 old_location.plugin = i;
608 new_location.plugin = i + 1;
609 tracks->change_plugins(old_location, new_location, 1);
616 void Track::remove_asset(Indexable *asset)
618 for(Edit *edit = edits->first; edit; edit = edit->next)
620 if(asset->is_asset &&
622 edit->asset == (Asset*)asset)
627 if(!asset->is_asset &&
629 edit->nested_edl == (EDL*)asset)
631 edit->nested_edl = 0;
637 void Track::remove_pluginset(PluginSet *plugin_set)
640 for(i = 0; i < this->plugin_set.total; i++)
641 if(plugin_set == this->plugin_set.values[i]) break;
643 this->plugin_set.remove_object(plugin_set);
644 for(i++ ; i < this->plugin_set.total; i++)
646 SharedLocation old_location, new_location;
647 new_location.module = old_location.module = tracks->number_of(this);
648 old_location.plugin = i;
649 new_location.plugin = i - 1;
650 tracks->change_plugins(old_location, new_location, 0);
654 void Track::shift_keyframes(int64_t position, int64_t length)
656 automation->paste_silence(position, position + length);
657 // Effect keyframes are shifted in shift_effects
660 void Track::shift_effects(int64_t position, int64_t length, int edit_autos)
662 for(int i = 0; i < plugin_set.total; i++)
664 plugin_set.values[i]->shift_effects(position, length, edit_autos);
668 void Track::detach_effect(Plugin *plugin)
670 //printf("Track::detach_effect 1\n");
671 for(int i = 0; i < plugin_set.total; i++)
673 PluginSet *plugin_set = this->plugin_set.values[i];
674 for(Plugin *dest = (Plugin*)plugin_set->first;
676 dest = (Plugin*)dest->next)
680 int64_t start = plugin->startproject;
681 int64_t end = plugin->startproject + plugin->length;
683 plugin_set->clear(start, end, 1);
685 //printf("Track::detach_effect 2 %d\n", plugin_set->length());
686 // Delete 0 length pluginsets
693 void Track::resample(double old_rate, double new_rate)
695 edits->resample(old_rate, new_rate);
696 automation->resample(old_rate, new_rate);
697 for(int i = 0; i < plugin_set.total; i++)
698 plugin_set.values[i]->resample(old_rate, new_rate);
699 nudge = (int64_t)(nudge * new_rate / old_rate);
702 void Track::detach_shared_effects(int module)
704 for(int i = 0; i < plugin_set.size(); i++) {
705 PluginSet *plugin_set = this->plugin_set.get(i);
706 for(Plugin *dest = (Plugin*)plugin_set->first; dest; ) {
707 if( (dest->plugin_type == PLUGIN_SHAREDPLUGIN ||
708 dest->plugin_type == PLUGIN_SHAREDMODULE) &&
709 dest->shared_location.module == module ) {
710 int64_t start = dest->startproject;
711 int64_t end = dest->startproject + dest->length;
712 plugin_set->clear(start, end, 1);
715 if(dest) dest = (Plugin*)dest->next;
722 void Track::optimize()
725 for(int i = 0; i < plugin_set.total; ) {
726 PluginSet *plugin_set = this->plugin_set.values[i];
727 plugin_set->optimize();
728 //printf("Track::optimize %d\n", plugin_set.values[i]->total());
729 // new definition of empty track...
730 if( !plugin_set->last ||
731 (plugin_set->last == plugin_set->first &&
732 plugin_set->last->silence()) ) {
733 remove_pluginset(plugin_set);
740 Plugin* Track::get_current_plugin(double position,
747 if(convert_units) position = to_units(position, 0);
748 if(use_nudge) position += nudge;
750 if(plugin_set >= this->plugin_set.total || plugin_set < 0) return 0;
752 //printf("Track::get_current_plugin 1 %d %d %d\n", position, this->plugin_set.total, direction);
753 if(direction == PLAY_FORWARD)
755 for(current = (Plugin*)this->plugin_set.values[plugin_set]->last;
757 current = (Plugin*)PREVIOUS)
759 // printf("Track::get_current_plugin 2 %d %ld %ld\n",
760 // current->startproject,
761 // current->startproject + current->length,
763 if(current->startproject <= position &&
764 current->startproject + current->length > position)
771 if(direction == PLAY_REVERSE)
773 for(current = (Plugin*)this->plugin_set.values[plugin_set]->first;
775 current = (Plugin*)NEXT)
777 if(current->startproject < position &&
778 current->startproject + current->length >= position)
788 Plugin* Track::get_current_transition(double position,
795 if(convert_units) position = to_units(position, 0);
796 if(use_nudge) position += nudge;
798 if(direction == PLAY_FORWARD)
800 for(current = edits->last; current; current = PREVIOUS)
802 if(current->startproject <= position && current->startproject + current->length > position)
804 //printf("Track::get_current_transition %p\n", current->transition);
805 if(current->transition && position < current->startproject + current->transition->length)
807 result = current->transition;
814 if(direction == PLAY_REVERSE)
816 for(current = edits->first; current; current = NEXT)
818 if(current->startproject < position && current->startproject + current->length >= position)
820 if(current->transition && position <= current->startproject + current->transition->length)
822 result = current->transition;
832 void Track::synchronize_params(Track *track)
834 for(Edit *this_edit = edits->first, *that_edit = track->edits->first;
835 this_edit && that_edit;
836 this_edit = this_edit->next, that_edit = that_edit->next)
838 this_edit->synchronize_params(that_edit);
841 for(int i = 0; i < plugin_set.total && i < track->plugin_set.total; i++)
842 plugin_set.values[i]->synchronize_params(track->plugin_set.values[i]);
844 automation->copy_from(track->automation);
845 this->nudge = track->nudge;
852 int Track::dump(FILE *fp)
854 fprintf(fp," Data type %d\n", data_type);
855 fprintf(fp," Title %s\n", title);
856 fprintf(fp," Edits:\n");
857 for(Edit* current = edits->first; current; current = NEXT)
861 automation->dump(fp);
862 fprintf(fp," Plugin Sets: %d\n", plugin_set.total);
864 for(int i = 0; i < plugin_set.total; i++)
865 plugin_set.values[i]->dump(fp);
866 //printf("Track::dump 2\n");
890 Track::Track() : ListItem<Track>()
895 // ======================================== accounting
897 int Track::number_of()
899 return tracks->number_of(this);
914 // ================================================= editing
916 int Track::select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y)
921 int Track::move_auto(AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
926 int Track::release_auto()
931 // used for copying automation alone
932 int Track::copy_automation(double selectionstart,
938 int64_t start = to_units(selectionstart, 0);
939 int64_t end = to_units(selectionend, 1);
941 file->tag.set_title("TRACK");
945 file->append_newline();
947 automation->copy(start, end, file, default_only, active_only);
949 if(edl->session->auto_conf->plugins)
951 for(int i = 0; i < plugin_set.total; i++)
954 plugin_set.values[i]->copy_keyframes(start,
962 file->tag.set_title("/TRACK");
964 file->append_newline();
965 file->append_newline();
966 file->append_newline();
967 file->append_newline();
972 int Track::paste_automation(double selectionstart,
980 // Only used for pasting automation alone.
985 int current_pluginset;
987 if(data_type == TRACK_AUDIO)
988 scale = edl->session->sample_rate / sample_rate;
990 scale = edl->session->frame_rate / frame_rate;
992 total_length *= scale;
993 start = to_units(selectionstart, 0);
994 length = to_units(total_length, 1);
996 current_pluginset = 0;
997 //printf("Track::paste_automation 1\n");
1001 result = file->read_tag();
1005 if(file->tag.title_is("/TRACK"))
1008 if(automation->paste(start, length, scale, file,
1009 default_only, active_only, 0)) {}
1010 else if(file->tag.title_is("PLUGINSET")) {
1011 if(current_pluginset < plugin_set.total) {
1012 plugin_set.values[current_pluginset]->
1013 paste_keyframes(start, length, file,
1014 default_only, active_only);
1015 current_pluginset++;
1025 void Track::clear_automation(double selectionstart,
1026 double selectionend,
1030 int64_t start = to_units(selectionstart, 0);
1031 int64_t end = to_units(selectionend, 1);
1033 automation->clear(start, end, edl->session->auto_conf, 0);
1035 if(edl->session->auto_conf->plugins)
1037 for(int i = 0; i < plugin_set.total; i++)
1039 plugin_set.values[i]->clear_keyframes(start, end);
1045 void Track::set_automation_mode(double selectionstart,
1046 double selectionend,
1049 int64_t start = to_units(selectionstart, 0);
1050 int64_t end = to_units(selectionend, 1);
1052 automation->set_automation_mode(start, end, mode, edl->session->auto_conf);
1058 int Track::copy(double start,
1061 const char *output_path)
1063 // Use a copy of the selection in converted units
1064 // So copy_automation doesn't reconvert.
1065 int64_t start_unit = to_units(start, 0);
1066 int64_t end_unit = to_units(end, 1);
1071 file->tag.set_title("TRACK");
1072 file->tag.set_property("RECORD", record);
1073 file->tag.set_property("NUDGE", nudge);
1074 file->tag.set_property("MIXER_ID", mixer_id);
1075 file->tag.set_property("PLAY", play);
1076 file->tag.set_property("GANG", gang);
1077 file->tag.set_property("DRAW", draw);
1078 file->tag.set_property("EXPAND", expand_view);
1079 file->tag.set_property("TRACK_W", track_w);
1080 file->tag.set_property("TRACK_H", track_h);
1083 file->append_newline();
1086 file->tag.set_title("TITLE");
1088 file->append_text(title);
1089 file->tag.set_title("/TITLE");
1091 file->append_newline();
1093 // if(data_type == TRACK_AUDIO)
1094 // file->tag.set_property("TYPE", "AUDIO");
1096 // file->tag.set_property("TYPE", "VIDEO");
1098 // file->append_tag();
1099 // file->append_newline();
1101 edits->copy(start_unit, end_unit, file, output_path);
1104 auto_conf.set_all(1);
1105 automation->copy(start_unit, end_unit, file, 0, 0);
1108 for(int i = 0; i < plugin_set.total; i++)
1110 plugin_set.values[i]->copy(start_unit, end_unit, file);
1113 copy_derived(start_unit, end_unit, file);
1115 file->tag.set_title("/TRACK");
1117 file->append_newline();
1118 file->append_newline();
1119 file->append_newline();
1120 file->append_newline();
1125 int Track::copy_assets(double start,
1127 ArrayList<Asset*> *asset_list)
1131 start = to_units(start, 0);
1132 end = to_units(end, 1);
1134 Edit *current = edits->editof((int64_t)start, PLAY_FORWARD, 0);
1137 while(current && current->startproject < end)
1139 // Check for duplicate assets
1142 for(i = 0, result = 0; i < asset_list->total; i++)
1144 if(asset_list->values[i] == current->asset) result = 1;
1146 // append pointer to new asset
1147 if(!result) asset_list->append(current->asset);
1156 int Track::blade(double position)
1158 int64_t start = to_units(position, 0);
1159 Edit *edit = edits->split_edit(start);
1160 if( !edit ) return 1;
1161 edit->hard_left = 1;
1162 if( edit->previous ) edit->previous->hard_right = 1;
1166 int Track::clear(double start, double end,
1167 int edit_edits, int edit_labels, int edit_plugins,
1168 int edit_autos, int convert_units, Edits *trim_edits)
1170 // Edits::move_auto calls this routine after the units are converted to the track
1172 //printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
1175 start = to_units(start, 0);
1176 end = to_units(end, 1);
1181 automation->clear((int64_t)start, (int64_t)end, 0, 1);
1185 for(int i = 0; i < plugin_set.total; i++)
1187 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1188 plugin_set.values[i]->clear((int64_t)start, (int64_t)end, edit_autos);
1193 edits->clear((int64_t)start, (int64_t)end);
1197 int Track::clear_handle(double start,
1204 edits->clear_handle(start, end, clear_plugins, edit_autos, distance);
1208 int Track::popup_transition(int cursor_x, int cursor_y)
1215 int Track::modify_edithandles(double oldposition,
1223 edits->modify_handles(oldposition,
1237 int Track::modify_pluginhandles(double oldposition,
1245 for(int i = 0; i < plugin_set.total; i++)
1247 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1248 plugin_set.values[i]->modify_handles(oldposition,
1252 // Don't allow plugin tweeks to affect edits.
1263 int Track::paste_silence(double start, double end, int edit_plugins, int edit_autos)
1265 int64_t start_i = to_units(start, 0);
1266 int64_t end_i = to_units(end, 1);
1268 edits->paste_silence(start_i, end_i);
1269 if(edit_autos) shift_keyframes(start_i, end_i - start_i);
1270 if(edit_plugins) shift_effects(start_i, end_i - start_i, edit_autos);
1276 int Track::select_edit(int cursor_x,
1284 int Track::scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end)
1289 void Track::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
1291 for(int i = 0; i < plugin_set.total; i++)
1293 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1295 plugin = (Plugin*)plugin->next)
1297 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
1299 if(plugin->shared_location == old_location)
1300 plugin->shared_location = new_location;
1302 if(do_swap && plugin->shared_location == new_location)
1303 plugin->shared_location = old_location;
1309 void Track::change_modules(int old_location, int new_location, int do_swap)
1311 for(int i = 0; i < plugin_set.total; i++)
1313 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1315 plugin = (Plugin*)plugin->next)
1317 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN ||
1318 plugin->plugin_type == PLUGIN_SHAREDMODULE)
1320 if(plugin->shared_location.module == old_location)
1321 plugin->shared_location.module = new_location;
1323 if(do_swap && plugin->shared_location.module == new_location)
1324 plugin->shared_location.module = old_location;
1331 int Track::playable_edit(int64_t position, int direction)
1334 if(direction == PLAY_REVERSE) position--;
1335 for(Edit *current = edits->first; current && !result; current = NEXT)
1337 if(current->startproject <= position &&
1338 current->startproject + current->length > position)
1340 //printf("Track::playable_edit %p %p\n", current->transition, current->asset);
1341 if(current->transition ||
1343 current->nested_edl) result = 1;
1350 int Track::need_edit(Edit *current, int test_transitions)
1352 return ((test_transitions && current->transition) ||
1353 (!test_transitions && current->asset));
1356 int64_t Track::plugin_change_duration(int64_t input_position,
1357 int64_t input_length,
1361 if(use_nudge) input_position += nudge;
1362 for(int i = 0; i < plugin_set.total; i++)
1364 int64_t new_duration = plugin_set.values[i]->plugin_change_duration(
1368 if(new_duration < input_length) input_length = new_duration;
1370 return input_length;
1373 int64_t Track::edit_change_duration(int64_t input_position,
1374 int64_t input_length,
1376 int test_transitions,
1380 int64_t edit_length = input_length;
1381 if(use_nudge) input_position += nudge;
1385 // ================================= Reverse playback
1386 // Get first edit on or after position
1387 for(current = edits->first;
1388 current && current->startproject + current->length <= input_position;
1394 if(current->startproject > input_position)
1396 // Before first edit
1400 if(need_edit(current, test_transitions))
1402 // Over an edit of interest.
1403 if(input_position - current->startproject < input_length)
1404 edit_length = input_position - current->startproject + 1;
1408 // Over an edit that isn't of interest.
1409 // Search for next edit of interest.
1410 for(current = PREVIOUS ;
1412 current->startproject + current->length > input_position - input_length &&
1413 !need_edit(current, test_transitions);
1418 need_edit(current, test_transitions) &&
1419 current->startproject + current->length > input_position - input_length)
1420 edit_length = input_position - current->startproject - current->length + 1;
1425 // Not over an edit. Try the last edit.
1426 current = edits->last;
1428 ((test_transitions && current->transition) ||
1429 (!test_transitions && current->asset)))
1430 edit_length = input_position - edits->length() + 1;
1435 // =================================== forward playback
1436 // Get first edit on or before position
1437 for(current = edits->last;
1438 current && current->startproject > input_position;
1444 if(current->startproject + current->length <= input_position)
1446 // Beyond last edit.
1450 if(need_edit(current, test_transitions))
1452 // Over an edit of interest.
1453 // Next edit is going to require a change.
1454 if(current->length + current->startproject - input_position < input_length)
1455 edit_length = current->startproject + current->length - input_position;
1459 // Over an edit that isn't of interest.
1460 // Search for next edit of interest.
1461 for(current = NEXT ;
1463 current->startproject < input_position + input_length &&
1464 !need_edit(current, test_transitions);
1469 need_edit(current, test_transitions) &&
1470 current->startproject < input_position + input_length)
1471 edit_length = current->startproject - input_position;
1476 // Not over an edit. Try the first edit.
1477 current = edits->first;
1479 ((test_transitions && current->transition) ||
1480 (!test_transitions && current->asset)))
1481 edit_length = edits->first->startproject - input_position;
1485 if(edit_length < input_length)
1488 return input_length;
1491 void Track::shuffle_edits(double start, double end, int first_track)
1493 ArrayList<Edit*> new_edits;
1494 ArrayList<Label*> new_labels;
1495 int64_t start_units = to_units(start, 0);
1496 int64_t end_units = to_units(end, 0);
1497 // Sample range of all edits selected
1498 //int64_t total_start_units = 0;
1499 //int64_t total_end_units = 0;
1500 // Edit before range
1501 Edit *start_edit = 0;
1502 int have_start_edit = 0;
1504 // Move all edit pointers to list
1505 for(Edit *current = edits->first;
1508 if(current->startproject >= start_units &&
1509 current->startproject + current->length <= end_units)
1511 if(!have_start_edit) start_edit = current->previous;
1512 have_start_edit = 1;
1513 //total_start_units = current->startproject;
1514 //total_end_units = current->startproject + current->length;
1515 new_edits.append(current);
1517 // Move label pointers
1518 if(first_track && edl->session->labels_follow_edits)
1520 double start_seconds = from_units(current->startproject);
1521 double end_seconds = from_units(current->startproject +
1523 for(Label *label = edl->labels->first;
1525 label = label->next)
1527 if(label->position >= start_seconds &&
1528 label->position < end_seconds)
1530 new_labels.append(label);
1531 edl->labels->remove_pointer(label);
1536 // Remove edit pointer
1537 Edit *previous = current;
1539 edits->remove_pointer(previous);
1547 // Insert pointers in random order
1548 while(new_edits.size())
1550 int index = rand() % new_edits.size();
1551 Edit *edit = new_edits.get(index);
1552 new_edits.remove_number(index);
1554 edits->insert_before(edits->first, edit);
1556 edits->insert_after(start_edit, edit);
1559 // Recalculate start position
1560 // Save old position for moving labels
1561 int64_t startproject1 = edit->startproject;
1562 int64_t startproject2 = 0;
1565 edit->startproject =
1567 edit->previous->startproject + edit->previous->length;
1571 edit->startproject = startproject2 = 0;
1575 // Insert label pointers
1576 if(first_track && edl->session->labels_follow_edits)
1578 double start_seconds1 = from_units(startproject1);
1579 double end_seconds1 = from_units(startproject1 + edit->length);
1580 double start_seconds2 = from_units(startproject2);
1581 for(int i = new_labels.size() - 1; i >= 0; i--)
1583 Label *label = new_labels.get(i);
1584 // Was in old edit position
1585 if(label->position >= start_seconds1 &&
1586 label->position < end_seconds1)
1588 // Move to new edit position
1589 double position = label->position -
1590 start_seconds1 + start_seconds2;
1591 edl->labels->insert_label(position);
1592 new_labels.remove_object_number(i);
1602 if(first_track && edl->session->labels_follow_edits)
1604 edl->labels->optimize();
1608 // exactly the same as shuffle_edits except for 1 line
1609 void Track::reverse_edits(double start, double end, int first_track)
1611 ArrayList<Edit*> new_edits;
1612 ArrayList<Label*> new_labels;
1613 int64_t start_units = to_units(start, 0);
1614 int64_t end_units = to_units(end, 0);
1615 // Sample range of all edits selected
1616 //int64_t total_start_units = 0;
1617 //int64_t total_end_units = 0;
1618 // Edit before range
1619 Edit *start_edit = 0;
1620 int have_start_edit = 0;
1622 // Move all edit pointers to list
1623 for(Edit *current = edits->first; current; )
1625 if(current->startproject >= start_units &&
1626 current->startproject + current->length <= end_units)
1628 if(!have_start_edit) start_edit = current->previous;
1629 have_start_edit = 1;
1630 //total_start_units = current->startproject;
1631 //total_end_units = current->startproject + current->length;
1632 new_edits.append(current);
1634 // Move label pointers
1635 if(first_track && edl->session->labels_follow_edits)
1637 double start_seconds = from_units(current->startproject);
1638 double end_seconds = from_units(current->startproject +
1640 for(Label *label = edl->labels->first;
1642 label = label->next)
1644 if(label->position >= start_seconds &&
1645 label->position < end_seconds)
1647 new_labels.append(label);
1648 edl->labels->remove_pointer(label);
1653 // Remove edit pointer
1654 Edit *previous = current;
1656 edits->remove_pointer(previous);
1664 // Insert pointers in reverse order
1665 while(new_edits.size())
1667 int index = new_edits.size() - 1;
1668 Edit *edit = new_edits.get(index);
1669 new_edits.remove_number(index);
1671 edits->insert_before(edits->first, edit);
1673 edits->insert_after(start_edit, edit);
1676 // Recalculate start position
1677 // Save old position for moving labels
1678 int64_t startproject1 = edit->startproject;
1679 int64_t startproject2 = 0;
1682 edit->startproject =
1684 edit->previous->startproject + edit->previous->length;
1688 edit->startproject = startproject2 = 0;
1692 // Insert label pointers
1693 if(first_track && edl->session->labels_follow_edits)
1695 double start_seconds1 = from_units(startproject1);
1696 double end_seconds1 = from_units(startproject1 + edit->length);
1697 double start_seconds2 = from_units(startproject2);
1698 for(int i = new_labels.size() - 1; i >= 0; i--)
1700 Label *label = new_labels.get(i);
1701 // Was in old edit position
1702 if(label->position >= start_seconds1 &&
1703 label->position < end_seconds1)
1705 // Move to new edit position
1706 double position = label->position -
1707 start_seconds1 + start_seconds2;
1708 edl->labels->insert_label(position);
1709 new_labels.remove_object_number(i);
1719 if(first_track && edl->session->labels_follow_edits)
1721 edl->labels->optimize();
1725 void Track::align_edits(double start,
1727 ArrayList<double> *times)
1729 int64_t start_units = to_units(start, 0);
1730 int64_t end_units = to_units(end, 0);
1732 // If 1st track with data, times is empty & we need to collect the edit times.
1735 for(Edit *current = edits->first; current; current = NEXT)
1737 if(current->startproject >= start_units &&
1738 current->startproject + current->length <= end_units)
1740 times->append(from_units(current->startproject));
1745 // All other tracks get silence or cut to align the edits on the times.
1747 int current_time = 0;
1748 for(Edit *current = edits->first;
1749 current && current_time < times->size(); )
1751 if(current->startproject >= start_units &&
1752 current->startproject + current->length <= end_units)
1754 int64_t desired_startunits = to_units(times->get(current_time), 0);
1755 int64_t current_startunits = current->startproject;
1759 if(current_startunits < desired_startunits)
1761 //printf("Track::align_edits %d\n", __LINE__);
1762 edits->paste_silence(current_startunits,
1763 desired_startunits);
1764 shift_keyframes(current_startunits,
1765 desired_startunits - current_startunits);
1768 if(current_startunits > desired_startunits)
1770 edits->clear(desired_startunits,
1771 current_startunits);
1772 if(edl->session->autos_follow_edits)
1773 shift_keyframes(desired_startunits,
1774 current_startunits - desired_startunits);
1789 int Track::purge_asset(Asset *asset)
1794 int Track::asset_used(Asset *asset)
1799 for(current_edit = edits->first; current_edit; current_edit = current_edit->next)
1801 if(current_edit->asset == asset)
1809 int Track::is_playable(int64_t position, int direction)
1815 int Track::plugin_used(int64_t position, int64_t direction)
1817 //printf("Track::plugin_used 1 %d\n", this->plugin_set.total);
1818 for(int i = 0; i < this->plugin_set.total; i++)
1820 Plugin *current_plugin = get_current_plugin(position,
1826 //printf("Track::plugin_used 2 %p %d %d\n", current_plugin, current_plugin->on, current_plugin->plugin_type);
1827 if(current_plugin &&
1828 current_plugin->on &&
1829 current_plugin->plugin_type != PLUGIN_NONE)
1834 //printf("Track::plugin_used 3 %p\n", current_plugin);
1838 // Audio is always rendered through VConsole
1839 int Track::direct_copy_possible(int64_t start, int direction, int use_nudge)
1844 int64_t Track::to_units(double position, int round)
1846 return (int64_t)position;
1849 double Track::to_doubleunits(double position)
1854 double Track::from_units(int64_t position)
1856 return (double)position;
1859 int Track::plugin_exists(Plugin *plugin)
1861 for(int number = 0; number < plugin_set.size(); number++)
1863 PluginSet *ptr = plugin_set.get(number);
1864 for(Plugin *current_plugin = (Plugin*)ptr->first;
1866 current_plugin = (Plugin*)current_plugin->next)
1868 if(current_plugin == plugin) return 1;
1872 for(Edit *current = edits->first; current; current = NEXT)
1874 if(current->transition &&
1875 (Plugin*)current->transition == plugin) return 1;
1882 int Track::get_mixer_id()
1884 if( mixer_id < 0 ) {
1886 for( Track *track=tracks->first; track!=0; track=track->next )
1887 if( track->mixer_id > v ) v = track->mixer_id;