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 0, 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_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 edl->copy_mixers(new_edls->values[0]);
1348 gui->mainmenu->update_toggles(0);
1349 gui->unlock_window();
1350 gwindow->gui->update_toggles(1);
1351 gui->lock_window("MWindow::paste_edls");
1353 // Insert labels for certain modes constitutively
1357 // Force reset of preview
1358 // original_length = 0;
1359 // original_preview_end = -1;
1365 // Create new tracks in master EDL
1366 if( load_mode == LOADMODE_REPLACE ||
1367 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1368 load_mode == LOADMODE_NEW_TRACKS ) {
1370 need_new_tracks = 1;
1371 for( int i = 0; i < new_edls->total; i++ ) {
1372 EDL *new_edl = new_edls->values[i];
1373 for( Track *current = new_edl->tracks->first;
1376 if( current->data_type == TRACK_VIDEO ) {
1377 edl->tracks->add_video_track(0, 0);
1378 if( current->draw ) edl->tracks->last->draw = 1;
1379 destination_tracks.append(edl->tracks->last);
1382 if( current->data_type == TRACK_AUDIO ) {
1383 edl->tracks->add_audio_track(0, 0);
1384 destination_tracks.append(edl->tracks->last);
1387 if( current->data_type == TRACK_SUBTITLE ) {
1388 edl->tracks->add_subttl_track(0, 0);
1389 destination_tracks.append(edl->tracks->last);
1391 edl->session->highlighted_track = edl->tracks->total() - 1;
1394 // Base track count on first EDL only for concatenation
1395 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1400 // Recycle existing tracks of master EDL
1401 if( load_mode == LOADMODE_CONCATENATE ||
1402 load_mode == LOADMODE_PASTE ||
1403 load_mode == LOADMODE_NESTED ) {
1406 // The point of this is to shift forward labels after the selection so they can
1407 // then be shifted back to their original locations without recursively
1408 // shifting back every paste.
1409 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1410 edl->session->labels_follow_edits )
1411 edl->labels->clear(edl->local_session->get_selectionstart(),
1412 edl->local_session->get_selectionend(),
1415 Track *current = first_track ? first_track : edl->tracks->first;
1416 for( ; current; current = NEXT) {
1417 if( current->record ) {
1418 destination_tracks.append(current);
1425 int destination_track = 0;
1426 double *paste_position = new double[destination_tracks.total];
1428 // Iterate through the edls
1429 for( int i = 0; i < new_edls->total; i++ ) {
1431 EDL *new_edl = new_edls->values[i];
1432 double edl_length = new_edl->local_session->clipboard_length ?
1433 new_edl->local_session->clipboard_length :
1434 new_edl->tracks->total_length();
1435 // printf("MWindow::paste_edls 2 %f %f\n",
1436 // new_edl->local_session->clipboard_length,
1437 // new_edl->tracks->total_length());
1441 // Convert EDL to master rates
1442 new_edl->resample(new_edl->session->sample_rate,
1443 edl->session->sample_rate,
1445 new_edl->resample(new_edl->session->frame_rate,
1446 edl->session->frame_rate,
1449 // Add assets and prepare index files
1450 for( Asset *new_asset = new_edl->assets->first;
1452 new_asset = new_asset->next ) {
1453 mainindexes->add_next_asset(0, new_asset);
1455 // Capture index file status from mainindex test
1456 edl->update_assets(new_edl);
1458 // Get starting point of insertion. Need this to paste labels.
1459 switch( load_mode ) {
1460 case LOADMODE_REPLACE:
1461 case LOADMODE_NEW_TRACKS:
1462 current_position = 0;
1465 case LOADMODE_CONCATENATE:
1466 case LOADMODE_REPLACE_CONCATENATE:
1467 destination_track = 0;
1468 if( destination_tracks.total )
1469 current_position = destination_tracks.values[0]->get_length();
1471 current_position = 0;
1474 case LOADMODE_PASTE:
1475 case LOADMODE_NESTED:
1476 destination_track = 0;
1478 for( int j = 0; j < destination_tracks.total; j++ ) {
1479 paste_position[j] = (current_position >= 0) ?
1481 edl->local_session->get_selectionstart();
1486 case LOADMODE_RESOURCESONLY:
1487 edl->add_clip(new_edl);
1492 if( load_mode != LOADMODE_RESOURCESONLY &&
1493 load_mode != LOADMODE_ASSETSONLY ) {
1495 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1496 if( load_mode == LOADMODE_PASTE ||
1497 load_mode == LOADMODE_NESTED )
1498 edl->labels->insert_labels(new_edl->labels,
1499 destination_tracks.total ? paste_position[0] : 0.0,
1503 edl->labels->insert_labels(new_edl->labels,
1509 for( Track *new_track = new_edl->tracks->first;
1511 new_track = new_track->next ) {
1512 // Get destination track of same type as new_track
1514 k < destination_tracks.total &&
1515 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1516 k++, destination_track++ ) {
1517 if( destination_track >= destination_tracks.total - 1 )
1518 destination_track = 0;
1521 // Insert data into destination track
1522 if( destination_track < destination_tracks.total &&
1523 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1524 Track *track = destination_tracks.values[destination_track];
1526 // Replace default keyframes if first EDL and new tracks were created.
1527 // This means data copied from one track and pasted to another won't retain
1528 // the camera position unless it's a keyframe. If it did, previous data in the
1529 // track might get unknowingly corrupted. Ideally we would detect when differing
1530 // default keyframes existed and create discrete keyframes for both.
1531 int replace_default = (i == 0) && need_new_tracks;
1533 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1534 // Insert new track at current position
1535 switch( load_mode ) {
1536 case LOADMODE_REPLACE_CONCATENATE:
1537 case LOADMODE_CONCATENATE:
1538 current_position = track->get_length();
1541 case LOADMODE_PASTE:
1542 case LOADMODE_NESTED:
1543 current_position = paste_position[destination_track];
1544 paste_position[destination_track] += new_track->get_length();
1548 track->clear(current_position,
1549 current_position + new_track->get_length(),
1551 edit_labels, edit_plugins, edit_autos,
1556 track->insert_track(new_track, current_position, replace_default,
1557 edit_plugins, edit_autos, edl_length);
1561 // Get next destination track
1562 destination_track++;
1563 if( destination_track >= destination_tracks.total )
1564 destination_track = 0;
1568 if( load_mode == LOADMODE_PASTE ||
1569 load_mode == LOADMODE_NESTED )
1570 current_position += edl_length;
1574 // Move loading of clips and vwindow to the end - this fixes some
1575 // strange issue, for index not being shown
1576 // Assume any paste operation from the same EDL won't contain any clips.
1577 // If it did it would duplicate every clip here.
1578 for( int i = 0; i < new_edls->total; i++ ) {
1579 EDL *new_edl = new_edls->values[i];
1581 for( int j = 0; j < new_edl->clips.total; j++ ) {
1582 edl->add_clip(new_edl->clips.values[j]);
1585 if( new_edl->total_vwindow_edls() ) {
1586 // if( edl->vwindow_edl )
1587 // edl->vwindow_edl->Garbage::remove_user();
1588 // edl->vwindow_edl = new EDL(edl);
1589 // edl->vwindow_edl->create_objects();
1590 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1592 for( int j = 0; j < new_edl->total_vwindow_edls(); j++ ) {
1593 EDL *vwindow_edl = new EDL(edl);
1594 vwindow_edl->create_objects();
1595 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1596 edl->append_vwindow_edl(vwindow_edl, 0);
1601 if( paste_position ) delete [] paste_position;
1603 // This is already done in load_filenames and everything else that uses paste_edls
1604 // update_project(load_mode);
1606 // Fix preview range
1607 // if( EQUIV(original_length, original_preview_end) )
1609 // edl->local_session->preview_end = edl->tracks->total_length();
1612 // Start examining next batch of index files
1613 mainindexes->start_build();
1615 // Don't save a backup after loading since the loaded file is on disk already.
1620 void MWindow::paste_silence()
1622 double start = edl->local_session->get_selectionstart();
1623 double end = edl->local_session->get_selectionend();
1624 undo->update_undo_before();
1625 edl->paste_silence(start, end,
1626 edl->session->labels_follow_edits,
1627 edl->session->plugins_follow_edits,
1628 edl->session->autos_follow_edits);
1629 edl->deglitch(start);
1633 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1635 update_plugin_guis();
1637 gui->update(1, 2, 1, 1, 1, 1, 0);
1638 cwindow->update(1, 0, 0, 0, 1);
1639 cwindow->playback_engine->que->
1640 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1643 void MWindow::detach_transition(Transition *transition)
1645 undo->update_undo_before();
1646 hide_plugin(transition, 1);
1647 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1648 transition->edit->detach_transition();
1650 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1652 if( is_video ) restart_brender();
1653 gui->update(0, 1, 0, 0, 0, 0, 0);
1654 sync_parameters(CHANGE_EDL);
1657 void MWindow::detach_transitions()
1659 gui->lock_window("MWindow::detach_transitions 1");
1661 undo->update_undo_before();
1662 double start = edl->local_session->get_selectionstart();
1663 double end = edl->local_session->get_selectionend();
1664 edl->tracks->clear_transitions(start, end);
1667 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1669 sync_parameters(CHANGE_EDL);
1670 gui->update(0, 1, 0, 0, 0, 0, 0);
1671 gui->unlock_window();
1674 void MWindow::paste_transition()
1676 // Only the first transition gets dropped.
1677 PluginServer *server = session->drag_pluginservers->values[0];
1679 undo->update_undo_before();
1681 strcpy(edl->session->default_atransition, server->title);
1683 strcpy(edl->session->default_vtransition, server->title);
1685 edl->tracks->paste_transition(server, session->edit_highlighted);
1687 undo->update_undo_after(_("transition"), LOAD_EDITS);
1689 if( server->video ) restart_brender();
1690 sync_parameters(CHANGE_ALL);
1693 void MWindow::paste_transitions(int track_type, char *title)
1695 gui->lock_window("MWindow::detach_transitions 1");
1697 undo->update_undo_before();
1698 double start = edl->local_session->get_selectionstart();
1699 double end = edl->local_session->get_selectionend();
1700 edl->tracks->paste_transitions(start, end, track_type, title);
1703 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1705 sync_parameters(CHANGE_EDL);
1706 gui->update(0, 1, 0, 0, 0, 0, 0);
1707 gui->unlock_window();
1710 void MWindow::paste_transition_cwindow(Track *dest_track)
1712 PluginServer *server = session->drag_pluginservers->values[0];
1713 undo->update_undo_before();
1714 edl->tracks->paste_video_transition(server, 1);
1716 undo->update_undo_after(_("transition"), LOAD_EDITS);
1718 gui->update(0, 1, 0, 0, 0, 0, 0);
1719 sync_parameters(CHANGE_ALL);
1722 void MWindow::paste_audio_transition()
1724 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1727 char string[BCTEXTLEN];
1728 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1729 gui->show_message(string);
1733 undo->update_undo_before();
1734 edl->tracks->paste_audio_transition(server);
1736 undo->update_undo_after(_("transition"), LOAD_EDITS);
1738 sync_parameters(CHANGE_EDL);
1739 gui->update(0, 1, 0, 0, 0, 0, 0);
1742 void MWindow::paste_video_transition()
1744 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1747 char string[BCTEXTLEN];
1748 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1749 gui->show_message(string);
1753 undo->update_undo_before();
1755 edl->tracks->paste_video_transition(server);
1757 undo->update_undo_after(_("transition"), LOAD_EDITS);
1759 sync_parameters(CHANGE_EDL);
1761 gui->update(0, 1, 0, 0, 0, 0, 0);
1764 void MWindow::shuffle_edits()
1766 gui->lock_window("MWindow::shuffle_edits 1");
1768 undo->update_undo_before();
1769 double start = edl->local_session->get_selectionstart();
1770 double end = edl->local_session->get_selectionend();
1772 edl->tracks->shuffle_edits(start, end);
1775 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1777 sync_parameters(CHANGE_EDL);
1779 gui->update(0, 1, 1, 0, 0, 0, 0);
1780 gui->unlock_window();
1783 void MWindow::reverse_edits()
1785 gui->lock_window("MWindow::reverse_edits 1");
1787 undo->update_undo_before();
1788 double start = edl->local_session->get_selectionstart();
1789 double end = edl->local_session->get_selectionend();
1791 edl->tracks->reverse_edits(start, end);
1794 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1796 sync_parameters(CHANGE_EDL);
1798 gui->update(0, 1, 1, 0, 0, 0, 0);
1799 gui->unlock_window();
1802 void MWindow::align_edits()
1804 gui->lock_window("MWindow::align_edits 1");
1806 undo->update_undo_before();
1807 double start = edl->local_session->get_selectionstart();
1808 double end = edl->local_session->get_selectionend();
1810 edl->tracks->align_edits(start, end);
1813 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1815 sync_parameters(CHANGE_EDL);
1817 gui->update(0, 1, 1, 0, 0, 0, 0);
1818 gui->unlock_window();
1821 void MWindow::set_edit_length(double length)
1823 gui->lock_window("MWindow::detach_transitions 1");
1825 undo->update_undo_before();
1826 double start = edl->local_session->get_selectionstart();
1827 double end = edl->local_session->get_selectionend();
1829 edl->tracks->set_edit_length(start, end, length);
1832 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1834 sync_parameters(CHANGE_EDL);
1836 gui->update(0, 1, 1, 0, 0, 0, 0);
1837 gui->unlock_window();
1841 void MWindow::set_transition_length(Transition *transition, double length)
1843 gui->lock_window("MWindow::detach_transitions 1");
1845 undo->update_undo_before();
1846 //double start = edl->local_session->get_selectionstart();
1847 //double end = edl->local_session->get_selectionend();
1849 edl->tracks->set_transition_length(transition, length);
1852 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1854 edl->session->default_transition_length = length;
1855 sync_parameters(CHANGE_PARAMS);
1856 gui->update(0, 1, 0, 0, 0, 0, 0);
1857 gui->unlock_window();
1860 void MWindow::set_transition_length(double length)
1862 gui->lock_window("MWindow::detach_transitions 1");
1864 undo->update_undo_before();
1865 double start = edl->local_session->get_selectionstart();
1866 double end = edl->local_session->get_selectionend();
1868 edl->tracks->set_transition_length(start, end, length);
1871 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1873 edl->session->default_transition_length = length;
1874 sync_parameters(CHANGE_PARAMS);
1876 gui->update(0, 1, 0, 0, 0, 0, 0);
1877 gui->unlock_window();
1881 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1884 calling_window_gui->unlock_window();
1886 cwindow->playback_engine->que->
1887 send_command(STOP, CHANGE_NONE, 0, 0);
1888 cwindow->playback_engine->interrupt_playback(0);
1890 for( int i = 0; i < vwindows.size(); i++ ) {
1891 if( vwindows.get(i)->is_running() ) {
1892 vwindows.get(i)->playback_engine->que->
1893 send_command(STOP, CHANGE_NONE, 0, 0);
1894 vwindows.get(i)->playback_engine->interrupt_playback(0);
1898 cwindow->gui->lock_window("MWindow::redo_entry");
1899 for( int i = 0; i < vwindows.size(); i++ ) {
1900 if( vwindows.get(i)->is_running() ) {
1901 if( calling_window_gui != vwindows.get(i)->gui ) {
1902 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1911 update_plugin_states();
1912 update_plugin_guis();
1914 gui->update(1, 2, 1, 1, 1, 1, 1);
1915 cwindow->update(1, 1, 1, 1, 1);
1917 if( calling_window_gui != cwindow->gui )
1918 cwindow->gui->unlock_window();
1919 if( calling_window_gui != gui )
1920 gui->unlock_window();
1923 for( int i = 0; i < vwindows.size(); i++ ) {
1924 if( vwindows.get(i)->is_running() ) {
1925 if( calling_window_gui != vwindows.get(i)->gui ) {
1926 vwindows.get(i)->gui->unlock_window();
1931 cwindow->playback_engine->que->
1932 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
1936 void MWindow::resize_track(Track *track, int w, int h)
1938 undo->update_undo_before();
1939 // We have to move all maskpoints so they do not move in relation to image areas
1940 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1941 (w - track->track_w) / 2,
1942 (h - track->track_h) / 2);
1945 undo->update_undo_after(_("resize track"), LOAD_ALL);
1949 sync_parameters(CHANGE_EDL);
1953 void MWindow::set_inpoint(int is_mwindow)
1955 undo->update_undo_before();
1956 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1958 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1961 gui->lock_window("MWindow::set_inpoint 1");
1963 gui->update_timebar(1);
1965 gui->unlock_window();
1969 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1971 cwindow->gui->timebar->update(1);
1973 cwindow->gui->unlock_window();
1977 void MWindow::set_outpoint(int is_mwindow)
1979 undo->update_undo_before();
1980 edl->set_outpoint(edl->local_session->get_selectionend(1));
1982 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1985 gui->lock_window("MWindow::set_outpoint 1");
1987 gui->update_timebar(1);
1989 gui->unlock_window();
1993 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1995 cwindow->gui->timebar->update(1);
1997 cwindow->gui->unlock_window();
2001 void MWindow::splice(EDL *source)
2005 undo->update_undo_before();
2006 double source_start = source->local_session->get_selectionstart();
2007 double source_end = source->local_session->get_selectionend();
2008 source->copy(source_start, source_end, 1, 0, 0, &file, "", 1);
2010 double start = edl->local_session->get_selectionstart();
2011 //double end = edl->local_session->get_selectionend();
2013 paste(start, start, &file,
2014 edl->session->labels_follow_edits,
2015 edl->session->plugins_follow_edits,
2016 edl->session->autos_follow_edits);
2018 // Position at end of clip
2019 edl->local_session->set_selectionstart(start + source_end - source_start);
2020 edl->local_session->set_selectionend(start + source_end - source_start);
2023 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2024 update_plugin_guis();
2026 gui->update(1, 1, 1, 1, 0, 1, 0);
2027 sync_parameters(CHANGE_EDL);
2030 void MWindow::save_clip(EDL *new_edl, const char *txt)
2032 new_edl->local_session->set_selectionstart(0);
2033 new_edl->local_session->set_selectionend(0);
2034 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2035 session->clip_number++);
2036 char duration[BCTEXTLEN];
2037 Units::totext(duration, new_edl->tracks->total_length(),
2038 new_edl->session->time_format,
2039 new_edl->session->sample_rate,
2040 new_edl->session->frame_rate,
2041 new_edl->session->frames_per_foot);
2043 Track *track = new_edl->tracks->first;
2044 const char *path = edl->path;
2045 for( ; (!path || !*path) && track; track=track->next ) {
2046 if( !track->record ) continue;
2047 Edit *edit = track->edits->first;
2048 if( !edit ) continue;
2049 Indexable *indexable = edit->get_source();
2050 if( !indexable ) continue;
2051 path = indexable->path;
2054 time_t now; time(&now);
2055 struct tm *tm = localtime(&now);
2056 char *cp = new_edl->local_session->clip_notes;
2057 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2059 n = snprintf(cp, sz, "%s", txt);
2062 n = snprintf(cp, sz,
2063 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2064 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
2065 tm->tm_hour, tm->tm_min, tm->tm_sec, duration);
2067 if( path && *path ) {
2069 char title[BCTEXTLEN];
2070 fs.extract_name(title, path);
2071 n = snprintf(cp, sz, "%s", title);
2076 edl->update_assets(new_edl);
2078 gui->get_abs_cursor(cur_x, cur_y, 0);
2079 gui->unlock_window();
2081 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2083 gui->lock_window("MWindow::save_clip");
2087 void MWindow::to_clip(EDL *edl, const char *txt)
2092 gui->lock_window("MWindow::to_clip 1");
2093 start = edl->local_session->get_selectionstart();
2094 end = edl->local_session->get_selectionend();
2096 if( EQUIV(end, start) ) {
2098 end = edl->tracks->total_length();
2101 // Don't copy all since we don't want the clips twice.
2102 edl->copy(start, end, 0, 0, 0, &file, "", 1);
2104 EDL *new_edl = new EDL(edl);
2105 new_edl->create_objects();
2106 new_edl->load_xml(&file, LOAD_ALL);
2107 save_clip(new_edl, txt);
2108 gui->unlock_window();
2111 int MWindow::toggle_label(int is_mwindow)
2113 double position1, position2;
2114 undo->update_undo_before();
2116 if( cwindow->playback_engine->is_playing_back ) {
2117 position1 = position2 =
2118 cwindow->playback_engine->get_tracking_position();
2121 position1 = edl->local_session->get_selectionstart(1);
2122 position2 = edl->local_session->get_selectionend(1);
2125 position1 = edl->align_to_frame(position1, 0);
2126 position2 = edl->align_to_frame(position2, 0);
2128 //printf("MWindow::toggle_label 1\n");
2130 edl->labels->toggle_label(position1, position2);
2134 gui->lock_window("MWindow::toggle_label 1");
2136 gui->update_timebar(0);
2137 gui->activate_timeline();
2140 gui->unlock_window();
2144 cwindow->gui->lock_window("MWindow::toggle_label 2");
2146 cwindow->gui->timebar->update(1);
2148 cwindow->gui->unlock_window();
2151 awindow->gui->async_update_assets();
2153 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2157 void MWindow::trim_selection()
2159 undo->update_undo_before();
2162 edl->trim_selection(edl->local_session->get_selectionstart(),
2163 edl->local_session->get_selectionend(),
2164 edl->session->labels_follow_edits,
2165 edl->session->plugins_follow_edits,
2166 edl->session->autos_follow_edits);
2168 edl->deglitch(edl->local_session->get_selectionend() -
2169 edl->local_session->get_selectionstart());
2173 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2174 update_plugin_guis();
2175 gui->update(1, 2, 1, 1, 1, 1, 0);
2176 cwindow->update(1, 0, 0, 0, 1);
2178 cwindow->playback_engine->que->
2179 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
2183 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2185 calling_window_gui->unlock_window();
2187 cwindow->playback_engine->que->
2188 send_command(STOP, CHANGE_NONE, 0, 0);
2189 cwindow->playback_engine->interrupt_playback(0);
2191 //printf("MWindow::undo_entry %d %d\n", __LINE__, vwindows.size());
2192 for( int i = 0; i < vwindows.size(); i++ ) {
2193 if( vwindows.get(i)->is_running() ) {
2194 vwindows.get(i)->playback_engine->que->
2195 send_command(STOP, CHANGE_NONE, 0, 0);
2196 vwindows.get(i)->playback_engine->interrupt_playback(0);
2200 cwindow->gui->lock_window("MWindow::undo_entry 1");
2201 for( int i = 0; i < vwindows.size(); i++ ) {
2202 if( vwindows.get(i)->is_running() ) {
2203 if( calling_window_gui != vwindows.get(i)->gui ) {
2204 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2208 gui->lock_window("MWindow::undo_entry 2");
2214 update_plugin_states();
2215 update_plugin_guis();
2217 gui->update(1, 2, 1, 1, 1, 1, 1);
2218 gui->unlock_window();
2219 cwindow->update(1, 1, 1, 1, 1);
2220 cwindow->gui->unlock_window();
2222 for( int i = 0; i < vwindows.size(); i++ ) {
2223 if( vwindows.get(i)->is_running() ) {
2224 if( calling_window_gui != vwindows.get(i)->gui ) {
2225 vwindows.get(i)->gui->unlock_window();
2230 if( calling_window_gui != gui )
2231 gui->unlock_window();
2233 awindow->gui->async_update_assets();
2235 cwindow->playback_engine->que->
2236 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
2237 calling_window_gui->lock_window("MWindow::undo_entry 4");
2241 void MWindow::new_folder(const char *new_folder)
2243 undo->update_undo_before();
2244 edl->new_folder(new_folder);
2245 undo->update_undo_after(_("new folder"), LOAD_ALL);
2246 awindow->gui->async_update_assets();
2249 void MWindow::delete_folder(char *folder)
2251 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2254 void MWindow::select_point(double position)
2256 edl->local_session->set_selectionstart(position);
2257 edl->local_session->set_selectionend(position);
2260 cwindow->update(1, 0, 0, 0, 1);
2262 update_plugin_guis();
2263 gui->update_patchbay();
2264 gui->hide_cursor(0);
2265 gui->draw_cursor(0);
2266 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2267 gui->zoombar->update();
2268 gui->update_timebar(0);
2269 gui->flash_canvas(0);
2276 void MWindow::map_audio(int pattern)
2278 undo->update_undo_before();
2279 remap_audio(pattern);
2280 undo->update_undo_after(
2281 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2283 sync_parameters(CHANGE_PARAMS);
2284 gui->update(0, 1, 0, 0, 1, 0, 0);
2287 void MWindow::remap_audio(int pattern)
2289 int current_channel = 0;
2290 int current_track = 0;
2291 for( Track *current = edl->tracks->first; current; current = NEXT ) {
2292 if( current->data_type == TRACK_AUDIO &&
2294 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2295 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2297 for( int i = 0; i < MAXCHANNELS; i++ ) {
2298 pan_auto->values[i] = 0.0;
2301 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2302 pan_auto->values[current_channel] = 1.0;
2305 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2306 switch( current_track ) {
2308 pan_auto->values[0] = 0.5;
2309 pan_auto->values[1] = 0.5;
2312 pan_auto->values[0] = 1;
2315 pan_auto->values[1] = 1;
2318 pan_auto->values[0] = 1;
2321 pan_auto->values[1] = 1;
2324 pan_auto->values[0] = 0.5;
2325 pan_auto->values[1] = 0.5;
2330 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2331 edl->session->achannel_positions, pan_auto->values,
2332 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2336 if( current_channel >= edl->session->audio_channels )
2337 current_channel = 0;
2342 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2343 ArrayList<Indexable*> *orig_assets,
2344 ArrayList<Indexable*> *proxy_assets)
2346 int orig_use_scaler = edl->session->proxy_use_scaler;
2347 int orig_scale = edl->session->proxy_scale;
2348 // rescale to full size asset in read_frame
2349 edl->session->proxy_use_scaler = use_scaler;
2350 edl->session->proxy_scale = new_scale;
2351 edl->session->proxy_auto_scale = auto_scale;
2354 for( int i=0; i<proxy_assets->size(); ++i ) {
2355 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2356 proxy_asset->width = orig_assets->get(i)->get_w();
2357 proxy_asset->height = orig_assets->get(i)->get_h();
2362 if( !orig_use_scaler && new_scale != orig_scale ) {
2364 float orig_w = (float)edl->session->output_w * orig_scale;
2365 float orig_h = (float)edl->session->output_h * orig_scale;
2366 edl->session->output_w = Units::round(orig_w / new_scale);
2367 edl->session->output_h = Units::round(orig_h / new_scale);
2370 for( Track *track=edl->tracks->first; track; track=track->next ) {
2371 if( track->data_type != TRACK_VIDEO ) continue;
2372 orig_w = (float)track->track_w * orig_scale;
2373 orig_h = (float)track->track_h * orig_scale;
2374 track->track_w = Units::round(orig_w / new_scale);
2375 track->track_h = Units::round(orig_h / new_scale);
2376 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2377 set_proxy(orig_scale, new_scale);
2378 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2379 set_proxy(orig_scale, new_scale);
2380 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2381 set_proxy(orig_scale, new_scale);
2382 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2383 set_proxy(orig_scale, new_scale);
2384 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2385 set_proxy(orig_scale, new_scale);
2389 // change original assets to proxy assets
2390 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2391 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2392 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2393 proxy_asset->awindow_folder = awindow_folder;
2394 // replace track contents
2395 for( Track *track = edl->tracks->first; track; track = track->next ) {
2396 if( track->data_type != TRACK_VIDEO ) continue;
2397 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2398 if( !edit->asset ) continue;
2399 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2400 edit->asset = proxy_asset;
2407 void MWindow::add_proxy(int use_scaler,
2408 ArrayList<Indexable*> *orig_assets,
2409 ArrayList<Indexable*> *proxy_assets)
2412 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2413 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2414 proxy_asset->width = orig_assets->get(i)->get_w();
2415 proxy_asset->height = orig_assets->get(i)->get_h();
2419 // change original assets to proxy assets
2420 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2421 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2422 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2423 // replace track contents
2424 for( Track *track = edl->tracks->first; track; track = track->next ) {
2425 if( track->data_type != TRACK_VIDEO ) continue;
2426 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2427 if( !edit->asset ) continue;
2428 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2429 edit->asset = proxy_asset;
2436 void MWindow::cut_commercials()
2438 undo->update_undo_before();
2439 commercials->scan_media();
2442 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2445 update_plugin_guis();
2446 gui->update(1, 2, 1, 1, 1, 1, 0);
2447 cwindow->update(1, 0, 0, 0, 1);
2448 cwindow->playback_engine->que->
2449 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);