3 #include "automation.h"
8 #include "edlsession.h"
12 #include "localsession.h"
15 #include "mainsession.h"
16 #include "pluginserver.h"
17 #include "pluginset.h"
19 #include "trackcanvas.h"
21 #include "trackscroll.h"
22 #include "transition.h"
23 #include "transportque.h"
27 int Tracks::clear(double start, double end, int clear_plugins)
31 for(current_track = first;
33 current_track = current_track->next)
35 if(current_track->record)
37 current_track->clear(start,
48 void Tracks::clear_automation(double selectionstart, double selectionend)
52 for(current_track = first; current_track; current_track = current_track->next)
54 if(current_track->record)
56 current_track->clear_automation(selectionstart,
64 int Tracks::clear_default_keyframe()
66 for(Track *current = first; current; current = NEXT)
69 current->clear_automation(0, 0, 0, 1);
74 int Tracks::clear_handle(double start,
76 double &longest_distance,
83 for(current_track = first; current_track; current_track = current_track->next)
85 if(current_track->record)
87 current_track->clear_handle(start,
92 if(distance > longest_distance) longest_distance = distance;
99 int Tracks::copy_automation(double selectionstart,
105 // called by MWindow::copy_automation for copying automation alone
106 Track* current_track;
108 file->tag.set_title("AUTO_CLIPBOARD");
109 file->tag.set_property("LENGTH", selectionend - selectionstart);
110 file->tag.set_property("FRAMERATE", edl->session->frame_rate);
111 file->tag.set_property("SAMPLERATE", edl->session->sample_rate);
113 file->append_newline();
114 file->append_newline();
116 for(current_track = first;
118 current_track = current_track->next)
120 if(current_track->record)
122 current_track->copy_automation(selectionstart,
130 file->tag.set_title("/AUTO_CLIPBOARD");
132 file->append_newline();
133 file->terminate_string();
137 int Tracks::copy_default_keyframe(FileXML *file)
139 copy_automation(0, 0, file, 1, 0);
143 int Tracks::delete_tracks()
145 int result = 1, total_deleted = 0;
146 Track *track, *next_track, *shifted_track;
151 // keep deleting until all the recordable tracks are gone
154 //printf("Tracks::delete_tracks 1\n");
155 // Stop when first recordable track is reached
160 //printf("Tracks::delete_tracks 2\n");
161 next_track = track->next;
165 deleted_number = number_of(track);
169 // Shift all the plugin pointers.
170 for(shifted_track = next_track;
172 shifted_track = shifted_track->next)
174 shifted_track->delete_module_pointers(deleted_number);
180 //printf("Tracks::delete_tracks 3\n");
182 //printf("Tracks::delete_tracks 4\n");
183 return total_deleted;
186 void Tracks::move_edits(ArrayList<Edit*> *edits,
189 int edit_labels, // Ignored
190 int edit_plugins) // Ignored
192 int current_aedit = 0;
193 int current_vedit = 0;
195 //printf("Tracks::move_edits 1\n");
196 for(Track *dest_track = track; dest_track; dest_track = dest_track->next)
198 if(dest_track->record)
200 // Need a local copy of the source edit since the original source edit may
201 // change in the editing operation.
202 Edit *source_edit = 0;
203 Track *source_track = 0;
205 if(dest_track->data_type == TRACK_AUDIO &&
206 current_aedit < edits->total)
208 while(current_aedit < edits->total &&
209 edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
212 if(current_aedit < edits->total)
214 source_edit = edits->values[current_aedit];
215 source_track = source_edit->track;
220 if(dest_track->data_type == TRACK_VIDEO &&
221 current_vedit < edits->total)
223 while(current_vedit < edits->total &&
224 edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
227 if(current_vedit < edits->total)
229 source_edit = edits->values[current_vedit];
230 source_track = source_edit->track;
235 //printf("Tracks::move_edits 2 %s %s %d\n", source_track->title, dest_track->title, source_edit->length);
240 AutoConf temp_autoconf;
241 int64_t position_i = source_track->to_units(position, 0);
242 // Source edit changes
243 int64_t source_length = source_edit->length;
245 temp_autoconf.set_all();
246 source_track->automation->copy(source_edit->startproject,
247 source_edit->startproject + source_edit->length,
251 temp.terminate_string();
255 //printf("Tracks::move_edits 1 %d\n", source_edit->length);
257 Edit *dest_edit = dest_track->edits->shift(position_i,
259 Edit *result = dest_track->edits->insert_before(dest_edit,
260 new Edit(edl, dest_track));
261 result->copy_from(source_edit);
262 result->startproject = position_i;
263 result->length = source_length;
265 // Insert new keyframes
266 //printf("Tracks::move_edits 2 %d %p\n", result->startproject, result->asset);
267 dest_track->automation->paste_silence(source_edit->startproject,
268 source_edit->startproject + source_length);
269 while(!temp.read_tag())
270 dest_track->automation->paste(position_i,
277 //printf("Tracks::move_edits 5\n");
278 //dest_track->dump();
281 int64_t clear_start = source_edit->startproject;
282 int64_t clear_end = clear_start + source_length;
284 //printf("Tracks::move_edits 7 %d %d\n", clear_start, clear_end);
285 source_track->edits->clear(clear_start,
287 source_track->automation->clear(clear_start,
293 //printf("Tracks::move_edits 8 %d %d\n", clear_start, source_edit->length);
294 //dest_track->dump();
295 //printf("Tracks::move_edits 9\n");
296 source_track->optimize();
297 dest_track->optimize();
298 //printf("Tracks::move_edits 10\n");
300 // delete source_edit;
307 void Tracks::move_effect(Plugin *plugin,
308 PluginSet *dest_plugin_set,
310 int64_t dest_position)
312 Track *source_track = plugin->track;
315 // Insert on an existing plugin set
316 if(!dest_track && dest_plugin_set)
318 Track *dest_track = dest_plugin_set->track;
321 // Assume this operation never splits a plugin
322 // Shift destination plugins back
323 dest_plugin_set->shift(dest_position, plugin->length);
327 for(current = (Plugin*)dest_plugin_set->first; current; current = (Plugin*)NEXT)
328 if(current->startproject >= dest_position) break;
330 result = (Plugin*)dest_plugin_set->insert_before(current,
331 new Plugin(edl, dest_plugin_set, ""));
334 // Create a new plugin set
338 if(edl->local_session->get_selectionend() >
339 edl->local_session->get_selectionstart())
341 start = edl->local_session->get_selectionstart();
342 length = edl->local_session->get_selectionend() -
346 if(dest_track->get_length() > 0)
349 length = dest_track->get_length();
354 length = dest_track->from_units(plugin->length);
358 result = dest_track->insert_effect("",
359 &plugin->shared_location,
364 plugin->plugin_type);
369 result->copy_from(plugin);
370 result->shift(dest_position - plugin->startproject);
372 // Clear new plugin from old set
373 plugin->plugin_set->clear(plugin->startproject, plugin->startproject + plugin->length);
376 source_track->optimize();
381 int Tracks::concatenate_tracks(int edit_plugins)
383 Track *output_track, *first_output_track, *input_track;
384 int i, data_type = TRACK_AUDIO;
388 IntAuto *play_keyframe = 0;
391 for(i = 0; i < 2; i++)
393 // Get first output track
394 for(output_track = first;
396 output_track = output_track->next)
397 if(output_track->data_type == data_type &&
398 output_track->record) break;
400 first_output_track = output_track;
402 // Get first input track
403 for(input_track = first;
405 input_track = input_track->next)
407 if(input_track->data_type == data_type &&
409 !input_track->record) break;
413 if(output_track && input_track)
415 // Transfer input track to end of output track one at a time
418 output_start = output_track->get_length();
419 output_track->insert_track(input_track,
424 // Get next source and destination
425 for(input_track = input_track->next;
427 input_track = input_track->next)
430 if(input_track->data_type == data_type &&
431 !input_track->record &&
432 input_track->play) break;
435 for(output_track = output_track->next;
437 output_track = output_track->next)
439 if(output_track->data_type == data_type &&
440 output_track->record) break;
445 output_track = first_output_track;
451 if(data_type == TRACK_AUDIO) data_type = TRACK_VIDEO;
457 int Tracks::delete_audio_track()
461 for(current = last; current && current->data_type != TRACK_AUDIO; current = PREVIOUS)
466 if(current) delete_track(current);
469 int Tracks::delete_video_track()
473 for(current = last; current && current->data_type != TRACK_VIDEO; current = PREVIOUS)
478 if(current) delete_track(current);
481 int Tracks::delete_all_tracks()
483 while(last) delete last;
488 void Tracks::change_modules(int old_location, int new_location, int do_swap)
490 for(Track* current = first ; current; current = current->next)
492 current->change_modules(old_location, new_location, do_swap);
496 void Tracks::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
498 for(Track* current = first ; current; current = current->next)
500 current->change_plugins(old_location, new_location, do_swap);
506 // =========================================== EDL editing
509 int Tracks::copy(double start,
516 if(start == end && !all) return 1;
524 if(current->record || all)
526 current->copy(start, end, file,output_path);
535 int Tracks::move_track_up(Track *track)
537 Track *next_track = track->previous;
538 if(!next_track) next_track = last;
540 change_modules(number_of(track), number_of(next_track), 1);
542 // printf("Tracks::move_track_up 1 %p %p\n", track, next_track);
544 // for(Track *current = first; current && count < 5; current = NEXT, count++)
545 // printf("Tracks::move_track_up %p %p %p\n", current->previous, current, current->next);
546 // printf("Tracks::move_track_up 2\n");
548 swap(track, next_track);
551 // for(Track *current = first; current && count < 5; current = NEXT, count++)
552 // printf("Tracks::move_track_up %p %p %p\n", current->previous, current, current->next);
553 // printf("Tracks::move_track_up 3\n");
558 int Tracks::move_track_down(Track *track)
560 Track *next_track = track->next;
561 if(!next_track) next_track = first;
563 change_modules(number_of(track), number_of(next_track), 1);
564 swap(track, next_track);
569 int Tracks::move_tracks_up()
571 Track *track, *next_track;
578 next_track = track->next;
584 change_modules(number_of(track->previous), number_of(track), 1);
586 swap(track->previous, track);
595 int Tracks::move_tracks_down()
597 Track *track, *previous_track;
602 track = previous_track)
604 previous_track = track->previous;
610 change_modules(number_of(track), number_of(track->next), 1);
612 swap(track, track->next);
623 void Tracks::paste_audio_transition(PluginServer *server)
625 for(Track *current = first; current; current = NEXT)
627 if(current->data_type == TRACK_AUDIO &&
630 int64_t position = current->to_units(
631 edl->local_session->get_selectionstart(), 0);
632 Edit *current_edit = current->edits->editof(position, PLAY_FORWARD);
635 paste_transition(server, current_edit);
641 void Tracks::paste_automation(double selectionstart,
645 Track* current_atrack = 0;
646 Track* current_vtrack = 0;
649 double frame_rate = edl->session->frame_rate;
650 int64_t sample_rate = edl->session->sample_rate;
651 char string[BCTEXTLEN];
656 result = file->read_tag();
658 !file->tag.title_is("AUTO_CLIPBOARD"));
662 length = file->tag.get_property("LENGTH", 0);
663 frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
664 sample_rate = file->tag.get_property("SAMPLERATE", sample_rate);
669 result = file->read_tag();
673 if(file->tag.title_is("/AUTO_CLIPBOARD"))
678 if(file->tag.title_is("TRACK"))
680 file->tag.get_property("TYPE", string);
682 if(!strcmp(string, "AUDIO"))
684 // Get next audio track
686 current_atrack = first;
688 current_atrack = current_atrack->next;
690 while(current_atrack &&
691 (current_atrack->data_type != TRACK_AUDIO ||
692 !current_atrack->record))
693 current_atrack = current_atrack->next;
698 current_atrack->paste_automation(selectionstart,
708 // Get next video track
710 current_vtrack = first;
712 current_vtrack = current_vtrack->next;
714 while(current_vtrack &&
715 (current_vtrack->data_type != TRACK_VIDEO ||
716 !current_vtrack->record))
717 current_vtrack = current_vtrack->next;
722 //printf("Tracks::paste_automation 1 %s %d\n", current_vtrack->title, current_vtrack->record);
723 current_vtrack->paste_automation(selectionstart,
737 int Tracks::paste_default_keyframe(FileXML *file)
739 paste_automation(0, file, 1);
743 void Tracks::paste_transition(PluginServer *server, Edit *dest_edit)
745 dest_edit->insert_transition(server->title);
748 void Tracks::paste_video_transition(PluginServer *server, int first_track)
750 for(Track *current = first; current; current = NEXT)
752 if(current->data_type == TRACK_VIDEO &&
755 int64_t position = current->to_units(
756 edl->local_session->get_selectionstart(), 0);
757 Edit *current_edit = current->edits->editof(position, PLAY_FORWARD);
760 paste_transition(server, current_edit);
762 if(first_track) break;
768 int Tracks::paste_silence(double start, double end, int edit_plugins)
770 Track* current_track;
772 for(current_track = first;
774 current_track = current_track->next)
776 if(current_track->record)
778 current_track->paste_silence(start, end, edit_plugins);
786 int Tracks::select_auto(int cursor_x, int cursor_y)
789 for(Track* current = first; current && !result; current = NEXT) { result = current->select_auto(&auto_conf, cursor_x, cursor_y); }
793 int Tracks::move_auto(int cursor_x, int cursor_y, int shift_down)
797 for(Track* current = first; current && !result; current = NEXT)
799 result = current->move_auto(&auto_conf, cursor_x, cursor_y, shift_down);
804 int Tracks::modify_edithandles(double &oldposition,
813 for(current = first; current; current = NEXT)
817 current->modify_edithandles(oldposition,
828 int Tracks::modify_pluginhandles(double &oldposition,
836 for(current = first; current; current = NEXT)
840 current->modify_pluginhandles(oldposition,
852 int Tracks::purge_asset(Asset *asset)
854 Track *current_track;
857 for(current_track = first; current_track; current_track = current_track->next)
859 result += current_track->purge_asset(asset);
864 int Tracks::asset_used(Asset *asset)
866 Track *current_track;
869 for(current_track = first; current_track; current_track = current_track->next)
871 result += current_track->asset_used(asset);
876 int Tracks::scale_time(float rate_scale, int ignore_record, int scale_edits, int scale_autos, int64_t start, int64_t end)
878 Track *current_track;
880 for(current_track = first;
882 current_track = current_track->next)
884 if((current_track->record || ignore_record) &&
885 current_track->data_type == TRACK_VIDEO)
887 current_track->scale_time(rate_scale, scale_edits, scale_autos, start, end);