3 * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "awindowgui.h"
25 #include "bcsignals.h"
29 #include "commercials.h"
31 #include "cplayback.h"
34 #include "cwindowgui.h"
37 #include "edlsession.h"
38 #include "filesystem.h"
40 #include "floatauto.h"
41 #include "floatautos.h"
43 #include "gwindowgui.h"
45 #include "keyframes.h"
48 #include "levelwindow.h"
49 #include "localsession.h"
50 #include "mainclock.h"
51 #include "maincursor.h"
52 #include "mainerror.h"
53 #include "mainindexes.h"
55 #include "mainsession.h"
57 #include "maskautos.h"
59 #include "mwindowgui.h"
63 #include "playbackengine.h"
64 #include "pluginset.h"
65 #include "recordlabel.h"
66 #include "samplescroll.h"
67 #include "trackcanvas.h"
69 #include "trackscroll.h"
71 #include "transition.h"
72 #include "transportque.h"
74 #include "undostackitem.h"
75 #include "vplayback.h"
77 #include "vwindowgui.h"
80 #include "automation.h"
81 #include "maskautos.h"
85 void MWindow::add_audio_track_entry(int above, Track *dst)
88 Track *track = add_audio_track(above, dst);
91 undo_after(_("add track"), LOAD_ALL);
94 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
95 gui->activate_timeline();
96 cwindow->refresh_frame(CHANGE_EDL);
99 void MWindow::add_video_track_entry(int above, Track *dst)
102 Track *track = add_video_track(above, dst);
104 undo_after(_("add track"), LOAD_ALL);
108 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
109 gui->activate_timeline();
110 cwindow->refresh_frame(CHANGE_EDL);
114 void MWindow::add_subttl_track_entry(int above, Track *dst)
117 Track *track = add_subttl_track(above, dst);
119 undo_after(_("add track"), LOAD_ALL);
123 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
124 gui->activate_timeline();
125 cwindow->refresh_frame(CHANGE_EDL);
130 Track *MWindow::add_audio_track(int above, Track *dst)
132 Track *track = edl->tracks->add_audio_track(above, dst);
133 edl->tracks->update_y_pixels(theme);
138 Track *MWindow::add_video_track(int above, Track *dst)
140 Track *track = edl->tracks->add_video_track(above, dst);
141 edl->tracks->update_y_pixels(theme);
146 Track *MWindow::add_subttl_track(int above, Track *dst)
148 Track *track = edl->tracks->add_subttl_track(above, dst);
149 edl->tracks->update_y_pixels(theme);
154 void MWindow::asset_to_all()
156 if( !session->drag_assets->size() ) return;
157 Indexable *indexable = session->drag_assets->get(0);
159 // if( indexable->have_video() )
166 w = indexable->get_w();
167 h = indexable->get_h();
168 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
169 double old_framerate = edl->session->frame_rate;
170 int old_samplerate = edl->session->sample_rate;
171 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
174 if( indexable->have_video() ) {
175 edl->session->output_w = w;
176 edl->session->output_h = h;
177 edl->session->frame_rate = new_framerate;
179 edl->session->aspect_w,
180 edl->session->aspect_h,
183 for( Track *current=edl->tracks->first; current; current=NEXT ) {
184 if( current->data_type == TRACK_VIDEO /* &&
185 current->is_armed() */ ) {
186 current->track_w = w;
187 current->track_h = h;
192 if( ((edl->session->output_w % 4) ||
193 (edl->session->output_h % 4)) &&
194 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
195 MainError::show_error(
196 _("This project's dimensions are not multiples of 4 so\n"
197 "it can't be rendered by OpenGL."));
201 if( defaults->get("AUTOASPECT", 0) ) {
203 edl->session->aspect_w,
204 edl->session->aspect_h,
209 if( indexable->have_audio() ) {
210 edl->session->sample_rate = new_samplerate;
211 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
212 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
217 undo_after(_("asset to all"), LOAD_ALL);
219 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
220 sync_parameters(CHANGE_ALL);
224 void MWindow::asset_to_size()
226 if( !session->drag_assets->size() ) return;
227 Indexable *indexable = session->drag_assets->get(0);
229 if( indexable->have_video() ) {
234 w = indexable->get_w();
235 h = indexable->get_h();
236 edl->session->output_w = w;
237 edl->session->output_h = h;
239 if( ((edl->session->output_w % 4) ||
240 (edl->session->output_h % 4)) &&
241 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
242 MainError::show_error(
243 _("This project's dimensions are not multiples of 4 so\n"
244 "it can't be rendered by OpenGL."));
248 if( defaults->get("AUTOASPECT", 0) ) {
249 create_aspect_ratio(edl->session->aspect_w,
250 edl->session->aspect_h,
257 undo_after(_("asset to size"), LOAD_ALL);
259 sync_parameters(CHANGE_ALL);
264 void MWindow::asset_to_rate()
266 if( session->drag_assets->size() &&
267 session->drag_assets->get(0)->have_video() ) {
268 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
269 double old_framerate = edl->session->frame_rate;
272 edl->session->frame_rate = new_framerate;
273 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
277 undo_after(_("asset to rate"), LOAD_ALL);
279 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
280 sync_parameters(CHANGE_ALL);
285 void MWindow::clear_entry()
292 undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
295 update_plugin_guis();
296 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
297 cwindow->update(1, 0, 0, 0, 1);
298 cwindow->refresh_frame(CHANGE_EDL);
301 void MWindow::clear(int clear_handle)
303 double start = edl->local_session->get_selectionstart();
304 double end = edl->local_session->get_selectionend();
305 if( clear_handle || !EQUIV(start, end) ) {
308 edl->session->labels_follow_edits,
309 edl->session->plugins_follow_edits,
310 edl->session->autos_follow_edits);
314 void MWindow::update_gui(int changed_edl)
317 update_plugin_guis();
319 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
320 cwindow->update(1, 0, 0, 0, 1);
321 cwindow->refresh_frame(CHANGE_EDL);
324 gui->draw_overlays(1);
325 sync_parameters(CHANGE_PARAMS);
326 gui->update_patchbay();
327 cwindow->update(1, 0, 0);
331 void MWindow::set_automation_mode(int mode)
335 edl->tracks->set_automation_mode(
336 edl->local_session->get_selectionstart(),
337 edl->local_session->get_selectionend(),
339 int changed_edl = speed_after(1);
341 char string[BCSTRLEN];
342 sprintf(string,"set %s", FloatAuto::curve_name(mode));
344 !changed_edl ? LOAD_AUTOMATION :
345 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
346 update_gui(changed_edl);
349 void MWindow::clear_automation()
353 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
354 edl->local_session->get_selectionend());
355 int changed_edl = speed_after(1);
357 undo_after(_("clear keyframes"),
358 !changed_edl ? LOAD_AUTOMATION :
359 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
360 update_gui(changed_edl);
363 int MWindow::clear_default_keyframe()
367 edl->tracks->clear_default_keyframe();
368 int changed_edl = speed_after(1);
370 undo_after(_("clear default keyframe"),
371 !changed_edl ? LOAD_AUTOMATION :
372 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
373 update_gui(changed_edl);
377 void MWindow::clear_labels()
380 clear_labels(edl->local_session->get_selectionstart(),
381 edl->local_session->get_selectionend());
382 undo_after(_("clear labels"), LOAD_TIMEBAR);
384 gui->update_timebar(1);
385 cwindow->update(0, 0, 0, 0, 1);
389 int MWindow::clear_labels(double start, double end)
393 end = edl->tracks->total_length();
395 edl->labels->clear(start, end, 0);
399 void MWindow::clear_hard_edges()
402 clear_hard_edges(edl->local_session->get_selectionstart(),
403 edl->local_session->get_selectionend());
406 undo_after(_("clear hard edges"), LOAD_EDITS);
408 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
409 cwindow->refresh_frame(CHANGE_EDL);
412 int MWindow::clear_hard_edges(double start, double end)
416 end = edl->tracks->total_length();
418 edl->clear_hard_edges(start, end);
422 void MWindow::clear_select()
424 edl->tracks->clear_selected_edits();
425 gui->draw_overlays(1);
428 void MWindow::concatenate_tracks()
431 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
432 edl->session->autos_follow_edits);
434 undo_after(_("concatenate tracks"), LOAD_EDITS);
437 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
438 cwindow->refresh_frame(CHANGE_EDL);
442 int MWindow::copy_flags(int copy_flags)
444 if( !edl->session->labels_follow_edits )
445 copy_flags &= ~COPY_LABELS;
446 if( !edl->session->autos_follow_edits )
447 copy_flags &= ~COPY_AUTOS;
448 if( !edl->session->plugins_follow_edits )
449 copy_flags &= ~COPY_PLUGINS;
455 copy(edl->local_session->get_selectionstart(),
456 edl->local_session->get_selectionend());
459 int MWindow::copy(double start, double end)
461 if( start == end ) return 1;
464 edl->copy(copy_flags(), start, end, &file, "", 1);
465 const char *file_string = file.string();
466 long file_length = strlen(file_string);
467 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
468 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
473 int MWindow::copy_automation()
476 double start = edl->local_session->get_selectionstart();
477 double end = edl->local_session->get_selectionend();
478 edl->tracks->copy_automation(start, end, &file, 0, 1);
479 const char *file_string = file.string();
480 long file_length = strlen(file_string);
481 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
482 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
486 int MWindow::copy_default_keyframe()
489 double start = edl->local_session->get_selectionstart();
490 double end = edl->local_session->get_selectionend();
491 edl->tracks->copy_automation(start, end, &file, 1, 0);
492 const char *file_string = file.string();
493 long file_length = strlen(file_string);
494 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
495 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
499 // Uses cropping coordinates in edl session to crop and translate video.
500 // We modify the projector since camera automation depends on the track size.
501 void MWindow::crop_video(int mode)
504 // Clamp EDL crop region
505 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
506 edl->session->crop_x1 ^= edl->session->crop_x2;
507 edl->session->crop_x2 ^= edl->session->crop_x1;
508 edl->session->crop_x1 ^= edl->session->crop_x2;
510 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
511 edl->session->crop_y1 ^= edl->session->crop_y2;
512 edl->session->crop_y2 ^= edl->session->crop_y1;
513 edl->session->crop_y1 ^= edl->session->crop_y2;
516 case CROP_REFORMAT: {
517 float ctr_x = edl->session->output_w / 2.;
518 float ctr_y = edl->session->output_h / 2.;
519 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
520 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
521 float dx = -(new_x - ctr_x), dy = -(new_y - ctr_y);
522 edl->tracks->translate_projector(dx, dy, 1);
524 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
525 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
526 edl->session->crop_x1 = edl->session->crop_y1 = 0;
527 edl->session->crop_x2 = edl->session->output_w;
528 edl->session->crop_y2 = edl->session->output_h;
531 float old_w = edl->session->output_w;
532 float old_h = edl->session->output_h;
533 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
534 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
535 if( !new_w ) new_w = 1;
536 if( !new_h ) new_h = 1;
537 float xzoom = old_w / new_w, yzoom = old_h / new_h;
538 float new_z = bmin(xzoom, yzoom);
539 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
540 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
541 edl->tracks->crop_resize(new_x, new_y, new_z);
543 edl->session->crop_x1 = 0;
544 edl->session->crop_y1 = 0;
545 edl->session->crop_x2 = edl->session->output_w;
546 edl->session->crop_y2 = edl->session->output_h;
549 float old_w = edl->session->output_w;
550 float old_h = edl->session->output_h;
551 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
552 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
553 if( !new_w ) new_w = 1;
554 if( !new_h ) new_h = 1;
555 float xzoom = old_w / new_w, yzoom = old_h / new_h;
556 float new_z = bmin(xzoom, yzoom);
558 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
559 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
560 edl->tracks->crop_shrink(new_x, new_y, new_z);
564 // Recalculate aspect ratio
565 if( defaults->get("AUTOASPECT", 0) ) {
566 create_aspect_ratio(edl->session->aspect_w,
567 edl->session->aspect_h,
568 edl->session->output_w,
569 edl->session->output_h);
572 undo_after(_("crop"), LOAD_ALL);
575 cwindow->refresh_frame(CHANGE_ALL);
581 double start = edl->local_session->get_selectionstart();
582 double end = edl->local_session->get_selectionend();
583 if( EQUIV(start,end) )
589 void MWindow::blade(double position)
592 edl->blade(position);
595 undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
597 update_plugin_guis();
598 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
599 cwindow->update(1, 0, 0, 0, 1);
600 awindow->gui->async_update_assets();
601 cwindow->refresh_frame(CHANGE_EDL);
604 void MWindow::cut(double start, double end, double new_position)
608 edl->clear(start, end,
609 edl->session->labels_follow_edits,
610 edl->session->plugins_follow_edits,
611 edl->session->autos_follow_edits);
615 undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
616 if( new_position >= 0 ) {
617 edl->local_session->set_selectionstart(new_position);
618 edl->local_session->set_selectionend(new_position);
621 update_plugin_guis();
622 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
623 cwindow->update(1, 0, 0, 0, 1);
624 awindow->gui->async_update_assets();
625 cwindow->refresh_frame(CHANGE_EDL);
628 void MWindow::cut_left_edit()
630 double start_pos = edl->local_session->get_selectionstart(1);
631 double position = edl->prev_edit(start_pos);
632 if( position < start_pos )
633 cut(position, start_pos, position);
636 void MWindow::cut_right_edit()
638 double end_pos = edl->local_session->get_selectionend(1);
639 double position = edl->next_edit(end_pos);
640 if( end_pos < position )
641 cut(end_pos, position, end_pos);
644 void MWindow::cut_left_label()
646 double start_pos = edl->local_session->get_selectionstart(1);
647 Label *left_label = edl->labels->prev_label(start_pos);
648 if( !left_label ) return;
649 double position = left_label->position;
650 if( position < start_pos )
651 cut(position, start_pos, position);
654 void MWindow::cut_right_label()
656 double end_pos = edl->local_session->get_selectionend(1);
657 Label *right_label = edl->labels->next_label(end_pos);
658 if( !right_label ) return;
659 double position = right_label->position;
660 if( end_pos < position )
661 cut(end_pos, position, end_pos);
664 int MWindow::cut_automation()
669 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
670 edl->local_session->get_selectionend());
671 int changed_edl = speed_after(1);
673 undo_after(_("cut keyframes"),
674 !changed_edl ? LOAD_AUTOMATION :
675 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
676 update_gui(changed_edl);
680 int MWindow::cut_default_keyframe()
685 copy_default_keyframe();
686 edl->tracks->clear_default_keyframe();
687 int changed_edl = speed_after(1);
689 undo_after(_("cut default keyframe"),
690 !changed_edl ? LOAD_AUTOMATION :
691 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
692 update_gui(changed_edl);
697 void MWindow::delete_tracks()
700 edl->tracks->delete_tracks();
701 undo_after(_("delete tracks"), LOAD_ALL);
705 update_plugin_states();
707 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
708 cwindow->refresh_frame(CHANGE_EDL);
711 void MWindow::delete_track(Track *track)
714 edl->tracks->delete_track(track);
715 undo_after(_("delete track"), LOAD_ALL);
718 update_plugin_states();
720 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
721 cwindow->refresh_frame(CHANGE_EDL);
726 // Insert data from clipboard
727 void MWindow::insert(double position, FileXML *file,
728 int edit_labels, int edit_plugins, int edit_autos,
729 EDL *parent_edl, Track *first_track, int overwrite)
731 // For clipboard pasting make the new edl use a separate session
732 // from the master EDL. Then it can be resampled to the master rates.
733 // For splice, overwrite, and dragging need same session to get the assets.
734 EDL *edl = new EDL(parent_edl);
735 ArrayList<EDL*> new_edls;
736 uint32_t load_flags = LOAD_ALL;
739 new_edls.append(edl);
740 edl->create_objects();
745 if( parent_edl ) load_flags &= ~LOAD_SESSION;
746 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
747 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
749 edl->load_xml(file, load_flags);
752 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
756 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
757 edit_labels, edit_plugins, edit_autos, overwrite);
758 // if( vwindow->edl )
759 // printf("MWindow::insert 5 %f %f\n",
760 // vwindow->edl->local_session->in_point,
761 // vwindow->edl->local_session->out_point);
762 new_edls.remove_all();
763 edl->Garbage::remove_user();
764 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
767 void MWindow::insert_effects_canvas(Track *dest_track, double start, double length)
771 ArrayList<SharedLocation> shared_locations;
772 PluginSet *pluginset = session->pluginset_highlighted;
773 int gang = edl->session->gang_tracks != GANG_NONE ? 1 : 0;
774 int data_type = dest_track->data_type;
777 for( Track *track=dest_track; track; track=track->next ) {
778 if( gang && track->master && !first_track ) break;
779 if( track->data_type != data_type ) continue;
780 if( !track->is_armed() ) continue;
781 int module = edl->tracks->number_of(track);
782 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
783 PluginServer *plugin = session->drag_pluginservers->values[i];
784 int shared = gang; // && plugin->multichannel ? 1 : 0;
785 int plugin_type = !first_track && shared ?
786 PLUGIN_SHAREDPLUGIN : PLUGIN_STANDALONE;
787 SharedLocation *shared_location = !first_track ?
788 &shared_locations[i] : &shared_locations.append();
789 insert_effect(plugin->title, shared_location, track,
790 pluginset, start, length, plugin_type);
791 if( first_track && shared ) {
792 shared_location->module = module;
793 shared_location->plugin = pluginset ?
794 track->plugin_set.number_of(pluginset) :
795 track->plugin_set.total-1 ;
804 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
806 sync_parameters(CHANGE_EDL);
807 // GUI updated in TrackCanvas, after current_operations are reset
810 void MWindow::insert_effects_cwindow(Track *dest_track)
812 if( !dest_track ) return;
815 double length = dest_track->get_length();
817 if( edl->local_session->get_selectionend() >
818 edl->local_session->get_selectionstart() ) {
819 start = edl->local_session->get_selectionstart();
820 length = edl->local_session->get_selectionend() -
821 edl->local_session->get_selectionstart();
824 insert_effects_canvas(dest_track, start, length);
825 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
828 void MWindow::insert_effect(char *title, SharedLocation *shared_location,
829 int data_type, int plugin_type, int single_standalone)
831 Track *current = edl->tracks->first;
832 SharedLocation shared_location_local;
833 shared_location_local.copy_from(shared_location);
835 double start_pos = edl->local_session->get_selectionstart(1);
836 double end_pos = edl->local_session->get_selectionend(1);
837 for( ; current; current=NEXT ) {
838 if( current->data_type != data_type ) continue;
839 if( !current->is_armed() ) continue;
840 double start = start_pos, end = end_pos;
841 if( plugin_type == PLUGIN_STANDALONE && start >= end ) {
843 end = current->get_length();
845 double length = end - start;
846 insert_effect(title, &shared_location_local,
847 current, 0, start, length, plugin_type);
849 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
850 plugin_type = PLUGIN_SHAREDPLUGIN;
851 shared_location_local.module = edl->tracks->number_of(current);
852 shared_location_local.plugin = current->plugin_set.total - 1;
853 start_pos = start; end_pos = end;
860 void MWindow::insert_effect(char *title,
861 SharedLocation *shared_location, Track *track, PluginSet *plugin_set,
862 double start, double length, int plugin_type)
864 KeyFrame *default_keyframe = 0;
865 PluginServer *server = 0;
866 // Get default keyframe
867 if( plugin_type == PLUGIN_STANDALONE ) {
868 default_keyframe = new KeyFrame;
869 server = new PluginServer(*scan_plugindb(title, track->data_type));
871 server->open_plugin(0, preferences, edl, 0);
872 server->save_data(default_keyframe);
874 // Insert plugin object
875 track->insert_effect(title, shared_location, default_keyframe,
876 plugin_set, start, length, plugin_type);
879 if( plugin_type == PLUGIN_STANDALONE ) {
880 server->close_plugin();
882 delete default_keyframe;
886 int MWindow::modify_edithandles()
889 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
890 edl->modify_edithandles(session->drag_start,
891 session->drag_position, session->drag_handle, handle_mode,
892 edl->session->labels_follow_edits,
893 edl->session->plugins_follow_edits,
894 edl->session->autos_follow_edits,
895 session->drag_edit->group_id);
896 finish_modify_handles();
897 //printf("MWindow::modify_handles 1\n");
901 int MWindow::modify_pluginhandles()
905 edl->modify_pluginhandles(session->drag_start,
906 session->drag_position,
907 session->drag_handle,
908 edl->session->edit_handle_mode[session->drag_button],
909 edl->session->labels_follow_edits,
910 edl->session->autos_follow_edits,
911 session->trim_edits);
913 finish_modify_handles();
919 // Common to edithandles and plugin handles
920 void MWindow::finish_modify_handles()
922 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
923 double position = -1;
924 switch( edit_mode ) {
926 position = !session->drag_handle ?
927 session->drag_start : session->drag_position;
931 position = session->drag_position;
935 position = session->drag_start;
938 if( position >= 0 ) {
939 edl->local_session->set_selectionstart(position);
940 edl->local_session->set_selectionend(position);
942 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
946 sync_parameters(CHANGE_EDL);
947 update_plugin_guis();
948 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
949 // label list can be modified
950 awindow->gui->async_update_assets();
951 cwindow->update(1, 0, 0, 0, 1);
954 void MWindow::match_output_size(Track *track)
957 track->track_w = edl->session->output_w;
958 track->track_h = edl->session->output_h;
960 undo_after(_("match output size"), LOAD_ALL);
963 sync_parameters(CHANGE_EDL);
967 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
969 ArrayList<Edit*> edits;
971 delete_edits(&edits, msg, collapse);
974 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
976 if( !edits->size() ) return;
978 if( edl->session->labels_follow_edits )
979 edl->delete_edit_labels(edits, collapse);
980 edl->delete_edits(edits, collapse);
983 undo_after(msg, LOAD_EDITS);
986 cwindow->refresh_frame(CHANGE_EDL);
987 update_plugin_guis();
988 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
991 void MWindow::delete_edits(int collapse)
993 ArrayList<Edit*> edits;
994 edl->tracks->get_selected_edits(&edits);
995 delete_edits(&edits,_("del edit"), collapse);
998 // collapse - delete from timeline, not collapse replace with silence
999 // packed - omit unselected from selection, unpacked - replace unselected with silence
1000 void MWindow::cut_selected_edits(int collapse, int packed)
1002 selected_edits_to_clipboard(packed);
1003 ArrayList<Edit*> edits;
1004 edl->tracks->get_selected_edits(&edits);
1005 delete_edits(&edits, _("cut edit"), collapse);
1009 void MWindow::move_edits(ArrayList<Edit*> *edits,
1010 Track *track, double position, int mode)
1013 // lockout timebar labels update
1014 // labels can be deleted with tooltip repeater running
1015 cwindow->gui->lock_window("Tracks::move_edits");
1016 edl->tracks->move_edits(edits, track, position,
1017 edl->session->labels_follow_edits,
1018 edl->session->plugins_follow_edits,
1019 edl->session->autos_follow_edits, mode);
1020 cwindow->gui->timebar->update(1);
1021 cwindow->gui->unlock_window();
1024 undo_after(_("move edit"), LOAD_ALL);
1027 cwindow->refresh_frame(CHANGE_EDL);
1029 update_plugin_guis();
1030 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1033 void MWindow::selected_edits_to_clipboard(int packed)
1035 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1036 edl->session->labels_follow_edits,
1037 edl->session->autos_follow_edits,
1038 edl->session->plugins_follow_edits);
1039 if( !new_edl ) return;
1041 new_edl->copy(COPY_EDL, &file, "", 1);
1042 const char *file_string = file.string();
1043 long file_length = strlen(file_string);
1044 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1045 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1046 new_edl->remove_user();
1049 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1050 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1052 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1054 char *string = new char[len];
1055 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1057 file.read_from_string(string);
1059 EDL *clip = new EDL();
1060 clip->create_objects();
1061 if( !clip->load_xml(&file, LOAD_ALL) ) {
1063 edl->paste_edits(clip, first_track, position, overwrite,
1064 edit_edits, edit_labels, edit_autos, edit_plugins);
1066 undo_after(_("paste clip"), LOAD_ALL);
1068 cwindow->refresh_frame(CHANGE_EDL);
1070 update_plugin_guis();
1071 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1073 clip->remove_user();
1076 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1079 // lockout timebar labels update
1080 // labels can be deleted with tooltip repeater running
1081 cwindow->gui->lock_window("Tracks::move_group");
1083 ArrayList<Edit *>edits;
1084 edl->tracks->get_selected_edits(&edits);
1085 if( edl->session->labels_follow_edits )
1086 edl->delete_edit_labels(&edits, 0);
1087 edl->delete_edits(&edits, 0);
1088 edl->paste_edits(group, first_track, position, overwrite, 1,
1089 edl->session->labels_follow_edits,
1090 edl->session->autos_follow_edits,
1091 edl->session->plugins_follow_edits);
1092 cwindow->gui->timebar->update(1);
1093 cwindow->gui->unlock_window();
1094 // big debate over whether to do this, must either clear selected, or no tweaking
1095 // edl->tracks->clear_selected_edits();
1098 undo_after(_("move group"), LOAD_ALL);
1100 cwindow->refresh_frame(CHANGE_EDL);
1102 update_plugin_guis();
1103 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1106 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1109 edl->tracks->move_effect(plugin, track, position);
1111 undo_after(_("paste effect"), LOAD_ALL);
1114 cwindow->refresh_frame(CHANGE_EDL);
1115 update_plugin_guis();
1116 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1119 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1122 edl->tracks->move_effect(plugin, plugin_set, position);
1124 undo_after(_("move effect"), LOAD_ALL);
1127 cwindow->refresh_frame(CHANGE_EDL);
1128 update_plugin_guis();
1129 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1132 void MWindow::move_plugins_up(PluginSet *plugin_set)
1136 plugin_set->track->move_plugins_up(plugin_set);
1139 undo_after(_("move effect up"), LOAD_ALL);
1141 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1142 sync_parameters(CHANGE_EDL);
1145 void MWindow::move_plugins_down(PluginSet *plugin_set)
1149 plugin_set->track->move_plugins_down(plugin_set);
1152 undo_after(_("move effect down"), LOAD_ALL);
1154 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1155 sync_parameters(CHANGE_EDL);
1158 void MWindow::move_track_down(Track *track)
1161 edl->tracks->move_track_down(track);
1163 undo_after(_("move track down"), LOAD_ALL);
1166 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1167 sync_parameters(CHANGE_EDL);
1171 void MWindow::move_tracks_down()
1174 edl->tracks->move_tracks_down();
1176 undo_after(_("move tracks down"), LOAD_ALL);
1179 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1180 sync_parameters(CHANGE_EDL);
1184 void MWindow::move_track_up(Track *track)
1187 edl->tracks->move_track_up(track);
1189 undo_after(_("move track up"), LOAD_ALL);
1191 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1192 sync_parameters(CHANGE_EDL);
1196 void MWindow::move_tracks_up()
1199 edl->tracks->move_tracks_up();
1201 undo_after(_("move tracks up"), LOAD_ALL);
1203 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1204 sync_parameters(CHANGE_EDL);
1208 void MWindow::swap_track_down(Track *track)
1211 edl->tracks->swap_track_down(track);
1213 undo_after(_("swap track down"), LOAD_ALL);
1216 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1217 sync_parameters(CHANGE_EDL);
1221 void MWindow::swap_tracks_down()
1224 edl->tracks->swap_tracks_down();
1226 undo_after(_("swap tracks down"), LOAD_ALL);
1229 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1230 sync_parameters(CHANGE_EDL);
1234 void MWindow::swap_track_up(Track *track)
1237 edl->tracks->swap_track_up(track);
1239 undo_after(_("swap track up"), LOAD_ALL);
1241 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1242 sync_parameters(CHANGE_EDL);
1246 void MWindow::swap_tracks_up()
1249 edl->tracks->swap_tracks_up();
1251 undo_after(_("swap tracks up"), LOAD_ALL);
1253 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1254 sync_parameters(CHANGE_EDL);
1258 void MWindow::mute_selection()
1260 double start = edl->local_session->get_selectionstart();
1261 double end = edl->local_session->get_selectionend();
1262 if( start != end ) {
1264 edl->clear(start, end, 0,
1265 edl->session->plugins_follow_edits,
1266 edl->session->autos_follow_edits);
1267 edl->local_session->set_selectionend(end);
1268 edl->local_session->set_selectionstart(start);
1269 edl->paste_silence(start, end, 0,
1270 edl->session->plugins_follow_edits,
1271 edl->session->autos_follow_edits);
1274 undo_after(_("mute"), LOAD_EDITS);
1277 update_plugin_guis();
1278 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1279 cwindow->refresh_frame(CHANGE_EDL);
1284 void MWindow::overwrite(EDL *source, int all)
1288 LocalSession *src = source->local_session;
1289 double src_start = all ? 0 :
1290 src->inpoint_valid() ? src->get_inpoint() :
1291 src->outpoint_valid() ? 0 :
1292 src->get_selectionstart();
1293 double src_end = all ? source->tracks->total_length() :
1294 src->outpoint_valid() ? src->get_outpoint() :
1295 src->inpoint_valid() ? source->tracks->total_length() :
1296 src->get_selectionend();
1297 double overwrite_len = src_end - src_start;
1298 double dst_start = edl->local_session->get_selectionstart();
1299 double dst_len = edl->local_session->get_selectionend() - dst_start;
1302 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1303 // in/out points or selection present and shorter than overwrite range
1304 // shorten the copy range
1305 overwrite_len = dst_len;
1308 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1310 // HACK around paste_edl get_start/endselection on its own
1311 // so we need to clear only when not using both io points
1312 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1313 if( edl->local_session->get_inpoint() < 0 ||
1314 edl->local_session->get_outpoint() < 0 )
1315 edl->clear(dst_start, dst_start + overwrite_len,
1316 edl->session->labels_follow_edits,
1317 edl->session->plugins_follow_edits,
1318 edl->session->autos_follow_edits);
1320 paste(dst_start, dst_start + overwrite_len, &file,
1321 edl->session->labels_follow_edits,
1322 edl->session->plugins_follow_edits,
1323 edl->session->autos_follow_edits, 0, 0);
1325 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1326 edl->local_session->set_selectionend(dst_start + overwrite_len);
1329 undo_after(_("overwrite"), LOAD_EDITS);
1332 update_plugin_guis();
1333 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1334 sync_parameters(CHANGE_EDL);
1337 // For splice and overwrite
1338 int MWindow::paste(double start, double end, FileXML *file,
1339 int edit_labels, int edit_plugins, int edit_autos,
1340 Track *first_track, int overwrite)
1344 // Want to insert with assets shared with the master EDL.
1346 edit_labels, edit_plugins, edit_autos,
1347 edl, first_track, overwrite);
1352 // For editing using insertion point
1353 void MWindow::paste()
1355 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1358 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1360 //double end = edl->local_session->get_selectionend();
1361 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1364 char *string = new char[len];
1366 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1368 file.read_from_string(string);
1369 if( clear_selection ) clear(0);
1371 insert(start, &file,
1372 edl->session->labels_follow_edits,
1373 edl->session->plugins_follow_edits,
1374 edl->session->autos_follow_edits,
1375 0, first_track, overwrite);
1382 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1384 update_plugin_guis();
1385 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1386 awindow->gui->async_update_assets();
1387 sync_parameters(CHANGE_EDL);
1392 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1397 if( session->drag_assets->total ) {
1398 load_assets(session->drag_assets,
1399 position, LOADMODE_PASTE, dest_track, 0,
1400 edl->session->labels_follow_edits,
1401 edl->session->plugins_follow_edits,
1402 edl->session->autos_follow_edits,
1407 if( session->drag_clips->total ) {
1408 paste_edls(session->drag_clips,
1409 LOADMODE_PASTE, dest_track, position,
1410 edl->session->labels_follow_edits,
1411 edl->session->plugins_follow_edits,
1412 edl->session->autos_follow_edits,
1419 undo_after(_("paste assets"), LOAD_EDITS);
1421 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1422 sync_parameters(CHANGE_EDL);
1426 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1427 double position, int load_mode, Track *first_track, RecordLabels *labels,
1428 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1430 if( load_mode == LOADMODE_RESOURCESONLY )
1431 load_mode = LOADMODE_ASSETSONLY;
1432 const int debug = 0;
1433 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1435 position = edl->local_session->get_selectionstart();
1437 ArrayList<EDL*> new_edls;
1438 for( int i=0; i<new_assets->total; ++i ) {
1439 Indexable *indexable = new_assets->get(i);
1440 if( indexable->is_asset ) {
1441 remove_from_caches(indexable);
1443 EDL *new_edl = new EDL;
1444 new_edl->create_objects();
1445 new_edl->copy_session(edl);
1446 if( !indexable->is_asset ) {
1447 EDL *nested_edl = (EDL*)indexable;
1448 new_edl->create_nested(nested_edl);
1449 new_edl->set_path(indexable->path);
1452 Asset *asset = (Asset*)indexable;
1453 asset_to_edl(new_edl, asset);
1455 new_edls.append(new_edl);
1458 for( RecordLabel *label=labels->first; label; label=label->next ) {
1459 new_edl->labels->toggle_label(label->position, label->position);
1463 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1465 paste_edls(&new_edls, load_mode, first_track, position,
1466 edit_labels, edit_plugins, edit_autos, overwrite);
1467 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1470 for( int i=0; i<new_edls.size(); ++i )
1471 new_edls.get(i)->Garbage::remove_user();
1473 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1476 int MWindow::paste_automation()
1478 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1483 char *string = new char[len];
1484 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1486 file.read_from_string(string);
1488 double start = edl->local_session->get_selectionstart();
1489 double end = edl->local_session->get_selectionend();
1490 edl->tracks->clear_automation(start, end);
1491 edl->tracks->paste_automation(start, &file, 0, 1,
1492 edl->session->typeless_keyframes);
1493 int changed_edl = speed_after(1);
1495 undo_after(_("paste keyframes"),
1496 !changed_edl ? LOAD_AUTOMATION :
1497 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1498 update_gui(changed_edl);
1504 int MWindow::paste_default_keyframe()
1506 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1511 char *string = new char[len];
1512 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1514 file.read_from_string(string);
1516 double start = edl->local_session->get_selectionstart();
1517 edl->tracks->paste_automation(start, &file, 1, 0,
1518 edl->session->typeless_keyframes);
1519 // edl->tracks->paste_default_keyframe(&file);
1520 int changed_edl = speed_after(1);
1521 undo_after(_("paste default keyframe"),
1522 !changed_edl ? LOAD_AUTOMATION :
1523 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1525 update_gui(changed_edl);
1532 // Insert edls with project deletion and index file generation.
1533 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1534 Track *first_track, double current_position,
1535 int edit_labels, int edit_plugins, int edit_autos,
1539 ArrayList<Track*> destination_tracks;
1540 int need_new_tracks = 0;
1543 if( !new_edls->total ) return 0;
1546 // double original_length = edl->tracks->total_length();
1547 // double original_preview_end = edl->local_session->preview_end;
1550 // Delete current project
1551 if( load_mode == LOADMODE_REPLACE ||
1552 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1554 edl->save_defaults(defaults);
1556 edl->Garbage::remove_user();
1558 edl->create_objects();
1559 edl->copy_session(new_edls->values[0]);
1560 edl->copy_mixers(new_edls->values[0]);
1561 gui->mainmenu->update_toggles(0);
1562 gui->unlock_window();
1563 gwindow->gui->update_toggles(1);
1564 gui->lock_window("MWindow::paste_edls");
1566 // Insert labels for certain modes constitutively
1570 // Force reset of preview
1571 // original_length = 0;
1572 // original_preview_end = -1;
1578 // Create new tracks in master EDL
1579 if( load_mode == LOADMODE_REPLACE ||
1580 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1581 load_mode == LOADMODE_NEW_TRACKS ) {
1583 need_new_tracks = 1;
1584 for( int i=0; i<new_edls->total; ++i ) {
1585 EDL *new_edl = new_edls->values[i];
1586 int first_track = 1;
1587 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1588 switch( current->data_type ) {
1590 edl->tracks->add_video_track(0, 0);
1591 if( current->draw ) edl->tracks->last->draw = 1;
1594 edl->tracks->add_audio_track(0, 0);
1596 case TRACK_SUBTITLE:
1597 edl->tracks->add_subttl_track(0, 0);
1603 edl->tracks->last->master = 1;
1606 // re-label only if not already labeled
1607 if( new_edl->local_session->asset2edl )
1608 strcpy(current->title, edl->tracks->last->title);
1609 destination_tracks.append(edl->tracks->last);
1612 // Base track count on first EDL only for concatenation
1613 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1615 edl->session->highlighted_track = edl->tracks->total() - 1;
1618 // Recycle existing tracks of master EDL
1619 if( load_mode == LOADMODE_CONCATENATE ||
1620 load_mode == LOADMODE_PASTE ) {
1621 Track *current = first_track ? first_track : edl->tracks->first;
1622 for( ; current; current=NEXT ) {
1623 if( current->is_armed() ) {
1624 destination_tracks.append(current);
1630 int destination_track = 0;
1631 double *paste_position = new double[destination_tracks.total];
1633 // Iterate through the edls
1634 for( int i=0; i<new_edls->total; ++i ) {
1636 EDL *new_edl = new_edls->values[i];
1637 double edl_length = new_edl->local_session->clipboard_length ?
1638 new_edl->local_session->clipboard_length :
1639 new_edl->tracks->total_length();
1640 // printf("MWindow::paste_edls 2 %f %f\n",
1641 // new_edl->local_session->clipboard_length,
1642 // new_edl->tracks->total_length());
1646 // Convert EDL to master rates
1647 new_edl->resample(new_edl->session->sample_rate,
1648 edl->session->sample_rate,
1650 new_edl->resample(new_edl->session->frame_rate,
1651 edl->session->frame_rate,
1654 // Add assets and prepare index files
1655 for( Asset *new_asset=new_edl->assets->first;
1656 new_asset; new_asset=new_asset->next ) {
1657 mainindexes->add_indexable(new_asset);
1659 // Capture index file status from mainindex test
1660 edl->update_assets(new_edl);
1662 // Get starting point of insertion. Need this to paste labels.
1663 switch( load_mode ) {
1664 case LOADMODE_NOTHING:
1666 case LOADMODE_REPLACE:
1667 current_position = 0;
1669 case LOADMODE_NEW_TRACKS:
1671 current_position = 0;
1674 case LOADMODE_CONCATENATE:
1675 case LOADMODE_REPLACE_CONCATENATE:
1676 destination_track = 0;
1677 if( destination_tracks.total )
1678 current_position = destination_tracks.values[0]->get_length();
1680 current_position = 0;
1683 case LOADMODE_PASTE:
1684 destination_track = 0;
1686 for( int j=0; j<destination_tracks.total; ++j ) {
1687 paste_position[j] = (current_position >= 0) ?
1689 edl->local_session->get_selectionstart();
1694 case LOADMODE_RESOURCESONLY:
1695 edl->add_clip(new_edl);
1699 if( load_mode != LOADMODE_RESOURCESONLY &&
1700 load_mode != LOADMODE_ASSETSONLY ) {
1703 if( load_mode == LOADMODE_PASTE )
1704 edl->labels->insert_labels(new_edl->labels,
1705 destination_tracks.total ? paste_position[0] : 0.0,
1708 edl->labels->insert_labels(new_edl->labels, current_position,
1711 double total_length = new_edl->tracks->total_length();
1712 for( Track *new_track=new_edl->tracks->first;
1713 new_track; new_track=new_track->next ) {
1714 // Get destination track of same type as new_track
1716 k < destination_tracks.total &&
1717 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1718 ++k, ++destination_track ) {
1719 if( destination_track >= destination_tracks.total - 1 )
1720 destination_track = 0;
1723 // Insert data into destination track
1724 if( destination_track < destination_tracks.total &&
1725 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1726 Track *track = destination_tracks.values[destination_track];
1727 // Replace default keyframes if first EDL and new tracks were created.
1728 // This means data copied from one track and pasted to another won't retain
1729 // the camera position unless it's a keyframe. If it did, previous data in the
1730 // track might get unknowingly corrupted. Ideally we would detect when differing
1731 // default keyframes existed and create discrete keyframes for both.
1732 int replace_default = (i == 0) && need_new_tracks;
1733 // master tracks are the first track in each new edl when new tracks are created
1734 int master = track->master;
1735 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1736 // Insert new track at current position
1737 switch( load_mode ) {
1738 case LOADMODE_REPLACE_CONCATENATE:
1739 case LOADMODE_CONCATENATE:
1740 current_position = track->get_length();
1743 case LOADMODE_PASTE:
1744 current_position = paste_position[destination_track];
1745 paste_position[destination_track] += new_track->get_length();
1749 double length = overwrite >= 0 ?
1750 new_track->get_length() : total_length;
1751 track->clear(current_position,
1752 current_position + length,
1754 edit_labels, edit_plugins, edit_autos,
1758 track->insert_track(new_track, current_position, replace_default,
1759 edit_plugins, edit_autos, edl_length);
1760 if( master ) track->master = 1;
1764 // Get next destination track
1765 destination_track++;
1766 if( destination_track >= destination_tracks.total )
1767 destination_track = 0;
1771 if( load_mode == LOADMODE_PASTE )
1772 current_position += edl_length;
1776 // Move loading of clips and vwindow to the end - this fixes some
1777 // strange issue, for index not being shown
1778 // Assume any paste operation from the same EDL won't contain any clips.
1779 // If it did it would duplicate every clip here.
1780 for( int i=0; i<new_edls->total; ++i ) {
1781 EDL *new_edl = new_edls->get(i);
1783 for( int j=0; j<new_edl->clips.size(); ++j ) {
1784 edl->add_clip(new_edl->clips[j]);
1786 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1787 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1790 if( new_edl->total_vwindow_edls() ) {
1791 // if( edl->vwindow_edl )
1792 // edl->vwindow_edl->Garbage::remove_user();
1793 // edl->vwindow_edl = new EDL(edl);
1794 // edl->vwindow_edl->create_objects();
1795 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1797 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1798 EDL *vwindow_edl = new EDL(edl);
1799 vwindow_edl->create_objects();
1800 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1801 edl->append_vwindow_edl(vwindow_edl, 0);
1806 if( paste_position ) delete [] paste_position;
1808 // This is already done in load_filenames and everything else that uses paste_edls
1809 // update_project(load_mode);
1811 // Fix preview range
1812 // if( EQUIV(original_length, original_preview_end) )
1814 // edl->local_session->preview_end = edl->tracks->total_length();
1817 // Start examining next batch of index files
1818 mainindexes->start_build();
1820 // Don't save a backup after loading since the loaded file is on disk already.
1825 void MWindow::paste_silence()
1827 double start = edl->local_session->get_selectionstart();
1828 double end = edl->local_session->get_selectionend();
1829 if( EQUIV(start, end) ) {
1830 if( edl->session->frame_rate > 0 )
1831 end += 1./edl->session->frame_rate;
1833 undo_before(_("silence"), this);
1834 edl->paste_silence(start, end,
1835 edl->session->labels_follow_edits,
1836 edl->session->plugins_follow_edits,
1837 edl->session->autos_follow_edits);
1840 undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1842 update_plugin_guis();
1844 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1845 cwindow->update(1, 0, 0, 0, 1);
1846 cwindow->refresh_frame(CHANGE_EDL);
1849 void MWindow::detach_transition(Transition *transition)
1852 hide_plugin(transition, 1);
1853 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1854 transition->edit->detach_transition();
1856 undo_after(_("detach transition"), LOAD_ALL);
1858 if( is_video ) restart_brender();
1859 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1860 sync_parameters(CHANGE_EDL);
1863 void MWindow::detach_transitions()
1865 gui->lock_window("MWindow::detach_transitions 1");
1868 double start = edl->local_session->get_selectionstart();
1869 double end = edl->local_session->get_selectionend();
1870 edl->tracks->clear_transitions(start, end);
1873 undo_after(_("detach transitions"), LOAD_EDITS);
1875 sync_parameters(CHANGE_EDL);
1876 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1877 gui->unlock_window();
1880 void MWindow::paste_transition()
1882 // Only the first transition gets dropped.
1883 PluginServer *server = session->drag_pluginservers->values[0];
1886 edl->tracks->paste_transition(server, session->edit_highlighted);
1888 undo_after(_("transition"), LOAD_EDITS);
1890 if( server->video ) restart_brender();
1891 sync_parameters(CHANGE_ALL);
1894 void MWindow::paste_transitions(int track_type, char *title)
1896 gui->lock_window("MWindow::detach_transitions 1");
1899 double start = edl->local_session->get_selectionstart();
1900 double end = edl->local_session->get_selectionend();
1901 edl->tracks->paste_transitions(start, end, track_type, title);
1903 undo_after(_("attach transitions"), LOAD_EDITS);
1905 sync_parameters(CHANGE_EDL);
1906 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1907 gui->unlock_window();
1910 void MWindow::paste_transition_cwindow(Track *dest_track)
1912 PluginServer *server = session->drag_pluginservers->values[0];
1914 edl->tracks->paste_video_transition(server, 1);
1916 undo_after(_("transition"), LOAD_EDITS);
1918 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1919 sync_parameters(CHANGE_ALL);
1922 void MWindow::paste_audio_transition()
1924 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1927 char string[BCTEXTLEN];
1928 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1929 gui->show_message(string);
1934 edl->tracks->paste_audio_transition(server);
1936 undo_after(_("transition"), LOAD_EDITS);
1938 sync_parameters(CHANGE_EDL);
1939 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1942 void MWindow::paste_video_transition()
1944 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1947 char string[BCTEXTLEN];
1948 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1949 gui->show_message(string);
1955 edl->tracks->paste_video_transition(server);
1957 undo_after(_("transition"), LOAD_EDITS);
1959 sync_parameters(CHANGE_EDL);
1961 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1964 void MWindow::shuffle_edits()
1966 gui->lock_window("MWindow::shuffle_edits 1");
1969 double start = edl->local_session->get_selectionstart();
1970 double end = edl->local_session->get_selectionend();
1972 edl->tracks->shuffle_edits(start, end);
1975 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1977 sync_parameters(CHANGE_EDL);
1979 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1980 gui->unlock_window();
1983 void MWindow::reverse_edits()
1985 gui->lock_window("MWindow::reverse_edits 1");
1988 double start = edl->local_session->get_selectionstart();
1989 double end = edl->local_session->get_selectionend();
1991 edl->tracks->reverse_edits(start, end);
1994 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1996 sync_parameters(CHANGE_EDL);
1998 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1999 gui->unlock_window();
2002 void MWindow::align_edits()
2004 gui->lock_window("MWindow::align_edits 1");
2007 double start = edl->local_session->get_selectionstart();
2008 double end = edl->local_session->get_selectionend();
2010 edl->tracks->align_edits(start, end);
2013 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
2015 sync_parameters(CHANGE_EDL);
2017 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2018 gui->unlock_window();
2021 void MWindow::set_edit_length(double length)
2023 gui->lock_window("MWindow::set_edit_length 1");
2026 double start = edl->local_session->get_selectionstart();
2027 double end = edl->local_session->get_selectionend();
2029 edl->tracks->set_edit_length(start, end, length);
2032 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
2034 sync_parameters(CHANGE_EDL);
2036 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2037 gui->unlock_window();
2041 void MWindow::set_transition_length(Transition *transition, double length)
2043 gui->lock_window("MWindow::set_transition_length 1");
2046 //double start = edl->local_session->get_selectionstart();
2047 //double end = edl->local_session->get_selectionend();
2049 edl->tracks->set_transition_length(transition, length);
2052 undo_after(_("transition length"), LOAD_EDITS);
2054 edl->session->default_transition_length = length;
2055 sync_parameters(CHANGE_PARAMS);
2056 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2057 gui->unlock_window();
2060 void MWindow::set_transition_length(double length)
2062 gui->lock_window("MWindow::set_transition_length 2");
2065 double start = edl->local_session->get_selectionstart();
2066 double end = edl->local_session->get_selectionend();
2068 edl->tracks->set_transition_length(start, end, length);
2071 undo_after(_("transition length"), LOAD_EDITS);
2073 edl->session->default_transition_length = length;
2074 sync_parameters(CHANGE_PARAMS);
2076 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2077 gui->unlock_window();
2081 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2083 calling_window_gui->unlock_window();
2085 if( undo->redo_load_flags() & LOAD_SESSION )
2088 cwindow->gui->lock_window("MWindow::redo_entry 1");
2089 for( int i=0; i<vwindows.size(); ++i ) {
2090 if( vwindows.get(i)->is_running() ) {
2091 if( calling_window_gui != vwindows.get(i)->gui ) {
2092 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2096 gui->lock_window("MWindow::redo_entry 3");
2102 update_plugin_states();
2103 update_plugin_guis();
2105 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2106 gui->update_proxy_toggle();
2107 gui->unlock_window();
2108 cwindow->gui->unlock_window();
2109 cwindow->update(1, 1, 1, 1, 1);
2111 for( int i=0; i < vwindows.size(); ++i ) {
2112 if( vwindows.get(i)->is_running() ) {
2113 if( calling_window_gui != vwindows.get(i)->gui ) {
2114 vwindows.get(i)->gui->unlock_window();
2119 awindow->gui->async_update_assets();
2121 cwindow->refresh_frame(CHANGE_ALL);
2122 calling_window_gui->lock_window("MWindow::redo_entry 4");
2126 void MWindow::resize_track(Track *track, int w, int h)
2129 // We have to move all maskpoints so they do not move in relation to image areas
2130 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2131 (w - track->track_w) / 2,
2132 (h - track->track_h) / 2);
2135 undo_after(_("resize track"), LOAD_ALL);
2139 sync_parameters(CHANGE_EDL);
2143 void MWindow::set_inpoint()
2146 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2148 undo_after(_("in point"), LOAD_TIMEBAR);
2149 gui->update_timebar(1);
2151 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2152 cwindow->gui->timebar->update(1);
2153 cwindow->gui->unlock_window();
2156 void MWindow::set_outpoint()
2159 edl->set_outpoint(edl->local_session->get_selectionend(1));
2161 undo_after(_("out point"), LOAD_TIMEBAR);
2163 gui->update_timebar(1);
2164 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2165 cwindow->gui->timebar->update(1);
2166 cwindow->gui->unlock_window();
2169 void MWindow::unset_inoutpoint()
2172 edl->unset_inoutpoint();
2174 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2176 gui->update_timebar(1);
2177 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2178 cwindow->gui->timebar->update(1);
2179 cwindow->gui->unlock_window();
2182 void MWindow::splice(EDL *source, int all)
2185 LocalSession *src = source->local_session;
2188 double source_start = all ? 0 :
2189 src->inpoint_valid() ? src->get_inpoint() :
2190 src->outpoint_valid() ? 0 : src->get_selectionstart();
2191 double source_end = all ? source->tracks->total_length() :
2192 src->outpoint_valid() ? src->get_outpoint() :
2193 src->inpoint_valid() ? source->tracks->total_length() :
2194 src->get_selectionend();
2195 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2197 double start = edl->local_session->get_selectionstart();
2198 //double end = edl->local_session->get_selectionend();
2200 paste(start, start, &file,
2201 edl->session->labels_follow_edits,
2202 edl->session->plugins_follow_edits,
2203 edl->session->autos_follow_edits,
2206 // Position at end of clip
2207 edl->local_session->set_selectionstart(start + source_end - source_start);
2208 edl->local_session->set_selectionend(start + source_end - source_start);
2211 undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2212 update_plugin_guis();
2214 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2215 sync_parameters(CHANGE_EDL);
2218 void MWindow::save_clip(EDL *new_edl, const char *txt)
2220 new_edl->local_session->set_selectionstart(0);
2221 new_edl->local_session->set_selectionend(0);
2222 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2223 session->clip_number++);
2224 char duration[BCTEXTLEN];
2225 Units::totext(duration, new_edl->tracks->total_length(),
2226 new_edl->session->time_format,
2227 new_edl->session->sample_rate,
2228 new_edl->session->frame_rate,
2229 new_edl->session->frames_per_foot);
2231 Track *track = new_edl->tracks->first;
2232 const char *path = edl->path;
2233 for( ; (!path || !*path) && track; track=track->next ) {
2234 if( !track->is_armed() ) continue;
2235 Edit *edit = track->edits->first;
2236 if( !edit ) continue;
2237 Indexable *indexable = edit->get_source();
2238 if( !indexable ) continue;
2239 path = indexable->path;
2242 time_t now; time(&now);
2243 struct tm dtm; localtime_r(&now, &dtm);
2244 char *cp = new_edl->local_session->clip_notes;
2245 char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2247 cp += snprintf(cp, ep-cp, "%s", txt);
2248 cp += snprintf(cp, ep-cp,
2249 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2250 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2251 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2252 if( path && *path ) {
2254 char title[BCTEXTLEN];
2255 fs.extract_name(title, path);
2256 cp += snprintf(cp, ep-cp, "%s", title);
2258 sprintf(new_edl->local_session->clip_icon,
2259 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2260 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2261 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2263 new_edl->folder_no = AW_CLIP_FOLDER;
2264 edl->update_assets(new_edl);
2266 gui->get_abs_cursor(cur_x, cur_y, 0);
2267 gui->unlock_window();
2269 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2270 new_edl->remove_user();
2272 gui->lock_window("MWindow::save_clip");
2276 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2279 LocalSession *src = edl->local_session;
2281 gui->lock_window("MWindow::to_clip 1");
2282 double start = all ? 0 :
2283 src->inpoint_valid() ? src->get_inpoint() :
2284 src->outpoint_valid() ? 0 : src->get_selectionstart();
2285 double end = all ? edl->tracks->total_length() :
2286 src->outpoint_valid() ? src->get_outpoint() :
2287 src->inpoint_valid() ? edl->tracks->total_length() :
2288 src->get_selectionend();
2289 if( EQUIV(end, start) ) {
2291 end = edl->tracks->total_length();
2294 // Don't copy all since we don't want the clips twice.
2295 edl->copy(copy_flags(), start, end, &file, "", 1);
2297 EDL *new_edl = new EDL(edl);
2298 new_edl->create_objects();
2299 new_edl->load_xml(&file, LOAD_ALL);
2300 save_clip(new_edl, txt);
2301 gui->unlock_window();
2304 int MWindow::toggle_label()
2306 double position1, position2;
2309 position1 = edl->local_session->get_selectionstart(1);
2310 position2 = edl->local_session->get_selectionend(1);
2311 position1 = edl->align_to_frame(position1, 0);
2312 position2 = edl->align_to_frame(position2, 0);
2314 edl->labels->toggle_label(position1, position2);
2317 gui->update_timebar(0);
2318 gui->activate_timeline();
2321 cwindow->gui->lock_window("MWindow::toggle_label 2");
2322 cwindow->gui->timebar->update(1);
2323 cwindow->gui->unlock_window();
2324 awindow->gui->async_update_assets();
2326 undo_after(_("label"), LOAD_TIMEBAR);
2330 void MWindow::trim_selection()
2335 edl->trim_selection(edl->local_session->get_selectionstart(),
2336 edl->local_session->get_selectionend(),
2337 edl->session->labels_follow_edits,
2338 edl->session->plugins_follow_edits,
2339 edl->session->autos_follow_edits);
2342 undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2343 update_plugin_guis();
2344 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2345 cwindow->update(1, 0, 0, 0, 1);
2346 awindow->gui->async_update_assets();
2348 cwindow->refresh_frame(CHANGE_EDL);
2352 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2354 calling_window_gui->unlock_window();
2356 if( undo->undo_load_flags() & LOAD_SESSION )
2359 cwindow->gui->lock_window("MWindow::undo_entry 1");
2360 for( int i=0; i<vwindows.size(); ++i ) {
2361 if( vwindows.get(i)->is_running() ) {
2362 if( calling_window_gui != vwindows.get(i)->gui ) {
2363 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2367 gui->lock_window("MWindow::undo_entry 2");
2373 update_plugin_states();
2374 update_plugin_guis();
2376 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2377 gui->update_proxy_toggle();
2378 gui->unlock_window();
2379 cwindow->gui->unlock_window();
2380 cwindow->update(1, 1, 1, 1, 1);
2382 for( int i=0; i<vwindows.size(); ++i ) {
2383 if( vwindows.get(i)->is_running() ) {
2384 if( calling_window_gui != vwindows.get(i)->gui ) {
2385 vwindows.get(i)->gui->unlock_window();
2390 awindow->gui->async_update_assets();
2392 cwindow->refresh_frame(CHANGE_ALL);
2393 calling_window_gui->lock_window("MWindow::undo_entry 4");
2397 void MWindow::new_folder(const char *new_folder, int is_clips)
2400 if( edl->new_folder(new_folder, is_clips) ) {
2401 MainError::show_error(_("create new folder failed"));
2403 undo_after(_("new folder"), LOAD_ALL);
2404 awindow->gui->async_update_assets();
2407 void MWindow::delete_folder(char *folder)
2410 if( edl->delete_folder(folder) < 0 ) {
2411 MainError::show_error(_("delete folder failed"));
2413 undo_after(_("del folder"), LOAD_ALL);
2414 awindow->gui->async_update_assets();
2417 void MWindow::select_point(double position)
2419 gui->unlock_window();
2420 gui->stop_drawing();
2421 cwindow->stop_playback(0);
2422 gui->lock_window("MWindow::select_point");
2424 edl->local_session->set_selectionstart(position);
2425 edl->local_session->set_selectionend(position);
2428 cwindow->update(1, 0, 0, 0, 1);
2430 update_plugin_guis();
2431 gui->update_patchbay();
2432 gui->hide_cursor(0);
2433 gui->draw_cursor(0);
2434 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2435 gui->zoombar->update();
2436 gui->update_timebar(0);
2437 gui->flash_canvas(0);
2444 void MWindow::map_audio(int pattern)
2447 remap_audio(pattern);
2449 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2451 sync_parameters(CHANGE_PARAMS);
2452 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2455 void MWindow::remap_audio(int pattern)
2457 int current_channel = 0;
2458 int current_track = 0;
2459 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2460 if( current->data_type == TRACK_AUDIO &&
2461 current->is_armed() ) {
2462 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2463 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2465 for( int i=0; i < MAXCHANNELS; ++i ) {
2466 pan_auto->values[i] = 0.0;
2469 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2470 pan_auto->values[current_channel] = 1.0;
2473 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2474 switch( current_track ) {
2477 pan_auto->values[0] = 1;
2481 pan_auto->values[1] = 1;
2485 pan_auto->values[0] = 0.5;
2486 pan_auto->values[1] = 0.5;
2491 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2492 edl->session->achannel_positions, pan_auto->values,
2493 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2497 if( current_channel >= edl->session->audio_channels )
2498 current_channel = 0;
2504 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2506 edl->rescale_proxy(orig_scale, new_scale);
2509 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2511 edl->add_proxy(orig_assets, proxy_assets);
2514 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2515 float beep, int to_proxy, int remove_originals)
2517 if( !convert_render )
2518 convert_render = new ConvertRender(this);
2519 convert_render->set_format(format_asset, suffix, to_proxy);
2520 int found = convert_render->find_convertable_assets(edl);
2521 if( convert_render->needed_idxbls.size() > 0 )
2522 convert_render->start_convert(beep, remove_originals);
2523 else if( found > 0 )
2524 finish_convert(remove_originals);
2525 else if( found < 0 )
2526 eprintf(_("convert assets format error"));
2528 eprintf(_("No convertable assets found"));
2531 void MWindow::finish_convert(int remove_originals)
2533 gui->lock_window("MWindow::finish_convert");
2535 edl->replace_assets(
2536 convert_render->orig_idxbls,
2537 convert_render->orig_copies);
2538 if( remove_originals ) {
2539 remove_assets_from_project(0, 0, 0,
2540 &convert_render->orig_idxbls, 0);
2543 undo_after(_("convert"), LOAD_ALL);
2545 update_plugin_guis();
2546 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2547 cwindow->update(1, 0, 0, 0, 1);
2548 awindow->gui->async_update_assets();
2549 cwindow->refresh_frame(CHANGE_EDL);
2550 gui->unlock_window();
2553 void MWindow::cut_commercials()
2555 #ifdef HAVE_COMMERCIAL
2557 commercials->scan_media();
2560 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2563 update_plugin_guis();
2564 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2565 cwindow->update(1, 0, 0, 0, 1);
2566 cwindow->refresh_frame(CHANGE_EDL);
2570 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2573 Track *old_track = old_edl->tracks->first;
2574 Track *new_track = new_edl->tracks->first;
2575 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2576 if( old_track->data_type != new_track->data_type ) continue;
2577 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2578 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2579 if( !old_speeds || !new_speeds ) continue;
2580 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2581 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2582 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2583 old_speed = (FloatAuto *)old_speed->next;
2584 new_speed = (FloatAuto *)new_speed->next;
2586 Edit *old_edit = old_track->edits->first;
2587 Edit *new_edit = new_track->edits->first;
2588 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2589 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2590 if( old_speed || new_speed ) {
2591 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2592 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2593 edit_start = new_speeds->speed_position(orig_start);
2594 edit_end = new_speeds->speed_position(orig_end);
2597 new_edit->startproject = edit_start;
2598 new_edit->length = edit_end - edit_start;
2604 void MWindow::speed_before()
2607 speed_edl = new EDL;
2608 speed_edl->create_objects();
2610 speed_edl->copy_all(edl);
2613 int MWindow::speed_after(int done)
2618 result = normalize_speed(speed_edl, edl);
2620 speed_edl->remove_user();
2627 void MWindow::collect_effects()
2630 const char *file_string = "";
2632 int ret = edl->collect_effects(group);
2634 case COLLECT_EFFECTS_RECORD:
2635 eprintf(_("Selected edit track not armed."));
2637 case COLLECT_EFFECTS_MULTIPLE:
2638 eprintf(_("More than one edit selected on a track."));
2640 case COLLECT_EFFECTS_MISSING:
2641 eprintf(_("No effects under selected edit."));
2643 case COLLECT_EFFECTS_EMPTY:
2644 eprintf(_("No edits selected."));
2646 case COLLECT_EFFECTS_MASTER:
2647 eprintf(_("Shared effect added without master."));
2650 group->save_xml(&file, "");
2651 file_string = file.string();
2652 group->remove_user();
2654 long file_length = strlen(file_string);
2655 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2656 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2659 void MWindow::paste_effects()
2662 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2664 string = new char[len];
2665 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2667 if( !string || !string[0] ) {
2668 eprintf(_("Error clipboard buffer empty."));
2672 file.read_from_string(string);
2673 EDL *group = new EDL();
2674 group->create_objects();
2675 if( !group->load_xml(&file, LOAD_ALL) ) {
2677 int ret = edl->insert_effects(group);
2679 case INSERT_EFFECTS_RECORD:
2680 eprintf(_("Selected edit track not armed."));
2682 case INSERT_EFFECTS_TYPE:
2683 eprintf(_("Track type mismatched."));
2685 case INSERT_EFFECTS_MULTIPLE:
2686 eprintf(_("More than one edit selected on a track."));
2688 case INSERT_EFFECTS_MISSING:
2689 eprintf(_("Too few target edits to add group effects."));
2691 case INSERT_EFFECTS_EXTRA:
2692 eprintf(_("Too many target edits to add group effects."));
2694 case INSERT_EFFECTS_MASTER:
2695 eprintf(_("Shared effect added without master."));
2701 undo_after(_("paste effects"), LOAD_ALL);
2703 cwindow->refresh_frame(CHANGE_EDL);
2704 update_plugin_guis();
2705 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2708 eprintf(_("Error loading clip from clipboard buffer."));
2710 group->remove_user();
2713 void MWindow::align_timecodes()
2716 double offset = edl->tracks->align_timecodes();
2717 set_timecode_offset(offset);
2719 undo_after(_("align timecodes"), LOAD_ALL);
2721 cwindow->refresh_frame(CHANGE_EDL);
2722 update_plugin_guis();
2726 int MWindow::masters_to_mixers()
2728 Track *master_track = edl->tracks->first;
2729 while( master_track && !master_track->master )
2730 master_track = master_track->next;
2731 while( master_track ) { // test for track/mixer conflicts
2733 Track *mixer_last = master_track;
2734 Track *track = master_track->next;
2735 for( ; track && !track->master; track=track->next )
2737 Track *next_track = track;
2738 Mixer *master_mixer = 0;
2739 for( int i=0, n=edl->mixers.size(); i<n; ++i ) {
2740 if( master_track->index_in(edl->mixers[i]) >= 0 ) {
2741 master_mixer = edl->mixers[i];
2745 if( master_mixer ) { // existing mixer track group
2746 for( track=master_track; !failed && track; track=track->next ) {
2747 if( track->index_in(master_mixer) < 0 ) {
2748 eprintf("Mixer: %s missing track: %s",
2749 master_mixer->title, track->title);
2752 if( track == mixer_last ) break;
2754 for( int i=0, n=master_mixer->mixer_ids.size(); !failed && i<n; ++i ) {
2755 int mixer_id = master_mixer->mixer_ids[i], found = 0;
2756 for( track=master_track; track; track=track->next ) {
2757 if( track->mixer_id == mixer_id ) {
2761 if( track == mixer_last ) break;
2764 eprintf("Mixer: %s track missing: %s",
2765 master_mixer->title, track->title);
2770 else { // create mixer
2771 for( track=master_track->next; !failed && track; track=track->next ) {
2772 for( int i=0, n=edl->mixers.size(); !failed && i<n; ++i ) {
2773 Mixer *mixer = edl->mixers[i];
2774 if( track->index_in(mixer) >= 0 ) {
2775 eprintf("Track: %s already exists in mixer: %s",
2776 track->title, mixer->title);
2781 if( track == mixer_last ) break;
2783 if( !failed ) { // new mixer
2784 ZWindow *zwindow = get_mixer(master_mixer);
2785 zwindow->set_title(master_track->title);
2786 sprintf(master_track->title, _("Mixer %d"), zwindow->idx);
2787 for( track=master_track; track; track=track->next ) {
2788 track->play = track->armed = 0;
2789 master_mixer->mixer_ids.append(track->get_mixer_id());
2790 if( track == mixer_last ) break;
2795 master_track = next_track;
2800 void MWindow::mix_masters()
2803 masters_to_mixers();
2804 undo_after(_("mix masters"), LOAD_ALL);
2807 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
2808 gui->activate_timeline();
2809 cwindow->refresh_frame(CHANGE_EDL);