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, int deglitch)
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);
330 // always needed by paste operations
333 edl->deglitch(start);
337 void MWindow::set_automation_mode(int mode)
339 undo->update_undo_before();
340 edl->tracks->set_automation_mode(
341 edl->local_session->get_selectionstart(),
342 edl->local_session->get_selectionend(),
345 char string[BCSTRLEN];
346 sprintf(string,"set %s", FloatAuto::curve_name(mode));
347 undo->update_undo_after(string, LOAD_AUTOMATION);
350 update_plugin_guis();
351 gui->draw_overlays(1);
352 sync_parameters(CHANGE_PARAMS);
353 gui->update_patchbay();
354 cwindow->update(1, 0, 0);
357 void MWindow::clear_automation()
359 undo->update_undo_before();
360 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
361 edl->local_session->get_selectionend());
363 undo->update_undo_after(_("clear keyframes"), LOAD_AUTOMATION);
366 update_plugin_guis();
367 gui->draw_overlays(1);
368 sync_parameters(CHANGE_PARAMS);
369 gui->update_patchbay();
370 cwindow->update(1, 0, 0);
373 int MWindow::clear_default_keyframe()
375 undo->update_undo_before();
376 edl->tracks->clear_default_keyframe();
378 undo->update_undo_after(_("clear default keyframe"), LOAD_AUTOMATION);
381 gui->draw_overlays(1);
382 sync_parameters(CHANGE_PARAMS);
383 gui->update_patchbay();
384 cwindow->update(1, 0, 0);
389 void MWindow::clear_labels()
391 undo->update_undo_before();
392 clear_labels(edl->local_session->get_selectionstart(),
393 edl->local_session->get_selectionend());
394 undo->update_undo_after(_("clear labels"), LOAD_TIMEBAR);
396 gui->update_timebar(1);
397 cwindow->update(0, 0, 0, 0, 1);
401 int MWindow::clear_labels(double start, double end)
403 edl->labels->clear(start, end, 0);
407 void MWindow::concatenate_tracks()
409 undo->update_undo_before();
410 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
411 edl->session->autos_follow_edits);
413 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
416 gui->update(1, 1, 0, 0, 1, 0, 0);
417 cwindow->playback_engine->que->
418 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
424 copy(edl->local_session->get_selectionstart(),
425 edl->local_session->get_selectionend());
428 int MWindow::copy(double start, double end)
430 if( start == end ) return 1;
433 edl->copy(start, end, 0, 0, 0, &file, "", 1);
434 const char *file_string = file.string();
435 long file_length = strlen(file_string);
436 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
437 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
442 int MWindow::copy_automation()
445 double start = edl->local_session->get_selectionstart();
446 double end = edl->local_session->get_selectionend();
447 edl->tracks->copy_automation(start, end, &file, 0, 1);
448 const char *file_string = file.string();
449 long file_length = strlen(file_string);
450 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
451 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
455 int MWindow::copy_default_keyframe()
458 double start = edl->local_session->get_selectionstart();
459 double end = edl->local_session->get_selectionend();
460 edl->tracks->copy_automation(start, end, &file, 1, 0);
461 const char *file_string = file.string();
462 long file_length = strlen(file_string);
463 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
464 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
469 // Uses cropping coordinates in edl session to crop and translate video.
470 // We modify the projector since camera automation depends on the track size.
471 void MWindow::crop_video()
474 undo->update_undo_before();
475 // Clamp EDL crop region
476 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
477 edl->session->crop_x1 ^= edl->session->crop_x2;
478 edl->session->crop_x2 ^= edl->session->crop_x1;
479 edl->session->crop_x1 ^= edl->session->crop_x2;
481 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
482 edl->session->crop_y1 ^= edl->session->crop_y2;
483 edl->session->crop_y2 ^= edl->session->crop_y1;
484 edl->session->crop_y1 ^= edl->session->crop_y2;
487 float old_projector_x = (float)edl->session->output_w / 2;
488 float old_projector_y = (float)edl->session->output_h / 2;
489 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
490 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
491 float projector_offset_x = -(new_projector_x - old_projector_x);
492 float projector_offset_y = -(new_projector_y - old_projector_y);
494 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
496 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
497 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
498 edl->session->crop_x1 = 0;
499 edl->session->crop_y1 = 0;
500 edl->session->crop_x2 = edl->session->output_w;
501 edl->session->crop_y2 = edl->session->output_h;
503 // Recalculate aspect ratio
504 if( defaults->get("AUTOASPECT", 0) ) {
505 create_aspect_ratio(edl->session->aspect_w,
506 edl->session->aspect_h,
507 edl->session->output_w,
508 edl->session->output_h);
511 undo->update_undo_after(_("crop"), LOAD_ALL);
514 cwindow->playback_engine->que->
515 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
521 double start = edl->local_session->get_selectionstart();
522 double end = edl->local_session->get_selectionend();
526 void MWindow::cut(double start, double end, double new_position)
528 undo->update_undo_before();
530 edl->clear(start, end,
531 edl->session->labels_follow_edits,
532 edl->session->plugins_follow_edits,
533 edl->session->autos_follow_edits);
534 edl->deglitch(start);
539 undo->update_undo_after(_("cut"), LOAD_EDITS | LOAD_TIMEBAR);
540 if( new_position >= 0 ) {
541 edl->local_session->set_selectionstart(new_position);
542 edl->local_session->set_selectionend(new_position);
545 update_plugin_guis();
546 gui->update(1, 2, 1, 1, 1, 1, 0);
547 cwindow->update(1, 0, 0, 0, 1);
548 cwindow->playback_engine->que->
549 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
552 void MWindow::snap_left_edit()
554 double start_pos = edl->local_session->get_selectionstart(1);
555 double position = edl->prev_edit(start_pos);
556 if( position < start_pos )
557 cut(position, start_pos, position);
560 void MWindow::snap_right_edit()
562 double end_pos = edl->local_session->get_selectionend(1);
563 double position = edl->next_edit(end_pos);
564 if( end_pos < position )
565 cut(end_pos, position, end_pos);
568 void MWindow::snap_left_label()
570 double start_pos = edl->local_session->get_selectionstart(1);
571 Label *left_label = edl->labels->prev_label(start_pos);
572 if( !left_label ) return;
573 double position = left_label->position;
574 if( position < start_pos )
575 cut(position, start_pos, position);
578 void MWindow::snap_right_label()
580 double end_pos = edl->local_session->get_selectionend(1);
581 Label *right_label = edl->labels->next_label(end_pos);
582 if( !right_label ) return;
583 double position = right_label->position;
584 if( end_pos < position )
585 cut(end_pos, position, end_pos);
588 int MWindow::cut_automation()
590 undo->update_undo_before();
594 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
595 edl->local_session->get_selectionend());
597 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
601 update_plugin_guis();
602 gui->draw_overlays(1);
603 sync_parameters(CHANGE_PARAMS);
604 gui->update_patchbay();
605 cwindow->update(1, 0, 0);
609 int MWindow::cut_default_keyframe()
612 undo->update_undo_before();
613 copy_default_keyframe();
614 edl->tracks->clear_default_keyframe();
615 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
618 gui->draw_overlays(1);
619 sync_parameters(CHANGE_PARAMS);
620 gui->update_patchbay();
621 cwindow->update(1, 0, 0);
629 void MWindow::delete_inpoint()
631 edl->local_session->unset_inpoint();
635 void MWindow::delete_outpoint()
637 edl->local_session->unset_outpoint();
642 void MWindow::delete_track()
644 if( edl->tracks->last )
645 delete_track(edl->tracks->last);
648 void MWindow::delete_tracks()
650 undo->update_undo_before();
651 edl->tracks->delete_tracks();
652 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
656 update_plugin_states();
658 gui->update(1, 1, 1, 0, 1, 0, 0);
659 cwindow->playback_engine->que->
660 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
663 void MWindow::delete_track(Track *track)
665 undo->update_undo_before();
666 edl->tracks->delete_track(track);
667 undo->update_undo_after(_("delete track"), LOAD_ALL);
670 update_plugin_states();
672 gui->update(1, 1, 1, 0, 1, 0, 0);
673 cwindow->playback_engine->que->
674 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
679 // Insert data from clipboard
680 void MWindow::insert(double position, FileXML *file,
681 int edit_labels, int edit_plugins, int edit_autos,
684 // For clipboard pasting make the new edl use a separate session
685 // from the master EDL. Then it can be resampled to the master rates.
686 // For splice, overwrite, and dragging need same session to get the assets.
687 EDL *edl = new EDL(parent_edl);
688 ArrayList<EDL*> new_edls;
689 uint32_t load_flags = LOAD_ALL;
692 new_edls.append(edl);
693 edl->create_objects();
698 if( parent_edl ) load_flags &= ~LOAD_SESSION;
699 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
700 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
702 edl->load_xml(file, load_flags);
705 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
709 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
710 edit_labels, edit_plugins, edit_autos, 0); // overwrite
711 // if( vwindow->edl )
712 // printf("MWindow::insert 5 %f %f\n",
713 // vwindow->edl->local_session->in_point,
714 // vwindow->edl->local_session->out_point);
715 new_edls.remove_all();
716 edl->Garbage::remove_user();
717 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
720 void MWindow::insert_effects_canvas(double start,
723 Track *dest_track = session->track_highlighted;
724 if( !dest_track ) return;
726 undo->update_undo_before();
728 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
729 PluginServer *plugin = session->drag_pluginservers->values[i];
730 insert_effect(plugin->title, 0, dest_track,
731 i == 0 ? session->pluginset_highlighted : 0,
732 start, length, PLUGIN_STANDALONE);
736 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
738 sync_parameters(CHANGE_EDL);
739 // GUI updated in TrackCanvas, after current_operations are reset
742 void MWindow::insert_effects_cwindow(Track *dest_track)
744 if( !dest_track ) return;
746 undo->update_undo_before();
749 double length = dest_track->get_length();
751 if( edl->local_session->get_selectionend() >
752 edl->local_session->get_selectionstart() ) {
753 start = edl->local_session->get_selectionstart();
754 length = edl->local_session->get_selectionend() -
755 edl->local_session->get_selectionstart();
758 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
759 PluginServer *plugin = session->drag_pluginservers->values[i];
760 insert_effect(plugin->title, 0, dest_track, 0,
761 start, length, PLUGIN_STANDALONE);
765 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
767 sync_parameters(CHANGE_EDL);
768 gui->update(1, 1, 0, 0, 1, 0, 0);
771 void MWindow::insert_effect(char *title,
772 SharedLocation *shared_location,
775 int single_standalone)
777 Track *current = edl->tracks->first;
778 SharedLocation shared_location_local;
779 shared_location_local.copy_from(shared_location);
781 for( ; current; current = NEXT) {
782 if( current->data_type == data_type &&
784 insert_effect(title, &shared_location_local,
785 current, 0, 0, 0, plugin_type);
788 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
789 plugin_type = PLUGIN_SHAREDPLUGIN;
790 shared_location_local.module = edl->tracks->number_of(current);
791 shared_location_local.plugin = current->plugin_set.total - 1;
800 void MWindow::insert_effect(char *title,
801 SharedLocation *shared_location,
803 PluginSet *plugin_set,
808 KeyFrame *default_keyframe = 0;
809 PluginServer *server = 0;
810 // Get default keyframe
811 if( plugin_type == PLUGIN_STANDALONE ) {
812 default_keyframe = new KeyFrame;
813 server = new PluginServer(*scan_plugindb(title, track->data_type));
815 server->open_plugin(0, preferences, edl, 0);
816 server->save_data(default_keyframe);
818 // Insert plugin object
819 track->insert_effect(title, shared_location,
820 default_keyframe, plugin_set,
821 start, length, plugin_type);
824 if( plugin_type == PLUGIN_STANDALONE ) {
825 server->close_plugin();
827 delete default_keyframe;
831 int MWindow::modify_edithandles()
833 undo->update_undo_before();
834 edl->modify_edithandles(session->drag_start,
835 session->drag_position,
836 session->drag_handle,
837 edl->session->edit_handle_mode[session->drag_button],
838 edl->session->labels_follow_edits,
839 edl->session->plugins_follow_edits,
840 edl->session->autos_follow_edits);
842 finish_modify_handles();
843 //printf("MWindow::modify_handles 1\n");
847 int MWindow::modify_pluginhandles()
849 undo->update_undo_before();
851 edl->modify_pluginhandles(session->drag_start,
852 session->drag_position,
853 session->drag_handle,
854 edl->session->edit_handle_mode[session->drag_button],
855 edl->session->labels_follow_edits,
856 edl->session->autos_follow_edits,
857 session->trim_edits);
859 finish_modify_handles();
865 // Common to edithandles and plugin handles
866 void MWindow::finish_modify_handles()
868 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
870 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
871 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
872 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
873 edl->local_session->set_selectionstart(session->drag_position);
874 edl->local_session->set_selectionend(session->drag_position);
875 edl->deglitch(session->drag_position);
878 if( edit_mode != MOVE_NO_EDITS ) {
879 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
880 edl->local_session->set_selectionstart(session->drag_start);
881 edl->local_session->set_selectionend(session->drag_start);
882 edl->deglitch(session->drag_start);
885 // clamp the selection to 0
886 if( edl->local_session->get_selectionstart(1) < 0 ) {
887 edl->local_session->set_selectionstart(0);
888 edl->local_session->set_selectionend(0);
890 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
894 sync_parameters(CHANGE_EDL);
895 update_plugin_guis();
896 gui->update(1, 2, 1, 1, 1, 1, 0);
897 cwindow->update(1, 0, 0, 0, 1);
900 void MWindow::match_output_size(Track *track)
902 undo->update_undo_before();
903 track->track_w = edl->session->output_w;
904 track->track_h = edl->session->output_h;
906 undo->update_undo_after(_("match output size"), LOAD_ALL);
909 sync_parameters(CHANGE_EDL);
913 void MWindow::move_edits(ArrayList<Edit*> *edits,
918 undo->update_undo_before();
920 edl->tracks->move_edits(edits,
923 edl->session->labels_follow_edits,
924 edl->session->plugins_follow_edits,
925 edl->session->autos_follow_edits,
929 undo->update_undo_after(_("move edit"), LOAD_ALL);
932 cwindow->playback_engine->que->
933 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
935 update_plugin_guis();
936 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
940 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
942 undo->update_undo_before();
943 edl->tracks->move_effect(plugin, track, position);
945 undo->update_undo_after(_("paste effect"), LOAD_ALL);
948 cwindow->playback_engine->que->
949 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
950 update_plugin_guis();
951 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
955 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
957 undo->update_undo_before();
958 edl->tracks->move_effect(plugin, plugin_set, position);
960 undo->update_undo_after(_("move effect"), LOAD_ALL);
963 cwindow->playback_engine->que->
964 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
965 update_plugin_guis();
966 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
970 void MWindow::move_plugins_up(PluginSet *plugin_set)
973 undo->update_undo_before();
974 plugin_set->track->move_plugins_up(plugin_set);
977 undo->update_undo_after(_("move effect up"), LOAD_ALL);
979 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
981 sync_parameters(CHANGE_EDL);
984 void MWindow::move_plugins_down(PluginSet *plugin_set)
986 undo->update_undo_before();
988 plugin_set->track->move_plugins_down(plugin_set);
991 undo->update_undo_after(_("move effect down"), LOAD_ALL);
993 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
995 sync_parameters(CHANGE_EDL);
998 void MWindow::move_track_down(Track *track)
1000 undo->update_undo_before();
1001 edl->tracks->move_track_down(track);
1003 undo->update_undo_after(_("move track down"), LOAD_ALL);
1006 gui->update(1, 1, 0, 0, 1, 0, 0);
1007 sync_parameters(CHANGE_EDL);
1011 void MWindow::move_tracks_down()
1013 undo->update_undo_before();
1014 edl->tracks->move_tracks_down();
1016 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1019 gui->update(1, 1, 0, 0, 1, 0, 0);
1020 sync_parameters(CHANGE_EDL);
1024 void MWindow::move_track_up(Track *track)
1026 undo->update_undo_before();
1027 edl->tracks->move_track_up(track);
1029 undo->update_undo_after(_("move track up"), LOAD_ALL);
1031 gui->update(1, 1, 0, 0, 1, 0, 0);
1032 sync_parameters(CHANGE_EDL);
1036 void MWindow::move_tracks_up()
1038 undo->update_undo_before();
1039 edl->tracks->move_tracks_up();
1041 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1043 gui->update(1, 1, 0, 0, 1, 0, 0);
1044 sync_parameters(CHANGE_EDL);
1048 void MWindow::mute_selection()
1050 double start = edl->local_session->get_selectionstart();
1051 double end = edl->local_session->get_selectionend();
1052 if( start != end ) {
1053 undo->update_undo_before();
1054 edl->clear(start, end, 0,
1055 edl->session->plugins_follow_edits,
1056 edl->session->autos_follow_edits);
1057 edl->local_session->set_selectionend(end);
1058 edl->local_session->set_selectionstart(start);
1059 edl->paste_silence(start, end, 0,
1060 edl->session->plugins_follow_edits,
1061 edl->session->autos_follow_edits);
1062 edl->deglitch(start);
1067 undo->update_undo_after(_("mute"), LOAD_EDITS);
1070 update_plugin_guis();
1071 gui->update(1, 2, 1, 1, 1, 1, 0);
1072 cwindow->playback_engine->que->
1073 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1078 void MWindow::overwrite(EDL *source)
1082 double src_start = source->local_session->get_selectionstart();
1083 double overwrite_len = source->local_session->get_selectionend() - src_start;
1084 double dst_start = edl->local_session->get_selectionstart();
1085 double dst_len = edl->local_session->get_selectionend() - dst_start;
1087 undo->update_undo_before();
1088 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1089 // in/out points or selection present and shorter than overwrite range
1090 // shorten the copy range
1091 overwrite_len = dst_len;
1094 source->copy(src_start, src_start + overwrite_len,
1095 1, 0, 0, &file, "", 1);
1097 // HACK around paste_edl get_start/endselection on its own
1098 // so we need to clear only when not using both io points
1099 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1100 if( edl->local_session->get_inpoint() < 0 ||
1101 edl->local_session->get_outpoint() < 0 )
1102 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1104 paste(dst_start, dst_start + overwrite_len,
1107 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1108 edl->local_session->set_selectionend(dst_start + overwrite_len);
1111 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1114 update_plugin_guis();
1115 gui->update(1, 1, 1, 1, 0, 1, 0);
1116 sync_parameters(CHANGE_EDL);
1119 // For splice and overwrite
1120 int MWindow::paste(double start,
1129 // Want to insert with assets shared with the master EDL.
1131 edit_labels, edit_plugins, edit_autos,
1137 // For editing using insertion point
1138 void MWindow::paste()
1140 double start = edl->local_session->get_selectionstart();
1141 //double end = edl->local_session->get_selectionend();
1142 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1145 char *string = new char[len];
1146 undo->update_undo_before();
1147 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1149 file.read_from_string(string);
1152 insert(start, &file,
1153 edl->session->labels_follow_edits,
1154 edl->session->plugins_follow_edits,
1155 edl->session->autos_follow_edits,
1163 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1165 update_plugin_guis();
1166 gui->update(1, 2, 1, 1, 0, 1, 0);
1167 awindow->gui->async_update_assets();
1168 sync_parameters(CHANGE_EDL);
1173 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1176 undo->update_undo_before();
1178 if( session->drag_assets->total ) {
1179 load_assets(session->drag_assets,
1180 position, LOADMODE_PASTE, dest_track, 0,
1181 edl->session->labels_follow_edits,
1182 edl->session->plugins_follow_edits,
1183 edl->session->autos_follow_edits,
1188 if( session->drag_clips->total ) {
1189 paste_edls(session->drag_clips,
1190 LOADMODE_PASTE, dest_track, position,
1191 edl->session->labels_follow_edits,
1192 edl->session->plugins_follow_edits,
1193 edl->session->autos_follow_edits,
1200 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1202 gui->update(1, 2, 1, 0, 0, 1, 0);
1203 sync_parameters(CHANGE_EDL);
1207 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1208 double position, int load_mode, Track *first_track, RecordLabels *labels,
1209 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1211 if( load_mode == LOADMODE_RESOURCESONLY )
1212 load_mode = LOADMODE_ASSETSONLY;
1213 const int debug = 0;
1214 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1215 if( position < 0 ) position = edl->local_session->get_selectionstart();
1217 ArrayList<EDL*> new_edls;
1218 for( int i = 0; i < new_assets->total; i++ ) {
1219 Indexable *indexable = new_assets->get(i);
1220 if( indexable->is_asset ) {
1221 remove_asset_from_caches((Asset*)indexable);
1223 EDL *new_edl = new EDL;
1224 new_edl->create_objects();
1225 new_edl->copy_session(edl);
1226 new_edls.append(new_edl);
1229 if( indexable->is_asset ) {
1230 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1231 if( debug ) ((Asset*)indexable)->dump();
1232 asset_to_edl(new_edl, (Asset*)indexable);
1235 edl_to_nested(new_edl, (EDL*)indexable);
1236 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1240 for( RecordLabel *label = labels->first; label; label = label->next ) {
1241 new_edl->labels->toggle_label(label->position, label->position);
1245 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1247 paste_edls(&new_edls, load_mode, first_track, position,
1248 edit_labels, edit_plugins, edit_autos, overwrite);
1249 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1252 for( int i = 0; i < new_edls.size(); i++ )
1253 new_edls.get(i)->Garbage::remove_user();
1255 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1258 int MWindow::paste_automation()
1260 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1263 undo->update_undo_before();
1264 char *string = new char[len];
1265 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1267 file.read_from_string(string);
1269 double start = edl->local_session->get_selectionstart();
1270 double end = edl->local_session->get_selectionend();
1271 edl->tracks->clear_automation(start, end);
1272 edl->tracks->paste_automation(start, &file, 0, 1,
1273 edl->session->typeless_keyframes);
1275 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1279 update_plugin_guis();
1280 gui->draw_overlays(1);
1281 sync_parameters(CHANGE_PARAMS);
1282 gui->update_patchbay();
1283 cwindow->update(1, 0, 0);
1289 int MWindow::paste_default_keyframe()
1291 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1294 undo->update_undo_before();
1295 char *string = new char[len];
1296 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1298 file.read_from_string(string);
1299 double start = edl->local_session->get_selectionstart();
1300 edl->tracks->paste_automation(start, &file, 1, 0,
1301 edl->session->typeless_keyframes);
1302 // edl->tracks->paste_default_keyframe(&file);
1303 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1306 update_plugin_guis();
1307 gui->draw_overlays(1);
1308 sync_parameters(CHANGE_PARAMS);
1309 gui->update_patchbay();
1310 cwindow->update(1, 0, 0);
1319 // Insert edls with project deletion and index file generation.
1320 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1321 Track *first_track, double current_position,
1322 int edit_labels, int edit_plugins, int edit_autos,
1326 ArrayList<Track*> destination_tracks;
1327 int need_new_tracks = 0;
1330 if( !new_edls->total ) return 0;
1333 // double original_length = edl->tracks->total_playable_length();
1334 // double original_preview_end = edl->local_session->preview_end;
1337 // Delete current project
1338 if( load_mode == LOADMODE_REPLACE ||
1339 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1341 edl->save_defaults(defaults);
1343 edl->Garbage::remove_user();
1345 edl->create_objects();
1346 edl->copy_session(new_edls->values[0]);
1347 gui->mainmenu->update_toggles(0);
1348 gui->unlock_window();
1349 gwindow->gui->update_toggles(1);
1350 gui->lock_window("MWindow::paste_edls");
1352 // Insert labels for certain modes constitutively
1356 // Force reset of preview
1357 // original_length = 0;
1358 // original_preview_end = -1;
1364 // Create new tracks in master EDL
1365 if( load_mode == LOADMODE_REPLACE ||
1366 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1367 load_mode == LOADMODE_NEW_TRACKS ) {
1369 need_new_tracks = 1;
1370 for( int i = 0; i < new_edls->total; i++ ) {
1371 EDL *new_edl = new_edls->values[i];
1372 for( Track *current = new_edl->tracks->first;
1375 if( current->data_type == TRACK_VIDEO ) {
1376 edl->tracks->add_video_track(0, 0);
1377 if( current->draw ) edl->tracks->last->draw = 1;
1378 destination_tracks.append(edl->tracks->last);
1381 if( current->data_type == TRACK_AUDIO ) {
1382 edl->tracks->add_audio_track(0, 0);
1383 destination_tracks.append(edl->tracks->last);
1386 if( current->data_type == TRACK_SUBTITLE ) {
1387 edl->tracks->add_subttl_track(0, 0);
1388 destination_tracks.append(edl->tracks->last);
1390 edl->session->highlighted_track = edl->tracks->total() - 1;
1393 // Base track count on first EDL only for concatenation
1394 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1399 // Recycle existing tracks of master EDL
1400 if( load_mode == LOADMODE_CONCATENATE ||
1401 load_mode == LOADMODE_PASTE ||
1402 load_mode == LOADMODE_NESTED ) {
1405 // The point of this is to shift forward labels after the selection so they can
1406 // then be shifted back to their original locations without recursively
1407 // shifting back every paste.
1408 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1409 edl->session->labels_follow_edits )
1410 edl->labels->clear(edl->local_session->get_selectionstart(),
1411 edl->local_session->get_selectionend(),
1414 Track *current = first_track ? first_track : edl->tracks->first;
1415 for( ; current; current = NEXT) {
1416 if( current->record ) {
1417 destination_tracks.append(current);
1424 int destination_track = 0;
1425 double *paste_position = new double[destination_tracks.total];
1427 // Iterate through the edls
1428 for( int i = 0; i < new_edls->total; i++ ) {
1430 EDL *new_edl = new_edls->values[i];
1431 double edl_length = new_edl->local_session->clipboard_length ?
1432 new_edl->local_session->clipboard_length :
1433 new_edl->tracks->total_length();
1434 // printf("MWindow::paste_edls 2 %f %f\n",
1435 // new_edl->local_session->clipboard_length,
1436 // new_edl->tracks->total_length());
1440 // Convert EDL to master rates
1441 new_edl->resample(new_edl->session->sample_rate,
1442 edl->session->sample_rate,
1444 new_edl->resample(new_edl->session->frame_rate,
1445 edl->session->frame_rate,
1448 // Add assets and prepare index files
1449 for( Asset *new_asset = new_edl->assets->first;
1451 new_asset = new_asset->next ) {
1452 mainindexes->add_next_asset(0, new_asset);
1454 // Capture index file status from mainindex test
1455 edl->update_assets(new_edl);
1457 // Get starting point of insertion. Need this to paste labels.
1458 switch( load_mode ) {
1459 case LOADMODE_REPLACE:
1460 case LOADMODE_NEW_TRACKS:
1461 current_position = 0;
1464 case LOADMODE_CONCATENATE:
1465 case LOADMODE_REPLACE_CONCATENATE:
1466 destination_track = 0;
1467 if( destination_tracks.total )
1468 current_position = destination_tracks.values[0]->get_length();
1470 current_position = 0;
1473 case LOADMODE_PASTE:
1474 case LOADMODE_NESTED:
1475 destination_track = 0;
1477 for( int j = 0; j < destination_tracks.total; j++ ) {
1478 paste_position[j] = (current_position >= 0) ?
1480 edl->local_session->get_selectionstart();
1485 case LOADMODE_RESOURCESONLY:
1486 edl->add_clip(new_edl);
1491 if( load_mode != LOADMODE_RESOURCESONLY &&
1492 load_mode != LOADMODE_ASSETSONLY ) {
1494 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1495 if( load_mode == LOADMODE_PASTE ||
1496 load_mode == LOADMODE_NESTED )
1497 edl->labels->insert_labels(new_edl->labels,
1498 destination_tracks.total ? paste_position[0] : 0.0,
1502 edl->labels->insert_labels(new_edl->labels,
1508 for( Track *new_track = new_edl->tracks->first;
1510 new_track = new_track->next ) {
1511 // Get destination track of same type as new_track
1513 k < destination_tracks.total &&
1514 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1515 k++, destination_track++ ) {
1516 if( destination_track >= destination_tracks.total - 1 )
1517 destination_track = 0;
1520 // Insert data into destination track
1521 if( destination_track < destination_tracks.total &&
1522 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1523 Track *track = destination_tracks.values[destination_track];
1525 // Replace default keyframes if first EDL and new tracks were created.
1526 // This means data copied from one track and pasted to another won't retain
1527 // the camera position unless it's a keyframe. If it did, previous data in the
1528 // track might get unknowingly corrupted. Ideally we would detect when differing
1529 // default keyframes existed and create discrete keyframes for both.
1530 int replace_default = (i == 0) && need_new_tracks;
1532 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1533 // Insert new track at current position
1534 switch( load_mode ) {
1535 case LOADMODE_REPLACE_CONCATENATE:
1536 case LOADMODE_CONCATENATE:
1537 current_position = track->get_length();
1540 case LOADMODE_PASTE:
1541 case LOADMODE_NESTED:
1542 current_position = paste_position[destination_track];
1543 paste_position[destination_track] += new_track->get_length();
1547 track->clear(current_position,
1548 current_position + new_track->get_length(),
1550 edit_labels, edit_plugins, edit_autos,
1555 track->insert_track(new_track, current_position, replace_default,
1556 edit_plugins, edit_autos, edl_length);
1560 // Get next destination track
1561 destination_track++;
1562 if( destination_track >= destination_tracks.total )
1563 destination_track = 0;
1567 if( load_mode == LOADMODE_PASTE ||
1568 load_mode == LOADMODE_NESTED )
1569 current_position += edl_length;
1573 // Move loading of clips and vwindow to the end - this fixes some
1574 // strange issue, for index not being shown
1575 // Assume any paste operation from the same EDL won't contain any clips.
1576 // If it did it would duplicate every clip here.
1577 for( int i = 0; i < new_edls->total; i++ ) {
1578 EDL *new_edl = new_edls->values[i];
1580 for( int j = 0; j < new_edl->clips.total; j++ ) {
1581 edl->add_clip(new_edl->clips.values[j]);
1584 if( new_edl->total_vwindow_edls() ) {
1585 // if( edl->vwindow_edl )
1586 // edl->vwindow_edl->Garbage::remove_user();
1587 // edl->vwindow_edl = new EDL(edl);
1588 // edl->vwindow_edl->create_objects();
1589 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1591 for( int j = 0; j < new_edl->total_vwindow_edls(); j++ ) {
1592 EDL *vwindow_edl = new EDL(edl);
1593 vwindow_edl->create_objects();
1594 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1595 edl->append_vwindow_edl(vwindow_edl, 0);
1600 if( paste_position ) delete [] paste_position;
1602 // This is already done in load_filenames and everything else that uses paste_edls
1603 // update_project(load_mode);
1605 // Fix preview range
1606 // if( EQUIV(original_length, original_preview_end) )
1608 // edl->local_session->preview_end = edl->tracks->total_playable_length();
1611 // Start examining next batch of index files
1612 mainindexes->start_build();
1614 // Don't save a backup after loading since the loaded file is on disk already.
1619 void MWindow::paste_silence()
1621 double start = edl->local_session->get_selectionstart();
1622 double end = edl->local_session->get_selectionend();
1623 undo->update_undo_before();
1624 edl->paste_silence(start, end,
1625 edl->session->labels_follow_edits,
1626 edl->session->plugins_follow_edits,
1627 edl->session->autos_follow_edits);
1628 edl->deglitch(start);
1632 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1634 update_plugin_guis();
1636 gui->update(1, 2, 1, 1, 1, 1, 0);
1637 cwindow->update(1, 0, 0, 0, 1);
1638 cwindow->playback_engine->que->
1639 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1642 void MWindow::detach_transition(Transition *transition)
1644 undo->update_undo_before();
1645 hide_plugin(transition, 1);
1646 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1647 transition->edit->detach_transition();
1649 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1651 if( is_video ) restart_brender();
1652 gui->update(0, 1, 0, 0, 0, 0, 0);
1653 sync_parameters(CHANGE_EDL);
1656 void MWindow::detach_transitions()
1658 gui->lock_window("MWindow::detach_transitions 1");
1660 undo->update_undo_before();
1661 double start = edl->local_session->get_selectionstart();
1662 double end = edl->local_session->get_selectionend();
1663 edl->tracks->clear_transitions(start, end);
1666 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1668 sync_parameters(CHANGE_EDL);
1669 gui->update(0, 1, 0, 0, 0, 0, 0);
1670 gui->unlock_window();
1673 void MWindow::paste_transition()
1675 // Only the first transition gets dropped.
1676 PluginServer *server = session->drag_pluginservers->values[0];
1678 undo->update_undo_before();
1680 strcpy(edl->session->default_atransition, server->title);
1682 strcpy(edl->session->default_vtransition, server->title);
1684 edl->tracks->paste_transition(server, session->edit_highlighted);
1686 undo->update_undo_after(_("transition"), LOAD_EDITS);
1688 if( server->video ) restart_brender();
1689 sync_parameters(CHANGE_ALL);
1692 void MWindow::paste_transitions(int track_type, char *title)
1694 gui->lock_window("MWindow::detach_transitions 1");
1696 undo->update_undo_before();
1697 double start = edl->local_session->get_selectionstart();
1698 double end = edl->local_session->get_selectionend();
1699 edl->tracks->paste_transitions(start, end, track_type, title);
1702 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1704 sync_parameters(CHANGE_EDL);
1705 gui->update(0, 1, 0, 0, 0, 0, 0);
1706 gui->unlock_window();
1709 void MWindow::paste_transition_cwindow(Track *dest_track)
1711 PluginServer *server = session->drag_pluginservers->values[0];
1712 undo->update_undo_before();
1713 edl->tracks->paste_video_transition(server, 1);
1715 undo->update_undo_after(_("transition"), LOAD_EDITS);
1717 gui->update(0, 1, 0, 0, 0, 0, 0);
1718 sync_parameters(CHANGE_ALL);
1721 void MWindow::paste_audio_transition()
1723 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1726 char string[BCTEXTLEN];
1727 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1728 gui->show_message(string);
1732 undo->update_undo_before();
1733 edl->tracks->paste_audio_transition(server);
1735 undo->update_undo_after(_("transition"), LOAD_EDITS);
1737 sync_parameters(CHANGE_EDL);
1738 gui->update(0, 1, 0, 0, 0, 0, 0);
1741 void MWindow::paste_video_transition()
1743 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1746 char string[BCTEXTLEN];
1747 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1748 gui->show_message(string);
1752 undo->update_undo_before();
1754 edl->tracks->paste_video_transition(server);
1756 undo->update_undo_after(_("transition"), LOAD_EDITS);
1758 sync_parameters(CHANGE_EDL);
1760 gui->update(0, 1, 0, 0, 0, 0, 0);
1763 void MWindow::shuffle_edits()
1765 gui->lock_window("MWindow::shuffle_edits 1");
1767 undo->update_undo_before();
1768 double start = edl->local_session->get_selectionstart();
1769 double end = edl->local_session->get_selectionend();
1771 edl->tracks->shuffle_edits(start, end);
1774 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1776 sync_parameters(CHANGE_EDL);
1778 gui->update(0, 1, 1, 0, 0, 0, 0);
1779 gui->unlock_window();
1782 void MWindow::reverse_edits()
1784 gui->lock_window("MWindow::reverse_edits 1");
1786 undo->update_undo_before();
1787 double start = edl->local_session->get_selectionstart();
1788 double end = edl->local_session->get_selectionend();
1790 edl->tracks->reverse_edits(start, end);
1793 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1795 sync_parameters(CHANGE_EDL);
1797 gui->update(0, 1, 1, 0, 0, 0, 0);
1798 gui->unlock_window();
1801 void MWindow::align_edits()
1803 gui->lock_window("MWindow::align_edits 1");
1805 undo->update_undo_before();
1806 double start = edl->local_session->get_selectionstart();
1807 double end = edl->local_session->get_selectionend();
1809 edl->tracks->align_edits(start, end);
1812 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1814 sync_parameters(CHANGE_EDL);
1816 gui->update(0, 1, 1, 0, 0, 0, 0);
1817 gui->unlock_window();
1820 void MWindow::set_edit_length(double length)
1822 gui->lock_window("MWindow::detach_transitions 1");
1824 undo->update_undo_before();
1825 double start = edl->local_session->get_selectionstart();
1826 double end = edl->local_session->get_selectionend();
1828 edl->tracks->set_edit_length(start, end, length);
1831 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1833 sync_parameters(CHANGE_EDL);
1835 gui->update(0, 1, 1, 0, 0, 0, 0);
1836 gui->unlock_window();
1840 void MWindow::set_transition_length(Transition *transition, double length)
1842 gui->lock_window("MWindow::detach_transitions 1");
1844 undo->update_undo_before();
1845 //double start = edl->local_session->get_selectionstart();
1846 //double end = edl->local_session->get_selectionend();
1848 edl->tracks->set_transition_length(transition, length);
1851 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1853 edl->session->default_transition_length = length;
1854 sync_parameters(CHANGE_PARAMS);
1855 gui->update(0, 1, 0, 0, 0, 0, 0);
1856 gui->unlock_window();
1859 void MWindow::set_transition_length(double length)
1861 gui->lock_window("MWindow::detach_transitions 1");
1863 undo->update_undo_before();
1864 double start = edl->local_session->get_selectionstart();
1865 double end = edl->local_session->get_selectionend();
1867 edl->tracks->set_transition_length(start, end, length);
1870 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1872 edl->session->default_transition_length = length;
1873 sync_parameters(CHANGE_PARAMS);
1875 gui->update(0, 1, 0, 0, 0, 0, 0);
1876 gui->unlock_window();
1880 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1883 calling_window_gui->unlock_window();
1885 cwindow->playback_engine->que->
1886 send_command(STOP, CHANGE_NONE, 0, 0);
1887 cwindow->playback_engine->interrupt_playback(0);
1889 for( int i = 0; i < vwindows.size(); i++ ) {
1890 if( vwindows.get(i)->is_running() ) {
1891 vwindows.get(i)->playback_engine->que->
1892 send_command(STOP, CHANGE_NONE, 0, 0);
1893 vwindows.get(i)->playback_engine->interrupt_playback(0);
1897 cwindow->gui->lock_window("MWindow::redo_entry");
1898 for( int i = 0; i < vwindows.size(); i++ ) {
1899 if( vwindows.get(i)->is_running() ) {
1900 if( calling_window_gui != vwindows.get(i)->gui ) {
1901 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1910 update_plugin_states();
1911 update_plugin_guis();
1913 gui->update(1, 2, 1, 1, 1, 1, 1);
1914 cwindow->update(1, 1, 1, 1, 1);
1916 if( calling_window_gui != cwindow->gui )
1917 cwindow->gui->unlock_window();
1918 if( calling_window_gui != gui )
1919 gui->unlock_window();
1922 for( int i = 0; i < vwindows.size(); i++ ) {
1923 if( vwindows.get(i)->is_running() ) {
1924 if( calling_window_gui != vwindows.get(i)->gui ) {
1925 vwindows.get(i)->gui->unlock_window();
1930 cwindow->playback_engine->que->
1931 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
1935 void MWindow::resize_track(Track *track, int w, int h)
1937 undo->update_undo_before();
1938 // We have to move all maskpoints so they do not move in relation to image areas
1939 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1940 (w - track->track_w) / 2,
1941 (h - track->track_h) / 2);
1944 undo->update_undo_after(_("resize track"), LOAD_ALL);
1948 sync_parameters(CHANGE_EDL);
1952 void MWindow::set_inpoint(int is_mwindow)
1954 undo->update_undo_before();
1955 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1957 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1960 gui->lock_window("MWindow::set_inpoint 1");
1962 gui->update_timebar(1);
1964 gui->unlock_window();
1968 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1970 cwindow->gui->timebar->update(1);
1972 cwindow->gui->unlock_window();
1976 void MWindow::set_outpoint(int is_mwindow)
1978 undo->update_undo_before();
1979 edl->set_outpoint(edl->local_session->get_selectionend(1));
1981 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1984 gui->lock_window("MWindow::set_outpoint 1");
1986 gui->update_timebar(1);
1988 gui->unlock_window();
1992 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1994 cwindow->gui->timebar->update(1);
1996 cwindow->gui->unlock_window();
2000 void MWindow::splice(EDL *source)
2004 undo->update_undo_before();
2005 double source_start = source->local_session->get_selectionstart();
2006 double source_end = source->local_session->get_selectionend();
2007 source->copy(source_start, source_end, 1, 0, 0, &file, "", 1);
2009 double start = edl->local_session->get_selectionstart();
2010 //double end = edl->local_session->get_selectionend();
2012 paste(start, start, &file,
2013 edl->session->labels_follow_edits,
2014 edl->session->plugins_follow_edits,
2015 edl->session->autos_follow_edits);
2017 // Position at end of clip
2018 edl->local_session->set_selectionstart(start + source_end - source_start);
2019 edl->local_session->set_selectionend(start + source_end - source_start);
2022 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2023 update_plugin_guis();
2025 gui->update(1, 1, 1, 1, 0, 1, 0);
2026 sync_parameters(CHANGE_EDL);
2029 void MWindow::save_clip(EDL *new_edl, const char *txt)
2031 new_edl->local_session->set_selectionstart(0);
2032 new_edl->local_session->set_selectionend(0);
2033 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2034 session->clip_number++);
2035 char duration[BCTEXTLEN];
2036 Units::totext(duration, new_edl->tracks->total_length(),
2037 new_edl->session->time_format,
2038 new_edl->session->sample_rate,
2039 new_edl->session->frame_rate,
2040 new_edl->session->frames_per_foot);
2042 Track *track = new_edl->tracks->first;
2043 const char *path = edl->path;
2044 for( ; (!path || !*path) && track; track=track->next ) {
2045 if( !track->record ) continue;
2046 Edit *edit = track->edits->first;
2047 if( !edit ) continue;
2048 Indexable *indexable = edit->get_source();
2049 if( !indexable ) continue;
2050 path = indexable->path;
2053 time_t now; time(&now);
2054 struct tm *tm = localtime(&now);
2055 char *cp = new_edl->local_session->clip_notes;
2056 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2058 n = snprintf(cp, sz, "%s", txt);
2061 n = snprintf(cp, sz,
2062 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2063 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
2064 tm->tm_hour, tm->tm_min, tm->tm_sec, duration);
2066 if( path && *path ) {
2068 char title[BCTEXTLEN];
2069 fs.extract_name(title, path);
2070 n = snprintf(cp, sz, "%s", title);
2075 edl->update_assets(new_edl);
2077 gui->get_abs_cursor_xy(cur_x, cur_y, 0);
2078 gui->unlock_window();
2080 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2082 gui->lock_window("MWindow::save_clip");
2086 void MWindow::to_clip(EDL *edl, const char *txt)
2091 gui->lock_window("MWindow::to_clip 1");
2092 start = edl->local_session->get_selectionstart();
2093 end = edl->local_session->get_selectionend();
2095 if( EQUIV(end, start) ) {
2097 end = edl->tracks->total_length();
2100 // Don't copy all since we don't want the clips twice.
2101 edl->copy(start, end, 0, 0, 0, &file, "", 1);
2103 EDL *new_edl = new EDL(edl);
2104 new_edl->create_objects();
2105 new_edl->load_xml(&file, LOAD_ALL);
2106 save_clip(new_edl, txt);
2107 gui->unlock_window();
2110 int MWindow::toggle_label(int is_mwindow)
2112 double position1, position2;
2113 undo->update_undo_before();
2115 if( cwindow->playback_engine->is_playing_back ) {
2116 position1 = position2 =
2117 cwindow->playback_engine->get_tracking_position();
2120 position1 = edl->local_session->get_selectionstart(1);
2121 position2 = edl->local_session->get_selectionend(1);
2124 position1 = edl->align_to_frame(position1, 0);
2125 position2 = edl->align_to_frame(position2, 0);
2127 //printf("MWindow::toggle_label 1\n");
2129 edl->labels->toggle_label(position1, position2);
2133 gui->lock_window("MWindow::toggle_label 1");
2135 gui->update_timebar(0);
2136 gui->activate_timeline();
2139 gui->unlock_window();
2143 cwindow->gui->lock_window("MWindow::toggle_label 2");
2145 cwindow->gui->timebar->update(1);
2147 cwindow->gui->unlock_window();
2150 awindow->gui->async_update_assets();
2152 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2156 void MWindow::trim_selection()
2158 undo->update_undo_before();
2161 edl->trim_selection(edl->local_session->get_selectionstart(),
2162 edl->local_session->get_selectionend(),
2163 edl->session->labels_follow_edits,
2164 edl->session->plugins_follow_edits,
2165 edl->session->autos_follow_edits);
2167 edl->deglitch(edl->local_session->get_selectionend() -
2168 edl->local_session->get_selectionstart());
2172 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2173 update_plugin_guis();
2174 gui->update(1, 2, 1, 1, 1, 1, 0);
2175 cwindow->update(1, 0, 0, 0, 1);
2177 cwindow->playback_engine->que->
2178 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
2182 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2184 calling_window_gui->unlock_window();
2186 cwindow->playback_engine->que->
2187 send_command(STOP, CHANGE_NONE, 0, 0);
2188 cwindow->playback_engine->interrupt_playback(0);
2190 //printf("MWindow::undo_entry %d %d\n", __LINE__, vwindows.size());
2191 for( int i = 0; i < vwindows.size(); i++ ) {
2192 if( vwindows.get(i)->is_running() ) {
2193 vwindows.get(i)->playback_engine->que->
2194 send_command(STOP, CHANGE_NONE, 0, 0);
2195 vwindows.get(i)->playback_engine->interrupt_playback(0);
2199 cwindow->gui->lock_window("MWindow::undo_entry 1");
2200 for( int i = 0; i < vwindows.size(); i++ ) {
2201 if( vwindows.get(i)->is_running() ) {
2202 if( calling_window_gui != vwindows.get(i)->gui ) {
2203 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2207 gui->lock_window("MWindow::undo_entry 2");
2213 update_plugin_states();
2214 update_plugin_guis();
2216 gui->update(1, 2, 1, 1, 1, 1, 1);
2217 gui->unlock_window();
2218 cwindow->update(1, 1, 1, 1, 1);
2219 cwindow->gui->unlock_window();
2221 for( int i = 0; i < vwindows.size(); i++ ) {
2222 if( vwindows.get(i)->is_running() ) {
2223 if( calling_window_gui != vwindows.get(i)->gui ) {
2224 vwindows.get(i)->gui->unlock_window();
2229 if( calling_window_gui != gui )
2230 gui->unlock_window();
2232 awindow->gui->async_update_assets();
2234 cwindow->playback_engine->que->
2235 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
2236 calling_window_gui->lock_window("MWindow::undo_entry 4");
2240 void MWindow::new_folder(const char *new_folder)
2242 undo->update_undo_before();
2243 edl->new_folder(new_folder);
2244 undo->update_undo_after(_("new folder"), LOAD_ALL);
2245 awindow->gui->async_update_assets();
2248 void MWindow::delete_folder(char *folder)
2250 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2253 void MWindow::select_point(double position)
2255 edl->local_session->set_selectionstart(position);
2256 edl->local_session->set_selectionend(position);
2259 cwindow->update(1, 0, 0, 0, 1);
2261 update_plugin_guis();
2262 gui->update_patchbay();
2263 gui->hide_cursor(0);
2264 gui->draw_cursor(0);
2265 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2266 gui->zoombar->update();
2267 gui->update_timebar(0);
2268 gui->flash_canvas(0);
2275 void MWindow::map_audio(int pattern)
2277 undo->update_undo_before();
2278 remap_audio(pattern);
2279 undo->update_undo_after(
2280 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2282 sync_parameters(CHANGE_PARAMS);
2283 gui->update(0, 1, 0, 0, 1, 0, 0);
2286 void MWindow::remap_audio(int pattern)
2288 int current_channel = 0;
2289 int current_track = 0;
2290 for( Track *current = edl->tracks->first; current; current = NEXT ) {
2291 if( current->data_type == TRACK_AUDIO &&
2293 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2294 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2296 for( int i = 0; i < MAXCHANNELS; i++ ) {
2297 pan_auto->values[i] = 0.0;
2300 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2301 pan_auto->values[current_channel] = 1.0;
2304 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2305 switch( current_track ) {
2307 pan_auto->values[0] = 0.5;
2308 pan_auto->values[1] = 0.5;
2311 pan_auto->values[0] = 1;
2314 pan_auto->values[1] = 1;
2317 pan_auto->values[0] = 1;
2320 pan_auto->values[1] = 1;
2323 pan_auto->values[0] = 0.5;
2324 pan_auto->values[1] = 0.5;
2329 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2330 edl->session->achannel_positions, pan_auto->values,
2331 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2335 if( current_channel >= edl->session->audio_channels )
2336 current_channel = 0;
2341 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2342 ArrayList<Indexable*> *orig_assets,
2343 ArrayList<Indexable*> *proxy_assets)
2345 int orig_use_scaler = edl->session->proxy_use_scaler;
2346 int orig_scale = edl->session->proxy_scale;
2347 // rescale to full size asset in read_frame
2348 edl->session->proxy_use_scaler = use_scaler;
2349 edl->session->proxy_scale = new_scale;
2350 edl->session->proxy_auto_scale = auto_scale;
2353 for( int i=0; i<proxy_assets->size(); ++i ) {
2354 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2355 proxy_asset->width = orig_assets->get(i)->get_w();
2356 proxy_asset->height = orig_assets->get(i)->get_h();
2361 if( !orig_use_scaler && new_scale != orig_scale ) {
2363 float orig_w = (float)edl->session->output_w * orig_scale;
2364 float orig_h = (float)edl->session->output_h * orig_scale;
2365 edl->session->output_w = Units::round(orig_w / new_scale);
2366 edl->session->output_h = Units::round(orig_h / new_scale);
2369 for( Track *track=edl->tracks->first; track; track=track->next ) {
2370 if( track->data_type != TRACK_VIDEO ) continue;
2371 orig_w = (float)track->track_w * orig_scale;
2372 orig_h = (float)track->track_h * orig_scale;
2373 track->track_w = Units::round(orig_w / new_scale);
2374 track->track_h = Units::round(orig_h / new_scale);
2375 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2376 set_proxy(orig_scale, new_scale);
2377 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2378 set_proxy(orig_scale, new_scale);
2379 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2380 set_proxy(orig_scale, new_scale);
2381 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2382 set_proxy(orig_scale, new_scale);
2383 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2384 set_proxy(orig_scale, new_scale);
2388 // change original assets to proxy assets
2389 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2390 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2391 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2392 proxy_asset->awindow_folder = awindow_folder;
2393 // replace track contents
2394 for( Track *track = edl->tracks->first; track; track = track->next ) {
2395 if( track->data_type != TRACK_VIDEO ) continue;
2396 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2397 if( !edit->asset ) continue;
2398 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2399 edit->asset = proxy_asset;
2406 void MWindow::add_proxy(int use_scaler,
2407 ArrayList<Indexable*> *orig_assets,
2408 ArrayList<Indexable*> *proxy_assets)
2411 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2412 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2413 proxy_asset->width = orig_assets->get(i)->get_w();
2414 proxy_asset->height = orig_assets->get(i)->get_h();
2418 // change original assets to proxy assets
2419 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2420 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2421 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2422 // replace track contents
2423 for( Track *track = edl->tracks->first; track; track = track->next ) {
2424 if( track->data_type != TRACK_VIDEO ) continue;
2425 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2426 if( !edit->asset ) continue;
2427 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2428 edit->asset = proxy_asset;
2435 void MWindow::cut_commercials()
2437 undo->update_undo_before();
2438 commercials->scan_media();
2441 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2444 update_plugin_guis();
2445 gui->update(1, 2, 1, 1, 1, 1, 0);
2446 cwindow->update(1, 0, 0, 0, 1);
2447 cwindow->playback_engine->que->
2448 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);