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 this->plugin_set.remove_all_objects();
199 for( int i=0; i<track->plugin_set.total; ++i ) {
200 PluginSet *new_plugin_set = plugin_set.append(new PluginSet(edl, this));
201 new_plugin_set->copy_from(track->plugin_set.values[i]);
203 automation->copy_from(track->automation);
204 this->track_w = track->track_w;
205 this->track_h = track->track_h;
208 Track& Track::operator=(Track& track)
210 printf("Track::operator= 1\n");
215 int Track::vertical_span(Theme *theme)
219 result += theme->get_image("title_bg_data")->get_h();
221 result += edl->local_session->zoom_track;
223 result += plugin_set.total * theme->get_image("plugin_bg_data")->get_h();
224 result = MAX(result, theme->title_h);
228 double Track::get_length()
230 double total_length = 0;
236 length = from_units(edits->last->startproject + edits->last->length);
237 if(length > total_length) total_length = length;
241 for(int i = 0; i < plugin_set.total; i++)
243 if( !plugin_set.values[i]->last ) continue;
244 length = from_units(plugin_set.values[i]->last->startproject +
245 plugin_set.values[i]->last->length);
246 if(length > total_length) total_length = length;
250 length = from_units(automation->get_length());
251 if(length > total_length) total_length = length;
257 int Track::has_speed()
259 FloatAutos *autos = (FloatAutos*)automation->autos[AUTOMATION_SPEED];
264 for(FloatAuto *current = (FloatAuto*)autos->first;
266 current = (FloatAuto*)current->next)
268 if(!EQUIV(current->get_value(), 1.0) ||
269 !EQUIV(current->get_control_in_value(), 0.0) ||
270 !EQUIV(current->get_control_out_value(), 0.0))
281 int Track::show_assets()
283 return expand_view || edl->session->show_assets ? 1 : 0;
286 int Track::show_titles()
288 return expand_view || edl->session->show_titles ? 1 : 0;
291 int Track::show_transitions()
293 return expand_view || edl->session->auto_conf->transitions ? 1 : 0;
296 void Track::get_source_dimensions(double position, int &w, int &h)
298 int64_t native_position = to_units(position, 0);
299 for(Edit *current = edits->first; current; current = NEXT)
301 if(current->startproject <= native_position &&
302 current->startproject + current->length > native_position &&
305 w = current->asset->width;
306 h = current->asset->height;
313 int64_t Track::horizontal_span()
315 return (int64_t)(get_length() *
316 edl->session->sample_rate /
317 edl->local_session->zoom_sample +
322 int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
325 int current_plugin = 0;
328 record = file->tag.get_property("RECORD", record);
329 play = file->tag.get_property("PLAY", play);
330 gang = file->tag.get_property("GANG", gang);
331 draw = file->tag.get_property("DRAW", draw);
332 nudge = file->tag.get_property("NUDGE", nudge);
333 mixer_id = file->tag.get_property("MIXER_ID", mixer_id);
334 expand_view = file->tag.get_property("EXPAND", expand_view);
335 track_w = file->tag.get_property("TRACK_W", track_w);
336 track_h = file->tag.get_property("TRACK_H", track_h);
338 load_header(file, load_flags);
341 result = file->read_tag();
345 if(file->tag.title_is("/TRACK"))
350 if(file->tag.title_is("TITLE"))
353 file->read_text_until("/TITLE", &data);
354 memset(title, 0, sizeof(title));
355 strncpy(title, data.cstr(), sizeof(title)-1);
358 if(load_flags && automation->load(file)
359 /* strstr(file->tag.get_title(), "AUTOS") */)
364 if(file->tag.title_is("EDITS"))
366 if(load_flags & LOAD_EDITS)
367 edits->load(file, track_offset);
369 result = file->skip_tag();
372 if(file->tag.title_is("PLUGINSET"))
374 if(load_flags & LOAD_EDITS)
376 PluginSet *plugin_set = new PluginSet(edl, this);
377 this->plugin_set.append(plugin_set);
378 plugin_set->load(file, load_flags);
381 if(load_flags & LOAD_AUTOMATION)
383 if(current_plugin < this->plugin_set.total)
385 PluginSet *plugin_set = this->plugin_set.values[current_plugin];
386 plugin_set->load(file, load_flags);
391 result = file->skip_tag();
394 load_derived(file, load_flags);
403 void Track::insert_asset(Asset *asset,
409 edits->insert_asset(asset,
412 to_units(position, 0),
418 // Default keyframes: We don't replace default keyframes in pasting but
419 // when inserting the first EDL of a load operation we need to replace
420 // the default keyframes.
422 // Plugins: This is an arbitrary behavior
424 // 1) No plugin in source track: Paste silence into destination
426 // 2) Plugin in source track: plugin in source track is inserted into
427 // existing destination track plugin sets, new sets being added when
430 void Track::insert_track(Track *track,
437 // Calculate minimum length of data to pad.
438 int64_t min_length = to_units(
439 MAX(edl_length, track->get_length()),
441 //printf("Track::insert_track %d %s %jd\n", __LINE__, title, min_length);
443 // Decide whether to copy settings based on load_mode
444 if(replace_default) copy_settings(track);
446 edits->insert_edits(track->edits,
447 to_units(position, 0),
452 insert_plugin_set(track,
453 to_units(position, 0),
458 automation->insert_track(track->automation,
459 to_units(position, 0),
467 // Called by insert_track
468 void Track::insert_plugin_set(Track *track,
473 // Extend plugins if no incoming plugins
474 if( track->plugin_set.total ) {
475 for(int i = 0; i < track->plugin_set.total; i++) {
476 if(i >= plugin_set.total)
477 plugin_set.append(new PluginSet(edl, this));
479 plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
480 position, min_length, edit_autos);
484 shift_effects(position, min_length, edit_autos, 0);
488 Plugin* Track::insert_effect(const char *title,
489 SharedLocation *shared_location,
490 KeyFrame *default_keyframe,
491 PluginSet *plugin_set,
498 plugin_set = new PluginSet(edl, this);
499 this->plugin_set.append(plugin_set);
504 // Position is identical to source plugin
505 if(plugin_type == PLUGIN_SHAREDPLUGIN)
507 Track *source_track = tracks->get_item_number(shared_location->module);
510 Plugin *source_plugin = source_track->get_current_plugin(
511 edl->local_session->get_selectionstart(1),
512 shared_location->plugin,
517 // From an attach operation
520 plugin = plugin_set->insert_plugin(title,
521 source_plugin->startproject,
522 source_plugin->length,
529 // From a drag operation
531 plugin = plugin_set->insert_plugin(title,
543 // This should be done in the caller
546 if(edl->local_session->get_selectionend() >
547 edl->local_session->get_selectionstart())
549 start = edl->local_session->get_selectionstart();
550 length = edl->local_session->get_selectionend() - start;
555 length = get_length();
558 //printf("Track::insert_effect %f %f %d %d\n", start, length, to_units(start, 0),
559 // to_units(length, 0));
561 plugin = plugin_set->insert_plugin(title,
569 //printf("Track::insert_effect 2 %f %f\n", start, length);
575 void Track::move_plugins_up(PluginSet *plugin_set)
577 for(int i = 0; i < this->plugin_set.total; i++)
579 if(this->plugin_set.values[i] == plugin_set)
583 PluginSet *temp = this->plugin_set.values[i - 1];
584 this->plugin_set.values[i - 1] = this->plugin_set.values[i];
585 this->plugin_set.values[i] = temp;
587 SharedLocation old_location, new_location;
588 new_location.module = old_location.module = tracks->number_of(this);
589 old_location.plugin = i;
590 new_location.plugin = i - 1;
591 tracks->change_plugins(old_location, new_location, 1);
597 void Track::move_plugins_down(PluginSet *plugin_set)
599 for(int i = 0; i < this->plugin_set.total; i++)
601 if(this->plugin_set.values[i] == plugin_set)
603 if(i == this->plugin_set.total - 1) break;
605 PluginSet *temp = this->plugin_set.values[i + 1];
606 this->plugin_set.values[i + 1] = this->plugin_set.values[i];
607 this->plugin_set.values[i] = temp;
609 SharedLocation old_location, new_location;
610 new_location.module = old_location.module = tracks->number_of(this);
611 old_location.plugin = i;
612 new_location.plugin = i + 1;
613 tracks->change_plugins(old_location, new_location, 1);
620 void Track::remove_asset(Indexable *asset)
622 for(Edit *edit = edits->first; edit; edit = edit->next)
624 if(asset->is_asset &&
626 edit->asset == (Asset*)asset)
631 if(!asset->is_asset &&
633 edit->nested_edl == (EDL*)asset)
635 edit->nested_edl = 0;
641 void Track::remove_pluginset(PluginSet *plugin_set)
644 for(i = 0; i < this->plugin_set.total; i++)
645 if(plugin_set == this->plugin_set.values[i]) break;
647 this->plugin_set.remove_object(plugin_set);
648 for(i++ ; i < this->plugin_set.total; i++)
650 SharedLocation old_location, new_location;
651 new_location.module = old_location.module = tracks->number_of(this);
652 old_location.plugin = i;
653 new_location.plugin = i - 1;
654 tracks->change_plugins(old_location, new_location, 0);
658 void Track::shift_keyframes(int64_t position, int64_t length)
660 automation->paste_silence(position, position + length);
661 // Effect keyframes are shifted in shift_effects
664 void Track::shift_effects(int64_t position, int64_t length, int edit_autos, Edits *trim_edits)
666 for( int i=0; i<plugin_set.total; ++i ) {
667 if( !trim_edits || trim_edits == (Edits*)plugin_set.values[i] )
668 plugin_set.values[i]->shift_effects(position, length, edit_autos);
672 void Track::detach_effect(Plugin *plugin)
674 //printf("Track::detach_effect 1\n");
675 for(int i = 0; i < plugin_set.total; i++)
677 PluginSet *plugin_set = this->plugin_set.values[i];
678 for(Plugin *dest = (Plugin*)plugin_set->first;
680 dest = (Plugin*)dest->next)
684 int64_t start = plugin->startproject;
685 int64_t end = plugin->startproject + plugin->length;
687 plugin_set->clear(start, end, 1);
689 //printf("Track::detach_effect 2 %d\n", plugin_set->length());
690 // Delete 0 length pluginsets
697 void Track::resample(double old_rate, double new_rate)
699 edits->resample(old_rate, new_rate);
700 automation->resample(old_rate, new_rate);
701 for(int i = 0; i < plugin_set.total; i++)
702 plugin_set.values[i]->resample(old_rate, new_rate);
703 nudge = (int64_t)(nudge * new_rate / old_rate);
706 void Track::detach_shared_effects(int module)
708 for(int i = 0; i < plugin_set.size(); i++) {
709 PluginSet *plugin_set = this->plugin_set.get(i);
710 for(Plugin *dest = (Plugin*)plugin_set->first; dest; ) {
711 if( (dest->plugin_type == PLUGIN_SHAREDPLUGIN ||
712 dest->plugin_type == PLUGIN_SHAREDMODULE) &&
713 dest->shared_location.module == module ) {
714 int64_t start = dest->startproject;
715 int64_t end = dest->startproject + dest->length;
716 plugin_set->clear(start, end, 1);
719 if(dest) dest = (Plugin*)dest->next;
726 void Track::optimize()
729 for(int i = 0; i < plugin_set.total; ) {
730 PluginSet *plugin_set = this->plugin_set.values[i];
731 plugin_set->optimize();
732 //printf("Track::optimize %d\n", plugin_set.values[i]->total());
733 // new definition of empty track...
734 if( !plugin_set->last ||
735 (plugin_set->last == plugin_set->first &&
736 plugin_set->last->silence()) ) {
737 remove_pluginset(plugin_set);
744 Plugin* Track::get_current_plugin(double position,
751 if(convert_units) position = to_units(position, 0);
752 if(use_nudge) position += nudge;
754 if(plugin_set >= this->plugin_set.total || plugin_set < 0) return 0;
756 //printf("Track::get_current_plugin 1 %d %d %d\n", position, this->plugin_set.total, direction);
757 if(direction == PLAY_FORWARD)
759 for(current = (Plugin*)this->plugin_set.values[plugin_set]->last;
761 current = (Plugin*)PREVIOUS)
763 // printf("Track::get_current_plugin 2 %d %ld %ld\n",
764 // current->startproject,
765 // current->startproject + current->length,
767 if(current->startproject <= position &&
768 current->startproject + current->length > position)
775 if(direction == PLAY_REVERSE)
777 for(current = (Plugin*)this->plugin_set.values[plugin_set]->first;
779 current = (Plugin*)NEXT)
781 if(current->startproject < position &&
782 current->startproject + current->length >= position)
792 Plugin* Track::get_current_transition(double position,
799 if(convert_units) position = to_units(position, 0);
800 if(use_nudge) position += nudge;
802 if(direction == PLAY_FORWARD)
804 for(current = edits->last; current; current = PREVIOUS)
806 if(current->startproject <= position && current->startproject + current->length > position)
808 //printf("Track::get_current_transition %p\n", current->transition);
809 if(current->transition && position < current->startproject + current->transition->length)
811 result = current->transition;
818 if(direction == PLAY_REVERSE)
820 for(current = edits->first; current; current = NEXT)
822 if(current->startproject < position && current->startproject + current->length >= position)
824 if(current->transition && position <= current->startproject + current->transition->length)
826 result = current->transition;
836 void Track::synchronize_params(Track *track)
838 for(Edit *this_edit = edits->first, *that_edit = track->edits->first;
839 this_edit && that_edit;
840 this_edit = this_edit->next, that_edit = that_edit->next)
842 this_edit->synchronize_params(that_edit);
845 for(int i = 0; i < plugin_set.total && i < track->plugin_set.total; i++)
846 plugin_set.values[i]->synchronize_params(track->plugin_set.values[i]);
848 automation->copy_from(track->automation);
849 this->nudge = track->nudge;
853 int Track::dump(FILE *fp)
855 fprintf(fp," Data type %d, draw %d, gang %d, play %d, record %d, nudge %jd\n",
856 data_type, draw, gang, play, record, nudge);
857 fprintf(fp," Title %s\n", title);
858 fprintf(fp," Edits:\n");
859 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[i]->dump(fp);
870 Track::Track() : ListItem<Track>()
875 // ======================================== accounting
877 int Track::number_of()
879 return tracks->number_of(this);
894 // ================================================= editing
896 int Track::select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y)
901 int Track::move_auto(AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
906 int Track::release_auto()
911 // used for copying automation alone
912 int Track::copy_automation(double selectionstart,
918 int64_t start = to_units(selectionstart, 0);
919 int64_t end = to_units(selectionend, 1);
921 file->tag.set_title("TRACK");
925 file->append_newline();
927 automation->copy(start, end, file, default_only, active_only);
929 if(edl->session->auto_conf->plugins)
931 for(int i = 0; i < plugin_set.total; i++)
934 plugin_set.values[i]->copy_keyframes(start,
942 file->tag.set_title("/TRACK");
944 file->append_newline();
945 file->append_newline();
946 file->append_newline();
947 file->append_newline();
952 int Track::paste_automation(double selectionstart,
960 // Only used for pasting automation alone.
965 int current_pluginset;
967 if(data_type == TRACK_AUDIO)
968 scale = edl->session->sample_rate / sample_rate;
970 scale = edl->session->frame_rate / frame_rate;
972 total_length *= scale;
973 start = to_units(selectionstart, 0);
974 length = to_units(total_length, 1);
976 current_pluginset = 0;
977 //printf("Track::paste_automation 1\n");
981 result = file->read_tag();
985 if(file->tag.title_is("/TRACK"))
988 if(automation->paste(start, length, scale, file,
989 default_only, active_only, 0)) {}
990 else if(file->tag.title_is("PLUGINSET")) {
991 if(current_pluginset < plugin_set.total) {
992 plugin_set.values[current_pluginset]->
993 paste_keyframes(start, length, file,
994 default_only, active_only);
1005 void Track::clear_automation(double selectionstart,
1006 double selectionend,
1010 int64_t start = to_units(selectionstart, 0);
1011 int64_t end = to_units(selectionend, 1);
1013 automation->clear(start, end, edl->session->auto_conf, 0);
1015 if(edl->session->auto_conf->plugins)
1017 for(int i = 0; i < plugin_set.total; i++)
1019 plugin_set.values[i]->clear_keyframes(start, end);
1025 void Track::set_automation_mode(double selectionstart,
1026 double selectionend,
1029 int64_t start = to_units(selectionstart, 0);
1030 int64_t end = to_units(selectionend, 1);
1032 automation->set_automation_mode(start, end, mode, edl->session->auto_conf);
1038 int Track::copy(int copy_flags, double start, double end,
1039 FileXML *file, const char *output_path)
1041 // Use a copy of the selection in converted units
1042 // So copy_automation doesn't reconvert.
1043 int64_t start_unit = to_units(start, 0);
1044 int64_t end_unit = to_units(end, 1);
1049 file->tag.set_title("TRACK");
1050 file->tag.set_property("RECORD", record);
1051 file->tag.set_property("NUDGE", nudge);
1052 file->tag.set_property("MIXER_ID", mixer_id);
1053 file->tag.set_property("PLAY", play);
1054 file->tag.set_property("GANG", gang);
1055 file->tag.set_property("DRAW", draw);
1056 file->tag.set_property("EXPAND", expand_view);
1057 file->tag.set_property("TRACK_W", track_w);
1058 file->tag.set_property("TRACK_H", track_h);
1061 file->append_newline();
1064 file->tag.set_title("TITLE");
1066 file->append_text(title);
1067 file->tag.set_title("/TITLE");
1069 file->append_newline();
1071 // if(data_type == TRACK_AUDIO)
1072 // file->tag.set_property("TYPE", "AUDIO");
1074 // file->tag.set_property("TYPE", "VIDEO");
1076 // file->append_tag();
1077 // file->append_newline();
1079 if( (copy_flags & COPY_EDITS) )
1080 edits->copy(start_unit, end_unit, file, output_path);
1082 if( (copy_flags & COPY_AUTOS) ) {
1084 auto_conf.set_all(1);
1085 automation->copy(start_unit, end_unit, file, 0, 0);
1088 if( (copy_flags & COPY_PLUGINS) ) {
1089 for( int i=0; i<plugin_set.total; ++i )
1090 plugin_set.values[i]->copy(start_unit, end_unit, file);
1093 copy_derived(start_unit, end_unit, file);
1095 file->tag.set_title("/TRACK");
1097 file->append_newline();
1098 file->append_newline();
1099 file->append_newline();
1100 file->append_newline();
1105 int Track::copy_assets(double start,
1107 ArrayList<Asset*> *asset_list)
1111 start = to_units(start, 0);
1112 end = to_units(end, 1);
1114 Edit *current = edits->editof((int64_t)start, PLAY_FORWARD, 0);
1117 while(current && current->startproject < end)
1119 // Check for duplicate assets
1122 for(i = 0, result = 0; i < asset_list->total; i++)
1124 if(asset_list->values[i] == current->asset) result = 1;
1126 // append pointer to new asset
1127 if(!result) asset_list->append(current->asset);
1136 int Track::blade(double position)
1138 int64_t start = to_units(position, 0);
1139 Edit *edit = edits->split_edit(start);
1140 if( !edit ) return 1;
1141 edit->hard_left = 1;
1142 if( edit->previous ) edit->previous->hard_right = 1;
1146 int Track::clear(double start, double end,
1147 int edit_edits, int edit_labels, int edit_plugins,
1148 int edit_autos, Edits *trim_edits)
1150 return clear(to_units(start, 0), to_units(end, 1),
1151 edit_edits, edit_labels, edit_plugins, edit_autos, trim_edits);
1154 int Track::clear(int64_t start, int64_t end,
1155 int edit_edits, int edit_labels, int edit_plugins,
1156 int edit_autos, Edits *trim_edits)
1158 //printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
1160 automation->clear(start, end, 0, 1);
1161 if( edit_plugins ) {
1162 int edit_keyframes = edit_plugins < 0 ? 1 : edit_autos;
1163 for(int i = 0; i < plugin_set.total; i++) {
1164 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1165 plugin_set.values[i]->clear(start, end, edit_keyframes);
1169 edits->clear(start, end);
1173 int Track::clear_handle(double start,
1180 edits->clear_handle(start, end, clear_plugins, edit_autos, distance);
1184 int Track::popup_transition(int cursor_x, int cursor_y)
1191 int Track::modify_edithandles(double oldposition, double newposition,
1192 int currentend, int handle_mode, int edit_labels,
1193 int edit_plugins, int edit_autos, int group_id)
1195 edits->modify_handles(oldposition, newposition,
1196 currentend, handle_mode, 1, edit_labels, edit_plugins,
1197 edit_autos, 0, group_id);
1201 int Track::modify_pluginhandles(double oldposition,
1209 for(int i = 0; i < plugin_set.total; i++)
1211 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1212 plugin_set.values[i]->modify_handles(oldposition, newposition,
1213 // Don't allow plugin tweeks to affect edits.
1214 currentend, handle_mode, 0, 0, 0, 0, 0, 0);
1220 int Track::paste_silence(double start, double end, int edit_plugins, int edit_autos)
1222 return paste_silence(to_units(start, 0), to_units(end, 1),
1223 edit_plugins, edit_autos);
1226 int Track::paste_silence(int64_t start, int64_t end, int edit_plugins, int edit_autos)
1228 edits->paste_silence(start, end);
1230 shift_keyframes(start, end - start);
1232 shift_effects(start, end - start, edit_autos, 0);
1237 int Track::select_edit(int cursor_x,
1245 int Track::scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end)
1250 void Track::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
1252 for(int i = 0; i < plugin_set.total; i++)
1254 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1256 plugin = (Plugin*)plugin->next)
1258 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
1260 if(plugin->shared_location == old_location)
1261 plugin->shared_location = new_location;
1263 if(do_swap && plugin->shared_location == new_location)
1264 plugin->shared_location = old_location;
1270 void Track::change_modules(int old_location, int new_location, int do_swap)
1272 for(int i = 0; i < plugin_set.total; i++)
1274 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1276 plugin = (Plugin*)plugin->next)
1278 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN ||
1279 plugin->plugin_type == PLUGIN_SHAREDMODULE)
1281 if(plugin->shared_location.module == old_location)
1282 plugin->shared_location.module = new_location;
1284 if(do_swap && plugin->shared_location.module == new_location)
1285 plugin->shared_location.module = old_location;
1292 int Track::playable_edit(int64_t position, int direction)
1295 if(direction == PLAY_REVERSE) position--;
1296 for(Edit *current = edits->first; current && !result; current = NEXT)
1298 if(current->startproject <= position &&
1299 current->startproject + current->length > position)
1301 //printf("Track::playable_edit %p %p\n", current->transition, current->asset);
1302 if(current->transition ||
1304 current->nested_edl) result = 1;
1311 int Track::need_edit(Edit *current, int test_transitions)
1313 return ((test_transitions && current->transition) ||
1314 (!test_transitions && current->asset));
1317 int64_t Track::plugin_change_duration(int64_t input_position,
1318 int64_t input_length,
1322 if(use_nudge) input_position += nudge;
1323 for(int i = 0; i < plugin_set.total; i++)
1325 int64_t new_duration = plugin_set.values[i]->plugin_change_duration(
1329 if(new_duration < input_length) input_length = new_duration;
1331 return input_length;
1334 int64_t Track::edit_change_duration(int64_t input_position,
1335 int64_t input_length,
1337 int test_transitions,
1341 int64_t edit_length = input_length;
1342 if(use_nudge) input_position += nudge;
1346 // ================================= Reverse playback
1347 // Get first edit on or after position
1348 for(current = edits->first;
1349 current && current->startproject + current->length <= input_position;
1355 if(current->startproject > input_position)
1357 // Before first edit
1361 if(need_edit(current, test_transitions))
1363 // Over an edit of interest.
1364 if(input_position - current->startproject < input_length)
1365 edit_length = input_position - current->startproject + 1;
1369 // Over an edit that isn't of interest.
1370 // Search for next edit of interest.
1371 for(current = PREVIOUS ;
1373 current->startproject + current->length > input_position - input_length &&
1374 !need_edit(current, test_transitions);
1379 need_edit(current, test_transitions) &&
1380 current->startproject + current->length > input_position - input_length)
1381 edit_length = input_position - current->startproject - current->length + 1;
1386 // Not over an edit. Try the last edit.
1387 current = edits->last;
1389 ((test_transitions && current->transition) ||
1390 (!test_transitions && current->asset)))
1391 edit_length = input_position - edits->length() + 1;
1396 // =================================== forward playback
1397 // Get first edit on or before position
1398 for(current = edits->last;
1399 current && current->startproject > input_position;
1405 if(current->startproject + current->length <= input_position)
1407 // Beyond last edit.
1411 if(need_edit(current, test_transitions))
1413 // Over an edit of interest.
1414 // Next edit is going to require a change.
1415 if(current->length + current->startproject - input_position < input_length)
1416 edit_length = current->startproject + current->length - input_position;
1420 // Over an edit that isn't of interest.
1421 // Search for next edit of interest.
1422 for(current = NEXT ;
1424 current->startproject < input_position + input_length &&
1425 !need_edit(current, test_transitions);
1430 need_edit(current, test_transitions) &&
1431 current->startproject < input_position + input_length)
1432 edit_length = current->startproject - input_position;
1437 // Not over an edit. Try the first edit.
1438 current = edits->first;
1440 ((test_transitions && current->transition) ||
1441 (!test_transitions && current->asset)))
1442 edit_length = edits->first->startproject - input_position;
1446 if(edit_length < input_length)
1449 return input_length;
1452 void Track::shuffle_edits(double start, double end, int first_track)
1454 ArrayList<Edit*> new_edits;
1455 ArrayList<Label*> new_labels;
1456 int64_t start_units = to_units(start, 0);
1457 int64_t end_units = to_units(end, 0);
1458 // Sample range of all edits selected
1459 //int64_t total_start_units = 0;
1460 //int64_t total_end_units = 0;
1461 // Edit before range
1462 Edit *start_edit = 0;
1463 int have_start_edit = 0;
1465 // Move all edit pointers to list
1466 for(Edit *current = edits->first;
1469 if(current->startproject >= start_units &&
1470 current->startproject + current->length <= end_units)
1472 if(!have_start_edit) start_edit = current->previous;
1473 have_start_edit = 1;
1474 //total_start_units = current->startproject;
1475 //total_end_units = current->startproject + current->length;
1476 new_edits.append(current);
1478 // Move label pointers
1479 if(first_track && edl->session->labels_follow_edits)
1481 double start_seconds = from_units(current->startproject);
1482 double end_seconds = from_units(current->startproject +
1484 for(Label *label = edl->labels->first;
1486 label = label->next)
1488 if(label->position >= start_seconds &&
1489 label->position < end_seconds)
1491 new_labels.append(label);
1492 edl->labels->remove_pointer(label);
1497 // Remove edit pointer
1498 Edit *previous = current;
1500 edits->remove_pointer(previous);
1508 // Insert pointers in random order
1509 while(new_edits.size())
1511 int index = rand() % new_edits.size();
1512 Edit *edit = new_edits.get(index);
1513 new_edits.remove_number(index);
1515 edits->insert_before(edits->first, edit);
1517 edits->insert_after(start_edit, edit);
1520 // Recalculate start position
1521 // Save old position for moving labels
1522 int64_t startproject1 = edit->startproject;
1523 int64_t startproject2 = 0;
1526 edit->startproject =
1528 edit->previous->startproject + edit->previous->length;
1532 edit->startproject = startproject2 = 0;
1536 // Insert label pointers
1537 if(first_track && edl->session->labels_follow_edits)
1539 double start_seconds1 = from_units(startproject1);
1540 double end_seconds1 = from_units(startproject1 + edit->length);
1541 double start_seconds2 = from_units(startproject2);
1542 for(int i = new_labels.size() - 1; i >= 0; i--)
1544 Label *label = new_labels.get(i);
1545 // Was in old edit position
1546 if(label->position >= start_seconds1 &&
1547 label->position < end_seconds1)
1549 // Move to new edit position
1550 double position = label->position -
1551 start_seconds1 + start_seconds2;
1552 edl->labels->insert_label(position);
1553 new_labels.remove_object_number(i);
1563 if(first_track && edl->session->labels_follow_edits)
1565 edl->labels->optimize();
1569 // exactly the same as shuffle_edits except for 1 line
1570 void Track::reverse_edits(double start, double end, int first_track)
1572 ArrayList<Edit*> new_edits;
1573 ArrayList<Label*> new_labels;
1574 int64_t start_units = to_units(start, 0);
1575 int64_t end_units = to_units(end, 0);
1576 // Sample range of all edits selected
1577 //int64_t total_start_units = 0;
1578 //int64_t total_end_units = 0;
1579 // Edit before range
1580 Edit *start_edit = 0;
1581 int have_start_edit = 0;
1583 // Move all edit pointers to list
1584 for(Edit *current = edits->first; current; )
1586 if(current->startproject >= start_units &&
1587 current->startproject + current->length <= end_units)
1589 if(!have_start_edit) start_edit = current->previous;
1590 have_start_edit = 1;
1591 //total_start_units = current->startproject;
1592 //total_end_units = current->startproject + current->length;
1593 new_edits.append(current);
1595 // Move label pointers
1596 if(first_track && edl->session->labels_follow_edits)
1598 double start_seconds = from_units(current->startproject);
1599 double end_seconds = from_units(current->startproject +
1601 for(Label *label = edl->labels->first;
1603 label = label->next)
1605 if(label->position >= start_seconds &&
1606 label->position < end_seconds)
1608 new_labels.append(label);
1609 edl->labels->remove_pointer(label);
1614 // Remove edit pointer
1615 Edit *previous = current;
1617 edits->remove_pointer(previous);
1625 // Insert pointers in reverse order
1626 while(new_edits.size())
1628 int index = new_edits.size() - 1;
1629 Edit *edit = new_edits.get(index);
1630 new_edits.remove_number(index);
1632 edits->insert_before(edits->first, edit);
1634 edits->insert_after(start_edit, edit);
1637 // Recalculate start position
1638 // Save old position for moving labels
1639 int64_t startproject1 = edit->startproject;
1640 int64_t startproject2 = 0;
1643 edit->startproject =
1645 edit->previous->startproject + edit->previous->length;
1649 edit->startproject = startproject2 = 0;
1653 // Insert label pointers
1654 if(first_track && edl->session->labels_follow_edits)
1656 double start_seconds1 = from_units(startproject1);
1657 double end_seconds1 = from_units(startproject1 + edit->length);
1658 double start_seconds2 = from_units(startproject2);
1659 for(int i = new_labels.size() - 1; i >= 0; i--)
1661 Label *label = new_labels.get(i);
1662 // Was in old edit position
1663 if(label->position >= start_seconds1 &&
1664 label->position < end_seconds1)
1666 // Move to new edit position
1667 double position = label->position -
1668 start_seconds1 + start_seconds2;
1669 edl->labels->insert_label(position);
1670 new_labels.remove_object_number(i);
1680 if(first_track && edl->session->labels_follow_edits)
1682 edl->labels->optimize();
1686 void Track::align_edits(double start,
1688 ArrayList<double> *times)
1690 int64_t start_units = to_units(start, 0);
1691 int64_t end_units = to_units(end, 0);
1693 // If 1st track with data, times is empty & we need to collect the edit times.
1696 for(Edit *current = edits->first; current; current = NEXT)
1698 if(current->startproject >= start_units &&
1699 current->startproject + current->length <= end_units)
1701 times->append(from_units(current->startproject));
1706 // All other tracks get silence or cut to align the edits on the times.
1708 int current_time = 0;
1709 for(Edit *current = edits->first;
1710 current && current_time < times->size(); )
1712 if(current->startproject >= start_units &&
1713 current->startproject + current->length <= end_units)
1715 int64_t desired_startunits = to_units(times->get(current_time), 0);
1716 int64_t current_startunits = current->startproject;
1720 if(current_startunits < desired_startunits)
1722 //printf("Track::align_edits %d\n", __LINE__);
1723 edits->paste_silence(current_startunits,
1724 desired_startunits);
1725 shift_keyframes(current_startunits,
1726 desired_startunits - current_startunits);
1729 if(current_startunits > desired_startunits)
1731 edits->clear(desired_startunits,
1732 current_startunits);
1733 if(edl->session->autos_follow_edits)
1734 shift_keyframes(desired_startunits,
1735 current_startunits - desired_startunits);
1750 int Track::purge_asset(Asset *asset)
1755 int Track::asset_used(Asset *asset)
1760 for(current_edit = edits->first; current_edit; current_edit = current_edit->next)
1762 if(current_edit->asset == asset)
1770 int Track::is_playable(int64_t position, int direction)
1776 int Track::plugin_used(int64_t position, int64_t direction)
1778 //printf("Track::plugin_used 1 %d\n", this->plugin_set.total);
1779 for(int i = 0; i < this->plugin_set.total; i++)
1781 Plugin *current_plugin = get_current_plugin(position,
1787 //printf("Track::plugin_used 2 %p %d %d\n", current_plugin, current_plugin->on, current_plugin->plugin_type);
1788 if(current_plugin &&
1789 current_plugin->on &&
1790 current_plugin->plugin_type != PLUGIN_NONE)
1795 //printf("Track::plugin_used 3 %p\n", current_plugin);
1799 // Audio is always rendered through VConsole
1800 int Track::direct_copy_possible(int64_t start, int direction, int use_nudge)
1805 int64_t Track::to_units(double position, int round)
1807 return (int64_t)position;
1810 double Track::to_doubleunits(double position)
1815 double Track::from_units(int64_t position)
1817 return (double)position;
1820 int64_t Track::frame_align(int64_t position, int round)
1822 if( data_type != TRACK_VIDEO && edl->session->cursor_on_frames )
1823 position = to_units(edl->align_to_frame(from_units(position), round), round);
1827 int Track::plugin_exists(Plugin *plugin)
1829 for(int number = 0; number < plugin_set.size(); number++)
1831 PluginSet *ptr = plugin_set.get(number);
1832 for(Plugin *current_plugin = (Plugin*)ptr->first;
1834 current_plugin = (Plugin*)current_plugin->next)
1836 if(current_plugin == plugin) return 1;
1840 for(Edit *current = edits->first; current; current = NEXT)
1842 if(current->transition &&
1843 (Plugin*)current->transition == plugin) return 1;
1850 int Track::get_mixer_id()
1852 if( mixer_id < 0 ) {
1854 for( Track *track=tracks->first; track!=0; track=track->next )
1855 if( track->mixer_id > v ) v = track->mixer_id;