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::set_automation_mode(int mode)
330 undo->update_undo_before();
331 edl->tracks->set_automation_mode(
332 edl->local_session->get_selectionstart(),
333 edl->local_session->get_selectionend(),
336 char string[BCSTRLEN];
337 sprintf(string,"set %s", FloatAuto::curve_name(mode));
338 undo->update_undo_after(string, LOAD_AUTOMATION);
341 update_plugin_guis();
342 gui->draw_overlays(1);
343 sync_parameters(CHANGE_PARAMS);
344 gui->update_patchbay();
345 cwindow->update(1, 0, 0);
348 void MWindow::clear_automation()
350 undo->update_undo_before();
351 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
352 edl->local_session->get_selectionend());
354 undo->update_undo_after(_("clear keyframes"), LOAD_AUTOMATION);
357 update_plugin_guis();
358 gui->draw_overlays(1);
359 sync_parameters(CHANGE_PARAMS);
360 gui->update_patchbay();
361 cwindow->update(1, 0, 0);
364 int MWindow::clear_default_keyframe()
366 undo->update_undo_before();
367 edl->tracks->clear_default_keyframe();
369 undo->update_undo_after(_("clear default keyframe"), LOAD_AUTOMATION);
372 gui->draw_overlays(1);
373 sync_parameters(CHANGE_PARAMS);
374 gui->update_patchbay();
375 cwindow->update(1, 0, 0);
380 void MWindow::clear_labels()
382 undo->update_undo_before();
383 clear_labels(edl->local_session->get_selectionstart(),
384 edl->local_session->get_selectionend());
385 undo->update_undo_after(_("clear labels"), LOAD_TIMEBAR);
387 gui->update_timebar(1);
388 cwindow->update(0, 0, 0, 0, 1);
392 int MWindow::clear_labels(double start, double end)
394 edl->labels->clear(start, end, 0);
398 void MWindow::concatenate_tracks()
400 undo->update_undo_before();
401 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
402 edl->session->autos_follow_edits);
404 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
407 gui->update(1, 1, 0, 0, 1, 0, 0);
408 cwindow->refresh_frame(CHANGE_EDL);
414 copy(edl->local_session->get_selectionstart(),
415 edl->local_session->get_selectionend());
418 int MWindow::copy(double start, double end)
420 if( start == end ) return 1;
423 edl->copy(start, end, 0, &file, "", 1);
424 const char *file_string = file.string();
425 long file_length = strlen(file_string);
426 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
427 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
432 int MWindow::copy_automation()
435 double start = edl->local_session->get_selectionstart();
436 double end = edl->local_session->get_selectionend();
437 edl->tracks->copy_automation(start, end, &file, 0, 1);
438 const char *file_string = file.string();
439 long file_length = strlen(file_string);
440 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
441 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
445 int MWindow::copy_default_keyframe()
448 double start = edl->local_session->get_selectionstart();
449 double end = edl->local_session->get_selectionend();
450 edl->tracks->copy_automation(start, end, &file, 1, 0);
451 const char *file_string = file.string();
452 long file_length = strlen(file_string);
453 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
454 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
459 // Uses cropping coordinates in edl session to crop and translate video.
460 // We modify the projector since camera automation depends on the track size.
461 void MWindow::crop_video()
464 undo->update_undo_before();
465 // Clamp EDL crop region
466 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
467 edl->session->crop_x1 ^= edl->session->crop_x2;
468 edl->session->crop_x2 ^= edl->session->crop_x1;
469 edl->session->crop_x1 ^= edl->session->crop_x2;
471 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
472 edl->session->crop_y1 ^= edl->session->crop_y2;
473 edl->session->crop_y2 ^= edl->session->crop_y1;
474 edl->session->crop_y1 ^= edl->session->crop_y2;
477 float old_projector_x = (float)edl->session->output_w / 2;
478 float old_projector_y = (float)edl->session->output_h / 2;
479 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
480 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
481 float projector_offset_x = -(new_projector_x - old_projector_x);
482 float projector_offset_y = -(new_projector_y - old_projector_y);
484 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
486 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
487 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
488 edl->session->crop_x1 = 0;
489 edl->session->crop_y1 = 0;
490 edl->session->crop_x2 = edl->session->output_w;
491 edl->session->crop_y2 = edl->session->output_h;
493 // Recalculate aspect ratio
494 if( defaults->get("AUTOASPECT", 0) ) {
495 create_aspect_ratio(edl->session->aspect_w,
496 edl->session->aspect_h,
497 edl->session->output_w,
498 edl->session->output_h);
501 undo->update_undo_after(_("crop"), LOAD_ALL);
504 cwindow->refresh_frame(CHANGE_ALL);
510 double start = edl->local_session->get_selectionstart();
511 double end = edl->local_session->get_selectionend();
512 if( EQUIV(start,end) )
518 void MWindow::blade(double position)
520 undo->update_undo_before();
521 edl->blade(position);
524 undo->update_undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
526 update_plugin_guis();
527 gui->update(1, 2, 1, 1, 1, 1, 0);
528 cwindow->update(1, 0, 0, 0, 1);
529 awindow->gui->async_update_assets();
530 cwindow->refresh_frame(CHANGE_EDL);
533 void MWindow::cut(double start, double end, double new_position)
535 undo->update_undo_before();
537 edl->clear(start, end,
538 edl->session->labels_follow_edits,
539 edl->session->plugins_follow_edits,
540 edl->session->autos_follow_edits);
544 undo->update_undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
545 if( new_position >= 0 ) {
546 edl->local_session->set_selectionstart(new_position);
547 edl->local_session->set_selectionend(new_position);
550 update_plugin_guis();
551 gui->update(1, 2, 1, 1, 1, 1, 0);
552 cwindow->update(1, 0, 0, 0, 1);
553 awindow->gui->async_update_assets();
554 cwindow->refresh_frame(CHANGE_EDL);
557 void MWindow::cut_left_edit()
559 double start_pos = edl->local_session->get_selectionstart(1);
560 double position = edl->prev_edit(start_pos);
561 if( position < start_pos )
562 cut(position, start_pos, position);
565 void MWindow::cut_right_edit()
567 double end_pos = edl->local_session->get_selectionend(1);
568 double position = edl->next_edit(end_pos);
569 if( end_pos < position )
570 cut(end_pos, position, end_pos);
573 void MWindow::cut_left_label()
575 double start_pos = edl->local_session->get_selectionstart(1);
576 Label *left_label = edl->labels->prev_label(start_pos);
577 if( !left_label ) return;
578 double position = left_label->position;
579 if( position < start_pos )
580 cut(position, start_pos, position);
583 void MWindow::cut_right_label()
585 double end_pos = edl->local_session->get_selectionend(1);
586 Label *right_label = edl->labels->next_label(end_pos);
587 if( !right_label ) return;
588 double position = right_label->position;
589 if( end_pos < position )
590 cut(end_pos, position, end_pos);
593 int MWindow::cut_automation()
595 undo->update_undo_before();
599 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
600 edl->local_session->get_selectionend());
602 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
606 update_plugin_guis();
607 gui->draw_overlays(1);
608 sync_parameters(CHANGE_PARAMS);
609 gui->update_patchbay();
610 cwindow->update(1, 0, 0);
614 int MWindow::cut_default_keyframe()
617 undo->update_undo_before();
618 copy_default_keyframe();
619 edl->tracks->clear_default_keyframe();
620 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
623 gui->draw_overlays(1);
624 sync_parameters(CHANGE_PARAMS);
625 gui->update_patchbay();
626 cwindow->update(1, 0, 0);
634 void MWindow::delete_track()
636 if( edl->tracks->last )
637 delete_track(edl->tracks->last);
640 void MWindow::delete_tracks()
642 undo->update_undo_before();
643 edl->tracks->delete_tracks();
644 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
648 update_plugin_states();
650 gui->update(1, 1, 1, 0, 1, 0, 0);
651 cwindow->refresh_frame(CHANGE_EDL);
654 void MWindow::delete_track(Track *track)
656 undo->update_undo_before();
657 edl->tracks->delete_track(track);
658 undo->update_undo_after(_("delete track"), LOAD_ALL);
661 update_plugin_states();
663 gui->update(1, 1, 1, 0, 1, 0, 0);
664 cwindow->refresh_frame(CHANGE_EDL);
669 // Insert data from clipboard
670 void MWindow::insert(double position, FileXML *file,
671 int edit_labels, int edit_plugins, int edit_autos,
674 // For clipboard pasting make the new edl use a separate session
675 // from the master EDL. Then it can be resampled to the master rates.
676 // For splice, overwrite, and dragging need same session to get the assets.
677 EDL *edl = new EDL(parent_edl);
678 ArrayList<EDL*> new_edls;
679 uint32_t load_flags = LOAD_ALL;
682 new_edls.append(edl);
683 edl->create_objects();
688 if( parent_edl ) load_flags &= ~LOAD_SESSION;
689 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
690 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
692 edl->load_xml(file, load_flags);
695 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
699 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
700 edit_labels, edit_plugins, edit_autos, 0); // overwrite
701 // if( vwindow->edl )
702 // printf("MWindow::insert 5 %f %f\n",
703 // vwindow->edl->local_session->in_point,
704 // vwindow->edl->local_session->out_point);
705 new_edls.remove_all();
706 edl->Garbage::remove_user();
707 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
710 void MWindow::insert_effects_canvas(double start,
713 Track *dest_track = session->track_highlighted;
714 if( !dest_track ) return;
716 undo->update_undo_before();
718 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
719 PluginServer *plugin = session->drag_pluginservers->values[i];
720 insert_effect(plugin->title, 0, dest_track,
721 i == 0 ? session->pluginset_highlighted : 0,
722 start, length, PLUGIN_STANDALONE);
726 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
728 sync_parameters(CHANGE_EDL);
729 // GUI updated in TrackCanvas, after current_operations are reset
732 void MWindow::insert_effects_cwindow(Track *dest_track)
734 if( !dest_track ) return;
736 undo->update_undo_before();
739 double length = dest_track->get_length();
741 if( edl->local_session->get_selectionend() >
742 edl->local_session->get_selectionstart() ) {
743 start = edl->local_session->get_selectionstart();
744 length = edl->local_session->get_selectionend() -
745 edl->local_session->get_selectionstart();
748 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
749 PluginServer *plugin = session->drag_pluginservers->values[i];
750 insert_effect(plugin->title, 0, dest_track, 0,
751 start, length, PLUGIN_STANDALONE);
755 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
757 sync_parameters(CHANGE_EDL);
758 gui->update(1, 1, 0, 0, 1, 0, 0);
761 void MWindow::insert_effect(char *title,
762 SharedLocation *shared_location,
765 int single_standalone)
767 Track *current = edl->tracks->first;
768 SharedLocation shared_location_local;
769 shared_location_local.copy_from(shared_location);
771 for( ; current; current=NEXT ) {
772 if( current->data_type == data_type &&
774 insert_effect(title, &shared_location_local,
775 current, 0, 0, 0, plugin_type);
778 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
779 plugin_type = PLUGIN_SHAREDPLUGIN;
780 shared_location_local.module = edl->tracks->number_of(current);
781 shared_location_local.plugin = current->plugin_set.total - 1;
790 void MWindow::insert_effect(char *title,
791 SharedLocation *shared_location,
793 PluginSet *plugin_set,
798 KeyFrame *default_keyframe = 0;
799 PluginServer *server = 0;
800 // Get default keyframe
801 if( plugin_type == PLUGIN_STANDALONE ) {
802 default_keyframe = new KeyFrame;
803 server = new PluginServer(*scan_plugindb(title, track->data_type));
805 server->open_plugin(0, preferences, edl, 0);
806 server->save_data(default_keyframe);
808 // Insert plugin object
809 track->insert_effect(title, shared_location,
810 default_keyframe, plugin_set,
811 start, length, plugin_type);
814 if( plugin_type == PLUGIN_STANDALONE ) {
815 server->close_plugin();
817 delete default_keyframe;
821 int MWindow::modify_edithandles()
823 undo->update_undo_before();
824 edl->modify_edithandles(session->drag_start,
825 session->drag_position,
826 session->drag_handle,
827 edl->session->edit_handle_mode[session->drag_button],
828 edl->session->labels_follow_edits,
829 edl->session->plugins_follow_edits,
830 edl->session->autos_follow_edits);
832 finish_modify_handles();
833 //printf("MWindow::modify_handles 1\n");
837 int MWindow::modify_pluginhandles()
839 undo->update_undo_before();
841 edl->modify_pluginhandles(session->drag_start,
842 session->drag_position,
843 session->drag_handle,
844 edl->session->edit_handle_mode[session->drag_button],
845 edl->session->labels_follow_edits,
846 edl->session->autos_follow_edits,
847 session->trim_edits);
849 finish_modify_handles();
855 // Common to edithandles and plugin handles
856 void MWindow::finish_modify_handles()
858 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
860 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
861 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
862 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
863 edl->local_session->set_selectionstart(session->drag_position);
864 edl->local_session->set_selectionend(session->drag_position);
867 if( edit_mode != MOVE_NO_EDITS ) {
868 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
869 edl->local_session->set_selectionstart(session->drag_start);
870 edl->local_session->set_selectionend(session->drag_start);
873 // clamp the selection to 0
874 if( edl->local_session->get_selectionstart(1) < 0 ) {
875 edl->local_session->set_selectionstart(0);
876 edl->local_session->set_selectionend(0);
878 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
882 sync_parameters(CHANGE_EDL);
883 update_plugin_guis();
884 gui->update(1, 2, 1, 1, 1, 1, 0);
885 // label list can be modified
886 awindow->gui->async_update_assets();
887 cwindow->update(1, 0, 0, 0, 1);
890 void MWindow::match_output_size(Track *track)
892 undo->update_undo_before();
893 track->track_w = edl->session->output_w;
894 track->track_h = edl->session->output_h;
896 undo->update_undo_after(_("match output size"), LOAD_ALL);
899 sync_parameters(CHANGE_EDL);
903 void MWindow::move_edits(ArrayList<Edit*> *edits,
908 undo->update_undo_before();
910 edl->tracks->move_edits(edits,
913 edl->session->labels_follow_edits,
914 edl->session->plugins_follow_edits,
915 edl->session->autos_follow_edits,
919 undo->update_undo_after(_("move edit"), LOAD_ALL);
922 cwindow->refresh_frame(CHANGE_EDL);
924 update_plugin_guis();
925 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
929 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
931 undo->update_undo_before();
932 edl->tracks->move_effect(plugin, track, position);
934 undo->update_undo_after(_("paste effect"), LOAD_ALL);
937 cwindow->refresh_frame(CHANGE_EDL);
938 update_plugin_guis();
939 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
943 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
945 undo->update_undo_before();
946 edl->tracks->move_effect(plugin, plugin_set, position);
948 undo->update_undo_after(_("move effect"), LOAD_ALL);
951 cwindow->refresh_frame(CHANGE_EDL);
952 update_plugin_guis();
953 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
957 void MWindow::move_plugins_up(PluginSet *plugin_set)
960 undo->update_undo_before();
961 plugin_set->track->move_plugins_up(plugin_set);
964 undo->update_undo_after(_("move effect up"), LOAD_ALL);
966 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
968 sync_parameters(CHANGE_EDL);
971 void MWindow::move_plugins_down(PluginSet *plugin_set)
973 undo->update_undo_before();
975 plugin_set->track->move_plugins_down(plugin_set);
978 undo->update_undo_after(_("move effect down"), LOAD_ALL);
980 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
982 sync_parameters(CHANGE_EDL);
985 void MWindow::move_track_down(Track *track)
987 undo->update_undo_before();
988 edl->tracks->move_track_down(track);
990 undo->update_undo_after(_("move track down"), LOAD_ALL);
993 gui->update(1, 1, 0, 0, 1, 0, 0);
994 sync_parameters(CHANGE_EDL);
998 void MWindow::move_tracks_down()
1000 undo->update_undo_before();
1001 edl->tracks->move_tracks_down();
1003 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1006 gui->update(1, 1, 0, 0, 1, 0, 0);
1007 sync_parameters(CHANGE_EDL);
1011 void MWindow::move_track_up(Track *track)
1013 undo->update_undo_before();
1014 edl->tracks->move_track_up(track);
1016 undo->update_undo_after(_("move track up"), LOAD_ALL);
1018 gui->update(1, 1, 0, 0, 1, 0, 0);
1019 sync_parameters(CHANGE_EDL);
1023 void MWindow::move_tracks_up()
1025 undo->update_undo_before();
1026 edl->tracks->move_tracks_up();
1028 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1030 gui->update(1, 1, 0, 0, 1, 0, 0);
1031 sync_parameters(CHANGE_EDL);
1035 void MWindow::mute_selection()
1037 double start = edl->local_session->get_selectionstart();
1038 double end = edl->local_session->get_selectionend();
1039 if( start != end ) {
1040 undo->update_undo_before();
1041 edl->clear(start, end, 0,
1042 edl->session->plugins_follow_edits,
1043 edl->session->autos_follow_edits);
1044 edl->local_session->set_selectionend(end);
1045 edl->local_session->set_selectionstart(start);
1046 edl->paste_silence(start, end, 0,
1047 edl->session->plugins_follow_edits,
1048 edl->session->autos_follow_edits);
1051 undo->update_undo_after(_("mute"), LOAD_EDITS);
1054 update_plugin_guis();
1055 gui->update(1, 2, 1, 1, 1, 1, 0);
1056 cwindow->refresh_frame(CHANGE_EDL);
1061 void MWindow::overwrite(EDL *source)
1065 double src_start = source->local_session->get_selectionstart();
1066 double overwrite_len = source->local_session->get_selectionend() - src_start;
1067 double dst_start = edl->local_session->get_selectionstart();
1068 double dst_len = edl->local_session->get_selectionend() - dst_start;
1070 undo->update_undo_before();
1071 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1072 // in/out points or selection present and shorter than overwrite range
1073 // shorten the copy range
1074 overwrite_len = dst_len;
1077 source->copy(src_start, src_start + overwrite_len, 0, &file, "", 1);
1079 // HACK around paste_edl get_start/endselection on its own
1080 // so we need to clear only when not using both io points
1081 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1082 if( edl->local_session->get_inpoint() < 0 ||
1083 edl->local_session->get_outpoint() < 0 )
1084 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1086 paste(dst_start, dst_start + overwrite_len,
1089 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1090 edl->local_session->set_selectionend(dst_start + overwrite_len);
1093 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1096 update_plugin_guis();
1097 gui->update(1, 1, 1, 1, 0, 1, 0);
1098 sync_parameters(CHANGE_EDL);
1101 // For splice and overwrite
1102 int MWindow::paste(double start,
1111 // Want to insert with assets shared with the master EDL.
1113 edit_labels, edit_plugins, edit_autos,
1119 // For editing using insertion point
1120 void MWindow::paste()
1122 double start = edl->local_session->get_selectionstart();
1123 //double end = edl->local_session->get_selectionend();
1124 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1127 char *string = new char[len];
1128 undo->update_undo_before();
1129 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1131 file.read_from_string(string);
1134 insert(start, &file,
1135 edl->session->labels_follow_edits,
1136 edl->session->plugins_follow_edits,
1137 edl->session->autos_follow_edits,
1145 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1147 update_plugin_guis();
1148 gui->update(1, 2, 1, 1, 0, 1, 0);
1149 awindow->gui->async_update_assets();
1150 sync_parameters(CHANGE_EDL);
1155 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1158 undo->update_undo_before();
1160 if( session->drag_assets->total ) {
1161 load_assets(session->drag_assets,
1162 position, LOADMODE_PASTE, dest_track, 0,
1163 edl->session->labels_follow_edits,
1164 edl->session->plugins_follow_edits,
1165 edl->session->autos_follow_edits,
1170 if( session->drag_clips->total ) {
1171 paste_edls(session->drag_clips,
1172 LOADMODE_PASTE, dest_track, position,
1173 edl->session->labels_follow_edits,
1174 edl->session->plugins_follow_edits,
1175 edl->session->autos_follow_edits,
1182 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1184 gui->update(1, 2, 1, 0, 0, 1, 0);
1185 sync_parameters(CHANGE_EDL);
1189 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1190 double position, int load_mode, Track *first_track, RecordLabels *labels,
1191 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1193 if( load_mode == LOADMODE_RESOURCESONLY )
1194 load_mode = LOADMODE_ASSETSONLY;
1195 const int debug = 0;
1196 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1197 if( position < 0 ) position = edl->local_session->get_selectionstart();
1199 ArrayList<EDL*> new_edls;
1200 for( int i=0; i<new_assets->total; ++i ) {
1201 Indexable *indexable = new_assets->get(i);
1202 if( indexable->is_asset ) {
1203 remove_asset_from_caches((Asset*)indexable);
1205 EDL *new_edl = new EDL;
1206 new_edl->create_objects();
1207 new_edl->copy_session(edl);
1208 new_edls.append(new_edl);
1210 if( !indexable->is_asset ) {
1211 EDL *nested_edl = (EDL*)indexable;
1212 new_edl->to_nested(nested_edl);
1213 new_edl->local_session->set_clip_path(nested_edl);
1216 Asset *asset = (Asset*)indexable;
1217 asset_to_edl(new_edl, asset);
1221 for( RecordLabel *label=labels->first; label; label=label->next ) {
1222 new_edl->labels->toggle_label(label->position, label->position);
1226 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1228 paste_edls(&new_edls, load_mode, first_track, position,
1229 edit_labels, edit_plugins, edit_autos, overwrite);
1230 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1233 for( int i=0; i<new_edls.size(); ++i )
1234 new_edls.get(i)->Garbage::remove_user();
1236 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1239 int MWindow::paste_automation()
1241 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1244 undo->update_undo_before();
1245 char *string = new char[len];
1246 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1248 file.read_from_string(string);
1250 double start = edl->local_session->get_selectionstart();
1251 double end = edl->local_session->get_selectionend();
1252 edl->tracks->clear_automation(start, end);
1253 edl->tracks->paste_automation(start, &file, 0, 1,
1254 edl->session->typeless_keyframes);
1256 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1260 update_plugin_guis();
1261 gui->draw_overlays(1);
1262 sync_parameters(CHANGE_PARAMS);
1263 gui->update_patchbay();
1264 cwindow->update(1, 0, 0);
1270 int MWindow::paste_default_keyframe()
1272 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1275 undo->update_undo_before();
1276 char *string = new char[len];
1277 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1279 file.read_from_string(string);
1280 double start = edl->local_session->get_selectionstart();
1281 edl->tracks->paste_automation(start, &file, 1, 0,
1282 edl->session->typeless_keyframes);
1283 // edl->tracks->paste_default_keyframe(&file);
1284 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1287 update_plugin_guis();
1288 gui->draw_overlays(1);
1289 sync_parameters(CHANGE_PARAMS);
1290 gui->update_patchbay();
1291 cwindow->update(1, 0, 0);
1300 // Insert edls with project deletion and index file generation.
1301 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1302 Track *first_track, double current_position,
1303 int edit_labels, int edit_plugins, int edit_autos,
1307 ArrayList<Track*> destination_tracks;
1308 int need_new_tracks = 0;
1311 if( !new_edls->total ) return 0;
1314 // double original_length = edl->tracks->total_length();
1315 // double original_preview_end = edl->local_session->preview_end;
1318 // Delete current project
1319 if( load_mode == LOADMODE_REPLACE ||
1320 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1322 edl->save_defaults(defaults);
1324 edl->Garbage::remove_user();
1326 edl->create_objects();
1327 edl->copy_session(new_edls->values[0]);
1328 edl->copy_mixers(new_edls->values[0]);
1329 gui->mainmenu->update_toggles(0);
1330 gui->unlock_window();
1331 gwindow->gui->update_toggles(1);
1332 gui->lock_window("MWindow::paste_edls");
1334 // Insert labels for certain modes constitutively
1338 // Force reset of preview
1339 // original_length = 0;
1340 // original_preview_end = -1;
1346 // Create new tracks in master EDL
1347 if( load_mode == LOADMODE_REPLACE ||
1348 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1349 load_mode == LOADMODE_NEW_TRACKS ) {
1351 need_new_tracks = 1;
1352 for( int i=0; i<new_edls->total; ++i ) {
1353 EDL *new_edl = new_edls->values[i];
1354 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1355 switch( current->data_type ) {
1357 edl->tracks->add_video_track(0, 0);
1358 if( current->draw ) edl->tracks->last->draw = 1;
1361 edl->tracks->add_audio_track(0, 0);
1363 case TRACK_SUBTITLE:
1364 edl->tracks->add_subttl_track(0, 0);
1369 destination_tracks.append(edl->tracks->last);
1372 // Base track count on first EDL only for concatenation
1373 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1375 edl->session->highlighted_track = edl->tracks->total() - 1;
1378 // Recycle existing tracks of master EDL
1379 if( load_mode == LOADMODE_CONCATENATE ||
1380 load_mode == LOADMODE_PASTE ||
1381 load_mode == LOADMODE_NESTED ) {
1384 // The point of this is to shift forward labels after the selection so they can
1385 // then be shifted back to their original locations without recursively
1386 // shifting back every paste.
1387 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1388 edl->session->labels_follow_edits )
1389 edl->labels->clear(edl->local_session->get_selectionstart(),
1390 edl->local_session->get_selectionend(), 1);
1392 Track *current = first_track ? first_track : edl->tracks->first;
1393 for( ; current; current=NEXT ) {
1394 if( current->record ) {
1395 destination_tracks.append(current);
1402 int destination_track = 0;
1403 double *paste_position = new double[destination_tracks.total];
1405 // Iterate through the edls
1406 for( int i=0; i<new_edls->total; ++i ) {
1408 EDL *new_edl = new_edls->values[i];
1409 double edl_length = new_edl->local_session->clipboard_length ?
1410 new_edl->local_session->clipboard_length :
1411 new_edl->tracks->total_length();
1412 // printf("MWindow::paste_edls 2 %f %f\n",
1413 // new_edl->local_session->clipboard_length,
1414 // new_edl->tracks->total_length());
1418 // Convert EDL to master rates
1419 new_edl->resample(new_edl->session->sample_rate,
1420 edl->session->sample_rate,
1422 new_edl->resample(new_edl->session->frame_rate,
1423 edl->session->frame_rate,
1426 // Add assets and prepare index files
1427 for( Asset *new_asset=new_edl->assets->first;
1428 new_asset; new_asset=new_asset->next ) {
1429 mainindexes->add_next_asset(0, new_asset);
1431 // Capture index file status from mainindex test
1432 edl->update_assets(new_edl);
1434 // Get starting point of insertion. Need this to paste labels.
1435 switch( load_mode ) {
1436 case LOADMODE_REPLACE:
1437 case LOADMODE_NEW_TRACKS:
1438 current_position = 0;
1441 case LOADMODE_CONCATENATE:
1442 case LOADMODE_REPLACE_CONCATENATE:
1443 destination_track = 0;
1444 if( destination_tracks.total )
1445 current_position = destination_tracks.values[0]->get_length();
1447 current_position = 0;
1450 case LOADMODE_PASTE:
1451 case LOADMODE_NESTED:
1452 destination_track = 0;
1454 for( int j=0; j<destination_tracks.total; ++j ) {
1455 paste_position[j] = (current_position >= 0) ?
1457 edl->local_session->get_selectionstart();
1462 case LOADMODE_RESOURCESONLY:
1463 edl->add_clip(new_edl);
1468 if( load_mode != LOADMODE_RESOURCESONLY &&
1469 load_mode != LOADMODE_ASSETSONLY ) {
1471 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1472 if( load_mode == LOADMODE_PASTE ||
1473 load_mode == LOADMODE_NESTED )
1474 edl->labels->insert_labels(new_edl->labels,
1475 destination_tracks.total ? paste_position[0] : 0.0,
1479 edl->labels->insert_labels(new_edl->labels,
1485 for( Track *new_track=new_edl->tracks->first;
1486 new_track; new_track=new_track->next ) {
1487 // Get destination track of same type as new_track
1489 k < destination_tracks.total &&
1490 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1491 ++k, ++destination_track ) {
1492 if( destination_track >= destination_tracks.total - 1 )
1493 destination_track = 0;
1496 // Insert data into destination track
1497 if( destination_track < destination_tracks.total &&
1498 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1499 Track *track = destination_tracks.values[destination_track];
1501 // Replace default keyframes if first EDL and new tracks were created.
1502 // This means data copied from one track and pasted to another won't retain
1503 // the camera position unless it's a keyframe. If it did, previous data in the
1504 // track might get unknowingly corrupted. Ideally we would detect when differing
1505 // default keyframes existed and create discrete keyframes for both.
1506 int replace_default = (i == 0) && need_new_tracks;
1508 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1509 // Insert new track at current position
1510 switch( load_mode ) {
1511 case LOADMODE_REPLACE_CONCATENATE:
1512 case LOADMODE_CONCATENATE:
1513 current_position = track->get_length();
1516 case LOADMODE_PASTE:
1517 case LOADMODE_NESTED:
1518 current_position = paste_position[destination_track];
1519 paste_position[destination_track] += new_track->get_length();
1523 track->clear(current_position,
1524 current_position + new_track->get_length(),
1526 edit_labels, edit_plugins, edit_autos,
1531 track->insert_track(new_track, current_position, replace_default,
1532 edit_plugins, edit_autos, edl_length);
1536 // Get next destination track
1537 destination_track++;
1538 if( destination_track >= destination_tracks.total )
1539 destination_track = 0;
1543 if( load_mode == LOADMODE_PASTE ||
1544 load_mode == LOADMODE_NESTED )
1545 current_position += edl_length;
1549 // Move loading of clips and vwindow to the end - this fixes some
1550 // strange issue, for index not being shown
1551 // Assume any paste operation from the same EDL won't contain any clips.
1552 // If it did it would duplicate every clip here.
1553 for( int i=0; i<new_edls->total; ++i ) {
1554 EDL *new_edl = new_edls->get(i);
1556 for( int j=0; j<new_edl->clips.size(); ++j ) {
1557 edl->add_clip(new_edl->clips[j]);
1559 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1560 edl->nested_edls.get_copy(new_edl->nested_edls[j]);
1563 if( new_edl->total_vwindow_edls() ) {
1564 // if( edl->vwindow_edl )
1565 // edl->vwindow_edl->Garbage::remove_user();
1566 // edl->vwindow_edl = new EDL(edl);
1567 // edl->vwindow_edl->create_objects();
1568 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1570 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1571 EDL *vwindow_edl = new EDL(edl);
1572 vwindow_edl->create_objects();
1573 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1574 edl->append_vwindow_edl(vwindow_edl, 0);
1579 if( paste_position ) delete [] paste_position;
1581 // This is already done in load_filenames and everything else that uses paste_edls
1582 // update_project(load_mode);
1584 // Fix preview range
1585 // if( EQUIV(original_length, original_preview_end) )
1587 // edl->local_session->preview_end = edl->tracks->total_length();
1590 // Start examining next batch of index files
1591 mainindexes->start_build();
1593 // Don't save a backup after loading since the loaded file is on disk already.
1598 void MWindow::paste_silence()
1600 double start = edl->local_session->get_selectionstart();
1601 double end = edl->local_session->get_selectionend();
1602 undo->update_undo_before();
1603 edl->paste_silence(start, end,
1604 edl->session->labels_follow_edits,
1605 edl->session->plugins_follow_edits,
1606 edl->session->autos_follow_edits);
1609 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1611 update_plugin_guis();
1613 gui->update(1, 2, 1, 1, 1, 1, 0);
1614 cwindow->update(1, 0, 0, 0, 1);
1615 cwindow->refresh_frame(CHANGE_EDL);
1618 void MWindow::detach_transition(Transition *transition)
1620 undo->update_undo_before();
1621 hide_plugin(transition, 1);
1622 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1623 transition->edit->detach_transition();
1625 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1627 if( is_video ) restart_brender();
1628 gui->update(0, 1, 0, 0, 0, 0, 0);
1629 sync_parameters(CHANGE_EDL);
1632 void MWindow::detach_transitions()
1634 gui->lock_window("MWindow::detach_transitions 1");
1636 undo->update_undo_before();
1637 double start = edl->local_session->get_selectionstart();
1638 double end = edl->local_session->get_selectionend();
1639 edl->tracks->clear_transitions(start, end);
1642 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1644 sync_parameters(CHANGE_EDL);
1645 gui->update(0, 1, 0, 0, 0, 0, 0);
1646 gui->unlock_window();
1649 void MWindow::paste_transition()
1651 // Only the first transition gets dropped.
1652 PluginServer *server = session->drag_pluginservers->values[0];
1654 undo->update_undo_before();
1656 strcpy(edl->session->default_atransition, server->title);
1658 strcpy(edl->session->default_vtransition, server->title);
1660 edl->tracks->paste_transition(server, session->edit_highlighted);
1662 undo->update_undo_after(_("transition"), LOAD_EDITS);
1664 if( server->video ) restart_brender();
1665 sync_parameters(CHANGE_ALL);
1668 void MWindow::paste_transitions(int track_type, char *title)
1670 gui->lock_window("MWindow::detach_transitions 1");
1672 undo->update_undo_before();
1673 double start = edl->local_session->get_selectionstart();
1674 double end = edl->local_session->get_selectionend();
1675 edl->tracks->paste_transitions(start, end, track_type, title);
1678 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1680 sync_parameters(CHANGE_EDL);
1681 gui->update(0, 1, 0, 0, 0, 0, 0);
1682 gui->unlock_window();
1685 void MWindow::paste_transition_cwindow(Track *dest_track)
1687 PluginServer *server = session->drag_pluginservers->values[0];
1688 undo->update_undo_before();
1689 edl->tracks->paste_video_transition(server, 1);
1691 undo->update_undo_after(_("transition"), LOAD_EDITS);
1693 gui->update(0, 1, 0, 0, 0, 0, 0);
1694 sync_parameters(CHANGE_ALL);
1697 void MWindow::paste_audio_transition()
1699 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1702 char string[BCTEXTLEN];
1703 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1704 gui->show_message(string);
1708 undo->update_undo_before();
1709 edl->tracks->paste_audio_transition(server);
1711 undo->update_undo_after(_("transition"), LOAD_EDITS);
1713 sync_parameters(CHANGE_EDL);
1714 gui->update(0, 1, 0, 0, 0, 0, 0);
1717 void MWindow::paste_video_transition()
1719 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1722 char string[BCTEXTLEN];
1723 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1724 gui->show_message(string);
1728 undo->update_undo_before();
1730 edl->tracks->paste_video_transition(server);
1732 undo->update_undo_after(_("transition"), LOAD_EDITS);
1734 sync_parameters(CHANGE_EDL);
1736 gui->update(0, 1, 0, 0, 0, 0, 0);
1739 void MWindow::shuffle_edits()
1741 gui->lock_window("MWindow::shuffle_edits 1");
1743 undo->update_undo_before();
1744 double start = edl->local_session->get_selectionstart();
1745 double end = edl->local_session->get_selectionend();
1747 edl->tracks->shuffle_edits(start, end);
1750 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1752 sync_parameters(CHANGE_EDL);
1754 gui->update(0, 1, 1, 0, 0, 0, 0);
1755 gui->unlock_window();
1758 void MWindow::reverse_edits()
1760 gui->lock_window("MWindow::reverse_edits 1");
1762 undo->update_undo_before();
1763 double start = edl->local_session->get_selectionstart();
1764 double end = edl->local_session->get_selectionend();
1766 edl->tracks->reverse_edits(start, end);
1769 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1771 sync_parameters(CHANGE_EDL);
1773 gui->update(0, 1, 1, 0, 0, 0, 0);
1774 gui->unlock_window();
1777 void MWindow::align_edits()
1779 gui->lock_window("MWindow::align_edits 1");
1781 undo->update_undo_before();
1782 double start = edl->local_session->get_selectionstart();
1783 double end = edl->local_session->get_selectionend();
1785 edl->tracks->align_edits(start, end);
1788 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1790 sync_parameters(CHANGE_EDL);
1792 gui->update(0, 1, 1, 0, 0, 0, 0);
1793 gui->unlock_window();
1796 void MWindow::set_edit_length(double length)
1798 gui->lock_window("MWindow::detach_transitions 1");
1800 undo->update_undo_before();
1801 double start = edl->local_session->get_selectionstart();
1802 double end = edl->local_session->get_selectionend();
1804 edl->tracks->set_edit_length(start, end, length);
1807 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1809 sync_parameters(CHANGE_EDL);
1811 gui->update(0, 1, 1, 0, 0, 0, 0);
1812 gui->unlock_window();
1816 void MWindow::set_transition_length(Transition *transition, double length)
1818 gui->lock_window("MWindow::detach_transitions 1");
1820 undo->update_undo_before();
1821 //double start = edl->local_session->get_selectionstart();
1822 //double end = edl->local_session->get_selectionend();
1824 edl->tracks->set_transition_length(transition, length);
1827 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1829 edl->session->default_transition_length = length;
1830 sync_parameters(CHANGE_PARAMS);
1831 gui->update(0, 1, 0, 0, 0, 0, 0);
1832 gui->unlock_window();
1835 void MWindow::set_transition_length(double length)
1837 gui->lock_window("MWindow::detach_transitions 1");
1839 undo->update_undo_before();
1840 double start = edl->local_session->get_selectionstart();
1841 double end = edl->local_session->get_selectionend();
1843 edl->tracks->set_transition_length(start, end, length);
1846 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1848 edl->session->default_transition_length = length;
1849 sync_parameters(CHANGE_PARAMS);
1851 gui->update(0, 1, 0, 0, 0, 0, 0);
1852 gui->unlock_window();
1856 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1858 calling_window_gui->unlock_window();
1860 if( undo->redo_load_flags() & LOAD_SESSION )
1863 cwindow->gui->lock_window("MWindow::redo_entry 1");
1864 for( int i=0; i<vwindows.size(); ++i ) {
1865 if( vwindows.get(i)->is_running() ) {
1866 if( calling_window_gui != vwindows.get(i)->gui ) {
1867 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1871 gui->lock_window("MWindow::redo_entry 3");
1877 update_plugin_states();
1878 update_plugin_guis();
1880 gui->update(1, 2, 1, 1, 1, 1, 1);
1881 gui->unlock_window();
1882 cwindow->update(1, 1, 1, 1, 1);
1883 cwindow->gui->unlock_window();
1885 for( int i=0; i < vwindows.size(); ++i ) {
1886 if( vwindows.get(i)->is_running() ) {
1887 if( calling_window_gui != vwindows.get(i)->gui ) {
1888 vwindows.get(i)->gui->unlock_window();
1893 if( calling_window_gui != gui )
1894 gui->unlock_window();
1896 awindow->gui->async_update_assets();
1898 cwindow->refresh_frame(CHANGE_ALL);
1899 calling_window_gui->lock_window("MWindow::redo_entry 4");
1903 void MWindow::resize_track(Track *track, int w, int h)
1905 undo->update_undo_before();
1906 // We have to move all maskpoints so they do not move in relation to image areas
1907 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1908 (w - track->track_w) / 2,
1909 (h - track->track_h) / 2);
1912 undo->update_undo_after(_("resize track"), LOAD_ALL);
1916 sync_parameters(CHANGE_EDL);
1920 void MWindow::set_inpoint(int is_mwindow)
1922 undo->update_undo_before();
1923 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1925 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1928 gui->lock_window("MWindow::set_inpoint 1");
1930 gui->update_timebar(1);
1932 gui->unlock_window();
1936 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1938 cwindow->gui->timebar->update(1);
1940 cwindow->gui->unlock_window();
1944 void MWindow::set_outpoint(int is_mwindow)
1946 undo->update_undo_before();
1947 edl->set_outpoint(edl->local_session->get_selectionend(1));
1949 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1952 gui->lock_window("MWindow::set_outpoint 1");
1954 gui->update_timebar(1);
1956 gui->unlock_window();
1960 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1962 cwindow->gui->timebar->update(1);
1964 cwindow->gui->unlock_window();
1968 void MWindow::unset_inoutpoint(int is_mwindow)
1970 undo->update_undo_before();
1971 edl->unset_inoutpoint();
1973 undo->update_undo_after(_("clear in/out"), LOAD_TIMEBAR);
1976 gui->lock_window("MWindow::unset_inoutpoint 1");
1978 gui->update_timebar(1);
1980 gui->unlock_window();
1984 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
1986 cwindow->gui->timebar->update(1);
1988 cwindow->gui->unlock_window();
1992 void MWindow::splice(EDL *source)
1996 undo->update_undo_before();
1997 double source_start = source->local_session->get_selectionstart();
1998 double source_end = source->local_session->get_selectionend();
1999 source->copy(source_start, source_end, 1, &file, "", 1);
2001 double start = edl->local_session->get_selectionstart();
2002 //double end = edl->local_session->get_selectionend();
2004 paste(start, start, &file,
2005 edl->session->labels_follow_edits,
2006 edl->session->plugins_follow_edits,
2007 edl->session->autos_follow_edits);
2009 // Position at end of clip
2010 edl->local_session->set_selectionstart(start + source_end - source_start);
2011 edl->local_session->set_selectionend(start + source_end - source_start);
2014 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2015 update_plugin_guis();
2017 gui->update(1, 1, 1, 1, 0, 1, 0);
2018 sync_parameters(CHANGE_EDL);
2021 void MWindow::save_clip(EDL *new_edl, const char *txt)
2023 new_edl->local_session->set_selectionstart(0);
2024 new_edl->local_session->set_selectionend(0);
2025 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2026 session->clip_number++);
2027 char duration[BCTEXTLEN];
2028 Units::totext(duration, new_edl->tracks->total_length(),
2029 new_edl->session->time_format,
2030 new_edl->session->sample_rate,
2031 new_edl->session->frame_rate,
2032 new_edl->session->frames_per_foot);
2034 Track *track = new_edl->tracks->first;
2035 const char *path = edl->path;
2036 for( ; (!path || !*path) && track; track=track->next ) {
2037 if( !track->record ) continue;
2038 Edit *edit = track->edits->first;
2039 if( !edit ) continue;
2040 Indexable *indexable = edit->get_source();
2041 if( !indexable ) continue;
2042 path = indexable->path;
2045 time_t now; time(&now);
2046 struct tm dtm; localtime_r(&now, &dtm);
2047 char *cp = new_edl->local_session->clip_notes;
2048 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2050 n = snprintf(cp, sz, "%s", txt);
2053 n = snprintf(cp, sz,
2054 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2055 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2056 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2058 if( path && *path ) {
2060 char title[BCTEXTLEN];
2061 fs.extract_name(title, path);
2062 n = snprintf(cp, sz, "%s", title);
2066 sprintf(new_edl->local_session->clip_icon,
2067 "clip_%02d%02d%02d-%02d%02d%02d.png",
2068 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2069 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
2070 edl->update_assets(new_edl);
2072 gui->get_abs_cursor(cur_x, cur_y, 0);
2073 gui->unlock_window();
2075 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2076 new_edl->remove_user();
2078 gui->lock_window("MWindow::save_clip");
2082 void MWindow::to_clip(EDL *edl, const char *txt)
2087 gui->lock_window("MWindow::to_clip 1");
2088 start = edl->local_session->get_selectionstart();
2089 end = edl->local_session->get_selectionend();
2091 if( EQUIV(end, start) ) {
2093 end = edl->tracks->total_length();
2096 // Don't copy all since we don't want the clips twice.
2097 edl->copy(start, end, 0, &file, "", 1);
2099 EDL *new_edl = new EDL(edl);
2100 new_edl->create_objects();
2101 new_edl->load_xml(&file, LOAD_ALL);
2102 save_clip(new_edl, txt);
2103 gui->unlock_window();
2106 int MWindow::toggle_label(int is_mwindow)
2108 double position1, position2;
2109 undo->update_undo_before();
2111 if( cwindow->playback_engine->is_playing_back ) {
2112 position1 = position2 =
2113 cwindow->playback_engine->get_tracking_position();
2116 position1 = edl->local_session->get_selectionstart(1);
2117 position2 = edl->local_session->get_selectionend(1);
2120 position1 = edl->align_to_frame(position1, 0);
2121 position2 = edl->align_to_frame(position2, 0);
2123 //printf("MWindow::toggle_label 1\n");
2125 edl->labels->toggle_label(position1, position2);
2129 gui->lock_window("MWindow::toggle_label 1");
2131 gui->update_timebar(0);
2132 gui->activate_timeline();
2135 gui->unlock_window();
2139 cwindow->gui->lock_window("MWindow::toggle_label 2");
2141 cwindow->gui->timebar->update(1);
2143 cwindow->gui->unlock_window();
2146 awindow->gui->async_update_assets();
2148 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2152 void MWindow::trim_selection()
2154 undo->update_undo_before();
2157 edl->trim_selection(edl->local_session->get_selectionstart(),
2158 edl->local_session->get_selectionend(),
2159 edl->session->labels_follow_edits,
2160 edl->session->plugins_follow_edits,
2161 edl->session->autos_follow_edits);
2164 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2165 update_plugin_guis();
2166 gui->update(1, 2, 1, 1, 1, 1, 0);
2167 cwindow->update(1, 0, 0, 0, 1);
2168 awindow->gui->async_update_assets();
2170 cwindow->refresh_frame(CHANGE_EDL);
2174 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2176 calling_window_gui->unlock_window();
2178 if( undo->undo_load_flags() & LOAD_SESSION )
2181 cwindow->gui->lock_window("MWindow::undo_entry 1");
2182 for( int i=0; i<vwindows.size(); ++i ) {
2183 if( vwindows.get(i)->is_running() ) {
2184 if( calling_window_gui != vwindows.get(i)->gui ) {
2185 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2189 gui->lock_window("MWindow::undo_entry 2");
2195 update_plugin_states();
2196 update_plugin_guis();
2198 gui->update(1, 2, 1, 1, 1, 1, 1);
2199 gui->unlock_window();
2200 cwindow->update(1, 1, 1, 1, 1);
2201 cwindow->gui->unlock_window();
2203 for( int i=0; i<vwindows.size(); ++i ) {
2204 if( vwindows.get(i)->is_running() ) {
2205 if( calling_window_gui != vwindows.get(i)->gui ) {
2206 vwindows.get(i)->gui->unlock_window();
2211 if( calling_window_gui != gui )
2212 gui->unlock_window();
2214 awindow->gui->async_update_assets();
2216 cwindow->refresh_frame(CHANGE_ALL);
2217 calling_window_gui->lock_window("MWindow::undo_entry 4");
2221 void MWindow::new_folder(const char *new_folder)
2223 undo->update_undo_before();
2224 edl->new_folder(new_folder);
2225 undo->update_undo_after(_("new folder"), LOAD_ALL);
2226 awindow->gui->async_update_assets();
2229 void MWindow::delete_folder(char *folder)
2231 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2234 void MWindow::select_point(double position)
2236 edl->local_session->set_selectionstart(position);
2237 edl->local_session->set_selectionend(position);
2240 cwindow->update(1, 0, 0, 0, 1);
2242 update_plugin_guis();
2243 gui->update_patchbay();
2244 gui->hide_cursor(0);
2245 gui->draw_cursor(0);
2246 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2247 gui->zoombar->update();
2248 gui->update_timebar(0);
2249 gui->flash_canvas(0);
2256 void MWindow::map_audio(int pattern)
2258 undo->update_undo_before();
2259 remap_audio(pattern);
2260 undo->update_undo_after(
2261 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2263 sync_parameters(CHANGE_PARAMS);
2264 gui->update(0, 1, 0, 0, 1, 0, 0);
2267 void MWindow::remap_audio(int pattern)
2269 int current_channel = 0;
2270 int current_track = 0;
2271 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2272 if( current->data_type == TRACK_AUDIO &&
2274 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2275 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2277 for( int i=0; i < MAXCHANNELS; ++i ) {
2278 pan_auto->values[i] = 0.0;
2281 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2282 pan_auto->values[current_channel] = 1.0;
2285 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2286 switch( current_track ) {
2289 pan_auto->values[0] = 1;
2293 pan_auto->values[1] = 1;
2297 pan_auto->values[0] = 0.5;
2298 pan_auto->values[1] = 0.5;
2303 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2304 edl->session->achannel_positions, pan_auto->values,
2305 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2309 if( current_channel >= edl->session->audio_channels )
2310 current_channel = 0;
2315 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2316 ArrayList<Indexable*> *orig_assets,
2317 ArrayList<Indexable*> *proxy_assets)
2319 int orig_use_scaler = edl->session->proxy_use_scaler;
2320 int orig_scale = edl->session->proxy_scale;
2321 // rescale to full size asset in read_frame
2322 edl->session->proxy_use_scaler = use_scaler;
2323 edl->session->proxy_scale = new_scale;
2324 edl->session->proxy_auto_scale = auto_scale;
2327 for( int i=0; i<proxy_assets->size(); ++i ) {
2328 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2329 proxy_asset->width = orig_assets->get(i)->get_w();
2330 proxy_asset->height = orig_assets->get(i)->get_h();
2335 if( !orig_use_scaler && new_scale != orig_scale ) {
2337 float orig_w = (float)edl->session->output_w * orig_scale;
2338 float orig_h = (float)edl->session->output_h * orig_scale;
2339 edl->session->output_w = Units::round(orig_w / new_scale);
2340 edl->session->output_h = Units::round(orig_h / new_scale);
2343 for( Track *track=edl->tracks->first; track; track=track->next ) {
2344 if( track->data_type != TRACK_VIDEO ) continue;
2345 orig_w = (float)track->track_w * orig_scale;
2346 orig_h = (float)track->track_h * orig_scale;
2347 track->track_w = Units::round(orig_w / new_scale);
2348 track->track_h = Units::round(orig_h / new_scale);
2349 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2350 set_proxy(orig_scale, new_scale);
2351 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2352 set_proxy(orig_scale, new_scale);
2353 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2354 set_proxy(orig_scale, new_scale);
2355 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2356 set_proxy(orig_scale, new_scale);
2357 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2358 set_proxy(orig_scale, new_scale);
2362 // change original assets to proxy assets
2363 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2364 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2365 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2366 proxy_asset->awindow_folder = awindow_folder;
2367 // replace track contents
2368 for( Track *track=edl->tracks->first; track; track=track->next ) {
2369 if( track->data_type != TRACK_VIDEO ) continue;
2370 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2371 if( !edit->asset ) continue;
2372 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2373 edit->asset = proxy_asset;
2380 void MWindow::add_proxy(int use_scaler,
2381 ArrayList<Indexable*> *orig_assets,
2382 ArrayList<Indexable*> *proxy_assets)
2385 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2386 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2387 proxy_asset->width = orig_assets->get(i)->get_w();
2388 proxy_asset->height = orig_assets->get(i)->get_h();
2392 // change original assets to proxy assets
2393 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2394 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2395 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2396 // replace track contents
2397 for( Track *track=edl->tracks->first; track; track=track->next ) {
2398 if( track->data_type != TRACK_VIDEO ) continue;
2399 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2400 if( !edit->asset ) continue;
2401 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2402 edit->asset = proxy_asset;
2409 void MWindow::cut_commercials()
2411 undo->update_undo_before();
2412 commercials->scan_media();
2415 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2418 update_plugin_guis();
2419 gui->update(1, 2, 1, 1, 1, 1, 0);
2420 cwindow->update(1, 0, 0, 0, 1);
2421 cwindow->refresh_frame(CHANGE_EDL);