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"
36 #include "localsession.h"
41 #include "pluginset.h"
42 #include "mainsession.h"
46 #include "trackcanvas.h"
48 #include "transition.h"
49 #include "transportque.inc"
55 Track::Track(EDL *edl, Tracks *tracks) : ListItem<Track>()
58 this->tracks = tracks;
67 track_w = edl->session->output_w;
68 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->play = track->play;
92 this->track_w = track->track_w;
93 this->track_h = track->track_h;
94 strcpy(this->title, track->title);
104 int Track::load_defaults(BC_Hash *defaults)
109 void Track::equivalent_output(Track *track, double *result)
111 if(data_type != track->data_type ||
112 track_w != track->track_w ||
113 track_h != track->track_h ||
114 play != track->play ||
115 nudge != track->nudge)
118 // Convert result to track units
119 int64_t result2 = -1;
120 automation->equivalent_output(track->automation, &result2);
121 edits->equivalent_output(track->edits, &result2);
123 int plugin_sets = MIN(plugin_set.total, track->plugin_set.total);
124 // Test existing plugin sets
125 for(int i = 0; i < plugin_sets; i++)
127 plugin_set.values[i]->equivalent_output(
128 track->plugin_set.values[i],
132 // New EDL has more plugin sets. Get starting plugin in new plugin sets
133 for(int i = plugin_sets; i < plugin_set.total; i++)
135 Plugin *current = plugin_set.values[i]->get_first_plugin();
138 if(result2 < 0 || current->startproject < result2)
139 result2 = current->startproject;
143 // New EDL has fewer plugin sets. Get starting plugin in old plugin set
144 for(int i = plugin_sets; i < track->plugin_set.total; i++)
146 Plugin *current = track->plugin_set.values[i]->get_first_plugin();
149 if(result2 < 0 || current->startproject < result2)
150 result2 = current->startproject;
154 // Number of plugin sets differs but somehow we didn't find the start of the
156 if(track->plugin_set.total != plugin_set.total && result2 < 0)
160 (*result < 0 || from_units(result2) < *result))
161 *result = from_units(result2);
165 int Track::is_synthesis(int64_t position,
168 int is_synthesis = 0;
169 for(int i = 0; i < plugin_set.total; i++)
171 Plugin *plugin = get_current_plugin(position,
178 // Assume data from a shared track is synthesized
179 if(plugin->plugin_type == PLUGIN_SHAREDMODULE)
182 is_synthesis = plugin->is_synthesis(position,
185 //printf("Track::is_synthesis %d %d\n", __LINE__, is_synthesis);
186 if(is_synthesis) break;
192 void Track::copy_from(Track *track)
194 copy_settings(track);
195 edits->copy_from(track->edits);
196 for(int i = 0; i < this->plugin_set.total; i++)
197 delete this->plugin_set.values[i];
198 this->plugin_set.remove_all_objects();
200 for(int i = 0; i < track->plugin_set.total; i++)
202 PluginSet *new_plugin_set = plugin_set.append(new PluginSet(edl, this));
203 new_plugin_set->copy_from(track->plugin_set.values[i]);
205 automation->copy_from(track->automation);
206 this->track_w = track->track_w;
207 this->track_h = track->track_h;
210 Track& Track::operator=(Track& track)
212 printf("Track::operator= 1\n");
217 int Track::vertical_span(Theme *theme)
221 result = edl->local_session->zoom_track +
223 theme->get_image("plugin_bg_data")->get_h();
225 result = edl->local_session->zoom_track;
227 if(edl->session->show_titles)
228 result += theme->get_image("title_bg_data")->get_h();
233 double Track::get_length()
235 double total_length = 0;
241 length = from_units(edits->last->startproject + edits->last->length);
242 if(length > total_length) total_length = length;
246 for(int i = 0; i < plugin_set.total; i++)
248 if(plugin_set.values[i]->last)
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;
257 length = from_units(automation->get_length());
258 if(length > total_length) total_length = length;
264 int Track::has_speed()
266 FloatAutos *autos = (FloatAutos*)automation->autos[AUTOMATION_SPEED];
271 for(FloatAuto *current = (FloatAuto*)autos->first;
273 current = (FloatAuto*)current->next)
275 if(!EQUIV(current->value, 1.0) ||
276 !EQUIV(current->control_in_value, 0.0) ||
277 !EQUIV(current->control_out_value, 0.0))
290 void Track::get_source_dimensions(double position, int &w, int &h)
292 int64_t native_position = to_units(position, 0);
293 for(Edit *current = edits->first; current; current = NEXT)
295 if(current->startproject <= native_position &&
296 current->startproject + current->length > native_position &&
299 w = current->asset->width;
300 h = current->asset->height;
307 int64_t Track::horizontal_span()
309 return (int64_t)(get_length() *
310 edl->session->sample_rate /
311 edl->local_session->zoom_sample +
316 int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
319 int current_plugin = 0;
322 record = file->tag.get_property("RECORD", record);
323 play = file->tag.get_property("PLAY", play);
324 gang = file->tag.get_property("GANG", gang);
325 draw = file->tag.get_property("DRAW", draw);
326 nudge = file->tag.get_property("NUDGE", nudge);
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);
360 if(file->tag.title_is("PLUGINSET"))
362 if(load_flags & LOAD_EDITS)
364 PluginSet *plugin_set = new PluginSet(edl, this);
365 this->plugin_set.append(plugin_set);
366 plugin_set->load(file, load_flags);
369 if(load_flags & LOAD_AUTOMATION)
371 if(current_plugin < this->plugin_set.total)
373 PluginSet *plugin_set = this->plugin_set.values[current_plugin];
374 plugin_set->load(file, load_flags);
380 load_derived(file, load_flags);
389 void Track::insert_asset(Asset *asset,
395 edits->insert_asset(asset,
398 to_units(position, 0),
404 // Default keyframes: We don't replace default keyframes in pasting but
405 // when inserting the first EDL of a load operation we need to replace
406 // the default keyframes.
408 // Plugins: This is an arbitrary behavior
410 // 1) No plugin in source track: Paste silence into destination
412 // 2) Plugin in source track: plugin in source track is inserted into
413 // existing destination track plugin sets, new sets being added when
416 void Track::insert_track(Track *track,
423 // Calculate minimum length of data to pad.
424 int64_t min_length = to_units(
425 MAX(edl_length, track->get_length()),
427 //printf("Track::insert_track %d %s " _LD "\n", __LINE__, title, min_length);
429 // Decide whether to copy settings based on load_mode
430 if(replace_default) copy_settings(track);
432 edits->insert_edits(track->edits,
433 to_units(position, 0),
438 insert_plugin_set(track,
439 to_units(position, 0),
444 automation->insert_track(track->automation,
445 to_units(position, 0),
453 // Called by insert_track
454 void Track::insert_plugin_set(Track *track,
459 // Extend plugins if no incoming plugins
460 if(!track->plugin_set.total)
462 shift_effects(position,
467 for(int i = 0; i < track->plugin_set.total; i++)
469 if(i >= plugin_set.total)
470 plugin_set.append(new PluginSet(edl, this));
472 plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
480 Plugin* Track::insert_effect(const char *title,
481 SharedLocation *shared_location,
482 KeyFrame *default_keyframe,
483 PluginSet *plugin_set,
490 plugin_set = new PluginSet(edl, this);
491 this->plugin_set.append(plugin_set);
496 // Position is identical to source plugin
497 if(plugin_type == PLUGIN_SHAREDPLUGIN)
499 Track *source_track = tracks->get_item_number(shared_location->module);
502 Plugin *source_plugin = source_track->get_current_plugin(
503 edl->local_session->get_selectionstart(),
504 shared_location->plugin,
509 // From an attach operation
512 plugin = plugin_set->insert_plugin(title,
513 source_plugin->startproject,
514 source_plugin->length,
521 // From a drag operation
523 plugin = plugin_set->insert_plugin(title,
535 // This should be done in the caller
538 if(edl->local_session->get_selectionend() >
539 edl->local_session->get_selectionstart())
541 start = edl->local_session->get_selectionstart();
542 length = edl->local_session->get_selectionend() - start;
547 length = get_length();
550 //printf("Track::insert_effect %f %f %d %d\n", start, length, to_units(start, 0),
551 // to_units(length, 0));
553 plugin = plugin_set->insert_plugin(title,
561 //printf("Track::insert_effect 2 %f %f\n", start, length);
567 void Track::move_plugins_up(PluginSet *plugin_set)
569 for(int i = 0; i < this->plugin_set.total; i++)
571 if(this->plugin_set.values[i] == plugin_set)
575 PluginSet *temp = this->plugin_set.values[i - 1];
576 this->plugin_set.values[i - 1] = this->plugin_set.values[i];
577 this->plugin_set.values[i] = temp;
583 void Track::move_plugins_down(PluginSet *plugin_set)
585 for(int i = 0; i < this->plugin_set.total; i++)
587 if(this->plugin_set.values[i] == plugin_set)
589 if(i == this->plugin_set.total - 1) break;
591 PluginSet *temp = this->plugin_set.values[i + 1];
592 this->plugin_set.values[i + 1] = this->plugin_set.values[i];
593 this->plugin_set.values[i] = temp;
600 void Track::remove_asset(Indexable *asset)
602 for(Edit *edit = edits->first; edit; edit = edit->next)
604 if(asset->is_asset &&
606 edit->asset == (Asset*)asset)
611 if(!asset->is_asset &&
613 edit->nested_edl == (EDL*)asset)
615 edit->nested_edl = 0;
621 void Track::remove_pluginset(PluginSet *plugin_set)
624 for(i = 0; i < this->plugin_set.total; i++)
625 if(plugin_set == this->plugin_set.values[i]) break;
627 this->plugin_set.remove_object(plugin_set);
628 for(i++ ; i < this->plugin_set.total; i++)
630 SharedLocation old_location, new_location;
631 new_location.module = old_location.module = tracks->number_of(this);
632 old_location.plugin = i;
633 new_location.plugin = i - 1;
634 tracks->change_plugins(old_location, new_location, 0);
638 void Track::shift_keyframes(int64_t position, int64_t length)
640 automation->paste_silence(position,
642 // Effect keyframes are shifted in shift_effects
645 void Track::shift_effects(int64_t position, int64_t length, int edit_autos)
647 for(int i = 0; i < plugin_set.total; i++)
649 plugin_set.values[i]->shift_effects(position,
655 void Track::detach_effect(Plugin *plugin)
657 //printf("Track::detach_effect 1\n");
658 for(int i = 0; i < plugin_set.total; i++)
660 PluginSet *plugin_set = this->plugin_set.values[i];
661 for(Plugin *dest = (Plugin*)plugin_set->first;
663 dest = (Plugin*)dest->next)
667 int64_t start = plugin->startproject;
668 int64_t end = plugin->startproject + plugin->length;
670 plugin_set->clear(start, end, 1);
671 plugin_set->paste_silence(start, end);
673 // Delete 0 length pluginsets
674 plugin_set->optimize();
675 //printf("Track::detach_effect 2 %d\n", plugin_set->length());
676 if(!plugin_set->length())
677 this->plugin_set.remove_object(plugin_set);
685 void Track::resample(double old_rate, double new_rate)
687 edits->resample(old_rate, new_rate);
688 automation->resample(old_rate, new_rate);
689 for(int i = 0; i < plugin_set.total; i++)
690 plugin_set.values[i]->resample(old_rate, new_rate);
691 nudge = (int64_t)(nudge * new_rate / old_rate);
694 void Track::detach_shared_effects(int module)
696 for(int i = 0; i < plugin_set.size(); i++)
698 PluginSet *plugin_set = this->plugin_set.get(i);
699 for(Plugin *dest = (Plugin*)plugin_set->first;
703 if ((dest->plugin_type == PLUGIN_SHAREDPLUGIN ||
704 dest->plugin_type == PLUGIN_SHAREDMODULE)
706 dest->shared_location.module == module)
708 int64_t start = dest->startproject;
709 int64_t end = dest->startproject + dest->length;
711 plugin_set->clear(start, end, 1);
712 plugin_set->paste_silence(start, end);
714 // Delete 0 length pluginsets
715 plugin_set->optimize();
716 if(!plugin_set->length())
718 this->plugin_set.remove_object_number(i);
725 if(dest) dest = (Plugin*)dest->next;
731 void Track::optimize()
734 for(int i = 0; i < plugin_set.total; i++)
736 plugin_set.values[i]->optimize();
737 //printf("Track::optimize %d\n", plugin_set.values[i]->total());
738 if(plugin_set.values[i]->total() <= 0)
740 remove_pluginset(plugin_set.values[i]);
746 Plugin* Track::get_current_plugin(double position,
753 if(convert_units) position = to_units(position, 0);
754 if(use_nudge) position += nudge;
756 if(plugin_set >= this->plugin_set.total || plugin_set < 0) return 0;
758 //printf("Track::get_current_plugin 1 %d %d %d\n", position, this->plugin_set.total, direction);
759 if(direction == PLAY_FORWARD)
761 for(current = (Plugin*)this->plugin_set.values[plugin_set]->last;
763 current = (Plugin*)PREVIOUS)
765 // printf("Track::get_current_plugin 2 %d %ld %ld\n",
766 // current->startproject,
767 // current->startproject + current->length,
769 if(current->startproject <= position &&
770 current->startproject + current->length > position)
777 if(direction == PLAY_REVERSE)
779 for(current = (Plugin*)this->plugin_set.values[plugin_set]->first;
781 current = (Plugin*)NEXT)
783 if(current->startproject < position &&
784 current->startproject + current->length >= position)
794 Plugin* Track::get_current_transition(double position,
801 if(convert_units) position = to_units(position, 0);
802 if(use_nudge) position += nudge;
804 if(direction == PLAY_FORWARD)
806 for(current = edits->last; current; current = PREVIOUS)
808 if(current->startproject <= position && current->startproject + current->length > position)
810 //printf("Track::get_current_transition %p\n", current->transition);
811 if(current->transition && position < current->startproject + current->transition->length)
813 result = current->transition;
820 if(direction == PLAY_REVERSE)
822 for(current = edits->first; current; current = NEXT)
824 if(current->startproject < position && current->startproject + current->length >= position)
826 if(current->transition && position <= current->startproject + current->transition->length)
828 result = current->transition;
838 void Track::synchronize_params(Track *track)
840 for(Edit *this_edit = edits->first, *that_edit = track->edits->first;
841 this_edit && that_edit;
842 this_edit = this_edit->next, that_edit = that_edit->next)
844 this_edit->synchronize_params(that_edit);
847 for(int i = 0; i < plugin_set.total && i < track->plugin_set.total; i++)
848 plugin_set.values[i]->synchronize_params(track->plugin_set.values[i]);
850 automation->copy_from(track->automation);
851 this->nudge = track->nudge;
858 int Track::dump(FILE *fp)
860 fprintf(fp," Data type %d\n", data_type);
861 fprintf(fp," Title %s\n", title);
862 fprintf(fp," Edits:\n");
863 for(Edit* current = edits->first; current; current = NEXT)
867 automation->dump(fp);
868 fprintf(fp," Plugin Sets: %d\n", plugin_set.total);
870 for(int i = 0; i < plugin_set.total; i++)
871 plugin_set.values[i]->dump(fp);
872 //printf("Track::dump 2\n");
896 Track::Track() : ListItem<Track>()
901 // ======================================== accounting
903 int Track::number_of()
905 return tracks->number_of(this);
920 // ================================================= editing
922 int Track::select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y)
927 int Track::move_auto(AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
932 int Track::release_auto()
937 // used for copying automation alone
938 int Track::copy_automation(double selectionstart,
944 int64_t start = to_units(selectionstart, 0);
945 int64_t end = to_units(selectionend, 0);
947 file->tag.set_title("TRACK");
951 file->append_newline();
953 automation->copy(start, end, file, default_only, active_only);
955 if(edl->session->auto_conf->plugins)
957 for(int i = 0; i < plugin_set.total; i++)
960 plugin_set.values[i]->copy_keyframes(start,
968 file->tag.set_title("/TRACK");
970 file->append_newline();
971 file->append_newline();
972 file->append_newline();
973 file->append_newline();
978 int Track::paste_automation(double selectionstart,
986 // Only used for pasting automation alone.
991 int current_pluginset;
993 if(data_type == TRACK_AUDIO)
994 scale = edl->session->sample_rate / sample_rate;
996 scale = edl->session->frame_rate / frame_rate;
998 total_length *= scale;
999 start = to_units(selectionstart, 0);
1000 length = to_units(total_length, 0);
1002 current_pluginset = 0;
1003 //printf("Track::paste_automation 1\n");
1007 result = file->read_tag();
1011 if(file->tag.title_is("/TRACK"))
1014 if(automation->paste(start,
1025 if(file->tag.title_is("PLUGINSET"))
1027 if(current_pluginset < plugin_set.total)
1029 plugin_set.values[current_pluginset]->paste_keyframes(start,
1034 current_pluginset++;
1044 void Track::clear_automation(double selectionstart,
1045 double selectionend,
1049 int64_t start = to_units(selectionstart, 0);
1050 int64_t end = to_units(selectionend, 0);
1052 automation->clear(start, end, edl->session->auto_conf, 0);
1054 if(edl->session->auto_conf->plugins)
1056 for(int i = 0; i < plugin_set.total; i++)
1058 plugin_set.values[i]->clear_keyframes(start, end);
1064 void Track::set_automation_mode(double selectionstart,
1065 double selectionend,
1068 int64_t start = to_units(selectionstart, 0);
1069 int64_t end = to_units(selectionend, 0);
1071 automation->set_automation_mode(start, end, mode, edl->session->auto_conf);
1077 int Track::copy(double start,
1080 const char *output_path)
1082 // Use a copy of the selection in converted units
1083 // So copy_automation doesn't reconvert.
1084 int64_t start_unit = to_units(start, 0);
1085 int64_t end_unit = to_units(end, 1);
1090 file->tag.set_title("TRACK");
1091 file->tag.set_property("RECORD", record);
1092 file->tag.set_property("NUDGE", nudge);
1093 file->tag.set_property("PLAY", play);
1094 file->tag.set_property("GANG", gang);
1095 file->tag.set_property("DRAW", draw);
1096 file->tag.set_property("EXPAND", expand_view);
1097 file->tag.set_property("TRACK_W", track_w);
1098 file->tag.set_property("TRACK_H", track_h);
1101 file->append_newline();
1104 file->tag.set_title("TITLE");
1106 file->append_text(title);
1107 file->tag.set_title("/TITLE");
1109 file->append_newline();
1111 // if(data_type == TRACK_AUDIO)
1112 // file->tag.set_property("TYPE", "AUDIO");
1114 // file->tag.set_property("TYPE", "VIDEO");
1116 // file->append_tag();
1117 // file->append_newline();
1119 edits->copy(start_unit, end_unit, file, output_path);
1122 auto_conf.set_all(1);
1123 automation->copy(start_unit, end_unit, file, 0, 0);
1126 for(int i = 0; i < plugin_set.total; i++)
1128 plugin_set.values[i]->copy(start_unit, end_unit, file);
1131 copy_derived(start_unit, end_unit, file);
1133 file->tag.set_title("/TRACK");
1135 file->append_newline();
1136 file->append_newline();
1137 file->append_newline();
1138 file->append_newline();
1143 int Track::copy_assets(double start,
1145 ArrayList<Asset*> *asset_list)
1149 start = to_units(start, 0);
1150 end = to_units(end, 0);
1152 Edit *current = edits->editof((int64_t)start, PLAY_FORWARD, 0);
1155 while(current && current->startproject < end)
1157 // Check for duplicate assets
1160 for(i = 0, result = 0; i < asset_list->total; i++)
1162 if(asset_list->values[i] == current->asset) result = 1;
1164 // append pointer to new asset
1165 if(!result) asset_list->append(current->asset);
1178 int Track::clear(double start,
1187 // Edits::move_auto calls this routine after the units are converted to the track
1189 //printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
1192 start = to_units(start, 0);
1193 end = to_units(end, 0);
1198 automation->clear((int64_t)start, (int64_t)end, 0, 1);
1202 for(int i = 0; i < plugin_set.total; i++)
1204 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1205 plugin_set.values[i]->clear((int64_t)start, (int64_t)end, edit_autos);
1210 edits->clear((int64_t)start, (int64_t)end);
1214 int Track::clear_handle(double start,
1221 edits->clear_handle(start, end, clear_plugins, edit_autos, distance);
1225 int Track::popup_transition(int cursor_x, int cursor_y)
1232 int Track::modify_edithandles(double oldposition,
1240 edits->modify_handles(oldposition,
1254 int Track::modify_pluginhandles(double oldposition,
1262 for(int i = 0; i < plugin_set.total; i++)
1264 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1265 plugin_set.values[i]->modify_handles(oldposition,
1269 // Don't allow plugin tweeks to affect edits.
1280 int Track::paste_silence(double start, double end, int edit_plugins, int edit_autos)
1282 int64_t start_i = to_units(start, 0);
1283 int64_t end_i = to_units(end, 1);
1285 edits->paste_silence(start_i, end_i);
1286 if(edit_autos) shift_keyframes(start_i, end_i - start_i);
1287 if(edit_plugins) shift_effects(start_i, end_i - start_i, edit_autos);
1293 int Track::select_edit(int cursor_x,
1301 int Track::scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end)
1306 void Track::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
1308 for(int i = 0; i < plugin_set.total; i++)
1310 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1312 plugin = (Plugin*)plugin->next)
1314 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
1316 if(plugin->shared_location == old_location)
1317 plugin->shared_location = new_location;
1319 if(do_swap && plugin->shared_location == new_location)
1320 plugin->shared_location = old_location;
1326 void Track::change_modules(int old_location, int new_location, int do_swap)
1328 for(int i = 0; i < plugin_set.total; i++)
1330 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1332 plugin = (Plugin*)plugin->next)
1334 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN ||
1335 plugin->plugin_type == PLUGIN_SHAREDMODULE)
1337 if(plugin->shared_location.module == old_location)
1338 plugin->shared_location.module = new_location;
1340 if(do_swap && plugin->shared_location.module == new_location)
1341 plugin->shared_location.module = old_location;
1348 int Track::playable_edit(int64_t position, int direction)
1351 if(direction == PLAY_REVERSE) position--;
1352 for(Edit *current = edits->first; current && !result; current = NEXT)
1354 if(current->startproject <= position &&
1355 current->startproject + current->length > position)
1357 //printf("Track::playable_edit %p %p\n", current->transition, current->asset);
1358 if(current->transition ||
1360 current->nested_edl) result = 1;
1367 int Track::need_edit(Edit *current, int test_transitions)
1369 return ((test_transitions && current->transition) ||
1370 (!test_transitions && current->asset));
1373 int64_t Track::plugin_change_duration(int64_t input_position,
1374 int64_t input_length,
1378 if(use_nudge) input_position += nudge;
1379 for(int i = 0; i < plugin_set.total; i++)
1381 int64_t new_duration = plugin_set.values[i]->plugin_change_duration(
1385 if(new_duration < input_length) input_length = new_duration;
1387 return input_length;
1390 int64_t Track::edit_change_duration(int64_t input_position,
1391 int64_t input_length,
1393 int test_transitions,
1397 int64_t edit_length = input_length;
1398 if(use_nudge) input_position += nudge;
1402 // ================================= Reverse playback
1403 // Get first edit on or after position
1404 for(current = edits->first;
1405 current && current->startproject + current->length <= input_position;
1411 if(current->startproject > input_position)
1413 // Before first edit
1417 if(need_edit(current, test_transitions))
1419 // Over an edit of interest.
1420 if(input_position - current->startproject < input_length)
1421 edit_length = input_position - current->startproject + 1;
1425 // Over an edit that isn't of interest.
1426 // Search for next edit of interest.
1427 for(current = PREVIOUS ;
1429 current->startproject + current->length > input_position - input_length &&
1430 !need_edit(current, test_transitions);
1435 need_edit(current, test_transitions) &&
1436 current->startproject + current->length > input_position - input_length)
1437 edit_length = input_position - current->startproject - current->length + 1;
1442 // Not over an edit. Try the last edit.
1443 current = edits->last;
1445 ((test_transitions && current->transition) ||
1446 (!test_transitions && current->asset)))
1447 edit_length = input_position - edits->last->startproject - edits->last->length + 1;
1452 // =================================== forward playback
1453 // Get first edit on or before position
1454 for(current = edits->last;
1455 current && current->startproject > input_position;
1461 if(current->startproject + current->length <= input_position)
1463 // Beyond last edit.
1467 if(need_edit(current, test_transitions))
1469 // Over an edit of interest.
1470 // Next edit is going to require a change.
1471 if(current->length + current->startproject - input_position < input_length)
1472 edit_length = current->startproject + current->length - input_position;
1476 // Over an edit that isn't of interest.
1477 // Search for next edit of interest.
1478 for(current = NEXT ;
1480 current->startproject < input_position + input_length &&
1481 !need_edit(current, test_transitions);
1486 need_edit(current, test_transitions) &&
1487 current->startproject < input_position + input_length)
1488 edit_length = current->startproject - input_position;
1493 // Not over an edit. Try the first edit.
1494 current = edits->first;
1496 ((test_transitions && current->transition) ||
1497 (!test_transitions && current->asset)))
1498 edit_length = edits->first->startproject - input_position;
1502 if(edit_length < input_length)
1505 return input_length;
1508 void Track::shuffle_edits(double start, double end, int first_track)
1510 ArrayList<Edit*> new_edits;
1511 ArrayList<Label*> new_labels;
1512 int64_t start_units = to_units(start, 0);
1513 int64_t end_units = to_units(end, 0);
1514 // Sample range of all edits selected
1515 //int64_t total_start_units = 0;
1516 //int64_t total_end_units = 0;
1517 // Edit before range
1518 Edit *start_edit = 0;
1519 int have_start_edit = 0;
1521 // Move all edit pointers to list
1522 for(Edit *current = edits->first;
1525 if(current->startproject >= start_units &&
1526 current->startproject + current->length <= end_units)
1528 if(!have_start_edit) start_edit = current->previous;
1529 have_start_edit = 1;
1530 //total_start_units = current->startproject;
1531 //total_end_units = current->startproject + current->length;
1532 new_edits.append(current);
1534 // Move label pointers
1535 if(first_track && edl->session->labels_follow_edits)
1537 double start_seconds = from_units(current->startproject);
1538 double end_seconds = from_units(current->startproject +
1540 for(Label *label = edl->labels->first;
1542 label = label->next)
1544 if(label->position >= start_seconds &&
1545 label->position < end_seconds)
1547 new_labels.append(label);
1548 edl->labels->remove_pointer(label);
1553 // Remove edit pointer
1554 Edit *previous = current;
1556 edits->remove_pointer(previous);
1564 // Insert pointers in random order
1565 while(new_edits.size())
1567 int index = rand() % new_edits.size();
1568 Edit *edit = new_edits.get(index);
1569 new_edits.remove_number(index);
1570 edits->insert_after(start_edit, edit);
1573 // Recalculate start position
1574 // Save old position for moving labels
1575 int64_t startproject1 = edit->startproject;
1576 int64_t startproject2 = 0;
1579 edit->startproject =
1581 edit->previous->startproject + edit->previous->length;
1585 edit->startproject = startproject2 = 0;
1589 // Insert label pointers
1590 if(first_track && edl->session->labels_follow_edits)
1592 double start_seconds1 = from_units(startproject1);
1593 double start_seconds2 = from_units(startproject2);
1594 //double end_seconds1 = from_units(edit->startproject +
1596 for(int i = new_labels.size() - 1; i >= 0; i--)
1598 Label *label = new_labels.get(i);
1599 // Was in old edit position
1600 if(label->position >= start_seconds1 &&
1601 label->position < start_seconds2)
1603 // Move to new edit position
1604 double position = label->position -
1607 edl->labels->insert_label(position);
1608 new_labels.remove_object_number(i);
1618 if(first_track && edl->session->labels_follow_edits)
1620 edl->labels->optimize();
1624 void Track::align_edits(double start,
1626 ArrayList<double> *times)
1628 int64_t start_units = to_units(start, 0);
1629 int64_t end_units = to_units(end, 0);
1631 // If 1st track with data, times is empty & we need to collect the edit times.
1634 for(Edit *current = edits->first; current; current = NEXT)
1636 if(current->startproject >= start_units &&
1637 current->startproject + current->length <= end_units)
1639 times->append(from_units(current->startproject));
1644 // All other tracks get silence or cut to align the edits on the times.
1646 int current_time = 0;
1647 for(Edit *current = edits->first;
1648 current && current_time < times->size(); )
1650 if(current->startproject >= start_units &&
1651 current->startproject + current->length <= end_units)
1653 int64_t desired_startunits = to_units(times->get(current_time), 0);
1654 int64_t current_startunits = current->startproject;
1658 if(current_startunits < desired_startunits)
1660 //printf("Track::align_edits %d\n", __LINE__);
1661 edits->paste_silence(current_startunits,
1662 desired_startunits);
1663 shift_keyframes(current_startunits,
1664 desired_startunits - current_startunits);
1667 if(current_startunits > desired_startunits)
1669 edits->clear(desired_startunits,
1670 current_startunits);
1671 if(edl->session->autos_follow_edits)
1672 shift_keyframes(desired_startunits,
1673 current_startunits - desired_startunits);
1688 int Track::purge_asset(Asset *asset)
1693 int Track::asset_used(Asset *asset)
1698 for(current_edit = edits->first; current_edit; current_edit = current_edit->next)
1700 if(current_edit->asset == asset)
1708 int Track::is_playable(int64_t position, int direction)
1714 int Track::plugin_used(int64_t position, int64_t direction)
1716 //printf("Track::plugin_used 1 %d\n", this->plugin_set.total);
1717 for(int i = 0; i < this->plugin_set.total; i++)
1719 Plugin *current_plugin = get_current_plugin(position,
1725 //printf("Track::plugin_used 2 %p %d %d\n", current_plugin, current_plugin->on, current_plugin->plugin_type);
1726 if(current_plugin &&
1727 current_plugin->on &&
1728 current_plugin->plugin_type != PLUGIN_NONE)
1733 //printf("Track::plugin_used 3 %p\n", current_plugin);
1737 // Audio is always rendered through VConsole
1738 int Track::direct_copy_possible(int64_t start, int direction, int use_nudge)
1743 int64_t Track::to_units(double position, int round)
1745 return (int64_t)position;
1748 double Track::to_doubleunits(double position)
1753 double Track::from_units(int64_t position)
1755 return (double)position;
1758 int Track::plugin_exists(Plugin *plugin)
1760 for(int number = 0; number < plugin_set.size(); number++)
1762 PluginSet *ptr = plugin_set.get(number);
1763 for(Plugin *current_plugin = (Plugin*)ptr->first;
1765 current_plugin = (Plugin*)current_plugin->next)
1767 if(current_plugin == plugin) return 1;
1771 for(Edit *current = edits->first; current; current = NEXT)
1773 if(current->transition &&
1774 (Plugin*)current->transition == plugin) return 1;