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"
46 #include "levelwindow.h"
47 #include "localsession.h"
48 #include "mainclock.h"
49 #include "maincursor.h"
50 #include "mainerror.h"
51 #include "mainindexes.h"
53 #include "mainsession.h"
55 #include "maskautos.h"
57 #include "mwindowgui.h"
61 #include "playbackengine.h"
62 #include "pluginset.h"
63 #include "recordlabel.h"
64 #include "samplescroll.h"
65 #include "trackcanvas.h"
67 #include "trackscroll.h"
69 #include "transition.h"
70 #include "transportque.h"
72 #include "undostackitem.h"
73 #include "vplayback.h"
75 #include "vwindowgui.h"
78 #include "automation.h"
79 #include "maskautos.h"
83 void MWindow::add_audio_track_entry(int above, Track *dst)
85 undo->update_undo_before();
86 add_audio_track(above, dst);
88 undo->update_undo_after(_("add track"), LOAD_ALL);
91 gui->update(1, 1, 0, 0, 1, 0, 0);
92 gui->activate_timeline();
94 // gui->get_scrollbars(0);
95 // gui->canvas->draw();
96 // gui->patchbay->update();
97 // gui->cursor->draw(1);
98 // gui->canvas->flash();
99 // gui->canvas->activate();
100 cwindow->refresh_frame(CHANGE_EDL);
103 void MWindow::add_video_track_entry(Track *dst)
105 undo->update_undo_before();
106 add_video_track(1, dst);
107 undo->update_undo_after(_("add track"), LOAD_ALL);
111 gui->update(1, 1, 0, 0, 1, 0, 0);
112 gui->activate_timeline();
113 // gui->get_scrollbars(0);
114 // gui->canvas->draw();
115 // gui->patchbay->update();
116 // gui->cursor->draw(1);
117 // gui->canvas->flash();
118 // gui->canvas->activate();
119 cwindow->refresh_frame(CHANGE_EDL);
123 void MWindow::add_subttl_track_entry(Track *dst)
125 undo->update_undo_before();
126 add_subttl_track(1, dst);
127 undo->update_undo_after(_("add track"), LOAD_ALL);
131 gui->update(1, 1, 0, 0, 1, 0, 0);
132 gui->activate_timeline();
133 // gui->get_scrollbars(0);
134 // gui->canvas->draw();
135 // gui->patchbay->update();
136 // gui->cursor->draw(1);
137 // gui->canvas->flash();
138 // gui->canvas->activate();
139 cwindow->refresh_frame(CHANGE_EDL);
144 int MWindow::add_audio_track(int above, Track *dst)
146 edl->tracks->add_audio_track(above, dst);
147 edl->tracks->update_y_pixels(theme);
152 int MWindow::add_video_track(int above, Track *dst)
154 edl->tracks->add_video_track(above, dst);
155 edl->tracks->update_y_pixels(theme);
160 int MWindow::add_subttl_track(int above, Track *dst)
162 edl->tracks->add_subttl_track(above, dst);
163 edl->tracks->update_y_pixels(theme);
168 void MWindow::asset_to_all()
170 if( !session->drag_assets->size() ) return;
171 Indexable *indexable = session->drag_assets->get(0);
173 // if( indexable->have_video() )
177 undo->update_undo_before();
180 w = indexable->get_w();
181 h = indexable->get_h();
182 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
183 double old_framerate = edl->session->frame_rate;
184 int old_samplerate = edl->session->sample_rate;
185 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
188 if( indexable->have_video() ) {
189 edl->session->output_w = w;
190 edl->session->output_h = h;
191 edl->session->frame_rate = new_framerate;
193 edl->session->aspect_w,
194 edl->session->aspect_h,
197 for( Track *current=edl->tracks->first; current; current=NEXT ) {
198 if( current->data_type == TRACK_VIDEO /* &&
199 current->record */ ) {
200 current->track_w = w;
201 current->track_h = h;
206 if( ((edl->session->output_w % 4) ||
207 (edl->session->output_h % 4)) &&
208 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
209 MainError::show_error(
210 _("This project's dimensions are not multiples of 4 so\n"
211 "it can't be rendered by OpenGL."));
215 if( defaults->get("AUTOASPECT", 0) ) {
217 edl->session->aspect_w,
218 edl->session->aspect_h,
223 if( indexable->have_audio() ) {
224 edl->session->sample_rate = new_samplerate;
225 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
226 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
231 undo->update_undo_after(_("asset to all"), LOAD_ALL);
233 gui->update(1, 2, 1, 1, 1, 1, 0);
234 sync_parameters(CHANGE_ALL);
238 void MWindow::asset_to_size()
240 if( !session->drag_assets->size() ) return;
241 Indexable *indexable = session->drag_assets->get(0);
243 if( indexable->have_video() ) {
245 undo->update_undo_before();
248 w = indexable->get_w();
249 h = indexable->get_h();
250 edl->session->output_w = w;
251 edl->session->output_h = h;
253 if( ((edl->session->output_w % 4) ||
254 (edl->session->output_h % 4)) &&
255 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
256 MainError::show_error(
257 _("This project's dimensions are not multiples of 4 so\n"
258 "it can't be rendered by OpenGL."));
262 if( defaults->get("AUTOASPECT", 0) ) {
263 create_aspect_ratio(edl->session->aspect_w,
264 edl->session->aspect_h,
271 undo->update_undo_after(_("asset to size"), LOAD_ALL);
273 sync_parameters(CHANGE_ALL);
278 void MWindow::asset_to_rate()
280 if( session->drag_assets->size() &&
281 session->drag_assets->get(0)->have_video() ) {
282 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
283 double old_framerate = edl->session->frame_rate;
284 undo->update_undo_before();
286 edl->session->frame_rate = new_framerate;
287 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
291 undo->update_undo_after(_("asset to rate"), LOAD_ALL);
293 gui->update(1, 2, 1, 1, 1, 1, 0);
294 sync_parameters(CHANGE_ALL);
299 void MWindow::clear_entry()
301 undo->update_undo_before();
306 undo->update_undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
309 update_plugin_guis();
310 gui->update(1, 2, 1, 1, 1, 1, 0);
311 cwindow->update(1, 0, 0, 0, 1);
312 cwindow->refresh_frame(CHANGE_EDL);
315 void MWindow::clear(int clear_handle)
317 double start = edl->local_session->get_selectionstart();
318 double end = edl->local_session->get_selectionend();
319 if( clear_handle || !EQUIV(start, end) ) {
322 edl->session->labels_follow_edits,
323 edl->session->plugins_follow_edits,
324 edl->session->autos_follow_edits);
328 void MWindow::update_gui(int changed_edl)
331 update_plugin_guis();
333 gui->update(1, 2, 1, 1, 1, 1, 0);
334 cwindow->update(1, 0, 0, 0, 1);
335 cwindow->refresh_frame(CHANGE_EDL);
338 gui->draw_overlays(1);
339 sync_parameters(CHANGE_PARAMS);
340 gui->update_patchbay();
341 cwindow->update(1, 0, 0);
345 void MWindow::set_automation_mode(int mode)
347 undo->update_undo_before();
349 edl->tracks->set_automation_mode(
350 edl->local_session->get_selectionstart(),
351 edl->local_session->get_selectionend(),
353 int changed_edl = speed_after(1);
355 char string[BCSTRLEN];
356 sprintf(string,"set %s", FloatAuto::curve_name(mode));
357 undo->update_undo_after(string, LOAD_AUTOMATION);
358 update_gui(changed_edl);
361 void MWindow::clear_automation()
363 undo->update_undo_before();
365 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
366 edl->local_session->get_selectionend());
367 int changed_edl = speed_after(1);
369 undo->update_undo_after(_("clear keyframes"), LOAD_AUTOMATION);
370 update_gui(changed_edl);
373 int MWindow::clear_default_keyframe()
375 undo->update_undo_before();
377 edl->tracks->clear_default_keyframe();
378 int changed_edl = speed_after(1);
380 undo->update_undo_after(_("clear default keyframe"), LOAD_AUTOMATION);
381 update_gui(changed_edl);
385 void MWindow::clear_labels()
387 undo->update_undo_before();
388 clear_labels(edl->local_session->get_selectionstart(),
389 edl->local_session->get_selectionend());
390 undo->update_undo_after(_("clear labels"), LOAD_TIMEBAR);
392 gui->update_timebar(1);
393 cwindow->update(0, 0, 0, 0, 1);
397 int MWindow::clear_labels(double start, double end)
399 edl->labels->clear(start, end, 0);
403 void MWindow::concatenate_tracks()
405 undo->update_undo_before();
406 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
407 edl->session->autos_follow_edits);
409 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
412 gui->update(1, 1, 0, 0, 1, 0, 0);
413 cwindow->refresh_frame(CHANGE_EDL);
419 copy(edl->local_session->get_selectionstart(),
420 edl->local_session->get_selectionend());
423 int MWindow::copy(double start, double end)
425 if( start == end ) return 1;
428 edl->copy(start, end, 0, &file, "", 1);
429 const char *file_string = file.string();
430 long file_length = strlen(file_string);
431 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
432 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
437 int MWindow::copy_automation()
440 double start = edl->local_session->get_selectionstart();
441 double end = edl->local_session->get_selectionend();
442 edl->tracks->copy_automation(start, end, &file, 0, 1);
443 const char *file_string = file.string();
444 long file_length = strlen(file_string);
445 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
446 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
450 int MWindow::copy_default_keyframe()
453 double start = edl->local_session->get_selectionstart();
454 double end = edl->local_session->get_selectionend();
455 edl->tracks->copy_automation(start, end, &file, 1, 0);
456 const char *file_string = file.string();
457 long file_length = strlen(file_string);
458 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
459 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
464 // Uses cropping coordinates in edl session to crop and translate video.
465 // We modify the projector since camera automation depends on the track size.
466 void MWindow::crop_video()
469 undo->update_undo_before();
470 // Clamp EDL crop region
471 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
472 edl->session->crop_x1 ^= edl->session->crop_x2;
473 edl->session->crop_x2 ^= edl->session->crop_x1;
474 edl->session->crop_x1 ^= edl->session->crop_x2;
476 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
477 edl->session->crop_y1 ^= edl->session->crop_y2;
478 edl->session->crop_y2 ^= edl->session->crop_y1;
479 edl->session->crop_y1 ^= edl->session->crop_y2;
482 float old_projector_x = (float)edl->session->output_w / 2;
483 float old_projector_y = (float)edl->session->output_h / 2;
484 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
485 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
486 float projector_offset_x = -(new_projector_x - old_projector_x);
487 float projector_offset_y = -(new_projector_y - old_projector_y);
489 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
491 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
492 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
493 edl->session->crop_x1 = 0;
494 edl->session->crop_y1 = 0;
495 edl->session->crop_x2 = edl->session->output_w;
496 edl->session->crop_y2 = edl->session->output_h;
498 // Recalculate aspect ratio
499 if( defaults->get("AUTOASPECT", 0) ) {
500 create_aspect_ratio(edl->session->aspect_w,
501 edl->session->aspect_h,
502 edl->session->output_w,
503 edl->session->output_h);
506 undo->update_undo_after(_("crop"), LOAD_ALL);
509 cwindow->refresh_frame(CHANGE_ALL);
515 double start = edl->local_session->get_selectionstart();
516 double end = edl->local_session->get_selectionend();
517 if( EQUIV(start,end) )
523 void MWindow::blade(double position)
525 undo->update_undo_before();
526 edl->blade(position);
529 undo->update_undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
531 update_plugin_guis();
532 gui->update(1, 2, 1, 1, 1, 1, 0);
533 cwindow->update(1, 0, 0, 0, 1);
534 awindow->gui->async_update_assets();
535 cwindow->refresh_frame(CHANGE_EDL);
538 void MWindow::cut(double start, double end, double new_position)
540 undo->update_undo_before();
542 edl->clear(start, end,
543 edl->session->labels_follow_edits,
544 edl->session->plugins_follow_edits,
545 edl->session->autos_follow_edits);
549 undo->update_undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
550 if( new_position >= 0 ) {
551 edl->local_session->set_selectionstart(new_position);
552 edl->local_session->set_selectionend(new_position);
555 update_plugin_guis();
556 gui->update(1, 2, 1, 1, 1, 1, 0);
557 cwindow->update(1, 0, 0, 0, 1);
558 awindow->gui->async_update_assets();
559 cwindow->refresh_frame(CHANGE_EDL);
562 void MWindow::cut_left_edit()
564 double start_pos = edl->local_session->get_selectionstart(1);
565 double position = edl->prev_edit(start_pos);
566 if( position < start_pos )
567 cut(position, start_pos, position);
570 void MWindow::cut_right_edit()
572 double end_pos = edl->local_session->get_selectionend(1);
573 double position = edl->next_edit(end_pos);
574 if( end_pos < position )
575 cut(end_pos, position, end_pos);
578 void MWindow::cut_left_label()
580 double start_pos = edl->local_session->get_selectionstart(1);
581 Label *left_label = edl->labels->prev_label(start_pos);
582 if( !left_label ) return;
583 double position = left_label->position;
584 if( position < start_pos )
585 cut(position, start_pos, position);
588 void MWindow::cut_right_label()
590 double end_pos = edl->local_session->get_selectionend(1);
591 Label *right_label = edl->labels->next_label(end_pos);
592 if( !right_label ) return;
593 double position = right_label->position;
594 if( end_pos < position )
595 cut(end_pos, position, end_pos);
598 int MWindow::cut_automation()
600 undo->update_undo_before();
603 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
604 edl->local_session->get_selectionend());
605 int changed_edl = speed_after(1);
607 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
608 update_gui(changed_edl);
612 int MWindow::cut_default_keyframe()
615 undo->update_undo_before();
617 copy_default_keyframe();
618 edl->tracks->clear_default_keyframe();
619 int changed_edl = speed_after(1);
621 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
622 update_gui(changed_edl);
627 void MWindow::delete_track()
629 if( edl->tracks->last )
630 delete_track(edl->tracks->last);
633 void MWindow::delete_tracks()
635 undo->update_undo_before();
636 edl->tracks->delete_tracks();
637 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
641 update_plugin_states();
643 gui->update(1, 1, 1, 0, 1, 0, 0);
644 cwindow->refresh_frame(CHANGE_EDL);
647 void MWindow::delete_track(Track *track)
649 undo->update_undo_before();
650 edl->tracks->delete_track(track);
651 undo->update_undo_after(_("delete track"), LOAD_ALL);
654 update_plugin_states();
656 gui->update(1, 1, 1, 0, 1, 0, 0);
657 cwindow->refresh_frame(CHANGE_EDL);
662 // Insert data from clipboard
663 void MWindow::insert(double position, FileXML *file,
664 int edit_labels, int edit_plugins, int edit_autos,
667 // For clipboard pasting make the new edl use a separate session
668 // from the master EDL. Then it can be resampled to the master rates.
669 // For splice, overwrite, and dragging need same session to get the assets.
670 EDL *edl = new EDL(parent_edl);
671 ArrayList<EDL*> new_edls;
672 uint32_t load_flags = LOAD_ALL;
675 new_edls.append(edl);
676 edl->create_objects();
681 if( parent_edl ) load_flags &= ~LOAD_SESSION;
682 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
683 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
685 edl->load_xml(file, load_flags);
688 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
692 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
693 edit_labels, edit_plugins, edit_autos, 0); // overwrite
694 // if( vwindow->edl )
695 // printf("MWindow::insert 5 %f %f\n",
696 // vwindow->edl->local_session->in_point,
697 // vwindow->edl->local_session->out_point);
698 new_edls.remove_all();
699 edl->Garbage::remove_user();
700 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
703 void MWindow::insert_effects_canvas(double start,
706 Track *dest_track = session->track_highlighted;
707 if( !dest_track ) return;
709 undo->update_undo_before();
711 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
712 PluginServer *plugin = session->drag_pluginservers->values[i];
713 insert_effect(plugin->title, 0, dest_track,
714 i == 0 ? session->pluginset_highlighted : 0,
715 start, length, PLUGIN_STANDALONE);
719 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
721 sync_parameters(CHANGE_EDL);
722 // GUI updated in TrackCanvas, after current_operations are reset
725 void MWindow::insert_effects_cwindow(Track *dest_track)
727 if( !dest_track ) return;
729 undo->update_undo_before();
732 double length = dest_track->get_length();
734 if( edl->local_session->get_selectionend() >
735 edl->local_session->get_selectionstart() ) {
736 start = edl->local_session->get_selectionstart();
737 length = edl->local_session->get_selectionend() -
738 edl->local_session->get_selectionstart();
741 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
742 PluginServer *plugin = session->drag_pluginservers->values[i];
743 insert_effect(plugin->title, 0, dest_track, 0,
744 start, length, PLUGIN_STANDALONE);
748 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
750 sync_parameters(CHANGE_EDL);
751 gui->update(1, 1, 0, 0, 1, 0, 0);
754 void MWindow::insert_effect(char *title,
755 SharedLocation *shared_location,
758 int single_standalone)
760 Track *current = edl->tracks->first;
761 SharedLocation shared_location_local;
762 shared_location_local.copy_from(shared_location);
764 for( ; current; current=NEXT ) {
765 if( current->data_type == data_type &&
767 insert_effect(title, &shared_location_local,
768 current, 0, 0, 0, plugin_type);
771 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
772 plugin_type = PLUGIN_SHAREDPLUGIN;
773 shared_location_local.module = edl->tracks->number_of(current);
774 shared_location_local.plugin = current->plugin_set.total - 1;
783 void MWindow::insert_effect(char *title,
784 SharedLocation *shared_location,
786 PluginSet *plugin_set,
791 KeyFrame *default_keyframe = 0;
792 PluginServer *server = 0;
793 // Get default keyframe
794 if( plugin_type == PLUGIN_STANDALONE ) {
795 default_keyframe = new KeyFrame;
796 server = new PluginServer(*scan_plugindb(title, track->data_type));
798 server->open_plugin(0, preferences, edl, 0);
799 server->save_data(default_keyframe);
801 // Insert plugin object
802 track->insert_effect(title, shared_location,
803 default_keyframe, plugin_set,
804 start, length, plugin_type);
807 if( plugin_type == PLUGIN_STANDALONE ) {
808 server->close_plugin();
810 delete default_keyframe;
814 int MWindow::modify_edithandles()
816 undo->update_undo_before();
817 edl->modify_edithandles(session->drag_start,
818 session->drag_position,
819 session->drag_handle,
820 edl->session->edit_handle_mode[session->drag_button],
821 edl->session->labels_follow_edits,
822 edl->session->plugins_follow_edits,
823 edl->session->autos_follow_edits);
825 finish_modify_handles();
826 //printf("MWindow::modify_handles 1\n");
830 int MWindow::modify_pluginhandles()
832 undo->update_undo_before();
834 edl->modify_pluginhandles(session->drag_start,
835 session->drag_position,
836 session->drag_handle,
837 edl->session->edit_handle_mode[session->drag_button],
838 edl->session->labels_follow_edits,
839 edl->session->autos_follow_edits,
840 session->trim_edits);
842 finish_modify_handles();
848 // Common to edithandles and plugin handles
849 void MWindow::finish_modify_handles()
851 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
853 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
854 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
855 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
856 edl->local_session->set_selectionstart(session->drag_position);
857 edl->local_session->set_selectionend(session->drag_position);
860 if( edit_mode != MOVE_NO_EDITS ) {
861 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
862 edl->local_session->set_selectionstart(session->drag_start);
863 edl->local_session->set_selectionend(session->drag_start);
866 // clamp the selection to 0
867 if( edl->local_session->get_selectionstart(1) < 0 ) {
868 edl->local_session->set_selectionstart(0);
869 edl->local_session->set_selectionend(0);
871 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
875 sync_parameters(CHANGE_EDL);
876 update_plugin_guis();
877 gui->update(1, 2, 1, 1, 1, 1, 0);
878 // label list can be modified
879 awindow->gui->async_update_assets();
880 cwindow->update(1, 0, 0, 0, 1);
883 void MWindow::match_output_size(Track *track)
885 undo->update_undo_before();
886 track->track_w = edl->session->output_w;
887 track->track_h = edl->session->output_h;
889 undo->update_undo_after(_("match output size"), LOAD_ALL);
892 sync_parameters(CHANGE_EDL);
896 void MWindow::move_edits(ArrayList<Edit*> *edits,
901 undo->update_undo_before();
903 edl->tracks->move_edits(edits,
906 edl->session->labels_follow_edits,
907 edl->session->plugins_follow_edits,
908 edl->session->autos_follow_edits,
912 undo->update_undo_after(_("move edit"), LOAD_ALL);
915 cwindow->refresh_frame(CHANGE_EDL);
917 update_plugin_guis();
918 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
922 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
924 undo->update_undo_before();
925 edl->tracks->move_effect(plugin, track, position);
927 undo->update_undo_after(_("paste effect"), LOAD_ALL);
930 cwindow->refresh_frame(CHANGE_EDL);
931 update_plugin_guis();
932 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
936 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
938 undo->update_undo_before();
939 edl->tracks->move_effect(plugin, plugin_set, position);
941 undo->update_undo_after(_("move effect"), LOAD_ALL);
944 cwindow->refresh_frame(CHANGE_EDL);
945 update_plugin_guis();
946 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
950 void MWindow::move_plugins_up(PluginSet *plugin_set)
953 undo->update_undo_before();
954 plugin_set->track->move_plugins_up(plugin_set);
957 undo->update_undo_after(_("move effect up"), LOAD_ALL);
959 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
961 sync_parameters(CHANGE_EDL);
964 void MWindow::move_plugins_down(PluginSet *plugin_set)
966 undo->update_undo_before();
968 plugin_set->track->move_plugins_down(plugin_set);
971 undo->update_undo_after(_("move effect down"), LOAD_ALL);
973 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
975 sync_parameters(CHANGE_EDL);
978 void MWindow::move_track_down(Track *track)
980 undo->update_undo_before();
981 edl->tracks->move_track_down(track);
983 undo->update_undo_after(_("move track down"), LOAD_ALL);
986 gui->update(1, 1, 0, 0, 1, 0, 0);
987 sync_parameters(CHANGE_EDL);
991 void MWindow::move_tracks_down()
993 undo->update_undo_before();
994 edl->tracks->move_tracks_down();
996 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
999 gui->update(1, 1, 0, 0, 1, 0, 0);
1000 sync_parameters(CHANGE_EDL);
1004 void MWindow::move_track_up(Track *track)
1006 undo->update_undo_before();
1007 edl->tracks->move_track_up(track);
1009 undo->update_undo_after(_("move track up"), LOAD_ALL);
1011 gui->update(1, 1, 0, 0, 1, 0, 0);
1012 sync_parameters(CHANGE_EDL);
1016 void MWindow::move_tracks_up()
1018 undo->update_undo_before();
1019 edl->tracks->move_tracks_up();
1021 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1023 gui->update(1, 1, 0, 0, 1, 0, 0);
1024 sync_parameters(CHANGE_EDL);
1028 void MWindow::mute_selection()
1030 double start = edl->local_session->get_selectionstart();
1031 double end = edl->local_session->get_selectionend();
1032 if( start != end ) {
1033 undo->update_undo_before();
1034 edl->clear(start, end, 0,
1035 edl->session->plugins_follow_edits,
1036 edl->session->autos_follow_edits);
1037 edl->local_session->set_selectionend(end);
1038 edl->local_session->set_selectionstart(start);
1039 edl->paste_silence(start, end, 0,
1040 edl->session->plugins_follow_edits,
1041 edl->session->autos_follow_edits);
1044 undo->update_undo_after(_("mute"), LOAD_EDITS);
1047 update_plugin_guis();
1048 gui->update(1, 2, 1, 1, 1, 1, 0);
1049 cwindow->refresh_frame(CHANGE_EDL);
1054 void MWindow::overwrite(EDL *source, int all)
1058 double src_start = all ? 0 :
1059 source->local_session->get_selectionstart();
1060 double overwrite_len = all ? source->tracks->total_length() :
1061 source->local_session->get_selectionend() - src_start;
1062 double dst_start = edl->local_session->get_selectionstart();
1063 double dst_len = edl->local_session->get_selectionend() - dst_start;
1065 undo->update_undo_before();
1066 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1067 // in/out points or selection present and shorter than overwrite range
1068 // shorten the copy range
1069 overwrite_len = dst_len;
1072 source->copy(src_start, src_start + overwrite_len, 0, &file, "", 1);
1074 // HACK around paste_edl get_start/endselection on its own
1075 // so we need to clear only when not using both io points
1076 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1077 if( edl->local_session->get_inpoint() < 0 ||
1078 edl->local_session->get_outpoint() < 0 )
1079 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1081 paste(dst_start, dst_start + overwrite_len,
1084 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1085 edl->local_session->set_selectionend(dst_start + overwrite_len);
1088 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1091 update_plugin_guis();
1092 gui->update(1, 1, 1, 1, 0, 1, 0);
1093 sync_parameters(CHANGE_EDL);
1096 // For splice and overwrite
1097 int MWindow::paste(double start,
1106 // Want to insert with assets shared with the master EDL.
1108 edit_labels, edit_plugins, edit_autos,
1114 // For editing using insertion point
1115 void MWindow::paste()
1117 double start = edl->local_session->get_selectionstart();
1118 //double end = edl->local_session->get_selectionend();
1119 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1122 char *string = new char[len];
1123 undo->update_undo_before();
1124 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1126 file.read_from_string(string);
1129 insert(start, &file,
1130 edl->session->labels_follow_edits,
1131 edl->session->plugins_follow_edits,
1132 edl->session->autos_follow_edits,
1140 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1142 update_plugin_guis();
1143 gui->update(1, 2, 1, 1, 0, 1, 0);
1144 awindow->gui->async_update_assets();
1145 sync_parameters(CHANGE_EDL);
1150 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1153 undo->update_undo_before();
1155 if( session->drag_assets->total ) {
1156 load_assets(session->drag_assets,
1157 position, LOADMODE_PASTE, dest_track, 0,
1158 edl->session->labels_follow_edits,
1159 edl->session->plugins_follow_edits,
1160 edl->session->autos_follow_edits,
1165 if( session->drag_clips->total ) {
1166 paste_edls(session->drag_clips,
1167 LOADMODE_PASTE, dest_track, position,
1168 edl->session->labels_follow_edits,
1169 edl->session->plugins_follow_edits,
1170 edl->session->autos_follow_edits,
1177 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1179 gui->update(1, 2, 1, 0, 0, 1, 0);
1180 sync_parameters(CHANGE_EDL);
1184 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1185 double position, int load_mode, Track *first_track, RecordLabels *labels,
1186 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1188 if( load_mode == LOADMODE_RESOURCESONLY )
1189 load_mode = LOADMODE_ASSETSONLY;
1190 const int debug = 0;
1191 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1192 if( position < 0 ) position = edl->local_session->get_selectionstart();
1194 ArrayList<EDL*> new_edls;
1195 for( int i=0; i<new_assets->total; ++i ) {
1196 Indexable *indexable = new_assets->get(i);
1197 if( indexable->is_asset ) {
1198 remove_asset_from_caches((Asset*)indexable);
1200 EDL *new_edl = new EDL;
1201 new_edl->create_objects();
1202 new_edl->copy_session(edl);
1203 if( !indexable->is_asset ) {
1204 EDL *nested_edl = (EDL*)indexable;
1205 new_edl->create_nested(nested_edl);
1206 new_edl->set_path(indexable->path);
1209 Asset *asset = (Asset*)indexable;
1210 asset_to_edl(new_edl, asset);
1212 new_edls.append(new_edl);
1215 for( RecordLabel *label=labels->first; label; label=label->next ) {
1216 new_edl->labels->toggle_label(label->position, label->position);
1220 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1222 paste_edls(&new_edls, load_mode, first_track, position,
1223 edit_labels, edit_plugins, edit_autos, overwrite);
1224 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1227 for( int i=0; i<new_edls.size(); ++i )
1228 new_edls.get(i)->Garbage::remove_user();
1230 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1233 int MWindow::paste_automation()
1235 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1238 undo->update_undo_before();
1240 char *string = new char[len];
1241 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1243 file.read_from_string(string);
1245 double start = edl->local_session->get_selectionstart();
1246 double end = edl->local_session->get_selectionend();
1247 edl->tracks->clear_automation(start, end);
1248 edl->tracks->paste_automation(start, &file, 0, 1,
1249 edl->session->typeless_keyframes);
1250 int changed_edl = speed_after(1);
1252 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1254 update_gui(changed_edl);
1260 int MWindow::paste_default_keyframe()
1262 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1265 undo->update_undo_before();
1267 char *string = new char[len];
1268 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1270 file.read_from_string(string);
1271 double start = edl->local_session->get_selectionstart();
1272 edl->tracks->paste_automation(start, &file, 1, 0,
1273 edl->session->typeless_keyframes);
1274 // edl->tracks->paste_default_keyframe(&file);
1275 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1276 int changed_edl = speed_after(1);
1279 update_gui(changed_edl);
1286 // Insert edls with project deletion and index file generation.
1287 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1288 Track *first_track, double current_position,
1289 int edit_labels, int edit_plugins, int edit_autos,
1293 ArrayList<Track*> destination_tracks;
1294 int need_new_tracks = 0;
1297 if( !new_edls->total ) return 0;
1300 // double original_length = edl->tracks->total_length();
1301 // double original_preview_end = edl->local_session->preview_end;
1304 // Delete current project
1305 if( load_mode == LOADMODE_REPLACE ||
1306 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1308 edl->save_defaults(defaults);
1310 edl->Garbage::remove_user();
1312 edl->create_objects();
1313 edl->copy_session(new_edls->values[0]);
1314 edl->copy_mixers(new_edls->values[0]);
1315 gui->mainmenu->update_toggles(0);
1316 gui->unlock_window();
1317 gwindow->gui->update_toggles(1);
1318 gui->lock_window("MWindow::paste_edls");
1320 // Insert labels for certain modes constitutively
1324 // Force reset of preview
1325 // original_length = 0;
1326 // original_preview_end = -1;
1332 // Create new tracks in master EDL
1333 if( load_mode == LOADMODE_REPLACE ||
1334 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1335 load_mode == LOADMODE_NEW_TRACKS ) {
1337 need_new_tracks = 1;
1338 for( int i=0; i<new_edls->total; ++i ) {
1339 EDL *new_edl = new_edls->values[i];
1340 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1341 switch( current->data_type ) {
1343 edl->tracks->add_video_track(0, 0);
1344 if( current->draw ) edl->tracks->last->draw = 1;
1347 edl->tracks->add_audio_track(0, 0);
1349 case TRACK_SUBTITLE:
1350 edl->tracks->add_subttl_track(0, 0);
1355 destination_tracks.append(edl->tracks->last);
1358 // Base track count on first EDL only for concatenation
1359 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1361 edl->session->highlighted_track = edl->tracks->total() - 1;
1364 // Recycle existing tracks of master EDL
1365 if( load_mode == LOADMODE_CONCATENATE ||
1366 load_mode == LOADMODE_PASTE ||
1367 load_mode == LOADMODE_NESTED ) {
1370 // The point of this is to shift forward labels after the selection so they can
1371 // then be shifted back to their original locations without recursively
1372 // shifting back every paste.
1373 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1374 edl->session->labels_follow_edits )
1375 edl->labels->clear(edl->local_session->get_selectionstart(),
1376 edl->local_session->get_selectionend(), 1);
1378 Track *current = first_track ? first_track : edl->tracks->first;
1379 for( ; current; current=NEXT ) {
1380 if( current->record ) {
1381 destination_tracks.append(current);
1388 int destination_track = 0;
1389 double *paste_position = new double[destination_tracks.total];
1391 // Iterate through the edls
1392 for( int i=0; i<new_edls->total; ++i ) {
1394 EDL *new_edl = new_edls->values[i];
1395 double edl_length = new_edl->local_session->clipboard_length ?
1396 new_edl->local_session->clipboard_length :
1397 new_edl->tracks->total_length();
1398 // printf("MWindow::paste_edls 2 %f %f\n",
1399 // new_edl->local_session->clipboard_length,
1400 // new_edl->tracks->total_length());
1404 // Convert EDL to master rates
1405 new_edl->resample(new_edl->session->sample_rate,
1406 edl->session->sample_rate,
1408 new_edl->resample(new_edl->session->frame_rate,
1409 edl->session->frame_rate,
1412 // Add assets and prepare index files
1413 for( Asset *new_asset=new_edl->assets->first;
1414 new_asset; new_asset=new_asset->next ) {
1415 mainindexes->add_next_asset(0, new_asset);
1417 // Capture index file status from mainindex test
1418 edl->update_assets(new_edl);
1420 // Get starting point of insertion. Need this to paste labels.
1421 switch( load_mode ) {
1422 case LOADMODE_REPLACE:
1423 case LOADMODE_NEW_TRACKS:
1424 current_position = 0;
1427 case LOADMODE_CONCATENATE:
1428 case LOADMODE_REPLACE_CONCATENATE:
1429 destination_track = 0;
1430 if( destination_tracks.total )
1431 current_position = destination_tracks.values[0]->get_length();
1433 current_position = 0;
1436 case LOADMODE_PASTE:
1437 case LOADMODE_NESTED:
1438 destination_track = 0;
1440 for( int j=0; j<destination_tracks.total; ++j ) {
1441 paste_position[j] = (current_position >= 0) ?
1443 edl->local_session->get_selectionstart();
1448 case LOADMODE_RESOURCESONLY:
1449 edl->add_clip(new_edl);
1454 if( load_mode != LOADMODE_RESOURCESONLY &&
1455 load_mode != LOADMODE_ASSETSONLY ) {
1457 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1458 if( load_mode == LOADMODE_PASTE ||
1459 load_mode == LOADMODE_NESTED )
1460 edl->labels->insert_labels(new_edl->labels,
1461 destination_tracks.total ? paste_position[0] : 0.0,
1465 edl->labels->insert_labels(new_edl->labels,
1471 for( Track *new_track=new_edl->tracks->first;
1472 new_track; new_track=new_track->next ) {
1473 // Get destination track of same type as new_track
1475 k < destination_tracks.total &&
1476 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1477 ++k, ++destination_track ) {
1478 if( destination_track >= destination_tracks.total - 1 )
1479 destination_track = 0;
1482 // Insert data into destination track
1483 if( destination_track < destination_tracks.total &&
1484 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1485 Track *track = destination_tracks.values[destination_track];
1487 // Replace default keyframes if first EDL and new tracks were created.
1488 // This means data copied from one track and pasted to another won't retain
1489 // the camera position unless it's a keyframe. If it did, previous data in the
1490 // track might get unknowingly corrupted. Ideally we would detect when differing
1491 // default keyframes existed and create discrete keyframes for both.
1492 int replace_default = (i == 0) && need_new_tracks;
1494 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1495 // Insert new track at current position
1496 switch( load_mode ) {
1497 case LOADMODE_REPLACE_CONCATENATE:
1498 case LOADMODE_CONCATENATE:
1499 current_position = track->get_length();
1502 case LOADMODE_PASTE:
1503 case LOADMODE_NESTED:
1504 current_position = paste_position[destination_track];
1505 paste_position[destination_track] += new_track->get_length();
1509 track->clear(current_position,
1510 current_position + new_track->get_length(),
1512 edit_labels, edit_plugins, edit_autos,
1517 track->insert_track(new_track, current_position, replace_default,
1518 edit_plugins, edit_autos, edl_length);
1522 // Get next destination track
1523 destination_track++;
1524 if( destination_track >= destination_tracks.total )
1525 destination_track = 0;
1529 if( load_mode == LOADMODE_PASTE ||
1530 load_mode == LOADMODE_NESTED )
1531 current_position += edl_length;
1535 // Move loading of clips and vwindow to the end - this fixes some
1536 // strange issue, for index not being shown
1537 // Assume any paste operation from the same EDL won't contain any clips.
1538 // If it did it would duplicate every clip here.
1539 for( int i=0; i<new_edls->total; ++i ) {
1540 EDL *new_edl = new_edls->get(i);
1542 for( int j=0; j<new_edl->clips.size(); ++j ) {
1543 edl->add_clip(new_edl->clips[j]);
1545 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1546 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1549 if( new_edl->total_vwindow_edls() ) {
1550 // if( edl->vwindow_edl )
1551 // edl->vwindow_edl->Garbage::remove_user();
1552 // edl->vwindow_edl = new EDL(edl);
1553 // edl->vwindow_edl->create_objects();
1554 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1556 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1557 EDL *vwindow_edl = new EDL(edl);
1558 vwindow_edl->create_objects();
1559 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1560 edl->append_vwindow_edl(vwindow_edl, 0);
1565 if( paste_position ) delete [] paste_position;
1567 // This is already done in load_filenames and everything else that uses paste_edls
1568 // update_project(load_mode);
1570 // Fix preview range
1571 // if( EQUIV(original_length, original_preview_end) )
1573 // edl->local_session->preview_end = edl->tracks->total_length();
1576 // Start examining next batch of index files
1577 mainindexes->start_build();
1579 // Don't save a backup after loading since the loaded file is on disk already.
1584 void MWindow::paste_silence()
1586 double start = edl->local_session->get_selectionstart();
1587 double end = edl->local_session->get_selectionend();
1588 if( EQUIV(start, end) ) {
1589 if( edl->session->frame_rate > 0 )
1590 end += 1./edl->session->frame_rate;
1592 undo->update_undo_before();
1593 edl->paste_silence(start, end,
1594 edl->session->labels_follow_edits,
1595 edl->session->plugins_follow_edits,
1596 edl->session->autos_follow_edits);
1599 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1601 update_plugin_guis();
1603 gui->update(1, 2, 1, 1, 1, 1, 0);
1604 cwindow->update(1, 0, 0, 0, 1);
1605 cwindow->refresh_frame(CHANGE_EDL);
1608 void MWindow::detach_transition(Transition *transition)
1610 undo->update_undo_before();
1611 hide_plugin(transition, 1);
1612 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1613 transition->edit->detach_transition();
1615 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1617 if( is_video ) restart_brender();
1618 gui->update(0, 1, 0, 0, 0, 0, 0);
1619 sync_parameters(CHANGE_EDL);
1622 void MWindow::detach_transitions()
1624 gui->lock_window("MWindow::detach_transitions 1");
1626 undo->update_undo_before();
1627 double start = edl->local_session->get_selectionstart();
1628 double end = edl->local_session->get_selectionend();
1629 edl->tracks->clear_transitions(start, end);
1632 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1634 sync_parameters(CHANGE_EDL);
1635 gui->update(0, 1, 0, 0, 0, 0, 0);
1636 gui->unlock_window();
1639 void MWindow::paste_transition()
1641 // Only the first transition gets dropped.
1642 PluginServer *server = session->drag_pluginservers->values[0];
1644 undo->update_undo_before();
1646 strcpy(edl->session->default_atransition, server->title);
1648 strcpy(edl->session->default_vtransition, server->title);
1650 edl->tracks->paste_transition(server, session->edit_highlighted);
1652 undo->update_undo_after(_("transition"), LOAD_EDITS);
1654 if( server->video ) restart_brender();
1655 sync_parameters(CHANGE_ALL);
1658 void MWindow::paste_transitions(int track_type, char *title)
1660 gui->lock_window("MWindow::detach_transitions 1");
1662 undo->update_undo_before();
1663 double start = edl->local_session->get_selectionstart();
1664 double end = edl->local_session->get_selectionend();
1665 edl->tracks->paste_transitions(start, end, track_type, title);
1668 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1670 sync_parameters(CHANGE_EDL);
1671 gui->update(0, 1, 0, 0, 0, 0, 0);
1672 gui->unlock_window();
1675 void MWindow::paste_transition_cwindow(Track *dest_track)
1677 PluginServer *server = session->drag_pluginservers->values[0];
1678 undo->update_undo_before();
1679 edl->tracks->paste_video_transition(server, 1);
1681 undo->update_undo_after(_("transition"), LOAD_EDITS);
1683 gui->update(0, 1, 0, 0, 0, 0, 0);
1684 sync_parameters(CHANGE_ALL);
1687 void MWindow::paste_audio_transition()
1689 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1692 char string[BCTEXTLEN];
1693 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1694 gui->show_message(string);
1698 undo->update_undo_before();
1699 edl->tracks->paste_audio_transition(server);
1701 undo->update_undo_after(_("transition"), LOAD_EDITS);
1703 sync_parameters(CHANGE_EDL);
1704 gui->update(0, 1, 0, 0, 0, 0, 0);
1707 void MWindow::paste_video_transition()
1709 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1712 char string[BCTEXTLEN];
1713 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1714 gui->show_message(string);
1718 undo->update_undo_before();
1720 edl->tracks->paste_video_transition(server);
1722 undo->update_undo_after(_("transition"), LOAD_EDITS);
1724 sync_parameters(CHANGE_EDL);
1726 gui->update(0, 1, 0, 0, 0, 0, 0);
1729 void MWindow::shuffle_edits()
1731 gui->lock_window("MWindow::shuffle_edits 1");
1733 undo->update_undo_before();
1734 double start = edl->local_session->get_selectionstart();
1735 double end = edl->local_session->get_selectionend();
1737 edl->tracks->shuffle_edits(start, end);
1740 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1742 sync_parameters(CHANGE_EDL);
1744 gui->update(0, 1, 1, 0, 0, 0, 0);
1745 gui->unlock_window();
1748 void MWindow::reverse_edits()
1750 gui->lock_window("MWindow::reverse_edits 1");
1752 undo->update_undo_before();
1753 double start = edl->local_session->get_selectionstart();
1754 double end = edl->local_session->get_selectionend();
1756 edl->tracks->reverse_edits(start, end);
1759 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1761 sync_parameters(CHANGE_EDL);
1763 gui->update(0, 1, 1, 0, 0, 0, 0);
1764 gui->unlock_window();
1767 void MWindow::align_edits()
1769 gui->lock_window("MWindow::align_edits 1");
1771 undo->update_undo_before();
1772 double start = edl->local_session->get_selectionstart();
1773 double end = edl->local_session->get_selectionend();
1775 edl->tracks->align_edits(start, end);
1778 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1780 sync_parameters(CHANGE_EDL);
1782 gui->update(0, 1, 1, 0, 0, 0, 0);
1783 gui->unlock_window();
1786 void MWindow::set_edit_length(double length)
1788 gui->lock_window("MWindow::detach_transitions 1");
1790 undo->update_undo_before();
1791 double start = edl->local_session->get_selectionstart();
1792 double end = edl->local_session->get_selectionend();
1794 edl->tracks->set_edit_length(start, end, length);
1797 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1799 sync_parameters(CHANGE_EDL);
1801 gui->update(0, 1, 1, 0, 0, 0, 0);
1802 gui->unlock_window();
1806 void MWindow::set_transition_length(Transition *transition, double length)
1808 gui->lock_window("MWindow::detach_transitions 1");
1810 undo->update_undo_before();
1811 //double start = edl->local_session->get_selectionstart();
1812 //double end = edl->local_session->get_selectionend();
1814 edl->tracks->set_transition_length(transition, length);
1817 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1819 edl->session->default_transition_length = length;
1820 sync_parameters(CHANGE_PARAMS);
1821 gui->update(0, 1, 0, 0, 0, 0, 0);
1822 gui->unlock_window();
1825 void MWindow::set_transition_length(double length)
1827 gui->lock_window("MWindow::detach_transitions 1");
1829 undo->update_undo_before();
1830 double start = edl->local_session->get_selectionstart();
1831 double end = edl->local_session->get_selectionend();
1833 edl->tracks->set_transition_length(start, end, length);
1836 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1838 edl->session->default_transition_length = length;
1839 sync_parameters(CHANGE_PARAMS);
1841 gui->update(0, 1, 0, 0, 0, 0, 0);
1842 gui->unlock_window();
1846 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1848 calling_window_gui->unlock_window();
1850 if( undo->redo_load_flags() & LOAD_SESSION )
1853 cwindow->gui->lock_window("MWindow::redo_entry 1");
1854 for( int i=0; i<vwindows.size(); ++i ) {
1855 if( vwindows.get(i)->is_running() ) {
1856 if( calling_window_gui != vwindows.get(i)->gui ) {
1857 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1861 gui->lock_window("MWindow::redo_entry 3");
1867 update_plugin_states();
1868 update_plugin_guis();
1870 gui->update(1, 2, 1, 1, 1, 1, 1);
1871 gui->unlock_window();
1872 cwindow->update(1, 1, 1, 1, 1);
1873 cwindow->gui->unlock_window();
1875 for( int i=0; i < vwindows.size(); ++i ) {
1876 if( vwindows.get(i)->is_running() ) {
1877 if( calling_window_gui != vwindows.get(i)->gui ) {
1878 vwindows.get(i)->gui->unlock_window();
1883 if( calling_window_gui != gui )
1884 gui->unlock_window();
1886 awindow->gui->async_update_assets();
1888 cwindow->refresh_frame(CHANGE_ALL);
1889 calling_window_gui->lock_window("MWindow::redo_entry 4");
1893 void MWindow::resize_track(Track *track, int w, int h)
1895 undo->update_undo_before();
1896 // We have to move all maskpoints so they do not move in relation to image areas
1897 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1898 (w - track->track_w) / 2,
1899 (h - track->track_h) / 2);
1902 undo->update_undo_after(_("resize track"), LOAD_ALL);
1906 sync_parameters(CHANGE_EDL);
1910 void MWindow::set_inpoint(int is_mwindow)
1912 undo->update_undo_before();
1913 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1915 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1918 gui->lock_window("MWindow::set_inpoint 1");
1920 gui->update_timebar(1);
1922 gui->unlock_window();
1926 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1928 cwindow->gui->timebar->update(1);
1930 cwindow->gui->unlock_window();
1934 void MWindow::set_outpoint(int is_mwindow)
1936 undo->update_undo_before();
1937 edl->set_outpoint(edl->local_session->get_selectionend(1));
1939 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1942 gui->lock_window("MWindow::set_outpoint 1");
1944 gui->update_timebar(1);
1946 gui->unlock_window();
1950 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1952 cwindow->gui->timebar->update(1);
1954 cwindow->gui->unlock_window();
1958 void MWindow::unset_inoutpoint(int is_mwindow)
1960 undo->update_undo_before();
1961 edl->unset_inoutpoint();
1963 undo->update_undo_after(_("clear in/out"), LOAD_TIMEBAR);
1966 gui->lock_window("MWindow::unset_inoutpoint 1");
1968 gui->update_timebar(1);
1970 gui->unlock_window();
1974 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
1976 cwindow->gui->timebar->update(1);
1978 cwindow->gui->unlock_window();
1982 void MWindow::splice(EDL *source, int all)
1986 undo->update_undo_before();
1987 double source_start = all ? 0 :
1988 source->local_session->get_selectionstart();
1989 double source_end = all ? source->tracks->total_length() :
1990 source->local_session->get_selectionend();
1991 source->copy(source_start, source_end, 1, &file, "", 1);
1993 double start = edl->local_session->get_selectionstart();
1994 //double end = edl->local_session->get_selectionend();
1996 paste(start, start, &file,
1997 edl->session->labels_follow_edits,
1998 edl->session->plugins_follow_edits,
1999 edl->session->autos_follow_edits);
2001 // Position at end of clip
2002 edl->local_session->set_selectionstart(start + source_end - source_start);
2003 edl->local_session->set_selectionend(start + source_end - source_start);
2006 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2007 update_plugin_guis();
2009 gui->update(1, 1, 1, 1, 0, 1, 0);
2010 sync_parameters(CHANGE_EDL);
2013 void MWindow::save_clip(EDL *new_edl, const char *txt)
2015 new_edl->local_session->set_selectionstart(0);
2016 new_edl->local_session->set_selectionend(0);
2017 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2018 session->clip_number++);
2019 char duration[BCTEXTLEN];
2020 Units::totext(duration, new_edl->tracks->total_length(),
2021 new_edl->session->time_format,
2022 new_edl->session->sample_rate,
2023 new_edl->session->frame_rate,
2024 new_edl->session->frames_per_foot);
2026 Track *track = new_edl->tracks->first;
2027 const char *path = edl->path;
2028 for( ; (!path || !*path) && track; track=track->next ) {
2029 if( !track->record ) continue;
2030 Edit *edit = track->edits->first;
2031 if( !edit ) continue;
2032 Indexable *indexable = edit->get_source();
2033 if( !indexable ) continue;
2034 path = indexable->path;
2037 time_t now; time(&now);
2038 struct tm dtm; localtime_r(&now, &dtm);
2039 char *cp = new_edl->local_session->clip_notes;
2040 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2042 n = snprintf(cp, sz, "%s", txt);
2045 n = snprintf(cp, sz,
2046 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2047 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2048 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2050 if( path && *path ) {
2052 char title[BCTEXTLEN];
2053 fs.extract_name(title, path);
2054 n = snprintf(cp, sz, "%s", title);
2058 sprintf(new_edl->local_session->clip_icon,
2059 "clip_%02d%02d%02d-%02d%02d%02d.png",
2060 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2061 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
2062 edl->update_assets(new_edl);
2064 gui->get_abs_cursor(cur_x, cur_y, 0);
2065 gui->unlock_window();
2067 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2068 new_edl->remove_user();
2070 gui->lock_window("MWindow::save_clip");
2074 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2079 gui->lock_window("MWindow::to_clip 1");
2081 edl->local_session->get_selectionstart();
2082 end = all ? edl->tracks->total_length() :
2083 edl->local_session->get_selectionend();
2085 if( EQUIV(end, start) ) {
2087 end = edl->tracks->total_length();
2090 // Don't copy all since we don't want the clips twice.
2091 edl->copy(start, end, 0, &file, "", 1);
2093 EDL *new_edl = new EDL(edl);
2094 new_edl->create_objects();
2095 new_edl->load_xml(&file, LOAD_ALL);
2096 save_clip(new_edl, txt);
2097 gui->unlock_window();
2100 int MWindow::toggle_label(int is_mwindow)
2102 double position1, position2;
2103 undo->update_undo_before();
2105 if( cwindow->playback_engine->is_playing_back ) {
2106 position1 = position2 =
2107 cwindow->playback_engine->get_tracking_position();
2110 position1 = edl->local_session->get_selectionstart(1);
2111 position2 = edl->local_session->get_selectionend(1);
2114 position1 = edl->align_to_frame(position1, 0);
2115 position2 = edl->align_to_frame(position2, 0);
2117 //printf("MWindow::toggle_label 1\n");
2119 edl->labels->toggle_label(position1, position2);
2123 gui->lock_window("MWindow::toggle_label 1");
2125 gui->update_timebar(0);
2126 gui->activate_timeline();
2129 gui->unlock_window();
2133 cwindow->gui->lock_window("MWindow::toggle_label 2");
2135 cwindow->gui->timebar->update(1);
2137 cwindow->gui->unlock_window();
2140 awindow->gui->async_update_assets();
2142 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2146 void MWindow::trim_selection()
2148 undo->update_undo_before();
2151 edl->trim_selection(edl->local_session->get_selectionstart(),
2152 edl->local_session->get_selectionend(),
2153 edl->session->labels_follow_edits,
2154 edl->session->plugins_follow_edits,
2155 edl->session->autos_follow_edits);
2158 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2159 update_plugin_guis();
2160 gui->update(1, 2, 1, 1, 1, 1, 0);
2161 cwindow->update(1, 0, 0, 0, 1);
2162 awindow->gui->async_update_assets();
2164 cwindow->refresh_frame(CHANGE_EDL);
2168 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2170 calling_window_gui->unlock_window();
2172 if( undo->undo_load_flags() & LOAD_SESSION )
2175 cwindow->gui->lock_window("MWindow::undo_entry 1");
2176 for( int i=0; i<vwindows.size(); ++i ) {
2177 if( vwindows.get(i)->is_running() ) {
2178 if( calling_window_gui != vwindows.get(i)->gui ) {
2179 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2183 gui->lock_window("MWindow::undo_entry 2");
2189 update_plugin_states();
2190 update_plugin_guis();
2192 gui->update(1, 2, 1, 1, 1, 1, 1);
2193 gui->unlock_window();
2194 cwindow->update(1, 1, 1, 1, 1);
2195 cwindow->gui->unlock_window();
2197 for( int i=0; i<vwindows.size(); ++i ) {
2198 if( vwindows.get(i)->is_running() ) {
2199 if( calling_window_gui != vwindows.get(i)->gui ) {
2200 vwindows.get(i)->gui->unlock_window();
2205 if( calling_window_gui != gui )
2206 gui->unlock_window();
2208 awindow->gui->async_update_assets();
2210 cwindow->refresh_frame(CHANGE_ALL);
2211 calling_window_gui->lock_window("MWindow::undo_entry 4");
2215 void MWindow::new_folder(const char *new_folder)
2217 undo->update_undo_before();
2218 edl->new_folder(new_folder);
2219 undo->update_undo_after(_("new folder"), LOAD_ALL);
2220 awindow->gui->async_update_assets();
2223 void MWindow::delete_folder(char *folder)
2225 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2228 void MWindow::select_point(double position)
2230 edl->local_session->set_selectionstart(position);
2231 edl->local_session->set_selectionend(position);
2234 cwindow->update(1, 0, 0, 0, 1);
2236 update_plugin_guis();
2237 gui->update_patchbay();
2238 gui->hide_cursor(0);
2239 gui->draw_cursor(0);
2240 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2241 gui->zoombar->update();
2242 gui->update_timebar(0);
2243 gui->flash_canvas(0);
2250 void MWindow::map_audio(int pattern)
2252 undo->update_undo_before();
2253 remap_audio(pattern);
2254 undo->update_undo_after(
2255 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2257 sync_parameters(CHANGE_PARAMS);
2258 gui->update(0, 1, 0, 0, 1, 0, 0);
2261 void MWindow::remap_audio(int pattern)
2263 int current_channel = 0;
2264 int current_track = 0;
2265 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2266 if( current->data_type == TRACK_AUDIO &&
2268 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2269 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2271 for( int i=0; i < MAXCHANNELS; ++i ) {
2272 pan_auto->values[i] = 0.0;
2275 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2276 pan_auto->values[current_channel] = 1.0;
2279 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2280 switch( current_track ) {
2283 pan_auto->values[0] = 1;
2287 pan_auto->values[1] = 1;
2291 pan_auto->values[0] = 0.5;
2292 pan_auto->values[1] = 0.5;
2297 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2298 edl->session->achannel_positions, pan_auto->values,
2299 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2303 if( current_channel >= edl->session->audio_channels )
2304 current_channel = 0;
2309 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2310 ArrayList<Indexable*> *orig_assets,
2311 ArrayList<Indexable*> *proxy_assets)
2313 int orig_use_scaler = edl->session->proxy_use_scaler;
2314 int orig_scale = edl->session->proxy_scale;
2315 // rescale to full size asset in read_frame
2316 edl->session->proxy_use_scaler = use_scaler;
2317 edl->session->proxy_scale = new_scale;
2318 edl->session->proxy_auto_scale = auto_scale;
2321 for( int i=0; i<proxy_assets->size(); ++i ) {
2322 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2323 proxy_asset->width = orig_assets->get(i)->get_w();
2324 proxy_asset->height = orig_assets->get(i)->get_h();
2329 if( !orig_use_scaler && new_scale != orig_scale ) {
2331 float orig_w = (float)edl->session->output_w * orig_scale;
2332 float orig_h = (float)edl->session->output_h * orig_scale;
2333 edl->session->output_w = Units::round(orig_w / new_scale);
2334 edl->session->output_h = Units::round(orig_h / new_scale);
2337 for( Track *track=edl->tracks->first; track; track=track->next ) {
2338 if( track->data_type != TRACK_VIDEO ) continue;
2339 orig_w = (float)track->track_w * orig_scale;
2340 orig_h = (float)track->track_h * orig_scale;
2341 track->track_w = Units::round(orig_w / new_scale);
2342 track->track_h = Units::round(orig_h / new_scale);
2343 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2344 set_proxy(orig_scale, new_scale);
2345 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2346 set_proxy(orig_scale, new_scale);
2347 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2348 set_proxy(orig_scale, new_scale);
2349 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2350 set_proxy(orig_scale, new_scale);
2351 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2352 set_proxy(orig_scale, new_scale);
2356 // change original assets to proxy assets
2357 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2358 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2359 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2360 proxy_asset->awindow_folder = awindow_folder;
2361 // replace track contents
2362 for( Track *track=edl->tracks->first; track; track=track->next ) {
2363 if( track->data_type != TRACK_VIDEO ) continue;
2364 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2365 if( !edit->asset ) continue;
2366 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2367 edit->asset = proxy_asset;
2371 for( int j=0,m=edl->clips.size(); j<m; ++j ) {
2372 EDL *clip = edl->clips[j];
2373 for( Track *track=clip->tracks->first; track; track=track->next ) {
2374 if( track->data_type != TRACK_VIDEO ) continue;
2375 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2376 if( !edit->asset ) continue;
2377 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2378 edit->asset = proxy_asset;
2386 void MWindow::add_proxy(int use_scaler,
2387 ArrayList<Indexable*> *orig_assets,
2388 ArrayList<Indexable*> *proxy_assets)
2391 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2392 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2393 proxy_asset->width = orig_assets->get(i)->get_w();
2394 proxy_asset->height = orig_assets->get(i)->get_h();
2398 // change original assets to proxy assets
2399 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2400 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2401 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2402 // replace track contents
2403 for( Track *track=edl->tracks->first; track; track=track->next ) {
2404 if( track->data_type != TRACK_VIDEO ) continue;
2405 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2406 if( !edit->asset ) continue;
2407 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2408 edit->asset = proxy_asset;
2415 void MWindow::cut_commercials()
2417 undo->update_undo_before();
2418 commercials->scan_media();
2421 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2424 update_plugin_guis();
2425 gui->update(1, 2, 1, 1, 1, 1, 0);
2426 cwindow->update(1, 0, 0, 0, 1);
2427 cwindow->refresh_frame(CHANGE_EDL);
2430 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2433 Track *old_track = old_edl->tracks->first;
2434 Track *new_track = new_edl->tracks->first;
2435 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2436 if( old_track->data_type != new_track->data_type ) continue;
2437 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2438 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2439 if( !old_speeds || !new_speeds ) continue;
2440 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2441 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2442 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2443 old_speed = (FloatAuto *)old_speed->next;
2444 new_speed = (FloatAuto *)new_speed->next;
2446 Edit *old_edit = old_track->edits->first;
2447 Edit *new_edit = new_track->edits->first;
2448 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2449 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2450 if( old_speed || new_speed ) {
2451 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2452 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2453 edit_start = new_speeds->speed_position(orig_start);
2454 edit_end = new_speeds->speed_position(orig_end);
2457 new_edit->startproject = edit_start;
2458 new_edit->length = edit_end - edit_start;
2464 void MWindow::speed_before()
2467 speed_edl = new EDL;
2468 speed_edl->create_objects();
2470 speed_edl->copy_all(edl);
2473 int MWindow::speed_after(int done)
2476 if( speed_edl && done >= 0 )
2477 result = normalize_speed(speed_edl, edl);
2479 speed_edl->remove_user();