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->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 for( ; current; current=NEXT ) {
833 if( current->data_type == data_type && current->is_armed() ) {
834 double start = edl->local_session->get_selectionstart(1);
835 double end = edl->local_session->get_selectionend(1);
836 double length = end - start;
839 length = current->get_length();
841 insert_effect(title, &shared_location_local,
842 current, 0, start, length, plugin_type);
845 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
846 plugin_type = PLUGIN_SHAREDPLUGIN;
847 shared_location_local.module = edl->tracks->number_of(current);
848 shared_location_local.plugin = current->plugin_set.total - 1;
857 void MWindow::insert_effect(char *title,
858 SharedLocation *shared_location,
860 PluginSet *plugin_set,
865 KeyFrame *default_keyframe = 0;
866 PluginServer *server = 0;
867 // Get default keyframe
868 if( plugin_type == PLUGIN_STANDALONE ) {
869 default_keyframe = new KeyFrame;
870 server = new PluginServer(*scan_plugindb(title, track->data_type));
872 server->open_plugin(0, preferences, edl, 0);
873 server->save_data(default_keyframe);
875 // Insert plugin object
876 track->insert_effect(title, shared_location,
877 default_keyframe, plugin_set,
878 start, length, plugin_type);
881 if( plugin_type == PLUGIN_STANDALONE ) {
882 server->close_plugin();
884 delete default_keyframe;
888 int MWindow::modify_edithandles()
891 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
892 edl->modify_edithandles(session->drag_start,
893 session->drag_position, session->drag_handle, handle_mode,
894 edl->session->labels_follow_edits,
895 edl->session->plugins_follow_edits,
896 edl->session->autos_follow_edits,
897 session->drag_edit->group_id);
898 finish_modify_handles();
899 //printf("MWindow::modify_handles 1\n");
903 int MWindow::modify_pluginhandles()
907 edl->modify_pluginhandles(session->drag_start,
908 session->drag_position,
909 session->drag_handle,
910 edl->session->edit_handle_mode[session->drag_button],
911 edl->session->labels_follow_edits,
912 edl->session->autos_follow_edits,
913 session->trim_edits);
915 finish_modify_handles();
921 // Common to edithandles and plugin handles
922 void MWindow::finish_modify_handles()
924 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
925 double position = -1;
926 switch( edit_mode ) {
928 position = !session->drag_handle ?
929 session->drag_start : session->drag_position;
933 position = session->drag_position;
937 position = session->drag_start;
940 if( position >= 0 ) {
941 edl->local_session->set_selectionstart(position);
942 edl->local_session->set_selectionend(position);
944 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
948 sync_parameters(CHANGE_EDL);
949 update_plugin_guis();
950 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
951 // label list can be modified
952 awindow->gui->async_update_assets();
953 cwindow->update(1, 0, 0, 0, 1);
956 void MWindow::match_output_size(Track *track)
959 track->track_w = edl->session->output_w;
960 track->track_h = edl->session->output_h;
962 undo_after(_("match output size"), LOAD_ALL);
965 sync_parameters(CHANGE_EDL);
969 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
971 ArrayList<Edit*> edits;
973 delete_edits(&edits, msg, collapse);
976 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
978 if( !edits->size() ) return;
980 if( edl->session->labels_follow_edits )
981 edl->delete_edit_labels(edits, collapse);
982 edl->delete_edits(edits, collapse);
985 undo_after(msg, LOAD_EDITS);
988 cwindow->refresh_frame(CHANGE_EDL);
989 update_plugin_guis();
990 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
993 void MWindow::delete_edits(int collapse)
995 ArrayList<Edit*> edits;
996 edl->tracks->get_selected_edits(&edits);
997 delete_edits(&edits,_("del edit"), collapse);
1000 // collapse - delete from timeline, not collapse replace with silence
1001 // packed - omit unselected from selection, unpacked - replace unselected with silence
1002 void MWindow::cut_selected_edits(int collapse, int packed)
1004 selected_edits_to_clipboard(packed);
1005 ArrayList<Edit*> edits;
1006 edl->tracks->get_selected_edits(&edits);
1007 delete_edits(&edits, _("cut edit"), collapse);
1011 void MWindow::move_edits(ArrayList<Edit*> *edits,
1012 Track *track, double position, int mode)
1015 // lockout timebar labels update
1016 // labels can be deleted with tooltip repeater running
1017 cwindow->gui->lock_window("Tracks::move_edits");
1018 edl->tracks->move_edits(edits, track, position,
1019 edl->session->labels_follow_edits,
1020 edl->session->plugins_follow_edits,
1021 edl->session->autos_follow_edits, mode);
1022 cwindow->gui->timebar->update(1);
1023 cwindow->gui->unlock_window();
1026 undo_after(_("move edit"), LOAD_ALL);
1029 cwindow->refresh_frame(CHANGE_EDL);
1031 update_plugin_guis();
1032 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1035 void MWindow::selected_edits_to_clipboard(int packed)
1037 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1038 edl->session->labels_follow_edits,
1039 edl->session->autos_follow_edits,
1040 edl->session->plugins_follow_edits);
1041 if( !new_edl ) return;
1043 new_edl->copy(COPY_EDL, &file, "", 1);
1044 const char *file_string = file.string();
1045 long file_length = strlen(file_string);
1046 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1047 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1048 new_edl->remove_user();
1051 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1052 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1054 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1056 char *string = new char[len];
1057 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1059 file.read_from_string(string);
1061 EDL *clip = new EDL();
1062 clip->create_objects();
1063 if( !clip->load_xml(&file, LOAD_ALL) ) {
1065 edl->paste_edits(clip, first_track, position, overwrite,
1066 edit_edits, edit_labels, edit_autos, edit_plugins);
1068 undo_after(_("paste clip"), LOAD_ALL);
1070 cwindow->refresh_frame(CHANGE_EDL);
1072 update_plugin_guis();
1073 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1075 clip->remove_user();
1078 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1081 // lockout timebar labels update
1082 // labels can be deleted with tooltip repeater running
1083 cwindow->gui->lock_window("Tracks::move_group");
1085 ArrayList<Edit *>edits;
1086 edl->tracks->get_selected_edits(&edits);
1087 if( edl->session->labels_follow_edits )
1088 edl->delete_edit_labels(&edits, 0);
1089 edl->delete_edits(&edits, 0);
1090 edl->paste_edits(group, first_track, position, overwrite, 1,
1091 edl->session->labels_follow_edits,
1092 edl->session->autos_follow_edits,
1093 edl->session->plugins_follow_edits);
1094 cwindow->gui->timebar->update(1);
1095 cwindow->gui->unlock_window();
1096 // big debate over whether to do this, must either clear selected, or no tweaking
1097 // edl->tracks->clear_selected_edits();
1100 undo_after(_("move group"), LOAD_ALL);
1102 cwindow->refresh_frame(CHANGE_EDL);
1104 update_plugin_guis();
1105 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1108 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1111 edl->tracks->move_effect(plugin, track, position);
1113 undo_after(_("paste effect"), LOAD_ALL);
1116 cwindow->refresh_frame(CHANGE_EDL);
1117 update_plugin_guis();
1118 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1121 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1124 edl->tracks->move_effect(plugin, plugin_set, position);
1126 undo_after(_("move effect"), LOAD_ALL);
1129 cwindow->refresh_frame(CHANGE_EDL);
1130 update_plugin_guis();
1131 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1134 void MWindow::move_plugins_up(PluginSet *plugin_set)
1138 plugin_set->track->move_plugins_up(plugin_set);
1141 undo_after(_("move effect up"), LOAD_ALL);
1143 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1144 sync_parameters(CHANGE_EDL);
1147 void MWindow::move_plugins_down(PluginSet *plugin_set)
1151 plugin_set->track->move_plugins_down(plugin_set);
1154 undo_after(_("move effect down"), LOAD_ALL);
1156 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1157 sync_parameters(CHANGE_EDL);
1160 void MWindow::move_track_down(Track *track)
1163 edl->tracks->move_track_down(track);
1165 undo_after(_("move track down"), LOAD_ALL);
1168 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1169 sync_parameters(CHANGE_EDL);
1173 void MWindow::move_tracks_down()
1176 edl->tracks->move_tracks_down();
1178 undo_after(_("move tracks down"), LOAD_ALL);
1181 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1182 sync_parameters(CHANGE_EDL);
1186 void MWindow::move_track_up(Track *track)
1189 edl->tracks->move_track_up(track);
1191 undo_after(_("move track up"), LOAD_ALL);
1193 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1194 sync_parameters(CHANGE_EDL);
1198 void MWindow::move_tracks_up()
1201 edl->tracks->move_tracks_up();
1203 undo_after(_("move tracks up"), LOAD_ALL);
1205 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1206 sync_parameters(CHANGE_EDL);
1210 void MWindow::mute_selection()
1212 double start = edl->local_session->get_selectionstart();
1213 double end = edl->local_session->get_selectionend();
1214 if( start != end ) {
1216 edl->clear(start, end, 0,
1217 edl->session->plugins_follow_edits,
1218 edl->session->autos_follow_edits);
1219 edl->local_session->set_selectionend(end);
1220 edl->local_session->set_selectionstart(start);
1221 edl->paste_silence(start, end, 0,
1222 edl->session->plugins_follow_edits,
1223 edl->session->autos_follow_edits);
1226 undo_after(_("mute"), LOAD_EDITS);
1229 update_plugin_guis();
1230 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1231 cwindow->refresh_frame(CHANGE_EDL);
1236 void MWindow::overwrite(EDL *source, int all)
1240 LocalSession *src = source->local_session;
1241 double src_start = all ? 0 :
1242 src->inpoint_valid() ? src->get_inpoint() :
1243 src->outpoint_valid() ? 0 :
1244 src->get_selectionstart();
1245 double src_end = all ? source->tracks->total_length() :
1246 src->outpoint_valid() ? src->get_outpoint() :
1247 src->inpoint_valid() ? source->tracks->total_length() :
1248 src->get_selectionend();
1249 double overwrite_len = src_end - src_start;
1250 double dst_start = edl->local_session->get_selectionstart();
1251 double dst_len = edl->local_session->get_selectionend() - dst_start;
1254 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1255 // in/out points or selection present and shorter than overwrite range
1256 // shorten the copy range
1257 overwrite_len = dst_len;
1260 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1262 // HACK around paste_edl get_start/endselection on its own
1263 // so we need to clear only when not using both io points
1264 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1265 if( edl->local_session->get_inpoint() < 0 ||
1266 edl->local_session->get_outpoint() < 0 )
1267 edl->clear(dst_start, dst_start + overwrite_len,
1268 edl->session->labels_follow_edits,
1269 edl->session->plugins_follow_edits,
1270 edl->session->autos_follow_edits);
1272 paste(dst_start, dst_start + overwrite_len, &file,
1273 edl->session->labels_follow_edits,
1274 edl->session->plugins_follow_edits,
1275 edl->session->autos_follow_edits, 0, 0);
1277 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1278 edl->local_session->set_selectionend(dst_start + overwrite_len);
1281 undo_after(_("overwrite"), LOAD_EDITS);
1284 update_plugin_guis();
1285 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1286 sync_parameters(CHANGE_EDL);
1289 // For splice and overwrite
1290 int MWindow::paste(double start, double end, FileXML *file,
1291 int edit_labels, int edit_plugins, int edit_autos,
1292 Track *first_track, int overwrite)
1296 // Want to insert with assets shared with the master EDL.
1298 edit_labels, edit_plugins, edit_autos,
1299 edl, first_track, overwrite);
1304 // For editing using insertion point
1305 void MWindow::paste()
1307 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1310 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1312 //double end = edl->local_session->get_selectionend();
1313 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1316 char *string = new char[len];
1318 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1320 file.read_from_string(string);
1321 if( clear_selection ) clear(0);
1323 insert(start, &file,
1324 edl->session->labels_follow_edits,
1325 edl->session->plugins_follow_edits,
1326 edl->session->autos_follow_edits,
1327 0, first_track, overwrite);
1334 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1336 update_plugin_guis();
1337 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1338 awindow->gui->async_update_assets();
1339 sync_parameters(CHANGE_EDL);
1344 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1349 if( session->drag_assets->total ) {
1350 load_assets(session->drag_assets,
1351 position, LOADMODE_PASTE, dest_track, 0,
1352 edl->session->labels_follow_edits,
1353 edl->session->plugins_follow_edits,
1354 edl->session->autos_follow_edits,
1359 if( session->drag_clips->total ) {
1360 paste_edls(session->drag_clips,
1361 LOADMODE_PASTE, dest_track, position,
1362 edl->session->labels_follow_edits,
1363 edl->session->plugins_follow_edits,
1364 edl->session->autos_follow_edits,
1371 undo_after(_("paste assets"), LOAD_EDITS);
1373 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1374 sync_parameters(CHANGE_EDL);
1378 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1379 double position, int load_mode, Track *first_track, RecordLabels *labels,
1380 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1382 if( load_mode == LOADMODE_RESOURCESONLY )
1383 load_mode = LOADMODE_ASSETSONLY;
1384 const int debug = 0;
1385 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1387 position = edl->local_session->get_selectionstart();
1389 ArrayList<EDL*> new_edls;
1390 for( int i=0; i<new_assets->total; ++i ) {
1391 Indexable *indexable = new_assets->get(i);
1392 if( indexable->is_asset ) {
1393 remove_from_caches(indexable);
1395 EDL *new_edl = new EDL;
1396 new_edl->create_objects();
1397 new_edl->copy_session(edl);
1398 if( !indexable->is_asset ) {
1399 EDL *nested_edl = (EDL*)indexable;
1400 new_edl->create_nested(nested_edl);
1401 new_edl->set_path(indexable->path);
1404 Asset *asset = (Asset*)indexable;
1405 asset_to_edl(new_edl, asset);
1407 new_edls.append(new_edl);
1410 for( RecordLabel *label=labels->first; label; label=label->next ) {
1411 new_edl->labels->toggle_label(label->position, label->position);
1415 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1417 paste_edls(&new_edls, load_mode, first_track, position,
1418 edit_labels, edit_plugins, edit_autos, overwrite);
1419 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1422 for( int i=0; i<new_edls.size(); ++i )
1423 new_edls.get(i)->Garbage::remove_user();
1425 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1428 int MWindow::paste_automation()
1430 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1435 char *string = new char[len];
1436 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1438 file.read_from_string(string);
1440 double start = edl->local_session->get_selectionstart();
1441 double end = edl->local_session->get_selectionend();
1442 edl->tracks->clear_automation(start, end);
1443 edl->tracks->paste_automation(start, &file, 0, 1,
1444 edl->session->typeless_keyframes);
1445 int changed_edl = speed_after(1);
1447 undo_after(_("paste keyframes"),
1448 !changed_edl ? LOAD_AUTOMATION :
1449 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1450 update_gui(changed_edl);
1456 int MWindow::paste_default_keyframe()
1458 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1463 char *string = new char[len];
1464 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1466 file.read_from_string(string);
1468 double start = edl->local_session->get_selectionstart();
1469 edl->tracks->paste_automation(start, &file, 1, 0,
1470 edl->session->typeless_keyframes);
1471 // edl->tracks->paste_default_keyframe(&file);
1472 int changed_edl = speed_after(1);
1473 undo_after(_("paste default keyframe"),
1474 !changed_edl ? LOAD_AUTOMATION :
1475 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1477 update_gui(changed_edl);
1484 // Insert edls with project deletion and index file generation.
1485 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1486 Track *first_track, double current_position,
1487 int edit_labels, int edit_plugins, int edit_autos,
1491 ArrayList<Track*> destination_tracks;
1492 int need_new_tracks = 0;
1495 if( !new_edls->total ) return 0;
1498 // double original_length = edl->tracks->total_length();
1499 // double original_preview_end = edl->local_session->preview_end;
1502 // Delete current project
1503 if( load_mode == LOADMODE_REPLACE ||
1504 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1506 edl->save_defaults(defaults);
1508 edl->Garbage::remove_user();
1510 edl->create_objects();
1511 edl->copy_session(new_edls->values[0]);
1512 edl->copy_mixers(new_edls->values[0]);
1513 gui->mainmenu->update_toggles(0);
1514 gui->unlock_window();
1515 gwindow->gui->update_toggles(1);
1516 gui->lock_window("MWindow::paste_edls");
1518 // Insert labels for certain modes constitutively
1522 // Force reset of preview
1523 // original_length = 0;
1524 // original_preview_end = -1;
1530 // Create new tracks in master EDL
1531 if( load_mode == LOADMODE_REPLACE ||
1532 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1533 load_mode == LOADMODE_NEW_TRACKS ) {
1535 need_new_tracks = 1;
1536 for( int i=0; i<new_edls->total; ++i ) {
1537 EDL *new_edl = new_edls->values[i];
1538 int first_track = 1;
1539 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1540 switch( current->data_type ) {
1542 edl->tracks->add_video_track(0, 0);
1543 if( current->draw ) edl->tracks->last->draw = 1;
1546 edl->tracks->add_audio_track(0, 0);
1548 case TRACK_SUBTITLE:
1549 edl->tracks->add_subttl_track(0, 0);
1555 edl->tracks->last->master = 1;
1558 // re-label only if not already labeled
1559 if( new_edl->local_session->asset2edl )
1560 strcpy(current->title, edl->tracks->last->title);
1561 destination_tracks.append(edl->tracks->last);
1564 // Base track count on first EDL only for concatenation
1565 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1567 edl->session->highlighted_track = edl->tracks->total() - 1;
1570 // Recycle existing tracks of master EDL
1571 if( load_mode == LOADMODE_CONCATENATE ||
1572 load_mode == LOADMODE_PASTE ) {
1573 Track *current = first_track ? first_track : edl->tracks->first;
1574 for( ; current; current=NEXT ) {
1575 if( current->is_armed() ) {
1576 destination_tracks.append(current);
1582 int destination_track = 0;
1583 double *paste_position = new double[destination_tracks.total];
1585 // Iterate through the edls
1586 for( int i=0; i<new_edls->total; ++i ) {
1588 EDL *new_edl = new_edls->values[i];
1589 double edl_length = new_edl->local_session->clipboard_length ?
1590 new_edl->local_session->clipboard_length :
1591 new_edl->tracks->total_length();
1592 // printf("MWindow::paste_edls 2 %f %f\n",
1593 // new_edl->local_session->clipboard_length,
1594 // new_edl->tracks->total_length());
1598 // Convert EDL to master rates
1599 new_edl->resample(new_edl->session->sample_rate,
1600 edl->session->sample_rate,
1602 new_edl->resample(new_edl->session->frame_rate,
1603 edl->session->frame_rate,
1606 // Add assets and prepare index files
1607 for( Asset *new_asset=new_edl->assets->first;
1608 new_asset; new_asset=new_asset->next ) {
1609 mainindexes->add_indexable(new_asset);
1611 // Capture index file status from mainindex test
1612 edl->update_assets(new_edl);
1614 // Get starting point of insertion. Need this to paste labels.
1615 switch( load_mode ) {
1616 case LOADMODE_NOTHING:
1618 case LOADMODE_REPLACE:
1619 current_position = 0;
1621 case LOADMODE_NEW_TRACKS:
1623 current_position = 0;
1626 case LOADMODE_CONCATENATE:
1627 case LOADMODE_REPLACE_CONCATENATE:
1628 destination_track = 0;
1629 if( destination_tracks.total )
1630 current_position = destination_tracks.values[0]->get_length();
1632 current_position = 0;
1635 case LOADMODE_PASTE:
1636 destination_track = 0;
1638 for( int j=0; j<destination_tracks.total; ++j ) {
1639 paste_position[j] = (current_position >= 0) ?
1641 edl->local_session->get_selectionstart();
1646 case LOADMODE_RESOURCESONLY:
1647 edl->add_clip(new_edl);
1651 if( load_mode != LOADMODE_RESOURCESONLY &&
1652 load_mode != LOADMODE_ASSETSONLY ) {
1655 if( load_mode == LOADMODE_PASTE )
1656 edl->labels->insert_labels(new_edl->labels,
1657 destination_tracks.total ? paste_position[0] : 0.0,
1660 edl->labels->insert_labels(new_edl->labels, current_position,
1663 double total_length = new_edl->tracks->total_length();
1664 for( Track *new_track=new_edl->tracks->first;
1665 new_track; new_track=new_track->next ) {
1666 // Get destination track of same type as new_track
1668 k < destination_tracks.total &&
1669 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1670 ++k, ++destination_track ) {
1671 if( destination_track >= destination_tracks.total - 1 )
1672 destination_track = 0;
1675 // Insert data into destination track
1676 if( destination_track < destination_tracks.total &&
1677 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1678 Track *track = destination_tracks.values[destination_track];
1679 // Replace default keyframes if first EDL and new tracks were created.
1680 // This means data copied from one track and pasted to another won't retain
1681 // the camera position unless it's a keyframe. If it did, previous data in the
1682 // track might get unknowingly corrupted. Ideally we would detect when differing
1683 // default keyframes existed and create discrete keyframes for both.
1684 int replace_default = (i == 0) && need_new_tracks;
1685 // master tracks are the first track in each new edl when new tracks are created
1686 int master = track->master;
1687 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1688 // Insert new track at current position
1689 switch( load_mode ) {
1690 case LOADMODE_REPLACE_CONCATENATE:
1691 case LOADMODE_CONCATENATE:
1692 current_position = track->get_length();
1695 case LOADMODE_PASTE:
1696 current_position = paste_position[destination_track];
1697 paste_position[destination_track] += new_track->get_length();
1701 double length = overwrite >= 0 ?
1702 new_track->get_length() : total_length;
1703 track->clear(current_position,
1704 current_position + length,
1706 edit_labels, edit_plugins, edit_autos,
1710 track->insert_track(new_track, current_position, replace_default,
1711 edit_plugins, edit_autos, edl_length);
1712 if( master ) track->master = 1;
1716 // Get next destination track
1717 destination_track++;
1718 if( destination_track >= destination_tracks.total )
1719 destination_track = 0;
1723 if( load_mode == LOADMODE_PASTE )
1724 current_position += edl_length;
1728 // Move loading of clips and vwindow to the end - this fixes some
1729 // strange issue, for index not being shown
1730 // Assume any paste operation from the same EDL won't contain any clips.
1731 // If it did it would duplicate every clip here.
1732 for( int i=0; i<new_edls->total; ++i ) {
1733 EDL *new_edl = new_edls->get(i);
1735 for( int j=0; j<new_edl->clips.size(); ++j ) {
1736 edl->add_clip(new_edl->clips[j]);
1738 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1739 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1742 if( new_edl->total_vwindow_edls() ) {
1743 // if( edl->vwindow_edl )
1744 // edl->vwindow_edl->Garbage::remove_user();
1745 // edl->vwindow_edl = new EDL(edl);
1746 // edl->vwindow_edl->create_objects();
1747 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1749 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1750 EDL *vwindow_edl = new EDL(edl);
1751 vwindow_edl->create_objects();
1752 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1753 edl->append_vwindow_edl(vwindow_edl, 0);
1758 if( paste_position ) delete [] paste_position;
1760 // This is already done in load_filenames and everything else that uses paste_edls
1761 // update_project(load_mode);
1763 // Fix preview range
1764 // if( EQUIV(original_length, original_preview_end) )
1766 // edl->local_session->preview_end = edl->tracks->total_length();
1769 // Start examining next batch of index files
1770 mainindexes->start_build();
1772 // Don't save a backup after loading since the loaded file is on disk already.
1777 void MWindow::paste_silence()
1779 double start = edl->local_session->get_selectionstart();
1780 double end = edl->local_session->get_selectionend();
1781 if( EQUIV(start, end) ) {
1782 if( edl->session->frame_rate > 0 )
1783 end += 1./edl->session->frame_rate;
1785 undo_before(_("silence"), this);
1786 edl->paste_silence(start, end,
1787 edl->session->labels_follow_edits,
1788 edl->session->plugins_follow_edits,
1789 edl->session->autos_follow_edits);
1792 undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1794 update_plugin_guis();
1796 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1797 cwindow->update(1, 0, 0, 0, 1);
1798 cwindow->refresh_frame(CHANGE_EDL);
1801 void MWindow::detach_transition(Transition *transition)
1804 hide_plugin(transition, 1);
1805 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1806 transition->edit->detach_transition();
1808 undo_after(_("detach transition"), LOAD_ALL);
1810 if( is_video ) restart_brender();
1811 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1812 sync_parameters(CHANGE_EDL);
1815 void MWindow::detach_transitions()
1817 gui->lock_window("MWindow::detach_transitions 1");
1820 double start = edl->local_session->get_selectionstart();
1821 double end = edl->local_session->get_selectionend();
1822 edl->tracks->clear_transitions(start, end);
1825 undo_after(_("detach transitions"), LOAD_EDITS);
1827 sync_parameters(CHANGE_EDL);
1828 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1829 gui->unlock_window();
1832 void MWindow::paste_transition()
1834 // Only the first transition gets dropped.
1835 PluginServer *server = session->drag_pluginservers->values[0];
1838 edl->tracks->paste_transition(server, session->edit_highlighted);
1840 undo_after(_("transition"), LOAD_EDITS);
1842 if( server->video ) restart_brender();
1843 sync_parameters(CHANGE_ALL);
1846 void MWindow::paste_transitions(int track_type, char *title)
1848 gui->lock_window("MWindow::detach_transitions 1");
1851 double start = edl->local_session->get_selectionstart();
1852 double end = edl->local_session->get_selectionend();
1853 edl->tracks->paste_transitions(start, end, track_type, title);
1855 undo_after(_("attach transitions"), LOAD_EDITS);
1857 sync_parameters(CHANGE_EDL);
1858 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1859 gui->unlock_window();
1862 void MWindow::paste_transition_cwindow(Track *dest_track)
1864 PluginServer *server = session->drag_pluginservers->values[0];
1866 edl->tracks->paste_video_transition(server, 1);
1868 undo_after(_("transition"), LOAD_EDITS);
1870 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1871 sync_parameters(CHANGE_ALL);
1874 void MWindow::paste_audio_transition()
1876 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1879 char string[BCTEXTLEN];
1880 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1881 gui->show_message(string);
1886 edl->tracks->paste_audio_transition(server);
1888 undo_after(_("transition"), LOAD_EDITS);
1890 sync_parameters(CHANGE_EDL);
1891 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1894 void MWindow::paste_video_transition()
1896 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1899 char string[BCTEXTLEN];
1900 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1901 gui->show_message(string);
1907 edl->tracks->paste_video_transition(server);
1909 undo_after(_("transition"), LOAD_EDITS);
1911 sync_parameters(CHANGE_EDL);
1913 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1916 void MWindow::shuffle_edits()
1918 gui->lock_window("MWindow::shuffle_edits 1");
1921 double start = edl->local_session->get_selectionstart();
1922 double end = edl->local_session->get_selectionend();
1924 edl->tracks->shuffle_edits(start, end);
1927 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1929 sync_parameters(CHANGE_EDL);
1931 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1932 gui->unlock_window();
1935 void MWindow::reverse_edits()
1937 gui->lock_window("MWindow::reverse_edits 1");
1940 double start = edl->local_session->get_selectionstart();
1941 double end = edl->local_session->get_selectionend();
1943 edl->tracks->reverse_edits(start, end);
1946 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1948 sync_parameters(CHANGE_EDL);
1950 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1951 gui->unlock_window();
1954 void MWindow::align_edits()
1956 gui->lock_window("MWindow::align_edits 1");
1959 double start = edl->local_session->get_selectionstart();
1960 double end = edl->local_session->get_selectionend();
1962 edl->tracks->align_edits(start, end);
1965 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1967 sync_parameters(CHANGE_EDL);
1969 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1970 gui->unlock_window();
1973 void MWindow::set_edit_length(double length)
1975 gui->lock_window("MWindow::set_edit_length 1");
1978 double start = edl->local_session->get_selectionstart();
1979 double end = edl->local_session->get_selectionend();
1981 edl->tracks->set_edit_length(start, end, length);
1984 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1986 sync_parameters(CHANGE_EDL);
1988 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1989 gui->unlock_window();
1993 void MWindow::set_transition_length(Transition *transition, double length)
1995 gui->lock_window("MWindow::set_transition_length 1");
1998 //double start = edl->local_session->get_selectionstart();
1999 //double end = edl->local_session->get_selectionend();
2001 edl->tracks->set_transition_length(transition, length);
2004 undo_after(_("transition length"), LOAD_EDITS);
2006 edl->session->default_transition_length = length;
2007 sync_parameters(CHANGE_PARAMS);
2008 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2009 gui->unlock_window();
2012 void MWindow::set_transition_length(double length)
2014 gui->lock_window("MWindow::set_transition_length 2");
2017 double start = edl->local_session->get_selectionstart();
2018 double end = edl->local_session->get_selectionend();
2020 edl->tracks->set_transition_length(start, end, length);
2023 undo_after(_("transition length"), LOAD_EDITS);
2025 edl->session->default_transition_length = length;
2026 sync_parameters(CHANGE_PARAMS);
2028 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2029 gui->unlock_window();
2033 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2035 calling_window_gui->unlock_window();
2037 if( undo->redo_load_flags() & LOAD_SESSION )
2040 cwindow->gui->lock_window("MWindow::redo_entry 1");
2041 for( int i=0; i<vwindows.size(); ++i ) {
2042 if( vwindows.get(i)->is_running() ) {
2043 if( calling_window_gui != vwindows.get(i)->gui ) {
2044 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2048 gui->lock_window("MWindow::redo_entry 3");
2054 update_plugin_states();
2055 update_plugin_guis();
2057 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2058 gui->update_proxy_toggle();
2059 gui->unlock_window();
2060 cwindow->gui->unlock_window();
2061 cwindow->update(1, 1, 1, 1, 1);
2063 for( int i=0; i < vwindows.size(); ++i ) {
2064 if( vwindows.get(i)->is_running() ) {
2065 if( calling_window_gui != vwindows.get(i)->gui ) {
2066 vwindows.get(i)->gui->unlock_window();
2071 awindow->gui->async_update_assets();
2073 cwindow->refresh_frame(CHANGE_ALL);
2074 calling_window_gui->lock_window("MWindow::redo_entry 4");
2078 void MWindow::resize_track(Track *track, int w, int h)
2081 // We have to move all maskpoints so they do not move in relation to image areas
2082 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2083 (w - track->track_w) / 2,
2084 (h - track->track_h) / 2);
2087 undo_after(_("resize track"), LOAD_ALL);
2091 sync_parameters(CHANGE_EDL);
2095 void MWindow::set_inpoint()
2098 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2100 undo_after(_("in point"), LOAD_TIMEBAR);
2101 gui->update_timebar(1);
2103 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2104 cwindow->gui->timebar->update(1);
2105 cwindow->gui->unlock_window();
2108 void MWindow::set_outpoint()
2111 edl->set_outpoint(edl->local_session->get_selectionend(1));
2113 undo_after(_("out point"), LOAD_TIMEBAR);
2115 gui->update_timebar(1);
2116 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2117 cwindow->gui->timebar->update(1);
2118 cwindow->gui->unlock_window();
2121 void MWindow::unset_inoutpoint()
2124 edl->unset_inoutpoint();
2126 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2128 gui->update_timebar(1);
2129 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2130 cwindow->gui->timebar->update(1);
2131 cwindow->gui->unlock_window();
2134 void MWindow::splice(EDL *source, int all)
2137 LocalSession *src = source->local_session;
2140 double source_start = all ? 0 :
2141 src->inpoint_valid() ? src->get_inpoint() :
2142 src->outpoint_valid() ? 0 : src->get_selectionstart();
2143 double source_end = all ? source->tracks->total_length() :
2144 src->outpoint_valid() ? src->get_outpoint() :
2145 src->inpoint_valid() ? source->tracks->total_length() :
2146 src->get_selectionend();
2147 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2149 double start = edl->local_session->get_selectionstart();
2150 //double end = edl->local_session->get_selectionend();
2152 paste(start, start, &file,
2153 edl->session->labels_follow_edits,
2154 edl->session->plugins_follow_edits,
2155 edl->session->autos_follow_edits,
2158 // Position at end of clip
2159 edl->local_session->set_selectionstart(start + source_end - source_start);
2160 edl->local_session->set_selectionend(start + source_end - source_start);
2163 undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2164 update_plugin_guis();
2166 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2167 sync_parameters(CHANGE_EDL);
2170 void MWindow::save_clip(EDL *new_edl, const char *txt)
2172 new_edl->local_session->set_selectionstart(0);
2173 new_edl->local_session->set_selectionend(0);
2174 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2175 session->clip_number++);
2176 char duration[BCTEXTLEN];
2177 Units::totext(duration, new_edl->tracks->total_length(),
2178 new_edl->session->time_format,
2179 new_edl->session->sample_rate,
2180 new_edl->session->frame_rate,
2181 new_edl->session->frames_per_foot);
2183 Track *track = new_edl->tracks->first;
2184 const char *path = edl->path;
2185 for( ; (!path || !*path) && track; track=track->next ) {
2186 if( !track->is_armed() ) continue;
2187 Edit *edit = track->edits->first;
2188 if( !edit ) continue;
2189 Indexable *indexable = edit->get_source();
2190 if( !indexable ) continue;
2191 path = indexable->path;
2194 time_t now; time(&now);
2195 struct tm dtm; localtime_r(&now, &dtm);
2196 char *cp = new_edl->local_session->clip_notes;
2197 char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2199 cp += snprintf(cp, ep-cp, "%s", txt);
2200 cp += snprintf(cp, ep-cp,
2201 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2202 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2203 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2204 if( path && *path ) {
2206 char title[BCTEXTLEN];
2207 fs.extract_name(title, path);
2208 cp += snprintf(cp, ep-cp, "%s", title);
2210 sprintf(new_edl->local_session->clip_icon,
2211 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2212 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2213 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2215 new_edl->folder_no = AW_CLIP_FOLDER;
2216 edl->update_assets(new_edl);
2218 gui->get_abs_cursor(cur_x, cur_y, 0);
2219 gui->unlock_window();
2221 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2222 new_edl->remove_user();
2224 gui->lock_window("MWindow::save_clip");
2228 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2231 LocalSession *src = edl->local_session;
2233 gui->lock_window("MWindow::to_clip 1");
2234 double start = all ? 0 :
2235 src->inpoint_valid() ? src->get_inpoint() :
2236 src->outpoint_valid() ? 0 : src->get_selectionstart();
2237 double end = all ? edl->tracks->total_length() :
2238 src->outpoint_valid() ? src->get_outpoint() :
2239 src->inpoint_valid() ? edl->tracks->total_length() :
2240 src->get_selectionend();
2241 if( EQUIV(end, start) ) {
2243 end = edl->tracks->total_length();
2246 // Don't copy all since we don't want the clips twice.
2247 edl->copy(copy_flags(), start, end, &file, "", 1);
2249 EDL *new_edl = new EDL(edl);
2250 new_edl->create_objects();
2251 new_edl->load_xml(&file, LOAD_ALL);
2252 save_clip(new_edl, txt);
2253 gui->unlock_window();
2256 int MWindow::toggle_label()
2258 double position1, position2;
2261 position1 = edl->local_session->get_selectionstart(1);
2262 position2 = edl->local_session->get_selectionend(1);
2263 position1 = edl->align_to_frame(position1, 0);
2264 position2 = edl->align_to_frame(position2, 0);
2266 edl->labels->toggle_label(position1, position2);
2269 gui->update_timebar(0);
2270 gui->activate_timeline();
2273 cwindow->gui->lock_window("MWindow::toggle_label 2");
2274 cwindow->gui->timebar->update(1);
2275 cwindow->gui->unlock_window();
2276 awindow->gui->async_update_assets();
2278 undo_after(_("label"), LOAD_TIMEBAR);
2282 void MWindow::trim_selection()
2287 edl->trim_selection(edl->local_session->get_selectionstart(),
2288 edl->local_session->get_selectionend(),
2289 edl->session->labels_follow_edits,
2290 edl->session->plugins_follow_edits,
2291 edl->session->autos_follow_edits);
2294 undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2295 update_plugin_guis();
2296 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2297 cwindow->update(1, 0, 0, 0, 1);
2298 awindow->gui->async_update_assets();
2300 cwindow->refresh_frame(CHANGE_EDL);
2304 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2306 calling_window_gui->unlock_window();
2308 if( undo->undo_load_flags() & LOAD_SESSION )
2311 cwindow->gui->lock_window("MWindow::undo_entry 1");
2312 for( int i=0; i<vwindows.size(); ++i ) {
2313 if( vwindows.get(i)->is_running() ) {
2314 if( calling_window_gui != vwindows.get(i)->gui ) {
2315 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2319 gui->lock_window("MWindow::undo_entry 2");
2325 update_plugin_states();
2326 update_plugin_guis();
2328 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2329 gui->update_proxy_toggle();
2330 gui->unlock_window();
2331 cwindow->gui->unlock_window();
2332 cwindow->update(1, 1, 1, 1, 1);
2334 for( int i=0; i<vwindows.size(); ++i ) {
2335 if( vwindows.get(i)->is_running() ) {
2336 if( calling_window_gui != vwindows.get(i)->gui ) {
2337 vwindows.get(i)->gui->unlock_window();
2342 awindow->gui->async_update_assets();
2344 cwindow->refresh_frame(CHANGE_ALL);
2345 calling_window_gui->lock_window("MWindow::undo_entry 4");
2349 void MWindow::new_folder(const char *new_folder, int is_clips)
2352 if( edl->new_folder(new_folder, is_clips) ) {
2353 MainError::show_error(_("create new folder failed"));
2355 undo_after(_("new folder"), LOAD_ALL);
2356 awindow->gui->async_update_assets();
2359 void MWindow::delete_folder(char *folder)
2362 if( edl->delete_folder(folder) < 0 ) {
2363 MainError::show_error(_("delete folder failed"));
2365 undo_after(_("del folder"), LOAD_ALL);
2366 awindow->gui->async_update_assets();
2369 void MWindow::select_point(double position)
2371 gui->unlock_window();
2372 gui->stop_drawing();
2373 cwindow->stop_playback(0);
2374 gui->lock_window("MWindow::select_point");
2376 edl->local_session->set_selectionstart(position);
2377 edl->local_session->set_selectionend(position);
2380 cwindow->update(1, 0, 0, 0, 1);
2382 update_plugin_guis();
2383 gui->update_patchbay();
2384 gui->hide_cursor(0);
2385 gui->draw_cursor(0);
2386 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2387 gui->zoombar->update();
2388 gui->update_timebar(0);
2389 gui->flash_canvas(0);
2396 void MWindow::map_audio(int pattern)
2399 remap_audio(pattern);
2401 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2403 sync_parameters(CHANGE_PARAMS);
2404 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2407 void MWindow::remap_audio(int pattern)
2409 int current_channel = 0;
2410 int current_track = 0;
2411 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2412 if( current->data_type == TRACK_AUDIO &&
2413 current->is_armed() ) {
2414 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2415 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2417 for( int i=0; i < MAXCHANNELS; ++i ) {
2418 pan_auto->values[i] = 0.0;
2421 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2422 pan_auto->values[current_channel] = 1.0;
2425 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2426 switch( current_track ) {
2429 pan_auto->values[0] = 1;
2433 pan_auto->values[1] = 1;
2437 pan_auto->values[0] = 0.5;
2438 pan_auto->values[1] = 0.5;
2443 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2444 edl->session->achannel_positions, pan_auto->values,
2445 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2449 if( current_channel >= edl->session->audio_channels )
2450 current_channel = 0;
2456 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2458 edl->rescale_proxy(orig_scale, new_scale);
2461 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2463 edl->add_proxy(orig_assets, proxy_assets);
2466 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2467 float beep, int to_proxy, int remove_originals)
2469 if( !convert_render )
2470 convert_render = new ConvertRender(this);
2471 convert_render->set_format(format_asset, suffix, to_proxy);
2472 int found = convert_render->find_convertable_assets(edl);
2473 if( convert_render->needed_idxbls.size() > 0 )
2474 convert_render->start_convert(beep, remove_originals);
2475 else if( found > 0 )
2476 finish_convert(remove_originals);
2477 else if( found < 0 )
2478 eprintf(_("convert assets format error"));
2480 eprintf(_("No convertable assets found"));
2483 void MWindow::finish_convert(int remove_originals)
2485 gui->lock_window("MWindow::finish_convert");
2487 edl->replace_assets(
2488 convert_render->orig_idxbls,
2489 convert_render->orig_copies);
2490 if( remove_originals ) {
2491 remove_assets_from_project(0, 0, 0,
2492 &convert_render->orig_idxbls, 0);
2495 undo_after(_("convert"), LOAD_ALL);
2497 update_plugin_guis();
2498 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2499 cwindow->update(1, 0, 0, 0, 1);
2500 awindow->gui->async_update_assets();
2501 cwindow->refresh_frame(CHANGE_EDL);
2502 gui->unlock_window();
2505 void MWindow::cut_commercials()
2507 #ifdef HAVE_COMMERCIAL
2509 commercials->scan_media();
2512 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2515 update_plugin_guis();
2516 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2517 cwindow->update(1, 0, 0, 0, 1);
2518 cwindow->refresh_frame(CHANGE_EDL);
2522 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2525 Track *old_track = old_edl->tracks->first;
2526 Track *new_track = new_edl->tracks->first;
2527 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2528 if( old_track->data_type != new_track->data_type ) continue;
2529 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2530 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2531 if( !old_speeds || !new_speeds ) continue;
2532 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2533 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2534 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2535 old_speed = (FloatAuto *)old_speed->next;
2536 new_speed = (FloatAuto *)new_speed->next;
2538 Edit *old_edit = old_track->edits->first;
2539 Edit *new_edit = new_track->edits->first;
2540 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2541 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2542 if( old_speed || new_speed ) {
2543 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2544 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2545 edit_start = new_speeds->speed_position(orig_start);
2546 edit_end = new_speeds->speed_position(orig_end);
2549 new_edit->startproject = edit_start;
2550 new_edit->length = edit_end - edit_start;
2556 void MWindow::speed_before()
2559 speed_edl = new EDL;
2560 speed_edl->create_objects();
2562 speed_edl->copy_all(edl);
2565 int MWindow::speed_after(int done)
2570 result = normalize_speed(speed_edl, edl);
2572 speed_edl->remove_user();
2579 void MWindow::collect_effects()
2582 const char *file_string = "";
2584 int ret = edl->collect_effects(group);
2586 case COLLECT_EFFECTS_RECORD:
2587 eprintf(_("Selected edit track not armed."));
2589 case COLLECT_EFFECTS_MULTIPLE:
2590 eprintf(_("More than one edit selected on a track."));
2592 case COLLECT_EFFECTS_MISSING:
2593 eprintf(_("No effects under selected edit."));
2595 case COLLECT_EFFECTS_EMPTY:
2596 eprintf(_("No edits selected."));
2598 case COLLECT_EFFECTS_MASTER:
2599 eprintf(_("Shared effect added without master."));
2602 group->save_xml(&file, "");
2603 file_string = file.string();
2604 group->remove_user();
2606 long file_length = strlen(file_string);
2607 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2608 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2611 void MWindow::paste_effects()
2614 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2616 string = new char[len];
2617 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2619 if( !string || !string[0] ) {
2620 eprintf(_("Error clipboard buffer empty."));
2624 file.read_from_string(string);
2625 EDL *group = new EDL();
2626 group->create_objects();
2627 if( !group->load_xml(&file, LOAD_ALL) ) {
2629 int ret = edl->insert_effects(group);
2631 case INSERT_EFFECTS_RECORD:
2632 eprintf(_("Selected edit track not armed."));
2634 case INSERT_EFFECTS_TYPE:
2635 eprintf(_("Track type mismatched."));
2637 case INSERT_EFFECTS_MULTIPLE:
2638 eprintf(_("More than one edit selected on a track."));
2640 case INSERT_EFFECTS_MISSING:
2641 eprintf(_("Too few target edits to add group effects."));
2643 case INSERT_EFFECTS_EXTRA:
2644 eprintf(_("Too many target edits to add group effects."));
2646 case INSERT_EFFECTS_MASTER:
2647 eprintf(_("Shared effect added without master."));
2653 undo_after(_("paste effects"), LOAD_ALL);
2655 cwindow->refresh_frame(CHANGE_EDL);
2656 update_plugin_guis();
2657 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2660 eprintf(_("Error loading clip from clipboard buffer."));
2662 group->remove_user();