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 += theme->get_image("title_bg_data")->get_h();
224 result += edl->local_session->zoom_track;
226 result += plugin_set.total * theme->get_image("plugin_bg_data")->get_h();
227 result = MAX(result, theme->title_h);
231 double Track::get_length()
233 double total_length = 0;
239 length = from_units(edits->last->startproject + edits->last->length);
240 if(length > total_length) total_length = length;
244 for(int i = 0; i < plugin_set.total; i++)
246 if( !plugin_set.values[i]->last ) continue;
247 length = from_units(plugin_set.values[i]->last->startproject +
248 plugin_set.values[i]->last->length);
249 if(length > total_length) total_length = length;
253 length = from_units(automation->get_length());
254 if(length > total_length) total_length = length;
260 int Track::has_speed()
262 FloatAutos *autos = (FloatAutos*)automation->autos[AUTOMATION_SPEED];
267 for(FloatAuto *current = (FloatAuto*)autos->first;
269 current = (FloatAuto*)current->next)
271 if(!EQUIV(current->get_value(), 1.0) ||
272 !EQUIV(current->get_control_in_value(), 0.0) ||
273 !EQUIV(current->get_control_out_value(), 0.0))
284 int Track::show_assets()
286 return expand_view || edl->session->show_assets ? 1 : 0;
289 int Track::show_titles()
291 return expand_view || edl->session->show_titles ? 1 : 0;
294 int Track::show_transitions()
296 return expand_view || edl->session->auto_conf->transitions ? 1 : 0;
299 void Track::get_source_dimensions(double position, int &w, int &h)
301 int64_t native_position = to_units(position, 0);
302 for(Edit *current = edits->first; current; current = NEXT)
304 if(current->startproject <= native_position &&
305 current->startproject + current->length > native_position &&
308 w = current->asset->width;
309 h = current->asset->height;
316 int64_t Track::horizontal_span()
318 return (int64_t)(get_length() *
319 edl->session->sample_rate /
320 edl->local_session->zoom_sample +
325 int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
328 int current_plugin = 0;
331 record = file->tag.get_property("RECORD", record);
332 play = file->tag.get_property("PLAY", play);
333 gang = file->tag.get_property("GANG", gang);
334 draw = file->tag.get_property("DRAW", draw);
335 nudge = file->tag.get_property("NUDGE", nudge);
336 mixer_id = file->tag.get_property("MIXER_ID", mixer_id);
337 expand_view = file->tag.get_property("EXPAND", expand_view);
338 track_w = file->tag.get_property("TRACK_W", track_w);
339 track_h = file->tag.get_property("TRACK_H", track_h);
341 load_header(file, load_flags);
344 result = file->read_tag();
348 if(file->tag.title_is("/TRACK"))
353 if(file->tag.title_is("TITLE"))
356 file->read_text_until("/TITLE", &data);
357 memset(title, 0, sizeof(title));
358 strncpy(title, data.cstr(), sizeof(title)-1);
361 if(load_flags && automation->load(file)
362 /* strstr(file->tag.get_title(), "AUTOS") */)
367 if(file->tag.title_is("EDITS"))
369 if(load_flags & LOAD_EDITS)
370 edits->load(file, track_offset);
372 result = file->skip_tag();
375 if(file->tag.title_is("PLUGINSET"))
377 if(load_flags & LOAD_EDITS)
379 PluginSet *plugin_set = new PluginSet(edl, this);
380 this->plugin_set.append(plugin_set);
381 plugin_set->load(file, load_flags);
384 if(load_flags & LOAD_AUTOMATION)
386 if(current_plugin < this->plugin_set.total)
388 PluginSet *plugin_set = this->plugin_set.values[current_plugin];
389 plugin_set->load(file, load_flags);
394 result = file->skip_tag();
397 load_derived(file, load_flags);
406 void Track::insert_asset(Asset *asset,
412 edits->insert_asset(asset,
415 to_units(position, 0),
421 // Default keyframes: We don't replace default keyframes in pasting but
422 // when inserting the first EDL of a load operation we need to replace
423 // the default keyframes.
425 // Plugins: This is an arbitrary behavior
427 // 1) No plugin in source track: Paste silence into destination
429 // 2) Plugin in source track: plugin in source track is inserted into
430 // existing destination track plugin sets, new sets being added when
433 void Track::insert_track(Track *track,
440 // Calculate minimum length of data to pad.
441 int64_t min_length = to_units(
442 MAX(edl_length, track->get_length()),
444 //printf("Track::insert_track %d %s %jd\n", __LINE__, title, min_length);
446 // Decide whether to copy settings based on load_mode
447 if(replace_default) copy_settings(track);
449 edits->insert_edits(track->edits,
450 to_units(position, 0),
455 insert_plugin_set(track,
456 to_units(position, 0),
461 automation->insert_track(track->automation,
462 to_units(position, 0),
470 // Called by insert_track
471 void Track::insert_plugin_set(Track *track,
476 // Extend plugins if no incoming plugins
477 if(!track->plugin_set.total)
479 shift_effects(position,
484 for(int i = 0; i < track->plugin_set.total; i++)
486 if(i >= plugin_set.total)
487 plugin_set.append(new PluginSet(edl, this));
489 plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
497 Plugin* Track::insert_effect(const char *title,
498 SharedLocation *shared_location,
499 KeyFrame *default_keyframe,
500 PluginSet *plugin_set,
507 plugin_set = new PluginSet(edl, this);
508 this->plugin_set.append(plugin_set);
513 // Position is identical to source plugin
514 if(plugin_type == PLUGIN_SHAREDPLUGIN)
516 Track *source_track = tracks->get_item_number(shared_location->module);
519 Plugin *source_plugin = source_track->get_current_plugin(
520 edl->local_session->get_selectionstart(1),
521 shared_location->plugin,
526 // From an attach operation
529 plugin = plugin_set->insert_plugin(title,
530 source_plugin->startproject,
531 source_plugin->length,
538 // From a drag operation
540 plugin = plugin_set->insert_plugin(title,
552 // This should be done in the caller
555 if(edl->local_session->get_selectionend() >
556 edl->local_session->get_selectionstart())
558 start = edl->local_session->get_selectionstart();
559 length = edl->local_session->get_selectionend() - start;
564 length = get_length();
567 //printf("Track::insert_effect %f %f %d %d\n", start, length, to_units(start, 0),
568 // to_units(length, 0));
570 plugin = plugin_set->insert_plugin(title,
578 //printf("Track::insert_effect 2 %f %f\n", start, length);
584 void Track::move_plugins_up(PluginSet *plugin_set)
586 for(int i = 0; i < this->plugin_set.total; i++)
588 if(this->plugin_set.values[i] == plugin_set)
592 PluginSet *temp = this->plugin_set.values[i - 1];
593 this->plugin_set.values[i - 1] = this->plugin_set.values[i];
594 this->plugin_set.values[i] = temp;
596 SharedLocation old_location, new_location;
597 new_location.module = old_location.module = tracks->number_of(this);
598 old_location.plugin = i;
599 new_location.plugin = i - 1;
600 tracks->change_plugins(old_location, new_location, 1);
606 void Track::move_plugins_down(PluginSet *plugin_set)
608 for(int i = 0; i < this->plugin_set.total; i++)
610 if(this->plugin_set.values[i] == plugin_set)
612 if(i == this->plugin_set.total - 1) break;
614 PluginSet *temp = this->plugin_set.values[i + 1];
615 this->plugin_set.values[i + 1] = this->plugin_set.values[i];
616 this->plugin_set.values[i] = temp;
618 SharedLocation old_location, new_location;
619 new_location.module = old_location.module = tracks->number_of(this);
620 old_location.plugin = i;
621 new_location.plugin = i + 1;
622 tracks->change_plugins(old_location, new_location, 1);
629 void Track::remove_asset(Indexable *asset)
631 for(Edit *edit = edits->first; edit; edit = edit->next)
633 if(asset->is_asset &&
635 edit->asset == (Asset*)asset)
640 if(!asset->is_asset &&
642 edit->nested_edl == (EDL*)asset)
644 edit->nested_edl = 0;
650 void Track::remove_pluginset(PluginSet *plugin_set)
653 for(i = 0; i < this->plugin_set.total; i++)
654 if(plugin_set == this->plugin_set.values[i]) break;
656 this->plugin_set.remove_object(plugin_set);
657 for(i++ ; i < this->plugin_set.total; i++)
659 SharedLocation old_location, new_location;
660 new_location.module = old_location.module = tracks->number_of(this);
661 old_location.plugin = i;
662 new_location.plugin = i - 1;
663 tracks->change_plugins(old_location, new_location, 0);
667 void Track::shift_keyframes(int64_t position, int64_t length)
669 automation->paste_silence(position, position + length);
670 // Effect keyframes are shifted in shift_effects
673 void Track::shift_effects(int64_t position, int64_t length, int edit_autos)
675 for(int i = 0; i < plugin_set.total; i++)
677 plugin_set.values[i]->shift_effects(position, length, edit_autos);
681 void Track::detach_effect(Plugin *plugin)
683 //printf("Track::detach_effect 1\n");
684 for(int i = 0; i < plugin_set.total; i++)
686 PluginSet *plugin_set = this->plugin_set.values[i];
687 for(Plugin *dest = (Plugin*)plugin_set->first;
689 dest = (Plugin*)dest->next)
693 int64_t start = plugin->startproject;
694 int64_t end = plugin->startproject + plugin->length;
696 plugin_set->clear(start, end, 1);
698 //printf("Track::detach_effect 2 %d\n", plugin_set->length());
699 // Delete 0 length pluginsets
706 void Track::resample(double old_rate, double new_rate)
708 edits->resample(old_rate, new_rate);
709 automation->resample(old_rate, new_rate);
710 for(int i = 0; i < plugin_set.total; i++)
711 plugin_set.values[i]->resample(old_rate, new_rate);
712 nudge = (int64_t)(nudge * new_rate / old_rate);
715 void Track::detach_shared_effects(int module)
717 for(int i = 0; i < plugin_set.size(); i++) {
718 PluginSet *plugin_set = this->plugin_set.get(i);
719 for(Plugin *dest = (Plugin*)plugin_set->first; dest; ) {
720 if( (dest->plugin_type == PLUGIN_SHAREDPLUGIN ||
721 dest->plugin_type == PLUGIN_SHAREDMODULE) &&
722 dest->shared_location.module == module ) {
723 int64_t start = dest->startproject;
724 int64_t end = dest->startproject + dest->length;
725 plugin_set->clear(start, end, 1);
728 if(dest) dest = (Plugin*)dest->next;
735 void Track::optimize()
738 for(int i = 0; i < plugin_set.total; ) {
739 PluginSet *plugin_set = this->plugin_set.values[i];
740 plugin_set->optimize();
741 //printf("Track::optimize %d\n", plugin_set.values[i]->total());
742 // new definition of empty track...
743 if( !plugin_set->last ||
744 (plugin_set->last == plugin_set->first &&
745 plugin_set->last->silence()) ) {
746 remove_pluginset(plugin_set);
753 Plugin* Track::get_current_plugin(double position,
760 if(convert_units) position = to_units(position, 0);
761 if(use_nudge) position += nudge;
763 if(plugin_set >= this->plugin_set.total || plugin_set < 0) return 0;
765 //printf("Track::get_current_plugin 1 %d %d %d\n", position, this->plugin_set.total, direction);
766 if(direction == PLAY_FORWARD)
768 for(current = (Plugin*)this->plugin_set.values[plugin_set]->last;
770 current = (Plugin*)PREVIOUS)
772 // printf("Track::get_current_plugin 2 %d %ld %ld\n",
773 // current->startproject,
774 // current->startproject + current->length,
776 if(current->startproject <= position &&
777 current->startproject + current->length > position)
784 if(direction == PLAY_REVERSE)
786 for(current = (Plugin*)this->plugin_set.values[plugin_set]->first;
788 current = (Plugin*)NEXT)
790 if(current->startproject < position &&
791 current->startproject + current->length >= position)
801 Plugin* Track::get_current_transition(double position,
808 if(convert_units) position = to_units(position, 0);
809 if(use_nudge) position += nudge;
811 if(direction == PLAY_FORWARD)
813 for(current = edits->last; current; current = PREVIOUS)
815 if(current->startproject <= position && current->startproject + current->length > position)
817 //printf("Track::get_current_transition %p\n", current->transition);
818 if(current->transition && position < current->startproject + current->transition->length)
820 result = current->transition;
827 if(direction == PLAY_REVERSE)
829 for(current = edits->first; current; current = NEXT)
831 if(current->startproject < position && current->startproject + current->length >= position)
833 if(current->transition && position <= current->startproject + current->transition->length)
835 result = current->transition;
845 void Track::synchronize_params(Track *track)
847 for(Edit *this_edit = edits->first, *that_edit = track->edits->first;
848 this_edit && that_edit;
849 this_edit = this_edit->next, that_edit = that_edit->next)
851 this_edit->synchronize_params(that_edit);
854 for(int i = 0; i < plugin_set.total && i < track->plugin_set.total; i++)
855 plugin_set.values[i]->synchronize_params(track->plugin_set.values[i]);
857 automation->copy_from(track->automation);
858 this->nudge = track->nudge;
865 int Track::dump(FILE *fp)
867 fprintf(fp," Data type %d\n", data_type);
868 fprintf(fp," Title %s\n", title);
869 fprintf(fp," Edits:\n");
870 for(Edit* current = edits->first; current; current = NEXT)
874 automation->dump(fp);
875 fprintf(fp," Plugin Sets: %d\n", plugin_set.total);
877 for(int i = 0; i < plugin_set.total; i++)
878 plugin_set.values[i]->dump(fp);
879 //printf("Track::dump 2\n");
903 Track::Track() : ListItem<Track>()
908 // ======================================== accounting
910 int Track::number_of()
912 return tracks->number_of(this);
927 // ================================================= editing
929 int Track::select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y)
934 int Track::move_auto(AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
939 int Track::release_auto()
944 // used for copying automation alone
945 int Track::copy_automation(double selectionstart,
951 int64_t start = to_units(selectionstart, 0);
952 int64_t end = to_units(selectionend, 1);
954 file->tag.set_title("TRACK");
958 file->append_newline();
960 automation->copy(start, end, file, default_only, active_only);
962 if(edl->session->auto_conf->plugins)
964 for(int i = 0; i < plugin_set.total; i++)
967 plugin_set.values[i]->copy_keyframes(start,
975 file->tag.set_title("/TRACK");
977 file->append_newline();
978 file->append_newline();
979 file->append_newline();
980 file->append_newline();
985 int Track::paste_automation(double selectionstart,
993 // Only used for pasting automation alone.
998 int current_pluginset;
1000 if(data_type == TRACK_AUDIO)
1001 scale = edl->session->sample_rate / sample_rate;
1003 scale = edl->session->frame_rate / frame_rate;
1005 total_length *= scale;
1006 start = to_units(selectionstart, 0);
1007 length = to_units(total_length, 1);
1009 current_pluginset = 0;
1010 //printf("Track::paste_automation 1\n");
1014 result = file->read_tag();
1018 if(file->tag.title_is("/TRACK"))
1021 if(automation->paste(start, length, scale, file,
1022 default_only, active_only, 0)) {}
1023 else if(file->tag.title_is("PLUGINSET")) {
1024 if(current_pluginset < plugin_set.total) {
1025 plugin_set.values[current_pluginset]->
1026 paste_keyframes(start, length, file,
1027 default_only, active_only);
1028 current_pluginset++;
1038 void Track::clear_automation(double selectionstart,
1039 double selectionend,
1043 int64_t start = to_units(selectionstart, 0);
1044 int64_t end = to_units(selectionend, 1);
1046 automation->clear(start, end, edl->session->auto_conf, 0);
1048 if(edl->session->auto_conf->plugins)
1050 for(int i = 0; i < plugin_set.total; i++)
1052 plugin_set.values[i]->clear_keyframes(start, end);
1058 void Track::set_automation_mode(double selectionstart,
1059 double selectionend,
1062 int64_t start = to_units(selectionstart, 0);
1063 int64_t end = to_units(selectionend, 1);
1065 automation->set_automation_mode(start, end, mode, edl->session->auto_conf);
1071 int Track::copy(double start,
1074 const char *output_path)
1076 // Use a copy of the selection in converted units
1077 // So copy_automation doesn't reconvert.
1078 int64_t start_unit = to_units(start, 0);
1079 int64_t end_unit = to_units(end, 1);
1084 file->tag.set_title("TRACK");
1085 file->tag.set_property("RECORD", record);
1086 file->tag.set_property("NUDGE", nudge);
1087 file->tag.set_property("MIXER_ID", mixer_id);
1088 file->tag.set_property("PLAY", play);
1089 file->tag.set_property("GANG", gang);
1090 file->tag.set_property("DRAW", draw);
1091 file->tag.set_property("EXPAND", expand_view);
1092 file->tag.set_property("TRACK_W", track_w);
1093 file->tag.set_property("TRACK_H", track_h);
1096 file->append_newline();
1099 file->tag.set_title("TITLE");
1101 file->append_text(title);
1102 file->tag.set_title("/TITLE");
1104 file->append_newline();
1106 // if(data_type == TRACK_AUDIO)
1107 // file->tag.set_property("TYPE", "AUDIO");
1109 // file->tag.set_property("TYPE", "VIDEO");
1111 // file->append_tag();
1112 // file->append_newline();
1114 edits->copy(start_unit, end_unit, file, output_path);
1117 auto_conf.set_all(1);
1118 automation->copy(start_unit, end_unit, file, 0, 0);
1121 for(int i = 0; i < plugin_set.total; i++)
1123 plugin_set.values[i]->copy(start_unit, end_unit, file);
1126 copy_derived(start_unit, end_unit, file);
1128 file->tag.set_title("/TRACK");
1130 file->append_newline();
1131 file->append_newline();
1132 file->append_newline();
1133 file->append_newline();
1138 int Track::copy_assets(double start,
1140 ArrayList<Asset*> *asset_list)
1144 start = to_units(start, 0);
1145 end = to_units(end, 1);
1147 Edit *current = edits->editof((int64_t)start, PLAY_FORWARD, 0);
1150 while(current && current->startproject < end)
1152 // Check for duplicate assets
1155 for(i = 0, result = 0; i < asset_list->total; i++)
1157 if(asset_list->values[i] == current->asset) result = 1;
1159 // append pointer to new asset
1160 if(!result) asset_list->append(current->asset);
1169 int Track::blade(double position)
1171 int64_t start = to_units(position, 0);
1172 Edit *edit = edits->split_edit(start);
1173 if( !edit ) return 1;
1174 edit->hard_left = 1;
1175 if( edit->previous ) edit->previous->hard_right = 1;
1179 int Track::clear(double start, double end,
1180 int edit_edits, int edit_labels, int edit_plugins,
1181 int edit_autos, Edits *trim_edits)
1183 return clear(to_units(start, 0), to_units(end, 1),
1184 edit_edits, edit_labels, edit_plugins, edit_autos, trim_edits);
1187 int Track::clear(int64_t start, int64_t end,
1188 int edit_edits, int edit_labels, int edit_plugins,
1189 int edit_autos, Edits *trim_edits)
1191 //printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
1193 automation->clear(start, end, 0, 1);
1194 if( edit_plugins ) {
1195 for(int i = 0; i < plugin_set.total; i++) {
1196 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1197 plugin_set.values[i]->clear(start, end, edit_autos);
1201 edits->clear(start, end);
1205 int Track::clear_handle(double start,
1212 edits->clear_handle(start, end, clear_plugins, edit_autos, distance);
1216 int Track::popup_transition(int cursor_x, int cursor_y)
1223 int Track::modify_edithandles(double oldposition, double newposition,
1224 int currentend, int handle_mode, int edit_labels,
1225 int edit_plugins, int edit_autos, int group_id)
1227 edits->modify_handles(oldposition, newposition,
1228 currentend, handle_mode, 1, edit_labels, edit_plugins,
1229 edit_autos, 0, group_id);
1233 int Track::modify_pluginhandles(double oldposition,
1241 for(int i = 0; i < plugin_set.total; i++)
1243 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1244 plugin_set.values[i]->modify_handles(oldposition, newposition,
1245 // Don't allow plugin tweeks to affect edits.
1246 currentend, handle_mode, 0,
1247 edit_labels, 1, edit_autos, trim_edits, 0);
1253 int Track::paste_silence(double start, double end, int edit_plugins, int edit_autos)
1255 return paste_silence(to_units(start, 0), to_units(end, 1),
1256 edit_plugins, edit_autos);
1259 int Track::paste_silence(int64_t start, int64_t end, int edit_plugins, int edit_autos)
1261 edits->paste_silence(start, end);
1263 shift_keyframes(start, end - start);
1265 shift_effects(start, end - start, edit_autos);
1270 int Track::select_edit(int cursor_x,
1278 int Track::scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end)
1283 void Track::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
1285 for(int i = 0; i < plugin_set.total; i++)
1287 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1289 plugin = (Plugin*)plugin->next)
1291 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
1293 if(plugin->shared_location == old_location)
1294 plugin->shared_location = new_location;
1296 if(do_swap && plugin->shared_location == new_location)
1297 plugin->shared_location = old_location;
1303 void Track::change_modules(int old_location, int new_location, int do_swap)
1305 for(int i = 0; i < plugin_set.total; i++)
1307 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1309 plugin = (Plugin*)plugin->next)
1311 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN ||
1312 plugin->plugin_type == PLUGIN_SHAREDMODULE)
1314 if(plugin->shared_location.module == old_location)
1315 plugin->shared_location.module = new_location;
1317 if(do_swap && plugin->shared_location.module == new_location)
1318 plugin->shared_location.module = old_location;
1325 int Track::playable_edit(int64_t position, int direction)
1328 if(direction == PLAY_REVERSE) position--;
1329 for(Edit *current = edits->first; current && !result; current = NEXT)
1331 if(current->startproject <= position &&
1332 current->startproject + current->length > position)
1334 //printf("Track::playable_edit %p %p\n", current->transition, current->asset);
1335 if(current->transition ||
1337 current->nested_edl) result = 1;
1344 int Track::need_edit(Edit *current, int test_transitions)
1346 return ((test_transitions && current->transition) ||
1347 (!test_transitions && current->asset));
1350 int64_t Track::plugin_change_duration(int64_t input_position,
1351 int64_t input_length,
1355 if(use_nudge) input_position += nudge;
1356 for(int i = 0; i < plugin_set.total; i++)
1358 int64_t new_duration = plugin_set.values[i]->plugin_change_duration(
1362 if(new_duration < input_length) input_length = new_duration;
1364 return input_length;
1367 int64_t Track::edit_change_duration(int64_t input_position,
1368 int64_t input_length,
1370 int test_transitions,
1374 int64_t edit_length = input_length;
1375 if(use_nudge) input_position += nudge;
1379 // ================================= Reverse playback
1380 // Get first edit on or after position
1381 for(current = edits->first;
1382 current && current->startproject + current->length <= input_position;
1388 if(current->startproject > input_position)
1390 // Before first edit
1394 if(need_edit(current, test_transitions))
1396 // Over an edit of interest.
1397 if(input_position - current->startproject < input_length)
1398 edit_length = input_position - current->startproject + 1;
1402 // Over an edit that isn't of interest.
1403 // Search for next edit of interest.
1404 for(current = PREVIOUS ;
1406 current->startproject + current->length > input_position - input_length &&
1407 !need_edit(current, test_transitions);
1412 need_edit(current, test_transitions) &&
1413 current->startproject + current->length > input_position - input_length)
1414 edit_length = input_position - current->startproject - current->length + 1;
1419 // Not over an edit. Try the last edit.
1420 current = edits->last;
1422 ((test_transitions && current->transition) ||
1423 (!test_transitions && current->asset)))
1424 edit_length = input_position - edits->length() + 1;
1429 // =================================== forward playback
1430 // Get first edit on or before position
1431 for(current = edits->last;
1432 current && current->startproject > input_position;
1438 if(current->startproject + current->length <= input_position)
1440 // Beyond last edit.
1444 if(need_edit(current, test_transitions))
1446 // Over an edit of interest.
1447 // Next edit is going to require a change.
1448 if(current->length + current->startproject - input_position < input_length)
1449 edit_length = current->startproject + current->length - input_position;
1453 // Over an edit that isn't of interest.
1454 // Search for next edit of interest.
1455 for(current = NEXT ;
1457 current->startproject < input_position + input_length &&
1458 !need_edit(current, test_transitions);
1463 need_edit(current, test_transitions) &&
1464 current->startproject < input_position + input_length)
1465 edit_length = current->startproject - input_position;
1470 // Not over an edit. Try the first edit.
1471 current = edits->first;
1473 ((test_transitions && current->transition) ||
1474 (!test_transitions && current->asset)))
1475 edit_length = edits->first->startproject - input_position;
1479 if(edit_length < input_length)
1482 return input_length;
1485 void Track::shuffle_edits(double start, double end, int first_track)
1487 ArrayList<Edit*> new_edits;
1488 ArrayList<Label*> new_labels;
1489 int64_t start_units = to_units(start, 0);
1490 int64_t end_units = to_units(end, 0);
1491 // Sample range of all edits selected
1492 //int64_t total_start_units = 0;
1493 //int64_t total_end_units = 0;
1494 // Edit before range
1495 Edit *start_edit = 0;
1496 int have_start_edit = 0;
1498 // Move all edit pointers to list
1499 for(Edit *current = edits->first;
1502 if(current->startproject >= start_units &&
1503 current->startproject + current->length <= end_units)
1505 if(!have_start_edit) start_edit = current->previous;
1506 have_start_edit = 1;
1507 //total_start_units = current->startproject;
1508 //total_end_units = current->startproject + current->length;
1509 new_edits.append(current);
1511 // Move label pointers
1512 if(first_track && edl->session->labels_follow_edits)
1514 double start_seconds = from_units(current->startproject);
1515 double end_seconds = from_units(current->startproject +
1517 for(Label *label = edl->labels->first;
1519 label = label->next)
1521 if(label->position >= start_seconds &&
1522 label->position < end_seconds)
1524 new_labels.append(label);
1525 edl->labels->remove_pointer(label);
1530 // Remove edit pointer
1531 Edit *previous = current;
1533 edits->remove_pointer(previous);
1541 // Insert pointers in random order
1542 while(new_edits.size())
1544 int index = rand() % new_edits.size();
1545 Edit *edit = new_edits.get(index);
1546 new_edits.remove_number(index);
1548 edits->insert_before(edits->first, edit);
1550 edits->insert_after(start_edit, edit);
1553 // Recalculate start position
1554 // Save old position for moving labels
1555 int64_t startproject1 = edit->startproject;
1556 int64_t startproject2 = 0;
1559 edit->startproject =
1561 edit->previous->startproject + edit->previous->length;
1565 edit->startproject = startproject2 = 0;
1569 // Insert label pointers
1570 if(first_track && edl->session->labels_follow_edits)
1572 double start_seconds1 = from_units(startproject1);
1573 double end_seconds1 = from_units(startproject1 + edit->length);
1574 double start_seconds2 = from_units(startproject2);
1575 for(int i = new_labels.size() - 1; i >= 0; i--)
1577 Label *label = new_labels.get(i);
1578 // Was in old edit position
1579 if(label->position >= start_seconds1 &&
1580 label->position < end_seconds1)
1582 // Move to new edit position
1583 double position = label->position -
1584 start_seconds1 + start_seconds2;
1585 edl->labels->insert_label(position);
1586 new_labels.remove_object_number(i);
1596 if(first_track && edl->session->labels_follow_edits)
1598 edl->labels->optimize();
1602 // exactly the same as shuffle_edits except for 1 line
1603 void Track::reverse_edits(double start, double end, int first_track)
1605 ArrayList<Edit*> new_edits;
1606 ArrayList<Label*> new_labels;
1607 int64_t start_units = to_units(start, 0);
1608 int64_t end_units = to_units(end, 0);
1609 // Sample range of all edits selected
1610 //int64_t total_start_units = 0;
1611 //int64_t total_end_units = 0;
1612 // Edit before range
1613 Edit *start_edit = 0;
1614 int have_start_edit = 0;
1616 // Move all edit pointers to list
1617 for(Edit *current = edits->first; current; )
1619 if(current->startproject >= start_units &&
1620 current->startproject + current->length <= end_units)
1622 if(!have_start_edit) start_edit = current->previous;
1623 have_start_edit = 1;
1624 //total_start_units = current->startproject;
1625 //total_end_units = current->startproject + current->length;
1626 new_edits.append(current);
1628 // Move label pointers
1629 if(first_track && edl->session->labels_follow_edits)
1631 double start_seconds = from_units(current->startproject);
1632 double end_seconds = from_units(current->startproject +
1634 for(Label *label = edl->labels->first;
1636 label = label->next)
1638 if(label->position >= start_seconds &&
1639 label->position < end_seconds)
1641 new_labels.append(label);
1642 edl->labels->remove_pointer(label);
1647 // Remove edit pointer
1648 Edit *previous = current;
1650 edits->remove_pointer(previous);
1658 // Insert pointers in reverse order
1659 while(new_edits.size())
1661 int index = new_edits.size() - 1;
1662 Edit *edit = new_edits.get(index);
1663 new_edits.remove_number(index);
1665 edits->insert_before(edits->first, edit);
1667 edits->insert_after(start_edit, edit);
1670 // Recalculate start position
1671 // Save old position for moving labels
1672 int64_t startproject1 = edit->startproject;
1673 int64_t startproject2 = 0;
1676 edit->startproject =
1678 edit->previous->startproject + edit->previous->length;
1682 edit->startproject = startproject2 = 0;
1686 // Insert label pointers
1687 if(first_track && edl->session->labels_follow_edits)
1689 double start_seconds1 = from_units(startproject1);
1690 double end_seconds1 = from_units(startproject1 + edit->length);
1691 double start_seconds2 = from_units(startproject2);
1692 for(int i = new_labels.size() - 1; i >= 0; i--)
1694 Label *label = new_labels.get(i);
1695 // Was in old edit position
1696 if(label->position >= start_seconds1 &&
1697 label->position < end_seconds1)
1699 // Move to new edit position
1700 double position = label->position -
1701 start_seconds1 + start_seconds2;
1702 edl->labels->insert_label(position);
1703 new_labels.remove_object_number(i);
1713 if(first_track && edl->session->labels_follow_edits)
1715 edl->labels->optimize();
1719 void Track::align_edits(double start,
1721 ArrayList<double> *times)
1723 int64_t start_units = to_units(start, 0);
1724 int64_t end_units = to_units(end, 0);
1726 // If 1st track with data, times is empty & we need to collect the edit times.
1729 for(Edit *current = edits->first; current; current = NEXT)
1731 if(current->startproject >= start_units &&
1732 current->startproject + current->length <= end_units)
1734 times->append(from_units(current->startproject));
1739 // All other tracks get silence or cut to align the edits on the times.
1741 int current_time = 0;
1742 for(Edit *current = edits->first;
1743 current && current_time < times->size(); )
1745 if(current->startproject >= start_units &&
1746 current->startproject + current->length <= end_units)
1748 int64_t desired_startunits = to_units(times->get(current_time), 0);
1749 int64_t current_startunits = current->startproject;
1753 if(current_startunits < desired_startunits)
1755 //printf("Track::align_edits %d\n", __LINE__);
1756 edits->paste_silence(current_startunits,
1757 desired_startunits);
1758 shift_keyframes(current_startunits,
1759 desired_startunits - current_startunits);
1762 if(current_startunits > desired_startunits)
1764 edits->clear(desired_startunits,
1765 current_startunits);
1766 if(edl->session->autos_follow_edits)
1767 shift_keyframes(desired_startunits,
1768 current_startunits - desired_startunits);
1783 int Track::purge_asset(Asset *asset)
1788 int Track::asset_used(Asset *asset)
1793 for(current_edit = edits->first; current_edit; current_edit = current_edit->next)
1795 if(current_edit->asset == asset)
1803 int Track::is_playable(int64_t position, int direction)
1809 int Track::plugin_used(int64_t position, int64_t direction)
1811 //printf("Track::plugin_used 1 %d\n", this->plugin_set.total);
1812 for(int i = 0; i < this->plugin_set.total; i++)
1814 Plugin *current_plugin = get_current_plugin(position,
1820 //printf("Track::plugin_used 2 %p %d %d\n", current_plugin, current_plugin->on, current_plugin->plugin_type);
1821 if(current_plugin &&
1822 current_plugin->on &&
1823 current_plugin->plugin_type != PLUGIN_NONE)
1828 //printf("Track::plugin_used 3 %p\n", current_plugin);
1832 // Audio is always rendered through VConsole
1833 int Track::direct_copy_possible(int64_t start, int direction, int use_nudge)
1838 int64_t Track::to_units(double position, int round)
1840 return (int64_t)position;
1843 double Track::to_doubleunits(double position)
1848 double Track::from_units(int64_t position)
1850 return (double)position;
1853 int64_t Track::frame_align(int64_t position, int round)
1855 if( data_type != TRACK_VIDEO && edl->session->cursor_on_frames )
1856 position = to_units(edl->align_to_frame(from_units(position), round), round);
1860 int Track::plugin_exists(Plugin *plugin)
1862 for(int number = 0; number < plugin_set.size(); number++)
1864 PluginSet *ptr = plugin_set.get(number);
1865 for(Plugin *current_plugin = (Plugin*)ptr->first;
1867 current_plugin = (Plugin*)current_plugin->next)
1869 if(current_plugin == plugin) return 1;
1873 for(Edit *current = edits->first; current; current = NEXT)
1875 if(current->transition &&
1876 (Plugin*)current->transition == plugin) return 1;
1883 int Track::get_mixer_id()
1885 if( mixer_id < 0 ) {
1887 for( Track *track=tracks->first; track!=0; track=track->next )
1888 if( track->mixer_id > v ) v = track->mixer_id;