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 awindow->gui->async_update_assets();
549 cwindow->playback_engine->que->
550 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
553 void MWindow::snap_left_edit()
555 double start_pos = edl->local_session->get_selectionstart(1);
556 double position = edl->prev_edit(start_pos);
557 if( position < start_pos )
558 cut(position, start_pos, position);
561 void MWindow::snap_right_edit()
563 double end_pos = edl->local_session->get_selectionend(1);
564 double position = edl->next_edit(end_pos);
565 if( end_pos < position )
566 cut(end_pos, position, end_pos);
569 void MWindow::snap_left_label()
571 double start_pos = edl->local_session->get_selectionstart(1);
572 Label *left_label = edl->labels->prev_label(start_pos);
573 if( !left_label ) return;
574 double position = left_label->position;
575 if( position < start_pos )
576 cut(position, start_pos, position);
579 void MWindow::snap_right_label()
581 double end_pos = edl->local_session->get_selectionend(1);
582 Label *right_label = edl->labels->next_label(end_pos);
583 if( !right_label ) return;
584 double position = right_label->position;
585 if( end_pos < position )
586 cut(end_pos, position, end_pos);
589 int MWindow::cut_automation()
591 undo->update_undo_before();
595 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
596 edl->local_session->get_selectionend());
598 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
602 update_plugin_guis();
603 gui->draw_overlays(1);
604 sync_parameters(CHANGE_PARAMS);
605 gui->update_patchbay();
606 cwindow->update(1, 0, 0);
610 int MWindow::cut_default_keyframe()
613 undo->update_undo_before();
614 copy_default_keyframe();
615 edl->tracks->clear_default_keyframe();
616 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
619 gui->draw_overlays(1);
620 sync_parameters(CHANGE_PARAMS);
621 gui->update_patchbay();
622 cwindow->update(1, 0, 0);
630 void MWindow::delete_inpoint()
632 edl->local_session->unset_inpoint();
636 void MWindow::delete_outpoint()
638 edl->local_session->unset_outpoint();
643 void MWindow::delete_track()
645 if( edl->tracks->last )
646 delete_track(edl->tracks->last);
649 void MWindow::delete_tracks()
651 undo->update_undo_before();
652 edl->tracks->delete_tracks();
653 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
657 update_plugin_states();
659 gui->update(1, 1, 1, 0, 1, 0, 0);
660 cwindow->playback_engine->que->
661 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
664 void MWindow::delete_track(Track *track)
666 undo->update_undo_before();
667 edl->tracks->delete_track(track);
668 undo->update_undo_after(_("delete track"), LOAD_ALL);
671 update_plugin_states();
673 gui->update(1, 1, 1, 0, 1, 0, 0);
674 cwindow->playback_engine->que->
675 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
680 // Insert data from clipboard
681 void MWindow::insert(double position, FileXML *file,
682 int edit_labels, int edit_plugins, int edit_autos,
685 // For clipboard pasting make the new edl use a separate session
686 // from the master EDL. Then it can be resampled to the master rates.
687 // For splice, overwrite, and dragging need same session to get the assets.
688 EDL *edl = new EDL(parent_edl);
689 ArrayList<EDL*> new_edls;
690 uint32_t load_flags = LOAD_ALL;
693 new_edls.append(edl);
694 edl->create_objects();
699 if( parent_edl ) load_flags &= ~LOAD_SESSION;
700 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
701 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
703 edl->load_xml(file, load_flags);
706 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
710 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
711 edit_labels, edit_plugins, edit_autos, 0); // overwrite
712 // if( vwindow->edl )
713 // printf("MWindow::insert 5 %f %f\n",
714 // vwindow->edl->local_session->in_point,
715 // vwindow->edl->local_session->out_point);
716 new_edls.remove_all();
717 edl->Garbage::remove_user();
718 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
721 void MWindow::insert_effects_canvas(double start,
724 Track *dest_track = session->track_highlighted;
725 if( !dest_track ) return;
727 undo->update_undo_before();
729 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
730 PluginServer *plugin = session->drag_pluginservers->values[i];
731 insert_effect(plugin->title, 0, dest_track,
732 i == 0 ? session->pluginset_highlighted : 0,
733 start, length, PLUGIN_STANDALONE);
737 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
739 sync_parameters(CHANGE_EDL);
740 // GUI updated in TrackCanvas, after current_operations are reset
743 void MWindow::insert_effects_cwindow(Track *dest_track)
745 if( !dest_track ) return;
747 undo->update_undo_before();
750 double length = dest_track->get_length();
752 if( edl->local_session->get_selectionend() >
753 edl->local_session->get_selectionstart() ) {
754 start = edl->local_session->get_selectionstart();
755 length = edl->local_session->get_selectionend() -
756 edl->local_session->get_selectionstart();
759 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
760 PluginServer *plugin = session->drag_pluginservers->values[i];
761 insert_effect(plugin->title, 0, dest_track, 0,
762 start, length, PLUGIN_STANDALONE);
766 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
768 sync_parameters(CHANGE_EDL);
769 gui->update(1, 1, 0, 0, 1, 0, 0);
772 void MWindow::insert_effect(char *title,
773 SharedLocation *shared_location,
776 int single_standalone)
778 Track *current = edl->tracks->first;
779 SharedLocation shared_location_local;
780 shared_location_local.copy_from(shared_location);
782 for( ; current; current = NEXT) {
783 if( current->data_type == data_type &&
785 insert_effect(title, &shared_location_local,
786 current, 0, 0, 0, plugin_type);
789 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
790 plugin_type = PLUGIN_SHAREDPLUGIN;
791 shared_location_local.module = edl->tracks->number_of(current);
792 shared_location_local.plugin = current->plugin_set.total - 1;
801 void MWindow::insert_effect(char *title,
802 SharedLocation *shared_location,
804 PluginSet *plugin_set,
809 KeyFrame *default_keyframe = 0;
810 PluginServer *server = 0;
811 // Get default keyframe
812 if( plugin_type == PLUGIN_STANDALONE ) {
813 default_keyframe = new KeyFrame;
814 server = new PluginServer(*scan_plugindb(title, track->data_type));
816 server->open_plugin(0, preferences, edl, 0);
817 server->save_data(default_keyframe);
819 // Insert plugin object
820 track->insert_effect(title, shared_location,
821 default_keyframe, plugin_set,
822 start, length, plugin_type);
825 if( plugin_type == PLUGIN_STANDALONE ) {
826 server->close_plugin();
828 delete default_keyframe;
832 int MWindow::modify_edithandles()
834 undo->update_undo_before();
835 edl->modify_edithandles(session->drag_start,
836 session->drag_position,
837 session->drag_handle,
838 edl->session->edit_handle_mode[session->drag_button],
839 edl->session->labels_follow_edits,
840 edl->session->plugins_follow_edits,
841 edl->session->autos_follow_edits);
843 finish_modify_handles();
844 //printf("MWindow::modify_handles 1\n");
848 int MWindow::modify_pluginhandles()
850 undo->update_undo_before();
852 edl->modify_pluginhandles(session->drag_start,
853 session->drag_position,
854 session->drag_handle,
855 edl->session->edit_handle_mode[session->drag_button],
856 edl->session->labels_follow_edits,
857 edl->session->autos_follow_edits,
858 session->trim_edits);
860 finish_modify_handles();
866 // Common to edithandles and plugin handles
867 void MWindow::finish_modify_handles()
869 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
871 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
872 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
873 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
874 edl->local_session->set_selectionstart(session->drag_position);
875 edl->local_session->set_selectionend(session->drag_position);
876 edl->deglitch(session->drag_position);
879 if( edit_mode != MOVE_NO_EDITS ) {
880 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
881 edl->local_session->set_selectionstart(session->drag_start);
882 edl->local_session->set_selectionend(session->drag_start);
883 edl->deglitch(session->drag_start);
886 // clamp the selection to 0
887 if( edl->local_session->get_selectionstart(1) < 0 ) {
888 edl->local_session->set_selectionstart(0);
889 edl->local_session->set_selectionend(0);
891 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
895 sync_parameters(CHANGE_EDL);
896 update_plugin_guis();
897 gui->update(1, 2, 1, 1, 1, 1, 0);
898 // label list can be modified
899 awindow->gui->async_update_assets();
900 cwindow->update(1, 0, 0, 0, 1);
903 void MWindow::match_output_size(Track *track)
905 undo->update_undo_before();
906 track->track_w = edl->session->output_w;
907 track->track_h = edl->session->output_h;
909 undo->update_undo_after(_("match output size"), LOAD_ALL);
912 sync_parameters(CHANGE_EDL);
916 void MWindow::move_edits(ArrayList<Edit*> *edits,
921 undo->update_undo_before();
923 edl->tracks->move_edits(edits,
926 edl->session->labels_follow_edits,
927 edl->session->plugins_follow_edits,
928 edl->session->autos_follow_edits,
932 undo->update_undo_after(_("move edit"), LOAD_ALL);
935 cwindow->playback_engine->que->
936 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, Track *track, int64_t position)
945 undo->update_undo_before();
946 edl->tracks->move_effect(plugin, track, position);
948 undo->update_undo_after(_("paste 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_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
960 undo->update_undo_before();
961 edl->tracks->move_effect(plugin, plugin_set, position);
963 undo->update_undo_after(_("move effect"), LOAD_ALL);
966 cwindow->playback_engine->que->
967 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
968 update_plugin_guis();
969 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
973 void MWindow::move_plugins_up(PluginSet *plugin_set)
976 undo->update_undo_before();
977 plugin_set->track->move_plugins_up(plugin_set);
980 undo->update_undo_after(_("move effect up"), LOAD_ALL);
982 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
984 sync_parameters(CHANGE_EDL);
987 void MWindow::move_plugins_down(PluginSet *plugin_set)
989 undo->update_undo_before();
991 plugin_set->track->move_plugins_down(plugin_set);
994 undo->update_undo_after(_("move effect down"), LOAD_ALL);
996 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
998 sync_parameters(CHANGE_EDL);
1001 void MWindow::move_track_down(Track *track)
1003 undo->update_undo_before();
1004 edl->tracks->move_track_down(track);
1006 undo->update_undo_after(_("move track down"), LOAD_ALL);
1009 gui->update(1, 1, 0, 0, 1, 0, 0);
1010 sync_parameters(CHANGE_EDL);
1014 void MWindow::move_tracks_down()
1016 undo->update_undo_before();
1017 edl->tracks->move_tracks_down();
1019 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1022 gui->update(1, 1, 0, 0, 1, 0, 0);
1023 sync_parameters(CHANGE_EDL);
1027 void MWindow::move_track_up(Track *track)
1029 undo->update_undo_before();
1030 edl->tracks->move_track_up(track);
1032 undo->update_undo_after(_("move track up"), LOAD_ALL);
1034 gui->update(1, 1, 0, 0, 1, 0, 0);
1035 sync_parameters(CHANGE_EDL);
1039 void MWindow::move_tracks_up()
1041 undo->update_undo_before();
1042 edl->tracks->move_tracks_up();
1044 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1046 gui->update(1, 1, 0, 0, 1, 0, 0);
1047 sync_parameters(CHANGE_EDL);
1051 void MWindow::mute_selection()
1053 double start = edl->local_session->get_selectionstart();
1054 double end = edl->local_session->get_selectionend();
1055 if( start != end ) {
1056 undo->update_undo_before();
1057 edl->clear(start, end, 0,
1058 edl->session->plugins_follow_edits,
1059 edl->session->autos_follow_edits);
1060 edl->local_session->set_selectionend(end);
1061 edl->local_session->set_selectionstart(start);
1062 edl->paste_silence(start, end, 0,
1063 edl->session->plugins_follow_edits,
1064 edl->session->autos_follow_edits);
1065 edl->deglitch(start);
1070 undo->update_undo_after(_("mute"), LOAD_EDITS);
1073 update_plugin_guis();
1074 gui->update(1, 2, 1, 1, 1, 1, 0);
1075 cwindow->playback_engine->que->
1076 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1081 void MWindow::overwrite(EDL *source)
1085 double src_start = source->local_session->get_selectionstart();
1086 double overwrite_len = source->local_session->get_selectionend() - src_start;
1087 double dst_start = edl->local_session->get_selectionstart();
1088 double dst_len = edl->local_session->get_selectionend() - dst_start;
1090 undo->update_undo_before();
1091 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1092 // in/out points or selection present and shorter than overwrite range
1093 // shorten the copy range
1094 overwrite_len = dst_len;
1097 source->copy(src_start, src_start + overwrite_len,
1098 0, 0, 0, &file, "", 1);
1100 // HACK around paste_edl get_start/endselection on its own
1101 // so we need to clear only when not using both io points
1102 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1103 if( edl->local_session->get_inpoint() < 0 ||
1104 edl->local_session->get_outpoint() < 0 )
1105 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1107 paste(dst_start, dst_start + overwrite_len,
1110 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1111 edl->local_session->set_selectionend(dst_start + overwrite_len);
1114 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1117 update_plugin_guis();
1118 gui->update(1, 1, 1, 1, 0, 1, 0);
1119 sync_parameters(CHANGE_EDL);
1122 // For splice and overwrite
1123 int MWindow::paste(double start,
1132 // Want to insert with assets shared with the master EDL.
1134 edit_labels, edit_plugins, edit_autos,
1140 // For editing using insertion point
1141 void MWindow::paste()
1143 double start = edl->local_session->get_selectionstart();
1144 //double end = edl->local_session->get_selectionend();
1145 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1148 char *string = new char[len];
1149 undo->update_undo_before();
1150 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1152 file.read_from_string(string);
1155 insert(start, &file,
1156 edl->session->labels_follow_edits,
1157 edl->session->plugins_follow_edits,
1158 edl->session->autos_follow_edits,
1166 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1168 update_plugin_guis();
1169 gui->update(1, 2, 1, 1, 0, 1, 0);
1170 awindow->gui->async_update_assets();
1171 sync_parameters(CHANGE_EDL);
1176 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1179 undo->update_undo_before();
1181 if( session->drag_assets->total ) {
1182 load_assets(session->drag_assets,
1183 position, LOADMODE_PASTE, dest_track, 0,
1184 edl->session->labels_follow_edits,
1185 edl->session->plugins_follow_edits,
1186 edl->session->autos_follow_edits,
1191 if( session->drag_clips->total ) {
1192 paste_edls(session->drag_clips,
1193 LOADMODE_PASTE, dest_track, position,
1194 edl->session->labels_follow_edits,
1195 edl->session->plugins_follow_edits,
1196 edl->session->autos_follow_edits,
1203 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1205 gui->update(1, 2, 1, 0, 0, 1, 0);
1206 sync_parameters(CHANGE_EDL);
1210 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1211 double position, int load_mode, Track *first_track, RecordLabels *labels,
1212 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1214 if( load_mode == LOADMODE_RESOURCESONLY )
1215 load_mode = LOADMODE_ASSETSONLY;
1216 const int debug = 0;
1217 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1218 if( position < 0 ) position = edl->local_session->get_selectionstart();
1220 ArrayList<EDL*> new_edls;
1221 for( int i = 0; i < new_assets->total; i++ ) {
1222 Indexable *indexable = new_assets->get(i);
1223 if( indexable->is_asset ) {
1224 remove_asset_from_caches((Asset*)indexable);
1226 EDL *new_edl = new EDL;
1227 new_edl->create_objects();
1228 new_edl->copy_session(edl);
1229 new_edls.append(new_edl);
1232 if( indexable->is_asset ) {
1233 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1234 if( debug ) ((Asset*)indexable)->dump();
1235 asset_to_edl(new_edl, (Asset*)indexable);
1238 edl_to_nested(new_edl, (EDL*)indexable);
1239 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1243 for( RecordLabel *label = labels->first; label; label = label->next ) {
1244 new_edl->labels->toggle_label(label->position, label->position);
1248 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1250 paste_edls(&new_edls, load_mode, first_track, position,
1251 edit_labels, edit_plugins, edit_autos, overwrite);
1252 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1255 for( int i = 0; i < new_edls.size(); i++ )
1256 new_edls.get(i)->Garbage::remove_user();
1258 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1261 int MWindow::paste_automation()
1263 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1266 undo->update_undo_before();
1267 char *string = new char[len];
1268 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1270 file.read_from_string(string);
1272 double start = edl->local_session->get_selectionstart();
1273 double end = edl->local_session->get_selectionend();
1274 edl->tracks->clear_automation(start, end);
1275 edl->tracks->paste_automation(start, &file, 0, 1,
1276 edl->session->typeless_keyframes);
1278 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1282 update_plugin_guis();
1283 gui->draw_overlays(1);
1284 sync_parameters(CHANGE_PARAMS);
1285 gui->update_patchbay();
1286 cwindow->update(1, 0, 0);
1292 int MWindow::paste_default_keyframe()
1294 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1297 undo->update_undo_before();
1298 char *string = new char[len];
1299 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1301 file.read_from_string(string);
1302 double start = edl->local_session->get_selectionstart();
1303 edl->tracks->paste_automation(start, &file, 1, 0,
1304 edl->session->typeless_keyframes);
1305 // edl->tracks->paste_default_keyframe(&file);
1306 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1309 update_plugin_guis();
1310 gui->draw_overlays(1);
1311 sync_parameters(CHANGE_PARAMS);
1312 gui->update_patchbay();
1313 cwindow->update(1, 0, 0);
1322 // Insert edls with project deletion and index file generation.
1323 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1324 Track *first_track, double current_position,
1325 int edit_labels, int edit_plugins, int edit_autos,
1329 ArrayList<Track*> destination_tracks;
1330 int need_new_tracks = 0;
1333 if( !new_edls->total ) return 0;
1336 // double original_length = edl->tracks->total_length();
1337 // double original_preview_end = edl->local_session->preview_end;
1340 // Delete current project
1341 if( load_mode == LOADMODE_REPLACE ||
1342 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1344 edl->save_defaults(defaults);
1346 edl->Garbage::remove_user();
1348 edl->create_objects();
1349 edl->copy_session(new_edls->values[0]);
1350 edl->copy_mixers(new_edls->values[0]);
1351 gui->mainmenu->update_toggles(0);
1352 gui->unlock_window();
1353 gwindow->gui->update_toggles(1);
1354 gui->lock_window("MWindow::paste_edls");
1356 // Insert labels for certain modes constitutively
1360 // Force reset of preview
1361 // original_length = 0;
1362 // original_preview_end = -1;
1368 // Create new tracks in master EDL
1369 if( load_mode == LOADMODE_REPLACE ||
1370 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1371 load_mode == LOADMODE_NEW_TRACKS ) {
1373 need_new_tracks = 1;
1374 for( int i = 0; i < new_edls->total; i++ ) {
1375 EDL *new_edl = new_edls->values[i];
1376 for( Track *current = new_edl->tracks->first;
1379 if( current->data_type == TRACK_VIDEO ) {
1380 edl->tracks->add_video_track(0, 0);
1381 if( current->draw ) edl->tracks->last->draw = 1;
1382 destination_tracks.append(edl->tracks->last);
1385 if( current->data_type == TRACK_AUDIO ) {
1386 edl->tracks->add_audio_track(0, 0);
1387 destination_tracks.append(edl->tracks->last);
1390 if( current->data_type == TRACK_SUBTITLE ) {
1391 edl->tracks->add_subttl_track(0, 0);
1392 destination_tracks.append(edl->tracks->last);
1394 edl->session->highlighted_track = edl->tracks->total() - 1;
1397 // Base track count on first EDL only for concatenation
1398 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1403 // Recycle existing tracks of master EDL
1404 if( load_mode == LOADMODE_CONCATENATE ||
1405 load_mode == LOADMODE_PASTE ||
1406 load_mode == LOADMODE_NESTED ) {
1409 // The point of this is to shift forward labels after the selection so they can
1410 // then be shifted back to their original locations without recursively
1411 // shifting back every paste.
1412 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1413 edl->session->labels_follow_edits )
1414 edl->labels->clear(edl->local_session->get_selectionstart(),
1415 edl->local_session->get_selectionend(),
1418 Track *current = first_track ? first_track : edl->tracks->first;
1419 for( ; current; current = NEXT) {
1420 if( current->record ) {
1421 destination_tracks.append(current);
1428 int destination_track = 0;
1429 double *paste_position = new double[destination_tracks.total];
1431 // Iterate through the edls
1432 for( int i = 0; i < new_edls->total; i++ ) {
1434 EDL *new_edl = new_edls->values[i];
1435 double edl_length = new_edl->local_session->clipboard_length ?
1436 new_edl->local_session->clipboard_length :
1437 new_edl->tracks->total_length();
1438 // printf("MWindow::paste_edls 2 %f %f\n",
1439 // new_edl->local_session->clipboard_length,
1440 // new_edl->tracks->total_length());
1444 // Convert EDL to master rates
1445 new_edl->resample(new_edl->session->sample_rate,
1446 edl->session->sample_rate,
1448 new_edl->resample(new_edl->session->frame_rate,
1449 edl->session->frame_rate,
1452 // Add assets and prepare index files
1453 for( Asset *new_asset = new_edl->assets->first;
1455 new_asset = new_asset->next ) {
1456 mainindexes->add_next_asset(0, new_asset);
1458 // Capture index file status from mainindex test
1459 edl->update_assets(new_edl);
1461 // Get starting point of insertion. Need this to paste labels.
1462 switch( load_mode ) {
1463 case LOADMODE_REPLACE:
1464 case LOADMODE_NEW_TRACKS:
1465 current_position = 0;
1468 case LOADMODE_CONCATENATE:
1469 case LOADMODE_REPLACE_CONCATENATE:
1470 destination_track = 0;
1471 if( destination_tracks.total )
1472 current_position = destination_tracks.values[0]->get_length();
1474 current_position = 0;
1477 case LOADMODE_PASTE:
1478 case LOADMODE_NESTED:
1479 destination_track = 0;
1481 for( int j = 0; j < destination_tracks.total; j++ ) {
1482 paste_position[j] = (current_position >= 0) ?
1484 edl->local_session->get_selectionstart();
1489 case LOADMODE_RESOURCESONLY:
1490 edl->add_clip(new_edl);
1495 if( load_mode != LOADMODE_RESOURCESONLY &&
1496 load_mode != LOADMODE_ASSETSONLY ) {
1498 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1499 if( load_mode == LOADMODE_PASTE ||
1500 load_mode == LOADMODE_NESTED )
1501 edl->labels->insert_labels(new_edl->labels,
1502 destination_tracks.total ? paste_position[0] : 0.0,
1506 edl->labels->insert_labels(new_edl->labels,
1512 for( Track *new_track = new_edl->tracks->first;
1514 new_track = new_track->next ) {
1515 // Get destination track of same type as new_track
1517 k < destination_tracks.total &&
1518 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1519 k++, destination_track++ ) {
1520 if( destination_track >= destination_tracks.total - 1 )
1521 destination_track = 0;
1524 // Insert data into destination track
1525 if( destination_track < destination_tracks.total &&
1526 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1527 Track *track = destination_tracks.values[destination_track];
1529 // Replace default keyframes if first EDL and new tracks were created.
1530 // This means data copied from one track and pasted to another won't retain
1531 // the camera position unless it's a keyframe. If it did, previous data in the
1532 // track might get unknowingly corrupted. Ideally we would detect when differing
1533 // default keyframes existed and create discrete keyframes for both.
1534 int replace_default = (i == 0) && need_new_tracks;
1536 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1537 // Insert new track at current position
1538 switch( load_mode ) {
1539 case LOADMODE_REPLACE_CONCATENATE:
1540 case LOADMODE_CONCATENATE:
1541 current_position = track->get_length();
1544 case LOADMODE_PASTE:
1545 case LOADMODE_NESTED:
1546 current_position = paste_position[destination_track];
1547 paste_position[destination_track] += new_track->get_length();
1551 track->clear(current_position,
1552 current_position + new_track->get_length(),
1554 edit_labels, edit_plugins, edit_autos,
1559 track->insert_track(new_track, current_position, replace_default,
1560 edit_plugins, edit_autos, edl_length);
1564 // Get next destination track
1565 destination_track++;
1566 if( destination_track >= destination_tracks.total )
1567 destination_track = 0;
1571 if( load_mode == LOADMODE_PASTE ||
1572 load_mode == LOADMODE_NESTED )
1573 current_position += edl_length;
1577 // Move loading of clips and vwindow to the end - this fixes some
1578 // strange issue, for index not being shown
1579 // Assume any paste operation from the same EDL won't contain any clips.
1580 // If it did it would duplicate every clip here.
1581 for( int i = 0; i < new_edls->total; i++ ) {
1582 EDL *new_edl = new_edls->values[i];
1584 for( int j = 0; j < new_edl->clips.total; j++ ) {
1585 edl->add_clip(new_edl->clips.values[j]);
1588 if( new_edl->total_vwindow_edls() ) {
1589 // if( edl->vwindow_edl )
1590 // edl->vwindow_edl->Garbage::remove_user();
1591 // edl->vwindow_edl = new EDL(edl);
1592 // edl->vwindow_edl->create_objects();
1593 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1595 for( int j = 0; j < new_edl->total_vwindow_edls(); j++ ) {
1596 EDL *vwindow_edl = new EDL(edl);
1597 vwindow_edl->create_objects();
1598 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1599 edl->append_vwindow_edl(vwindow_edl, 0);
1604 if( paste_position ) delete [] paste_position;
1606 // This is already done in load_filenames and everything else that uses paste_edls
1607 // update_project(load_mode);
1609 // Fix preview range
1610 // if( EQUIV(original_length, original_preview_end) )
1612 // edl->local_session->preview_end = edl->tracks->total_length();
1615 // Start examining next batch of index files
1616 mainindexes->start_build();
1618 // Don't save a backup after loading since the loaded file is on disk already.
1623 void MWindow::paste_silence()
1625 double start = edl->local_session->get_selectionstart();
1626 double end = edl->local_session->get_selectionend();
1627 undo->update_undo_before();
1628 edl->paste_silence(start, end,
1629 edl->session->labels_follow_edits,
1630 edl->session->plugins_follow_edits,
1631 edl->session->autos_follow_edits);
1632 edl->deglitch(start);
1636 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1638 update_plugin_guis();
1640 gui->update(1, 2, 1, 1, 1, 1, 0);
1641 cwindow->update(1, 0, 0, 0, 1);
1642 cwindow->playback_engine->que->
1643 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1646 void MWindow::detach_transition(Transition *transition)
1648 undo->update_undo_before();
1649 hide_plugin(transition, 1);
1650 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1651 transition->edit->detach_transition();
1653 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1655 if( is_video ) restart_brender();
1656 gui->update(0, 1, 0, 0, 0, 0, 0);
1657 sync_parameters(CHANGE_EDL);
1660 void MWindow::detach_transitions()
1662 gui->lock_window("MWindow::detach_transitions 1");
1664 undo->update_undo_before();
1665 double start = edl->local_session->get_selectionstart();
1666 double end = edl->local_session->get_selectionend();
1667 edl->tracks->clear_transitions(start, end);
1670 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1672 sync_parameters(CHANGE_EDL);
1673 gui->update(0, 1, 0, 0, 0, 0, 0);
1674 gui->unlock_window();
1677 void MWindow::paste_transition()
1679 // Only the first transition gets dropped.
1680 PluginServer *server = session->drag_pluginservers->values[0];
1682 undo->update_undo_before();
1684 strcpy(edl->session->default_atransition, server->title);
1686 strcpy(edl->session->default_vtransition, server->title);
1688 edl->tracks->paste_transition(server, session->edit_highlighted);
1690 undo->update_undo_after(_("transition"), LOAD_EDITS);
1692 if( server->video ) restart_brender();
1693 sync_parameters(CHANGE_ALL);
1696 void MWindow::paste_transitions(int track_type, char *title)
1698 gui->lock_window("MWindow::detach_transitions 1");
1700 undo->update_undo_before();
1701 double start = edl->local_session->get_selectionstart();
1702 double end = edl->local_session->get_selectionend();
1703 edl->tracks->paste_transitions(start, end, track_type, title);
1706 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1708 sync_parameters(CHANGE_EDL);
1709 gui->update(0, 1, 0, 0, 0, 0, 0);
1710 gui->unlock_window();
1713 void MWindow::paste_transition_cwindow(Track *dest_track)
1715 PluginServer *server = session->drag_pluginservers->values[0];
1716 undo->update_undo_before();
1717 edl->tracks->paste_video_transition(server, 1);
1719 undo->update_undo_after(_("transition"), LOAD_EDITS);
1721 gui->update(0, 1, 0, 0, 0, 0, 0);
1722 sync_parameters(CHANGE_ALL);
1725 void MWindow::paste_audio_transition()
1727 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1730 char string[BCTEXTLEN];
1731 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1732 gui->show_message(string);
1736 undo->update_undo_before();
1737 edl->tracks->paste_audio_transition(server);
1739 undo->update_undo_after(_("transition"), LOAD_EDITS);
1741 sync_parameters(CHANGE_EDL);
1742 gui->update(0, 1, 0, 0, 0, 0, 0);
1745 void MWindow::paste_video_transition()
1747 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1750 char string[BCTEXTLEN];
1751 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1752 gui->show_message(string);
1756 undo->update_undo_before();
1758 edl->tracks->paste_video_transition(server);
1760 undo->update_undo_after(_("transition"), LOAD_EDITS);
1762 sync_parameters(CHANGE_EDL);
1764 gui->update(0, 1, 0, 0, 0, 0, 0);
1767 void MWindow::shuffle_edits()
1769 gui->lock_window("MWindow::shuffle_edits 1");
1771 undo->update_undo_before();
1772 double start = edl->local_session->get_selectionstart();
1773 double end = edl->local_session->get_selectionend();
1775 edl->tracks->shuffle_edits(start, end);
1778 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1780 sync_parameters(CHANGE_EDL);
1782 gui->update(0, 1, 1, 0, 0, 0, 0);
1783 gui->unlock_window();
1786 void MWindow::reverse_edits()
1788 gui->lock_window("MWindow::reverse_edits 1");
1790 undo->update_undo_before();
1791 double start = edl->local_session->get_selectionstart();
1792 double end = edl->local_session->get_selectionend();
1794 edl->tracks->reverse_edits(start, end);
1797 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1799 sync_parameters(CHANGE_EDL);
1801 gui->update(0, 1, 1, 0, 0, 0, 0);
1802 gui->unlock_window();
1805 void MWindow::align_edits()
1807 gui->lock_window("MWindow::align_edits 1");
1809 undo->update_undo_before();
1810 double start = edl->local_session->get_selectionstart();
1811 double end = edl->local_session->get_selectionend();
1813 edl->tracks->align_edits(start, end);
1816 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1818 sync_parameters(CHANGE_EDL);
1820 gui->update(0, 1, 1, 0, 0, 0, 0);
1821 gui->unlock_window();
1824 void MWindow::set_edit_length(double length)
1826 gui->lock_window("MWindow::detach_transitions 1");
1828 undo->update_undo_before();
1829 double start = edl->local_session->get_selectionstart();
1830 double end = edl->local_session->get_selectionend();
1832 edl->tracks->set_edit_length(start, end, length);
1835 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1837 sync_parameters(CHANGE_EDL);
1839 gui->update(0, 1, 1, 0, 0, 0, 0);
1840 gui->unlock_window();
1844 void MWindow::set_transition_length(Transition *transition, double length)
1846 gui->lock_window("MWindow::detach_transitions 1");
1848 undo->update_undo_before();
1849 //double start = edl->local_session->get_selectionstart();
1850 //double end = edl->local_session->get_selectionend();
1852 edl->tracks->set_transition_length(transition, length);
1855 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1857 edl->session->default_transition_length = length;
1858 sync_parameters(CHANGE_PARAMS);
1859 gui->update(0, 1, 0, 0, 0, 0, 0);
1860 gui->unlock_window();
1863 void MWindow::set_transition_length(double length)
1865 gui->lock_window("MWindow::detach_transitions 1");
1867 undo->update_undo_before();
1868 double start = edl->local_session->get_selectionstart();
1869 double end = edl->local_session->get_selectionend();
1871 edl->tracks->set_transition_length(start, end, length);
1874 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1876 edl->session->default_transition_length = length;
1877 sync_parameters(CHANGE_PARAMS);
1879 gui->update(0, 1, 0, 0, 0, 0, 0);
1880 gui->unlock_window();
1884 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1887 calling_window_gui->unlock_window();
1889 cwindow->playback_engine->que->
1890 send_command(STOP, CHANGE_NONE, 0, 0);
1891 cwindow->playback_engine->interrupt_playback(0);
1893 for( int i = 0; i < vwindows.size(); i++ ) {
1894 if( vwindows.get(i)->is_running() ) {
1895 vwindows.get(i)->playback_engine->que->
1896 send_command(STOP, CHANGE_NONE, 0, 0);
1897 vwindows.get(i)->playback_engine->interrupt_playback(0);
1901 cwindow->gui->lock_window("MWindow::redo_entry");
1902 for( int i = 0; i < vwindows.size(); i++ ) {
1903 if( vwindows.get(i)->is_running() ) {
1904 if( calling_window_gui != vwindows.get(i)->gui ) {
1905 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1914 update_plugin_states();
1915 update_plugin_guis();
1916 awindow->gui->async_update_assets();
1918 gui->update(1, 2, 1, 1, 1, 1, 1);
1919 cwindow->update(1, 1, 1, 1, 1);
1921 if( calling_window_gui != cwindow->gui )
1922 cwindow->gui->unlock_window();
1923 if( calling_window_gui != gui )
1924 gui->unlock_window();
1927 for( int i = 0; i < vwindows.size(); i++ ) {
1928 if( vwindows.get(i)->is_running() ) {
1929 if( calling_window_gui != vwindows.get(i)->gui ) {
1930 vwindows.get(i)->gui->unlock_window();
1935 cwindow->playback_engine->que->
1936 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
1940 void MWindow::resize_track(Track *track, int w, int h)
1942 undo->update_undo_before();
1943 // We have to move all maskpoints so they do not move in relation to image areas
1944 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1945 (w - track->track_w) / 2,
1946 (h - track->track_h) / 2);
1949 undo->update_undo_after(_("resize track"), LOAD_ALL);
1953 sync_parameters(CHANGE_EDL);
1957 void MWindow::set_inpoint(int is_mwindow)
1959 undo->update_undo_before();
1960 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1962 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1965 gui->lock_window("MWindow::set_inpoint 1");
1967 gui->update_timebar(1);
1969 gui->unlock_window();
1973 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1975 cwindow->gui->timebar->update(1);
1977 cwindow->gui->unlock_window();
1981 void MWindow::set_outpoint(int is_mwindow)
1983 undo->update_undo_before();
1984 edl->set_outpoint(edl->local_session->get_selectionend(1));
1986 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1989 gui->lock_window("MWindow::set_outpoint 1");
1991 gui->update_timebar(1);
1993 gui->unlock_window();
1997 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1999 cwindow->gui->timebar->update(1);
2001 cwindow->gui->unlock_window();
2005 void MWindow::splice(EDL *source)
2009 undo->update_undo_before();
2010 double source_start = source->local_session->get_selectionstart();
2011 double source_end = source->local_session->get_selectionend();
2012 source->copy(source_start, source_end, 1, 0, 0, &file, "", 1);
2014 double start = edl->local_session->get_selectionstart();
2015 //double end = edl->local_session->get_selectionend();
2017 paste(start, start, &file,
2018 edl->session->labels_follow_edits,
2019 edl->session->plugins_follow_edits,
2020 edl->session->autos_follow_edits);
2022 // Position at end of clip
2023 edl->local_session->set_selectionstart(start + source_end - source_start);
2024 edl->local_session->set_selectionend(start + source_end - source_start);
2027 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2028 update_plugin_guis();
2030 gui->update(1, 1, 1, 1, 0, 1, 0);
2031 sync_parameters(CHANGE_EDL);
2034 void MWindow::save_clip(EDL *new_edl, const char *txt)
2036 new_edl->local_session->set_selectionstart(0);
2037 new_edl->local_session->set_selectionend(0);
2038 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2039 session->clip_number++);
2040 char duration[BCTEXTLEN];
2041 Units::totext(duration, new_edl->tracks->total_length(),
2042 new_edl->session->time_format,
2043 new_edl->session->sample_rate,
2044 new_edl->session->frame_rate,
2045 new_edl->session->frames_per_foot);
2047 Track *track = new_edl->tracks->first;
2048 const char *path = edl->path;
2049 for( ; (!path || !*path) && track; track=track->next ) {
2050 if( !track->record ) continue;
2051 Edit *edit = track->edits->first;
2052 if( !edit ) continue;
2053 Indexable *indexable = edit->get_source();
2054 if( !indexable ) continue;
2055 path = indexable->path;
2058 time_t now; time(&now);
2059 struct tm *tm = localtime(&now);
2060 char *cp = new_edl->local_session->clip_notes;
2061 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2063 n = snprintf(cp, sz, "%s", txt);
2066 n = snprintf(cp, sz,
2067 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2068 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
2069 tm->tm_hour, tm->tm_min, tm->tm_sec, duration);
2071 if( path && *path ) {
2073 char title[BCTEXTLEN];
2074 fs.extract_name(title, path);
2075 n = snprintf(cp, sz, "%s", title);
2080 edl->update_assets(new_edl);
2082 gui->get_abs_cursor(cur_x, cur_y, 0);
2083 gui->unlock_window();
2085 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2087 gui->lock_window("MWindow::save_clip");
2091 void MWindow::to_clip(EDL *edl, const char *txt)
2096 gui->lock_window("MWindow::to_clip 1");
2097 start = edl->local_session->get_selectionstart();
2098 end = edl->local_session->get_selectionend();
2100 if( EQUIV(end, start) ) {
2102 end = edl->tracks->total_length();
2105 // Don't copy all since we don't want the clips twice.
2106 edl->copy(start, end, 0, 0, 0, &file, "", 1);
2108 EDL *new_edl = new EDL(edl);
2109 new_edl->create_objects();
2110 new_edl->load_xml(&file, LOAD_ALL);
2111 save_clip(new_edl, txt);
2112 gui->unlock_window();
2115 int MWindow::toggle_label(int is_mwindow)
2117 double position1, position2;
2118 undo->update_undo_before();
2120 if( cwindow->playback_engine->is_playing_back ) {
2121 position1 = position2 =
2122 cwindow->playback_engine->get_tracking_position();
2125 position1 = edl->local_session->get_selectionstart(1);
2126 position2 = edl->local_session->get_selectionend(1);
2129 position1 = edl->align_to_frame(position1, 0);
2130 position2 = edl->align_to_frame(position2, 0);
2132 //printf("MWindow::toggle_label 1\n");
2134 edl->labels->toggle_label(position1, position2);
2138 gui->lock_window("MWindow::toggle_label 1");
2140 gui->update_timebar(0);
2141 gui->activate_timeline();
2144 gui->unlock_window();
2148 cwindow->gui->lock_window("MWindow::toggle_label 2");
2150 cwindow->gui->timebar->update(1);
2152 cwindow->gui->unlock_window();
2155 awindow->gui->async_update_assets();
2157 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2161 void MWindow::trim_selection()
2163 undo->update_undo_before();
2166 edl->trim_selection(edl->local_session->get_selectionstart(),
2167 edl->local_session->get_selectionend(),
2168 edl->session->labels_follow_edits,
2169 edl->session->plugins_follow_edits,
2170 edl->session->autos_follow_edits);
2172 edl->deglitch(edl->local_session->get_selectionend() -
2173 edl->local_session->get_selectionstart());
2177 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2178 update_plugin_guis();
2179 gui->update(1, 2, 1, 1, 1, 1, 0);
2180 cwindow->update(1, 0, 0, 0, 1);
2181 awindow->gui->async_update_assets();
2183 cwindow->playback_engine->que->
2184 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
2188 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2190 calling_window_gui->unlock_window();
2192 cwindow->playback_engine->que->
2193 send_command(STOP, CHANGE_NONE, 0, 0);
2194 cwindow->playback_engine->interrupt_playback(0);
2196 //printf("MWindow::undo_entry %d %d\n", __LINE__, vwindows.size());
2197 for( int i = 0; i < vwindows.size(); i++ ) {
2198 if( vwindows.get(i)->is_running() ) {
2199 vwindows.get(i)->playback_engine->que->
2200 send_command(STOP, CHANGE_NONE, 0, 0);
2201 vwindows.get(i)->playback_engine->interrupt_playback(0);
2205 cwindow->gui->lock_window("MWindow::undo_entry 1");
2206 for( int i = 0; i < vwindows.size(); i++ ) {
2207 if( vwindows.get(i)->is_running() ) {
2208 if( calling_window_gui != vwindows.get(i)->gui ) {
2209 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2213 gui->lock_window("MWindow::undo_entry 2");
2219 update_plugin_states();
2220 update_plugin_guis();
2222 gui->update(1, 2, 1, 1, 1, 1, 1);
2223 gui->unlock_window();
2224 cwindow->update(1, 1, 1, 1, 1);
2225 cwindow->gui->unlock_window();
2227 for( int i = 0; i < vwindows.size(); i++ ) {
2228 if( vwindows.get(i)->is_running() ) {
2229 if( calling_window_gui != vwindows.get(i)->gui ) {
2230 vwindows.get(i)->gui->unlock_window();
2235 if( calling_window_gui != gui )
2236 gui->unlock_window();
2238 awindow->gui->async_update_assets();
2240 cwindow->playback_engine->que->
2241 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
2242 calling_window_gui->lock_window("MWindow::undo_entry 4");
2246 void MWindow::new_folder(const char *new_folder)
2248 undo->update_undo_before();
2249 edl->new_folder(new_folder);
2250 undo->update_undo_after(_("new folder"), LOAD_ALL);
2251 awindow->gui->async_update_assets();
2254 void MWindow::delete_folder(char *folder)
2256 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2259 void MWindow::select_point(double position)
2261 edl->local_session->set_selectionstart(position);
2262 edl->local_session->set_selectionend(position);
2265 cwindow->update(1, 0, 0, 0, 1);
2267 update_plugin_guis();
2268 gui->update_patchbay();
2269 gui->hide_cursor(0);
2270 gui->draw_cursor(0);
2271 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2272 gui->zoombar->update();
2273 gui->update_timebar(0);
2274 gui->flash_canvas(0);
2281 void MWindow::map_audio(int pattern)
2283 undo->update_undo_before();
2284 remap_audio(pattern);
2285 undo->update_undo_after(
2286 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2288 sync_parameters(CHANGE_PARAMS);
2289 gui->update(0, 1, 0, 0, 1, 0, 0);
2292 void MWindow::remap_audio(int pattern)
2294 int current_channel = 0;
2295 int current_track = 0;
2296 for( Track *current = edl->tracks->first; current; current = NEXT ) {
2297 if( current->data_type == TRACK_AUDIO &&
2299 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2300 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2302 for( int i = 0; i < MAXCHANNELS; i++ ) {
2303 pan_auto->values[i] = 0.0;
2306 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2307 pan_auto->values[current_channel] = 1.0;
2310 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2311 switch( current_track ) {
2313 pan_auto->values[0] = 0.5;
2314 pan_auto->values[1] = 0.5;
2317 pan_auto->values[0] = 1;
2320 pan_auto->values[1] = 1;
2323 pan_auto->values[0] = 1;
2326 pan_auto->values[1] = 1;
2329 pan_auto->values[0] = 0.5;
2330 pan_auto->values[1] = 0.5;
2335 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2336 edl->session->achannel_positions, pan_auto->values,
2337 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2341 if( current_channel >= edl->session->audio_channels )
2342 current_channel = 0;
2347 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2348 ArrayList<Indexable*> *orig_assets,
2349 ArrayList<Indexable*> *proxy_assets)
2351 int orig_use_scaler = edl->session->proxy_use_scaler;
2352 int orig_scale = edl->session->proxy_scale;
2353 // rescale to full size asset in read_frame
2354 edl->session->proxy_use_scaler = use_scaler;
2355 edl->session->proxy_scale = new_scale;
2356 edl->session->proxy_auto_scale = auto_scale;
2359 for( int i=0; i<proxy_assets->size(); ++i ) {
2360 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2361 proxy_asset->width = orig_assets->get(i)->get_w();
2362 proxy_asset->height = orig_assets->get(i)->get_h();
2367 if( !orig_use_scaler && new_scale != orig_scale ) {
2369 float orig_w = (float)edl->session->output_w * orig_scale;
2370 float orig_h = (float)edl->session->output_h * orig_scale;
2371 edl->session->output_w = Units::round(orig_w / new_scale);
2372 edl->session->output_h = Units::round(orig_h / new_scale);
2375 for( Track *track=edl->tracks->first; track; track=track->next ) {
2376 if( track->data_type != TRACK_VIDEO ) continue;
2377 orig_w = (float)track->track_w * orig_scale;
2378 orig_h = (float)track->track_h * orig_scale;
2379 track->track_w = Units::round(orig_w / new_scale);
2380 track->track_h = Units::round(orig_h / new_scale);
2381 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2382 set_proxy(orig_scale, new_scale);
2383 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2384 set_proxy(orig_scale, new_scale);
2385 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2386 set_proxy(orig_scale, new_scale);
2387 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2388 set_proxy(orig_scale, new_scale);
2389 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2390 set_proxy(orig_scale, new_scale);
2394 // change original assets to proxy assets
2395 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2396 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2397 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2398 proxy_asset->awindow_folder = awindow_folder;
2399 // replace track contents
2400 for( Track *track = edl->tracks->first; track; track = track->next ) {
2401 if( track->data_type != TRACK_VIDEO ) continue;
2402 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2403 if( !edit->asset ) continue;
2404 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2405 edit->asset = proxy_asset;
2412 void MWindow::add_proxy(int use_scaler,
2413 ArrayList<Indexable*> *orig_assets,
2414 ArrayList<Indexable*> *proxy_assets)
2417 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2418 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2419 proxy_asset->width = orig_assets->get(i)->get_w();
2420 proxy_asset->height = orig_assets->get(i)->get_h();
2424 // change original assets to proxy assets
2425 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2426 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2427 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2428 // replace track contents
2429 for( Track *track = edl->tracks->first; track; track = track->next ) {
2430 if( track->data_type != TRACK_VIDEO ) continue;
2431 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2432 if( !edit->asset ) continue;
2433 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2434 edit->asset = proxy_asset;
2441 void MWindow::cut_commercials()
2443 undo->update_undo_before();
2444 commercials->scan_media();
2447 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2450 update_plugin_guis();
2451 gui->update(1, 2, 1, 1, 1, 1, 0);
2452 cwindow->update(1, 0, 0, 0, 1);
2453 cwindow->playback_engine->que->
2454 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);