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"
77 #include "automation.h"
78 #include "maskautos.h"
82 void MWindow::add_audio_track_entry(int above, Track *dst)
84 undo->update_undo_before();
85 add_audio_track(above, dst);
87 undo->update_undo_after(_("add track"), LOAD_ALL);
90 gui->update(1, 1, 0, 0, 1, 0, 0);
91 gui->activate_timeline();
93 // gui->get_scrollbars(0);
94 // gui->canvas->draw();
95 // gui->patchbay->update();
96 // gui->cursor->draw(1);
97 // gui->canvas->flash();
98 // gui->canvas->activate();
99 cwindow->refresh_frame(CHANGE_EDL);
102 void MWindow::add_video_track_entry(Track *dst)
104 undo->update_undo_before();
105 add_video_track(1, dst);
106 undo->update_undo_after(_("add track"), LOAD_ALL);
110 gui->update(1, 1, 0, 0, 1, 0, 0);
111 gui->activate_timeline();
112 // gui->get_scrollbars(0);
113 // gui->canvas->draw();
114 // gui->patchbay->update();
115 // gui->cursor->draw(1);
116 // gui->canvas->flash();
117 // gui->canvas->activate();
118 cwindow->refresh_frame(CHANGE_EDL);
122 void MWindow::add_subttl_track_entry(Track *dst)
124 undo->update_undo_before();
125 add_subttl_track(1, dst);
126 undo->update_undo_after(_("add track"), LOAD_ALL);
130 gui->update(1, 1, 0, 0, 1, 0, 0);
131 gui->activate_timeline();
132 // gui->get_scrollbars(0);
133 // gui->canvas->draw();
134 // gui->patchbay->update();
135 // gui->cursor->draw(1);
136 // gui->canvas->flash();
137 // gui->canvas->activate();
138 cwindow->refresh_frame(CHANGE_EDL);
143 int MWindow::add_audio_track(int above, Track *dst)
145 edl->tracks->add_audio_track(above, dst);
146 edl->tracks->update_y_pixels(theme);
151 int MWindow::add_video_track(int above, Track *dst)
153 edl->tracks->add_video_track(above, dst);
154 edl->tracks->update_y_pixels(theme);
159 int MWindow::add_subttl_track(int above, Track *dst)
161 edl->tracks->add_subttl_track(above, dst);
162 edl->tracks->update_y_pixels(theme);
167 void MWindow::asset_to_all()
169 if( !session->drag_assets->size() ) return;
170 Indexable *indexable = session->drag_assets->get(0);
172 // if( indexable->have_video() )
176 undo->update_undo_before();
179 w = indexable->get_w();
180 h = indexable->get_h();
181 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
182 double old_framerate = edl->session->frame_rate;
183 int old_samplerate = edl->session->sample_rate;
184 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
187 if( indexable->have_video() ) {
188 edl->session->output_w = w;
189 edl->session->output_h = h;
190 edl->session->frame_rate = new_framerate;
192 edl->session->aspect_w,
193 edl->session->aspect_h,
196 for( Track *current = edl->tracks->first; current; current = NEXT ) {
197 if( current->data_type == TRACK_VIDEO /* &&
198 current->record */ ) {
199 current->track_w = w;
200 current->track_h = h;
205 if( ((edl->session->output_w % 4) ||
206 (edl->session->output_h % 4)) &&
207 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
208 MainError::show_error(
209 _("This project's dimensions are not multiples of 4 so\n"
210 "it can't be rendered by OpenGL."));
214 if( defaults->get("AUTOASPECT", 0) ) {
216 edl->session->aspect_w,
217 edl->session->aspect_h,
222 if( indexable->have_audio() ) {
223 edl->session->sample_rate = new_samplerate;
224 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
225 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
230 undo->update_undo_after(_("asset to all"), LOAD_ALL);
232 gui->update(1, 2, 1, 1, 1, 1, 0);
233 sync_parameters(CHANGE_ALL);
237 void MWindow::asset_to_size()
239 if( !session->drag_assets->size() ) return;
240 Indexable *indexable = session->drag_assets->get(0);
242 if( indexable->have_video() ) {
244 undo->update_undo_before();
247 w = indexable->get_w();
248 h = indexable->get_h();
249 edl->session->output_w = w;
250 edl->session->output_h = h;
252 if( ((edl->session->output_w % 4) ||
253 (edl->session->output_h % 4)) &&
254 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
255 MainError::show_error(
256 _("This project's dimensions are not multiples of 4 so\n"
257 "it can't be rendered by OpenGL."));
261 if( defaults->get("AUTOASPECT", 0) ) {
262 create_aspect_ratio(edl->session->aspect_w,
263 edl->session->aspect_h,
270 undo->update_undo_after(_("asset to size"), LOAD_ALL);
272 sync_parameters(CHANGE_ALL);
277 void MWindow::asset_to_rate()
279 if( session->drag_assets->size() &&
280 session->drag_assets->get(0)->have_video() ) {
281 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
282 double old_framerate = edl->session->frame_rate;
283 undo->update_undo_before();
285 edl->session->frame_rate = new_framerate;
286 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
290 undo->update_undo_after(_("asset to rate"), LOAD_ALL);
292 gui->update(1, 2, 1, 1, 1, 1, 0);
293 sync_parameters(CHANGE_ALL);
298 void MWindow::clear_entry()
300 undo->update_undo_before();
305 undo->update_undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
308 update_plugin_guis();
309 gui->update(1, 2, 1, 1, 1, 1, 0);
310 cwindow->update(1, 0, 0, 0, 1);
311 cwindow->refresh_frame(CHANGE_EDL);
314 void MWindow::clear(int clear_handle)
316 double start = edl->local_session->get_selectionstart();
317 double end = edl->local_session->get_selectionend();
318 if( clear_handle || !EQUIV(start, end) ) {
321 edl->session->labels_follow_edits,
322 edl->session->plugins_follow_edits,
323 edl->session->autos_follow_edits);
327 void MWindow::set_automation_mode(int mode)
329 undo->update_undo_before();
330 edl->tracks->set_automation_mode(
331 edl->local_session->get_selectionstart(),
332 edl->local_session->get_selectionend(),
335 char string[BCSTRLEN];
336 sprintf(string,"set %s", FloatAuto::curve_name(mode));
337 undo->update_undo_after(string, LOAD_AUTOMATION);
340 update_plugin_guis();
341 gui->draw_overlays(1);
342 sync_parameters(CHANGE_PARAMS);
343 gui->update_patchbay();
344 cwindow->update(1, 0, 0);
347 void MWindow::clear_automation()
349 undo->update_undo_before();
350 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
351 edl->local_session->get_selectionend());
353 undo->update_undo_after(_("clear keyframes"), LOAD_AUTOMATION);
356 update_plugin_guis();
357 gui->draw_overlays(1);
358 sync_parameters(CHANGE_PARAMS);
359 gui->update_patchbay();
360 cwindow->update(1, 0, 0);
363 int MWindow::clear_default_keyframe()
365 undo->update_undo_before();
366 edl->tracks->clear_default_keyframe();
368 undo->update_undo_after(_("clear default keyframe"), LOAD_AUTOMATION);
371 gui->draw_overlays(1);
372 sync_parameters(CHANGE_PARAMS);
373 gui->update_patchbay();
374 cwindow->update(1, 0, 0);
379 void MWindow::clear_labels()
381 undo->update_undo_before();
382 clear_labels(edl->local_session->get_selectionstart(),
383 edl->local_session->get_selectionend());
384 undo->update_undo_after(_("clear labels"), LOAD_TIMEBAR);
386 gui->update_timebar(1);
387 cwindow->update(0, 0, 0, 0, 1);
391 int MWindow::clear_labels(double start, double end)
393 edl->labels->clear(start, end, 0);
397 void MWindow::concatenate_tracks()
399 undo->update_undo_before();
400 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
401 edl->session->autos_follow_edits);
403 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
406 gui->update(1, 1, 0, 0, 1, 0, 0);
407 cwindow->refresh_frame(CHANGE_EDL);
413 copy(edl->local_session->get_selectionstart(),
414 edl->local_session->get_selectionend());
417 int MWindow::copy(double start, double end)
419 if( start == end ) return 1;
422 edl->copy(start, end, 0, 0, 0, &file, "", 1);
423 const char *file_string = file.string();
424 long file_length = strlen(file_string);
425 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
426 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
431 int MWindow::copy_automation()
434 double start = edl->local_session->get_selectionstart();
435 double end = edl->local_session->get_selectionend();
436 edl->tracks->copy_automation(start, end, &file, 0, 1);
437 const char *file_string = file.string();
438 long file_length = strlen(file_string);
439 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
440 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
444 int MWindow::copy_default_keyframe()
447 double start = edl->local_session->get_selectionstart();
448 double end = edl->local_session->get_selectionend();
449 edl->tracks->copy_automation(start, end, &file, 1, 0);
450 const char *file_string = file.string();
451 long file_length = strlen(file_string);
452 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
453 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
458 // Uses cropping coordinates in edl session to crop and translate video.
459 // We modify the projector since camera automation depends on the track size.
460 void MWindow::crop_video()
463 undo->update_undo_before();
464 // Clamp EDL crop region
465 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
466 edl->session->crop_x1 ^= edl->session->crop_x2;
467 edl->session->crop_x2 ^= edl->session->crop_x1;
468 edl->session->crop_x1 ^= edl->session->crop_x2;
470 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
471 edl->session->crop_y1 ^= edl->session->crop_y2;
472 edl->session->crop_y2 ^= edl->session->crop_y1;
473 edl->session->crop_y1 ^= edl->session->crop_y2;
476 float old_projector_x = (float)edl->session->output_w / 2;
477 float old_projector_y = (float)edl->session->output_h / 2;
478 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
479 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
480 float projector_offset_x = -(new_projector_x - old_projector_x);
481 float projector_offset_y = -(new_projector_y - old_projector_y);
483 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
485 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
486 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
487 edl->session->crop_x1 = 0;
488 edl->session->crop_y1 = 0;
489 edl->session->crop_x2 = edl->session->output_w;
490 edl->session->crop_y2 = edl->session->output_h;
492 // Recalculate aspect ratio
493 if( defaults->get("AUTOASPECT", 0) ) {
494 create_aspect_ratio(edl->session->aspect_w,
495 edl->session->aspect_h,
496 edl->session->output_w,
497 edl->session->output_h);
500 undo->update_undo_after(_("crop"), LOAD_ALL);
503 cwindow->refresh_frame(CHANGE_ALL);
509 double start = edl->local_session->get_selectionstart();
510 double end = edl->local_session->get_selectionend();
511 if( EQUIV(start,end) )
517 void MWindow::blade(double position)
519 undo->update_undo_before();
520 edl->blade(position);
523 undo->update_undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
525 update_plugin_guis();
526 gui->update(1, 2, 1, 1, 1, 1, 0);
527 cwindow->update(1, 0, 0, 0, 1);
528 awindow->gui->async_update_assets();
529 cwindow->refresh_frame(CHANGE_EDL);
532 void MWindow::cut(double start, double end, double new_position)
534 undo->update_undo_before();
536 edl->clear(start, end,
537 edl->session->labels_follow_edits,
538 edl->session->plugins_follow_edits,
539 edl->session->autos_follow_edits);
543 undo->update_undo_after(_("cut"), LOAD_EDITS | LOAD_TIMEBAR);
544 if( new_position >= 0 ) {
545 edl->local_session->set_selectionstart(new_position);
546 edl->local_session->set_selectionend(new_position);
549 update_plugin_guis();
550 gui->update(1, 2, 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::snap_left_edit()
558 double start_pos = edl->local_session->get_selectionstart(1);
559 double position = edl->prev_edit(start_pos);
560 if( position < start_pos )
561 cut(position, start_pos, position);
564 void MWindow::snap_right_edit()
566 double end_pos = edl->local_session->get_selectionend(1);
567 double position = edl->next_edit(end_pos);
568 if( end_pos < position )
569 cut(end_pos, position, end_pos);
572 void MWindow::snap_left_label()
574 double start_pos = edl->local_session->get_selectionstart(1);
575 Label *left_label = edl->labels->prev_label(start_pos);
576 if( !left_label ) return;
577 double position = left_label->position;
578 if( position < start_pos )
579 cut(position, start_pos, position);
582 void MWindow::snap_right_label()
584 double end_pos = edl->local_session->get_selectionend(1);
585 Label *right_label = edl->labels->next_label(end_pos);
586 if( !right_label ) return;
587 double position = right_label->position;
588 if( end_pos < position )
589 cut(end_pos, position, end_pos);
592 int MWindow::cut_automation()
594 undo->update_undo_before();
598 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
599 edl->local_session->get_selectionend());
601 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
605 update_plugin_guis();
606 gui->draw_overlays(1);
607 sync_parameters(CHANGE_PARAMS);
608 gui->update_patchbay();
609 cwindow->update(1, 0, 0);
613 int MWindow::cut_default_keyframe()
616 undo->update_undo_before();
617 copy_default_keyframe();
618 edl->tracks->clear_default_keyframe();
619 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
622 gui->draw_overlays(1);
623 sync_parameters(CHANGE_PARAMS);
624 gui->update_patchbay();
625 cwindow->update(1, 0, 0);
633 void MWindow::delete_inpoint()
635 edl->local_session->unset_inpoint();
639 void MWindow::delete_outpoint()
641 edl->local_session->unset_outpoint();
646 void MWindow::delete_track()
648 if( edl->tracks->last )
649 delete_track(edl->tracks->last);
652 void MWindow::delete_tracks()
654 undo->update_undo_before();
655 edl->tracks->delete_tracks();
656 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
660 update_plugin_states();
662 gui->update(1, 1, 1, 0, 1, 0, 0);
663 cwindow->refresh_frame(CHANGE_EDL);
666 void MWindow::delete_track(Track *track)
668 undo->update_undo_before();
669 edl->tracks->delete_track(track);
670 undo->update_undo_after(_("delete track"), LOAD_ALL);
673 update_plugin_states();
675 gui->update(1, 1, 1, 0, 1, 0, 0);
676 cwindow->refresh_frame(CHANGE_EDL);
681 // Insert data from clipboard
682 void MWindow::insert(double position, FileXML *file,
683 int edit_labels, int edit_plugins, int edit_autos,
686 // For clipboard pasting make the new edl use a separate session
687 // from the master EDL. Then it can be resampled to the master rates.
688 // For splice, overwrite, and dragging need same session to get the assets.
689 EDL *edl = new EDL(parent_edl);
690 ArrayList<EDL*> new_edls;
691 uint32_t load_flags = LOAD_ALL;
694 new_edls.append(edl);
695 edl->create_objects();
700 if( parent_edl ) load_flags &= ~LOAD_SESSION;
701 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
702 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
704 edl->load_xml(file, load_flags);
707 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
711 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
712 edit_labels, edit_plugins, edit_autos, 0); // overwrite
713 // if( vwindow->edl )
714 // printf("MWindow::insert 5 %f %f\n",
715 // vwindow->edl->local_session->in_point,
716 // vwindow->edl->local_session->out_point);
717 new_edls.remove_all();
718 edl->Garbage::remove_user();
719 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
722 void MWindow::insert_effects_canvas(double start,
725 Track *dest_track = session->track_highlighted;
726 if( !dest_track ) return;
728 undo->update_undo_before();
730 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
731 PluginServer *plugin = session->drag_pluginservers->values[i];
732 insert_effect(plugin->title, 0, dest_track,
733 i == 0 ? session->pluginset_highlighted : 0,
734 start, length, PLUGIN_STANDALONE);
738 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
740 sync_parameters(CHANGE_EDL);
741 // GUI updated in TrackCanvas, after current_operations are reset
744 void MWindow::insert_effects_cwindow(Track *dest_track)
746 if( !dest_track ) return;
748 undo->update_undo_before();
751 double length = dest_track->get_length();
753 if( edl->local_session->get_selectionend() >
754 edl->local_session->get_selectionstart() ) {
755 start = edl->local_session->get_selectionstart();
756 length = edl->local_session->get_selectionend() -
757 edl->local_session->get_selectionstart();
760 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
761 PluginServer *plugin = session->drag_pluginservers->values[i];
762 insert_effect(plugin->title, 0, dest_track, 0,
763 start, length, PLUGIN_STANDALONE);
767 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
769 sync_parameters(CHANGE_EDL);
770 gui->update(1, 1, 0, 0, 1, 0, 0);
773 void MWindow::insert_effect(char *title,
774 SharedLocation *shared_location,
777 int single_standalone)
779 Track *current = edl->tracks->first;
780 SharedLocation shared_location_local;
781 shared_location_local.copy_from(shared_location);
783 for( ; current; current = NEXT) {
784 if( current->data_type == data_type &&
786 insert_effect(title, &shared_location_local,
787 current, 0, 0, 0, plugin_type);
790 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
791 plugin_type = PLUGIN_SHAREDPLUGIN;
792 shared_location_local.module = edl->tracks->number_of(current);
793 shared_location_local.plugin = current->plugin_set.total - 1;
802 void MWindow::insert_effect(char *title,
803 SharedLocation *shared_location,
805 PluginSet *plugin_set,
810 KeyFrame *default_keyframe = 0;
811 PluginServer *server = 0;
812 // Get default keyframe
813 if( plugin_type == PLUGIN_STANDALONE ) {
814 default_keyframe = new KeyFrame;
815 server = new PluginServer(*scan_plugindb(title, track->data_type));
817 server->open_plugin(0, preferences, edl, 0);
818 server->save_data(default_keyframe);
820 // Insert plugin object
821 track->insert_effect(title, shared_location,
822 default_keyframe, plugin_set,
823 start, length, plugin_type);
826 if( plugin_type == PLUGIN_STANDALONE ) {
827 server->close_plugin();
829 delete default_keyframe;
833 int MWindow::modify_edithandles()
835 undo->update_undo_before();
836 edl->modify_edithandles(session->drag_start,
837 session->drag_position,
838 session->drag_handle,
839 edl->session->edit_handle_mode[session->drag_button],
840 edl->session->labels_follow_edits,
841 edl->session->plugins_follow_edits,
842 edl->session->autos_follow_edits);
844 finish_modify_handles();
845 //printf("MWindow::modify_handles 1\n");
849 int MWindow::modify_pluginhandles()
851 undo->update_undo_before();
853 edl->modify_pluginhandles(session->drag_start,
854 session->drag_position,
855 session->drag_handle,
856 edl->session->edit_handle_mode[session->drag_button],
857 edl->session->labels_follow_edits,
858 edl->session->autos_follow_edits,
859 session->trim_edits);
861 finish_modify_handles();
867 // Common to edithandles and plugin handles
868 void MWindow::finish_modify_handles()
870 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
872 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
873 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
874 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
875 edl->local_session->set_selectionstart(session->drag_position);
876 edl->local_session->set_selectionend(session->drag_position);
879 if( edit_mode != MOVE_NO_EDITS ) {
880 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
881 edl->local_session->set_selectionstart(session->drag_start);
882 edl->local_session->set_selectionend(session->drag_start);
885 // clamp the selection to 0
886 if( edl->local_session->get_selectionstart(1) < 0 ) {
887 edl->local_session->set_selectionstart(0);
888 edl->local_session->set_selectionend(0);
890 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
894 sync_parameters(CHANGE_EDL);
895 update_plugin_guis();
896 gui->update(1, 2, 1, 1, 1, 1, 0);
897 // label list can be modified
898 awindow->gui->async_update_assets();
899 cwindow->update(1, 0, 0, 0, 1);
902 void MWindow::match_output_size(Track *track)
904 undo->update_undo_before();
905 track->track_w = edl->session->output_w;
906 track->track_h = edl->session->output_h;
908 undo->update_undo_after(_("match output size"), LOAD_ALL);
911 sync_parameters(CHANGE_EDL);
915 void MWindow::move_edits(ArrayList<Edit*> *edits,
920 undo->update_undo_before();
922 edl->tracks->move_edits(edits,
925 edl->session->labels_follow_edits,
926 edl->session->plugins_follow_edits,
927 edl->session->autos_follow_edits,
931 undo->update_undo_after(_("move edit"), LOAD_ALL);
934 cwindow->refresh_frame(CHANGE_EDL);
936 update_plugin_guis();
937 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
941 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
943 undo->update_undo_before();
944 edl->tracks->move_effect(plugin, track, position);
946 undo->update_undo_after(_("paste effect"), LOAD_ALL);
949 cwindow->refresh_frame(CHANGE_EDL);
950 update_plugin_guis();
951 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
955 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
957 undo->update_undo_before();
958 edl->tracks->move_effect(plugin, plugin_set, position);
960 undo->update_undo_after(_("move effect"), LOAD_ALL);
963 cwindow->refresh_frame(CHANGE_EDL);
964 update_plugin_guis();
965 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
969 void MWindow::move_plugins_up(PluginSet *plugin_set)
972 undo->update_undo_before();
973 plugin_set->track->move_plugins_up(plugin_set);
976 undo->update_undo_after(_("move effect up"), LOAD_ALL);
978 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
980 sync_parameters(CHANGE_EDL);
983 void MWindow::move_plugins_down(PluginSet *plugin_set)
985 undo->update_undo_before();
987 plugin_set->track->move_plugins_down(plugin_set);
990 undo->update_undo_after(_("move effect down"), LOAD_ALL);
992 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
994 sync_parameters(CHANGE_EDL);
997 void MWindow::move_track_down(Track *track)
999 undo->update_undo_before();
1000 edl->tracks->move_track_down(track);
1002 undo->update_undo_after(_("move track down"), LOAD_ALL);
1005 gui->update(1, 1, 0, 0, 1, 0, 0);
1006 sync_parameters(CHANGE_EDL);
1010 void MWindow::move_tracks_down()
1012 undo->update_undo_before();
1013 edl->tracks->move_tracks_down();
1015 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1018 gui->update(1, 1, 0, 0, 1, 0, 0);
1019 sync_parameters(CHANGE_EDL);
1023 void MWindow::move_track_up(Track *track)
1025 undo->update_undo_before();
1026 edl->tracks->move_track_up(track);
1028 undo->update_undo_after(_("move track up"), LOAD_ALL);
1030 gui->update(1, 1, 0, 0, 1, 0, 0);
1031 sync_parameters(CHANGE_EDL);
1035 void MWindow::move_tracks_up()
1037 undo->update_undo_before();
1038 edl->tracks->move_tracks_up();
1040 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1042 gui->update(1, 1, 0, 0, 1, 0, 0);
1043 sync_parameters(CHANGE_EDL);
1047 void MWindow::mute_selection()
1049 double start = edl->local_session->get_selectionstart();
1050 double end = edl->local_session->get_selectionend();
1051 if( start != end ) {
1052 undo->update_undo_before();
1053 edl->clear(start, end, 0,
1054 edl->session->plugins_follow_edits,
1055 edl->session->autos_follow_edits);
1056 edl->local_session->set_selectionend(end);
1057 edl->local_session->set_selectionstart(start);
1058 edl->paste_silence(start, end, 0,
1059 edl->session->plugins_follow_edits,
1060 edl->session->autos_follow_edits);
1063 undo->update_undo_after(_("mute"), LOAD_EDITS);
1066 update_plugin_guis();
1067 gui->update(1, 2, 1, 1, 1, 1, 0);
1068 cwindow->refresh_frame(CHANGE_EDL);
1073 void MWindow::overwrite(EDL *source)
1077 double src_start = source->local_session->get_selectionstart();
1078 double overwrite_len = source->local_session->get_selectionend() - src_start;
1079 double dst_start = edl->local_session->get_selectionstart();
1080 double dst_len = edl->local_session->get_selectionend() - dst_start;
1082 undo->update_undo_before();
1083 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1084 // in/out points or selection present and shorter than overwrite range
1085 // shorten the copy range
1086 overwrite_len = dst_len;
1089 source->copy(src_start, src_start + overwrite_len,
1090 0, 0, 0, &file, "", 1);
1092 // HACK around paste_edl get_start/endselection on its own
1093 // so we need to clear only when not using both io points
1094 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1095 if( edl->local_session->get_inpoint() < 0 ||
1096 edl->local_session->get_outpoint() < 0 )
1097 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1099 paste(dst_start, dst_start + overwrite_len,
1102 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1103 edl->local_session->set_selectionend(dst_start + overwrite_len);
1106 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1109 update_plugin_guis();
1110 gui->update(1, 1, 1, 1, 0, 1, 0);
1111 sync_parameters(CHANGE_EDL);
1114 // For splice and overwrite
1115 int MWindow::paste(double start,
1124 // Want to insert with assets shared with the master EDL.
1126 edit_labels, edit_plugins, edit_autos,
1132 // For editing using insertion point
1133 void MWindow::paste()
1135 double start = edl->local_session->get_selectionstart();
1136 //double end = edl->local_session->get_selectionend();
1137 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1140 char *string = new char[len];
1141 undo->update_undo_before();
1142 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1144 file.read_from_string(string);
1147 insert(start, &file,
1148 edl->session->labels_follow_edits,
1149 edl->session->plugins_follow_edits,
1150 edl->session->autos_follow_edits,
1158 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1160 update_plugin_guis();
1161 gui->update(1, 2, 1, 1, 0, 1, 0);
1162 awindow->gui->async_update_assets();
1163 sync_parameters(CHANGE_EDL);
1168 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1171 undo->update_undo_before();
1173 if( session->drag_assets->total ) {
1174 load_assets(session->drag_assets,
1175 position, LOADMODE_PASTE, dest_track, 0,
1176 edl->session->labels_follow_edits,
1177 edl->session->plugins_follow_edits,
1178 edl->session->autos_follow_edits,
1183 if( session->drag_clips->total ) {
1184 paste_edls(session->drag_clips,
1185 LOADMODE_PASTE, dest_track, position,
1186 edl->session->labels_follow_edits,
1187 edl->session->plugins_follow_edits,
1188 edl->session->autos_follow_edits,
1195 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1197 gui->update(1, 2, 1, 0, 0, 1, 0);
1198 sync_parameters(CHANGE_EDL);
1202 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1203 double position, int load_mode, Track *first_track, RecordLabels *labels,
1204 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1206 if( load_mode == LOADMODE_RESOURCESONLY )
1207 load_mode = LOADMODE_ASSETSONLY;
1208 const int debug = 0;
1209 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1210 if( position < 0 ) position = edl->local_session->get_selectionstart();
1212 ArrayList<EDL*> new_edls;
1213 for( int i = 0; i < new_assets->total; i++ ) {
1214 Indexable *indexable = new_assets->get(i);
1215 if( indexable->is_asset ) {
1216 remove_asset_from_caches((Asset*)indexable);
1218 EDL *new_edl = new EDL;
1219 new_edl->create_objects();
1220 new_edl->copy_session(edl);
1221 new_edls.append(new_edl);
1224 if( indexable->is_asset ) {
1225 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1226 if( debug ) ((Asset*)indexable)->dump();
1227 asset_to_edl(new_edl, (Asset*)indexable);
1230 edl_to_nested(new_edl, (EDL*)indexable);
1231 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1235 for( RecordLabel *label = labels->first; label; label = label->next ) {
1236 new_edl->labels->toggle_label(label->position, label->position);
1240 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1242 paste_edls(&new_edls, load_mode, first_track, position,
1243 edit_labels, edit_plugins, edit_autos, overwrite);
1244 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1247 for( int i = 0; i < new_edls.size(); i++ )
1248 new_edls.get(i)->Garbage::remove_user();
1250 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1253 int MWindow::paste_automation()
1255 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1258 undo->update_undo_before();
1259 char *string = new char[len];
1260 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1262 file.read_from_string(string);
1264 double start = edl->local_session->get_selectionstart();
1265 double end = edl->local_session->get_selectionend();
1266 edl->tracks->clear_automation(start, end);
1267 edl->tracks->paste_automation(start, &file, 0, 1,
1268 edl->session->typeless_keyframes);
1270 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1274 update_plugin_guis();
1275 gui->draw_overlays(1);
1276 sync_parameters(CHANGE_PARAMS);
1277 gui->update_patchbay();
1278 cwindow->update(1, 0, 0);
1284 int MWindow::paste_default_keyframe()
1286 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1289 undo->update_undo_before();
1290 char *string = new char[len];
1291 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1293 file.read_from_string(string);
1294 double start = edl->local_session->get_selectionstart();
1295 edl->tracks->paste_automation(start, &file, 1, 0,
1296 edl->session->typeless_keyframes);
1297 // edl->tracks->paste_default_keyframe(&file);
1298 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1301 update_plugin_guis();
1302 gui->draw_overlays(1);
1303 sync_parameters(CHANGE_PARAMS);
1304 gui->update_patchbay();
1305 cwindow->update(1, 0, 0);
1314 // Insert edls with project deletion and index file generation.
1315 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1316 Track *first_track, double current_position,
1317 int edit_labels, int edit_plugins, int edit_autos,
1321 ArrayList<Track*> destination_tracks;
1322 int need_new_tracks = 0;
1325 if( !new_edls->total ) return 0;
1328 // double original_length = edl->tracks->total_length();
1329 // double original_preview_end = edl->local_session->preview_end;
1332 // Delete current project
1333 if( load_mode == LOADMODE_REPLACE ||
1334 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1336 edl->save_defaults(defaults);
1338 edl->Garbage::remove_user();
1340 edl->create_objects();
1341 edl->copy_session(new_edls->values[0]);
1342 edl->copy_mixers(new_edls->values[0]);
1343 gui->mainmenu->update_toggles(0);
1344 gui->unlock_window();
1345 gwindow->gui->update_toggles(1);
1346 gui->lock_window("MWindow::paste_edls");
1348 // Insert labels for certain modes constitutively
1352 // Force reset of preview
1353 // original_length = 0;
1354 // original_preview_end = -1;
1360 // Create new tracks in master EDL
1361 if( load_mode == LOADMODE_REPLACE ||
1362 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1363 load_mode == LOADMODE_NEW_TRACKS ) {
1365 need_new_tracks = 1;
1366 for( int i = 0; i < new_edls->total; i++ ) {
1367 EDL *new_edl = new_edls->values[i];
1368 for( Track *current = new_edl->tracks->first;
1371 if( current->data_type == TRACK_VIDEO ) {
1372 edl->tracks->add_video_track(0, 0);
1373 if( current->draw ) edl->tracks->last->draw = 1;
1374 destination_tracks.append(edl->tracks->last);
1377 if( current->data_type == TRACK_AUDIO ) {
1378 edl->tracks->add_audio_track(0, 0);
1379 destination_tracks.append(edl->tracks->last);
1382 if( current->data_type == TRACK_SUBTITLE ) {
1383 edl->tracks->add_subttl_track(0, 0);
1384 destination_tracks.append(edl->tracks->last);
1386 edl->session->highlighted_track = edl->tracks->total() - 1;
1389 // Base track count on first EDL only for concatenation
1390 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1395 // Recycle existing tracks of master EDL
1396 if( load_mode == LOADMODE_CONCATENATE ||
1397 load_mode == LOADMODE_PASTE ||
1398 load_mode == LOADMODE_NESTED ) {
1401 // The point of this is to shift forward labels after the selection so they can
1402 // then be shifted back to their original locations without recursively
1403 // shifting back every paste.
1404 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1405 edl->session->labels_follow_edits )
1406 edl->labels->clear(edl->local_session->get_selectionstart(),
1407 edl->local_session->get_selectionend(),
1410 Track *current = first_track ? first_track : edl->tracks->first;
1411 for( ; current; current = NEXT) {
1412 if( current->record ) {
1413 destination_tracks.append(current);
1420 int destination_track = 0;
1421 double *paste_position = new double[destination_tracks.total];
1423 // Iterate through the edls
1424 for( int i = 0; i < new_edls->total; i++ ) {
1426 EDL *new_edl = new_edls->values[i];
1427 double edl_length = new_edl->local_session->clipboard_length ?
1428 new_edl->local_session->clipboard_length :
1429 new_edl->tracks->total_length();
1430 // printf("MWindow::paste_edls 2 %f %f\n",
1431 // new_edl->local_session->clipboard_length,
1432 // new_edl->tracks->total_length());
1436 // Convert EDL to master rates
1437 new_edl->resample(new_edl->session->sample_rate,
1438 edl->session->sample_rate,
1440 new_edl->resample(new_edl->session->frame_rate,
1441 edl->session->frame_rate,
1444 // Add assets and prepare index files
1445 for( Asset *new_asset = new_edl->assets->first;
1447 new_asset = new_asset->next ) {
1448 mainindexes->add_next_asset(0, new_asset);
1450 // Capture index file status from mainindex test
1451 edl->update_assets(new_edl);
1453 // Get starting point of insertion. Need this to paste labels.
1454 switch( load_mode ) {
1455 case LOADMODE_REPLACE:
1456 case LOADMODE_NEW_TRACKS:
1457 current_position = 0;
1460 case LOADMODE_CONCATENATE:
1461 case LOADMODE_REPLACE_CONCATENATE:
1462 destination_track = 0;
1463 if( destination_tracks.total )
1464 current_position = destination_tracks.values[0]->get_length();
1466 current_position = 0;
1469 case LOADMODE_PASTE:
1470 case LOADMODE_NESTED:
1471 destination_track = 0;
1473 for( int j = 0; j < destination_tracks.total; j++ ) {
1474 paste_position[j] = (current_position >= 0) ?
1476 edl->local_session->get_selectionstart();
1481 case LOADMODE_RESOURCESONLY:
1482 edl->add_clip(new_edl);
1487 if( load_mode != LOADMODE_RESOURCESONLY &&
1488 load_mode != LOADMODE_ASSETSONLY ) {
1490 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1491 if( load_mode == LOADMODE_PASTE ||
1492 load_mode == LOADMODE_NESTED )
1493 edl->labels->insert_labels(new_edl->labels,
1494 destination_tracks.total ? paste_position[0] : 0.0,
1498 edl->labels->insert_labels(new_edl->labels,
1504 for( Track *new_track = new_edl->tracks->first;
1506 new_track = new_track->next ) {
1507 // Get destination track of same type as new_track
1509 k < destination_tracks.total &&
1510 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1511 k++, destination_track++ ) {
1512 if( destination_track >= destination_tracks.total - 1 )
1513 destination_track = 0;
1516 // Insert data into destination track
1517 if( destination_track < destination_tracks.total &&
1518 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1519 Track *track = destination_tracks.values[destination_track];
1521 // Replace default keyframes if first EDL and new tracks were created.
1522 // This means data copied from one track and pasted to another won't retain
1523 // the camera position unless it's a keyframe. If it did, previous data in the
1524 // track might get unknowingly corrupted. Ideally we would detect when differing
1525 // default keyframes existed and create discrete keyframes for both.
1526 int replace_default = (i == 0) && need_new_tracks;
1528 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1529 // Insert new track at current position
1530 switch( load_mode ) {
1531 case LOADMODE_REPLACE_CONCATENATE:
1532 case LOADMODE_CONCATENATE:
1533 current_position = track->get_length();
1536 case LOADMODE_PASTE:
1537 case LOADMODE_NESTED:
1538 current_position = paste_position[destination_track];
1539 paste_position[destination_track] += new_track->get_length();
1543 track->clear(current_position,
1544 current_position + new_track->get_length(),
1546 edit_labels, edit_plugins, edit_autos,
1551 track->insert_track(new_track, current_position, replace_default,
1552 edit_plugins, edit_autos, edl_length);
1556 // Get next destination track
1557 destination_track++;
1558 if( destination_track >= destination_tracks.total )
1559 destination_track = 0;
1563 if( load_mode == LOADMODE_PASTE ||
1564 load_mode == LOADMODE_NESTED )
1565 current_position += edl_length;
1569 // Move loading of clips and vwindow to the end - this fixes some
1570 // strange issue, for index not being shown
1571 // Assume any paste operation from the same EDL won't contain any clips.
1572 // If it did it would duplicate every clip here.
1573 for( int i = 0; i < new_edls->total; i++ ) {
1574 EDL *new_edl = new_edls->values[i];
1576 for( int j = 0; j < new_edl->clips.total; j++ ) {
1577 edl->add_clip(new_edl->clips.values[j]);
1580 if( new_edl->total_vwindow_edls() ) {
1581 // if( edl->vwindow_edl )
1582 // edl->vwindow_edl->Garbage::remove_user();
1583 // edl->vwindow_edl = new EDL(edl);
1584 // edl->vwindow_edl->create_objects();
1585 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1587 for( int j = 0; j < new_edl->total_vwindow_edls(); j++ ) {
1588 EDL *vwindow_edl = new EDL(edl);
1589 vwindow_edl->create_objects();
1590 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1591 edl->append_vwindow_edl(vwindow_edl, 0);
1596 if( paste_position ) delete [] paste_position;
1598 // This is already done in load_filenames and everything else that uses paste_edls
1599 // update_project(load_mode);
1601 // Fix preview range
1602 // if( EQUIV(original_length, original_preview_end) )
1604 // edl->local_session->preview_end = edl->tracks->total_length();
1607 // Start examining next batch of index files
1608 mainindexes->start_build();
1610 // Don't save a backup after loading since the loaded file is on disk already.
1615 void MWindow::paste_silence()
1617 double start = edl->local_session->get_selectionstart();
1618 double end = edl->local_session->get_selectionend();
1619 undo->update_undo_before();
1620 edl->paste_silence(start, end,
1621 edl->session->labels_follow_edits,
1622 edl->session->plugins_follow_edits,
1623 edl->session->autos_follow_edits);
1626 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1628 update_plugin_guis();
1630 gui->update(1, 2, 1, 1, 1, 1, 0);
1631 cwindow->update(1, 0, 0, 0, 1);
1632 cwindow->refresh_frame(CHANGE_EDL);
1635 void MWindow::detach_transition(Transition *transition)
1637 undo->update_undo_before();
1638 hide_plugin(transition, 1);
1639 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1640 transition->edit->detach_transition();
1642 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1644 if( is_video ) restart_brender();
1645 gui->update(0, 1, 0, 0, 0, 0, 0);
1646 sync_parameters(CHANGE_EDL);
1649 void MWindow::detach_transitions()
1651 gui->lock_window("MWindow::detach_transitions 1");
1653 undo->update_undo_before();
1654 double start = edl->local_session->get_selectionstart();
1655 double end = edl->local_session->get_selectionend();
1656 edl->tracks->clear_transitions(start, end);
1659 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1661 sync_parameters(CHANGE_EDL);
1662 gui->update(0, 1, 0, 0, 0, 0, 0);
1663 gui->unlock_window();
1666 void MWindow::paste_transition()
1668 // Only the first transition gets dropped.
1669 PluginServer *server = session->drag_pluginservers->values[0];
1671 undo->update_undo_before();
1673 strcpy(edl->session->default_atransition, server->title);
1675 strcpy(edl->session->default_vtransition, server->title);
1677 edl->tracks->paste_transition(server, session->edit_highlighted);
1679 undo->update_undo_after(_("transition"), LOAD_EDITS);
1681 if( server->video ) restart_brender();
1682 sync_parameters(CHANGE_ALL);
1685 void MWindow::paste_transitions(int track_type, char *title)
1687 gui->lock_window("MWindow::detach_transitions 1");
1689 undo->update_undo_before();
1690 double start = edl->local_session->get_selectionstart();
1691 double end = edl->local_session->get_selectionend();
1692 edl->tracks->paste_transitions(start, end, track_type, title);
1695 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1697 sync_parameters(CHANGE_EDL);
1698 gui->update(0, 1, 0, 0, 0, 0, 0);
1699 gui->unlock_window();
1702 void MWindow::paste_transition_cwindow(Track *dest_track)
1704 PluginServer *server = session->drag_pluginservers->values[0];
1705 undo->update_undo_before();
1706 edl->tracks->paste_video_transition(server, 1);
1708 undo->update_undo_after(_("transition"), LOAD_EDITS);
1710 gui->update(0, 1, 0, 0, 0, 0, 0);
1711 sync_parameters(CHANGE_ALL);
1714 void MWindow::paste_audio_transition()
1716 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1719 char string[BCTEXTLEN];
1720 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1721 gui->show_message(string);
1725 undo->update_undo_before();
1726 edl->tracks->paste_audio_transition(server);
1728 undo->update_undo_after(_("transition"), LOAD_EDITS);
1730 sync_parameters(CHANGE_EDL);
1731 gui->update(0, 1, 0, 0, 0, 0, 0);
1734 void MWindow::paste_video_transition()
1736 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1739 char string[BCTEXTLEN];
1740 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1741 gui->show_message(string);
1745 undo->update_undo_before();
1747 edl->tracks->paste_video_transition(server);
1749 undo->update_undo_after(_("transition"), LOAD_EDITS);
1751 sync_parameters(CHANGE_EDL);
1753 gui->update(0, 1, 0, 0, 0, 0, 0);
1756 void MWindow::shuffle_edits()
1758 gui->lock_window("MWindow::shuffle_edits 1");
1760 undo->update_undo_before();
1761 double start = edl->local_session->get_selectionstart();
1762 double end = edl->local_session->get_selectionend();
1764 edl->tracks->shuffle_edits(start, end);
1767 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1769 sync_parameters(CHANGE_EDL);
1771 gui->update(0, 1, 1, 0, 0, 0, 0);
1772 gui->unlock_window();
1775 void MWindow::reverse_edits()
1777 gui->lock_window("MWindow::reverse_edits 1");
1779 undo->update_undo_before();
1780 double start = edl->local_session->get_selectionstart();
1781 double end = edl->local_session->get_selectionend();
1783 edl->tracks->reverse_edits(start, end);
1786 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1788 sync_parameters(CHANGE_EDL);
1790 gui->update(0, 1, 1, 0, 0, 0, 0);
1791 gui->unlock_window();
1794 void MWindow::align_edits()
1796 gui->lock_window("MWindow::align_edits 1");
1798 undo->update_undo_before();
1799 double start = edl->local_session->get_selectionstart();
1800 double end = edl->local_session->get_selectionend();
1802 edl->tracks->align_edits(start, end);
1805 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1807 sync_parameters(CHANGE_EDL);
1809 gui->update(0, 1, 1, 0, 0, 0, 0);
1810 gui->unlock_window();
1813 void MWindow::set_edit_length(double length)
1815 gui->lock_window("MWindow::detach_transitions 1");
1817 undo->update_undo_before();
1818 double start = edl->local_session->get_selectionstart();
1819 double end = edl->local_session->get_selectionend();
1821 edl->tracks->set_edit_length(start, end, length);
1824 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1826 sync_parameters(CHANGE_EDL);
1828 gui->update(0, 1, 1, 0, 0, 0, 0);
1829 gui->unlock_window();
1833 void MWindow::set_transition_length(Transition *transition, double length)
1835 gui->lock_window("MWindow::detach_transitions 1");
1837 undo->update_undo_before();
1838 //double start = edl->local_session->get_selectionstart();
1839 //double end = edl->local_session->get_selectionend();
1841 edl->tracks->set_transition_length(transition, length);
1844 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1846 edl->session->default_transition_length = length;
1847 sync_parameters(CHANGE_PARAMS);
1848 gui->update(0, 1, 0, 0, 0, 0, 0);
1849 gui->unlock_window();
1852 void MWindow::set_transition_length(double length)
1854 gui->lock_window("MWindow::detach_transitions 1");
1856 undo->update_undo_before();
1857 double start = edl->local_session->get_selectionstart();
1858 double end = edl->local_session->get_selectionend();
1860 edl->tracks->set_transition_length(start, end, length);
1863 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1865 edl->session->default_transition_length = length;
1866 sync_parameters(CHANGE_PARAMS);
1868 gui->update(0, 1, 0, 0, 0, 0, 0);
1869 gui->unlock_window();
1873 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1875 calling_window_gui->unlock_window();
1878 cwindow->gui->lock_window("MWindow::redo_entry");
1879 for( int i = 0; i < vwindows.size(); i++ ) {
1880 if( vwindows.get(i)->is_running() ) {
1881 if( calling_window_gui != vwindows.get(i)->gui ) {
1882 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1891 update_plugin_states();
1892 update_plugin_guis();
1893 awindow->gui->async_update_assets();
1895 gui->update(1, 2, 1, 1, 1, 1, 1);
1896 cwindow->update(1, 1, 1, 1, 1);
1898 if( calling_window_gui != cwindow->gui )
1899 cwindow->gui->unlock_window();
1900 if( calling_window_gui != gui )
1901 gui->unlock_window();
1904 for( int i = 0; i < vwindows.size(); i++ ) {
1905 if( vwindows.get(i)->is_running() ) {
1906 if( calling_window_gui != vwindows.get(i)->gui ) {
1907 vwindows.get(i)->gui->unlock_window();
1912 cwindow->refresh_frame(CHANGE_ALL);
1916 void MWindow::resize_track(Track *track, int w, int h)
1918 undo->update_undo_before();
1919 // We have to move all maskpoints so they do not move in relation to image areas
1920 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1921 (w - track->track_w) / 2,
1922 (h - track->track_h) / 2);
1925 undo->update_undo_after(_("resize track"), LOAD_ALL);
1929 sync_parameters(CHANGE_EDL);
1933 void MWindow::set_inpoint(int is_mwindow)
1935 undo->update_undo_before();
1936 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1938 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1941 gui->lock_window("MWindow::set_inpoint 1");
1943 gui->update_timebar(1);
1945 gui->unlock_window();
1949 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1951 cwindow->gui->timebar->update(1);
1953 cwindow->gui->unlock_window();
1957 void MWindow::set_outpoint(int is_mwindow)
1959 undo->update_undo_before();
1960 edl->set_outpoint(edl->local_session->get_selectionend(1));
1962 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1965 gui->lock_window("MWindow::set_outpoint 1");
1967 gui->update_timebar(1);
1969 gui->unlock_window();
1973 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1975 cwindow->gui->timebar->update(1);
1977 cwindow->gui->unlock_window();
1981 void MWindow::splice(EDL *source)
1985 undo->update_undo_before();
1986 double source_start = source->local_session->get_selectionstart();
1987 double source_end = source->local_session->get_selectionend();
1988 source->copy(source_start, source_end, 1, 0, 0, &file, "", 1);
1990 double start = edl->local_session->get_selectionstart();
1991 //double end = edl->local_session->get_selectionend();
1993 paste(start, start, &file,
1994 edl->session->labels_follow_edits,
1995 edl->session->plugins_follow_edits,
1996 edl->session->autos_follow_edits);
1998 // Position at end of clip
1999 edl->local_session->set_selectionstart(start + source_end - source_start);
2000 edl->local_session->set_selectionend(start + source_end - source_start);
2003 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2004 update_plugin_guis();
2006 gui->update(1, 1, 1, 1, 0, 1, 0);
2007 sync_parameters(CHANGE_EDL);
2010 void MWindow::save_clip(EDL *new_edl, const char *txt)
2012 new_edl->local_session->set_selectionstart(0);
2013 new_edl->local_session->set_selectionend(0);
2014 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2015 session->clip_number++);
2016 char duration[BCTEXTLEN];
2017 Units::totext(duration, new_edl->tracks->total_length(),
2018 new_edl->session->time_format,
2019 new_edl->session->sample_rate,
2020 new_edl->session->frame_rate,
2021 new_edl->session->frames_per_foot);
2023 Track *track = new_edl->tracks->first;
2024 const char *path = edl->path;
2025 for( ; (!path || !*path) && track; track=track->next ) {
2026 if( !track->record ) continue;
2027 Edit *edit = track->edits->first;
2028 if( !edit ) continue;
2029 Indexable *indexable = edit->get_source();
2030 if( !indexable ) continue;
2031 path = indexable->path;
2034 time_t now; time(&now);
2035 struct tm *tm = localtime(&now);
2036 char *cp = new_edl->local_session->clip_notes;
2037 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2039 n = snprintf(cp, sz, "%s", txt);
2042 n = snprintf(cp, sz,
2043 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2044 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
2045 tm->tm_hour, tm->tm_min, tm->tm_sec, duration);
2047 if( path && *path ) {
2049 char title[BCTEXTLEN];
2050 fs.extract_name(title, path);
2051 n = snprintf(cp, sz, "%s", title);
2056 edl->update_assets(new_edl);
2058 gui->get_abs_cursor(cur_x, cur_y, 0);
2059 gui->unlock_window();
2061 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2063 gui->lock_window("MWindow::save_clip");
2067 void MWindow::to_clip(EDL *edl, const char *txt)
2072 gui->lock_window("MWindow::to_clip 1");
2073 start = edl->local_session->get_selectionstart();
2074 end = edl->local_session->get_selectionend();
2076 if( EQUIV(end, start) ) {
2078 end = edl->tracks->total_length();
2081 // Don't copy all since we don't want the clips twice.
2082 edl->copy(start, end, 0, 0, 0, &file, "", 1);
2084 EDL *new_edl = new EDL(edl);
2085 new_edl->create_objects();
2086 new_edl->load_xml(&file, LOAD_ALL);
2087 save_clip(new_edl, txt);
2088 gui->unlock_window();
2091 int MWindow::toggle_label(int is_mwindow)
2093 double position1, position2;
2094 undo->update_undo_before();
2096 if( cwindow->playback_engine->is_playing_back ) {
2097 position1 = position2 =
2098 cwindow->playback_engine->get_tracking_position();
2101 position1 = edl->local_session->get_selectionstart(1);
2102 position2 = edl->local_session->get_selectionend(1);
2105 position1 = edl->align_to_frame(position1, 0);
2106 position2 = edl->align_to_frame(position2, 0);
2108 //printf("MWindow::toggle_label 1\n");
2110 edl->labels->toggle_label(position1, position2);
2114 gui->lock_window("MWindow::toggle_label 1");
2116 gui->update_timebar(0);
2117 gui->activate_timeline();
2120 gui->unlock_window();
2124 cwindow->gui->lock_window("MWindow::toggle_label 2");
2126 cwindow->gui->timebar->update(1);
2128 cwindow->gui->unlock_window();
2131 awindow->gui->async_update_assets();
2133 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2137 void MWindow::trim_selection()
2139 undo->update_undo_before();
2142 edl->trim_selection(edl->local_session->get_selectionstart(),
2143 edl->local_session->get_selectionend(),
2144 edl->session->labels_follow_edits,
2145 edl->session->plugins_follow_edits,
2146 edl->session->autos_follow_edits);
2149 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2150 update_plugin_guis();
2151 gui->update(1, 2, 1, 1, 1, 1, 0);
2152 cwindow->update(1, 0, 0, 0, 1);
2153 awindow->gui->async_update_assets();
2155 cwindow->refresh_frame(CHANGE_EDL);
2159 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2161 calling_window_gui->unlock_window();
2164 cwindow->gui->lock_window("MWindow::undo_entry 1");
2165 for( int i = 0; i < vwindows.size(); i++ ) {
2166 if( vwindows.get(i)->is_running() ) {
2167 if( calling_window_gui != vwindows.get(i)->gui ) {
2168 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2172 gui->lock_window("MWindow::undo_entry 2");
2178 update_plugin_states();
2179 update_plugin_guis();
2181 gui->update(1, 2, 1, 1, 1, 1, 1);
2182 gui->unlock_window();
2183 cwindow->update(1, 1, 1, 1, 1);
2184 cwindow->gui->unlock_window();
2186 for( int i = 0; i < vwindows.size(); i++ ) {
2187 if( vwindows.get(i)->is_running() ) {
2188 if( calling_window_gui != vwindows.get(i)->gui ) {
2189 vwindows.get(i)->gui->unlock_window();
2194 if( calling_window_gui != gui )
2195 gui->unlock_window();
2197 awindow->gui->async_update_assets();
2199 cwindow->refresh_frame(CHANGE_ALL);
2200 calling_window_gui->lock_window("MWindow::undo_entry 4");
2204 void MWindow::new_folder(const char *new_folder)
2206 undo->update_undo_before();
2207 edl->new_folder(new_folder);
2208 undo->update_undo_after(_("new folder"), LOAD_ALL);
2209 awindow->gui->async_update_assets();
2212 void MWindow::delete_folder(char *folder)
2214 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2217 void MWindow::select_point(double position)
2219 edl->local_session->set_selectionstart(position);
2220 edl->local_session->set_selectionend(position);
2223 cwindow->update(1, 0, 0, 0, 1);
2225 update_plugin_guis();
2226 gui->update_patchbay();
2227 gui->hide_cursor(0);
2228 gui->draw_cursor(0);
2229 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2230 gui->zoombar->update();
2231 gui->update_timebar(0);
2232 gui->flash_canvas(0);
2239 void MWindow::map_audio(int pattern)
2241 undo->update_undo_before();
2242 remap_audio(pattern);
2243 undo->update_undo_after(
2244 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2246 sync_parameters(CHANGE_PARAMS);
2247 gui->update(0, 1, 0, 0, 1, 0, 0);
2250 void MWindow::remap_audio(int pattern)
2252 int current_channel = 0;
2253 int current_track = 0;
2254 for( Track *current = edl->tracks->first; current; current = NEXT ) {
2255 if( current->data_type == TRACK_AUDIO &&
2257 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2258 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2260 for( int i = 0; i < MAXCHANNELS; i++ ) {
2261 pan_auto->values[i] = 0.0;
2264 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2265 pan_auto->values[current_channel] = 1.0;
2268 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2269 switch( current_track ) {
2271 pan_auto->values[0] = 0.5;
2272 pan_auto->values[1] = 0.5;
2275 pan_auto->values[0] = 1;
2278 pan_auto->values[1] = 1;
2281 pan_auto->values[0] = 1;
2284 pan_auto->values[1] = 1;
2287 pan_auto->values[0] = 0.5;
2288 pan_auto->values[1] = 0.5;
2293 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2294 edl->session->achannel_positions, pan_auto->values,
2295 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2299 if( current_channel >= edl->session->audio_channels )
2300 current_channel = 0;
2305 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2306 ArrayList<Indexable*> *orig_assets,
2307 ArrayList<Indexable*> *proxy_assets)
2309 int orig_use_scaler = edl->session->proxy_use_scaler;
2310 int orig_scale = edl->session->proxy_scale;
2311 // rescale to full size asset in read_frame
2312 edl->session->proxy_use_scaler = use_scaler;
2313 edl->session->proxy_scale = new_scale;
2314 edl->session->proxy_auto_scale = auto_scale;
2317 for( int i=0; i<proxy_assets->size(); ++i ) {
2318 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2319 proxy_asset->width = orig_assets->get(i)->get_w();
2320 proxy_asset->height = orig_assets->get(i)->get_h();
2325 if( !orig_use_scaler && new_scale != orig_scale ) {
2327 float orig_w = (float)edl->session->output_w * orig_scale;
2328 float orig_h = (float)edl->session->output_h * orig_scale;
2329 edl->session->output_w = Units::round(orig_w / new_scale);
2330 edl->session->output_h = Units::round(orig_h / new_scale);
2333 for( Track *track=edl->tracks->first; track; track=track->next ) {
2334 if( track->data_type != TRACK_VIDEO ) continue;
2335 orig_w = (float)track->track_w * orig_scale;
2336 orig_h = (float)track->track_h * orig_scale;
2337 track->track_w = Units::round(orig_w / new_scale);
2338 track->track_h = Units::round(orig_h / new_scale);
2339 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2340 set_proxy(orig_scale, new_scale);
2341 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2342 set_proxy(orig_scale, new_scale);
2343 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2344 set_proxy(orig_scale, new_scale);
2345 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2346 set_proxy(orig_scale, new_scale);
2347 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2348 set_proxy(orig_scale, new_scale);
2352 // change original assets to proxy assets
2353 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2354 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2355 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2356 proxy_asset->awindow_folder = awindow_folder;
2357 // replace track contents
2358 for( Track *track = edl->tracks->first; track; track = track->next ) {
2359 if( track->data_type != TRACK_VIDEO ) continue;
2360 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2361 if( !edit->asset ) continue;
2362 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2363 edit->asset = proxy_asset;
2370 void MWindow::add_proxy(int use_scaler,
2371 ArrayList<Indexable*> *orig_assets,
2372 ArrayList<Indexable*> *proxy_assets)
2375 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2376 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2377 proxy_asset->width = orig_assets->get(i)->get_w();
2378 proxy_asset->height = orig_assets->get(i)->get_h();
2382 // change original assets to proxy assets
2383 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2384 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2385 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2386 // replace track contents
2387 for( Track *track = edl->tracks->first; track; track = track->next ) {
2388 if( track->data_type != TRACK_VIDEO ) continue;
2389 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2390 if( !edit->asset ) continue;
2391 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2392 edit->asset = proxy_asset;
2399 void MWindow::cut_commercials()
2401 undo->update_undo_before();
2402 commercials->scan_media();
2405 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2408 update_plugin_guis();
2409 gui->update(1, 2, 1, 1, 1, 1, 0);
2410 cwindow->update(1, 0, 0, 0, 1);
2411 cwindow->refresh_frame(CHANGE_EDL);