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 add_audio_track(above, dst);
90 undo_after(_("add track"), LOAD_ALL);
93 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
94 gui->activate_timeline();
95 cwindow->refresh_frame(CHANGE_EDL);
98 void MWindow::add_video_track_entry(Track *dst)
101 add_video_track(1, dst);
102 undo_after(_("add track"), LOAD_ALL);
106 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
107 gui->activate_timeline();
108 cwindow->refresh_frame(CHANGE_EDL);
112 void MWindow::add_subttl_track_entry(Track *dst)
115 add_subttl_track(1, dst);
116 undo_after(_("add track"), LOAD_ALL);
120 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
121 gui->activate_timeline();
122 cwindow->refresh_frame(CHANGE_EDL);
127 int MWindow::add_audio_track(int above, Track *dst)
129 edl->tracks->add_audio_track(above, dst);
130 edl->tracks->update_y_pixels(theme);
135 int MWindow::add_video_track(int above, Track *dst)
137 edl->tracks->add_video_track(above, dst);
138 edl->tracks->update_y_pixels(theme);
143 int MWindow::add_subttl_track(int above, Track *dst)
145 edl->tracks->add_subttl_track(above, dst);
146 edl->tracks->update_y_pixels(theme);
151 void MWindow::asset_to_all()
153 if( !session->drag_assets->size() ) return;
154 Indexable *indexable = session->drag_assets->get(0);
156 // if( indexable->have_video() )
163 w = indexable->get_w();
164 h = indexable->get_h();
165 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
166 double old_framerate = edl->session->frame_rate;
167 int old_samplerate = edl->session->sample_rate;
168 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
171 if( indexable->have_video() ) {
172 edl->session->output_w = w;
173 edl->session->output_h = h;
174 edl->session->frame_rate = new_framerate;
176 edl->session->aspect_w,
177 edl->session->aspect_h,
180 for( Track *current=edl->tracks->first; current; current=NEXT ) {
181 if( current->data_type == TRACK_VIDEO /* &&
182 current->is_armed() */ ) {
183 current->track_w = w;
184 current->track_h = h;
189 if( ((edl->session->output_w % 4) ||
190 (edl->session->output_h % 4)) &&
191 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
192 MainError::show_error(
193 _("This project's dimensions are not multiples of 4 so\n"
194 "it can't be rendered by OpenGL."));
198 if( defaults->get("AUTOASPECT", 0) ) {
200 edl->session->aspect_w,
201 edl->session->aspect_h,
206 if( indexable->have_audio() ) {
207 edl->session->sample_rate = new_samplerate;
208 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
209 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
214 undo_after(_("asset to all"), LOAD_ALL);
216 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
217 sync_parameters(CHANGE_ALL);
221 void MWindow::asset_to_size()
223 if( !session->drag_assets->size() ) return;
224 Indexable *indexable = session->drag_assets->get(0);
226 if( indexable->have_video() ) {
231 w = indexable->get_w();
232 h = indexable->get_h();
233 edl->session->output_w = w;
234 edl->session->output_h = h;
236 if( ((edl->session->output_w % 4) ||
237 (edl->session->output_h % 4)) &&
238 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
239 MainError::show_error(
240 _("This project's dimensions are not multiples of 4 so\n"
241 "it can't be rendered by OpenGL."));
245 if( defaults->get("AUTOASPECT", 0) ) {
246 create_aspect_ratio(edl->session->aspect_w,
247 edl->session->aspect_h,
254 undo_after(_("asset to size"), LOAD_ALL);
256 sync_parameters(CHANGE_ALL);
261 void MWindow::asset_to_rate()
263 if( session->drag_assets->size() &&
264 session->drag_assets->get(0)->have_video() ) {
265 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
266 double old_framerate = edl->session->frame_rate;
269 edl->session->frame_rate = new_framerate;
270 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
274 undo_after(_("asset to rate"), LOAD_ALL);
276 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
277 sync_parameters(CHANGE_ALL);
282 void MWindow::clear_entry()
289 undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
292 update_plugin_guis();
293 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
294 cwindow->update(1, 0, 0, 0, 1);
295 cwindow->refresh_frame(CHANGE_EDL);
298 void MWindow::clear(int clear_handle)
300 double start = edl->local_session->get_selectionstart();
301 double end = edl->local_session->get_selectionend();
302 if( clear_handle || !EQUIV(start, end) ) {
305 edl->session->labels_follow_edits,
306 edl->session->plugins_follow_edits,
307 edl->session->autos_follow_edits);
311 void MWindow::update_gui(int changed_edl)
314 update_plugin_guis();
316 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
317 cwindow->update(1, 0, 0, 0, 1);
318 cwindow->refresh_frame(CHANGE_EDL);
321 gui->draw_overlays(1);
322 sync_parameters(CHANGE_PARAMS);
323 gui->update_patchbay();
324 cwindow->update(1, 0, 0);
328 void MWindow::set_automation_mode(int mode)
332 edl->tracks->set_automation_mode(
333 edl->local_session->get_selectionstart(),
334 edl->local_session->get_selectionend(),
336 int changed_edl = speed_after(1);
338 char string[BCSTRLEN];
339 sprintf(string,"set %s", FloatAuto::curve_name(mode));
341 !changed_edl ? LOAD_AUTOMATION :
342 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
343 update_gui(changed_edl);
346 void MWindow::clear_automation()
350 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
351 edl->local_session->get_selectionend());
352 int changed_edl = speed_after(1);
354 undo_after(_("clear keyframes"),
355 !changed_edl ? LOAD_AUTOMATION :
356 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
357 update_gui(changed_edl);
360 int MWindow::clear_default_keyframe()
364 edl->tracks->clear_default_keyframe();
365 int changed_edl = speed_after(1);
367 undo_after(_("clear default keyframe"),
368 !changed_edl ? LOAD_AUTOMATION :
369 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
370 update_gui(changed_edl);
374 void MWindow::clear_labels()
377 clear_labels(edl->local_session->get_selectionstart(),
378 edl->local_session->get_selectionend());
379 undo_after(_("clear labels"), LOAD_TIMEBAR);
381 gui->update_timebar(1);
382 cwindow->update(0, 0, 0, 0, 1);
386 int MWindow::clear_labels(double start, double end)
390 end = edl->tracks->total_length();
392 edl->labels->clear(start, end, 0);
396 void MWindow::clear_hard_edges()
399 clear_hard_edges(edl->local_session->get_selectionstart(),
400 edl->local_session->get_selectionend());
403 undo_after(_("clear hard edges"), LOAD_EDITS);
405 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
406 cwindow->refresh_frame(CHANGE_EDL);
409 int MWindow::clear_hard_edges(double start, double end)
413 end = edl->tracks->total_length();
415 edl->clear_hard_edges(start, end);
419 void MWindow::clear_select()
421 edl->tracks->clear_selected_edits();
422 gui->draw_overlays(1);
425 void MWindow::concatenate_tracks()
428 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
429 edl->session->autos_follow_edits);
431 undo_after(_("concatenate tracks"), LOAD_EDITS);
434 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
435 cwindow->refresh_frame(CHANGE_EDL);
439 int MWindow::copy_flags(int copy_flags)
441 if( !edl->session->labels_follow_edits )
442 copy_flags &= ~COPY_LABELS;
443 if( !edl->session->autos_follow_edits )
444 copy_flags &= ~COPY_AUTOS;
445 if( !edl->session->plugins_follow_edits )
446 copy_flags &= ~COPY_PLUGINS;
452 copy(edl->local_session->get_selectionstart(),
453 edl->local_session->get_selectionend());
456 int MWindow::copy(double start, double end)
458 if( start == end ) return 1;
461 edl->copy(copy_flags(), start, end, &file, "", 1);
462 const char *file_string = file.string();
463 long file_length = strlen(file_string);
464 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
465 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
470 int MWindow::copy_automation()
473 double start = edl->local_session->get_selectionstart();
474 double end = edl->local_session->get_selectionend();
475 edl->tracks->copy_automation(start, end, &file, 0, 1);
476 const char *file_string = file.string();
477 long file_length = strlen(file_string);
478 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
479 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
483 int MWindow::copy_default_keyframe()
486 double start = edl->local_session->get_selectionstart();
487 double end = edl->local_session->get_selectionend();
488 edl->tracks->copy_automation(start, end, &file, 1, 0);
489 const char *file_string = file.string();
490 long file_length = strlen(file_string);
491 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
492 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
496 // Uses cropping coordinates in edl session to crop and translate video.
497 // We modify the projector since camera automation depends on the track size.
498 void MWindow::crop_video(int mode)
501 // Clamp EDL crop region
502 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
503 edl->session->crop_x1 ^= edl->session->crop_x2;
504 edl->session->crop_x2 ^= edl->session->crop_x1;
505 edl->session->crop_x1 ^= edl->session->crop_x2;
507 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
508 edl->session->crop_y1 ^= edl->session->crop_y2;
509 edl->session->crop_y2 ^= edl->session->crop_y1;
510 edl->session->crop_y1 ^= edl->session->crop_y2;
513 case CROP_REFORMAT: {
514 float ctr_x = edl->session->output_w / 2.;
515 float ctr_y = edl->session->output_h / 2.;
516 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
517 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
518 float dx = -(new_x - ctr_x), dy = -(new_y - ctr_y);
519 edl->tracks->translate_projector(dx, dy, 1);
521 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
522 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
523 edl->session->crop_x1 = edl->session->crop_y1 = 0;
524 edl->session->crop_x2 = edl->session->output_w;
525 edl->session->crop_y2 = edl->session->output_h;
528 float old_w = edl->session->output_w;
529 float old_h = edl->session->output_h;
530 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
531 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
532 if( !new_w ) new_w = 1;
533 if( !new_h ) new_h = 1;
534 float xzoom = old_w / new_w, yzoom = old_h / new_h;
535 float new_z = bmin(xzoom, yzoom);
536 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
537 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
538 edl->tracks->crop_resize(new_x, new_y, new_z);
540 edl->session->crop_x1 = 0;
541 edl->session->crop_y1 = 0;
542 edl->session->crop_x2 = edl->session->output_w;
543 edl->session->crop_y2 = edl->session->output_h;
546 float old_w = edl->session->output_w;
547 float old_h = edl->session->output_h;
548 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
549 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
550 if( !new_w ) new_w = 1;
551 if( !new_h ) new_h = 1;
552 float xzoom = old_w / new_w, yzoom = old_h / new_h;
553 float new_z = bmin(xzoom, yzoom);
555 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
556 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
557 edl->tracks->crop_shrink(new_x, new_y, new_z);
561 // Recalculate aspect ratio
562 if( defaults->get("AUTOASPECT", 0) ) {
563 create_aspect_ratio(edl->session->aspect_w,
564 edl->session->aspect_h,
565 edl->session->output_w,
566 edl->session->output_h);
569 undo_after(_("crop"), LOAD_ALL);
572 cwindow->refresh_frame(CHANGE_ALL);
578 double start = edl->local_session->get_selectionstart();
579 double end = edl->local_session->get_selectionend();
580 if( EQUIV(start,end) )
586 void MWindow::blade(double position)
589 edl->blade(position);
592 undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
594 update_plugin_guis();
595 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
596 cwindow->update(1, 0, 0, 0, 1);
597 awindow->gui->async_update_assets();
598 cwindow->refresh_frame(CHANGE_EDL);
601 void MWindow::cut(double start, double end, double new_position)
605 edl->clear(start, end,
606 edl->session->labels_follow_edits,
607 edl->session->plugins_follow_edits,
608 edl->session->autos_follow_edits);
612 undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
613 if( new_position >= 0 ) {
614 edl->local_session->set_selectionstart(new_position);
615 edl->local_session->set_selectionend(new_position);
618 update_plugin_guis();
619 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
620 cwindow->update(1, 0, 0, 0, 1);
621 awindow->gui->async_update_assets();
622 cwindow->refresh_frame(CHANGE_EDL);
625 void MWindow::cut_left_edit()
627 double start_pos = edl->local_session->get_selectionstart(1);
628 double position = edl->prev_edit(start_pos);
629 if( position < start_pos )
630 cut(position, start_pos, position);
633 void MWindow::cut_right_edit()
635 double end_pos = edl->local_session->get_selectionend(1);
636 double position = edl->next_edit(end_pos);
637 if( end_pos < position )
638 cut(end_pos, position, end_pos);
641 void MWindow::cut_left_label()
643 double start_pos = edl->local_session->get_selectionstart(1);
644 Label *left_label = edl->labels->prev_label(start_pos);
645 if( !left_label ) return;
646 double position = left_label->position;
647 if( position < start_pos )
648 cut(position, start_pos, position);
651 void MWindow::cut_right_label()
653 double end_pos = edl->local_session->get_selectionend(1);
654 Label *right_label = edl->labels->next_label(end_pos);
655 if( !right_label ) return;
656 double position = right_label->position;
657 if( end_pos < position )
658 cut(end_pos, position, end_pos);
661 int MWindow::cut_automation()
666 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
667 edl->local_session->get_selectionend());
668 int changed_edl = speed_after(1);
670 undo_after(_("cut keyframes"),
671 !changed_edl ? LOAD_AUTOMATION :
672 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
673 update_gui(changed_edl);
677 int MWindow::cut_default_keyframe()
682 copy_default_keyframe();
683 edl->tracks->clear_default_keyframe();
684 int changed_edl = speed_after(1);
686 undo_after(_("cut default keyframe"),
687 !changed_edl ? LOAD_AUTOMATION :
688 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
689 update_gui(changed_edl);
694 void MWindow::delete_tracks()
697 edl->tracks->delete_tracks();
698 undo_after(_("delete tracks"), LOAD_ALL);
702 update_plugin_states();
704 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
705 cwindow->refresh_frame(CHANGE_EDL);
708 void MWindow::delete_track(Track *track)
711 edl->tracks->delete_track(track);
712 undo_after(_("delete track"), LOAD_ALL);
715 update_plugin_states();
717 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
718 cwindow->refresh_frame(CHANGE_EDL);
723 // Insert data from clipboard
724 void MWindow::insert(double position, FileXML *file,
725 int edit_labels, int edit_plugins, int edit_autos,
726 EDL *parent_edl, Track *first_track, int overwrite)
728 // For clipboard pasting make the new edl use a separate session
729 // from the master EDL. Then it can be resampled to the master rates.
730 // For splice, overwrite, and dragging need same session to get the assets.
731 EDL *edl = new EDL(parent_edl);
732 ArrayList<EDL*> new_edls;
733 uint32_t load_flags = LOAD_ALL;
736 new_edls.append(edl);
737 edl->create_objects();
742 if( parent_edl ) load_flags &= ~LOAD_SESSION;
743 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
744 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
746 edl->load_xml(file, load_flags);
749 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
753 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
754 edit_labels, edit_plugins, edit_autos, overwrite);
755 // if( vwindow->edl )
756 // printf("MWindow::insert 5 %f %f\n",
757 // vwindow->edl->local_session->in_point,
758 // vwindow->edl->local_session->out_point);
759 new_edls.remove_all();
760 edl->Garbage::remove_user();
761 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
764 void MWindow::insert_effects_canvas(Track *dest_track, double start, double length)
768 ArrayList<SharedLocation> shared_locations;
769 PluginSet *pluginset = session->pluginset_highlighted;
770 int gang = edl->session->gang_tracks != GANG_NONE ? 1 : 0;
771 int data_type = dest_track->data_type;
774 for( Track *track=dest_track; track; track=track->next ) {
775 if( gang && track->master && !first_track ) break;
776 if( track->data_type != data_type ) continue;
777 if( !track->is_armed() ) continue;
778 int module = edl->tracks->number_of(track);
779 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
780 PluginServer *plugin = session->drag_pluginservers->values[i];
781 int shared = gang; // && plugin->multichannel ? 1 : 0;
782 int plugin_type = !first_track && shared ?
783 PLUGIN_SHAREDPLUGIN : PLUGIN_STANDALONE;
784 SharedLocation *shared_location = !first_track ?
785 &shared_locations[i] : &shared_locations.append();
786 insert_effect(plugin->title, shared_location, track,
787 pluginset, start, length, plugin_type);
788 if( first_track && shared ) {
789 shared_location->module = module;
790 shared_location->plugin = pluginset ?
791 track->plugin_set.number_of(pluginset) :
792 track->plugin_set.total-1 ;
801 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
803 sync_parameters(CHANGE_EDL);
804 // GUI updated in TrackCanvas, after current_operations are reset
807 void MWindow::insert_effects_cwindow(Track *dest_track)
809 if( !dest_track ) return;
812 double length = dest_track->get_length();
814 if( edl->local_session->get_selectionend() >
815 edl->local_session->get_selectionstart() ) {
816 start = edl->local_session->get_selectionstart();
817 length = edl->local_session->get_selectionend() -
818 edl->local_session->get_selectionstart();
821 insert_effects_canvas(dest_track, start, length);
822 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
825 void MWindow::insert_effect(char *title, SharedLocation *shared_location,
826 int data_type, int plugin_type, int single_standalone)
828 Track *current = edl->tracks->first;
829 SharedLocation shared_location_local;
830 shared_location_local.copy_from(shared_location);
832 double start_pos = edl->local_session->get_selectionstart(1);
833 double end_pos = edl->local_session->get_selectionend(1);
834 for( ; current; current=NEXT ) {
835 if( current->data_type != data_type ) continue;
836 if( !current->is_armed() ) continue;
837 double start = start_pos, end = end_pos;
838 if( plugin_type == PLUGIN_STANDALONE && start >= end ) {
840 end = current->get_length();
842 double length = end - start;
843 insert_effect(title, &shared_location_local,
844 current, 0, start, length, plugin_type);
846 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
847 plugin_type = PLUGIN_SHAREDPLUGIN;
848 shared_location_local.module = edl->tracks->number_of(current);
849 shared_location_local.plugin = current->plugin_set.total - 1;
850 start_pos = start; end_pos = end;
857 void MWindow::insert_effect(char *title,
858 SharedLocation *shared_location, Track *track, PluginSet *plugin_set,
859 double start, double length, int plugin_type)
861 KeyFrame *default_keyframe = 0;
862 PluginServer *server = 0;
863 // Get default keyframe
864 if( plugin_type == PLUGIN_STANDALONE ) {
865 default_keyframe = new KeyFrame;
866 server = new PluginServer(*scan_plugindb(title, track->data_type));
868 server->open_plugin(0, preferences, edl, 0);
869 server->save_data(default_keyframe);
871 // Insert plugin object
872 track->insert_effect(title, shared_location, default_keyframe,
873 plugin_set, start, length, plugin_type);
876 if( plugin_type == PLUGIN_STANDALONE ) {
877 server->close_plugin();
879 delete default_keyframe;
883 int MWindow::modify_edithandles()
886 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
887 edl->modify_edithandles(session->drag_start,
888 session->drag_position, session->drag_handle, handle_mode,
889 edl->session->labels_follow_edits,
890 edl->session->plugins_follow_edits,
891 edl->session->autos_follow_edits,
892 session->drag_edit->group_id);
893 finish_modify_handles();
894 //printf("MWindow::modify_handles 1\n");
898 int MWindow::modify_pluginhandles()
902 edl->modify_pluginhandles(session->drag_start,
903 session->drag_position,
904 session->drag_handle,
905 edl->session->edit_handle_mode[session->drag_button],
906 edl->session->labels_follow_edits,
907 edl->session->autos_follow_edits,
908 session->trim_edits);
910 finish_modify_handles();
916 // Common to edithandles and plugin handles
917 void MWindow::finish_modify_handles()
919 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
920 double position = -1;
921 switch( edit_mode ) {
923 position = !session->drag_handle ?
924 session->drag_start : session->drag_position;
928 position = session->drag_position;
932 position = session->drag_start;
935 if( position >= 0 ) {
936 edl->local_session->set_selectionstart(position);
937 edl->local_session->set_selectionend(position);
939 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
943 sync_parameters(CHANGE_EDL);
944 update_plugin_guis();
945 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
946 // label list can be modified
947 awindow->gui->async_update_assets();
948 cwindow->update(1, 0, 0, 0, 1);
951 void MWindow::match_output_size(Track *track)
954 track->track_w = edl->session->output_w;
955 track->track_h = edl->session->output_h;
957 undo_after(_("match output size"), LOAD_ALL);
960 sync_parameters(CHANGE_EDL);
964 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
966 ArrayList<Edit*> edits;
968 delete_edits(&edits, msg, collapse);
971 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
973 if( !edits->size() ) return;
975 if( edl->session->labels_follow_edits )
976 edl->delete_edit_labels(edits, collapse);
977 edl->delete_edits(edits, collapse);
980 undo_after(msg, LOAD_EDITS);
983 cwindow->refresh_frame(CHANGE_EDL);
984 update_plugin_guis();
985 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
988 void MWindow::delete_edits(int collapse)
990 ArrayList<Edit*> edits;
991 edl->tracks->get_selected_edits(&edits);
992 delete_edits(&edits,_("del edit"), collapse);
995 // collapse - delete from timeline, not collapse replace with silence
996 // packed - omit unselected from selection, unpacked - replace unselected with silence
997 void MWindow::cut_selected_edits(int collapse, int packed)
999 selected_edits_to_clipboard(packed);
1000 ArrayList<Edit*> edits;
1001 edl->tracks->get_selected_edits(&edits);
1002 delete_edits(&edits, _("cut edit"), collapse);
1006 void MWindow::move_edits(ArrayList<Edit*> *edits,
1007 Track *track, double position, int mode)
1010 // lockout timebar labels update
1011 // labels can be deleted with tooltip repeater running
1012 cwindow->gui->lock_window("Tracks::move_edits");
1013 edl->tracks->move_edits(edits, track, position,
1014 edl->session->labels_follow_edits,
1015 edl->session->plugins_follow_edits,
1016 edl->session->autos_follow_edits, mode);
1017 cwindow->gui->timebar->update(1);
1018 cwindow->gui->unlock_window();
1021 undo_after(_("move edit"), LOAD_ALL);
1024 cwindow->refresh_frame(CHANGE_EDL);
1026 update_plugin_guis();
1027 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1030 void MWindow::selected_edits_to_clipboard(int packed)
1032 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1033 edl->session->labels_follow_edits,
1034 edl->session->autos_follow_edits,
1035 edl->session->plugins_follow_edits);
1036 if( !new_edl ) return;
1038 new_edl->copy(COPY_EDL, &file, "", 1);
1039 const char *file_string = file.string();
1040 long file_length = strlen(file_string);
1041 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1042 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1043 new_edl->remove_user();
1046 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1047 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1049 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1051 char *string = new char[len];
1052 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1054 file.read_from_string(string);
1056 EDL *clip = new EDL();
1057 clip->create_objects();
1058 if( !clip->load_xml(&file, LOAD_ALL) ) {
1060 edl->paste_edits(clip, first_track, position, overwrite,
1061 edit_edits, edit_labels, edit_autos, edit_plugins);
1063 undo_after(_("paste clip"), LOAD_ALL);
1065 cwindow->refresh_frame(CHANGE_EDL);
1067 update_plugin_guis();
1068 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1070 clip->remove_user();
1073 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1076 // lockout timebar labels update
1077 // labels can be deleted with tooltip repeater running
1078 cwindow->gui->lock_window("Tracks::move_group");
1080 ArrayList<Edit *>edits;
1081 edl->tracks->get_selected_edits(&edits);
1082 if( edl->session->labels_follow_edits )
1083 edl->delete_edit_labels(&edits, 0);
1084 edl->delete_edits(&edits, 0);
1085 edl->paste_edits(group, first_track, position, overwrite, 1,
1086 edl->session->labels_follow_edits,
1087 edl->session->autos_follow_edits,
1088 edl->session->plugins_follow_edits);
1089 cwindow->gui->timebar->update(1);
1090 cwindow->gui->unlock_window();
1091 // big debate over whether to do this, must either clear selected, or no tweaking
1092 // edl->tracks->clear_selected_edits();
1095 undo_after(_("move group"), LOAD_ALL);
1097 cwindow->refresh_frame(CHANGE_EDL);
1099 update_plugin_guis();
1100 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1103 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1106 edl->tracks->move_effect(plugin, track, position);
1108 undo_after(_("paste effect"), LOAD_ALL);
1111 cwindow->refresh_frame(CHANGE_EDL);
1112 update_plugin_guis();
1113 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1116 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1119 edl->tracks->move_effect(plugin, plugin_set, position);
1121 undo_after(_("move effect"), LOAD_ALL);
1124 cwindow->refresh_frame(CHANGE_EDL);
1125 update_plugin_guis();
1126 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1129 void MWindow::move_plugins_up(PluginSet *plugin_set)
1133 plugin_set->track->move_plugins_up(plugin_set);
1136 undo_after(_("move effect up"), LOAD_ALL);
1138 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1139 sync_parameters(CHANGE_EDL);
1142 void MWindow::move_plugins_down(PluginSet *plugin_set)
1146 plugin_set->track->move_plugins_down(plugin_set);
1149 undo_after(_("move effect down"), LOAD_ALL);
1151 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1152 sync_parameters(CHANGE_EDL);
1155 void MWindow::move_track_down(Track *track)
1158 edl->tracks->move_track_down(track);
1160 undo_after(_("move track down"), LOAD_ALL);
1163 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1164 sync_parameters(CHANGE_EDL);
1168 void MWindow::move_tracks_down()
1171 edl->tracks->move_tracks_down();
1173 undo_after(_("move tracks down"), LOAD_ALL);
1176 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1177 sync_parameters(CHANGE_EDL);
1181 void MWindow::move_track_up(Track *track)
1184 edl->tracks->move_track_up(track);
1186 undo_after(_("move track up"), LOAD_ALL);
1188 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1189 sync_parameters(CHANGE_EDL);
1193 void MWindow::move_tracks_up()
1196 edl->tracks->move_tracks_up();
1198 undo_after(_("move tracks up"), LOAD_ALL);
1200 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1201 sync_parameters(CHANGE_EDL);
1205 void MWindow::mute_selection()
1207 double start = edl->local_session->get_selectionstart();
1208 double end = edl->local_session->get_selectionend();
1209 if( start != end ) {
1211 edl->clear(start, end, 0,
1212 edl->session->plugins_follow_edits,
1213 edl->session->autos_follow_edits);
1214 edl->local_session->set_selectionend(end);
1215 edl->local_session->set_selectionstart(start);
1216 edl->paste_silence(start, end, 0,
1217 edl->session->plugins_follow_edits,
1218 edl->session->autos_follow_edits);
1221 undo_after(_("mute"), LOAD_EDITS);
1224 update_plugin_guis();
1225 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1226 cwindow->refresh_frame(CHANGE_EDL);
1231 void MWindow::overwrite(EDL *source, int all)
1235 LocalSession *src = source->local_session;
1236 double src_start = all ? 0 :
1237 src->inpoint_valid() ? src->get_inpoint() :
1238 src->outpoint_valid() ? 0 :
1239 src->get_selectionstart();
1240 double src_end = all ? source->tracks->total_length() :
1241 src->outpoint_valid() ? src->get_outpoint() :
1242 src->inpoint_valid() ? source->tracks->total_length() :
1243 src->get_selectionend();
1244 double overwrite_len = src_end - src_start;
1245 double dst_start = edl->local_session->get_selectionstart();
1246 double dst_len = edl->local_session->get_selectionend() - dst_start;
1249 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1250 // in/out points or selection present and shorter than overwrite range
1251 // shorten the copy range
1252 overwrite_len = dst_len;
1255 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1257 // HACK around paste_edl get_start/endselection on its own
1258 // so we need to clear only when not using both io points
1259 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1260 if( edl->local_session->get_inpoint() < 0 ||
1261 edl->local_session->get_outpoint() < 0 )
1262 edl->clear(dst_start, dst_start + overwrite_len,
1263 edl->session->labels_follow_edits,
1264 edl->session->plugins_follow_edits,
1265 edl->session->autos_follow_edits);
1267 paste(dst_start, dst_start + overwrite_len, &file,
1268 edl->session->labels_follow_edits,
1269 edl->session->plugins_follow_edits,
1270 edl->session->autos_follow_edits, 0, 0);
1272 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1273 edl->local_session->set_selectionend(dst_start + overwrite_len);
1276 undo_after(_("overwrite"), LOAD_EDITS);
1279 update_plugin_guis();
1280 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1281 sync_parameters(CHANGE_EDL);
1284 // For splice and overwrite
1285 int MWindow::paste(double start, double end, FileXML *file,
1286 int edit_labels, int edit_plugins, int edit_autos,
1287 Track *first_track, int overwrite)
1291 // Want to insert with assets shared with the master EDL.
1293 edit_labels, edit_plugins, edit_autos,
1294 edl, first_track, overwrite);
1299 // For editing using insertion point
1300 void MWindow::paste()
1302 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1305 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1307 //double end = edl->local_session->get_selectionend();
1308 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1311 char *string = new char[len];
1313 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1315 file.read_from_string(string);
1316 if( clear_selection ) clear(0);
1318 insert(start, &file,
1319 edl->session->labels_follow_edits,
1320 edl->session->plugins_follow_edits,
1321 edl->session->autos_follow_edits,
1322 0, first_track, overwrite);
1329 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1331 update_plugin_guis();
1332 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1333 awindow->gui->async_update_assets();
1334 sync_parameters(CHANGE_EDL);
1339 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1344 if( session->drag_assets->total ) {
1345 load_assets(session->drag_assets,
1346 position, LOADMODE_PASTE, dest_track, 0,
1347 edl->session->labels_follow_edits,
1348 edl->session->plugins_follow_edits,
1349 edl->session->autos_follow_edits,
1354 if( session->drag_clips->total ) {
1355 paste_edls(session->drag_clips,
1356 LOADMODE_PASTE, dest_track, position,
1357 edl->session->labels_follow_edits,
1358 edl->session->plugins_follow_edits,
1359 edl->session->autos_follow_edits,
1366 undo_after(_("paste assets"), LOAD_EDITS);
1368 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1369 sync_parameters(CHANGE_EDL);
1373 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1374 double position, int load_mode, Track *first_track, RecordLabels *labels,
1375 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1377 if( load_mode == LOADMODE_RESOURCESONLY )
1378 load_mode = LOADMODE_ASSETSONLY;
1379 const int debug = 0;
1380 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1382 position = edl->local_session->get_selectionstart();
1384 ArrayList<EDL*> new_edls;
1385 for( int i=0; i<new_assets->total; ++i ) {
1386 Indexable *indexable = new_assets->get(i);
1387 if( indexable->is_asset ) {
1388 remove_from_caches(indexable);
1390 EDL *new_edl = new EDL;
1391 new_edl->create_objects();
1392 new_edl->copy_session(edl);
1393 if( !indexable->is_asset ) {
1394 EDL *nested_edl = (EDL*)indexable;
1395 new_edl->create_nested(nested_edl);
1396 new_edl->set_path(indexable->path);
1399 Asset *asset = (Asset*)indexable;
1400 asset_to_edl(new_edl, asset);
1402 new_edls.append(new_edl);
1405 for( RecordLabel *label=labels->first; label; label=label->next ) {
1406 new_edl->labels->toggle_label(label->position, label->position);
1410 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1412 paste_edls(&new_edls, load_mode, first_track, position,
1413 edit_labels, edit_plugins, edit_autos, overwrite);
1414 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1417 for( int i=0; i<new_edls.size(); ++i )
1418 new_edls.get(i)->Garbage::remove_user();
1420 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1423 int MWindow::paste_automation()
1425 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1430 char *string = new char[len];
1431 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1433 file.read_from_string(string);
1435 double start = edl->local_session->get_selectionstart();
1436 double end = edl->local_session->get_selectionend();
1437 edl->tracks->clear_automation(start, end);
1438 edl->tracks->paste_automation(start, &file, 0, 1,
1439 edl->session->typeless_keyframes);
1440 int changed_edl = speed_after(1);
1442 undo_after(_("paste keyframes"),
1443 !changed_edl ? LOAD_AUTOMATION :
1444 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1445 update_gui(changed_edl);
1451 int MWindow::paste_default_keyframe()
1453 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1458 char *string = new char[len];
1459 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1461 file.read_from_string(string);
1463 double start = edl->local_session->get_selectionstart();
1464 edl->tracks->paste_automation(start, &file, 1, 0,
1465 edl->session->typeless_keyframes);
1466 // edl->tracks->paste_default_keyframe(&file);
1467 int changed_edl = speed_after(1);
1468 undo_after(_("paste default keyframe"),
1469 !changed_edl ? LOAD_AUTOMATION :
1470 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1472 update_gui(changed_edl);
1479 // Insert edls with project deletion and index file generation.
1480 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1481 Track *first_track, double current_position,
1482 int edit_labels, int edit_plugins, int edit_autos,
1486 ArrayList<Track*> destination_tracks;
1487 int need_new_tracks = 0;
1490 if( !new_edls->total ) return 0;
1493 // double original_length = edl->tracks->total_length();
1494 // double original_preview_end = edl->local_session->preview_end;
1497 // Delete current project
1498 if( load_mode == LOADMODE_REPLACE ||
1499 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1501 edl->save_defaults(defaults);
1503 edl->Garbage::remove_user();
1505 edl->create_objects();
1506 edl->copy_session(new_edls->values[0]);
1507 edl->copy_mixers(new_edls->values[0]);
1508 gui->mainmenu->update_toggles(0);
1509 gui->unlock_window();
1510 gwindow->gui->update_toggles(1);
1511 gui->lock_window("MWindow::paste_edls");
1513 // Insert labels for certain modes constitutively
1517 // Force reset of preview
1518 // original_length = 0;
1519 // original_preview_end = -1;
1525 // Create new tracks in master EDL
1526 if( load_mode == LOADMODE_REPLACE ||
1527 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1528 load_mode == LOADMODE_NEW_TRACKS ) {
1530 need_new_tracks = 1;
1531 for( int i=0; i<new_edls->total; ++i ) {
1532 EDL *new_edl = new_edls->values[i];
1533 int first_track = 1;
1534 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1535 switch( current->data_type ) {
1537 edl->tracks->add_video_track(0, 0);
1538 if( current->draw ) edl->tracks->last->draw = 1;
1541 edl->tracks->add_audio_track(0, 0);
1543 case TRACK_SUBTITLE:
1544 edl->tracks->add_subttl_track(0, 0);
1550 edl->tracks->last->master = 1;
1553 // re-label only if not already labeled
1554 if( new_edl->local_session->asset2edl )
1555 strcpy(current->title, edl->tracks->last->title);
1556 destination_tracks.append(edl->tracks->last);
1559 // Base track count on first EDL only for concatenation
1560 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1562 edl->session->highlighted_track = edl->tracks->total() - 1;
1565 // Recycle existing tracks of master EDL
1566 if( load_mode == LOADMODE_CONCATENATE ||
1567 load_mode == LOADMODE_PASTE ) {
1568 Track *current = first_track ? first_track : edl->tracks->first;
1569 for( ; current; current=NEXT ) {
1570 if( current->is_armed() ) {
1571 destination_tracks.append(current);
1577 int destination_track = 0;
1578 double *paste_position = new double[destination_tracks.total];
1580 // Iterate through the edls
1581 for( int i=0; i<new_edls->total; ++i ) {
1583 EDL *new_edl = new_edls->values[i];
1584 double edl_length = new_edl->local_session->clipboard_length ?
1585 new_edl->local_session->clipboard_length :
1586 new_edl->tracks->total_length();
1587 // printf("MWindow::paste_edls 2 %f %f\n",
1588 // new_edl->local_session->clipboard_length,
1589 // new_edl->tracks->total_length());
1593 // Convert EDL to master rates
1594 new_edl->resample(new_edl->session->sample_rate,
1595 edl->session->sample_rate,
1597 new_edl->resample(new_edl->session->frame_rate,
1598 edl->session->frame_rate,
1601 // Add assets and prepare index files
1602 for( Asset *new_asset=new_edl->assets->first;
1603 new_asset; new_asset=new_asset->next ) {
1604 mainindexes->add_indexable(new_asset);
1606 // Capture index file status from mainindex test
1607 edl->update_assets(new_edl);
1609 // Get starting point of insertion. Need this to paste labels.
1610 switch( load_mode ) {
1611 case LOADMODE_NOTHING:
1613 case LOADMODE_REPLACE:
1614 current_position = 0;
1616 case LOADMODE_NEW_TRACKS:
1618 current_position = 0;
1621 case LOADMODE_CONCATENATE:
1622 case LOADMODE_REPLACE_CONCATENATE:
1623 destination_track = 0;
1624 if( destination_tracks.total )
1625 current_position = destination_tracks.values[0]->get_length();
1627 current_position = 0;
1630 case LOADMODE_PASTE:
1631 destination_track = 0;
1633 for( int j=0; j<destination_tracks.total; ++j ) {
1634 paste_position[j] = (current_position >= 0) ?
1636 edl->local_session->get_selectionstart();
1641 case LOADMODE_RESOURCESONLY:
1642 edl->add_clip(new_edl);
1646 if( load_mode != LOADMODE_RESOURCESONLY &&
1647 load_mode != LOADMODE_ASSETSONLY ) {
1650 if( load_mode == LOADMODE_PASTE )
1651 edl->labels->insert_labels(new_edl->labels,
1652 destination_tracks.total ? paste_position[0] : 0.0,
1655 edl->labels->insert_labels(new_edl->labels, current_position,
1658 double total_length = new_edl->tracks->total_length();
1659 for( Track *new_track=new_edl->tracks->first;
1660 new_track; new_track=new_track->next ) {
1661 // Get destination track of same type as new_track
1663 k < destination_tracks.total &&
1664 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1665 ++k, ++destination_track ) {
1666 if( destination_track >= destination_tracks.total - 1 )
1667 destination_track = 0;
1670 // Insert data into destination track
1671 if( destination_track < destination_tracks.total &&
1672 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1673 Track *track = destination_tracks.values[destination_track];
1674 // Replace default keyframes if first EDL and new tracks were created.
1675 // This means data copied from one track and pasted to another won't retain
1676 // the camera position unless it's a keyframe. If it did, previous data in the
1677 // track might get unknowingly corrupted. Ideally we would detect when differing
1678 // default keyframes existed and create discrete keyframes for both.
1679 int replace_default = (i == 0) && need_new_tracks;
1680 // master tracks are the first track in each new edl when new tracks are created
1681 int master = track->master;
1682 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1683 // Insert new track at current position
1684 switch( load_mode ) {
1685 case LOADMODE_REPLACE_CONCATENATE:
1686 case LOADMODE_CONCATENATE:
1687 current_position = track->get_length();
1690 case LOADMODE_PASTE:
1691 current_position = paste_position[destination_track];
1692 paste_position[destination_track] += new_track->get_length();
1696 double length = overwrite >= 0 ?
1697 new_track->get_length() : total_length;
1698 track->clear(current_position,
1699 current_position + length,
1701 edit_labels, edit_plugins, edit_autos,
1705 track->insert_track(new_track, current_position, replace_default,
1706 edit_plugins, edit_autos, edl_length);
1707 if( master ) track->master = 1;
1711 // Get next destination track
1712 destination_track++;
1713 if( destination_track >= destination_tracks.total )
1714 destination_track = 0;
1718 if( load_mode == LOADMODE_PASTE )
1719 current_position += edl_length;
1723 // Move loading of clips and vwindow to the end - this fixes some
1724 // strange issue, for index not being shown
1725 // Assume any paste operation from the same EDL won't contain any clips.
1726 // If it did it would duplicate every clip here.
1727 for( int i=0; i<new_edls->total; ++i ) {
1728 EDL *new_edl = new_edls->get(i);
1730 for( int j=0; j<new_edl->clips.size(); ++j ) {
1731 edl->add_clip(new_edl->clips[j]);
1733 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1734 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1737 if( new_edl->total_vwindow_edls() ) {
1738 // if( edl->vwindow_edl )
1739 // edl->vwindow_edl->Garbage::remove_user();
1740 // edl->vwindow_edl = new EDL(edl);
1741 // edl->vwindow_edl->create_objects();
1742 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1744 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1745 EDL *vwindow_edl = new EDL(edl);
1746 vwindow_edl->create_objects();
1747 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1748 edl->append_vwindow_edl(vwindow_edl, 0);
1753 if( paste_position ) delete [] paste_position;
1755 // This is already done in load_filenames and everything else that uses paste_edls
1756 // update_project(load_mode);
1758 // Fix preview range
1759 // if( EQUIV(original_length, original_preview_end) )
1761 // edl->local_session->preview_end = edl->tracks->total_length();
1764 // Start examining next batch of index files
1765 mainindexes->start_build();
1767 // Don't save a backup after loading since the loaded file is on disk already.
1772 void MWindow::paste_silence()
1774 double start = edl->local_session->get_selectionstart();
1775 double end = edl->local_session->get_selectionend();
1776 if( EQUIV(start, end) ) {
1777 if( edl->session->frame_rate > 0 )
1778 end += 1./edl->session->frame_rate;
1780 undo_before(_("silence"), this);
1781 edl->paste_silence(start, end,
1782 edl->session->labels_follow_edits,
1783 edl->session->plugins_follow_edits,
1784 edl->session->autos_follow_edits);
1787 undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1789 update_plugin_guis();
1791 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1792 cwindow->update(1, 0, 0, 0, 1);
1793 cwindow->refresh_frame(CHANGE_EDL);
1796 void MWindow::detach_transition(Transition *transition)
1799 hide_plugin(transition, 1);
1800 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1801 transition->edit->detach_transition();
1803 undo_after(_("detach transition"), LOAD_ALL);
1805 if( is_video ) restart_brender();
1806 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1807 sync_parameters(CHANGE_EDL);
1810 void MWindow::detach_transitions()
1812 gui->lock_window("MWindow::detach_transitions 1");
1815 double start = edl->local_session->get_selectionstart();
1816 double end = edl->local_session->get_selectionend();
1817 edl->tracks->clear_transitions(start, end);
1820 undo_after(_("detach transitions"), LOAD_EDITS);
1822 sync_parameters(CHANGE_EDL);
1823 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1824 gui->unlock_window();
1827 void MWindow::paste_transition()
1829 // Only the first transition gets dropped.
1830 PluginServer *server = session->drag_pluginservers->values[0];
1833 edl->tracks->paste_transition(server, session->edit_highlighted);
1835 undo_after(_("transition"), LOAD_EDITS);
1837 if( server->video ) restart_brender();
1838 sync_parameters(CHANGE_ALL);
1841 void MWindow::paste_transitions(int track_type, char *title)
1843 gui->lock_window("MWindow::detach_transitions 1");
1846 double start = edl->local_session->get_selectionstart();
1847 double end = edl->local_session->get_selectionend();
1848 edl->tracks->paste_transitions(start, end, track_type, title);
1850 undo_after(_("attach transitions"), LOAD_EDITS);
1852 sync_parameters(CHANGE_EDL);
1853 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1854 gui->unlock_window();
1857 void MWindow::paste_transition_cwindow(Track *dest_track)
1859 PluginServer *server = session->drag_pluginservers->values[0];
1861 edl->tracks->paste_video_transition(server, 1);
1863 undo_after(_("transition"), LOAD_EDITS);
1865 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1866 sync_parameters(CHANGE_ALL);
1869 void MWindow::paste_audio_transition()
1871 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1874 char string[BCTEXTLEN];
1875 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1876 gui->show_message(string);
1881 edl->tracks->paste_audio_transition(server);
1883 undo_after(_("transition"), LOAD_EDITS);
1885 sync_parameters(CHANGE_EDL);
1886 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1889 void MWindow::paste_video_transition()
1891 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1894 char string[BCTEXTLEN];
1895 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1896 gui->show_message(string);
1902 edl->tracks->paste_video_transition(server);
1904 undo_after(_("transition"), LOAD_EDITS);
1906 sync_parameters(CHANGE_EDL);
1908 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1911 void MWindow::shuffle_edits()
1913 gui->lock_window("MWindow::shuffle_edits 1");
1916 double start = edl->local_session->get_selectionstart();
1917 double end = edl->local_session->get_selectionend();
1919 edl->tracks->shuffle_edits(start, end);
1922 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1924 sync_parameters(CHANGE_EDL);
1926 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1927 gui->unlock_window();
1930 void MWindow::reverse_edits()
1932 gui->lock_window("MWindow::reverse_edits 1");
1935 double start = edl->local_session->get_selectionstart();
1936 double end = edl->local_session->get_selectionend();
1938 edl->tracks->reverse_edits(start, end);
1941 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1943 sync_parameters(CHANGE_EDL);
1945 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1946 gui->unlock_window();
1949 void MWindow::align_edits()
1951 gui->lock_window("MWindow::align_edits 1");
1954 double start = edl->local_session->get_selectionstart();
1955 double end = edl->local_session->get_selectionend();
1957 edl->tracks->align_edits(start, end);
1960 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1962 sync_parameters(CHANGE_EDL);
1964 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1965 gui->unlock_window();
1968 void MWindow::set_edit_length(double length)
1970 gui->lock_window("MWindow::set_edit_length 1");
1973 double start = edl->local_session->get_selectionstart();
1974 double end = edl->local_session->get_selectionend();
1976 edl->tracks->set_edit_length(start, end, length);
1979 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1981 sync_parameters(CHANGE_EDL);
1983 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1984 gui->unlock_window();
1988 void MWindow::set_transition_length(Transition *transition, double length)
1990 gui->lock_window("MWindow::set_transition_length 1");
1993 //double start = edl->local_session->get_selectionstart();
1994 //double end = edl->local_session->get_selectionend();
1996 edl->tracks->set_transition_length(transition, length);
1999 undo_after(_("transition length"), LOAD_EDITS);
2001 edl->session->default_transition_length = length;
2002 sync_parameters(CHANGE_PARAMS);
2003 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2004 gui->unlock_window();
2007 void MWindow::set_transition_length(double length)
2009 gui->lock_window("MWindow::set_transition_length 2");
2012 double start = edl->local_session->get_selectionstart();
2013 double end = edl->local_session->get_selectionend();
2015 edl->tracks->set_transition_length(start, end, length);
2018 undo_after(_("transition length"), LOAD_EDITS);
2020 edl->session->default_transition_length = length;
2021 sync_parameters(CHANGE_PARAMS);
2023 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2024 gui->unlock_window();
2028 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2030 calling_window_gui->unlock_window();
2032 if( undo->redo_load_flags() & LOAD_SESSION )
2035 cwindow->gui->lock_window("MWindow::redo_entry 1");
2036 for( int i=0; i<vwindows.size(); ++i ) {
2037 if( vwindows.get(i)->is_running() ) {
2038 if( calling_window_gui != vwindows.get(i)->gui ) {
2039 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2043 gui->lock_window("MWindow::redo_entry 3");
2049 update_plugin_states();
2050 update_plugin_guis();
2052 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2053 gui->update_proxy_toggle();
2054 gui->unlock_window();
2055 cwindow->gui->unlock_window();
2056 cwindow->update(1, 1, 1, 1, 1);
2058 for( int i=0; i < vwindows.size(); ++i ) {
2059 if( vwindows.get(i)->is_running() ) {
2060 if( calling_window_gui != vwindows.get(i)->gui ) {
2061 vwindows.get(i)->gui->unlock_window();
2066 awindow->gui->async_update_assets();
2068 cwindow->refresh_frame(CHANGE_ALL);
2069 calling_window_gui->lock_window("MWindow::redo_entry 4");
2073 void MWindow::resize_track(Track *track, int w, int h)
2076 // We have to move all maskpoints so they do not move in relation to image areas
2077 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2078 (w - track->track_w) / 2,
2079 (h - track->track_h) / 2);
2082 undo_after(_("resize track"), LOAD_ALL);
2086 sync_parameters(CHANGE_EDL);
2090 void MWindow::set_inpoint()
2093 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2095 undo_after(_("in point"), LOAD_TIMEBAR);
2096 gui->update_timebar(1);
2098 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2099 cwindow->gui->timebar->update(1);
2100 cwindow->gui->unlock_window();
2103 void MWindow::set_outpoint()
2106 edl->set_outpoint(edl->local_session->get_selectionend(1));
2108 undo_after(_("out point"), LOAD_TIMEBAR);
2110 gui->update_timebar(1);
2111 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2112 cwindow->gui->timebar->update(1);
2113 cwindow->gui->unlock_window();
2116 void MWindow::unset_inoutpoint()
2119 edl->unset_inoutpoint();
2121 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2123 gui->update_timebar(1);
2124 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2125 cwindow->gui->timebar->update(1);
2126 cwindow->gui->unlock_window();
2129 void MWindow::splice(EDL *source, int all)
2132 LocalSession *src = source->local_session;
2135 double source_start = all ? 0 :
2136 src->inpoint_valid() ? src->get_inpoint() :
2137 src->outpoint_valid() ? 0 : src->get_selectionstart();
2138 double source_end = all ? source->tracks->total_length() :
2139 src->outpoint_valid() ? src->get_outpoint() :
2140 src->inpoint_valid() ? source->tracks->total_length() :
2141 src->get_selectionend();
2142 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2144 double start = edl->local_session->get_selectionstart();
2145 //double end = edl->local_session->get_selectionend();
2147 paste(start, start, &file,
2148 edl->session->labels_follow_edits,
2149 edl->session->plugins_follow_edits,
2150 edl->session->autos_follow_edits,
2153 // Position at end of clip
2154 edl->local_session->set_selectionstart(start + source_end - source_start);
2155 edl->local_session->set_selectionend(start + source_end - source_start);
2158 undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2159 update_plugin_guis();
2161 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2162 sync_parameters(CHANGE_EDL);
2165 void MWindow::save_clip(EDL *new_edl, const char *txt)
2167 new_edl->local_session->set_selectionstart(0);
2168 new_edl->local_session->set_selectionend(0);
2169 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2170 session->clip_number++);
2171 char duration[BCTEXTLEN];
2172 Units::totext(duration, new_edl->tracks->total_length(),
2173 new_edl->session->time_format,
2174 new_edl->session->sample_rate,
2175 new_edl->session->frame_rate,
2176 new_edl->session->frames_per_foot);
2178 Track *track = new_edl->tracks->first;
2179 const char *path = edl->path;
2180 for( ; (!path || !*path) && track; track=track->next ) {
2181 if( !track->is_armed() ) continue;
2182 Edit *edit = track->edits->first;
2183 if( !edit ) continue;
2184 Indexable *indexable = edit->get_source();
2185 if( !indexable ) continue;
2186 path = indexable->path;
2189 time_t now; time(&now);
2190 struct tm dtm; localtime_r(&now, &dtm);
2191 char *cp = new_edl->local_session->clip_notes;
2192 char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2194 cp += snprintf(cp, ep-cp, "%s", txt);
2195 cp += snprintf(cp, ep-cp,
2196 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2197 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2198 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2199 if( path && *path ) {
2201 char title[BCTEXTLEN];
2202 fs.extract_name(title, path);
2203 cp += snprintf(cp, ep-cp, "%s", title);
2205 sprintf(new_edl->local_session->clip_icon,
2206 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2207 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2208 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2210 new_edl->folder_no = AW_CLIP_FOLDER;
2211 edl->update_assets(new_edl);
2213 gui->get_abs_cursor(cur_x, cur_y, 0);
2214 gui->unlock_window();
2216 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2217 new_edl->remove_user();
2219 gui->lock_window("MWindow::save_clip");
2223 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2226 LocalSession *src = edl->local_session;
2228 gui->lock_window("MWindow::to_clip 1");
2229 double start = all ? 0 :
2230 src->inpoint_valid() ? src->get_inpoint() :
2231 src->outpoint_valid() ? 0 : src->get_selectionstart();
2232 double end = all ? edl->tracks->total_length() :
2233 src->outpoint_valid() ? src->get_outpoint() :
2234 src->inpoint_valid() ? edl->tracks->total_length() :
2235 src->get_selectionend();
2236 if( EQUIV(end, start) ) {
2238 end = edl->tracks->total_length();
2241 // Don't copy all since we don't want the clips twice.
2242 edl->copy(copy_flags(), start, end, &file, "", 1);
2244 EDL *new_edl = new EDL(edl);
2245 new_edl->create_objects();
2246 new_edl->load_xml(&file, LOAD_ALL);
2247 save_clip(new_edl, txt);
2248 gui->unlock_window();
2251 int MWindow::toggle_label()
2253 double position1, position2;
2256 position1 = edl->local_session->get_selectionstart(1);
2257 position2 = edl->local_session->get_selectionend(1);
2258 position1 = edl->align_to_frame(position1, 0);
2259 position2 = edl->align_to_frame(position2, 0);
2261 edl->labels->toggle_label(position1, position2);
2264 gui->update_timebar(0);
2265 gui->activate_timeline();
2268 cwindow->gui->lock_window("MWindow::toggle_label 2");
2269 cwindow->gui->timebar->update(1);
2270 cwindow->gui->unlock_window();
2271 awindow->gui->async_update_assets();
2273 undo_after(_("label"), LOAD_TIMEBAR);
2277 void MWindow::trim_selection()
2282 edl->trim_selection(edl->local_session->get_selectionstart(),
2283 edl->local_session->get_selectionend(),
2284 edl->session->labels_follow_edits,
2285 edl->session->plugins_follow_edits,
2286 edl->session->autos_follow_edits);
2289 undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2290 update_plugin_guis();
2291 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2292 cwindow->update(1, 0, 0, 0, 1);
2293 awindow->gui->async_update_assets();
2295 cwindow->refresh_frame(CHANGE_EDL);
2299 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2301 calling_window_gui->unlock_window();
2303 if( undo->undo_load_flags() & LOAD_SESSION )
2306 cwindow->gui->lock_window("MWindow::undo_entry 1");
2307 for( int i=0; i<vwindows.size(); ++i ) {
2308 if( vwindows.get(i)->is_running() ) {
2309 if( calling_window_gui != vwindows.get(i)->gui ) {
2310 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2314 gui->lock_window("MWindow::undo_entry 2");
2320 update_plugin_states();
2321 update_plugin_guis();
2323 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2324 gui->update_proxy_toggle();
2325 gui->unlock_window();
2326 cwindow->gui->unlock_window();
2327 cwindow->update(1, 1, 1, 1, 1);
2329 for( int i=0; i<vwindows.size(); ++i ) {
2330 if( vwindows.get(i)->is_running() ) {
2331 if( calling_window_gui != vwindows.get(i)->gui ) {
2332 vwindows.get(i)->gui->unlock_window();
2337 awindow->gui->async_update_assets();
2339 cwindow->refresh_frame(CHANGE_ALL);
2340 calling_window_gui->lock_window("MWindow::undo_entry 4");
2344 void MWindow::new_folder(const char *new_folder, int is_clips)
2347 if( edl->new_folder(new_folder, is_clips) ) {
2348 MainError::show_error(_("create new folder failed"));
2350 undo_after(_("new folder"), LOAD_ALL);
2351 awindow->gui->async_update_assets();
2354 void MWindow::delete_folder(char *folder)
2357 if( edl->delete_folder(folder) < 0 ) {
2358 MainError::show_error(_("delete folder failed"));
2360 undo_after(_("del folder"), LOAD_ALL);
2361 awindow->gui->async_update_assets();
2364 void MWindow::select_point(double position)
2366 gui->unlock_window();
2367 gui->stop_drawing();
2368 cwindow->stop_playback(0);
2369 gui->lock_window("MWindow::select_point");
2371 edl->local_session->set_selectionstart(position);
2372 edl->local_session->set_selectionend(position);
2375 cwindow->update(1, 0, 0, 0, 1);
2377 update_plugin_guis();
2378 gui->update_patchbay();
2379 gui->hide_cursor(0);
2380 gui->draw_cursor(0);
2381 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2382 gui->zoombar->update();
2383 gui->update_timebar(0);
2384 gui->flash_canvas(0);
2391 void MWindow::map_audio(int pattern)
2394 remap_audio(pattern);
2396 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2398 sync_parameters(CHANGE_PARAMS);
2399 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2402 void MWindow::remap_audio(int pattern)
2404 int current_channel = 0;
2405 int current_track = 0;
2406 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2407 if( current->data_type == TRACK_AUDIO &&
2408 current->is_armed() ) {
2409 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2410 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2412 for( int i=0; i < MAXCHANNELS; ++i ) {
2413 pan_auto->values[i] = 0.0;
2416 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2417 pan_auto->values[current_channel] = 1.0;
2420 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2421 switch( current_track ) {
2424 pan_auto->values[0] = 1;
2428 pan_auto->values[1] = 1;
2432 pan_auto->values[0] = 0.5;
2433 pan_auto->values[1] = 0.5;
2438 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2439 edl->session->achannel_positions, pan_auto->values,
2440 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2444 if( current_channel >= edl->session->audio_channels )
2445 current_channel = 0;
2451 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2453 edl->rescale_proxy(orig_scale, new_scale);
2456 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2458 edl->add_proxy(orig_assets, proxy_assets);
2461 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2462 float beep, int to_proxy, int remove_originals)
2464 if( !convert_render )
2465 convert_render = new ConvertRender(this);
2466 convert_render->set_format(format_asset, suffix, to_proxy);
2467 int found = convert_render->find_convertable_assets(edl);
2468 if( convert_render->needed_idxbls.size() > 0 )
2469 convert_render->start_convert(beep, remove_originals);
2470 else if( found > 0 )
2471 finish_convert(remove_originals);
2472 else if( found < 0 )
2473 eprintf(_("convert assets format error"));
2475 eprintf(_("No convertable assets found"));
2478 void MWindow::finish_convert(int remove_originals)
2480 gui->lock_window("MWindow::finish_convert");
2482 edl->replace_assets(
2483 convert_render->orig_idxbls,
2484 convert_render->orig_copies);
2485 if( remove_originals ) {
2486 remove_assets_from_project(0, 0, 0,
2487 &convert_render->orig_idxbls, 0);
2490 undo_after(_("convert"), LOAD_ALL);
2492 update_plugin_guis();
2493 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2494 cwindow->update(1, 0, 0, 0, 1);
2495 awindow->gui->async_update_assets();
2496 cwindow->refresh_frame(CHANGE_EDL);
2497 gui->unlock_window();
2500 void MWindow::cut_commercials()
2502 #ifdef HAVE_COMMERCIAL
2504 commercials->scan_media();
2507 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2510 update_plugin_guis();
2511 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2512 cwindow->update(1, 0, 0, 0, 1);
2513 cwindow->refresh_frame(CHANGE_EDL);
2517 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2520 Track *old_track = old_edl->tracks->first;
2521 Track *new_track = new_edl->tracks->first;
2522 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2523 if( old_track->data_type != new_track->data_type ) continue;
2524 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2525 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2526 if( !old_speeds || !new_speeds ) continue;
2527 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2528 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2529 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2530 old_speed = (FloatAuto *)old_speed->next;
2531 new_speed = (FloatAuto *)new_speed->next;
2533 Edit *old_edit = old_track->edits->first;
2534 Edit *new_edit = new_track->edits->first;
2535 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2536 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2537 if( old_speed || new_speed ) {
2538 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2539 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2540 edit_start = new_speeds->speed_position(orig_start);
2541 edit_end = new_speeds->speed_position(orig_end);
2544 new_edit->startproject = edit_start;
2545 new_edit->length = edit_end - edit_start;
2551 void MWindow::speed_before()
2554 speed_edl = new EDL;
2555 speed_edl->create_objects();
2557 speed_edl->copy_all(edl);
2560 int MWindow::speed_after(int done)
2565 result = normalize_speed(speed_edl, edl);
2567 speed_edl->remove_user();
2574 void MWindow::collect_effects()
2577 const char *file_string = "";
2579 int ret = edl->collect_effects(group);
2581 case COLLECT_EFFECTS_RECORD:
2582 eprintf(_("Selected edit track not armed."));
2584 case COLLECT_EFFECTS_MULTIPLE:
2585 eprintf(_("More than one edit selected on a track."));
2587 case COLLECT_EFFECTS_MISSING:
2588 eprintf(_("No effects under selected edit."));
2590 case COLLECT_EFFECTS_EMPTY:
2591 eprintf(_("No edits selected."));
2593 case COLLECT_EFFECTS_MASTER:
2594 eprintf(_("Shared effect added without master."));
2597 group->save_xml(&file, "");
2598 file_string = file.string();
2599 group->remove_user();
2601 long file_length = strlen(file_string);
2602 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2603 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2606 void MWindow::paste_effects()
2609 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2611 string = new char[len];
2612 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2614 if( !string || !string[0] ) {
2615 eprintf(_("Error clipboard buffer empty."));
2619 file.read_from_string(string);
2620 EDL *group = new EDL();
2621 group->create_objects();
2622 if( !group->load_xml(&file, LOAD_ALL) ) {
2624 int ret = edl->insert_effects(group);
2626 case INSERT_EFFECTS_RECORD:
2627 eprintf(_("Selected edit track not armed."));
2629 case INSERT_EFFECTS_TYPE:
2630 eprintf(_("Track type mismatched."));
2632 case INSERT_EFFECTS_MULTIPLE:
2633 eprintf(_("More than one edit selected on a track."));
2635 case INSERT_EFFECTS_MISSING:
2636 eprintf(_("Too few target edits to add group effects."));
2638 case INSERT_EFFECTS_EXTRA:
2639 eprintf(_("Too many target edits to add group effects."));
2641 case INSERT_EFFECTS_MASTER:
2642 eprintf(_("Shared effect added without master."));
2648 undo_after(_("paste effects"), LOAD_ALL);
2650 cwindow->refresh_frame(CHANGE_EDL);
2651 update_plugin_guis();
2652 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2655 eprintf(_("Error loading clip from clipboard buffer."));
2657 group->remove_user();