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 //printf("Tracks::move_edits 1\n");
193 for(Track *dest_track = track; dest_track; dest_track = dest_track->next)
195 if(dest_track->record)
197 // Need a local copy of the source edit since the original source edit may
198 // change in the editing operation.
199 Edit *source_edit = 0;
200 Track *source_track = 0;
204 if(dest_track->data_type == TRACK_AUDIO)
206 int current_aedit = 0;
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;
216 edits->remove_number(current_aedit);
220 if(dest_track->data_type == TRACK_VIDEO)
222 int current_vedit = 0;
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;
231 edits->remove_number(current_vedit);
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();
247 source_track->automation->copy(source_edit->startproject,
248 source_edit->startproject + source_edit->length,
252 temp.terminate_string();
254 // Insert new keyframes
255 //printf("Tracks::move_edits 2 %d %p\n", result->startproject, result->asset);
256 source_track->automation->clear(source_edit->startproject,
257 source_edit->startproject + source_edit->length,
260 int64_t position_a = position_i;
261 if (dest_track == source_track)
263 if (position_a > source_edit->startproject)
264 position_a -= source_length;
267 dest_track->automation->paste_silence(position_a,
268 position_a + source_length);
269 while(!temp.read_tag())
270 dest_track->automation->paste(position_a,
279 //printf("Tracks::move_edits 1 %d\n", source_edit->length);
281 Edit *dest_edit = dest_track->edits->shift(position_i,
283 Edit *result = dest_track->edits->insert_before(dest_edit,
284 new Edit(edl, dest_track));
285 result->copy_from(source_edit);
286 result->startproject = position_i;
287 result->length = source_length;
289 //printf("Tracks::move_edits 5\n");
290 //dest_track->dump();
293 //printf("Tracks::move_edits 7 %d %d\n", clear_start, clear_end);
294 source_track->edits->clear(source_edit->startproject,
295 source_edit->startproject + source_length);
299 //printf("Tracks::move_edits 8 %d %d\n", clear_start, source_edit->length);
300 //dest_track->dump();
301 //printf("Tracks::move_edits 9\n");
302 source_track->optimize();
303 dest_track->optimize();
304 //printf("Tracks::move_edits 10\n");
306 // delete source_edit;
313 void Tracks::move_effect(Plugin *plugin,
314 PluginSet *dest_plugin_set,
316 int64_t dest_position)
318 Track *source_track = plugin->track;
321 // Insert on an existing plugin set
322 if(!dest_track && dest_plugin_set)
324 Track *dest_track = dest_plugin_set->track;
327 // Assume this operation never splits a plugin
328 // Shift destination plugins back
329 dest_plugin_set->shift(dest_position, plugin->length);
333 for(current = (Plugin*)dest_plugin_set->first; current; current = (Plugin*)NEXT)
334 if(current->startproject >= dest_position) break;
336 result = (Plugin*)dest_plugin_set->insert_before(current,
337 new Plugin(edl, dest_plugin_set, ""));
340 // Create a new plugin set
344 if(edl->local_session->get_selectionend() >
345 edl->local_session->get_selectionstart())
347 start = edl->local_session->get_selectionstart();
348 length = edl->local_session->get_selectionend() -
352 if(dest_track->get_length() > 0)
355 length = dest_track->get_length();
360 length = dest_track->from_units(plugin->length);
364 result = dest_track->insert_effect("",
365 &plugin->shared_location,
370 plugin->plugin_type);
375 result->copy_from(plugin);
376 result->shift(dest_position - plugin->startproject);
378 // Clear new plugin from old set
379 plugin->plugin_set->clear(plugin->startproject, plugin->startproject + plugin->length);
382 source_track->optimize();
387 int Tracks::concatenate_tracks(int edit_plugins)
389 Track *output_track, *first_output_track, *input_track;
390 int i, data_type = TRACK_AUDIO;
394 IntAuto *play_keyframe = 0;
397 for(i = 0; i < 2; i++)
399 // Get first output track
400 for(output_track = first;
402 output_track = output_track->next)
403 if(output_track->data_type == data_type &&
404 output_track->record) break;
406 first_output_track = output_track;
408 // Get first input track
409 for(input_track = first;
411 input_track = input_track->next)
413 if(input_track->data_type == data_type &&
415 !input_track->record) break;
419 if(output_track && input_track)
421 // Transfer input track to end of output track one at a time
424 output_start = output_track->get_length();
425 output_track->insert_track(input_track,
430 // Get next source and destination
431 for(input_track = input_track->next;
433 input_track = input_track->next)
436 if(input_track->data_type == data_type &&
437 !input_track->record &&
438 input_track->play) break;
441 for(output_track = output_track->next;
443 output_track = output_track->next)
445 if(output_track->data_type == data_type &&
446 output_track->record) break;
451 output_track = first_output_track;
457 if(data_type == TRACK_AUDIO) data_type = TRACK_VIDEO;
463 int Tracks::delete_audio_track()
467 for(current = last; current && current->data_type != TRACK_AUDIO; current = PREVIOUS)
472 if(current) delete_track(current);
475 int Tracks::delete_video_track()
479 for(current = last; current && current->data_type != TRACK_VIDEO; current = PREVIOUS)
484 if(current) delete_track(current);
487 int Tracks::delete_all_tracks()
489 while(last) delete last;
494 void Tracks::change_modules(int old_location, int new_location, int do_swap)
496 for(Track* current = first ; current; current = current->next)
498 current->change_modules(old_location, new_location, do_swap);
502 void Tracks::change_plugins(SharedLocation &old_location, SharedLocation &new_location, int do_swap)
504 for(Track* current = first ; current; current = current->next)
506 current->change_plugins(old_location, new_location, do_swap);
512 // =========================================== EDL editing
515 int Tracks::copy(double start,
522 if(start == end && !all) return 1;
530 if(current->record || all)
532 current->copy(start, end, file,output_path);
541 int Tracks::move_track_up(Track *track)
543 Track *next_track = track->previous;
544 if(!next_track) next_track = last;
546 change_modules(number_of(track), number_of(next_track), 1);
548 // printf("Tracks::move_track_up 1 %p %p\n", track, next_track);
550 // for(Track *current = first; current && count < 5; current = NEXT, count++)
551 // printf("Tracks::move_track_up %p %p %p\n", current->previous, current, current->next);
552 // printf("Tracks::move_track_up 2\n");
554 swap(track, next_track);
557 // for(Track *current = first; current && count < 5; current = NEXT, count++)
558 // printf("Tracks::move_track_up %p %p %p\n", current->previous, current, current->next);
559 // printf("Tracks::move_track_up 3\n");
564 int Tracks::move_track_down(Track *track)
566 Track *next_track = track->next;
567 if(!next_track) next_track = first;
569 change_modules(number_of(track), number_of(next_track), 1);
570 swap(track, next_track);
575 int Tracks::move_tracks_up()
577 Track *track, *next_track;
584 next_track = track->next;
590 change_modules(number_of(track->previous), number_of(track), 1);
592 swap(track->previous, track);
601 int Tracks::move_tracks_down()
603 Track *track, *previous_track;
608 track = previous_track)
610 previous_track = track->previous;
616 change_modules(number_of(track), number_of(track->next), 1);
618 swap(track, track->next);
629 void Tracks::paste_audio_transition(PluginServer *server)
631 for(Track *current = first; current; current = NEXT)
633 if(current->data_type == TRACK_AUDIO &&
636 int64_t position = current->to_units(
637 edl->local_session->get_selectionstart(), 0);
638 Edit *current_edit = current->edits->editof(position,
643 paste_transition(server, current_edit);
649 void Tracks::paste_automation(double selectionstart,
653 Track* current_atrack = 0;
654 Track* current_vtrack = 0;
657 double frame_rate = edl->session->frame_rate;
658 int64_t sample_rate = edl->session->sample_rate;
659 char string[BCTEXTLEN];
664 result = file->read_tag();
666 !file->tag.title_is("AUTO_CLIPBOARD"));
670 length = file->tag.get_property("LENGTH", 0);
671 frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
672 sample_rate = file->tag.get_property("SAMPLERATE", sample_rate);
677 result = file->read_tag();
681 if(file->tag.title_is("/AUTO_CLIPBOARD"))
686 if(file->tag.title_is("TRACK"))
688 file->tag.get_property("TYPE", string);
690 if(!strcmp(string, "AUDIO"))
692 // Get next audio track
694 current_atrack = first;
696 current_atrack = current_atrack->next;
698 while(current_atrack &&
699 (current_atrack->data_type != TRACK_AUDIO ||
700 !current_atrack->record))
701 current_atrack = current_atrack->next;
706 current_atrack->paste_automation(selectionstart,
716 // Get next video track
718 current_vtrack = first;
720 current_vtrack = current_vtrack->next;
722 while(current_vtrack &&
723 (current_vtrack->data_type != TRACK_VIDEO ||
724 !current_vtrack->record))
725 current_vtrack = current_vtrack->next;
730 //printf("Tracks::paste_automation 1 %s %d\n", current_vtrack->title, current_vtrack->record);
731 current_vtrack->paste_automation(selectionstart,
745 int Tracks::paste_default_keyframe(FileXML *file)
747 paste_automation(0, file, 1);
751 void Tracks::paste_transition(PluginServer *server, Edit *dest_edit)
753 dest_edit->insert_transition(server->title);
756 void Tracks::paste_video_transition(PluginServer *server, int first_track)
758 for(Track *current = first; current; current = NEXT)
760 if(current->data_type == TRACK_VIDEO &&
763 int64_t position = current->to_units(
764 edl->local_session->get_selectionstart(), 0);
765 Edit *current_edit = current->edits->editof(position,
770 paste_transition(server, current_edit);
772 if(first_track) break;
778 int Tracks::paste_silence(double start, double end, int edit_plugins)
780 Track* current_track;
782 for(current_track = first;
784 current_track = current_track->next)
786 if(current_track->record)
788 current_track->paste_silence(start, end, edit_plugins);
796 int Tracks::select_auto(int cursor_x, int cursor_y)
799 for(Track* current = first; current && !result; current = NEXT) { result = current->select_auto(&auto_conf, cursor_x, cursor_y); }
803 int Tracks::move_auto(int cursor_x, int cursor_y, int shift_down)
807 for(Track* current = first; current && !result; current = NEXT)
809 result = current->move_auto(&auto_conf, cursor_x, cursor_y, shift_down);
814 int Tracks::modify_edithandles(double &oldposition,
824 for(current = first; current; current = NEXT)
828 current->modify_edithandles(oldposition,
840 int Tracks::modify_pluginhandles(double &oldposition,
849 for(current = first; current; current = NEXT)
853 current->modify_pluginhandles(oldposition,
866 int Tracks::purge_asset(Asset *asset)
868 Track *current_track;
871 for(current_track = first; current_track; current_track = current_track->next)
873 result += current_track->purge_asset(asset);
878 int Tracks::asset_used(Asset *asset)
880 Track *current_track;
883 for(current_track = first; current_track; current_track = current_track->next)
885 result += current_track->asset_used(asset);
890 int Tracks::scale_time(float rate_scale, int ignore_record, int scale_edits, int scale_autos, int64_t start, int64_t end)
892 Track *current_track;
894 for(current_track = first;
896 current_track = current_track->next)
898 if((current_track->record || ignore_record) &&
899 current_track->data_type == TRACK_VIDEO)
901 current_track->scale_time(rate_scale, scale_edits, scale_autos, start, end);