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"
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;
69 track_w = edl->session->output_w;
70 track_h = edl->session->output_h;
73 masks = (1<<SUBMASKS)-1;
80 plugin_set.remove_all_objects();
83 void Track::create_objects()
88 int Track::copy_settings(Track *track)
90 this->expand_view = track->expand_view;
91 this->draw = track->draw;
92 this->ganged = track->ganged;
93 this->master = track->master;
94 this->armed = track->armed;
95 this->nudge = track->nudge;
96 this->mixer_id = track->mixer_id;
97 this->play = track->play;
98 this->data_h = track->data_h;
99 this->track_w = track->track_w;
100 this->track_h = track->track_h;
101 this->masks = track->masks;
102 strcpy(this->title, track->title);
112 int Track::load_defaults(BC_Hash *defaults)
117 void Track::equivalent_output(Track *track, double *result)
119 if(data_type != track->data_type ||
120 track_w != track->track_w ||
121 track_h != track->track_h ||
122 play != track->play ||
123 nudge != track->nudge)
126 // Convert result to track units
127 int64_t result2 = -1;
128 automation->equivalent_output(track->automation, &result2);
129 edits->equivalent_output(track->edits, &result2);
131 int plugin_sets = MIN(plugin_set.total, track->plugin_set.total);
132 // Test existing plugin sets
133 for(int i = 0; i < plugin_sets; i++)
135 plugin_set.values[i]->equivalent_output(
136 track->plugin_set.values[i],
140 // New EDL has more plugin sets. Get starting plugin in new plugin sets
141 for(int i = plugin_sets; i < plugin_set.total; i++)
143 Plugin *current = plugin_set.values[i]->get_first_plugin();
146 if(result2 < 0 || current->startproject < result2)
147 result2 = current->startproject;
151 // New EDL has fewer plugin sets. Get starting plugin in old plugin set
152 for(int i = plugin_sets; i < track->plugin_set.total; i++)
154 Plugin *current = track->plugin_set.values[i]->get_first_plugin();
157 if(result2 < 0 || current->startproject < result2)
158 result2 = current->startproject;
162 // Number of plugin sets differs but somehow we didn't find the start of the
164 if(track->plugin_set.total != plugin_set.total && result2 < 0)
168 (*result < 0 || from_units(result2) < *result))
169 *result = from_units(result2);
173 int Track::is_synthesis(int64_t position, int direction, int depth)
176 for( int i = 0; !result && i<plugin_set.total; ++i ) {
177 Plugin *plugin = get_current_plugin(position, i, direction, 0, 0);
178 if( !plugin ) continue;
179 // Assume data from a shared track is synthesized
180 result = plugin->plugin_type == PLUGIN_SHAREDMODULE ? 1 :
181 plugin->is_synthesis(position, direction, depth);
186 void Track::copy_from(Track *track)
188 copy_settings(track);
189 edits->copy_from(track->edits);
190 this->plugin_set.remove_all_objects();
192 for( int i=0; i<track->plugin_set.total; ++i ) {
193 PluginSet *new_plugin_set = plugin_set.append(new PluginSet(edl, this));
194 new_plugin_set->copy_from(track->plugin_set.values[i]);
196 automation->copy_from(track->automation);
197 this->track_w = track->track_w;
198 this->track_h = track->track_h;
201 Track& Track::operator=(Track& track)
203 printf("Track::operator= 1\n");
208 int Track::vertical_span(Theme *theme)
212 result += theme->get_image("title_bg_data")->get_h();
216 result += plugin_set.total * theme->get_image("plugin_bg_data")->get_h();
217 result = MAX(result, theme->title_h);
221 double Track::get_length()
223 double total_length = 0;
229 length = from_units(edits->last->startproject + edits->last->length);
230 if(length > total_length) total_length = length;
234 for(int i = 0; i < plugin_set.total; i++)
236 if( !plugin_set.values[i]->last ) continue;
237 length = from_units(plugin_set.values[i]->last->startproject +
238 plugin_set.values[i]->last->length);
239 if(length > total_length) total_length = length;
243 length = from_units(automation->get_length());
244 if(length > total_length) total_length = length;
250 int Track::has_speed()
252 FloatAutos *autos = (FloatAutos*)automation->autos[AUTOMATION_SPEED];
257 for(FloatAuto *current = (FloatAuto*)autos->first;
259 current = (FloatAuto*)current->next)
261 if(!EQUIV(current->get_value(), 1.0) ||
262 !EQUIV(current->get_control_in_value(), 0.0) ||
263 !EQUIV(current->get_control_out_value(), 0.0))
274 int Track::show_assets()
276 return expand_view || edl->session->show_assets ? 1 : 0;
279 int Track::show_titles()
281 return expand_view || edl->session->show_titles ? 1 : 0;
284 int Track::show_transitions()
286 return expand_view || edl->session->auto_conf->transitions ? 1 : 0;
289 void Track::get_source_dimensions(double position, int &w, int &h)
291 int64_t native_position = to_units(position, 0);
292 for(Edit *current = edits->first; current; current = NEXT)
294 if(current->startproject <= native_position &&
295 current->startproject + current->length > native_position &&
298 w = current->asset->width;
299 h = current->asset->height;
306 int64_t Track::horizontal_span()
308 return (int64_t)(get_length() *
309 edl->session->sample_rate /
310 edl->local_session->zoom_sample +
315 int Track::load(FileXML *file, int track_offset, uint32_t load_flags)
318 int current_plugin = 0;
321 armed = file->tag.get_property("RECORD", armed);
322 play = file->tag.get_property("PLAY", play);
323 ganged = file->tag.get_property("GANG", ganged);
324 master = file->tag.get_property("MASTER", 1);
325 draw = file->tag.get_property("DRAW", draw);
326 nudge = file->tag.get_property("NUDGE", nudge);
327 mixer_id = file->tag.get_property("MIXER_ID", mixer_id);
328 expand_view = file->tag.get_property("EXPAND", expand_view);
329 data_h = file->tag.get_property("DATA_H", data_h);
330 track_w = file->tag.get_property("TRACK_W", track_w);
331 track_h = file->tag.get_property("TRACK_H", track_h);
332 masks = file->tag.get_property("MASKS", masks);
334 load_header(file, load_flags);
337 result = file->read_tag();
341 if(file->tag.title_is("/TRACK"))
346 if(file->tag.title_is("TITLE"))
349 file->read_text_until("/TITLE", &data);
350 memset(title, 0, sizeof(title));
351 strncpy(title, data.cstr(), sizeof(title)-1);
354 if(load_flags && automation->load(file)
355 /* strstr(file->tag.get_title(), "AUTOS") */)
360 if(file->tag.title_is("EDITS"))
362 if(load_flags & LOAD_EDITS)
363 edits->load(file, track_offset);
365 result = file->skip_tag();
368 if(file->tag.title_is("PLUGINSET"))
370 if(load_flags & LOAD_EDITS)
372 PluginSet *plugin_set = new PluginSet(edl, this);
373 this->plugin_set.append(plugin_set);
374 plugin_set->load(file, load_flags);
377 if(load_flags & LOAD_AUTOMATION)
379 if(current_plugin < this->plugin_set.total)
381 PluginSet *plugin_set = this->plugin_set.values[current_plugin];
382 plugin_set->load(file, load_flags);
387 result = file->skip_tag();
390 load_derived(file, load_flags);
399 void Track::insert_asset(Asset *asset,
405 edits->insert_asset(asset,
408 to_units(position, 0),
414 // Default keyframes: We don't replace default keyframes in pasting but
415 // when inserting the first EDL of a load operation we need to replace
416 // the default keyframes.
418 // Plugins: This is an arbitrary behavior
420 // 1) No plugin in source track: Paste silence into destination
422 // 2) Plugin in source track: plugin in source track is inserted into
423 // existing destination track plugin sets, new sets being added when
426 void Track::insert_track(Track *track,
433 // Calculate minimum length of data to pad.
434 int64_t min_length = to_units(
435 MAX(edl_length, track->get_length()),
437 //printf("Track::insert_track %d %s %jd\n", __LINE__, title, min_length);
439 // Decide whether to copy settings based on load_mode
440 if(replace_default) copy_settings(track);
442 edits->insert_edits(track->edits,
443 to_units(position, 0),
448 insert_plugin_set(track,
449 to_units(position, 0),
454 automation->insert_track(track->automation,
455 to_units(position, 0),
463 // Called by insert_track
464 void Track::insert_plugin_set(Track *track,
469 // Extend plugins if no incoming plugins
470 if( track->plugin_set.total ) {
471 for(int i = 0; i < track->plugin_set.total; i++) {
472 if(i >= plugin_set.total)
473 plugin_set.append(new PluginSet(edl, this));
475 plugin_set.values[i]->insert_edits(track->plugin_set.values[i],
476 position, min_length, edit_autos);
480 shift_effects(position, min_length, edit_autos, 0);
483 Plugin* Track::insert_effect(const char *title, SharedLocation *shared_location,
484 KeyFrame *default_keyframe, PluginSet *plugin_set,
485 double start, double length, int plugin_type)
488 plugin_set = new PluginSet(edl, this);
489 this->plugin_set.append(plugin_set);
491 Plugin *plugin = plugin_set->insert_plugin(title,
492 to_units(start, 0), to_units(length, 1), plugin_type,
493 shared_location, default_keyframe, 1);
498 void Track::move_plugins_up(PluginSet *plugin_set)
500 for(int i = 0; i < this->plugin_set.total; i++)
502 if(this->plugin_set.values[i] == plugin_set)
506 PluginSet *temp = this->plugin_set.values[i - 1];
507 this->plugin_set.values[i - 1] = this->plugin_set.values[i];
508 this->plugin_set.values[i] = temp;
510 SharedLocation old_location, new_location;
511 new_location.module = old_location.module = tracks->number_of(this);
512 old_location.plugin = i;
513 new_location.plugin = i - 1;
514 tracks->change_plugins(old_location, new_location, 1);
520 void Track::move_plugins_down(PluginSet *plugin_set)
522 for(int i = 0; i < this->plugin_set.total; i++)
524 if(this->plugin_set.values[i] == plugin_set)
526 if(i == this->plugin_set.total - 1) break;
528 PluginSet *temp = this->plugin_set.values[i + 1];
529 this->plugin_set.values[i + 1] = this->plugin_set.values[i];
530 this->plugin_set.values[i] = temp;
532 SharedLocation old_location, new_location;
533 new_location.module = old_location.module = tracks->number_of(this);
534 old_location.plugin = i;
535 new_location.plugin = i + 1;
536 tracks->change_plugins(old_location, new_location, 1);
543 void Track::remove_asset(Indexable *asset)
545 for(Edit *edit = edits->first; edit; edit = edit->next)
547 if(asset->is_asset &&
549 edit->asset == (Asset*)asset)
554 if(!asset->is_asset &&
556 edit->nested_edl == (EDL*)asset)
558 edit->nested_edl = 0;
564 void Track::remove_pluginset(PluginSet *plugin_set)
567 for(i = 0; i < this->plugin_set.total; i++)
568 if(plugin_set == this->plugin_set.values[i]) break;
570 this->plugin_set.remove_object(plugin_set);
571 for( ++i ; i<=this->plugin_set.total; ++i ) {
572 SharedLocation old_location, new_location;
573 new_location.module = old_location.module = tracks->number_of(this);
574 old_location.plugin = i;
575 new_location.plugin = i - 1;
576 tracks->change_plugins(old_location, new_location, 0);
580 void Track::shift_keyframes(int64_t position, int64_t length)
582 automation->paste_silence(position, position + length);
583 // Effect keyframes are shifted in shift_effects
586 void Track::shift_effects(int64_t position, int64_t length, int edit_autos, Edits *trim_edits)
588 for( int i=0; i<plugin_set.total; ++i ) {
589 if( !trim_edits || trim_edits == (Edits*)plugin_set.values[i] )
590 plugin_set.values[i]->shift_effects(position, length, edit_autos);
594 void Track::detach_effect(Plugin *plugin)
596 //printf("Track::detach_effect 1\n");
597 for( int i=0; i<plugin_set.size(); ++i ) {
598 PluginSet *pluginset = plugin_set[i];
599 Plugin *dest = (Plugin*)pluginset->first;
600 while( dest && dest != plugin ) dest = (Plugin*)dest->next;
601 if( !dest ) continue;
602 tracks->detach_ganged_effects(plugin);
603 int64_t start = plugin->startproject;
604 int64_t end = start + plugin->length;
605 pluginset->clear(start, end, 1);
607 //printf("Track::detach_effect 2 %d\n", plugin_set->length());
608 // Delete 0 length pluginsets
613 void Track::detach_shared_effects(int module)
615 for( int i=0; i<plugin_set.size(); ++i ) {
616 PluginSet *pluginset = this->plugin_set[i];
617 Plugin *dest = (Plugin*)pluginset->first;
618 for( ; dest; dest=(Plugin*)dest->next ) {
619 if( (dest->plugin_type != PLUGIN_SHAREDPLUGIN &&
620 dest->plugin_type != PLUGIN_SHAREDMODULE) ) continue;
621 if( dest->shared_location.module != module ) continue;
622 int64_t start = dest->startproject;
623 int64_t end = start + dest->length;
624 pluginset->clear(start, end, 1);
630 void Track::detach_ganged_effects(Plugin *plugin)
632 for( int i=0; i<plugin_set.size(); ++i ) {
633 PluginSet *pluginset = this->plugin_set[i];
634 Plugin *dest = (Plugin*)pluginset->first;
635 for( ; dest; dest=(Plugin*)dest->next ) {
636 if( strcmp(dest->title, plugin->title) != 0 ) continue;
637 if( dest->startproject != plugin->startproject ) continue;
638 if( dest->length != plugin->length ) continue;
639 int64_t start = dest->startproject;
640 int64_t end = start + dest->length;
641 pluginset->clear(start, end, 1);
647 void Track::resample(double old_rate, double new_rate)
649 edits->resample(old_rate, new_rate);
650 automation->resample(old_rate, new_rate);
651 for(int i = 0; i < plugin_set.total; i++)
652 plugin_set.values[i]->resample(old_rate, new_rate);
653 nudge = (int64_t)(nudge * new_rate / old_rate);
657 void Track::optimize()
660 for(int i = 0; i < plugin_set.total; ) {
661 PluginSet *plugin_set = this->plugin_set.values[i];
662 plugin_set->optimize();
663 //printf("Track::optimize %d\n", plugin_set.values[i]->total());
664 // new definition of empty track...
665 if( !plugin_set->last ||
666 (plugin_set->last == plugin_set->first &&
667 plugin_set->last->silence()) ) {
668 remove_pluginset(plugin_set);
675 Plugin* Track::get_current_plugin(double position,
682 if(convert_units) position = to_units(position, 0);
683 if(use_nudge) position += nudge;
685 if(plugin_set >= this->plugin_set.total || plugin_set < 0) return 0;
687 //printf("Track::get_current_plugin 1 %d %d %d\n", position, this->plugin_set.total, direction);
688 if(direction == PLAY_FORWARD)
690 for(current = (Plugin*)this->plugin_set.values[plugin_set]->last;
692 current = (Plugin*)PREVIOUS)
694 // printf("Track::get_current_plugin 2 %d %ld %ld\n",
695 // current->startproject,
696 // current->startproject + current->length,
698 if(current->startproject <= position &&
699 current->startproject + current->length > position)
706 if(direction == PLAY_REVERSE)
708 for(current = (Plugin*)this->plugin_set.values[plugin_set]->first;
710 current = (Plugin*)NEXT)
712 if(current->startproject < position &&
713 current->startproject + current->length >= position)
723 Plugin* Track::get_current_transition(double position,
730 if(convert_units) position = to_units(position, 0);
731 if(use_nudge) position += nudge;
733 if(direction == PLAY_FORWARD)
735 for(current = edits->last; current; current = PREVIOUS)
737 if(current->startproject <= position && current->startproject + current->length > position)
739 //printf("Track::get_current_transition %p\n", current->transition);
740 if(current->transition && position < current->startproject + current->transition->length)
742 result = current->transition;
749 if(direction == PLAY_REVERSE)
751 for(current = edits->first; current; current = NEXT)
753 if(current->startproject < position && current->startproject + current->length >= position)
755 if(current->transition && position <= current->startproject + current->transition->length)
757 result = current->transition;
767 void Track::synchronize_params(Track *track)
769 for(Edit *this_edit = edits->first, *that_edit = track->edits->first;
770 this_edit && that_edit;
771 this_edit = this_edit->next, that_edit = that_edit->next)
773 this_edit->synchronize_params(that_edit);
776 for(int i = 0; i < plugin_set.total && i < track->plugin_set.total; i++)
777 plugin_set.values[i]->synchronize_params(track->plugin_set.values[i]);
779 automation->copy_from(track->automation);
780 this->nudge = track->nudge;
784 int Track::dump(FILE *fp)
786 fprintf(fp," Title %s\n", title);
787 fprintf(fp," Data type %d, draw %d, gang %d, master %d, mixer_id %d\n"
788 " play %d, armed %d, nudge %jd, masks 0x%04x\n",
789 data_type, draw, ganged, master, mixer_id, play, armed, nudge, masks);
790 fprintf(fp," Edits:\n");
791 for(Edit* current = edits->first; current; current = NEXT)
793 automation->dump(fp);
794 fprintf(fp," Plugin Sets: %d\n", plugin_set.total);
796 for( int i=0; i<plugin_set.total; ++i )
797 plugin_set[i]->dump(fp);
801 // ======================================== accounting
803 int Track::number_of()
805 return tracks->number_of(this);
810 // ================================================= editing
812 int Track::select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y)
817 int Track::move_auto(AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down)
822 int Track::release_auto()
827 // used for copying automation alone
828 int Track::copy_automation(double selectionstart,
834 int64_t start = to_units(selectionstart, 0);
835 int64_t end = to_units(selectionend, 1);
837 file->tag.set_title("TRACK");
841 file->append_newline();
843 automation->copy(start, end, file, default_only, active_only);
845 if(edl->session->auto_conf->plugins)
847 for(int i = 0; i < plugin_set.total; i++)
850 plugin_set.values[i]->copy_keyframes(start,
858 file->tag.set_title("/TRACK");
860 file->append_newline();
861 file->append_newline();
862 file->append_newline();
863 file->append_newline();
868 int Track::paste_automation(double selectionstart, double total_length,
869 double frame_rate, int64_t sample_rate,
870 FileXML *file, int default_only, int active_only)
872 // Only used for pasting automation alone.
873 double scale = data_type == TRACK_AUDIO ?
874 edl->session->sample_rate / sample_rate :
875 edl->session->frame_rate / frame_rate ;
877 total_length *= scale;
878 int64_t start = to_units(selectionstart, 0);
879 int64_t length = to_units(total_length, 1);
881 int current_pluginset = 0;
882 //printf("Track::paste_automation 1\n");
884 while( !(result = file->read_tag()) ) {
885 if( file->tag.title_is("/TRACK") ) break;
886 if( automation->paste(start, length, scale, file,
887 default_only, active_only, 0) )
889 if( file->tag.title_is("PLUGINSET") ) {
890 if( current_pluginset < plugin_set.total ) {
891 plugin_set.values[current_pluginset]->
892 paste_keyframes(start, length, file,
893 default_only, active_only);
902 void Track::clear_automation(double selectionstart,
907 int64_t start = to_units(selectionstart, 0);
908 int64_t end = to_units(selectionend, 1);
910 automation->clear(start, end, edl->session->auto_conf, 0);
912 if(edl->session->auto_conf->plugins)
914 for(int i = 0; i < plugin_set.total; i++)
916 plugin_set.values[i]->clear_keyframes(start, end);
922 void Track::set_automation_mode(double selectionstart,
926 int64_t start = to_units(selectionstart, 0);
927 int64_t end = to_units(selectionend, 1);
929 automation->set_automation_mode(start, end, mode, edl->session->auto_conf);
935 int Track::copy(int copy_flags, double start, double end,
936 FileXML *file, const char *output_path)
938 // Use a copy of the selection in converted units
939 // So copy_automation doesn't reconvert.
940 int64_t start_unit = to_units(start, 0);
941 int64_t end_unit = to_units(end, 1);
946 file->tag.set_title("TRACK");
947 file->tag.set_property("RECORD", armed);
948 file->tag.set_property("NUDGE", nudge);
949 file->tag.set_property("MIXER_ID", mixer_id);
950 file->tag.set_property("PLAY", play);
951 file->tag.set_property("GANG", ganged);
952 file->tag.set_property("MASTER", master);
953 file->tag.set_property("DRAW", draw);
954 file->tag.set_property("EXPAND", expand_view);
955 file->tag.set_property("DATA_H", data_h);
956 file->tag.set_property("TRACK_W", track_w);
957 file->tag.set_property("TRACK_H", track_h);
958 file->tag.set_property("MASKS", masks);
961 file->append_newline();
964 file->tag.set_title("TITLE");
966 file->append_text(title);
967 file->tag.set_title("/TITLE");
969 file->append_newline();
971 // if(data_type == TRACK_AUDIO)
972 // file->tag.set_property("TYPE", "AUDIO");
974 // file->tag.set_property("TYPE", "VIDEO");
976 // file->append_tag();
977 // file->append_newline();
979 if( (copy_flags & COPY_EDITS) )
980 edits->copy(start_unit, end_unit, file, output_path);
982 if( (copy_flags & COPY_AUTOS) ) {
984 auto_conf.set_all(1);
985 automation->copy(start_unit, end_unit, file, 0, 0);
988 if( (copy_flags & COPY_PLUGINS) ) {
989 for( int i=0; i<plugin_set.total; ++i )
990 plugin_set.values[i]->copy(start_unit, end_unit, file);
993 copy_derived(start_unit, end_unit, file);
995 file->tag.set_title("/TRACK");
997 file->append_newline();
998 file->append_newline();
999 file->append_newline();
1000 file->append_newline();
1005 int Track::copy_assets(double start,
1007 ArrayList<Asset*> *asset_list)
1011 start = to_units(start, 0);
1012 end = to_units(end, 1);
1014 Edit *current = edits->editof((int64_t)start, PLAY_FORWARD, 0);
1017 while(current && current->startproject < end)
1019 // Check for duplicate assets
1022 for(i = 0, result = 0; i < asset_list->total; i++)
1024 if(asset_list->values[i] == current->asset) result = 1;
1026 // append pointer to new asset
1027 if(!result) asset_list->append(current->asset);
1036 int Track::blade(double position)
1038 int64_t start = to_units(position, 0);
1039 Edit *edit = edits->split_edit(start);
1040 if( !edit || edit->silence() ) return 1;
1041 edit->hard_left = 1;
1042 if( edit->previous ) edit->previous->hard_right = 1;
1046 int Track::clear(double start, double end,
1047 int edit_edits, int edit_labels, int edit_plugins,
1048 int edit_autos, Edits *trim_edits)
1050 return clear(to_units(start, 0), to_units(end, 1),
1051 edit_edits, edit_labels, edit_plugins, edit_autos, trim_edits);
1054 int Track::clear(int64_t start, int64_t end,
1055 int edit_edits, int edit_labels, int edit_plugins,
1056 int edit_autos, Edits *trim_edits)
1058 //printf("Track::clear 1 %d %d %d\n", edit_edits, edit_labels, edit_plugins);
1060 automation->clear(start, end, 0, 1);
1061 if( edit_plugins ) {
1062 int edit_keyframes = edit_plugins < 0 ? 1 : edit_autos;
1063 for(int i = 0; i < plugin_set.total; i++) {
1064 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1065 plugin_set.values[i]->clear(start, end, edit_keyframes);
1069 edits->clear(start, end);
1073 int Track::clear_handle(double start,
1080 edits->clear_handle(start, end, clear_plugins, edit_autos, distance);
1084 int Track::popup_transition(int cursor_x, int cursor_y)
1091 int Track::modify_edithandles(double oldposition, double newposition,
1092 int currentend, int handle_mode, int edit_labels,
1093 int edit_plugins, int edit_autos, int group_id)
1095 edits->modify_handles(oldposition, newposition,
1096 currentend, handle_mode, 1, edit_labels, edit_plugins,
1097 edit_autos, 0, group_id);
1101 int Track::modify_pluginhandles(double oldposition,
1109 for(int i = 0; i < plugin_set.total; i++)
1111 if(!trim_edits || trim_edits == (Edits*)plugin_set.values[i])
1112 plugin_set.values[i]->modify_handles(oldposition, newposition,
1113 // Don't allow plugin tweeks to affect edits.
1114 currentend, handle_mode, 0, 0, 0, 0, 0, 0);
1120 int Track::paste_silence(double start, double end, int edit_plugins, int edit_autos)
1122 return paste_silence(to_units(start, 0), to_units(end, 1),
1123 edit_plugins, edit_autos);
1126 int Track::paste_silence(int64_t start, int64_t end, int edit_plugins, int edit_autos)
1128 edits->paste_silence(start, end);
1130 shift_keyframes(start, end - start);
1132 shift_effects(start, end - start, edit_autos, 0);
1137 int Track::select_edit(int cursor_x,
1145 int Track::scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end)
1150 void Track::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
1152 for(int i = 0; i < plugin_set.total; i++)
1154 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1156 plugin = (Plugin*)plugin->next)
1158 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN)
1160 if(plugin->shared_location == old_location)
1161 plugin->shared_location = new_location;
1163 if(do_swap && plugin->shared_location == new_location)
1164 plugin->shared_location = old_location;
1170 void Track::change_modules(int old_location, int new_location, int do_swap)
1172 for(int i = 0; i < plugin_set.total; i++)
1174 for(Plugin *plugin = (Plugin*)plugin_set.values[i]->first;
1176 plugin = (Plugin*)plugin->next)
1178 if(plugin->plugin_type == PLUGIN_SHAREDPLUGIN ||
1179 plugin->plugin_type == PLUGIN_SHAREDMODULE)
1181 if(plugin->shared_location.module == old_location)
1182 plugin->shared_location.module = new_location;
1184 if(do_swap && plugin->shared_location.module == new_location)
1185 plugin->shared_location.module = old_location;
1192 int Track::playable_edit(int64_t position, int direction)
1195 if(direction == PLAY_REVERSE) position--;
1196 for(Edit *current = edits->first; current && !result; current = NEXT)
1198 if(current->startproject <= position &&
1199 current->startproject + current->length > position)
1201 //printf("Track::playable_edit %p %p\n", current->transition, current->asset);
1202 if(current->transition ||
1204 current->nested_edl) result = 1;
1211 int Track::need_edit(Edit *current, int test_transitions)
1213 return ((test_transitions && current->transition) ||
1214 (!test_transitions && current->asset));
1217 int64_t Track::plugin_change_duration(int64_t input_position,
1218 int64_t input_length,
1222 if(use_nudge) input_position += nudge;
1223 for(int i = 0; i < plugin_set.total; i++)
1225 int64_t new_duration = plugin_set.values[i]->plugin_change_duration(
1229 if(new_duration < input_length) input_length = new_duration;
1231 return input_length;
1234 int64_t Track::edit_change_duration(int64_t input_position,
1235 int64_t input_length,
1237 int test_transitions,
1241 int64_t edit_length = input_length;
1242 if(use_nudge) input_position += nudge;
1246 // ================================= Reverse playback
1247 // Get first edit on or after position
1248 for(current = edits->first;
1249 current && current->startproject + current->length <= input_position;
1255 if(current->startproject > input_position)
1257 // Before first edit
1261 if(need_edit(current, test_transitions))
1263 // Over an edit of interest.
1264 if(input_position - current->startproject < input_length)
1265 edit_length = input_position - current->startproject + 1;
1269 // Over an edit that isn't of interest.
1270 // Search for next edit of interest.
1271 for(current = PREVIOUS ;
1273 current->startproject + current->length > input_position - input_length &&
1274 !need_edit(current, test_transitions);
1279 need_edit(current, test_transitions) &&
1280 current->startproject + current->length > input_position - input_length)
1281 edit_length = input_position - current->startproject - current->length + 1;
1286 // Not over an edit. Try the last edit.
1287 current = edits->last;
1289 ((test_transitions && current->transition) ||
1290 (!test_transitions && current->asset)))
1291 edit_length = input_position - edits->length() + 1;
1296 // =================================== forward playback
1297 // Get first edit on or before position
1298 for(current = edits->last;
1299 current && current->startproject > input_position;
1305 if(current->startproject + current->length <= input_position)
1307 // Beyond last edit.
1311 if(need_edit(current, test_transitions))
1313 // Over an edit of interest.
1314 // Next edit is going to require a change.
1315 if(current->length + current->startproject - input_position < input_length)
1316 edit_length = current->startproject + current->length - input_position;
1320 // Over an edit that isn't of interest.
1321 // Search for next edit of interest.
1322 for(current = NEXT ;
1324 current->startproject < input_position + input_length &&
1325 !need_edit(current, test_transitions);
1330 need_edit(current, test_transitions) &&
1331 current->startproject < input_position + input_length)
1332 edit_length = current->startproject - input_position;
1337 // Not over an edit. Try the first edit.
1338 current = edits->first;
1340 ((test_transitions && current->transition) ||
1341 (!test_transitions && current->asset)))
1342 edit_length = edits->first->startproject - input_position;
1346 if(edit_length < input_length)
1349 return input_length;
1352 void Track::shuffle_edits(double start, double end, int first_track)
1354 ArrayList<Edit*> new_edits;
1355 ArrayList<Label*> new_labels;
1356 int64_t start_units = to_units(start, 0);
1357 int64_t end_units = to_units(end, 0);
1358 // Sample range of all edits selected
1359 //int64_t total_start_units = 0;
1360 //int64_t total_end_units = 0;
1361 // Edit before range
1362 Edit *start_edit = 0;
1363 int have_start_edit = 0;
1365 // Move all edit pointers to list
1366 for(Edit *current = edits->first;
1369 if(current->startproject >= start_units &&
1370 current->startproject + current->length <= end_units)
1372 if(!have_start_edit) start_edit = current->previous;
1373 have_start_edit = 1;
1374 //total_start_units = current->startproject;
1375 //total_end_units = current->startproject + current->length;
1376 new_edits.append(current);
1378 // Move label pointers
1379 if(first_track && edl->session->labels_follow_edits)
1381 double start_seconds = from_units(current->startproject);
1382 double end_seconds = from_units(current->startproject +
1384 for(Label *label = edl->labels->first;
1386 label = label->next)
1388 if(label->position >= start_seconds &&
1389 label->position < end_seconds)
1391 new_labels.append(label);
1392 edl->labels->remove_pointer(label);
1397 // Remove edit pointer
1398 Edit *previous = current;
1400 edits->remove_pointer(previous);
1408 // Insert pointers in random order
1409 while(new_edits.size())
1411 int index = rand() % new_edits.size();
1412 Edit *edit = new_edits.get(index);
1413 new_edits.remove_number(index);
1415 edits->insert_before(edits->first, edit);
1417 edits->insert_after(start_edit, edit);
1420 // Recalculate start position
1421 // Save old position for moving labels
1422 int64_t startproject1 = edit->startproject;
1423 int64_t startproject2 = 0;
1426 edit->startproject =
1428 edit->previous->startproject + edit->previous->length;
1432 edit->startproject = startproject2 = 0;
1436 // Insert label pointers
1437 if(first_track && edl->session->labels_follow_edits)
1439 double start_seconds1 = from_units(startproject1);
1440 double end_seconds1 = from_units(startproject1 + edit->length);
1441 double start_seconds2 = from_units(startproject2);
1442 for(int i = new_labels.size() - 1; i >= 0; i--)
1444 Label *label = new_labels.get(i);
1445 // Was in old edit position
1446 if(label->position >= start_seconds1 &&
1447 label->position < end_seconds1)
1449 // Move to new edit position
1450 double position = label->position -
1451 start_seconds1 + start_seconds2;
1452 edl->labels->insert_label(position);
1453 new_labels.remove_object_number(i);
1463 if(first_track && edl->session->labels_follow_edits)
1465 edl->labels->optimize();
1469 // exactly the same as shuffle_edits except for 1 line
1470 void Track::reverse_edits(double start, double end, int first_track)
1472 ArrayList<Edit*> new_edits;
1473 ArrayList<Label*> new_labels;
1474 int64_t start_units = to_units(start, 0);
1475 int64_t end_units = to_units(end, 0);
1476 // Sample range of all edits selected
1477 //int64_t total_start_units = 0;
1478 //int64_t total_end_units = 0;
1479 // Edit before range
1480 Edit *start_edit = 0;
1481 int have_start_edit = 0;
1483 // Move all edit pointers to list
1484 for(Edit *current = edits->first; current; )
1486 if(current->startproject >= start_units &&
1487 current->startproject + current->length <= end_units)
1489 if(!have_start_edit) start_edit = current->previous;
1490 have_start_edit = 1;
1491 //total_start_units = current->startproject;
1492 //total_end_units = current->startproject + current->length;
1493 new_edits.append(current);
1495 // Move label pointers
1496 if(first_track && edl->session->labels_follow_edits)
1498 double start_seconds = from_units(current->startproject);
1499 double end_seconds = from_units(current->startproject +
1501 for(Label *label = edl->labels->first;
1503 label = label->next)
1505 if(label->position >= start_seconds &&
1506 label->position < end_seconds)
1508 new_labels.append(label);
1509 edl->labels->remove_pointer(label);
1514 // Remove edit pointer
1515 Edit *previous = current;
1517 edits->remove_pointer(previous);
1525 // Insert pointers in reverse order
1526 while(new_edits.size())
1528 int index = new_edits.size() - 1;
1529 Edit *edit = new_edits.get(index);
1530 new_edits.remove_number(index);
1532 edits->insert_before(edits->first, edit);
1534 edits->insert_after(start_edit, edit);
1537 // Recalculate start position
1538 // Save old position for moving labels
1539 int64_t startproject1 = edit->startproject;
1540 int64_t startproject2 = 0;
1543 edit->startproject =
1545 edit->previous->startproject + edit->previous->length;
1549 edit->startproject = startproject2 = 0;
1553 // Insert label pointers
1554 if(first_track && edl->session->labels_follow_edits)
1556 double start_seconds1 = from_units(startproject1);
1557 double end_seconds1 = from_units(startproject1 + edit->length);
1558 double start_seconds2 = from_units(startproject2);
1559 for(int i = new_labels.size() - 1; i >= 0; i--)
1561 Label *label = new_labels.get(i);
1562 // Was in old edit position
1563 if(label->position >= start_seconds1 &&
1564 label->position < end_seconds1)
1566 // Move to new edit position
1567 double position = label->position -
1568 start_seconds1 + start_seconds2;
1569 edl->labels->insert_label(position);
1570 new_labels.remove_object_number(i);
1580 if(first_track && edl->session->labels_follow_edits)
1582 edl->labels->optimize();
1586 void Track::align_edits(double start, double end, Track *master_track)
1588 int64_t start_units = to_units(start, 0);
1589 int64_t end_units = to_units(end, 0);
1591 // All other tracks get silence or cut to align the edits on the times.
1592 Edit *master = master_track->edits->first;
1593 for(Edit *current = edits->first; current && master; ) {
1594 if( current->startproject >= start_units &&
1595 current->startproject + current->length <= end_units ) {
1596 // edit is in highlighted region
1597 int64_t master_length_units = to_units(master_track->from_units(master->length), 0);
1598 // starting time of master edit
1599 int64_t master_start_units = to_units(master_track->from_units(master->startproject), 0);
1600 // starting time of current edit
1601 int64_t current_startunits = current->startproject;
1603 // the following occur if multiple aligns are performed
1604 // master edit is not silence but current edit is silence
1605 if( !master->silence() && current->silence() ) {
1606 // try again with next edit
1610 if( master->silence() && !current->silence() ) {
1611 // master edit is silence but current edit is not silence
1612 master = master->next;
1615 if( current->length < master_length_units / 2 ) {
1616 // current edit is a glitch edit between 2 required edits
1622 // current edit starts before master edit
1623 if( current_startunits < master_start_units ) {
1624 //printf("Track::align_edits %d\n", __LINE__);
1625 edits->paste_silence(current_startunits, master_start_units);
1626 shift_keyframes(current_startunits,
1627 master_start_units - current_startunits);
1629 else if( current_startunits > master_start_units ) {
1630 // current edit starts after master edit
1631 edits->clear(master_start_units,
1632 current_startunits);
1633 if(edl->session->autos_follow_edits)
1634 shift_keyframes(master_start_units,
1635 current_startunits - master_start_units);
1638 master = master->next;
1642 master = master->next;
1649 int Track::purge_asset(Asset *asset)
1654 int Track::asset_used(Asset *asset)
1659 for(current_edit = edits->first; current_edit; current_edit = current_edit->next)
1661 if(current_edit->asset == asset)
1669 int Track::is_playable(int64_t position, int direction)
1675 int Track::plugin_used(int64_t position, int64_t direction)
1677 //printf("Track::plugin_used 1 %d\n", this->plugin_set.total);
1678 for(int i = 0; i < this->plugin_set.total; i++)
1680 Plugin *current_plugin = get_current_plugin(position,
1686 //printf("Track::plugin_used 2 %p %d %d\n", current_plugin, current_plugin->on, current_plugin->plugin_type);
1687 if(current_plugin &&
1688 current_plugin->on &&
1689 current_plugin->plugin_type != PLUGIN_NONE)
1694 //printf("Track::plugin_used 3 %p\n", current_plugin);
1698 // Audio is always rendered through VConsole
1699 int Track::direct_copy_possible(int64_t start, int direction, int use_nudge)
1704 int64_t Track::to_units(double position, int round)
1706 return (int64_t)position;
1709 double Track::to_doubleunits(double position)
1714 double Track::from_units(int64_t position)
1716 return (double)position;
1719 int64_t Track::frame_align(int64_t position, int round)
1721 if( data_type != TRACK_VIDEO && edl->session->cursor_on_frames )
1722 position = to_units(edl->align_to_frame(from_units(position), round), round);
1726 Plugin *Track::plugin_exists(int plugin_id)
1728 for( int i=0; i<plugin_set.size(); ++i ) {
1729 PluginSet *set = plugin_set.get(i);
1730 Plugin *plugin = (Plugin*)set->first;
1731 for( ; plugin; plugin=(Plugin*)plugin->next ) {
1732 if( plugin->orig_id == plugin_id )
1736 for( Edit *current=edits->first; current; current=NEXT ) {
1737 Plugin *plugin = (Plugin *)current->transition;
1738 if( plugin && plugin->orig_id == plugin_id )
1744 int Track::get_mixer_id()
1746 if( mixer_id < 0 ) {
1748 for( Track *track=tracks->first; track!=0; track=track->next )
1749 if( track->mixer_id > v ) v = track->mixer_id;
1755 void Track::get_fauto_xyz(int fauto, float &x, float &y, float &z)
1757 FloatAutos **fautos = (FloatAutos **)&automation->autos;
1758 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
1759 if( xauto ) x = xauto->get_value();
1760 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
1761 if( yauto ) y = yauto->get_value();
1762 FloatAuto *zauto = (FloatAuto *)fautos[fauto+2]->get_auto_for_editing(-1, 1);
1763 if( zauto ) z = zauto->get_value();
1765 void Track::set_fauto_xyz(int fauto, float x, float y, float z)
1767 FloatAutos **fautos = (FloatAutos **)&automation->autos;
1768 FloatAuto *xauto = (FloatAuto *)fautos[fauto+0]->get_auto_for_editing(-1, 1);
1769 if( xauto ) xauto->set_value(x);
1770 FloatAuto *yauto = (FloatAuto *)fautos[fauto+1]->get_auto_for_editing(-1, 1);
1771 if( yauto ) yauto->set_value(y);
1772 FloatAuto *zauto = (FloatAuto *)fautos[fauto+2]->get_auto_for_editing(-1, 1);
1773 if( zauto ) zauto->set_value(z);
1776 void Track::get_projector(float &x, float &y, float &z)
1778 get_fauto_xyz(AUTOMATION_PROJECTOR_X, x, y, z);
1780 void Track::set_projector(float x, float y, float z)
1782 set_fauto_xyz(AUTOMATION_PROJECTOR_X, x, y, z);
1785 void Track::get_camera(float &x, float &y, float &z)
1787 get_fauto_xyz(AUTOMATION_CAMERA_X, x, y, z);
1789 void Track::set_camera(float x, float y, float z)
1791 set_fauto_xyz(AUTOMATION_CAMERA_X, x, y, z);
1794 Track *Track::gang_master()
1796 if( edl->session->gang_tracks == GANG_NONE ) return this;
1797 Track *track = this;
1798 while( track && !track->master ) track = track->previous;
1799 return !track ? tracks->first : track;
1802 int Track::is_hidden()
1804 if( master ) return 0;
1805 if( edl->session->gang_tracks == GANG_MEDIA ) return 1;
1806 if( edl->session->gang_tracks == GANG_CHANNELS ) {
1807 for( Track *track=previous; track; track=track->previous ) {
1808 if( track->data_type == data_type ) return 1;
1809 if( track->master ) return 0;
1814 int Track::is_armed()
1816 return gang_master()->armed;
1818 int Track::is_ganged()
1820 return gang_master()->ganged;
1823 int Track::armed_gang(Track *track)
1825 if( edl->session->gang_tracks == GANG_NONE ) return ganged;
1826 Track *current = gang_master();
1828 if( track == current ) return 1;
1829 current = current->next;
1830 if( !current || current->master ) return 0;
1836 int Track::index_in(Mixer *mixer)
1838 if( !mixer || mixer_id < 0 ) return -1;
1839 int k = mixer->mixer_ids.size();
1840 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );