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"
31 #include "cplayback.h"
34 #include "cwindowgui.h"
37 #include "edlsession.h"
38 #include "filesystem.h"
40 #include "floatauto.h"
41 #include "floatautos.h"
43 #include "gwindowgui.h"
45 #include "keyframes.h"
48 #include "levelwindow.h"
49 #include "localsession.h"
50 #include "mainclock.h"
51 #include "maincursor.h"
52 #include "mainerror.h"
53 #include "mainindexes.h"
55 #include "mainsession.h"
57 #include "maskautos.h"
59 #include "mwindowgui.h"
63 #include "playbackengine.h"
64 #include "pluginset.h"
65 #include "recordlabel.h"
66 #include "samplescroll.h"
67 #include "trackcanvas.h"
69 #include "trackscroll.h"
71 #include "transition.h"
72 #include "transportque.h"
74 #include "undostackitem.h"
75 #include "vplayback.h"
77 #include "vwindowgui.h"
80 #include "automation.h"
81 #include "maskautos.h"
85 void MWindow::add_audio_track_entry(int above, Track *dst)
88 Track *track = add_audio_track(above, dst);
91 undo_after(_("add track"), LOAD_ALL);
94 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
95 gui->activate_timeline();
96 cwindow->refresh_frame(CHANGE_EDL);
99 void MWindow::add_video_track_entry(int above, Track *dst)
102 Track *track = add_video_track(above, dst);
104 undo_after(_("add track"), LOAD_ALL);
108 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
109 gui->activate_timeline();
110 cwindow->refresh_frame(CHANGE_EDL);
114 void MWindow::add_subttl_track_entry(int above, Track *dst)
117 Track *track = add_subttl_track(above, dst);
119 undo_after(_("add track"), LOAD_ALL);
123 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
124 gui->activate_timeline();
125 cwindow->refresh_frame(CHANGE_EDL);
130 Track *MWindow::add_audio_track(int above, Track *dst)
132 Track *track = edl->tracks->add_audio_track(above, dst);
133 edl->tracks->update_y_pixels(theme);
138 Track *MWindow::add_video_track(int above, Track *dst)
140 Track *track = edl->tracks->add_video_track(above, dst);
141 edl->tracks->update_y_pixels(theme);
146 Track *MWindow::add_subttl_track(int above, Track *dst)
148 Track *track = edl->tracks->add_subttl_track(above, dst);
149 edl->tracks->update_y_pixels(theme);
154 void MWindow::asset_to_all()
156 if( !session->drag_assets->size() ) return;
157 Indexable *indexable = session->drag_assets->get(0);
159 // if( indexable->have_video() )
166 w = indexable->get_w();
167 h = indexable->get_h();
168 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
169 double old_framerate = edl->session->frame_rate;
170 int old_samplerate = edl->session->sample_rate;
171 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
174 if( indexable->have_video() ) {
175 edl->session->output_w = w;
176 edl->session->output_h = h;
177 edl->session->frame_rate = new_framerate;
179 edl->session->aspect_w,
180 edl->session->aspect_h,
183 for( Track *current=edl->tracks->first; current; current=NEXT ) {
184 if( current->data_type == TRACK_VIDEO /* &&
185 current->is_armed() */ ) {
186 current->track_w = w;
187 current->track_h = h;
192 if( ((edl->session->output_w % 4) ||
193 (edl->session->output_h % 4)) &&
194 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
195 MainError::show_error(
196 _("This project's dimensions are not multiples of 4 so\n"
197 "it can't be rendered by OpenGL."));
201 if( defaults->get("AUTOASPECT", 0) ) {
203 edl->session->aspect_w,
204 edl->session->aspect_h,
209 if( indexable->have_audio() ) {
210 edl->session->sample_rate = new_samplerate;
211 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
212 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
217 undo_after(_("asset to all"), LOAD_ALL);
219 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
220 sync_parameters(CHANGE_ALL);
224 void MWindow::asset_to_size()
226 if( !session->drag_assets->size() ) return;
227 Indexable *indexable = session->drag_assets->get(0);
229 if( indexable->have_video() ) {
234 w = indexable->get_w();
235 h = indexable->get_h();
236 edl->session->output_w = w;
237 edl->session->output_h = h;
239 if( ((edl->session->output_w % 4) ||
240 (edl->session->output_h % 4)) &&
241 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
242 MainError::show_error(
243 _("This project's dimensions are not multiples of 4 so\n"
244 "it can't be rendered by OpenGL."));
248 if( defaults->get("AUTOASPECT", 0) ) {
249 create_aspect_ratio(edl->session->aspect_w,
250 edl->session->aspect_h,
257 undo_after(_("asset to size"), LOAD_ALL);
259 sync_parameters(CHANGE_ALL);
264 void MWindow::asset_to_rate()
266 if( session->drag_assets->size() &&
267 session->drag_assets->get(0)->have_video() ) {
268 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
269 double old_framerate = edl->session->frame_rate;
272 edl->session->frame_rate = new_framerate;
273 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
277 undo_after(_("asset to rate"), LOAD_ALL);
279 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
280 sync_parameters(CHANGE_ALL);
285 void MWindow::clear_entry()
292 undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
295 update_plugin_guis();
296 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
297 cwindow->update(1, 0, 0, 0, 1);
298 cwindow->refresh_frame(CHANGE_EDL);
301 void MWindow::clear(int clear_handle)
303 double start = edl->local_session->get_selectionstart();
304 double end = edl->local_session->get_selectionend();
305 if( clear_handle || !EQUIV(start, end) ) {
308 edl->session->labels_follow_edits,
309 edl->session->plugins_follow_edits,
310 edl->session->autos_follow_edits);
314 void MWindow::update_gui(int changed_edl)
317 update_plugin_guis();
319 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
320 cwindow->update(1, 0, 0, 0, 1);
321 cwindow->refresh_frame(CHANGE_EDL);
324 gui->draw_overlays(1);
325 sync_parameters(CHANGE_PARAMS);
326 gui->update_patchbay();
327 cwindow->update(1, 0, 0);
331 void MWindow::set_automation_mode(int mode)
335 edl->tracks->set_automation_mode(
336 edl->local_session->get_selectionstart(),
337 edl->local_session->get_selectionend(),
339 int changed_edl = speed_after(1);
341 char string[BCSTRLEN];
342 sprintf(string,"set %s", FloatAuto::curve_name(mode));
344 !changed_edl ? LOAD_AUTOMATION :
345 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
346 update_gui(changed_edl);
349 void MWindow::clear_automation()
353 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
354 edl->local_session->get_selectionend());
355 int changed_edl = speed_after(1);
357 undo_after(_("clear keyframes"),
358 !changed_edl ? LOAD_AUTOMATION :
359 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
360 update_gui(changed_edl);
363 int MWindow::clear_default_keyframe()
367 edl->tracks->clear_default_keyframe();
368 int changed_edl = speed_after(1);
370 undo_after(_("clear default keyframe"),
371 !changed_edl ? LOAD_AUTOMATION :
372 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
373 update_gui(changed_edl);
377 void MWindow::clear_labels()
380 clear_labels(edl->local_session->get_selectionstart(),
381 edl->local_session->get_selectionend());
382 undo_after(_("clear labels"), LOAD_TIMEBAR);
384 gui->update_timebar(1);
385 cwindow->update(0, 0, 0, 0, 1);
389 int MWindow::clear_labels(double start, double end)
393 end = edl->tracks->total_length();
395 edl->labels->clear(start, end, 0);
399 void MWindow::clear_hard_edges()
402 clear_hard_edges(edl->local_session->get_selectionstart(),
403 edl->local_session->get_selectionend());
406 undo_after(_("clear hard edges"), LOAD_EDITS);
408 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
409 cwindow->refresh_frame(CHANGE_EDL);
412 int MWindow::clear_hard_edges(double start, double end)
416 end = edl->tracks->total_length();
418 edl->clear_hard_edges(start, end);
422 void MWindow::clear_select()
424 edl->tracks->clear_selected_edits();
425 gui->draw_overlays(1);
428 void MWindow::concatenate_tracks()
431 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
432 edl->session->autos_follow_edits);
434 undo_after(_("concatenate tracks"), LOAD_EDITS);
437 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
438 cwindow->refresh_frame(CHANGE_EDL);
442 int MWindow::copy_flags(int copy_flags)
444 if( !edl->session->labels_follow_edits )
445 copy_flags &= ~COPY_LABELS;
446 if( !edl->session->autos_follow_edits )
447 copy_flags &= ~COPY_AUTOS;
448 if( !edl->session->plugins_follow_edits )
449 copy_flags &= ~COPY_PLUGINS;
455 copy(edl->local_session->get_selectionstart(),
456 edl->local_session->get_selectionend());
459 int MWindow::copy(double start, double end)
461 if( start == end ) return 1;
464 edl->copy(copy_flags(), start, end, &file, "", 1);
465 const char *file_string = file.string();
466 long file_length = strlen(file_string);
467 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
468 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
473 int MWindow::copy_automation()
476 double start = edl->local_session->get_selectionstart();
477 double end = edl->local_session->get_selectionend();
478 edl->tracks->copy_automation(start, end, &file, 0, 1);
479 const char *file_string = file.string();
480 long file_length = strlen(file_string);
481 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
482 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
486 int MWindow::copy_default_keyframe()
489 double start = edl->local_session->get_selectionstart();
490 double end = edl->local_session->get_selectionend();
491 edl->tracks->copy_automation(start, end, &file, 1, 0);
492 const char *file_string = file.string();
493 long file_length = strlen(file_string);
494 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
495 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
499 // Uses cropping coordinates in edl session to crop and translate video.
500 // We modify the projector since camera automation depends on the track size.
501 void MWindow::crop_video(int mode)
504 // Clamp EDL crop region
505 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
506 edl->session->crop_x1 ^= edl->session->crop_x2;
507 edl->session->crop_x2 ^= edl->session->crop_x1;
508 edl->session->crop_x1 ^= edl->session->crop_x2;
510 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
511 edl->session->crop_y1 ^= edl->session->crop_y2;
512 edl->session->crop_y2 ^= edl->session->crop_y1;
513 edl->session->crop_y1 ^= edl->session->crop_y2;
516 case CROP_REFORMAT: {
517 float ctr_x = edl->session->output_w / 2.;
518 float ctr_y = edl->session->output_h / 2.;
519 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
520 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
521 float dx = -(new_x - ctr_x), dy = -(new_y - ctr_y);
522 edl->tracks->translate_projector(dx, dy, 1);
524 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
525 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
526 edl->session->crop_x1 = edl->session->crop_y1 = 0;
527 edl->session->crop_x2 = edl->session->output_w;
528 edl->session->crop_y2 = edl->session->output_h;
531 float old_w = edl->session->output_w;
532 float old_h = edl->session->output_h;
533 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
534 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
535 if( !new_w ) new_w = 1;
536 if( !new_h ) new_h = 1;
537 float xzoom = old_w / new_w, yzoom = old_h / new_h;
538 float new_z = bmin(xzoom, yzoom);
539 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
540 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
541 edl->tracks->crop_resize(new_x, new_y, new_z);
543 edl->session->crop_x1 = 0;
544 edl->session->crop_y1 = 0;
545 edl->session->crop_x2 = edl->session->output_w;
546 edl->session->crop_y2 = edl->session->output_h;
549 float old_w = edl->session->output_w;
550 float old_h = edl->session->output_h;
551 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
552 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
553 if( !new_w ) new_w = 1;
554 if( !new_h ) new_h = 1;
555 float xzoom = old_w / new_w, yzoom = old_h / new_h;
556 float new_z = bmin(xzoom, yzoom);
558 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
559 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
560 edl->tracks->crop_shrink(new_x, new_y, new_z);
564 // Recalculate aspect ratio
565 if( defaults->get("AUTOASPECT", 0) ) {
566 create_aspect_ratio(edl->session->aspect_w,
567 edl->session->aspect_h,
568 edl->session->output_w,
569 edl->session->output_h);
572 undo_after(_("crop"), LOAD_ALL);
575 cwindow->refresh_frame(CHANGE_ALL);
581 double start = edl->local_session->get_selectionstart();
582 double end = edl->local_session->get_selectionend();
583 if( EQUIV(start,end) )
589 void MWindow::blade(double position)
592 edl->blade(position);
595 undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
597 update_plugin_guis();
598 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
599 cwindow->update(1, 0, 0, 0, 1);
600 awindow->gui->async_update_assets();
601 cwindow->refresh_frame(CHANGE_EDL);
604 void MWindow::cut(double start, double end, double new_position)
608 edl->clear(start, end,
609 edl->session->labels_follow_edits,
610 edl->session->plugins_follow_edits,
611 edl->session->autos_follow_edits);
615 undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
616 if( new_position >= 0 ) {
617 edl->local_session->set_selectionstart(new_position);
618 edl->local_session->set_selectionend(new_position);
621 update_plugin_guis();
622 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
623 cwindow->update(1, 0, 0, 0, 1);
624 awindow->gui->async_update_assets();
625 cwindow->refresh_frame(CHANGE_EDL);
628 void MWindow::cut_left_edit()
630 double start_pos = edl->local_session->get_selectionstart(1);
631 double position = edl->prev_edit(start_pos);
632 if( position < start_pos )
633 cut(position, start_pos, position);
636 void MWindow::cut_right_edit()
638 double end_pos = edl->local_session->get_selectionend(1);
639 double position = edl->next_edit(end_pos);
640 if( end_pos < position )
641 cut(end_pos, position, end_pos);
644 void MWindow::cut_left_label()
646 double start_pos = edl->local_session->get_selectionstart(1);
647 Label *left_label = edl->labels->prev_label(start_pos);
648 if( !left_label ) return;
649 double position = left_label->position;
650 if( position < start_pos )
651 cut(position, start_pos, position);
654 void MWindow::cut_right_label()
656 double end_pos = edl->local_session->get_selectionend(1);
657 Label *right_label = edl->labels->next_label(end_pos);
658 if( !right_label ) return;
659 double position = right_label->position;
660 if( end_pos < position )
661 cut(end_pos, position, end_pos);
664 int MWindow::cut_automation()
669 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
670 edl->local_session->get_selectionend());
671 int changed_edl = speed_after(1);
673 undo_after(_("cut keyframes"),
674 !changed_edl ? LOAD_AUTOMATION :
675 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
676 update_gui(changed_edl);
680 int MWindow::cut_default_keyframe()
685 copy_default_keyframe();
686 edl->tracks->clear_default_keyframe();
687 int changed_edl = speed_after(1);
689 undo_after(_("cut default keyframe"),
690 !changed_edl ? LOAD_AUTOMATION :
691 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
692 update_gui(changed_edl);
697 void MWindow::delete_tracks()
700 edl->tracks->delete_tracks();
701 undo_after(_("delete tracks"), LOAD_ALL);
705 update_plugin_states();
707 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
708 cwindow->refresh_frame(CHANGE_EDL);
711 void MWindow::delete_track(Track *track)
714 edl->tracks->delete_track(track);
715 undo_after(_("delete track"), LOAD_ALL);
718 update_plugin_states();
720 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
721 cwindow->refresh_frame(CHANGE_EDL);
726 // Insert data from clipboard
727 void MWindow::insert(double position, FileXML *file,
728 int edit_labels, int edit_plugins, int edit_autos,
729 EDL *parent_edl, Track *first_track, int overwrite)
731 // For clipboard pasting make the new edl use a separate session
732 // from the master EDL. Then it can be resampled to the master rates.
733 // For splice, overwrite, and dragging need same session to get the assets.
734 EDL *edl = new EDL(parent_edl);
735 ArrayList<EDL*> new_edls;
736 uint32_t load_flags = LOAD_ALL;
739 new_edls.append(edl);
740 edl->create_objects();
745 if( parent_edl ) load_flags &= ~LOAD_SESSION;
746 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
747 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
749 edl->load_xml(file, load_flags);
752 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
756 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
757 edit_labels, edit_plugins, edit_autos, overwrite);
758 // if( vwindow->edl )
759 // printf("MWindow::insert 5 %f %f\n",
760 // vwindow->edl->local_session->in_point,
761 // vwindow->edl->local_session->out_point);
762 new_edls.remove_all();
763 edl->Garbage::remove_user();
764 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
767 void MWindow::insert_effects_canvas(Track *dest_track, double start, double length)
771 ArrayList<SharedLocation> shared_locations;
772 PluginSet *pluginset = session->pluginset_highlighted;
773 int gang = edl->session->gang_tracks != GANG_NONE ? 1 : 0;
774 int data_type = dest_track->data_type;
777 for( Track *track=dest_track; track; track=track->next ) {
778 if( gang && track->master && !first_track ) break;
779 if( track->data_type != data_type ) continue;
780 if( !track->is_armed() ) continue;
781 int module = edl->tracks->number_of(track);
782 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
783 PluginServer *plugin = session->drag_pluginservers->values[i];
784 int shared = gang; // && plugin->multichannel ? 1 : 0;
785 int plugin_type = !first_track && shared ?
786 PLUGIN_SHAREDPLUGIN : PLUGIN_STANDALONE;
787 SharedLocation *shared_location = !first_track ?
788 &shared_locations[i] : &shared_locations.append();
789 insert_effect(plugin->title, shared_location, track,
790 pluginset, start, length, plugin_type);
791 if( first_track && shared ) {
792 shared_location->module = module;
793 shared_location->plugin = pluginset ?
794 track->plugin_set.number_of(pluginset) :
795 track->plugin_set.total-1 ;
804 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
806 sync_parameters(CHANGE_EDL);
807 // GUI updated in TrackCanvas, after current_operations are reset
810 void MWindow::insert_effects_cwindow(Track *dest_track)
812 if( !dest_track ) return;
815 double length = dest_track->get_length();
817 if( edl->local_session->get_selectionend() >
818 edl->local_session->get_selectionstart() ) {
819 start = edl->local_session->get_selectionstart();
820 length = edl->local_session->get_selectionend() -
821 edl->local_session->get_selectionstart();
824 insert_effects_canvas(dest_track, start, length);
825 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
828 void MWindow::insert_effect(char *title, SharedLocation *shared_location,
829 int data_type, int plugin_type, int single_standalone)
831 Track *current = edl->tracks->first;
832 SharedLocation shared_location_local;
833 shared_location_local.copy_from(shared_location);
835 double start_pos = edl->local_session->get_selectionstart(1);
836 double end_pos = edl->local_session->get_selectionend(1);
837 for( ; current; current=NEXT ) {
838 if( current->data_type != data_type ) continue;
839 if( !current->is_armed() ) continue;
840 double start = start_pos, end = end_pos;
841 if( plugin_type == PLUGIN_STANDALONE && start >= end ) {
843 end = current->get_length();
845 double length = end - start;
846 insert_effect(title, &shared_location_local,
847 current, 0, start, length, plugin_type);
849 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
850 plugin_type = PLUGIN_SHAREDPLUGIN;
851 shared_location_local.module = edl->tracks->number_of(current);
852 shared_location_local.plugin = current->plugin_set.total - 1;
853 start_pos = start; end_pos = end;
860 void MWindow::insert_effect(char *title,
861 SharedLocation *shared_location, Track *track, PluginSet *plugin_set,
862 double start, double length, int plugin_type)
864 KeyFrame *default_keyframe = 0;
865 PluginServer *server = 0;
866 // Get default keyframe
867 if( plugin_type == PLUGIN_STANDALONE ) {
868 default_keyframe = new KeyFrame;
869 server = new PluginServer(*scan_plugindb(title, track->data_type));
871 server->open_plugin(0, preferences, edl, 0);
872 server->save_data(default_keyframe);
874 // Insert plugin object
875 track->insert_effect(title, shared_location, default_keyframe,
876 plugin_set, start, length, plugin_type);
879 if( plugin_type == PLUGIN_STANDALONE ) {
880 server->close_plugin();
882 delete default_keyframe;
886 int MWindow::modify_edithandles()
889 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
890 edl->modify_edithandles(session->drag_start,
891 session->drag_position, session->drag_handle, handle_mode,
892 edl->session->labels_follow_edits,
893 edl->session->plugins_follow_edits,
894 edl->session->autos_follow_edits,
895 session->drag_edit->group_id);
896 finish_modify_handles();
897 //printf("MWindow::modify_handles 1\n");
901 int MWindow::modify_pluginhandles()
905 edl->modify_pluginhandles(session->drag_start,
906 session->drag_position,
907 session->drag_handle,
908 edl->session->edit_handle_mode[session->drag_button],
909 edl->session->labels_follow_edits,
910 edl->session->autos_follow_edits,
911 session->trim_edits);
913 finish_modify_handles();
919 // Common to edithandles and plugin handles
920 void MWindow::finish_modify_handles()
922 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
923 double position = -1;
924 switch( edit_mode ) {
926 position = !session->drag_handle ?
927 session->drag_start : session->drag_position;
931 position = session->drag_position;
935 position = session->drag_start;
938 if( position >= 0 ) {
939 edl->local_session->set_selectionstart(position);
940 edl->local_session->set_selectionend(position);
942 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
946 sync_parameters(CHANGE_EDL);
947 update_plugin_guis();
948 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
949 // label list can be modified
950 awindow->gui->async_update_assets();
951 cwindow->update(1, 0, 0, 0, 1);
954 void MWindow::match_output_size(Track *track)
957 track->track_w = edl->session->output_w;
958 track->track_h = edl->session->output_h;
960 undo_after(_("match output size"), LOAD_ALL);
963 sync_parameters(CHANGE_EDL);
967 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
969 ArrayList<Edit*> edits;
971 delete_edits(&edits, msg, collapse);
974 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
976 if( !edits->size() ) return;
978 if( edl->session->labels_follow_edits )
979 edl->delete_edit_labels(edits, collapse);
980 edl->delete_edits(edits, collapse);
983 undo_after(msg, LOAD_EDITS);
986 cwindow->refresh_frame(CHANGE_EDL);
987 update_plugin_guis();
988 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
991 void MWindow::delete_edits(int collapse)
993 ArrayList<Edit*> edits;
994 edl->tracks->get_selected_edits(&edits);
995 delete_edits(&edits,_("del edit"), collapse);
998 // collapse - delete from timeline, not collapse replace with silence
999 // packed - omit unselected from selection, unpacked - replace unselected with silence
1000 void MWindow::cut_selected_edits(int collapse, int packed)
1002 selected_edits_to_clipboard(packed);
1003 ArrayList<Edit*> edits;
1004 edl->tracks->get_selected_edits(&edits);
1005 delete_edits(&edits, _("cut edit"), collapse);
1009 void MWindow::move_edits(ArrayList<Edit*> *edits,
1010 Track *track, double position, int mode)
1013 // lockout timebar labels update
1014 // labels can be deleted with tooltip repeater running
1015 cwindow->gui->lock_window("Tracks::move_edits");
1016 edl->tracks->move_edits(edits, track, position,
1017 edl->session->labels_follow_edits,
1018 edl->session->plugins_follow_edits,
1019 edl->session->autos_follow_edits, mode);
1020 cwindow->gui->timebar->update(1);
1021 cwindow->gui->unlock_window();
1024 undo_after(_("move edit"), LOAD_ALL);
1027 cwindow->refresh_frame(CHANGE_EDL);
1029 update_plugin_guis();
1030 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1033 void MWindow::selected_edits_to_clipboard(int packed)
1035 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1036 edl->session->labels_follow_edits,
1037 edl->session->autos_follow_edits,
1038 edl->session->plugins_follow_edits);
1039 if( !new_edl ) return;
1041 new_edl->copy(COPY_EDL, &file, "", 1);
1042 const char *file_string = file.string();
1043 long file_length = strlen(file_string);
1044 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1045 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1046 new_edl->remove_user();
1049 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1050 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1052 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1054 char *string = new char[len];
1055 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1057 file.read_from_string(string);
1059 EDL *clip = new EDL();
1060 clip->create_objects();
1061 if( !clip->load_xml(&file, LOAD_ALL) ) {
1063 edl->paste_edits(clip, first_track, position, overwrite,
1064 edit_edits, edit_labels, edit_autos, edit_plugins);
1066 undo_after(_("paste clip"), LOAD_ALL);
1068 cwindow->refresh_frame(CHANGE_EDL);
1070 update_plugin_guis();
1071 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1073 clip->remove_user();
1076 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1079 // lockout timebar labels update
1080 // labels can be deleted with tooltip repeater running
1081 cwindow->gui->lock_window("Tracks::move_group");
1083 ArrayList<Edit *>edits;
1084 edl->tracks->get_selected_edits(&edits);
1085 if( edl->session->labels_follow_edits )
1086 edl->delete_edit_labels(&edits, 0);
1087 edl->delete_edits(&edits, 0);
1088 edl->paste_edits(group, first_track, position, overwrite, 1,
1089 edl->session->labels_follow_edits,
1090 edl->session->autos_follow_edits,
1091 edl->session->plugins_follow_edits);
1092 cwindow->gui->timebar->update(1);
1093 cwindow->gui->unlock_window();
1094 // big debate over whether to do this, must either clear selected, or no tweaking
1095 // edl->tracks->clear_selected_edits();
1098 undo_after(_("move group"), LOAD_ALL);
1100 cwindow->refresh_frame(CHANGE_EDL);
1102 update_plugin_guis();
1103 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1106 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1109 edl->tracks->move_effect(plugin, track, position);
1111 undo_after(_("paste effect"), LOAD_ALL);
1114 cwindow->refresh_frame(CHANGE_EDL);
1115 update_plugin_guis();
1116 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1119 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1122 edl->tracks->move_effect(plugin, plugin_set, position);
1124 undo_after(_("move effect"), LOAD_ALL);
1127 cwindow->refresh_frame(CHANGE_EDL);
1128 update_plugin_guis();
1129 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1132 void MWindow::move_plugins_up(PluginSet *plugin_set)
1136 plugin_set->track->move_plugins_up(plugin_set);
1139 undo_after(_("move effect up"), LOAD_ALL);
1141 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1142 sync_parameters(CHANGE_EDL);
1145 void MWindow::move_plugins_down(PluginSet *plugin_set)
1149 plugin_set->track->move_plugins_down(plugin_set);
1152 undo_after(_("move effect down"), LOAD_ALL);
1154 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1155 sync_parameters(CHANGE_EDL);
1158 void MWindow::move_track_down(Track *track)
1161 edl->tracks->move_track_down(track);
1163 undo_after(_("move track down"), LOAD_ALL);
1166 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1167 sync_parameters(CHANGE_EDL);
1171 void MWindow::move_tracks_down()
1174 edl->tracks->move_tracks_down();
1176 undo_after(_("move tracks down"), LOAD_ALL);
1179 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1180 sync_parameters(CHANGE_EDL);
1184 void MWindow::move_track_up(Track *track)
1187 edl->tracks->move_track_up(track);
1189 undo_after(_("move track up"), LOAD_ALL);
1191 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1192 sync_parameters(CHANGE_EDL);
1196 void MWindow::move_tracks_up()
1199 edl->tracks->move_tracks_up();
1201 undo_after(_("move tracks up"), LOAD_ALL);
1203 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1204 sync_parameters(CHANGE_EDL);
1208 void MWindow::mute_selection()
1210 double start = edl->local_session->get_selectionstart();
1211 double end = edl->local_session->get_selectionend();
1212 if( start != end ) {
1214 edl->clear(start, end, 0,
1215 edl->session->plugins_follow_edits,
1216 edl->session->autos_follow_edits);
1217 edl->local_session->set_selectionend(end);
1218 edl->local_session->set_selectionstart(start);
1219 edl->paste_silence(start, end, 0,
1220 edl->session->plugins_follow_edits,
1221 edl->session->autos_follow_edits);
1224 undo_after(_("mute"), LOAD_EDITS);
1227 update_plugin_guis();
1228 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1229 cwindow->refresh_frame(CHANGE_EDL);
1234 void MWindow::overwrite(EDL *source, int all)
1238 LocalSession *src = source->local_session;
1239 double src_start = all ? 0 :
1240 src->inpoint_valid() ? src->get_inpoint() :
1241 src->outpoint_valid() ? 0 :
1242 src->get_selectionstart();
1243 double src_end = all ? source->tracks->total_length() :
1244 src->outpoint_valid() ? src->get_outpoint() :
1245 src->inpoint_valid() ? source->tracks->total_length() :
1246 src->get_selectionend();
1247 double overwrite_len = src_end - src_start;
1248 double dst_start = edl->local_session->get_selectionstart();
1249 double dst_len = edl->local_session->get_selectionend() - dst_start;
1252 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1253 // in/out points or selection present and shorter than overwrite range
1254 // shorten the copy range
1255 overwrite_len = dst_len;
1258 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1260 // HACK around paste_edl get_start/endselection on its own
1261 // so we need to clear only when not using both io points
1262 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1263 if( edl->local_session->get_inpoint() < 0 ||
1264 edl->local_session->get_outpoint() < 0 )
1265 edl->clear(dst_start, dst_start + overwrite_len,
1266 edl->session->labels_follow_edits,
1267 edl->session->plugins_follow_edits,
1268 edl->session->autos_follow_edits);
1270 paste(dst_start, dst_start + overwrite_len, &file,
1271 edl->session->labels_follow_edits,
1272 edl->session->plugins_follow_edits,
1273 edl->session->autos_follow_edits, 0, 0);
1275 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1276 edl->local_session->set_selectionend(dst_start + overwrite_len);
1279 undo_after(_("overwrite"), LOAD_EDITS);
1282 update_plugin_guis();
1283 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1284 sync_parameters(CHANGE_EDL);
1287 // For splice and overwrite
1288 int MWindow::paste(double start, double end, FileXML *file,
1289 int edit_labels, int edit_plugins, int edit_autos,
1290 Track *first_track, int overwrite)
1294 // Want to insert with assets shared with the master EDL.
1296 edit_labels, edit_plugins, edit_autos,
1297 edl, first_track, overwrite);
1302 // For editing using insertion point
1303 void MWindow::paste()
1305 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1308 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1310 //double end = edl->local_session->get_selectionend();
1311 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1314 char *string = new char[len];
1316 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1318 file.read_from_string(string);
1319 if( clear_selection ) clear(0);
1321 insert(start, &file,
1322 edl->session->labels_follow_edits,
1323 edl->session->plugins_follow_edits,
1324 edl->session->autos_follow_edits,
1325 0, first_track, overwrite);
1332 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1334 update_plugin_guis();
1335 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1336 awindow->gui->async_update_assets();
1337 sync_parameters(CHANGE_EDL);
1342 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1347 if( session->drag_assets->total ) {
1348 load_assets(session->drag_assets,
1349 position, LOADMODE_PASTE, dest_track, 0,
1350 edl->session->labels_follow_edits,
1351 edl->session->plugins_follow_edits,
1352 edl->session->autos_follow_edits,
1357 if( session->drag_clips->total ) {
1358 paste_edls(session->drag_clips,
1359 LOADMODE_PASTE, dest_track, position,
1360 edl->session->labels_follow_edits,
1361 edl->session->plugins_follow_edits,
1362 edl->session->autos_follow_edits,
1369 undo_after(_("paste assets"), LOAD_EDITS);
1371 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1372 sync_parameters(CHANGE_EDL);
1376 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1377 double position, int load_mode, Track *first_track, RecordLabels *labels,
1378 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1380 if( load_mode == LOADMODE_RESOURCESONLY )
1381 load_mode = LOADMODE_ASSETSONLY;
1382 const int debug = 0;
1383 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1385 position = edl->local_session->get_selectionstart();
1387 ArrayList<EDL*> new_edls;
1388 for( int i=0; i<new_assets->total; ++i ) {
1389 Indexable *indexable = new_assets->get(i);
1390 if( indexable->is_asset ) {
1391 remove_from_caches(indexable);
1393 EDL *new_edl = new EDL;
1394 new_edl->create_objects();
1395 new_edl->copy_session(edl);
1396 if( !indexable->is_asset ) {
1397 EDL *nested_edl = (EDL*)indexable;
1398 new_edl->create_nested(nested_edl);
1399 new_edl->set_path(indexable->path);
1402 Asset *asset = (Asset*)indexable;
1403 asset_to_edl(new_edl, asset);
1405 new_edls.append(new_edl);
1408 for( RecordLabel *label=labels->first; label; label=label->next ) {
1409 new_edl->labels->toggle_label(label->position, label->position);
1413 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1415 paste_edls(&new_edls, load_mode, first_track, position,
1416 edit_labels, edit_plugins, edit_autos, overwrite);
1417 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1420 for( int i=0; i<new_edls.size(); ++i )
1421 new_edls.get(i)->Garbage::remove_user();
1423 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1426 int MWindow::paste_automation()
1428 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1433 char *string = new char[len];
1434 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1436 file.read_from_string(string);
1438 double start = edl->local_session->get_selectionstart();
1439 double end = edl->local_session->get_selectionend();
1440 edl->tracks->clear_automation(start, end);
1441 edl->tracks->paste_automation(start, &file, 0, 1,
1442 edl->session->typeless_keyframes);
1443 int changed_edl = speed_after(1);
1445 undo_after(_("paste keyframes"),
1446 !changed_edl ? LOAD_AUTOMATION :
1447 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1448 update_gui(changed_edl);
1454 int MWindow::paste_default_keyframe()
1456 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1461 char *string = new char[len];
1462 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1464 file.read_from_string(string);
1466 double start = edl->local_session->get_selectionstart();
1467 edl->tracks->paste_automation(start, &file, 1, 0,
1468 edl->session->typeless_keyframes);
1469 // edl->tracks->paste_default_keyframe(&file);
1470 int changed_edl = speed_after(1);
1471 undo_after(_("paste default keyframe"),
1472 !changed_edl ? LOAD_AUTOMATION :
1473 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1475 update_gui(changed_edl);
1482 // Insert edls with project deletion and index file generation.
1483 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1484 Track *first_track, double current_position,
1485 int edit_labels, int edit_plugins, int edit_autos,
1489 ArrayList<Track*> destination_tracks;
1490 int need_new_tracks = 0;
1493 if( !new_edls->total ) return 0;
1496 // double original_length = edl->tracks->total_length();
1497 // double original_preview_end = edl->local_session->preview_end;
1500 // Delete current project
1501 if( load_mode == LOADMODE_REPLACE ||
1502 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1504 edl->save_defaults(defaults);
1506 edl->Garbage::remove_user();
1508 edl->create_objects();
1509 edl->copy_session(new_edls->values[0]);
1510 edl->copy_mixers(new_edls->values[0]);
1511 gui->mainmenu->update_toggles(0);
1512 gui->unlock_window();
1513 gwindow->gui->update_toggles(1);
1514 gui->lock_window("MWindow::paste_edls");
1516 // Insert labels for certain modes constitutively
1520 // Force reset of preview
1521 // original_length = 0;
1522 // original_preview_end = -1;
1528 // Create new tracks in master EDL
1529 if( load_mode == LOADMODE_REPLACE ||
1530 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1531 load_mode == LOADMODE_NEW_TRACKS ) {
1533 need_new_tracks = 1;
1534 for( int i=0; i<new_edls->total; ++i ) {
1535 EDL *new_edl = new_edls->values[i];
1536 int first_track = 1;
1537 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1538 switch( current->data_type ) {
1540 edl->tracks->add_video_track(0, 0);
1541 if( current->draw ) edl->tracks->last->draw = 1;
1544 edl->tracks->add_audio_track(0, 0);
1546 case TRACK_SUBTITLE:
1547 edl->tracks->add_subttl_track(0, 0);
1553 edl->tracks->last->master = 1;
1556 // re-label only if not already labeled
1557 if( new_edl->local_session->asset2edl )
1558 strcpy(current->title, edl->tracks->last->title);
1559 destination_tracks.append(edl->tracks->last);
1562 // Base track count on first EDL only for concatenation
1563 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1565 edl->session->highlighted_track = edl->tracks->total() - 1;
1568 // Recycle existing tracks of master EDL
1569 if( load_mode == LOADMODE_CONCATENATE ||
1570 load_mode == LOADMODE_PASTE ) {
1571 Track *current = first_track ? first_track : edl->tracks->first;
1572 for( ; current; current=NEXT ) {
1573 if( current->is_armed() ) {
1574 destination_tracks.append(current);
1580 int destination_track = 0;
1581 double *paste_position = new double[destination_tracks.total];
1583 // Iterate through the edls
1584 for( int i=0; i<new_edls->total; ++i ) {
1586 EDL *new_edl = new_edls->values[i];
1587 double edl_length = new_edl->local_session->clipboard_length ?
1588 new_edl->local_session->clipboard_length :
1589 new_edl->tracks->total_length();
1590 // printf("MWindow::paste_edls 2 %f %f\n",
1591 // new_edl->local_session->clipboard_length,
1592 // new_edl->tracks->total_length());
1596 // Convert EDL to master rates
1597 new_edl->resample(new_edl->session->sample_rate,
1598 edl->session->sample_rate,
1600 new_edl->resample(new_edl->session->frame_rate,
1601 edl->session->frame_rate,
1604 // Add assets and prepare index files
1605 for( Asset *new_asset=new_edl->assets->first;
1606 new_asset; new_asset=new_asset->next ) {
1607 mainindexes->add_indexable(new_asset);
1609 // Capture index file status from mainindex test
1610 edl->update_assets(new_edl);
1612 // Get starting point of insertion. Need this to paste labels.
1613 switch( load_mode ) {
1614 case LOADMODE_NOTHING:
1616 case LOADMODE_REPLACE:
1617 current_position = 0;
1619 case LOADMODE_NEW_TRACKS:
1621 current_position = 0;
1624 case LOADMODE_CONCATENATE:
1625 case LOADMODE_REPLACE_CONCATENATE:
1626 destination_track = 0;
1627 if( destination_tracks.total )
1628 current_position = destination_tracks.values[0]->get_length();
1630 current_position = 0;
1633 case LOADMODE_PASTE:
1634 destination_track = 0;
1636 for( int j=0; j<destination_tracks.total; ++j ) {
1637 paste_position[j] = (current_position >= 0) ?
1639 edl->local_session->get_selectionstart();
1644 case LOADMODE_RESOURCESONLY:
1645 edl->add_clip(new_edl);
1649 if( load_mode != LOADMODE_RESOURCESONLY &&
1650 load_mode != LOADMODE_ASSETSONLY ) {
1653 if( load_mode == LOADMODE_PASTE )
1654 edl->labels->insert_labels(new_edl->labels,
1655 destination_tracks.total ? paste_position[0] : 0.0,
1658 edl->labels->insert_labels(new_edl->labels, current_position,
1661 double total_length = new_edl->tracks->total_length();
1662 for( Track *new_track=new_edl->tracks->first;
1663 new_track; new_track=new_track->next ) {
1664 // Get destination track of same type as new_track
1666 k < destination_tracks.total &&
1667 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1668 ++k, ++destination_track ) {
1669 if( destination_track >= destination_tracks.total - 1 )
1670 destination_track = 0;
1673 // Insert data into destination track
1674 if( destination_track < destination_tracks.total &&
1675 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1676 Track *track = destination_tracks.values[destination_track];
1677 // Replace default keyframes if first EDL and new tracks were created.
1678 // This means data copied from one track and pasted to another won't retain
1679 // the camera position unless it's a keyframe. If it did, previous data in the
1680 // track might get unknowingly corrupted. Ideally we would detect when differing
1681 // default keyframes existed and create discrete keyframes for both.
1682 int replace_default = (i == 0) && need_new_tracks;
1683 // master tracks are the first track in each new edl when new tracks are created
1684 int master = track->master;
1685 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1686 // Insert new track at current position
1687 switch( load_mode ) {
1688 case LOADMODE_REPLACE_CONCATENATE:
1689 case LOADMODE_CONCATENATE:
1690 current_position = track->get_length();
1693 case LOADMODE_PASTE:
1694 current_position = paste_position[destination_track];
1695 paste_position[destination_track] += new_track->get_length();
1699 double length = overwrite >= 0 ?
1700 new_track->get_length() : total_length;
1701 track->clear(current_position,
1702 current_position + length,
1704 edit_labels, edit_plugins, edit_autos,
1708 track->insert_track(new_track, current_position, replace_default,
1709 edit_plugins, edit_autos, edl_length);
1710 if( master ) track->master = 1;
1714 // Get next destination track
1715 destination_track++;
1716 if( destination_track >= destination_tracks.total )
1717 destination_track = 0;
1721 if( load_mode == LOADMODE_PASTE )
1722 current_position += edl_length;
1726 // Move loading of clips and vwindow to the end - this fixes some
1727 // strange issue, for index not being shown
1728 // Assume any paste operation from the same EDL won't contain any clips.
1729 // If it did it would duplicate every clip here.
1730 for( int i=0; i<new_edls->total; ++i ) {
1731 EDL *new_edl = new_edls->get(i);
1733 for( int j=0; j<new_edl->clips.size(); ++j ) {
1734 edl->add_clip(new_edl->clips[j]);
1736 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1737 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1740 if( new_edl->total_vwindow_edls() ) {
1741 // if( edl->vwindow_edl )
1742 // edl->vwindow_edl->Garbage::remove_user();
1743 // edl->vwindow_edl = new EDL(edl);
1744 // edl->vwindow_edl->create_objects();
1745 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1747 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1748 EDL *vwindow_edl = new EDL(edl);
1749 vwindow_edl->create_objects();
1750 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1751 edl->append_vwindow_edl(vwindow_edl, 0);
1756 if( paste_position ) delete [] paste_position;
1758 // This is already done in load_filenames and everything else that uses paste_edls
1759 // update_project(load_mode);
1761 // Fix preview range
1762 // if( EQUIV(original_length, original_preview_end) )
1764 // edl->local_session->preview_end = edl->tracks->total_length();
1767 // Start examining next batch of index files
1768 mainindexes->start_build();
1770 // Don't save a backup after loading since the loaded file is on disk already.
1775 void MWindow::paste_silence()
1777 double start = edl->local_session->get_selectionstart();
1778 double end = edl->local_session->get_selectionend();
1779 if( EQUIV(start, end) ) {
1780 if( edl->session->frame_rate > 0 )
1781 end += 1./edl->session->frame_rate;
1783 undo_before(_("silence"), this);
1784 edl->paste_silence(start, end,
1785 edl->session->labels_follow_edits,
1786 edl->session->plugins_follow_edits,
1787 edl->session->autos_follow_edits);
1790 undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1792 update_plugin_guis();
1794 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1795 cwindow->update(1, 0, 0, 0, 1);
1796 cwindow->refresh_frame(CHANGE_EDL);
1799 void MWindow::detach_transition(Transition *transition)
1802 hide_plugin(transition, 1);
1803 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1804 transition->edit->detach_transition();
1806 undo_after(_("detach transition"), LOAD_ALL);
1808 if( is_video ) restart_brender();
1809 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1810 sync_parameters(CHANGE_EDL);
1813 void MWindow::detach_transitions()
1815 gui->lock_window("MWindow::detach_transitions 1");
1818 double start = edl->local_session->get_selectionstart();
1819 double end = edl->local_session->get_selectionend();
1820 edl->tracks->clear_transitions(start, end);
1823 undo_after(_("detach transitions"), LOAD_EDITS);
1825 sync_parameters(CHANGE_EDL);
1826 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1827 gui->unlock_window();
1830 void MWindow::paste_transition()
1832 // Only the first transition gets dropped.
1833 PluginServer *server = session->drag_pluginservers->values[0];
1836 edl->tracks->paste_transition(server, session->edit_highlighted);
1838 undo_after(_("transition"), LOAD_EDITS);
1840 if( server->video ) restart_brender();
1841 sync_parameters(CHANGE_ALL);
1844 void MWindow::paste_transitions(int track_type, char *title)
1846 gui->lock_window("MWindow::detach_transitions 1");
1849 double start = edl->local_session->get_selectionstart();
1850 double end = edl->local_session->get_selectionend();
1851 edl->tracks->paste_transitions(start, end, track_type, title);
1853 undo_after(_("attach transitions"), LOAD_EDITS);
1855 sync_parameters(CHANGE_EDL);
1856 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1857 gui->unlock_window();
1860 void MWindow::paste_transition_cwindow(Track *dest_track)
1862 PluginServer *server = session->drag_pluginservers->values[0];
1864 edl->tracks->paste_video_transition(server, 1);
1866 undo_after(_("transition"), LOAD_EDITS);
1868 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1869 sync_parameters(CHANGE_ALL);
1872 void MWindow::paste_audio_transition()
1874 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1877 char string[BCTEXTLEN];
1878 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1879 gui->show_message(string);
1884 edl->tracks->paste_audio_transition(server);
1886 undo_after(_("transition"), LOAD_EDITS);
1888 sync_parameters(CHANGE_EDL);
1889 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1892 void MWindow::paste_video_transition()
1894 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1897 char string[BCTEXTLEN];
1898 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1899 gui->show_message(string);
1905 edl->tracks->paste_video_transition(server);
1907 undo_after(_("transition"), LOAD_EDITS);
1909 sync_parameters(CHANGE_EDL);
1911 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1914 void MWindow::shuffle_edits()
1916 gui->lock_window("MWindow::shuffle_edits 1");
1919 double start = edl->local_session->get_selectionstart();
1920 double end = edl->local_session->get_selectionend();
1922 edl->tracks->shuffle_edits(start, end);
1925 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1927 sync_parameters(CHANGE_EDL);
1929 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1930 gui->unlock_window();
1933 void MWindow::reverse_edits()
1935 gui->lock_window("MWindow::reverse_edits 1");
1938 double start = edl->local_session->get_selectionstart();
1939 double end = edl->local_session->get_selectionend();
1941 edl->tracks->reverse_edits(start, end);
1944 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1946 sync_parameters(CHANGE_EDL);
1948 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1949 gui->unlock_window();
1952 void MWindow::align_edits()
1954 gui->lock_window("MWindow::align_edits 1");
1957 double start = edl->local_session->get_selectionstart();
1958 double end = edl->local_session->get_selectionend();
1960 edl->tracks->align_edits(start, end);
1963 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1965 sync_parameters(CHANGE_EDL);
1967 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1968 gui->unlock_window();
1971 void MWindow::set_edit_length(double length)
1973 gui->lock_window("MWindow::set_edit_length 1");
1976 double start = edl->local_session->get_selectionstart();
1977 double end = edl->local_session->get_selectionend();
1979 edl->tracks->set_edit_length(start, end, length);
1982 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1984 sync_parameters(CHANGE_EDL);
1986 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1987 gui->unlock_window();
1991 void MWindow::set_transition_length(Transition *transition, double length)
1993 gui->lock_window("MWindow::set_transition_length 1");
1996 //double start = edl->local_session->get_selectionstart();
1997 //double end = edl->local_session->get_selectionend();
1999 edl->tracks->set_transition_length(transition, length);
2002 undo_after(_("transition length"), LOAD_EDITS);
2004 edl->session->default_transition_length = length;
2005 sync_parameters(CHANGE_PARAMS);
2006 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2007 gui->unlock_window();
2010 void MWindow::set_transition_length(double length)
2012 gui->lock_window("MWindow::set_transition_length 2");
2015 double start = edl->local_session->get_selectionstart();
2016 double end = edl->local_session->get_selectionend();
2018 edl->tracks->set_transition_length(start, end, length);
2021 undo_after(_("transition length"), LOAD_EDITS);
2023 edl->session->default_transition_length = length;
2024 sync_parameters(CHANGE_PARAMS);
2026 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2027 gui->unlock_window();
2031 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2033 calling_window_gui->unlock_window();
2035 if( undo->redo_load_flags() & LOAD_SESSION )
2038 cwindow->gui->lock_window("MWindow::redo_entry 1");
2039 for( int i=0; i<vwindows.size(); ++i ) {
2040 if( vwindows.get(i)->is_running() ) {
2041 if( calling_window_gui != vwindows.get(i)->gui ) {
2042 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2046 gui->lock_window("MWindow::redo_entry 3");
2052 update_plugin_states();
2053 update_plugin_guis();
2055 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2056 gui->update_proxy_toggle();
2057 gui->unlock_window();
2058 cwindow->gui->unlock_window();
2059 cwindow->update(1, 1, 1, 1, 1);
2061 for( int i=0; i < vwindows.size(); ++i ) {
2062 if( vwindows.get(i)->is_running() ) {
2063 if( calling_window_gui != vwindows.get(i)->gui ) {
2064 vwindows.get(i)->gui->unlock_window();
2069 awindow->gui->async_update_assets();
2071 cwindow->refresh_frame(CHANGE_ALL);
2072 calling_window_gui->lock_window("MWindow::redo_entry 4");
2076 void MWindow::resize_track(Track *track, int w, int h)
2079 // We have to move all maskpoints so they do not move in relation to image areas
2080 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2081 (w - track->track_w) / 2,
2082 (h - track->track_h) / 2);
2085 undo_after(_("resize track"), LOAD_ALL);
2089 sync_parameters(CHANGE_EDL);
2093 void MWindow::set_inpoint()
2096 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2098 undo_after(_("in point"), LOAD_TIMEBAR);
2099 gui->update_timebar(1);
2101 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2102 cwindow->gui->timebar->update(1);
2103 cwindow->gui->unlock_window();
2106 void MWindow::set_outpoint()
2109 edl->set_outpoint(edl->local_session->get_selectionend(1));
2111 undo_after(_("out point"), LOAD_TIMEBAR);
2113 gui->update_timebar(1);
2114 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2115 cwindow->gui->timebar->update(1);
2116 cwindow->gui->unlock_window();
2119 void MWindow::unset_inoutpoint()
2122 edl->unset_inoutpoint();
2124 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2126 gui->update_timebar(1);
2127 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2128 cwindow->gui->timebar->update(1);
2129 cwindow->gui->unlock_window();
2132 void MWindow::splice(EDL *source, int all)
2135 LocalSession *src = source->local_session;
2138 double source_start = all ? 0 :
2139 src->inpoint_valid() ? src->get_inpoint() :
2140 src->outpoint_valid() ? 0 : src->get_selectionstart();
2141 double source_end = all ? source->tracks->total_length() :
2142 src->outpoint_valid() ? src->get_outpoint() :
2143 src->inpoint_valid() ? source->tracks->total_length() :
2144 src->get_selectionend();
2145 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2147 double start = edl->local_session->get_selectionstart();
2148 //double end = edl->local_session->get_selectionend();
2150 paste(start, start, &file,
2151 edl->session->labels_follow_edits,
2152 edl->session->plugins_follow_edits,
2153 edl->session->autos_follow_edits,
2156 // Position at end of clip
2157 edl->local_session->set_selectionstart(start + source_end - source_start);
2158 edl->local_session->set_selectionend(start + source_end - source_start);
2161 undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2162 update_plugin_guis();
2164 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2165 sync_parameters(CHANGE_EDL);
2168 void MWindow::save_clip(EDL *new_edl, const char *txt)
2170 new_edl->local_session->set_selectionstart(0);
2171 new_edl->local_session->set_selectionend(0);
2172 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2173 session->clip_number++);
2174 char duration[BCTEXTLEN];
2175 Units::totext(duration, new_edl->tracks->total_length(),
2176 new_edl->session->time_format,
2177 new_edl->session->sample_rate,
2178 new_edl->session->frame_rate,
2179 new_edl->session->frames_per_foot);
2181 Track *track = new_edl->tracks->first;
2182 const char *path = edl->path;
2183 for( ; (!path || !*path) && track; track=track->next ) {
2184 if( !track->is_armed() ) continue;
2185 Edit *edit = track->edits->first;
2186 if( !edit ) continue;
2187 Indexable *indexable = edit->get_source();
2188 if( !indexable ) continue;
2189 path = indexable->path;
2192 time_t now; time(&now);
2193 struct tm dtm; localtime_r(&now, &dtm);
2194 char *cp = new_edl->local_session->clip_notes;
2195 char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2197 cp += snprintf(cp, ep-cp, "%s", txt);
2198 cp += snprintf(cp, ep-cp,
2199 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2200 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2201 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2202 if( path && *path ) {
2204 char title[BCTEXTLEN];
2205 fs.extract_name(title, path);
2206 cp += snprintf(cp, ep-cp, "%s", title);
2208 sprintf(new_edl->local_session->clip_icon,
2209 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2210 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2211 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2213 new_edl->folder_no = AW_CLIP_FOLDER;
2214 edl->update_assets(new_edl);
2216 gui->get_abs_cursor(cur_x, cur_y, 0);
2217 gui->unlock_window();
2219 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2220 new_edl->remove_user();
2222 gui->lock_window("MWindow::save_clip");
2226 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2229 LocalSession *src = edl->local_session;
2231 gui->lock_window("MWindow::to_clip 1");
2232 double start = all ? 0 :
2233 src->inpoint_valid() ? src->get_inpoint() :
2234 src->outpoint_valid() ? 0 : src->get_selectionstart();
2235 double end = all ? edl->tracks->total_length() :
2236 src->outpoint_valid() ? src->get_outpoint() :
2237 src->inpoint_valid() ? edl->tracks->total_length() :
2238 src->get_selectionend();
2239 if( EQUIV(end, start) ) {
2241 end = edl->tracks->total_length();
2244 // Don't copy all since we don't want the clips twice.
2245 edl->copy(copy_flags(), start, end, &file, "", 1);
2247 EDL *new_edl = new EDL(edl);
2248 new_edl->create_objects();
2249 new_edl->load_xml(&file, LOAD_ALL);
2250 save_clip(new_edl, txt);
2251 gui->unlock_window();
2254 int MWindow::toggle_label()
2256 double position1, position2;
2259 position1 = edl->local_session->get_selectionstart(1);
2260 position2 = edl->local_session->get_selectionend(1);
2261 position1 = edl->align_to_frame(position1, 0);
2262 position2 = edl->align_to_frame(position2, 0);
2264 edl->labels->toggle_label(position1, position2);
2267 gui->update_timebar(0);
2268 gui->activate_timeline();
2271 cwindow->gui->lock_window("MWindow::toggle_label 2");
2272 cwindow->gui->timebar->update(1);
2273 cwindow->gui->unlock_window();
2274 awindow->gui->async_update_assets();
2276 undo_after(_("label"), LOAD_TIMEBAR);
2280 void MWindow::trim_selection()
2285 edl->trim_selection(edl->local_session->get_selectionstart(),
2286 edl->local_session->get_selectionend(),
2287 edl->session->labels_follow_edits,
2288 edl->session->plugins_follow_edits,
2289 edl->session->autos_follow_edits);
2292 undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2293 update_plugin_guis();
2294 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2295 cwindow->update(1, 0, 0, 0, 1);
2296 awindow->gui->async_update_assets();
2298 cwindow->refresh_frame(CHANGE_EDL);
2302 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2304 calling_window_gui->unlock_window();
2306 if( undo->undo_load_flags() & LOAD_SESSION )
2309 cwindow->gui->lock_window("MWindow::undo_entry 1");
2310 for( int i=0; i<vwindows.size(); ++i ) {
2311 if( vwindows.get(i)->is_running() ) {
2312 if( calling_window_gui != vwindows.get(i)->gui ) {
2313 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2317 gui->lock_window("MWindow::undo_entry 2");
2323 update_plugin_states();
2324 update_plugin_guis();
2326 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2327 gui->update_proxy_toggle();
2328 gui->unlock_window();
2329 cwindow->gui->unlock_window();
2330 cwindow->update(1, 1, 1, 1, 1);
2332 for( int i=0; i<vwindows.size(); ++i ) {
2333 if( vwindows.get(i)->is_running() ) {
2334 if( calling_window_gui != vwindows.get(i)->gui ) {
2335 vwindows.get(i)->gui->unlock_window();
2340 awindow->gui->async_update_assets();
2342 cwindow->refresh_frame(CHANGE_ALL);
2343 calling_window_gui->lock_window("MWindow::undo_entry 4");
2347 void MWindow::new_folder(const char *new_folder, int is_clips)
2350 if( edl->new_folder(new_folder, is_clips) ) {
2351 MainError::show_error(_("create new folder failed"));
2353 undo_after(_("new folder"), LOAD_ALL);
2354 awindow->gui->async_update_assets();
2357 void MWindow::delete_folder(char *folder)
2360 if( edl->delete_folder(folder) < 0 ) {
2361 MainError::show_error(_("delete folder failed"));
2363 undo_after(_("del folder"), LOAD_ALL);
2364 awindow->gui->async_update_assets();
2367 void MWindow::select_point(double position)
2369 gui->unlock_window();
2370 gui->stop_drawing();
2371 cwindow->stop_playback(0);
2372 gui->lock_window("MWindow::select_point");
2374 edl->local_session->set_selectionstart(position);
2375 edl->local_session->set_selectionend(position);
2378 cwindow->update(1, 0, 0, 0, 1);
2380 update_plugin_guis();
2381 gui->update_patchbay();
2382 gui->hide_cursor(0);
2383 gui->draw_cursor(0);
2384 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2385 gui->zoombar->update();
2386 gui->update_timebar(0);
2387 gui->flash_canvas(0);
2394 void MWindow::map_audio(int pattern)
2397 remap_audio(pattern);
2399 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2401 sync_parameters(CHANGE_PARAMS);
2402 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2405 void MWindow::remap_audio(int pattern)
2407 int current_channel = 0;
2408 int current_track = 0;
2409 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2410 if( current->data_type == TRACK_AUDIO &&
2411 current->is_armed() ) {
2412 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2413 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2415 for( int i=0; i < MAXCHANNELS; ++i ) {
2416 pan_auto->values[i] = 0.0;
2419 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2420 pan_auto->values[current_channel] = 1.0;
2423 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2424 switch( current_track ) {
2427 pan_auto->values[0] = 1;
2431 pan_auto->values[1] = 1;
2435 pan_auto->values[0] = 0.5;
2436 pan_auto->values[1] = 0.5;
2441 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2442 edl->session->achannel_positions, pan_auto->values,
2443 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2447 if( current_channel >= edl->session->audio_channels )
2448 current_channel = 0;
2454 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2456 edl->rescale_proxy(orig_scale, new_scale);
2459 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2461 edl->add_proxy(orig_assets, proxy_assets);
2464 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2465 float beep, int to_proxy, int remove_originals)
2467 if( !convert_render )
2468 convert_render = new ConvertRender(this);
2469 convert_render->set_format(format_asset, suffix, to_proxy);
2470 int found = convert_render->find_convertable_assets(edl);
2471 if( convert_render->needed_idxbls.size() > 0 )
2472 convert_render->start_convert(beep, remove_originals);
2473 else if( found > 0 )
2474 finish_convert(remove_originals);
2475 else if( found < 0 )
2476 eprintf(_("convert assets format error"));
2478 eprintf(_("No convertable assets found"));
2481 void MWindow::finish_convert(int remove_originals)
2483 gui->lock_window("MWindow::finish_convert");
2485 edl->replace_assets(
2486 convert_render->orig_idxbls,
2487 convert_render->orig_copies);
2488 if( remove_originals ) {
2489 remove_assets_from_project(0, 0, 0,
2490 &convert_render->orig_idxbls, 0);
2493 undo_after(_("convert"), LOAD_ALL);
2495 update_plugin_guis();
2496 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2497 cwindow->update(1, 0, 0, 0, 1);
2498 awindow->gui->async_update_assets();
2499 cwindow->refresh_frame(CHANGE_EDL);
2500 gui->unlock_window();
2503 void MWindow::cut_commercials()
2505 #ifdef HAVE_COMMERCIAL
2507 commercials->scan_media();
2510 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2513 update_plugin_guis();
2514 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2515 cwindow->update(1, 0, 0, 0, 1);
2516 cwindow->refresh_frame(CHANGE_EDL);
2520 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2523 Track *old_track = old_edl->tracks->first;
2524 Track *new_track = new_edl->tracks->first;
2525 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2526 if( old_track->data_type != new_track->data_type ) continue;
2527 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2528 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2529 if( !old_speeds || !new_speeds ) continue;
2530 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2531 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2532 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2533 old_speed = (FloatAuto *)old_speed->next;
2534 new_speed = (FloatAuto *)new_speed->next;
2536 Edit *old_edit = old_track->edits->first;
2537 Edit *new_edit = new_track->edits->first;
2538 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2539 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2540 if( old_speed || new_speed ) {
2541 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2542 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2543 edit_start = new_speeds->speed_position(orig_start);
2544 edit_end = new_speeds->speed_position(orig_end);
2547 new_edit->startproject = edit_start;
2548 new_edit->length = edit_end - edit_start;
2554 void MWindow::speed_before()
2557 speed_edl = new EDL;
2558 speed_edl->create_objects();
2560 speed_edl->copy_all(edl);
2563 int MWindow::speed_after(int done)
2568 result = normalize_speed(speed_edl, edl);
2570 speed_edl->remove_user();
2577 void MWindow::collect_effects()
2580 const char *file_string = "";
2582 int ret = edl->collect_effects(group);
2584 case COLLECT_EFFECTS_RECORD:
2585 eprintf(_("Selected edit track not armed."));
2587 case COLLECT_EFFECTS_MULTIPLE:
2588 eprintf(_("More than one edit selected on a track."));
2590 case COLLECT_EFFECTS_MISSING:
2591 eprintf(_("No effects under selected edit."));
2593 case COLLECT_EFFECTS_EMPTY:
2594 eprintf(_("No edits selected."));
2596 case COLLECT_EFFECTS_MASTER:
2597 eprintf(_("Shared effect added without master."));
2600 group->save_xml(&file, "");
2601 file_string = file.string();
2602 group->remove_user();
2604 long file_length = strlen(file_string);
2605 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2606 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2609 void MWindow::paste_effects()
2612 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2614 string = new char[len];
2615 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2617 if( !string || !string[0] ) {
2618 eprintf(_("Error clipboard buffer empty."));
2622 file.read_from_string(string);
2623 EDL *group = new EDL();
2624 group->create_objects();
2625 if( !group->load_xml(&file, LOAD_ALL) ) {
2627 int ret = edl->insert_effects(group);
2629 case INSERT_EFFECTS_RECORD:
2630 eprintf(_("Selected edit track not armed."));
2632 case INSERT_EFFECTS_TYPE:
2633 eprintf(_("Track type mismatched."));
2635 case INSERT_EFFECTS_MULTIPLE:
2636 eprintf(_("More than one edit selected on a track."));
2638 case INSERT_EFFECTS_MISSING:
2639 eprintf(_("Too few target edits to add group effects."));
2641 case INSERT_EFFECTS_EXTRA:
2642 eprintf(_("Too many target edits to add group effects."));
2644 case INSERT_EFFECTS_MASTER:
2645 eprintf(_("Shared effect added without master."));
2651 undo_after(_("paste effects"), LOAD_ALL);
2653 cwindow->refresh_frame(CHANGE_EDL);
2654 update_plugin_guis();
2655 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2658 eprintf(_("Error loading clip from clipboard buffer."));
2660 group->remove_user();