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->playback_engine->que->
100 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
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->playback_engine->que->
120 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
124 void MWindow::add_subttl_track_entry(Track *dst)
126 undo->update_undo_before();
127 add_subttl_track(1, dst);
128 undo->update_undo_after(_("add track"), LOAD_ALL);
132 gui->update(1, 1, 0, 0, 1, 0, 0);
133 gui->activate_timeline();
134 // gui->get_scrollbars(0);
135 // gui->canvas->draw();
136 // gui->patchbay->update();
137 // gui->cursor->draw(1);
138 // gui->canvas->flash();
139 // gui->canvas->activate();
140 cwindow->playback_engine->que->
141 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
146 int MWindow::add_audio_track(int above, Track *dst)
148 edl->tracks->add_audio_track(above, dst);
149 edl->tracks->update_y_pixels(theme);
154 int MWindow::add_video_track(int above, Track *dst)
156 edl->tracks->add_video_track(above, dst);
157 edl->tracks->update_y_pixels(theme);
162 int MWindow::add_subttl_track(int above, Track *dst)
164 edl->tracks->add_subttl_track(above, dst);
165 edl->tracks->update_y_pixels(theme);
170 void MWindow::asset_to_all()
172 if( !session->drag_assets->size() ) return;
173 Indexable *indexable = session->drag_assets->get(0);
175 // if( indexable->have_video() )
179 undo->update_undo_before();
182 w = indexable->get_w();
183 h = indexable->get_h();
184 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
185 double old_framerate = edl->session->frame_rate;
186 int old_samplerate = edl->session->sample_rate;
187 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
190 if( indexable->have_video() ) {
191 edl->session->output_w = w;
192 edl->session->output_h = h;
193 edl->session->frame_rate = new_framerate;
195 edl->session->aspect_w,
196 edl->session->aspect_h,
199 for( Track *current = edl->tracks->first; current; current = NEXT ) {
200 if( current->data_type == TRACK_VIDEO /* &&
201 current->record */ ) {
202 current->track_w = w;
203 current->track_h = h;
208 if( ((edl->session->output_w % 4) ||
209 (edl->session->output_h % 4)) &&
210 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
211 MainError::show_error(
212 _("This project's dimensions are not multiples of 4 so\n"
213 "it can't be rendered by OpenGL."));
217 if( defaults->get("AUTOASPECT", 0) ) {
219 edl->session->aspect_w,
220 edl->session->aspect_h,
225 if( indexable->have_audio() ) {
226 edl->session->sample_rate = new_samplerate;
227 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
228 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
233 undo->update_undo_after(_("asset to all"), LOAD_ALL);
235 gui->update(1, 2, 1, 1, 1, 1, 0);
236 sync_parameters(CHANGE_ALL);
240 void MWindow::asset_to_size()
242 if( !session->drag_assets->size() ) return;
243 Indexable *indexable = session->drag_assets->get(0);
245 if( indexable->have_video() ) {
247 undo->update_undo_before();
250 w = indexable->get_w();
251 h = indexable->get_h();
252 edl->session->output_w = w;
253 edl->session->output_h = h;
255 if( ((edl->session->output_w % 4) ||
256 (edl->session->output_h % 4)) &&
257 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
258 MainError::show_error(
259 _("This project's dimensions are not multiples of 4 so\n"
260 "it can't be rendered by OpenGL."));
264 if( defaults->get("AUTOASPECT", 0) ) {
265 create_aspect_ratio(edl->session->aspect_w,
266 edl->session->aspect_h,
273 undo->update_undo_after(_("asset to size"), LOAD_ALL);
275 sync_parameters(CHANGE_ALL);
280 void MWindow::asset_to_rate()
282 if( session->drag_assets->size() &&
283 session->drag_assets->get(0)->have_video() ) {
284 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
285 double old_framerate = edl->session->frame_rate;
286 undo->update_undo_before();
288 edl->session->frame_rate = new_framerate;
289 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
293 undo->update_undo_after(_("asset to rate"), LOAD_ALL);
295 gui->update(1, 2, 1, 1, 1, 1, 0);
296 sync_parameters(CHANGE_ALL);
301 void MWindow::clear_entry()
303 undo->update_undo_before();
308 undo->update_undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
311 update_plugin_guis();
312 gui->update(1, 2, 1, 1, 1, 1, 0);
313 cwindow->update(1, 0, 0, 0, 1);
314 cwindow->playback_engine->que->
315 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
318 void MWindow::clear(int clear_handle)
320 double start = edl->local_session->get_selectionstart();
321 double end = edl->local_session->get_selectionend();
322 if( clear_handle || !EQUIV(start, end) ) {
325 edl->session->labels_follow_edits,
326 edl->session->plugins_follow_edits,
327 edl->session->autos_follow_edits);
331 void MWindow::set_automation_mode(int mode)
333 undo->update_undo_before();
334 edl->tracks->set_automation_mode(
335 edl->local_session->get_selectionstart(),
336 edl->local_session->get_selectionend(),
339 char string[BCSTRLEN];
340 sprintf(string,"set %s", FloatAuto::curve_name(mode));
341 undo->update_undo_after(string, LOAD_AUTOMATION);
344 update_plugin_guis();
345 gui->draw_overlays(1);
346 sync_parameters(CHANGE_PARAMS);
347 gui->update_patchbay();
348 cwindow->update(1, 0, 0);
351 void MWindow::clear_automation()
353 undo->update_undo_before();
354 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
355 edl->local_session->get_selectionend());
357 undo->update_undo_after(_("clear keyframes"), LOAD_AUTOMATION);
360 update_plugin_guis();
361 gui->draw_overlays(1);
362 sync_parameters(CHANGE_PARAMS);
363 gui->update_patchbay();
364 cwindow->update(1, 0, 0);
367 int MWindow::clear_default_keyframe()
369 undo->update_undo_before();
370 edl->tracks->clear_default_keyframe();
372 undo->update_undo_after(_("clear default keyframe"), LOAD_AUTOMATION);
375 gui->draw_overlays(1);
376 sync_parameters(CHANGE_PARAMS);
377 gui->update_patchbay();
378 cwindow->update(1, 0, 0);
383 void MWindow::clear_labels()
385 undo->update_undo_before();
386 clear_labels(edl->local_session->get_selectionstart(),
387 edl->local_session->get_selectionend());
388 undo->update_undo_after(_("clear labels"), LOAD_TIMEBAR);
390 gui->update_timebar(1);
391 cwindow->update(0, 0, 0, 0, 1);
395 int MWindow::clear_labels(double start, double end)
397 edl->labels->clear(start, end, 0);
401 void MWindow::concatenate_tracks()
403 undo->update_undo_before();
404 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
405 edl->session->autos_follow_edits);
407 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
410 gui->update(1, 1, 0, 0, 1, 0, 0);
411 cwindow->playback_engine->que->
412 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
418 copy(edl->local_session->get_selectionstart(),
419 edl->local_session->get_selectionend());
422 int MWindow::copy(double start, double end)
424 if( start == end ) return 1;
427 edl->copy(start, end, 0, 0, 0, &file, "", 1);
428 const char *file_string = file.string();
429 long file_length = strlen(file_string);
430 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
431 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
436 int MWindow::copy_automation()
439 double start = edl->local_session->get_selectionstart();
440 double end = edl->local_session->get_selectionend();
441 edl->tracks->copy_automation(start, end, &file, 0, 1);
442 const char *file_string = file.string();
443 long file_length = strlen(file_string);
444 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
445 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
449 int MWindow::copy_default_keyframe()
452 double start = edl->local_session->get_selectionstart();
453 double end = edl->local_session->get_selectionend();
454 edl->tracks->copy_automation(start, end, &file, 1, 0);
455 const char *file_string = file.string();
456 long file_length = strlen(file_string);
457 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
458 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
463 // Uses cropping coordinates in edl session to crop and translate video.
464 // We modify the projector since camera automation depends on the track size.
465 void MWindow::crop_video()
468 undo->update_undo_before();
469 // Clamp EDL crop region
470 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
471 edl->session->crop_x1 ^= edl->session->crop_x2;
472 edl->session->crop_x2 ^= edl->session->crop_x1;
473 edl->session->crop_x1 ^= edl->session->crop_x2;
475 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
476 edl->session->crop_y1 ^= edl->session->crop_y2;
477 edl->session->crop_y2 ^= edl->session->crop_y1;
478 edl->session->crop_y1 ^= edl->session->crop_y2;
481 float old_projector_x = (float)edl->session->output_w / 2;
482 float old_projector_y = (float)edl->session->output_h / 2;
483 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
484 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
485 float projector_offset_x = -(new_projector_x - old_projector_x);
486 float projector_offset_y = -(new_projector_y - old_projector_y);
488 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
490 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
491 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
492 edl->session->crop_x1 = 0;
493 edl->session->crop_y1 = 0;
494 edl->session->crop_x2 = edl->session->output_w;
495 edl->session->crop_y2 = edl->session->output_h;
497 // Recalculate aspect ratio
498 if( defaults->get("AUTOASPECT", 0) ) {
499 create_aspect_ratio(edl->session->aspect_w,
500 edl->session->aspect_h,
501 edl->session->output_w,
502 edl->session->output_h);
505 undo->update_undo_after(_("crop"), LOAD_ALL);
508 cwindow->playback_engine->que->
509 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
515 double start = edl->local_session->get_selectionstart();
516 double end = edl->local_session->get_selectionend();
520 void MWindow::cut(double start, double end, double new_position)
522 undo->update_undo_before();
524 edl->clear(start, end,
525 edl->session->labels_follow_edits,
526 edl->session->plugins_follow_edits,
527 edl->session->autos_follow_edits);
532 undo->update_undo_after(_("cut"), LOAD_EDITS | LOAD_TIMEBAR);
533 if( new_position >= 0 ) {
534 edl->local_session->set_selectionstart(new_position);
535 edl->local_session->set_selectionend(new_position);
538 update_plugin_guis();
539 gui->update(1, 2, 1, 1, 1, 1, 0);
540 cwindow->update(1, 0, 0, 0, 1);
541 cwindow->playback_engine->que->
542 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
545 void MWindow::snap_left_edit()
547 double start_pos = edl->local_session->get_selectionstart(1);
548 double position = edl->prev_edit(start_pos);
549 if( position < start_pos )
550 cut(position, start_pos, position);
553 void MWindow::snap_right_edit()
555 double end_pos = edl->local_session->get_selectionend(1);
556 double position = edl->next_edit(end_pos);
557 if( end_pos < position )
558 cut(end_pos, position, end_pos);
561 void MWindow::snap_left_label()
563 double start_pos = edl->local_session->get_selectionstart(1);
564 Label *left_label = edl->labels->prev_label(start_pos);
565 if( !left_label ) return;
566 double position = left_label->position;
567 if( position < start_pos )
568 cut(position, start_pos, position);
571 void MWindow::snap_right_label()
573 double end_pos = edl->local_session->get_selectionend(1);
574 Label *right_label = edl->labels->next_label(end_pos);
575 if( !right_label ) return;
576 double position = right_label->position;
577 if( end_pos < position )
578 cut(end_pos, position, end_pos);
581 int MWindow::cut_automation()
583 undo->update_undo_before();
587 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
588 edl->local_session->get_selectionend());
590 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
594 update_plugin_guis();
595 gui->draw_overlays(1);
596 sync_parameters(CHANGE_PARAMS);
597 gui->update_patchbay();
598 cwindow->update(1, 0, 0);
602 int MWindow::cut_default_keyframe()
605 undo->update_undo_before();
606 copy_default_keyframe();
607 edl->tracks->clear_default_keyframe();
608 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
611 gui->draw_overlays(1);
612 sync_parameters(CHANGE_PARAMS);
613 gui->update_patchbay();
614 cwindow->update(1, 0, 0);
622 void MWindow::delete_inpoint()
624 edl->local_session->unset_inpoint();
628 void MWindow::delete_outpoint()
630 edl->local_session->unset_outpoint();
635 void MWindow::delete_track()
637 if( edl->tracks->last )
638 delete_track(edl->tracks->last);
641 void MWindow::delete_tracks()
643 undo->update_undo_before();
644 edl->tracks->delete_tracks();
645 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
649 update_plugin_states();
651 gui->update(1, 1, 1, 0, 1, 0, 0);
652 cwindow->playback_engine->que->
653 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
656 void MWindow::delete_track(Track *track)
658 undo->update_undo_before();
659 edl->tracks->delete_track(track);
660 undo->update_undo_after(_("delete track"), LOAD_ALL);
663 update_plugin_states();
665 gui->update(1, 1, 1, 0, 1, 0, 0);
666 cwindow->playback_engine->que->
667 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
672 // Insert data from clipboard
673 void MWindow::insert(double position, FileXML *file,
674 int edit_labels, int edit_plugins, int edit_autos,
677 // For clipboard pasting make the new edl use a separate session
678 // from the master EDL. Then it can be resampled to the master rates.
679 // For splice, overwrite, and dragging need same session to get the assets.
680 EDL *edl = new EDL(parent_edl);
681 ArrayList<EDL*> new_edls;
682 uint32_t load_flags = LOAD_ALL;
685 new_edls.append(edl);
686 edl->create_objects();
691 if( parent_edl ) load_flags &= ~LOAD_SESSION;
692 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
693 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
695 edl->load_xml(file, load_flags);
698 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
702 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
703 edit_labels, edit_plugins, edit_autos, 0); // overwrite
704 // if( vwindow->edl )
705 // printf("MWindow::insert 5 %f %f\n",
706 // vwindow->edl->local_session->in_point,
707 // vwindow->edl->local_session->out_point);
708 new_edls.remove_all();
709 edl->Garbage::remove_user();
710 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
713 void MWindow::insert_effects_canvas(double start,
716 Track *dest_track = session->track_highlighted;
717 if( !dest_track ) return;
719 undo->update_undo_before();
721 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
722 PluginServer *plugin = session->drag_pluginservers->values[i];
723 insert_effect(plugin->title, 0, dest_track,
724 i == 0 ? session->pluginset_highlighted : 0,
725 start, length, PLUGIN_STANDALONE);
729 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
731 sync_parameters(CHANGE_EDL);
732 // GUI updated in TrackCanvas, after current_operations are reset
735 void MWindow::insert_effects_cwindow(Track *dest_track)
737 if( !dest_track ) return;
739 undo->update_undo_before();
742 double length = dest_track->get_length();
744 if( edl->local_session->get_selectionend() >
745 edl->local_session->get_selectionstart() ) {
746 start = edl->local_session->get_selectionstart();
747 length = edl->local_session->get_selectionend() -
748 edl->local_session->get_selectionstart();
751 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
752 PluginServer *plugin = session->drag_pluginservers->values[i];
753 insert_effect(plugin->title, 0, dest_track, 0,
754 start, length, PLUGIN_STANDALONE);
758 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
760 sync_parameters(CHANGE_EDL);
761 gui->update(1, 1, 0, 0, 1, 0, 0);
764 void MWindow::insert_effect(char *title,
765 SharedLocation *shared_location,
768 int single_standalone)
770 Track *current = edl->tracks->first;
771 SharedLocation shared_location_local;
772 shared_location_local.copy_from(shared_location);
774 for( ; current; current = NEXT) {
775 if( current->data_type == data_type &&
777 insert_effect(title, &shared_location_local,
778 current, 0, 0, 0, plugin_type);
781 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
782 plugin_type = PLUGIN_SHAREDPLUGIN;
783 shared_location_local.module = edl->tracks->number_of(current);
784 shared_location_local.plugin = current->plugin_set.total - 1;
793 void MWindow::insert_effect(char *title,
794 SharedLocation *shared_location,
796 PluginSet *plugin_set,
801 KeyFrame *default_keyframe = 0;
802 PluginServer *server = 0;
803 // Get default keyframe
804 if( plugin_type == PLUGIN_STANDALONE ) {
805 default_keyframe = new KeyFrame;
806 server = new PluginServer(*scan_plugindb(title, track->data_type));
808 server->open_plugin(0, preferences, edl, 0);
809 server->save_data(default_keyframe);
811 // Insert plugin object
812 track->insert_effect(title, shared_location,
813 default_keyframe, plugin_set,
814 start, length, plugin_type);
817 if( plugin_type == PLUGIN_STANDALONE ) {
818 server->close_plugin();
820 delete default_keyframe;
824 int MWindow::modify_edithandles()
826 undo->update_undo_before();
827 edl->modify_edithandles(session->drag_start,
828 session->drag_position,
829 session->drag_handle,
830 edl->session->edit_handle_mode[session->drag_button],
831 edl->session->labels_follow_edits,
832 edl->session->plugins_follow_edits,
833 edl->session->autos_follow_edits);
835 finish_modify_handles();
836 //printf("MWindow::modify_handles 1\n");
840 int MWindow::modify_pluginhandles()
842 undo->update_undo_before();
844 edl->modify_pluginhandles(session->drag_start,
845 session->drag_position,
846 session->drag_handle,
847 edl->session->edit_handle_mode[session->drag_button],
848 edl->session->labels_follow_edits,
849 edl->session->autos_follow_edits,
850 session->trim_edits);
852 finish_modify_handles();
858 // Common to edithandles and plugin handles
859 void MWindow::finish_modify_handles()
861 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
863 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
864 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
865 edl->local_session->set_selectionstart(session->drag_position);
866 edl->local_session->set_selectionend(session->drag_position);
869 if( edit_mode != MOVE_NO_EDITS ) {
870 edl->local_session->set_selectionstart(session->drag_start);
871 edl->local_session->set_selectionend(session->drag_start);
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 cwindow->update(1, 0, 0, 0, 1);
888 void MWindow::match_output_size(Track *track)
890 undo->update_undo_before();
891 track->track_w = edl->session->output_w;
892 track->track_h = edl->session->output_h;
894 undo->update_undo_after(_("match output size"), LOAD_ALL);
897 sync_parameters(CHANGE_EDL);
901 void MWindow::move_edits(ArrayList<Edit*> *edits,
906 undo->update_undo_before();
908 edl->tracks->move_edits(edits,
911 edl->session->labels_follow_edits,
912 edl->session->plugins_follow_edits,
913 edl->session->autos_follow_edits,
917 undo->update_undo_after(_("move edit"), LOAD_ALL);
920 cwindow->playback_engine->que->
921 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
923 update_plugin_guis();
924 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
928 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
930 undo->update_undo_before();
931 edl->tracks->move_effect(plugin, track, position);
933 undo->update_undo_after(_("paste effect"), LOAD_ALL);
936 cwindow->playback_engine->que->
937 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
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->playback_engine->que->
952 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
953 update_plugin_guis();
954 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
958 void MWindow::move_plugins_up(PluginSet *plugin_set)
961 undo->update_undo_before();
962 plugin_set->track->move_plugins_up(plugin_set);
965 undo->update_undo_after(_("move effect up"), LOAD_ALL);
967 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
969 sync_parameters(CHANGE_EDL);
972 void MWindow::move_plugins_down(PluginSet *plugin_set)
974 undo->update_undo_before();
976 plugin_set->track->move_plugins_down(plugin_set);
979 undo->update_undo_after(_("move effect down"), LOAD_ALL);
981 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
983 sync_parameters(CHANGE_EDL);
986 void MWindow::move_track_down(Track *track)
988 undo->update_undo_before();
989 edl->tracks->move_track_down(track);
991 undo->update_undo_after(_("move track down"), LOAD_ALL);
994 gui->update(1, 1, 0, 0, 1, 0, 0);
995 sync_parameters(CHANGE_EDL);
999 void MWindow::move_tracks_down()
1001 undo->update_undo_before();
1002 edl->tracks->move_tracks_down();
1004 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1007 gui->update(1, 1, 0, 0, 1, 0, 0);
1008 sync_parameters(CHANGE_EDL);
1012 void MWindow::move_track_up(Track *track)
1014 undo->update_undo_before();
1015 edl->tracks->move_track_up(track);
1017 undo->update_undo_after(_("move track up"), LOAD_ALL);
1019 gui->update(1, 1, 0, 0, 1, 0, 0);
1020 sync_parameters(CHANGE_EDL);
1024 void MWindow::move_tracks_up()
1026 undo->update_undo_before();
1027 edl->tracks->move_tracks_up();
1029 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1031 gui->update(1, 1, 0, 0, 1, 0, 0);
1032 sync_parameters(CHANGE_EDL);
1036 void MWindow::mute_selection()
1038 double start = edl->local_session->get_selectionstart();
1039 double end = edl->local_session->get_selectionend();
1040 if( start != end ) {
1041 undo->update_undo_before();
1042 edl->clear(start, end, 0,
1043 edl->session->plugins_follow_edits,
1044 edl->session->autos_follow_edits);
1045 edl->local_session->set_selectionend(end);
1046 edl->local_session->set_selectionstart(start);
1047 edl->paste_silence(start, end, 0,
1048 edl->session->plugins_follow_edits,
1049 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->playback_engine->que->
1057 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1062 void MWindow::overwrite(EDL *source)
1066 double src_start = source->local_session->get_selectionstart();
1067 double overwrite_len = source->local_session->get_selectionend() - src_start;
1068 double dst_start = edl->local_session->get_selectionstart();
1069 double dst_len = edl->local_session->get_selectionend() - dst_start;
1071 undo->update_undo_before();
1072 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1073 // in/out points or selection present and shorter than overwrite range
1074 // shorten the copy range
1075 overwrite_len = dst_len;
1078 source->copy(src_start, src_start + overwrite_len,
1079 1, 0, 0, &file, "", 1);
1081 // HACK around paste_edl get_start/endselection on its own
1082 // so we need to clear only when not using both io points
1083 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1084 if( edl->local_session->get_inpoint() < 0 ||
1085 edl->local_session->get_outpoint() < 0 )
1086 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1088 paste(dst_start, dst_start + overwrite_len,
1091 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1092 edl->local_session->set_selectionend(dst_start + overwrite_len);
1095 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1098 update_plugin_guis();
1099 gui->update(1, 1, 1, 1, 0, 1, 0);
1100 sync_parameters(CHANGE_EDL);
1103 // For splice and overwrite
1104 int MWindow::paste(double start,
1113 // Want to insert with assets shared with the master EDL.
1115 edit_labels, edit_plugins, edit_autos,
1121 // For editing using insertion point
1122 void MWindow::paste()
1124 double start = edl->local_session->get_selectionstart();
1125 //double end = edl->local_session->get_selectionend();
1126 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1129 char *string = new char[len];
1130 undo->update_undo_before();
1131 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1133 file.read_from_string(string);
1136 insert(start, &file,
1137 edl->session->labels_follow_edits,
1138 edl->session->plugins_follow_edits,
1139 edl->session->autos_follow_edits,
1147 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1149 update_plugin_guis();
1150 gui->update(1, 2, 1, 1, 0, 1, 0);
1151 awindow->gui->async_update_assets();
1152 sync_parameters(CHANGE_EDL);
1157 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1160 undo->update_undo_before();
1162 if( session->drag_assets->total ) {
1163 load_assets(session->drag_assets,
1164 position, LOADMODE_PASTE, dest_track, 0,
1165 edl->session->labels_follow_edits,
1166 edl->session->plugins_follow_edits,
1167 edl->session->autos_follow_edits,
1172 if( session->drag_clips->total ) {
1173 paste_edls(session->drag_clips,
1174 LOADMODE_PASTE, dest_track, position,
1175 edl->session->labels_follow_edits,
1176 edl->session->plugins_follow_edits,
1177 edl->session->autos_follow_edits,
1184 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1186 gui->update(1, 2, 1, 0, 0, 1, 0);
1187 sync_parameters(CHANGE_EDL);
1191 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1192 double position, int load_mode, Track *first_track, RecordLabels *labels,
1193 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1195 if( load_mode == LOADMODE_RESOURCESONLY )
1196 load_mode = LOADMODE_ASSETSONLY;
1197 const int debug = 0;
1198 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1199 if( position < 0 ) position = edl->local_session->get_selectionstart();
1201 ArrayList<EDL*> new_edls;
1202 for( int i = 0; i < new_assets->total; i++ ) {
1203 Indexable *indexable = new_assets->get(i);
1204 if( indexable->is_asset ) {
1205 remove_asset_from_caches((Asset*)indexable);
1207 EDL *new_edl = new EDL;
1208 new_edl->create_objects();
1209 new_edl->copy_session(edl);
1210 new_edls.append(new_edl);
1213 if( indexable->is_asset ) {
1214 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1215 if( debug ) ((Asset*)indexable)->dump();
1216 asset_to_edl(new_edl, (Asset*)indexable);
1219 edl_to_nested(new_edl, (EDL*)indexable);
1220 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1224 for( RecordLabel *label = labels->first; label; label = label->next ) {
1225 new_edl->labels->toggle_label(label->position, label->position);
1229 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1231 paste_edls(&new_edls, load_mode, first_track, position,
1232 edit_labels, edit_plugins, edit_autos, overwrite);
1233 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1236 for( int i = 0; i < new_edls.size(); i++ )
1237 new_edls.get(i)->Garbage::remove_user();
1239 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1242 int MWindow::paste_automation()
1244 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1247 undo->update_undo_before();
1248 char *string = new char[len];
1249 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1251 file.read_from_string(string);
1253 double start = edl->local_session->get_selectionstart();
1254 double end = edl->local_session->get_selectionend();
1255 edl->tracks->clear_automation(start, end);
1256 edl->tracks->paste_automation(start, &file, 0, 1,
1257 edl->session->typeless_keyframes);
1259 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1263 update_plugin_guis();
1264 gui->draw_overlays(1);
1265 sync_parameters(CHANGE_PARAMS);
1266 gui->update_patchbay();
1267 cwindow->update(1, 0, 0);
1273 int MWindow::paste_default_keyframe()
1275 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1278 undo->update_undo_before();
1279 char *string = new char[len];
1280 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1282 file.read_from_string(string);
1283 double start = edl->local_session->get_selectionstart();
1284 edl->tracks->paste_automation(start, &file, 1, 0,
1285 edl->session->typeless_keyframes);
1286 // edl->tracks->paste_default_keyframe(&file);
1287 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1290 update_plugin_guis();
1291 gui->draw_overlays(1);
1292 sync_parameters(CHANGE_PARAMS);
1293 gui->update_patchbay();
1294 cwindow->update(1, 0, 0);
1303 // Insert edls with project deletion and index file generation.
1304 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1305 Track *first_track, double current_position,
1306 int edit_labels, int edit_plugins, int edit_autos,
1310 ArrayList<Track*> destination_tracks;
1311 int need_new_tracks = 0;
1314 if( !new_edls->total ) return 0;
1317 // double original_length = edl->tracks->total_playable_length();
1318 // double original_preview_end = edl->local_session->preview_end;
1321 // Delete current project
1322 if( load_mode == LOADMODE_REPLACE ||
1323 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1325 edl->save_defaults(defaults);
1327 edl->Garbage::remove_user();
1329 edl->create_objects();
1330 edl->copy_session(new_edls->values[0]);
1331 gui->mainmenu->update_toggles(0);
1332 gui->unlock_window();
1333 gwindow->gui->update_toggles(1);
1334 gui->lock_window("MWindow::paste_edls");
1336 // Insert labels for certain modes constitutively
1340 // Force reset of preview
1341 // original_length = 0;
1342 // original_preview_end = -1;
1348 // Create new tracks in master EDL
1349 if( load_mode == LOADMODE_REPLACE ||
1350 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1351 load_mode == LOADMODE_NEW_TRACKS ) {
1353 need_new_tracks = 1;
1354 for( int i = 0; i < new_edls->total; i++ ) {
1355 EDL *new_edl = new_edls->values[i];
1356 for( Track *current = new_edl->tracks->first;
1359 if( current->data_type == TRACK_VIDEO ) {
1360 edl->tracks->add_video_track(0, 0);
1361 if( current->draw ) edl->tracks->last->draw = 1;
1362 destination_tracks.append(edl->tracks->last);
1365 if( current->data_type == TRACK_AUDIO ) {
1366 edl->tracks->add_audio_track(0, 0);
1367 destination_tracks.append(edl->tracks->last);
1370 if( current->data_type == TRACK_SUBTITLE ) {
1371 edl->tracks->add_subttl_track(0, 0);
1372 destination_tracks.append(edl->tracks->last);
1374 edl->session->highlighted_track = edl->tracks->total() - 1;
1377 // Base track count on first EDL only for concatenation
1378 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1383 // Recycle existing tracks of master EDL
1384 if( load_mode == LOADMODE_CONCATENATE ||
1385 load_mode == LOADMODE_PASTE ||
1386 load_mode == LOADMODE_NESTED ) {
1389 // The point of this is to shift forward labels after the selection so they can
1390 // then be shifted back to their original locations without recursively
1391 // shifting back every paste.
1392 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1393 edl->session->labels_follow_edits )
1394 edl->labels->clear(edl->local_session->get_selectionstart(),
1395 edl->local_session->get_selectionend(),
1398 Track *current = first_track ? first_track : edl->tracks->first;
1399 for( ; current; current = NEXT) {
1400 if( current->record ) {
1401 destination_tracks.append(current);
1408 int destination_track = 0;
1409 double *paste_position = new double[destination_tracks.total];
1411 // Iterate through the edls
1412 for( int i = 0; i < new_edls->total; i++ ) {
1414 EDL *new_edl = new_edls->values[i];
1415 double edl_length = new_edl->local_session->clipboard_length ?
1416 new_edl->local_session->clipboard_length :
1417 new_edl->tracks->total_length();
1418 // printf("MWindow::paste_edls 2 %f %f\n",
1419 // new_edl->local_session->clipboard_length,
1420 // new_edl->tracks->total_length());
1424 // Convert EDL to master rates
1425 new_edl->resample(new_edl->session->sample_rate,
1426 edl->session->sample_rate,
1428 new_edl->resample(new_edl->session->frame_rate,
1429 edl->session->frame_rate,
1432 // Add assets and prepare index files
1433 for( Asset *new_asset = new_edl->assets->first;
1435 new_asset = new_asset->next ) {
1436 mainindexes->add_next_asset(0, new_asset);
1438 // Capture index file status from mainindex test
1439 edl->update_assets(new_edl);
1441 // Get starting point of insertion. Need this to paste labels.
1442 switch( load_mode ) {
1443 case LOADMODE_REPLACE:
1444 case LOADMODE_NEW_TRACKS:
1445 current_position = 0;
1448 case LOADMODE_CONCATENATE:
1449 case LOADMODE_REPLACE_CONCATENATE:
1450 destination_track = 0;
1451 if( destination_tracks.total )
1452 current_position = destination_tracks.values[0]->get_length();
1454 current_position = 0;
1457 case LOADMODE_PASTE:
1458 case LOADMODE_NESTED:
1459 destination_track = 0;
1461 for( int j = 0; j < destination_tracks.total; j++ ) {
1462 paste_position[j] = (current_position >= 0) ?
1464 edl->local_session->get_selectionstart();
1469 case LOADMODE_RESOURCESONLY:
1470 edl->add_clip(new_edl);
1475 if( load_mode != LOADMODE_RESOURCESONLY &&
1476 load_mode != LOADMODE_ASSETSONLY ) {
1478 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1479 if( load_mode == LOADMODE_PASTE ||
1480 load_mode == LOADMODE_NESTED )
1481 edl->labels->insert_labels(new_edl->labels,
1482 destination_tracks.total ? paste_position[0] : 0.0,
1486 edl->labels->insert_labels(new_edl->labels,
1492 for( Track *new_track = new_edl->tracks->first;
1494 new_track = new_track->next ) {
1495 // Get destination track of same type as new_track
1497 k < destination_tracks.total &&
1498 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1499 k++, destination_track++ ) {
1500 if( destination_track >= destination_tracks.total - 1 )
1501 destination_track = 0;
1504 // Insert data into destination track
1505 if( destination_track < destination_tracks.total &&
1506 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1507 Track *track = destination_tracks.values[destination_track];
1509 // Replace default keyframes if first EDL and new tracks were created.
1510 // This means data copied from one track and pasted to another won't retain
1511 // the camera position unless it's a keyframe. If it did, previous data in the
1512 // track might get unknowingly corrupted. Ideally we would detect when differing
1513 // default keyframes existed and create discrete keyframes for both.
1514 int replace_default = (i == 0) && need_new_tracks;
1516 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1517 // Insert new track at current position
1518 switch( load_mode ) {
1519 case LOADMODE_REPLACE_CONCATENATE:
1520 case LOADMODE_CONCATENATE:
1521 current_position = track->get_length();
1524 case LOADMODE_PASTE:
1525 case LOADMODE_NESTED:
1526 current_position = paste_position[destination_track];
1527 paste_position[destination_track] += new_track->get_length();
1531 track->clear(current_position,
1532 current_position + new_track->get_length(),
1534 edit_labels, edit_plugins, edit_autos,
1539 track->insert_track(new_track, current_position, replace_default,
1540 edit_plugins, edit_autos, edl_length);
1544 // Get next destination track
1545 destination_track++;
1546 if( destination_track >= destination_tracks.total )
1547 destination_track = 0;
1551 if( load_mode == LOADMODE_PASTE ||
1552 load_mode == LOADMODE_NESTED )
1553 current_position += edl_length;
1557 // Move loading of clips and vwindow to the end - this fixes some
1558 // strange issue, for index not being shown
1559 // Assume any paste operation from the same EDL won't contain any clips.
1560 // If it did it would duplicate every clip here.
1561 for( int i = 0; i < new_edls->total; i++ ) {
1562 EDL *new_edl = new_edls->values[i];
1564 for( int j = 0; j < new_edl->clips.total; j++ ) {
1565 edl->add_clip(new_edl->clips.values[j]);
1568 if( new_edl->total_vwindow_edls() ) {
1569 // if( edl->vwindow_edl )
1570 // edl->vwindow_edl->Garbage::remove_user();
1571 // edl->vwindow_edl = new EDL(edl);
1572 // edl->vwindow_edl->create_objects();
1573 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1575 for( int j = 0; j < new_edl->total_vwindow_edls(); j++ ) {
1576 EDL *vwindow_edl = new EDL(edl);
1577 vwindow_edl->create_objects();
1578 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1579 edl->append_vwindow_edl(vwindow_edl, 0);
1584 if( paste_position ) delete [] paste_position;
1586 // This is already done in load_filenames and everything else that uses paste_edls
1587 // update_project(load_mode);
1589 // Fix preview range
1590 // if( EQUIV(original_length, original_preview_end) )
1592 // edl->local_session->preview_end = edl->tracks->total_playable_length();
1595 // Start examining next batch of index files
1596 mainindexes->start_build();
1598 // Don't save a backup after loading since the loaded file is on disk already.
1603 void MWindow::paste_silence()
1605 double start = edl->local_session->get_selectionstart();
1606 double end = edl->local_session->get_selectionend();
1607 undo->update_undo_before();
1608 edl->paste_silence(start, end,
1609 edl->session->labels_follow_edits,
1610 edl->session->plugins_follow_edits,
1611 edl->session->autos_follow_edits);
1614 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1616 update_plugin_guis();
1618 gui->update(1, 2, 1, 1, 1, 1, 0);
1619 cwindow->update(1, 0, 0, 0, 1);
1620 cwindow->playback_engine->que->
1621 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1624 void MWindow::detach_transition(Transition *transition)
1626 undo->update_undo_before();
1627 hide_plugin(transition, 1);
1628 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1629 transition->edit->detach_transition();
1631 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1633 if( is_video ) restart_brender();
1634 gui->update(0, 1, 0, 0, 0, 0, 0);
1635 sync_parameters(CHANGE_EDL);
1638 void MWindow::detach_transitions()
1640 gui->lock_window("MWindow::detach_transitions 1");
1642 undo->update_undo_before();
1643 double start = edl->local_session->get_selectionstart();
1644 double end = edl->local_session->get_selectionend();
1645 edl->tracks->clear_transitions(start, end);
1648 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1650 sync_parameters(CHANGE_EDL);
1651 gui->update(0, 1, 0, 0, 0, 0, 0);
1652 gui->unlock_window();
1655 void MWindow::paste_transition()
1657 // Only the first transition gets dropped.
1658 PluginServer *server = session->drag_pluginservers->values[0];
1660 undo->update_undo_before();
1662 strcpy(edl->session->default_atransition, server->title);
1664 strcpy(edl->session->default_vtransition, server->title);
1666 edl->tracks->paste_transition(server, session->edit_highlighted);
1668 undo->update_undo_after(_("transition"), LOAD_EDITS);
1670 if( server->video ) restart_brender();
1671 sync_parameters(CHANGE_ALL);
1674 void MWindow::paste_transitions(int track_type, char *title)
1676 gui->lock_window("MWindow::detach_transitions 1");
1678 undo->update_undo_before();
1679 double start = edl->local_session->get_selectionstart();
1680 double end = edl->local_session->get_selectionend();
1681 edl->tracks->paste_transitions(start, end, track_type, title);
1684 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1686 sync_parameters(CHANGE_EDL);
1687 gui->update(0, 1, 0, 0, 0, 0, 0);
1688 gui->unlock_window();
1691 void MWindow::paste_transition_cwindow(Track *dest_track)
1693 PluginServer *server = session->drag_pluginservers->values[0];
1694 undo->update_undo_before();
1695 edl->tracks->paste_video_transition(server, 1);
1697 undo->update_undo_after(_("transition"), LOAD_EDITS);
1699 gui->update(0, 1, 0, 0, 0, 0, 0);
1700 sync_parameters(CHANGE_ALL);
1703 void MWindow::paste_audio_transition()
1705 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1708 char string[BCTEXTLEN];
1709 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1710 gui->show_message(string);
1714 undo->update_undo_before();
1715 edl->tracks->paste_audio_transition(server);
1717 undo->update_undo_after(_("transition"), LOAD_EDITS);
1719 sync_parameters(CHANGE_EDL);
1720 gui->update(0, 1, 0, 0, 0, 0, 0);
1723 void MWindow::paste_video_transition()
1725 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1728 char string[BCTEXTLEN];
1729 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1730 gui->show_message(string);
1734 undo->update_undo_before();
1736 edl->tracks->paste_video_transition(server);
1738 undo->update_undo_after(_("transition"), LOAD_EDITS);
1740 sync_parameters(CHANGE_EDL);
1742 gui->update(0, 1, 0, 0, 0, 0, 0);
1745 void MWindow::shuffle_edits()
1747 gui->lock_window("MWindow::shuffle_edits 1");
1749 undo->update_undo_before();
1750 double start = edl->local_session->get_selectionstart();
1751 double end = edl->local_session->get_selectionend();
1753 edl->tracks->shuffle_edits(start, end);
1756 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1758 sync_parameters(CHANGE_EDL);
1760 gui->update(0, 1, 1, 0, 0, 0, 0);
1761 gui->unlock_window();
1764 void MWindow::reverse_edits()
1766 gui->lock_window("MWindow::reverse_edits 1");
1768 undo->update_undo_before();
1769 double start = edl->local_session->get_selectionstart();
1770 double end = edl->local_session->get_selectionend();
1772 edl->tracks->reverse_edits(start, end);
1775 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1777 sync_parameters(CHANGE_EDL);
1779 gui->update(0, 1, 1, 0, 0, 0, 0);
1780 gui->unlock_window();
1783 void MWindow::align_edits()
1785 gui->lock_window("MWindow::align_edits 1");
1787 undo->update_undo_before();
1788 double start = edl->local_session->get_selectionstart();
1789 double end = edl->local_session->get_selectionend();
1791 edl->tracks->align_edits(start, end);
1794 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1796 sync_parameters(CHANGE_EDL);
1798 gui->update(0, 1, 1, 0, 0, 0, 0);
1799 gui->unlock_window();
1802 void MWindow::set_edit_length(double length)
1804 gui->lock_window("MWindow::detach_transitions 1");
1806 undo->update_undo_before();
1807 double start = edl->local_session->get_selectionstart();
1808 double end = edl->local_session->get_selectionend();
1810 edl->tracks->set_edit_length(start, end, length);
1813 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1815 sync_parameters(CHANGE_EDL);
1817 gui->update(0, 1, 1, 0, 0, 0, 0);
1818 gui->unlock_window();
1822 void MWindow::set_transition_length(Transition *transition, double length)
1824 gui->lock_window("MWindow::detach_transitions 1");
1826 undo->update_undo_before();
1827 //double start = edl->local_session->get_selectionstart();
1828 //double end = edl->local_session->get_selectionend();
1830 edl->tracks->set_transition_length(transition, length);
1833 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1835 edl->session->default_transition_length = length;
1836 sync_parameters(CHANGE_PARAMS);
1837 gui->update(0, 1, 0, 0, 0, 0, 0);
1838 gui->unlock_window();
1841 void MWindow::set_transition_length(double length)
1843 gui->lock_window("MWindow::detach_transitions 1");
1845 undo->update_undo_before();
1846 double start = edl->local_session->get_selectionstart();
1847 double end = edl->local_session->get_selectionend();
1849 edl->tracks->set_transition_length(start, end, length);
1852 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1854 edl->session->default_transition_length = length;
1855 sync_parameters(CHANGE_PARAMS);
1857 gui->update(0, 1, 0, 0, 0, 0, 0);
1858 gui->unlock_window();
1862 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1865 calling_window_gui->unlock_window();
1867 cwindow->playback_engine->que->
1868 send_command(STOP, CHANGE_NONE, 0, 0);
1869 cwindow->playback_engine->interrupt_playback(0);
1871 for( int i = 0; i < vwindows.size(); i++ ) {
1872 if( vwindows.get(i)->is_running() ) {
1873 vwindows.get(i)->playback_engine->que->
1874 send_command(STOP, CHANGE_NONE, 0, 0);
1875 vwindows.get(i)->playback_engine->interrupt_playback(0);
1879 cwindow->gui->lock_window("MWindow::redo_entry");
1880 for( int i = 0; i < vwindows.size(); i++ ) {
1881 if( vwindows.get(i)->is_running() ) {
1882 if( calling_window_gui != vwindows.get(i)->gui ) {
1883 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1892 update_plugin_states();
1893 update_plugin_guis();
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->playback_engine->que->
1913 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
1917 void MWindow::resize_track(Track *track, int w, int h)
1919 undo->update_undo_before();
1920 // We have to move all maskpoints so they do not move in relation to image areas
1921 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1922 (w - track->track_w) / 2,
1923 (h - track->track_h) / 2);
1926 undo->update_undo_after(_("resize track"), LOAD_ALL);
1930 sync_parameters(CHANGE_EDL);
1934 void MWindow::set_inpoint(int is_mwindow)
1936 undo->update_undo_before();
1937 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1939 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1942 gui->lock_window("MWindow::set_inpoint 1");
1944 gui->update_timebar(1);
1946 gui->unlock_window();
1950 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1952 cwindow->gui->timebar->update(1);
1954 cwindow->gui->unlock_window();
1958 void MWindow::set_outpoint(int is_mwindow)
1960 undo->update_undo_before();
1961 edl->set_outpoint(edl->local_session->get_selectionend(1));
1963 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1966 gui->lock_window("MWindow::set_outpoint 1");
1968 gui->update_timebar(1);
1970 gui->unlock_window();
1974 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1976 cwindow->gui->timebar->update(1);
1978 cwindow->gui->unlock_window();
1982 void MWindow::splice(EDL *source)
1986 undo->update_undo_before();
1987 double source_start = source->local_session->get_selectionstart();
1988 double source_end = source->local_session->get_selectionend();
1989 source->copy(source_start, source_end, 1, 0, 0, &file, "", 1);
1991 double start = edl->local_session->get_selectionstart();
1992 //double end = edl->local_session->get_selectionend();
1994 paste(start, start, &file,
1995 edl->session->labels_follow_edits,
1996 edl->session->plugins_follow_edits,
1997 edl->session->autos_follow_edits);
1999 // Position at end of clip
2000 edl->local_session->set_selectionstart(start + source_end - source_start);
2001 edl->local_session->set_selectionend(start + source_end - source_start);
2004 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2005 update_plugin_guis();
2007 gui->update(1, 1, 1, 1, 0, 1, 0);
2008 sync_parameters(CHANGE_EDL);
2011 void MWindow::save_clip(EDL *new_edl, const char *txt)
2013 new_edl->local_session->set_selectionstart(0);
2014 new_edl->local_session->set_selectionend(0);
2015 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2016 session->clip_number++);
2017 char duration[BCTEXTLEN];
2018 Units::totext(duration, new_edl->tracks->total_length(),
2019 new_edl->session->time_format,
2020 new_edl->session->sample_rate,
2021 new_edl->session->frame_rate,
2022 new_edl->session->frames_per_foot);
2024 Track *track = new_edl->tracks->first;
2025 const char *path = edl->path;
2026 for( ; (!path || !*path) && track; track=track->next ) {
2027 if( !track->record ) continue;
2028 Edit *edit = track->edits->first;
2029 if( !edit ) continue;
2030 Indexable *indexable = edit->get_source();
2031 if( !indexable ) continue;
2032 path = indexable->path;
2035 time_t now; time(&now);
2036 struct tm *tm = localtime(&now);
2037 char *cp = new_edl->local_session->clip_notes;
2038 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2040 n = snprintf(cp, sz, "%s", txt);
2043 n = snprintf(cp, sz,
2044 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2045 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
2046 tm->tm_hour, tm->tm_min, tm->tm_sec, duration);
2048 if( path && *path ) {
2050 char title[BCTEXTLEN];
2051 fs.extract_name(title, path);
2052 n = snprintf(cp, sz, "%s", title);
2057 edl->update_assets(new_edl);
2059 gui->get_abs_cursor_xy(cur_x, cur_y, 0);
2060 gui->unlock_window();
2062 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2064 gui->lock_window("MWindow::save_clip");
2068 void MWindow::to_clip(EDL *edl, const char *txt)
2073 gui->lock_window("MWindow::to_clip 1");
2074 start = edl->local_session->get_selectionstart();
2075 end = edl->local_session->get_selectionend();
2077 if( EQUIV(end, start) ) {
2079 end = edl->tracks->total_length();
2082 // Don't copy all since we don't want the clips twice.
2083 edl->copy(start, end, 0, 0, 0, &file, "", 1);
2085 EDL *new_edl = new EDL(edl);
2086 new_edl->create_objects();
2087 new_edl->load_xml(&file, LOAD_ALL);
2088 save_clip(new_edl, txt);
2089 gui->unlock_window();
2092 int MWindow::toggle_label(int is_mwindow)
2094 double position1, position2;
2095 undo->update_undo_before();
2097 if( cwindow->playback_engine->is_playing_back ) {
2098 position1 = position2 =
2099 cwindow->playback_engine->get_tracking_position();
2102 position1 = edl->local_session->get_selectionstart(1);
2103 position2 = edl->local_session->get_selectionend(1);
2106 position1 = edl->align_to_frame(position1, 0);
2107 position2 = edl->align_to_frame(position2, 0);
2109 //printf("MWindow::toggle_label 1\n");
2111 edl->labels->toggle_label(position1, position2);
2115 gui->lock_window("MWindow::toggle_label 1");
2117 gui->update_timebar(0);
2118 gui->activate_timeline();
2121 gui->unlock_window();
2125 cwindow->gui->lock_window("MWindow::toggle_label 2");
2127 cwindow->gui->timebar->update(1);
2129 cwindow->gui->unlock_window();
2132 awindow->gui->async_update_assets();
2134 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2138 void MWindow::trim_selection()
2140 undo->update_undo_before();
2143 edl->trim_selection(edl->local_session->get_selectionstart(),
2144 edl->local_session->get_selectionend(),
2145 edl->session->labels_follow_edits,
2146 edl->session->plugins_follow_edits,
2147 edl->session->autos_follow_edits);
2150 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2151 update_plugin_guis();
2152 gui->update(1, 2, 1, 1, 1, 1, 0);
2153 cwindow->update(1, 0, 0, 0, 1);
2155 cwindow->playback_engine->que->
2156 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
2160 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2162 calling_window_gui->unlock_window();
2164 cwindow->playback_engine->que->
2165 send_command(STOP, CHANGE_NONE, 0, 0);
2166 cwindow->playback_engine->interrupt_playback(0);
2168 //printf("MWindow::undo_entry %d %d\n", __LINE__, vwindows.size());
2169 for( int i = 0; i < vwindows.size(); i++ ) {
2170 if( vwindows.get(i)->is_running() ) {
2171 vwindows.get(i)->playback_engine->que->
2172 send_command(STOP, CHANGE_NONE, 0, 0);
2173 vwindows.get(i)->playback_engine->interrupt_playback(0);
2177 cwindow->gui->lock_window("MWindow::undo_entry 1");
2178 for( int i = 0; i < vwindows.size(); i++ ) {
2179 if( vwindows.get(i)->is_running() ) {
2180 if( calling_window_gui != vwindows.get(i)->gui ) {
2181 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2185 gui->lock_window("MWindow::undo_entry 2");
2191 update_plugin_states();
2192 update_plugin_guis();
2194 gui->update(1, 2, 1, 1, 1, 1, 1);
2195 gui->unlock_window();
2196 cwindow->update(1, 1, 1, 1, 1);
2197 cwindow->gui->unlock_window();
2199 for( int i = 0; i < vwindows.size(); i++ ) {
2200 if( vwindows.get(i)->is_running() ) {
2201 if( calling_window_gui != vwindows.get(i)->gui ) {
2202 vwindows.get(i)->gui->unlock_window();
2207 if( calling_window_gui != gui )
2208 gui->unlock_window();
2210 awindow->gui->async_update_assets();
2212 cwindow->playback_engine->que->
2213 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
2214 calling_window_gui->lock_window("MWindow::undo_entry 4");
2218 void MWindow::new_folder(const char *new_folder)
2220 undo->update_undo_before();
2221 edl->new_folder(new_folder);
2222 undo->update_undo_after(_("new folder"), LOAD_ALL);
2223 awindow->gui->async_update_assets();
2226 void MWindow::delete_folder(char *folder)
2228 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2231 void MWindow::select_point(double position)
2233 edl->local_session->set_selectionstart(position);
2234 edl->local_session->set_selectionend(position);
2237 cwindow->update(1, 0, 0, 0, 1);
2239 update_plugin_guis();
2240 gui->update_patchbay();
2241 gui->hide_cursor(0);
2242 gui->draw_cursor(0);
2243 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2244 gui->zoombar->update();
2245 gui->update_timebar(0);
2246 gui->flash_canvas(0);
2253 void MWindow::map_audio(int pattern)
2255 undo->update_undo_before();
2256 remap_audio(pattern);
2257 undo->update_undo_after(
2258 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2260 sync_parameters(CHANGE_PARAMS);
2261 gui->update(0, 1, 0, 0, 1, 0, 0);
2264 void MWindow::remap_audio(int pattern)
2266 int current_channel = 0;
2267 int current_track = 0;
2268 for( Track *current = edl->tracks->first; current; current = NEXT ) {
2269 if( current->data_type == TRACK_AUDIO &&
2271 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2272 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2274 for( int i = 0; i < MAXCHANNELS; i++ ) {
2275 pan_auto->values[i] = 0.0;
2278 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2279 pan_auto->values[current_channel] = 1.0;
2282 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2283 switch( current_track ) {
2285 pan_auto->values[0] = 0.5;
2286 pan_auto->values[1] = 0.5;
2289 pan_auto->values[0] = 1;
2292 pan_auto->values[1] = 1;
2295 pan_auto->values[0] = 1;
2298 pan_auto->values[1] = 1;
2301 pan_auto->values[0] = 0.5;
2302 pan_auto->values[1] = 0.5;
2307 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2308 edl->session->achannel_positions, pan_auto->values,
2309 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2313 if( current_channel >= edl->session->audio_channels )
2314 current_channel = 0;
2319 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2320 ArrayList<Indexable*> *orig_assets,
2321 ArrayList<Indexable*> *proxy_assets)
2323 int orig_use_scaler = edl->session->proxy_use_scaler;
2324 int orig_scale = edl->session->proxy_scale;
2325 // rescale to full size asset in read_frame
2326 edl->session->proxy_use_scaler = use_scaler;
2327 edl->session->proxy_scale = new_scale;
2328 edl->session->proxy_auto_scale = auto_scale;
2331 for( int i=0; i<proxy_assets->size(); ++i ) {
2332 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2333 proxy_asset->width = orig_assets->get(i)->get_w();
2334 proxy_asset->height = orig_assets->get(i)->get_h();
2339 if( !orig_use_scaler && new_scale != orig_scale ) {
2341 float orig_w = (float)edl->session->output_w * orig_scale;
2342 float orig_h = (float)edl->session->output_h * orig_scale;
2343 edl->session->output_w = Units::round(orig_w / new_scale);
2344 edl->session->output_h = Units::round(orig_h / new_scale);
2347 for( Track *track=edl->tracks->first; track; track=track->next ) {
2348 if( track->data_type != TRACK_VIDEO ) continue;
2349 orig_w = (float)track->track_w * orig_scale;
2350 orig_h = (float)track->track_h * orig_scale;
2351 track->track_w = Units::round(orig_w / new_scale);
2352 track->track_h = Units::round(orig_h / new_scale);
2353 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2354 set_proxy(orig_scale, new_scale);
2355 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2356 set_proxy(orig_scale, new_scale);
2357 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2358 set_proxy(orig_scale, new_scale);
2359 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2360 set_proxy(orig_scale, new_scale);
2361 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2362 set_proxy(orig_scale, new_scale);
2366 // change original assets to proxy assets
2367 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2368 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2369 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2370 proxy_asset->awindow_folder = awindow_folder;
2371 // replace track contents
2372 for( Track *track = edl->tracks->first; track; track = track->next ) {
2373 if( track->data_type != TRACK_VIDEO ) continue;
2374 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2375 if( !edit->asset ) continue;
2376 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2377 edit->asset = proxy_asset;
2384 void MWindow::add_proxy(int use_scaler,
2385 ArrayList<Indexable*> *orig_assets,
2386 ArrayList<Indexable*> *proxy_assets)
2389 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2390 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2391 proxy_asset->width = orig_assets->get(i)->get_w();
2392 proxy_asset->height = orig_assets->get(i)->get_h();
2396 // change original assets to proxy assets
2397 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2398 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2399 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2400 // replace track contents
2401 for( Track *track = edl->tracks->first; track; track = track->next ) {
2402 if( track->data_type != TRACK_VIDEO ) continue;
2403 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2404 if( !edit->asset ) continue;
2405 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2406 edit->asset = proxy_asset;
2413 void MWindow::cut_commercials()
2415 undo->update_undo_before();
2416 commercials->scan_media();
2419 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2422 update_plugin_guis();
2423 gui->update(1, 2, 1, 1, 1, 1, 0);
2424 cwindow->update(1, 0, 0, 0, 1);
2425 cwindow->playback_engine->que->
2426 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);