3 * Copyright (C) 1997-2012 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 "awindowgui.h"
25 #include "bcsignals.h"
29 #include "commercials.h"
30 #include "cplayback.h"
33 #include "cwindowgui.h"
36 #include "edlsession.h"
37 #include "filesystem.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
42 #include "gwindowgui.h"
44 #include "keyframes.h"
47 #include "levelwindow.h"
48 #include "localsession.h"
49 #include "mainclock.h"
50 #include "maincursor.h"
51 #include "mainerror.h"
52 #include "mainindexes.h"
54 #include "mainsession.h"
56 #include "maskautos.h"
58 #include "mwindowgui.h"
62 #include "playbackengine.h"
63 #include "pluginset.h"
64 #include "recordlabel.h"
65 #include "samplescroll.h"
66 #include "trackcanvas.h"
68 #include "trackscroll.h"
70 #include "transition.h"
71 #include "transportque.h"
73 #include "undostackitem.h"
74 #include "vplayback.h"
76 #include "vwindowgui.h"
79 #include "automation.h"
80 #include "maskautos.h"
84 void MWindow::add_audio_track_entry(int above, Track *dst)
87 add_audio_track(above, dst);
89 undo_after(_("add track"), LOAD_ALL);
92 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
93 gui->activate_timeline();
95 // gui->get_scrollbars(0);
96 // gui->canvas->draw();
97 // gui->patchbay->update();
98 // gui->cursor->draw(1);
99 // gui->canvas->flash();
100 // gui->canvas->activate();
101 cwindow->refresh_frame(CHANGE_EDL);
104 void MWindow::add_video_track_entry(Track *dst)
107 add_video_track(1, dst);
108 undo_after(_("add track"), LOAD_ALL);
112 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
113 gui->activate_timeline();
114 // gui->get_scrollbars(0);
115 // gui->canvas->draw();
116 // gui->patchbay->update();
117 // gui->cursor->draw(1);
118 // gui->canvas->flash();
119 // gui->canvas->activate();
120 cwindow->refresh_frame(CHANGE_EDL);
124 void MWindow::add_subttl_track_entry(Track *dst)
127 add_subttl_track(1, dst);
128 undo_after(_("add track"), LOAD_ALL);
132 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
133 gui->activate_timeline();
134 // gui->get_scrollbars(0);
135 // gui->canvas->draw();
136 // gui->patchbay->update();
137 // gui->cursor->draw(1);
138 // gui->canvas->flash();
139 // gui->canvas->activate();
140 cwindow->refresh_frame(CHANGE_EDL);
145 int MWindow::add_audio_track(int above, Track *dst)
147 edl->tracks->add_audio_track(above, dst);
148 edl->tracks->update_y_pixels(theme);
153 int MWindow::add_video_track(int above, Track *dst)
155 edl->tracks->add_video_track(above, dst);
156 edl->tracks->update_y_pixels(theme);
161 int MWindow::add_subttl_track(int above, Track *dst)
163 edl->tracks->add_subttl_track(above, dst);
164 edl->tracks->update_y_pixels(theme);
169 void MWindow::asset_to_all()
171 if( !session->drag_assets->size() ) return;
172 Indexable *indexable = session->drag_assets->get(0);
174 // if( indexable->have_video() )
181 w = indexable->get_w();
182 h = indexable->get_h();
183 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
184 double old_framerate = edl->session->frame_rate;
185 int old_samplerate = edl->session->sample_rate;
186 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
189 if( indexable->have_video() ) {
190 edl->session->output_w = w;
191 edl->session->output_h = h;
192 edl->session->frame_rate = new_framerate;
194 edl->session->aspect_w,
195 edl->session->aspect_h,
198 for( Track *current=edl->tracks->first; current; current=NEXT ) {
199 if( current->data_type == TRACK_VIDEO /* &&
200 current->record */ ) {
201 current->track_w = w;
202 current->track_h = h;
207 if( ((edl->session->output_w % 4) ||
208 (edl->session->output_h % 4)) &&
209 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
210 MainError::show_error(
211 _("This project's dimensions are not multiples of 4 so\n"
212 "it can't be rendered by OpenGL."));
216 if( defaults->get("AUTOASPECT", 0) ) {
218 edl->session->aspect_w,
219 edl->session->aspect_h,
224 if( indexable->have_audio() ) {
225 edl->session->sample_rate = new_samplerate;
226 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
227 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
232 undo_after(_("asset to all"), LOAD_ALL);
234 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
235 sync_parameters(CHANGE_ALL);
239 void MWindow::asset_to_size()
241 if( !session->drag_assets->size() ) return;
242 Indexable *indexable = session->drag_assets->get(0);
244 if( indexable->have_video() ) {
249 w = indexable->get_w();
250 h = indexable->get_h();
251 edl->session->output_w = w;
252 edl->session->output_h = h;
254 if( ((edl->session->output_w % 4) ||
255 (edl->session->output_h % 4)) &&
256 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
257 MainError::show_error(
258 _("This project's dimensions are not multiples of 4 so\n"
259 "it can't be rendered by OpenGL."));
263 if( defaults->get("AUTOASPECT", 0) ) {
264 create_aspect_ratio(edl->session->aspect_w,
265 edl->session->aspect_h,
272 undo_after(_("asset to size"), LOAD_ALL);
274 sync_parameters(CHANGE_ALL);
279 void MWindow::asset_to_rate()
281 if( session->drag_assets->size() &&
282 session->drag_assets->get(0)->have_video() ) {
283 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
284 double old_framerate = edl->session->frame_rate;
287 edl->session->frame_rate = new_framerate;
288 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
292 undo_after(_("asset to rate"), LOAD_ALL);
294 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
295 sync_parameters(CHANGE_ALL);
300 void MWindow::clear_entry()
307 undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
310 update_plugin_guis();
311 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
312 cwindow->update(1, 0, 0, 0, 1);
313 cwindow->refresh_frame(CHANGE_EDL);
316 void MWindow::clear(int clear_handle)
318 double start = edl->local_session->get_selectionstart();
319 double end = edl->local_session->get_selectionend();
320 if( clear_handle || !EQUIV(start, end) ) {
323 edl->session->labels_follow_edits,
324 edl->session->plugins_follow_edits,
325 edl->session->autos_follow_edits);
329 void MWindow::update_gui(int changed_edl)
332 update_plugin_guis();
334 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
335 cwindow->update(1, 0, 0, 0, 1);
336 cwindow->refresh_frame(CHANGE_EDL);
339 gui->draw_overlays(1);
340 sync_parameters(CHANGE_PARAMS);
341 gui->update_patchbay();
342 cwindow->update(1, 0, 0);
346 void MWindow::set_automation_mode(int mode)
350 edl->tracks->set_automation_mode(
351 edl->local_session->get_selectionstart(),
352 edl->local_session->get_selectionend(),
354 int changed_edl = speed_after(1);
356 char string[BCSTRLEN];
357 sprintf(string,"set %s", FloatAuto::curve_name(mode));
359 !changed_edl ? LOAD_AUTOMATION :
360 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
361 update_gui(changed_edl);
364 void MWindow::clear_automation()
368 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
369 edl->local_session->get_selectionend());
370 int changed_edl = speed_after(1);
372 undo_after(_("clear keyframes"),
373 !changed_edl ? LOAD_AUTOMATION :
374 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
375 update_gui(changed_edl);
378 int MWindow::clear_default_keyframe()
382 edl->tracks->clear_default_keyframe();
383 int changed_edl = speed_after(1);
385 undo_after(_("clear default keyframe"),
386 !changed_edl ? LOAD_AUTOMATION :
387 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
388 update_gui(changed_edl);
392 void MWindow::clear_labels()
395 clear_labels(edl->local_session->get_selectionstart(),
396 edl->local_session->get_selectionend());
397 undo_after(_("clear labels"), LOAD_TIMEBAR);
399 gui->update_timebar(1);
400 cwindow->update(0, 0, 0, 0, 1);
404 int MWindow::clear_labels(double start, double end)
406 edl->labels->clear(start, end, 0);
410 void MWindow::concatenate_tracks()
413 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
414 edl->session->autos_follow_edits);
416 undo_after(_("concatenate tracks"), LOAD_EDITS);
419 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
420 cwindow->refresh_frame(CHANGE_EDL);
424 int MWindow::copy_flags(int copy_flags)
426 if( !edl->session->labels_follow_edits )
427 copy_flags &= ~COPY_LABELS;
428 if( !edl->session->autos_follow_edits )
429 copy_flags &= ~COPY_AUTOS;
430 if( !edl->session->plugins_follow_edits )
431 copy_flags &= ~COPY_PLUGINS;
437 copy(edl->local_session->get_selectionstart(),
438 edl->local_session->get_selectionend());
441 int MWindow::copy(double start, double end)
443 if( start == end ) return 1;
446 edl->copy(copy_flags(), start, end, &file, "", 1);
447 const char *file_string = file.string();
448 long file_length = strlen(file_string);
449 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
450 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
455 int MWindow::copy_automation()
458 double start = edl->local_session->get_selectionstart();
459 double end = edl->local_session->get_selectionend();
460 edl->tracks->copy_automation(start, end, &file, 0, 1);
461 const char *file_string = file.string();
462 long file_length = strlen(file_string);
463 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
464 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
468 int MWindow::copy_default_keyframe()
471 double start = edl->local_session->get_selectionstart();
472 double end = edl->local_session->get_selectionend();
473 edl->tracks->copy_automation(start, end, &file, 1, 0);
474 const char *file_string = file.string();
475 long file_length = strlen(file_string);
476 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
477 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
482 // Uses cropping coordinates in edl session to crop and translate video.
483 // We modify the projector since camera automation depends on the track size.
484 void MWindow::crop_video()
488 // Clamp EDL crop region
489 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
490 edl->session->crop_x1 ^= edl->session->crop_x2;
491 edl->session->crop_x2 ^= edl->session->crop_x1;
492 edl->session->crop_x1 ^= edl->session->crop_x2;
494 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
495 edl->session->crop_y1 ^= edl->session->crop_y2;
496 edl->session->crop_y2 ^= edl->session->crop_y1;
497 edl->session->crop_y1 ^= edl->session->crop_y2;
500 float old_projector_x = (float)edl->session->output_w / 2;
501 float old_projector_y = (float)edl->session->output_h / 2;
502 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
503 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
504 float projector_offset_x = -(new_projector_x - old_projector_x);
505 float projector_offset_y = -(new_projector_y - old_projector_y);
507 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
509 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
510 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
511 edl->session->crop_x1 = 0;
512 edl->session->crop_y1 = 0;
513 edl->session->crop_x2 = edl->session->output_w;
514 edl->session->crop_y2 = edl->session->output_h;
516 // Recalculate aspect ratio
517 if( defaults->get("AUTOASPECT", 0) ) {
518 create_aspect_ratio(edl->session->aspect_w,
519 edl->session->aspect_h,
520 edl->session->output_w,
521 edl->session->output_h);
524 undo_after(_("crop"), LOAD_ALL);
527 cwindow->refresh_frame(CHANGE_ALL);
533 double start = edl->local_session->get_selectionstart();
534 double end = edl->local_session->get_selectionend();
535 if( EQUIV(start,end) )
541 void MWindow::blade(double position)
544 edl->blade(position);
547 undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
549 update_plugin_guis();
550 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
551 cwindow->update(1, 0, 0, 0, 1);
552 awindow->gui->async_update_assets();
553 cwindow->refresh_frame(CHANGE_EDL);
556 void MWindow::cut(double start, double end, double new_position)
560 edl->clear(start, end,
561 edl->session->labels_follow_edits,
562 edl->session->plugins_follow_edits,
563 edl->session->autos_follow_edits);
567 undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
568 if( new_position >= 0 ) {
569 edl->local_session->set_selectionstart(new_position);
570 edl->local_session->set_selectionend(new_position);
573 update_plugin_guis();
574 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
575 cwindow->update(1, 0, 0, 0, 1);
576 awindow->gui->async_update_assets();
577 cwindow->refresh_frame(CHANGE_EDL);
580 void MWindow::cut_left_edit()
582 double start_pos = edl->local_session->get_selectionstart(1);
583 double position = edl->prev_edit(start_pos);
584 if( position < start_pos )
585 cut(position, start_pos, position);
588 void MWindow::cut_right_edit()
590 double end_pos = edl->local_session->get_selectionend(1);
591 double position = edl->next_edit(end_pos);
592 if( end_pos < position )
593 cut(end_pos, position, end_pos);
596 void MWindow::cut_left_label()
598 double start_pos = edl->local_session->get_selectionstart(1);
599 Label *left_label = edl->labels->prev_label(start_pos);
600 if( !left_label ) return;
601 double position = left_label->position;
602 if( position < start_pos )
603 cut(position, start_pos, position);
606 void MWindow::cut_right_label()
608 double end_pos = edl->local_session->get_selectionend(1);
609 Label *right_label = edl->labels->next_label(end_pos);
610 if( !right_label ) return;
611 double position = right_label->position;
612 if( end_pos < position )
613 cut(end_pos, position, end_pos);
616 int MWindow::cut_automation()
621 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
622 edl->local_session->get_selectionend());
623 int changed_edl = speed_after(1);
625 undo_after(_("cut keyframes"),
626 !changed_edl ? LOAD_AUTOMATION :
627 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
628 update_gui(changed_edl);
632 int MWindow::cut_default_keyframe()
637 copy_default_keyframe();
638 edl->tracks->clear_default_keyframe();
639 int changed_edl = speed_after(1);
641 undo_after(_("cut default keyframe"),
642 !changed_edl ? LOAD_AUTOMATION :
643 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
644 update_gui(changed_edl);
649 void MWindow::delete_track()
651 if( edl->tracks->last )
652 delete_track(edl->tracks->last);
655 void MWindow::delete_tracks()
658 edl->tracks->delete_tracks();
659 undo_after(_("delete tracks"), LOAD_ALL);
663 update_plugin_states();
665 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
666 cwindow->refresh_frame(CHANGE_EDL);
669 void MWindow::delete_track(Track *track)
672 edl->tracks->delete_track(track);
673 undo_after(_("delete track"), LOAD_ALL);
676 update_plugin_states();
678 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
679 cwindow->refresh_frame(CHANGE_EDL);
684 // Insert data from clipboard
685 void MWindow::insert(double position, FileXML *file,
686 int edit_labels, int edit_plugins, int edit_autos,
687 EDL *parent_edl, Track *first_track, int overwrite)
689 // For clipboard pasting make the new edl use a separate session
690 // from the master EDL. Then it can be resampled to the master rates.
691 // For splice, overwrite, and dragging need same session to get the assets.
692 EDL *edl = new EDL(parent_edl);
693 ArrayList<EDL*> new_edls;
694 uint32_t load_flags = LOAD_ALL;
697 new_edls.append(edl);
698 edl->create_objects();
703 if( parent_edl ) load_flags &= ~LOAD_SESSION;
704 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
705 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
707 edl->load_xml(file, load_flags);
710 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
714 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
715 edit_labels, edit_plugins, edit_autos, overwrite);
716 // if( vwindow->edl )
717 // printf("MWindow::insert 5 %f %f\n",
718 // vwindow->edl->local_session->in_point,
719 // vwindow->edl->local_session->out_point);
720 new_edls.remove_all();
721 edl->Garbage::remove_user();
722 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
725 void MWindow::insert_effects_canvas(double start,
728 Track *dest_track = session->track_highlighted;
729 if( !dest_track ) return;
733 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
734 PluginServer *plugin = session->drag_pluginservers->values[i];
735 insert_effect(plugin->title, 0, dest_track,
736 i == 0 ? session->pluginset_highlighted : 0,
737 start, length, PLUGIN_STANDALONE);
741 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
743 sync_parameters(CHANGE_EDL);
744 // GUI updated in TrackCanvas, after current_operations are reset
747 void MWindow::insert_effects_cwindow(Track *dest_track)
749 if( !dest_track ) return;
754 double length = dest_track->get_length();
756 if( edl->local_session->get_selectionend() >
757 edl->local_session->get_selectionstart() ) {
758 start = edl->local_session->get_selectionstart();
759 length = edl->local_session->get_selectionend() -
760 edl->local_session->get_selectionstart();
763 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
764 PluginServer *plugin = session->drag_pluginservers->values[i];
765 insert_effect(plugin->title, 0, dest_track, 0,
766 start, length, PLUGIN_STANDALONE);
770 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
772 sync_parameters(CHANGE_EDL);
773 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
776 void MWindow::insert_effect(char *title,
777 SharedLocation *shared_location,
780 int single_standalone)
782 Track *current = edl->tracks->first;
783 SharedLocation shared_location_local;
784 shared_location_local.copy_from(shared_location);
786 for( ; current; current=NEXT ) {
787 if( current->data_type == data_type &&
789 insert_effect(title, &shared_location_local,
790 current, 0, 0, 0, plugin_type);
793 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
794 plugin_type = PLUGIN_SHAREDPLUGIN;
795 shared_location_local.module = edl->tracks->number_of(current);
796 shared_location_local.plugin = current->plugin_set.total - 1;
805 void MWindow::insert_effect(char *title,
806 SharedLocation *shared_location,
808 PluginSet *plugin_set,
813 KeyFrame *default_keyframe = 0;
814 PluginServer *server = 0;
815 // Get default keyframe
816 if( plugin_type == PLUGIN_STANDALONE ) {
817 default_keyframe = new KeyFrame;
818 server = new PluginServer(*scan_plugindb(title, track->data_type));
820 server->open_plugin(0, preferences, edl, 0);
821 server->save_data(default_keyframe);
823 // Insert plugin object
824 track->insert_effect(title, shared_location,
825 default_keyframe, plugin_set,
826 start, length, plugin_type);
829 if( plugin_type == PLUGIN_STANDALONE ) {
830 server->close_plugin();
832 delete default_keyframe;
836 int MWindow::modify_edithandles()
839 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
840 edl->modify_edithandles(session->drag_start,
841 session->drag_position, session->drag_handle, handle_mode,
842 edl->session->labels_follow_edits,
843 edl->session->plugins_follow_edits,
844 edl->session->autos_follow_edits,
845 session->drag_edit->group_id);
846 finish_modify_handles();
847 //printf("MWindow::modify_handles 1\n");
851 int MWindow::modify_pluginhandles()
855 edl->modify_pluginhandles(session->drag_start,
856 session->drag_position,
857 session->drag_handle,
858 edl->session->edit_handle_mode[session->drag_button],
859 edl->session->labels_follow_edits,
860 edl->session->autos_follow_edits,
861 session->trim_edits);
863 finish_modify_handles();
869 // Common to edithandles and plugin handles
870 void MWindow::finish_modify_handles()
872 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
873 double position = -1;
874 switch( edit_mode ) {
876 position = !session->drag_handle ?
877 session->drag_start : session->drag_position;
881 position = session->drag_position;
885 position = session->drag_start;
888 if( position >= 0 ) {
889 edl->local_session->set_selectionstart(position);
890 edl->local_session->set_selectionend(position);
892 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
896 sync_parameters(CHANGE_EDL);
897 update_plugin_guis();
898 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
899 // label list can be modified
900 awindow->gui->async_update_assets();
901 cwindow->update(1, 0, 0, 0, 1);
904 void MWindow::match_output_size(Track *track)
907 track->track_w = edl->session->output_w;
908 track->track_h = edl->session->output_h;
910 undo_after(_("match output size"), LOAD_ALL);
913 sync_parameters(CHANGE_EDL);
917 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
919 ArrayList<Edit*> edits;
921 delete_edits(&edits, msg, collapse);
924 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
926 if( !edits->size() ) return;
928 if( edl->session->labels_follow_edits )
929 edl->delete_edit_labels(edits, collapse);
930 edl->delete_edits(edits, collapse);
933 undo_after(msg, LOAD_EDITS);
936 cwindow->refresh_frame(CHANGE_EDL);
937 update_plugin_guis();
938 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
941 void MWindow::delete_edits(int collapse)
943 ArrayList<Edit*> edits;
944 edl->tracks->get_selected_edits(&edits);
945 delete_edits(&edits,_("del edit"), collapse);
948 // collapse - delete from timeline, not collapse replace with silence
949 // packed - omit unselected from selection, unpacked - replace unselected with silence
950 void MWindow::cut_selected_edits(int collapse, int packed)
952 selected_edits_to_clipboard(packed);
953 ArrayList<Edit*> edits;
954 edl->tracks->get_selected_edits(&edits);
955 delete_edits(&edits, _("cut edit"), collapse);
959 void MWindow::move_edits(ArrayList<Edit*> *edits,
960 Track *track, double position, int mode)
963 // lockout timebar labels update
964 // labels can be deleted with tooltip repeater running
965 cwindow->gui->lock_window("Tracks::move_edits");
966 edl->tracks->move_edits(edits, track, position,
967 edl->session->labels_follow_edits,
968 edl->session->plugins_follow_edits,
969 edl->session->autos_follow_edits, mode);
970 cwindow->gui->timebar->update(1);
971 cwindow->gui->unlock_window();
974 undo_after(_("move edit"), LOAD_ALL);
977 cwindow->refresh_frame(CHANGE_EDL);
979 update_plugin_guis();
980 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
983 void MWindow::selected_edits_to_clipboard(int packed)
985 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
986 edl->session->labels_follow_edits,
987 edl->session->autos_follow_edits,
988 edl->session->plugins_follow_edits);
989 if( !new_edl ) return;
991 new_edl->copy(COPY_EDL, &file, "", 1);
992 const char *file_string = file.string();
993 long file_length = strlen(file_string);
994 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
995 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
996 new_edl->remove_user();
999 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1000 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1002 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1004 char *string = new char[len];
1005 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1007 file.read_from_string(string);
1009 EDL *clip = new EDL();
1010 clip->create_objects();
1011 if( !clip->load_xml(&file, LOAD_ALL) ) {
1013 edl->paste_edits(clip, first_track, position, overwrite,
1014 edit_edits, edit_labels, edit_autos, edit_plugins);
1016 undo_after(_("paste clip"), LOAD_ALL);
1018 cwindow->refresh_frame(CHANGE_EDL);
1020 update_plugin_guis();
1021 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1023 clip->remove_user();
1026 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1029 // lockout timebar labels update
1030 // labels can be deleted with tooltip repeater running
1031 cwindow->gui->lock_window("Tracks::move_group");
1033 ArrayList<Edit *>edits;
1034 edl->tracks->get_selected_edits(&edits);
1035 if( edl->session->labels_follow_edits )
1036 edl->delete_edit_labels(&edits, 0);
1037 edl->delete_edits(&edits, 0);
1038 edl->paste_edits(group, first_track, position, overwrite, 1,
1039 edl->session->labels_follow_edits,
1040 edl->session->autos_follow_edits,
1041 edl->session->plugins_follow_edits);
1042 cwindow->gui->timebar->update(1);
1043 cwindow->gui->unlock_window();
1044 // big debate over whether to do this, must either clear selected, or no tweaking
1045 // edl->tracks->clear_selected_edits();
1048 undo_after(_("move group"), LOAD_ALL);
1050 cwindow->refresh_frame(CHANGE_EDL);
1052 update_plugin_guis();
1053 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1056 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1059 edl->tracks->move_effect(plugin, track, position);
1061 undo_after(_("paste effect"), LOAD_ALL);
1064 cwindow->refresh_frame(CHANGE_EDL);
1065 update_plugin_guis();
1066 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1069 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1072 edl->tracks->move_effect(plugin, plugin_set, position);
1074 undo_after(_("move effect"), LOAD_ALL);
1077 cwindow->refresh_frame(CHANGE_EDL);
1078 update_plugin_guis();
1079 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1082 void MWindow::move_plugins_up(PluginSet *plugin_set)
1086 plugin_set->track->move_plugins_up(plugin_set);
1089 undo_after(_("move effect up"), LOAD_ALL);
1091 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1092 sync_parameters(CHANGE_EDL);
1095 void MWindow::move_plugins_down(PluginSet *plugin_set)
1099 plugin_set->track->move_plugins_down(plugin_set);
1102 undo_after(_("move effect down"), LOAD_ALL);
1104 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1105 sync_parameters(CHANGE_EDL);
1108 void MWindow::move_track_down(Track *track)
1111 edl->tracks->move_track_down(track);
1113 undo_after(_("move track down"), LOAD_ALL);
1116 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1117 sync_parameters(CHANGE_EDL);
1121 void MWindow::move_tracks_down()
1124 edl->tracks->move_tracks_down();
1126 undo_after(_("move tracks down"), LOAD_ALL);
1129 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1130 sync_parameters(CHANGE_EDL);
1134 void MWindow::move_track_up(Track *track)
1137 edl->tracks->move_track_up(track);
1139 undo_after(_("move track up"), LOAD_ALL);
1141 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1142 sync_parameters(CHANGE_EDL);
1146 void MWindow::move_tracks_up()
1149 edl->tracks->move_tracks_up();
1151 undo_after(_("move tracks up"), LOAD_ALL);
1153 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1154 sync_parameters(CHANGE_EDL);
1158 void MWindow::mute_selection()
1160 double start = edl->local_session->get_selectionstart();
1161 double end = edl->local_session->get_selectionend();
1162 if( start != end ) {
1164 edl->clear(start, end, 0,
1165 edl->session->plugins_follow_edits,
1166 edl->session->autos_follow_edits);
1167 edl->local_session->set_selectionend(end);
1168 edl->local_session->set_selectionstart(start);
1169 edl->paste_silence(start, end, 0,
1170 edl->session->plugins_follow_edits,
1171 edl->session->autos_follow_edits);
1174 undo_after(_("mute"), LOAD_EDITS);
1177 update_plugin_guis();
1178 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1179 cwindow->refresh_frame(CHANGE_EDL);
1184 void MWindow::overwrite(EDL *source, int all)
1188 LocalSession *src = source->local_session;
1189 double src_start = all ? 0 :
1190 src->inpoint_valid() ? src->get_inpoint() :
1191 src->outpoint_valid() ? 0 :
1192 src->get_selectionstart();
1193 double src_end = all ? source->tracks->total_length() :
1194 src->outpoint_valid() ? src->get_outpoint() :
1195 src->inpoint_valid() ? source->tracks->total_length() :
1196 src->get_selectionend();
1197 double overwrite_len = src_end - src_start;
1198 double dst_start = edl->local_session->get_selectionstart();
1199 double dst_len = edl->local_session->get_selectionend() - dst_start;
1202 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1203 // in/out points or selection present and shorter than overwrite range
1204 // shorten the copy range
1205 overwrite_len = dst_len;
1208 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1210 // HACK around paste_edl get_start/endselection on its own
1211 // so we need to clear only when not using both io points
1212 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1213 if( edl->local_session->get_inpoint() < 0 ||
1214 edl->local_session->get_outpoint() < 0 )
1215 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1217 paste(dst_start, dst_start + overwrite_len, &file, 0, 0, 0, 0, 0);
1219 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1220 edl->local_session->set_selectionend(dst_start + overwrite_len);
1223 undo_after(_("overwrite"), LOAD_EDITS);
1226 update_plugin_guis();
1227 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1228 sync_parameters(CHANGE_EDL);
1231 // For splice and overwrite
1232 int MWindow::paste(double start, double end, FileXML *file,
1233 int edit_labels, int edit_plugins, int edit_autos,
1234 Track *first_track, int overwrite)
1238 // Want to insert with assets shared with the master EDL.
1240 edit_labels, edit_plugins, edit_autos,
1241 edl, first_track, overwrite);
1246 // For editing using insertion point
1247 void MWindow::paste()
1249 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1252 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1254 //double end = edl->local_session->get_selectionend();
1255 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1258 char *string = new char[len];
1260 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1262 file.read_from_string(string);
1263 if( clear_selection ) clear(0);
1265 insert(start, &file,
1266 edl->session->labels_follow_edits,
1267 edl->session->plugins_follow_edits,
1268 edl->session->autos_follow_edits,
1269 0, first_track, overwrite);
1276 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1278 update_plugin_guis();
1279 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1280 awindow->gui->async_update_assets();
1281 sync_parameters(CHANGE_EDL);
1286 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1291 if( session->drag_assets->total ) {
1292 load_assets(session->drag_assets,
1293 position, LOADMODE_PASTE, dest_track, 0,
1294 edl->session->labels_follow_edits,
1295 edl->session->plugins_follow_edits,
1296 edl->session->autos_follow_edits,
1301 if( session->drag_clips->total ) {
1302 paste_edls(session->drag_clips,
1303 LOADMODE_PASTE, dest_track, position,
1304 edl->session->labels_follow_edits,
1305 edl->session->plugins_follow_edits,
1306 edl->session->autos_follow_edits,
1313 undo_after(_("paste assets"), LOAD_EDITS);
1315 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1316 sync_parameters(CHANGE_EDL);
1320 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1321 double position, int load_mode, Track *first_track, RecordLabels *labels,
1322 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1324 if( load_mode == LOADMODE_RESOURCESONLY )
1325 load_mode = LOADMODE_ASSETSONLY;
1326 const int debug = 0;
1327 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1328 if( position < 0 ) position = edl->local_session->get_selectionstart();
1330 ArrayList<EDL*> new_edls;
1331 for( int i=0; i<new_assets->total; ++i ) {
1332 Indexable *indexable = new_assets->get(i);
1333 if( indexable->is_asset ) {
1334 remove_asset_from_caches((Asset*)indexable);
1336 EDL *new_edl = new EDL;
1337 new_edl->create_objects();
1338 new_edl->copy_session(edl);
1339 if( !indexable->is_asset ) {
1340 EDL *nested_edl = (EDL*)indexable;
1341 new_edl->create_nested(nested_edl);
1342 new_edl->set_path(indexable->path);
1345 Asset *asset = (Asset*)indexable;
1346 asset_to_edl(new_edl, asset);
1348 new_edls.append(new_edl);
1351 for( RecordLabel *label=labels->first; label; label=label->next ) {
1352 new_edl->labels->toggle_label(label->position, label->position);
1356 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1358 paste_edls(&new_edls, load_mode, first_track, position,
1359 edit_labels, edit_plugins, edit_autos, overwrite);
1360 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1363 for( int i=0; i<new_edls.size(); ++i )
1364 new_edls.get(i)->Garbage::remove_user();
1366 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1369 int MWindow::paste_automation()
1371 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1376 char *string = new char[len];
1377 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1379 file.read_from_string(string);
1381 double start = edl->local_session->get_selectionstart();
1382 double end = edl->local_session->get_selectionend();
1383 edl->tracks->clear_automation(start, end);
1384 edl->tracks->paste_automation(start, &file, 0, 1,
1385 edl->session->typeless_keyframes);
1386 int changed_edl = speed_after(1);
1388 undo_after(_("paste keyframes"),
1389 !changed_edl ? LOAD_AUTOMATION :
1390 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1391 update_gui(changed_edl);
1397 int MWindow::paste_default_keyframe()
1399 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1404 char *string = new char[len];
1405 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1407 file.read_from_string(string);
1409 double start = edl->local_session->get_selectionstart();
1410 edl->tracks->paste_automation(start, &file, 1, 0,
1411 edl->session->typeless_keyframes);
1412 // edl->tracks->paste_default_keyframe(&file);
1413 int changed_edl = speed_after(1);
1414 undo_after(_("paste default keyframe"),
1415 !changed_edl ? LOAD_AUTOMATION :
1416 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1418 update_gui(changed_edl);
1425 // Insert edls with project deletion and index file generation.
1426 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1427 Track *first_track, double current_position,
1428 int edit_labels, int edit_plugins, int edit_autos,
1432 ArrayList<Track*> destination_tracks;
1433 int need_new_tracks = 0;
1436 if( !new_edls->total ) return 0;
1439 // double original_length = edl->tracks->total_length();
1440 // double original_preview_end = edl->local_session->preview_end;
1443 // Delete current project
1444 if( load_mode == LOADMODE_REPLACE ||
1445 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1447 edl->save_defaults(defaults);
1449 edl->Garbage::remove_user();
1451 edl->create_objects();
1452 edl->copy_session(new_edls->values[0]);
1453 edl->copy_mixers(new_edls->values[0]);
1454 gui->mainmenu->update_toggles(0);
1455 gui->unlock_window();
1456 gwindow->gui->update_toggles(1);
1457 gui->lock_window("MWindow::paste_edls");
1459 // Insert labels for certain modes constitutively
1463 // Force reset of preview
1464 // original_length = 0;
1465 // original_preview_end = -1;
1471 // Create new tracks in master EDL
1472 if( load_mode == LOADMODE_REPLACE ||
1473 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1474 load_mode == LOADMODE_NEW_TRACKS ) {
1476 need_new_tracks = 1;
1477 for( int i=0; i<new_edls->total; ++i ) {
1478 EDL *new_edl = new_edls->values[i];
1479 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1480 switch( current->data_type ) {
1482 edl->tracks->add_video_track(0, 0);
1483 if( current->draw ) edl->tracks->last->draw = 1;
1486 edl->tracks->add_audio_track(0, 0);
1488 case TRACK_SUBTITLE:
1489 edl->tracks->add_subttl_track(0, 0);
1494 destination_tracks.append(edl->tracks->last);
1497 // Base track count on first EDL only for concatenation
1498 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1500 edl->session->highlighted_track = edl->tracks->total() - 1;
1503 // Recycle existing tracks of master EDL
1504 if( load_mode == LOADMODE_CONCATENATE ||
1505 load_mode == LOADMODE_PASTE ||
1506 load_mode == LOADMODE_NESTED ) {
1507 Track *current = first_track ? first_track : edl->tracks->first;
1508 for( ; current; current=NEXT ) {
1509 if( current->record ) {
1510 destination_tracks.append(current);
1516 int destination_track = 0;
1517 double *paste_position = new double[destination_tracks.total];
1519 // Iterate through the edls
1520 for( int i=0; i<new_edls->total; ++i ) {
1522 EDL *new_edl = new_edls->values[i];
1523 double edl_length = new_edl->local_session->clipboard_length ?
1524 new_edl->local_session->clipboard_length :
1525 new_edl->tracks->total_length();
1526 // printf("MWindow::paste_edls 2 %f %f\n",
1527 // new_edl->local_session->clipboard_length,
1528 // new_edl->tracks->total_length());
1532 // Convert EDL to master rates
1533 new_edl->resample(new_edl->session->sample_rate,
1534 edl->session->sample_rate,
1536 new_edl->resample(new_edl->session->frame_rate,
1537 edl->session->frame_rate,
1540 // Add assets and prepare index files
1541 for( Asset *new_asset=new_edl->assets->first;
1542 new_asset; new_asset=new_asset->next ) {
1543 mainindexes->add_next_asset(0, new_asset);
1545 // Capture index file status from mainindex test
1546 edl->update_assets(new_edl);
1548 // Get starting point of insertion. Need this to paste labels.
1549 switch( load_mode ) {
1550 case LOADMODE_REPLACE:
1551 current_position = 0;
1552 case LOADMODE_NEW_TRACKS:
1555 case LOADMODE_CONCATENATE:
1556 case LOADMODE_REPLACE_CONCATENATE:
1557 destination_track = 0;
1558 if( destination_tracks.total )
1559 current_position = destination_tracks.values[0]->get_length();
1561 current_position = 0;
1564 case LOADMODE_PASTE:
1565 case LOADMODE_NESTED:
1566 destination_track = 0;
1568 for( int j=0; j<destination_tracks.total; ++j ) {
1569 paste_position[j] = (current_position >= 0) ?
1571 edl->local_session->get_selectionstart();
1576 case LOADMODE_RESOURCESONLY:
1577 edl->add_clip(new_edl);
1581 if( load_mode != LOADMODE_RESOURCESONLY &&
1582 load_mode != LOADMODE_ASSETSONLY ) {
1585 if( load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED )
1586 edl->labels->insert_labels(new_edl->labels,
1587 destination_tracks.total ? paste_position[0] : 0.0,
1590 edl->labels->insert_labels(new_edl->labels, current_position,
1593 double total_length = new_edl->tracks->total_length();
1594 for( Track *new_track=new_edl->tracks->first;
1595 new_track; new_track=new_track->next ) {
1596 // Get destination track of same type as new_track
1598 k < destination_tracks.total &&
1599 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1600 ++k, ++destination_track ) {
1601 if( destination_track >= destination_tracks.total - 1 )
1602 destination_track = 0;
1605 // Insert data into destination track
1606 if( destination_track < destination_tracks.total &&
1607 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1608 Track *track = destination_tracks.values[destination_track];
1610 // Replace default keyframes if first EDL and new tracks were created.
1611 // This means data copied from one track and pasted to another won't retain
1612 // the camera position unless it's a keyframe. If it did, previous data in the
1613 // track might get unknowingly corrupted. Ideally we would detect when differing
1614 // default keyframes existed and create discrete keyframes for both.
1615 int replace_default = (i == 0) && need_new_tracks;
1617 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1618 // Insert new track at current position
1619 switch( load_mode ) {
1620 case LOADMODE_REPLACE_CONCATENATE:
1621 case LOADMODE_CONCATENATE:
1622 current_position = track->get_length();
1625 case LOADMODE_PASTE:
1626 case LOADMODE_NESTED:
1627 current_position = paste_position[destination_track];
1628 paste_position[destination_track] += new_track->get_length();
1632 double length = overwrite >= 0 ?
1633 new_track->get_length() : total_length;
1634 track->clear(current_position,
1635 current_position + length,
1637 edit_labels, edit_plugins, edit_autos,
1641 track->insert_track(new_track, current_position, replace_default,
1642 edit_plugins, edit_autos, edl_length);
1646 // Get next destination track
1647 destination_track++;
1648 if( destination_track >= destination_tracks.total )
1649 destination_track = 0;
1653 if( load_mode == LOADMODE_PASTE ||
1654 load_mode == LOADMODE_NESTED )
1655 current_position += edl_length;
1659 // Move loading of clips and vwindow to the end - this fixes some
1660 // strange issue, for index not being shown
1661 // Assume any paste operation from the same EDL won't contain any clips.
1662 // If it did it would duplicate every clip here.
1663 for( int i=0; i<new_edls->total; ++i ) {
1664 EDL *new_edl = new_edls->get(i);
1666 for( int j=0; j<new_edl->clips.size(); ++j ) {
1667 edl->add_clip(new_edl->clips[j]);
1669 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1670 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1673 if( new_edl->total_vwindow_edls() ) {
1674 // if( edl->vwindow_edl )
1675 // edl->vwindow_edl->Garbage::remove_user();
1676 // edl->vwindow_edl = new EDL(edl);
1677 // edl->vwindow_edl->create_objects();
1678 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1680 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1681 EDL *vwindow_edl = new EDL(edl);
1682 vwindow_edl->create_objects();
1683 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1684 edl->append_vwindow_edl(vwindow_edl, 0);
1689 if( paste_position ) delete [] paste_position;
1691 // This is already done in load_filenames and everything else that uses paste_edls
1692 // update_project(load_mode);
1694 // Fix preview range
1695 // if( EQUIV(original_length, original_preview_end) )
1697 // edl->local_session->preview_end = edl->tracks->total_length();
1700 // Start examining next batch of index files
1701 mainindexes->start_build();
1703 // Don't save a backup after loading since the loaded file is on disk already.
1708 void MWindow::paste_silence()
1710 double start = edl->local_session->get_selectionstart();
1711 double end = edl->local_session->get_selectionend();
1712 if( EQUIV(start, end) ) {
1713 if( edl->session->frame_rate > 0 )
1714 end += 1./edl->session->frame_rate;
1716 undo_before(_("silence"), this);
1717 edl->paste_silence(start, end,
1718 edl->session->labels_follow_edits,
1719 edl->session->plugins_follow_edits,
1720 edl->session->autos_follow_edits);
1723 undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1725 update_plugin_guis();
1727 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1728 cwindow->update(1, 0, 0, 0, 1);
1729 cwindow->refresh_frame(CHANGE_EDL);
1732 void MWindow::detach_transition(Transition *transition)
1735 hide_plugin(transition, 1);
1736 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1737 transition->edit->detach_transition();
1739 undo_after(_("detach transition"), LOAD_ALL);
1741 if( is_video ) restart_brender();
1742 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1743 sync_parameters(CHANGE_EDL);
1746 void MWindow::detach_transitions()
1748 gui->lock_window("MWindow::detach_transitions 1");
1751 double start = edl->local_session->get_selectionstart();
1752 double end = edl->local_session->get_selectionend();
1753 edl->tracks->clear_transitions(start, end);
1756 undo_after(_("detach transitions"), LOAD_EDITS);
1758 sync_parameters(CHANGE_EDL);
1759 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1760 gui->unlock_window();
1763 void MWindow::paste_transition()
1765 // Only the first transition gets dropped.
1766 PluginServer *server = session->drag_pluginservers->values[0];
1769 edl->tracks->paste_transition(server, session->edit_highlighted);
1771 undo_after(_("transition"), LOAD_EDITS);
1773 if( server->video ) restart_brender();
1774 sync_parameters(CHANGE_ALL);
1777 void MWindow::paste_transitions(int track_type, char *title)
1779 gui->lock_window("MWindow::detach_transitions 1");
1782 double start = edl->local_session->get_selectionstart();
1783 double end = edl->local_session->get_selectionend();
1784 edl->tracks->paste_transitions(start, end, track_type, title);
1786 undo_after(_("attach transitions"), LOAD_EDITS);
1788 sync_parameters(CHANGE_EDL);
1789 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1790 gui->unlock_window();
1793 void MWindow::paste_transition_cwindow(Track *dest_track)
1795 PluginServer *server = session->drag_pluginservers->values[0];
1797 edl->tracks->paste_video_transition(server, 1);
1799 undo_after(_("transition"), LOAD_EDITS);
1801 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1802 sync_parameters(CHANGE_ALL);
1805 void MWindow::paste_audio_transition()
1807 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1810 char string[BCTEXTLEN];
1811 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1812 gui->show_message(string);
1817 edl->tracks->paste_audio_transition(server);
1819 undo_after(_("transition"), LOAD_EDITS);
1821 sync_parameters(CHANGE_EDL);
1822 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1825 void MWindow::paste_video_transition()
1827 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1830 char string[BCTEXTLEN];
1831 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1832 gui->show_message(string);
1838 edl->tracks->paste_video_transition(server);
1840 undo_after(_("transition"), LOAD_EDITS);
1842 sync_parameters(CHANGE_EDL);
1844 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1847 void MWindow::shuffle_edits()
1849 gui->lock_window("MWindow::shuffle_edits 1");
1852 double start = edl->local_session->get_selectionstart();
1853 double end = edl->local_session->get_selectionend();
1855 edl->tracks->shuffle_edits(start, end);
1858 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1860 sync_parameters(CHANGE_EDL);
1862 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1863 gui->unlock_window();
1866 void MWindow::reverse_edits()
1868 gui->lock_window("MWindow::reverse_edits 1");
1871 double start = edl->local_session->get_selectionstart();
1872 double end = edl->local_session->get_selectionend();
1874 edl->tracks->reverse_edits(start, end);
1877 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1879 sync_parameters(CHANGE_EDL);
1881 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1882 gui->unlock_window();
1885 void MWindow::align_edits()
1887 gui->lock_window("MWindow::align_edits 1");
1890 double start = edl->local_session->get_selectionstart();
1891 double end = edl->local_session->get_selectionend();
1893 edl->tracks->align_edits(start, end);
1896 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1898 sync_parameters(CHANGE_EDL);
1900 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1901 gui->unlock_window();
1904 void MWindow::set_edit_length(double length)
1906 gui->lock_window("MWindow::set_edit_length 1");
1909 double start = edl->local_session->get_selectionstart();
1910 double end = edl->local_session->get_selectionend();
1912 edl->tracks->set_edit_length(start, end, length);
1915 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1917 sync_parameters(CHANGE_EDL);
1919 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1920 gui->unlock_window();
1924 void MWindow::set_transition_length(Transition *transition, double length)
1926 gui->lock_window("MWindow::set_transition_length 1");
1929 //double start = edl->local_session->get_selectionstart();
1930 //double end = edl->local_session->get_selectionend();
1932 edl->tracks->set_transition_length(transition, length);
1935 undo_after(_("transition length"), LOAD_EDITS);
1937 edl->session->default_transition_length = length;
1938 sync_parameters(CHANGE_PARAMS);
1939 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1940 gui->unlock_window();
1943 void MWindow::set_transition_length(double length)
1945 gui->lock_window("MWindow::set_transition_length 2");
1948 double start = edl->local_session->get_selectionstart();
1949 double end = edl->local_session->get_selectionend();
1951 edl->tracks->set_transition_length(start, end, length);
1954 undo_after(_("transition length"), LOAD_EDITS);
1956 edl->session->default_transition_length = length;
1957 sync_parameters(CHANGE_PARAMS);
1959 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1960 gui->unlock_window();
1964 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1966 calling_window_gui->unlock_window();
1968 if( undo->redo_load_flags() & LOAD_SESSION )
1971 cwindow->gui->lock_window("MWindow::redo_entry 1");
1972 for( int i=0; i<vwindows.size(); ++i ) {
1973 if( vwindows.get(i)->is_running() ) {
1974 if( calling_window_gui != vwindows.get(i)->gui ) {
1975 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1979 gui->lock_window("MWindow::redo_entry 3");
1985 update_plugin_states();
1986 update_plugin_guis();
1988 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
1989 gui->update_proxy_toggle();
1990 gui->unlock_window();
1991 cwindow->update(1, 1, 1, 1, 1);
1992 cwindow->gui->unlock_window();
1994 for( int i=0; i < vwindows.size(); ++i ) {
1995 if( vwindows.get(i)->is_running() ) {
1996 if( calling_window_gui != vwindows.get(i)->gui ) {
1997 vwindows.get(i)->gui->unlock_window();
2002 awindow->gui->async_update_assets();
2004 cwindow->refresh_frame(CHANGE_ALL);
2005 calling_window_gui->lock_window("MWindow::redo_entry 4");
2009 void MWindow::resize_track(Track *track, int w, int h)
2012 // We have to move all maskpoints so they do not move in relation to image areas
2013 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2014 (w - track->track_w) / 2,
2015 (h - track->track_h) / 2);
2018 undo_after(_("resize track"), LOAD_ALL);
2022 sync_parameters(CHANGE_EDL);
2026 void MWindow::set_inpoint()
2029 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2031 undo_after(_("in point"), LOAD_TIMEBAR);
2032 gui->update_timebar(1);
2034 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2035 cwindow->gui->timebar->update(1);
2036 cwindow->gui->unlock_window();
2039 void MWindow::set_outpoint()
2042 edl->set_outpoint(edl->local_session->get_selectionend(1));
2044 undo_after(_("out point"), LOAD_TIMEBAR);
2046 gui->update_timebar(1);
2047 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2048 cwindow->gui->timebar->update(1);
2049 cwindow->gui->unlock_window();
2052 void MWindow::unset_inoutpoint()
2055 edl->unset_inoutpoint();
2057 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2059 gui->update_timebar(1);
2060 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2061 cwindow->gui->timebar->update(1);
2062 cwindow->gui->unlock_window();
2065 void MWindow::splice(EDL *source, int all)
2068 LocalSession *src = source->local_session;
2071 double source_start = all ? 0 :
2072 src->inpoint_valid() ? src->get_inpoint() :
2073 src->outpoint_valid() ? 0 : src->get_selectionstart();
2074 double source_end = all ? source->tracks->total_length() :
2075 src->outpoint_valid() ? src->get_outpoint() :
2076 src->inpoint_valid() ? source->tracks->total_length() :
2077 src->get_selectionend();
2078 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2080 double start = edl->local_session->get_selectionstart();
2081 //double end = edl->local_session->get_selectionend();
2083 paste(start, start, &file,
2084 edl->session->labels_follow_edits,
2085 edl->session->plugins_follow_edits,
2086 edl->session->autos_follow_edits,
2089 // Position at end of clip
2090 edl->local_session->set_selectionstart(start + source_end - source_start);
2091 edl->local_session->set_selectionend(start + source_end - source_start);
2094 undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2095 update_plugin_guis();
2097 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2098 sync_parameters(CHANGE_EDL);
2101 void MWindow::save_clip(EDL *new_edl, const char *txt)
2103 new_edl->local_session->set_selectionstart(0);
2104 new_edl->local_session->set_selectionend(0);
2105 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2106 session->clip_number++);
2107 char duration[BCTEXTLEN];
2108 Units::totext(duration, new_edl->tracks->total_length(),
2109 new_edl->session->time_format,
2110 new_edl->session->sample_rate,
2111 new_edl->session->frame_rate,
2112 new_edl->session->frames_per_foot);
2114 Track *track = new_edl->tracks->first;
2115 const char *path = edl->path;
2116 for( ; (!path || !*path) && track; track=track->next ) {
2117 if( !track->record ) continue;
2118 Edit *edit = track->edits->first;
2119 if( !edit ) continue;
2120 Indexable *indexable = edit->get_source();
2121 if( !indexable ) continue;
2122 path = indexable->path;
2125 time_t now; time(&now);
2126 struct tm dtm; localtime_r(&now, &dtm);
2127 char *cp = new_edl->local_session->clip_notes;
2128 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2130 n = snprintf(cp, sz, "%s", txt);
2133 n = snprintf(cp, sz,
2134 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2135 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2136 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2138 if( path && *path ) {
2140 char title[BCTEXTLEN];
2141 fs.extract_name(title, path);
2142 n = snprintf(cp, sz, "%s", title);
2146 sprintf(new_edl->local_session->clip_icon,
2147 "clip_%02d%02d%02d-%02d%02d%02d.png",
2148 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2149 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
2150 new_edl->folder_no = AW_CLIP_FOLDER;
2151 edl->update_assets(new_edl);
2153 gui->get_abs_cursor(cur_x, cur_y, 0);
2154 gui->unlock_window();
2156 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2157 new_edl->remove_user();
2159 gui->lock_window("MWindow::save_clip");
2163 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2166 LocalSession *src = edl->local_session;
2168 gui->lock_window("MWindow::to_clip 1");
2169 double start = all ? 0 :
2170 src->inpoint_valid() ? src->get_inpoint() :
2171 src->outpoint_valid() ? 0 : src->get_selectionstart();
2172 double end = all ? edl->tracks->total_length() :
2173 src->outpoint_valid() ? src->get_outpoint() :
2174 src->inpoint_valid() ? edl->tracks->total_length() :
2175 src->get_selectionend();
2176 if( EQUIV(end, start) ) {
2178 end = edl->tracks->total_length();
2181 // Don't copy all since we don't want the clips twice.
2182 edl->copy(copy_flags(), start, end, &file, "", 1);
2184 EDL *new_edl = new EDL(edl);
2185 new_edl->create_objects();
2186 new_edl->load_xml(&file, LOAD_ALL);
2187 save_clip(new_edl, txt);
2188 gui->unlock_window();
2191 int MWindow::toggle_label()
2193 double position1, position2;
2196 position1 = edl->local_session->get_selectionstart(1);
2197 position2 = edl->local_session->get_selectionend(1);
2198 position1 = edl->align_to_frame(position1, 0);
2199 position2 = edl->align_to_frame(position2, 0);
2201 edl->labels->toggle_label(position1, position2);
2204 gui->update_timebar(0);
2205 gui->activate_timeline();
2208 cwindow->gui->lock_window("MWindow::toggle_label 2");
2209 cwindow->gui->timebar->update(1);
2210 cwindow->gui->unlock_window();
2211 awindow->gui->async_update_assets();
2213 undo_after(_("label"), LOAD_TIMEBAR);
2217 void MWindow::trim_selection()
2222 edl->trim_selection(edl->local_session->get_selectionstart(),
2223 edl->local_session->get_selectionend(),
2224 edl->session->labels_follow_edits,
2225 edl->session->plugins_follow_edits,
2226 edl->session->autos_follow_edits);
2229 undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2230 update_plugin_guis();
2231 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2232 cwindow->update(1, 0, 0, 0, 1);
2233 awindow->gui->async_update_assets();
2235 cwindow->refresh_frame(CHANGE_EDL);
2239 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2241 calling_window_gui->unlock_window();
2243 if( undo->undo_load_flags() & LOAD_SESSION )
2246 cwindow->gui->lock_window("MWindow::undo_entry 1");
2247 for( int i=0; i<vwindows.size(); ++i ) {
2248 if( vwindows.get(i)->is_running() ) {
2249 if( calling_window_gui != vwindows.get(i)->gui ) {
2250 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2254 gui->lock_window("MWindow::undo_entry 2");
2260 update_plugin_states();
2261 update_plugin_guis();
2263 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2264 gui->update_proxy_toggle();
2265 gui->unlock_window();
2266 cwindow->update(1, 1, 1, 1, 1);
2267 cwindow->gui->unlock_window();
2269 for( int i=0; i<vwindows.size(); ++i ) {
2270 if( vwindows.get(i)->is_running() ) {
2271 if( calling_window_gui != vwindows.get(i)->gui ) {
2272 vwindows.get(i)->gui->unlock_window();
2277 awindow->gui->async_update_assets();
2279 cwindow->refresh_frame(CHANGE_ALL);
2280 calling_window_gui->lock_window("MWindow::undo_entry 4");
2284 void MWindow::new_folder(const char *new_folder, int is_clips)
2287 if( edl->new_folder(new_folder, is_clips) ) {
2288 MainError::show_error(_("create new folder failed"));
2290 undo_after(_("new folder"), LOAD_ALL);
2291 awindow->gui->async_update_assets();
2294 void MWindow::delete_folder(char *folder)
2297 if( edl->delete_folder(folder) < 0 ) {
2298 MainError::show_error(_("delete folder failed"));
2300 undo_after(_("del folder"), LOAD_ALL);
2301 awindow->gui->async_update_assets();
2304 void MWindow::select_point(double position)
2306 gui->unlock_window();
2307 gui->stop_drawing();
2308 cwindow->stop_playback(0);
2309 gui->lock_window("MWindow::select_point");
2311 edl->local_session->set_selectionstart(position);
2312 edl->local_session->set_selectionend(position);
2315 cwindow->update(1, 0, 0, 0, 1);
2317 update_plugin_guis();
2318 gui->update_patchbay();
2319 gui->hide_cursor(0);
2320 gui->draw_cursor(0);
2321 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2322 gui->zoombar->update();
2323 gui->update_timebar(0);
2324 gui->flash_canvas(0);
2331 void MWindow::map_audio(int pattern)
2334 remap_audio(pattern);
2336 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2338 sync_parameters(CHANGE_PARAMS);
2339 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2342 void MWindow::remap_audio(int pattern)
2344 int current_channel = 0;
2345 int current_track = 0;
2346 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2347 if( current->data_type == TRACK_AUDIO &&
2349 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2350 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2352 for( int i=0; i < MAXCHANNELS; ++i ) {
2353 pan_auto->values[i] = 0.0;
2356 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2357 pan_auto->values[current_channel] = 1.0;
2360 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2361 switch( current_track ) {
2364 pan_auto->values[0] = 1;
2368 pan_auto->values[1] = 1;
2372 pan_auto->values[0] = 0.5;
2373 pan_auto->values[1] = 0.5;
2378 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2379 edl->session->achannel_positions, pan_auto->values,
2380 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2384 if( current_channel >= edl->session->audio_channels )
2385 current_channel = 0;
2391 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2393 edl->rescale_proxy(orig_scale, new_scale);
2396 void MWindow::add_proxy(int use_scaler,
2397 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2399 edl->add_proxy(use_scaler, orig_assets, proxy_assets);
2402 void MWindow::cut_commercials()
2404 #ifdef HAVE_COMMERCIAL
2406 commercials->scan_media();
2409 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2412 update_plugin_guis();
2413 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2414 cwindow->update(1, 0, 0, 0, 1);
2415 cwindow->refresh_frame(CHANGE_EDL);
2419 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2422 Track *old_track = old_edl->tracks->first;
2423 Track *new_track = new_edl->tracks->first;
2424 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2425 if( old_track->data_type != new_track->data_type ) continue;
2426 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2427 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2428 if( !old_speeds || !new_speeds ) continue;
2429 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2430 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2431 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2432 old_speed = (FloatAuto *)old_speed->next;
2433 new_speed = (FloatAuto *)new_speed->next;
2435 Edit *old_edit = old_track->edits->first;
2436 Edit *new_edit = new_track->edits->first;
2437 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2438 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2439 if( old_speed || new_speed ) {
2440 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2441 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2442 edit_start = new_speeds->speed_position(orig_start);
2443 edit_end = new_speeds->speed_position(orig_end);
2446 new_edit->startproject = edit_start;
2447 new_edit->length = edit_end - edit_start;
2453 void MWindow::speed_before()
2456 speed_edl = new EDL;
2457 speed_edl->create_objects();
2459 speed_edl->copy_all(edl);
2462 int MWindow::speed_after(int done)
2467 result = normalize_speed(speed_edl, edl);
2469 speed_edl->remove_user();