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"),
293 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
296 update_plugin_guis();
297 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
298 cwindow->update(1, 0, 0, 0, 1);
299 cwindow->refresh_frame(CHANGE_EDL);
302 void MWindow::clear(int clear_handle)
304 double start = edl->local_session->get_selectionstart();
305 double end = edl->local_session->get_selectionend();
306 if( clear_handle || !EQUIV(start, end) ) {
309 edl->session->labels_follow_edits,
310 edl->session->plugins_follow_edits,
311 edl->session->autos_follow_edits);
315 void MWindow::update_gui(int changed_edl)
318 update_plugin_guis();
320 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
321 cwindow->update(1, 0, 0, 0, 1);
322 cwindow->refresh_frame(CHANGE_EDL);
325 gui->draw_overlays(1);
326 sync_parameters(CHANGE_PARAMS);
327 gui->update_patchbay();
328 cwindow->update(1, 0, 0);
332 void MWindow::set_automation_mode(int mode)
336 edl->tracks->set_automation_mode(
337 edl->local_session->get_selectionstart(),
338 edl->local_session->get_selectionend(),
340 int changed_edl = speed_after(1, 1);
342 char string[BCSTRLEN];
343 sprintf(string,"set %s", FloatAuto::curve_name(mode));
345 !changed_edl ? LOAD_AUTOMATION :
346 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
347 update_gui(changed_edl);
350 void MWindow::clear_automation()
354 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
355 edl->local_session->get_selectionend());
356 int changed_edl = speed_after(1, 1);
358 undo_after(_("clear keyframes"),
359 !changed_edl ? LOAD_AUTOMATION :
360 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
361 update_gui(changed_edl);
364 int MWindow::clear_default_keyframe()
368 edl->tracks->clear_default_keyframe();
369 int changed_edl = speed_after(1, 1);
371 undo_after(_("clear default keyframe"),
372 !changed_edl ? LOAD_AUTOMATION :
373 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
374 update_gui(changed_edl);
378 void MWindow::clear_labels()
381 clear_labels(edl->local_session->get_selectionstart(),
382 edl->local_session->get_selectionend());
383 undo_after(_("clear labels"), LOAD_TIMEBAR);
385 gui->update_timebar(1);
386 cwindow->update(0, 0, 0, 0, 1);
390 int MWindow::clear_labels(double start, double end)
394 end = edl->tracks->total_length();
396 edl->labels->clear(start, end, 0);
400 void MWindow::clear_hard_edges()
403 clear_hard_edges(edl->local_session->get_selectionstart(),
404 edl->local_session->get_selectionend());
407 undo_after(_("clear hard edges"), LOAD_EDITS);
409 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
410 cwindow->refresh_frame(CHANGE_EDL);
413 int MWindow::clear_hard_edges(double start, double end)
417 end = edl->tracks->total_length();
419 edl->clear_hard_edges(start, end);
423 void MWindow::clear_select()
425 edl->tracks->clear_selected_edits();
426 gui->draw_overlays(1);
429 void MWindow::select_edits(int v)
431 double start = edl->local_session->get_selectionstart();
432 double end = edl->local_session->get_selectionend();
433 edl->tracks->select_edits(start, end, v);
434 gui->draw_overlays(1);
437 void MWindow::concatenate_tracks()
440 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
441 edl->session->autos_follow_edits);
443 undo_after(_("concatenate tracks"), LOAD_EDITS);
446 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
447 cwindow->refresh_frame(CHANGE_EDL);
451 int MWindow::copy_flags(int copy_flags)
453 if( !edl->session->labels_follow_edits )
454 copy_flags &= ~COPY_LABELS;
455 if( !edl->session->autos_follow_edits )
456 copy_flags &= ~COPY_AUTOS;
457 if( !edl->session->plugins_follow_edits )
458 copy_flags &= ~COPY_PLUGINS;
464 copy(edl->local_session->get_selectionstart(),
465 edl->local_session->get_selectionend());
468 int MWindow::copy(double start, double end)
470 if( start == end ) return 1;
473 edl->copy(copy_flags(), start, end, &file, "", 1);
474 const char *file_string = file.string();
475 long file_length = strlen(file_string);
476 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
477 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
482 int MWindow::copy_automation()
485 double start = edl->local_session->get_selectionstart();
486 double end = edl->local_session->get_selectionend();
487 edl->tracks->copy_automation(start, end, &file, 0, 1);
488 const char *file_string = file.string();
489 long file_length = strlen(file_string);
490 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
491 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
495 int MWindow::copy_default_keyframe()
498 double start = edl->local_session->get_selectionstart();
499 double end = edl->local_session->get_selectionend();
500 edl->tracks->copy_automation(start, end, &file, 1, 0);
501 const char *file_string = file.string();
502 long file_length = strlen(file_string);
503 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
504 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
508 // Uses cropping coordinates in edl session to crop and translate video.
509 // We modify the projector since camera automation depends on the track size.
510 void MWindow::crop_video(int mode)
513 // Clamp EDL crop region
514 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
515 edl->session->crop_x1 ^= edl->session->crop_x2;
516 edl->session->crop_x2 ^= edl->session->crop_x1;
517 edl->session->crop_x1 ^= edl->session->crop_x2;
519 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
520 edl->session->crop_y1 ^= edl->session->crop_y2;
521 edl->session->crop_y2 ^= edl->session->crop_y1;
522 edl->session->crop_y1 ^= edl->session->crop_y2;
525 case CROP_REFORMAT: {
526 float ctr_x = edl->session->output_w / 2.;
527 float ctr_y = edl->session->output_h / 2.;
528 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
529 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
530 float dx = -(new_x - ctr_x), dy = -(new_y - ctr_y);
531 edl->tracks->translate_projector(dx, dy, 1);
533 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
534 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
535 edl->session->crop_x1 = edl->session->crop_y1 = 0;
536 edl->session->crop_x2 = edl->session->output_w;
537 edl->session->crop_y2 = edl->session->output_h;
540 float old_w = edl->session->output_w;
541 float old_h = edl->session->output_h;
542 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
543 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
544 if( !new_w ) new_w = 1;
545 if( !new_h ) new_h = 1;
546 float xzoom = old_w / new_w, yzoom = old_h / new_h;
547 float new_z = bmin(xzoom, yzoom);
548 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
549 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
550 edl->tracks->crop_resize(new_x, new_y, new_z);
552 edl->session->crop_x1 = 0;
553 edl->session->crop_y1 = 0;
554 edl->session->crop_x2 = edl->session->output_w;
555 edl->session->crop_y2 = edl->session->output_h;
558 float old_w = edl->session->output_w;
559 float old_h = edl->session->output_h;
560 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
561 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
562 if( !new_w ) new_w = 1;
563 if( !new_h ) new_h = 1;
564 float xzoom = old_w / new_w, yzoom = old_h / new_h;
565 float new_z = bmin(xzoom, yzoom);
567 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
568 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
569 edl->tracks->crop_shrink(new_x, new_y, new_z);
573 // Recalculate aspect ratio
574 if( defaults->get("AUTOASPECT", 0) ) {
575 create_aspect_ratio(edl->session->aspect_w,
576 edl->session->aspect_h,
577 edl->session->output_w,
578 edl->session->output_h);
581 undo_after(_("crop"), LOAD_ALL);
584 cwindow->refresh_frame(CHANGE_ALL);
590 double start = edl->local_session->get_selectionstart();
591 double end = edl->local_session->get_selectionend();
592 if( EQUIV(start,end) )
598 void MWindow::blade(double position)
601 edl->blade(position);
604 undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
606 update_plugin_guis();
607 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
608 cwindow->update(1, 0, 0, 0, 1);
609 awindow->gui->async_update_assets();
610 cwindow->refresh_frame(CHANGE_EDL);
613 void MWindow::cut(double start, double end, double new_position)
617 edl->clear(start, end,
618 edl->session->labels_follow_edits,
619 edl->session->plugins_follow_edits,
620 edl->session->autos_follow_edits);
624 undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
625 if( new_position >= 0 ) {
626 edl->local_session->set_selectionstart(new_position);
627 edl->local_session->set_selectionend(new_position);
630 update_plugin_guis();
631 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
632 cwindow->update(1, 0, 0, 0, 1);
633 awindow->gui->async_update_assets();
634 cwindow->refresh_frame(CHANGE_EDL);
637 void MWindow::cut_left_edit()
639 double start_pos = edl->local_session->get_selectionstart(1);
640 double position = edl->prev_edit(start_pos);
641 if( position < start_pos )
642 cut(position, start_pos, position);
645 void MWindow::cut_right_edit()
647 double end_pos = edl->local_session->get_selectionend(1);
648 double position = edl->next_edit(end_pos);
649 if( end_pos < position )
650 cut(end_pos, position, end_pos);
653 void MWindow::cut_left_label()
655 double start_pos = edl->local_session->get_selectionstart(1);
656 Label *left_label = edl->labels->prev_label(start_pos);
657 if( !left_label ) return;
658 double position = left_label->position;
659 if( position < start_pos )
660 cut(position, start_pos, position);
663 void MWindow::cut_right_label()
665 double end_pos = edl->local_session->get_selectionend(1);
666 Label *right_label = edl->labels->next_label(end_pos);
667 if( !right_label ) return;
668 double position = right_label->position;
669 if( end_pos < position )
670 cut(end_pos, position, end_pos);
673 int MWindow::cut_automation()
678 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
679 edl->local_session->get_selectionend());
680 int changed_edl = speed_after(1, 1);
682 undo_after(_("cut keyframes"),
683 !changed_edl ? LOAD_AUTOMATION :
684 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
685 update_gui(changed_edl);
689 int MWindow::cut_default_keyframe()
694 copy_default_keyframe();
695 edl->tracks->clear_default_keyframe();
696 int changed_edl = speed_after(1, 1);
698 undo_after(_("cut default keyframe"),
699 !changed_edl ? LOAD_AUTOMATION :
700 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
701 update_gui(changed_edl);
706 void MWindow::delete_tracks()
709 edl->tracks->delete_tracks();
710 undo_after(_("delete tracks"), LOAD_ALL);
714 update_plugin_states();
716 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
717 cwindow->refresh_frame(CHANGE_EDL);
720 void MWindow::delete_track(Track *track)
723 edl->tracks->delete_track(track);
724 undo_after(_("delete track"), LOAD_ALL);
727 update_plugin_states();
729 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
730 cwindow->refresh_frame(CHANGE_EDL);
735 // Insert data from clipboard
736 void MWindow::insert(double position, FileXML *file,
737 int edit_labels, int edit_plugins, int edit_autos,
738 EDL *parent_edl, Track *first_track, int overwrite)
740 // For clipboard pasting make the new edl use a separate session
741 // from the master EDL. Then it can be resampled to the master rates.
742 // For splice, overwrite, and dragging need same session to get the assets.
743 EDL *edl = new EDL(parent_edl);
744 ArrayList<EDL*> new_edls;
745 uint32_t load_flags = LOAD_ALL;
748 new_edls.append(edl);
749 edl->create_objects();
754 if( parent_edl ) load_flags &= ~LOAD_SESSION;
755 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
756 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
758 edl->load_xml(file, load_flags);
761 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
765 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
766 edit_labels, edit_plugins, edit_autos, overwrite);
767 // if( vwindow->edl )
768 // printf("MWindow::insert 5 %f %f\n",
769 // vwindow->edl->local_session->in_point,
770 // vwindow->edl->local_session->out_point);
771 new_edls.remove_all();
772 edl->Garbage::remove_user();
773 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
776 void MWindow::insert_effects_canvas(Track *dest_track, double start, double length)
780 ArrayList<SharedLocation> shared_locations;
781 PluginSet *pluginset = session->pluginset_highlighted;
782 int gang = edl->local_session->gang_tracks != GANG_NONE ? 1 : 0;
783 int data_type = dest_track->data_type;
786 for( Track *track=dest_track; track; track=track->next ) {
787 if( gang && track->master && !first_track ) break;
788 if( track->data_type != data_type ) continue;
789 if( !track->is_armed() ) continue;
790 int module = edl->tracks->number_of(track);
791 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
792 PluginServer *plugin = session->drag_pluginservers->values[i];
793 int shared = gang; // && plugin->multichannel ? 1 : 0;
794 int plugin_type = !first_track && shared ?
795 PLUGIN_SHAREDPLUGIN : PLUGIN_STANDALONE;
796 SharedLocation *shared_location = !first_track ?
797 &shared_locations[i] : &shared_locations.append();
798 insert_effect(plugin->title, shared_location, track,
799 pluginset, start, length, plugin_type);
800 if( first_track && shared ) {
801 shared_location->module = module;
802 shared_location->plugin = pluginset ?
803 track->plugin_set.number_of(pluginset) :
804 track->plugin_set.total-1 ;
813 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
815 sync_parameters(CHANGE_EDL);
816 // GUI updated in TrackCanvas, after current_operations are reset
819 void MWindow::insert_effects_cwindow(Track *dest_track)
821 if( !dest_track ) return;
824 double length = dest_track->get_length();
826 if( edl->local_session->get_selectionend() >
827 edl->local_session->get_selectionstart() ) {
828 start = edl->local_session->get_selectionstart();
829 length = edl->local_session->get_selectionend() -
830 edl->local_session->get_selectionstart();
833 insert_effects_canvas(dest_track, start, length);
834 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
837 void MWindow::insert_effect(char *title, SharedLocation *shared_location,
838 int data_type, int plugin_type, int single_standalone)
840 Track *current = edl->tracks->first;
841 SharedLocation shared_location_local;
842 shared_location_local.copy_from(shared_location);
844 double start_pos = edl->local_session->get_selectionstart();
845 double end_pos = edl->local_session->get_selectionend();
846 for( ; current; current=NEXT ) {
847 if( current->data_type != data_type ) continue;
848 if( !current->is_armed() ) continue;
849 double start = start_pos, end = end_pos;
850 if( plugin_type == PLUGIN_STANDALONE && start >= end ) {
852 end = current->get_length();
854 double length = end - start;
855 insert_effect(title, &shared_location_local,
856 current, 0, start, length, plugin_type);
858 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
859 plugin_type = PLUGIN_SHAREDPLUGIN;
860 shared_location_local.module = edl->tracks->number_of(current);
861 shared_location_local.plugin = current->plugin_set.total - 1;
862 start_pos = start; end_pos = end;
869 void MWindow::insert_effect(char *title,
870 SharedLocation *shared_location, Track *track, PluginSet *plugin_set,
871 double start, double length, int plugin_type)
873 KeyFrame *default_keyframe = 0;
874 PluginServer *server = 0;
875 // Get default keyframe
876 if( plugin_type == PLUGIN_STANDALONE ) {
877 default_keyframe = new KeyFrame;
878 server = new PluginServer(*scan_plugindb(title, track->data_type));
880 server->open_plugin(0, preferences, edl, 0);
881 server->save_data(default_keyframe);
883 // Insert plugin object
884 track->insert_effect(title, shared_location, default_keyframe,
885 plugin_set, start, length, plugin_type);
888 if( plugin_type == PLUGIN_STANDALONE ) {
889 server->close_plugin();
891 delete default_keyframe;
895 int MWindow::modify_edithandles()
898 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
899 edl->modify_edithandles(session->drag_start,
900 session->drag_position, session->drag_handle, handle_mode,
901 edl->session->labels_follow_edits,
902 edl->session->plugins_follow_edits,
903 edl->session->autos_follow_edits,
904 session->drag_edit->group_id);
905 finish_modify_handles();
906 //printf("MWindow::modify_handles 1\n");
910 int MWindow::modify_pluginhandles()
914 edl->modify_pluginhandles(session->drag_start,
915 session->drag_position,
916 session->drag_handle,
917 edl->session->edit_handle_mode[session->drag_button],
918 edl->session->labels_follow_edits,
919 edl->session->autos_follow_edits,
920 session->trim_edits);
922 finish_modify_handles();
928 // Common to edithandles and plugin handles
929 void MWindow::finish_modify_handles()
931 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
932 double position = -1;
933 switch( edit_mode ) {
935 position = !session->drag_handle ?
936 session->drag_start : session->drag_position;
940 position = session->drag_position;
944 position = session->drag_start;
947 if( position >= 0 ) {
948 edl->local_session->set_selectionstart(position);
949 edl->local_session->set_selectionend(position);
951 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
955 sync_parameters(CHANGE_EDL);
956 update_plugin_guis();
957 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
958 // label list can be modified
959 awindow->gui->async_update_assets();
960 cwindow->update(1, 0, 0, 0, 1);
963 int MWindow::modify_transnhandles()
965 gui->reset_default_message();
966 gui->default_message();
967 Transition *transition = session->drag_transition;
968 if( !transition ) return 1;
969 int64_t length = transition->length;
970 Track *track = transition->edit->track;
971 int64_t start_pos = track->to_units(session->drag_start, 0);
972 int64_t end_pos = track->to_units(session->drag_position, 0);
973 length += end_pos - start_pos;
974 if( length < 0 ) length = 0;
975 if( length == transition->length ) return 0;
978 transition->length = length;
979 undo_after(_("trans handle"), LOAD_EDITS);
983 sync_parameters(CHANGE_EDL);
984 update_plugin_guis();
985 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
986 cwindow->update(1, 0, 0, 0, 1);
991 void MWindow::match_output_size(Track *track)
994 track->track_w = edl->session->output_w;
995 track->track_h = edl->session->output_h;
997 undo_after(_("match output size"), LOAD_ALL);
1000 sync_parameters(CHANGE_EDL);
1004 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
1006 ArrayList<Edit*> edits;
1008 delete_edits(&edits, msg, collapse);
1011 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
1013 if( !edits->size() ) return;
1015 if( edl->session->labels_follow_edits )
1016 edl->delete_edit_labels(edits, collapse);
1017 edl->delete_edits(edits, collapse);
1020 undo_after(msg, LOAD_EDITS);
1023 cwindow->refresh_frame(CHANGE_EDL);
1024 update_plugin_guis();
1025 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1028 void MWindow::delete_edits(int collapse)
1030 ArrayList<Edit*> edits;
1031 edl->tracks->get_selected_edits(&edits);
1032 delete_edits(&edits,_("del edit"), collapse);
1035 // collapse - delete from timeline, not collapse replace with silence
1036 // packed - omit unselected from selection, unpacked - replace unselected with silence
1037 void MWindow::cut_selected_edits(int collapse, int packed)
1039 selected_edits_to_clipboard(packed);
1040 ArrayList<Edit*> edits;
1041 edl->tracks->get_selected_edits(&edits);
1042 delete_edits(&edits, _("cut edit"), collapse);
1046 void MWindow::move_edits(ArrayList<Edit*> *edits,
1047 Track *track, double position, int mode)
1050 // lockout timebar labels update
1051 // labels can be deleted with tooltip repeater running
1052 cwindow->gui->lock_window("Tracks::move_edits");
1053 edl->tracks->move_edits(edits, track, position,
1054 edl->session->labels_follow_edits,
1055 edl->session->plugins_follow_edits,
1056 edl->session->autos_follow_edits, mode);
1057 cwindow->gui->timebar->update(1);
1058 cwindow->gui->unlock_window();
1061 undo_after(_("move edit"), LOAD_ALL);
1064 cwindow->refresh_frame(CHANGE_EDL);
1066 update_plugin_guis();
1067 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1070 void MWindow::selected_edits_to_clipboard(int packed)
1072 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1073 edl->session->labels_follow_edits,
1074 edl->session->autos_follow_edits,
1075 edl->session->plugins_follow_edits);
1076 if( !new_edl ) return;
1078 new_edl->copy(COPY_EDL, &file, "", 1);
1079 const char *file_string = file.string();
1080 long file_length = strlen(file_string);
1081 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1082 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1083 new_edl->remove_user();
1086 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1087 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1089 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1091 char *string = new char[len];
1092 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1094 file.read_from_string(string);
1096 EDL *clip = new EDL();
1097 clip->create_objects();
1098 if( !clip->load_xml(&file, LOAD_ALL) ) {
1100 edl->paste_edits(clip, first_track, position, overwrite,
1101 edit_edits, edit_labels, edit_autos, edit_plugins);
1103 undo_after(_("paste clip"), LOAD_ALL);
1105 cwindow->refresh_frame(CHANGE_EDL);
1107 update_plugin_guis();
1108 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1110 clip->remove_user();
1113 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1116 // lockout timebar labels update
1117 // labels can be deleted with tooltip repeater running
1118 cwindow->gui->lock_window("Tracks::move_group");
1120 ArrayList<Edit *>edits;
1121 edl->tracks->get_selected_edits(&edits);
1122 if( edl->session->labels_follow_edits )
1123 edl->delete_edit_labels(&edits, 0);
1124 edl->delete_edits(&edits, 0);
1125 edl->paste_edits(group, first_track, position, overwrite, 1,
1126 edl->session->labels_follow_edits,
1127 edl->session->autos_follow_edits,
1128 edl->session->plugins_follow_edits);
1129 cwindow->gui->timebar->update(1);
1130 cwindow->gui->unlock_window();
1131 // big debate over whether to do this, must either clear selected, or no tweaking
1132 // edl->tracks->clear_selected_edits();
1135 undo_after(_("move group"), LOAD_ALL);
1137 cwindow->refresh_frame(CHANGE_EDL);
1139 update_plugin_guis();
1140 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1143 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1146 edl->tracks->move_effect(plugin, track, position);
1148 undo_after(_("paste effect"), LOAD_ALL);
1151 cwindow->refresh_frame(CHANGE_EDL);
1152 update_plugin_guis();
1153 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1156 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1159 edl->tracks->move_effect(plugin, plugin_set, position);
1161 undo_after(_("move effect"), LOAD_ALL);
1164 cwindow->refresh_frame(CHANGE_EDL);
1165 update_plugin_guis();
1166 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1169 void MWindow::move_plugins_up(PluginSet *plugin_set)
1173 plugin_set->track->move_plugins_up(plugin_set);
1176 undo_after(_("move effect up"), LOAD_ALL);
1178 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1179 sync_parameters(CHANGE_EDL);
1182 void MWindow::move_plugins_down(PluginSet *plugin_set)
1186 plugin_set->track->move_plugins_down(plugin_set);
1189 undo_after(_("move effect down"), LOAD_ALL);
1191 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1192 sync_parameters(CHANGE_EDL);
1195 void MWindow::roll_track_down(Track *track)
1198 edl->tracks->roll_track_down(track);
1200 undo_after(_("move track down"), LOAD_ALL);
1203 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1204 sync_parameters(CHANGE_EDL);
1208 void MWindow::roll_tracks_down()
1211 edl->tracks->roll_tracks_down();
1213 undo_after(_("move tracks down"), LOAD_ALL);
1216 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1217 sync_parameters(CHANGE_EDL);
1221 void MWindow::roll_track_up(Track *track)
1224 edl->tracks->roll_track_up(track);
1226 undo_after(_("move track up"), LOAD_ALL);
1228 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1229 sync_parameters(CHANGE_EDL);
1233 void MWindow::roll_tracks_up()
1236 edl->tracks->roll_tracks_up();
1238 undo_after(_("move tracks up"), LOAD_ALL);
1240 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1241 sync_parameters(CHANGE_EDL);
1245 void MWindow::move_track_down(Track *track)
1248 edl->tracks->move_track_down(track);
1250 undo_after(_("swap track down"), LOAD_ALL);
1253 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1254 sync_parameters(CHANGE_EDL);
1258 void MWindow::move_tracks_down()
1261 edl->tracks->move_tracks_down();
1263 undo_after(_("swap tracks down"), LOAD_ALL);
1266 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1267 sync_parameters(CHANGE_EDL);
1271 void MWindow::move_track_up(Track *track)
1274 edl->tracks->move_track_up(track);
1276 undo_after(_("swap track up"), LOAD_ALL);
1278 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1279 sync_parameters(CHANGE_EDL);
1283 void MWindow::move_tracks_up()
1286 edl->tracks->move_tracks_up();
1288 undo_after(_("swap tracks up"), LOAD_ALL);
1290 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1291 sync_parameters(CHANGE_EDL);
1295 void MWindow::mute_selection()
1297 double start = edl->local_session->get_selectionstart();
1298 double end = edl->local_session->get_selectionend();
1299 if( start != end ) {
1301 edl->clear(start, end, 0,
1302 edl->session->plugins_follow_edits,
1303 edl->session->autos_follow_edits);
1304 edl->local_session->set_selectionend(end);
1305 edl->local_session->set_selectionstart(start);
1306 edl->paste_silence(start, end, 0,
1307 edl->session->plugins_follow_edits,
1308 edl->session->autos_follow_edits);
1311 undo_after(_("mute"), LOAD_EDITS);
1314 update_plugin_guis();
1315 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1316 cwindow->refresh_frame(CHANGE_EDL);
1321 void MWindow::overwrite(EDL *source, int all)
1325 LocalSession *src = source->local_session;
1326 double src_start = all ? 0 :
1327 src->inpoint_valid() ? src->get_inpoint() :
1328 src->outpoint_valid() ? 0 :
1329 src->get_selectionstart();
1330 double src_end = all ? source->tracks->total_length() :
1331 src->outpoint_valid() ? src->get_outpoint() :
1332 src->inpoint_valid() ? source->tracks->total_length() :
1333 src->get_selectionend();
1334 double overwrite_len = src_end - src_start;
1335 double dst_start = edl->local_session->get_selectionstart();
1336 double dst_len = edl->local_session->get_selectionend() - dst_start;
1339 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1340 // in/out points or selection present and shorter than overwrite range
1341 // shorten the copy range
1342 overwrite_len = dst_len;
1345 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1347 // HACK around paste_edl get_start/endselection on its own
1348 // so we need to clear only when not using both io points
1349 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1350 if( edl->local_session->get_inpoint() < 0 ||
1351 edl->local_session->get_outpoint() < 0 )
1352 edl->clear(dst_start, dst_start + overwrite_len,
1353 edl->session->labels_follow_edits,
1354 edl->session->plugins_follow_edits,
1355 edl->session->autos_follow_edits);
1357 paste(dst_start, dst_start + overwrite_len, &file,
1358 edl->session->labels_follow_edits,
1359 edl->session->plugins_follow_edits,
1360 edl->session->autos_follow_edits, 0, 0);
1362 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1363 edl->local_session->set_selectionend(dst_start + overwrite_len);
1366 undo_after(_("overwrite"),
1367 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1370 update_plugin_guis();
1371 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1372 sync_parameters(CHANGE_EDL);
1375 // For splice and overwrite
1376 int MWindow::paste(double start, double end, FileXML *file,
1377 int edit_labels, int edit_plugins, int edit_autos,
1378 Track *first_track, int overwrite)
1382 // Want to insert with assets shared with the master EDL.
1384 edit_labels, edit_plugins, edit_autos,
1385 edl, first_track, overwrite);
1390 // For editing using insertion point
1391 void MWindow::paste()
1393 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1396 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1398 //double end = edl->local_session->get_selectionend();
1399 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1402 char *string = new char[len];
1404 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1406 file.read_from_string(string);
1407 if( clear_selection ) clear(0);
1409 insert(start, &file,
1410 edl->session->labels_follow_edits,
1411 edl->session->plugins_follow_edits,
1412 edl->session->autos_follow_edits,
1413 0, first_track, overwrite);
1420 undo_after(_("paste"),
1421 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1423 update_plugin_guis();
1424 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1425 awindow->gui->async_update_assets();
1426 sync_parameters(CHANGE_EDL);
1431 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1436 if( session->drag_assets->total ) {
1437 load_assets(session->drag_assets,
1438 position, LOADMODE_PASTE, dest_track, 0,
1439 edl->session->labels_follow_edits,
1440 edl->session->plugins_follow_edits,
1441 edl->session->autos_follow_edits,
1446 if( session->drag_clips->total ) {
1447 paste_edls(session->drag_clips,
1448 LOADMODE_PASTE, dest_track, position,
1449 edl->session->labels_follow_edits,
1450 edl->session->plugins_follow_edits,
1451 edl->session->autos_follow_edits,
1458 undo_after(_("paste assets"),
1459 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1461 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1462 sync_parameters(CHANGE_EDL);
1466 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1467 double position, int load_mode, Track *first_track, RecordLabels *labels,
1468 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1470 if( load_mode == LOADMODE_RESOURCESONLY )
1471 load_mode = LOADMODE_ASSETSONLY;
1472 const int debug = 0;
1473 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1475 position = edl->local_session->get_selectionstart();
1477 ArrayList<EDL*> new_edls;
1478 for( int i=0; i<new_assets->total; ++i ) {
1479 Indexable *indexable = new_assets->get(i);
1480 if( indexable->is_asset ) {
1481 remove_from_caches(indexable);
1483 EDL *new_edl = new EDL;
1484 new_edl->create_objects();
1485 new_edl->copy_session(edl);
1486 if( !indexable->is_asset ) {
1487 EDL *nested_edl = (EDL*)indexable;
1488 new_edl->create_nested(nested_edl);
1489 new_edl->set_path(indexable->path);
1492 Asset *asset = (Asset*)indexable;
1493 asset_to_edl(new_edl, asset);
1495 new_edls.append(new_edl);
1498 for( RecordLabel *label=labels->first; label; label=label->next ) {
1499 new_edl->labels->toggle_label(label->position, label->position);
1503 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1505 paste_edls(&new_edls, load_mode, first_track, position,
1506 edit_labels, edit_plugins, edit_autos, overwrite);
1507 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1510 for( int i=0; i<new_edls.size(); ++i )
1511 new_edls.get(i)->Garbage::remove_user();
1513 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1516 int MWindow::paste_automation()
1518 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1523 char *string = new char[len];
1524 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1526 file.read_from_string(string);
1528 double start = edl->local_session->get_selectionstart();
1529 double end = edl->local_session->get_selectionend();
1530 edl->tracks->clear_automation(start, end);
1531 edl->tracks->paste_automation(start, &file, 0, 1,
1532 edl->session->typeless_keyframes);
1533 int changed_edl = speed_after(1, 0);
1535 undo_after(_("paste keyframes"),
1536 !changed_edl ? LOAD_AUTOMATION :
1537 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1538 update_gui(changed_edl);
1544 int MWindow::paste_default_keyframe()
1546 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1551 char *string = new char[len];
1552 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1554 file.read_from_string(string);
1556 double start = edl->local_session->get_selectionstart();
1557 edl->tracks->paste_automation(start, &file, 1, 0,
1558 edl->session->typeless_keyframes);
1559 // edl->tracks->paste_default_keyframe(&file);
1560 int changed_edl = speed_after(1, 1);
1561 undo_after(_("paste default keyframe"),
1562 !changed_edl ? LOAD_AUTOMATION :
1563 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1565 update_gui(changed_edl);
1572 // Insert edls with project deletion and index file generation.
1573 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1574 Track *first_track, double current_position,
1575 int edit_labels, int edit_plugins, int edit_autos,
1579 ArrayList<Track*> destination_tracks;
1580 int need_new_tracks = 0;
1583 if( !new_edls->total ) return 0;
1586 // double original_length = edl->tracks->total_length();
1587 // double original_preview_end = edl->local_session->preview_end;
1590 // Delete current project
1591 if( load_mode == LOADMODE_REPLACE ||
1592 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1594 edl->save_defaults(defaults);
1596 edl->Garbage::remove_user();
1598 edl->create_objects();
1599 edl->copy_session(new_edls->values[0]);
1600 edl->copy_mixers(new_edls->values[0]);
1601 gui->mainmenu->update_toggles(0);
1602 gui->unlock_window();
1603 gwindow->gui->update_toggles(1);
1604 gui->lock_window("MWindow::paste_edls");
1606 // Insert labels for certain modes constitutively
1610 // Force reset of preview
1611 // original_length = 0;
1612 // original_preview_end = -1;
1618 // Create new tracks in master EDL
1619 if( load_mode == LOADMODE_REPLACE ||
1620 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1621 load_mode == LOADMODE_NEW_TRACKS ) {
1623 need_new_tracks = 1;
1624 for( int i=0; i<new_edls->total; ++i ) {
1625 EDL *new_edl = new_edls->values[i];
1626 int first_track = 1;
1627 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1628 switch( current->data_type ) {
1630 edl->tracks->add_video_track(0, 0);
1631 if( current->draw ) edl->tracks->last->draw = 1;
1634 edl->tracks->add_audio_track(0, 0);
1636 case TRACK_SUBTITLE:
1637 edl->tracks->add_subttl_track(0, 0);
1643 edl->tracks->last->master = 1;
1646 // re-label only if not already labeled
1647 if( new_edl->local_session->asset2edl )
1648 strcpy(current->title, edl->tracks->last->title);
1649 destination_tracks.append(edl->tracks->last);
1652 // Base track count on first EDL only for concatenation
1653 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1655 edl->session->highlighted_track = edl->tracks->total() - 1;
1658 // Recycle existing tracks of master EDL
1659 if( load_mode == LOADMODE_CONCATENATE ||
1660 load_mode == LOADMODE_PASTE ) {
1661 Track *current = first_track ? first_track : edl->tracks->first;
1662 for( ; current; current=NEXT ) {
1663 if( current->is_armed() ) {
1664 destination_tracks.append(current);
1670 int destination_track = 0;
1671 double *paste_position = new double[destination_tracks.total];
1673 // Iterate through the edls
1674 for( int i=0; i<new_edls->total; ++i ) {
1676 EDL *new_edl = new_edls->values[i];
1677 double edl_length = new_edl->local_session->clipboard_length ?
1678 new_edl->local_session->clipboard_length :
1679 new_edl->tracks->total_length();
1680 // printf("MWindow::paste_edls 2 %f %f\n",
1681 // new_edl->local_session->clipboard_length,
1682 // new_edl->tracks->total_length());
1686 // Convert EDL to master rates
1687 new_edl->resample(new_edl->session->sample_rate,
1688 edl->session->sample_rate,
1690 new_edl->resample(new_edl->session->frame_rate,
1691 edl->session->frame_rate,
1694 // Add assets and prepare index files
1695 for( Asset *new_asset=new_edl->assets->first;
1696 new_asset; new_asset=new_asset->next ) {
1697 mainindexes->add_indexable(new_asset);
1699 // Capture index file status from mainindex test
1700 edl->update_assets(new_edl);
1702 // Get starting point of insertion. Need this to paste labels.
1703 switch( load_mode ) {
1704 case LOADMODE_NOTHING:
1706 case LOADMODE_REPLACE:
1707 current_position = 0;
1709 case LOADMODE_NEW_TRACKS:
1711 current_position = 0;
1714 case LOADMODE_CONCATENATE:
1715 case LOADMODE_REPLACE_CONCATENATE:
1716 destination_track = 0;
1717 if( destination_tracks.total )
1718 current_position = destination_tracks.values[0]->get_length();
1720 current_position = 0;
1723 case LOADMODE_PASTE:
1724 destination_track = 0;
1726 for( int j=0; j<destination_tracks.total; ++j ) {
1727 paste_position[j] = (current_position >= 0) ?
1729 edl->local_session->get_selectionstart();
1734 case LOADMODE_RESOURCESONLY:
1735 edl->add_clip(new_edl);
1739 if( load_mode != LOADMODE_RESOURCESONLY &&
1740 load_mode != LOADMODE_ASSETSONLY ) {
1743 if( load_mode == LOADMODE_PASTE )
1744 edl->labels->insert_labels(new_edl->labels,
1745 destination_tracks.total ? paste_position[0] : 0.0,
1748 edl->labels->insert_labels(new_edl->labels, current_position,
1751 double total_length = new_edl->tracks->total_length();
1752 for( Track *new_track=new_edl->tracks->first;
1753 new_track; new_track=new_track->next ) {
1754 // Get destination track of same type as new_track
1756 k < destination_tracks.total &&
1757 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1758 ++k, ++destination_track ) {
1759 if( destination_track >= destination_tracks.total - 1 )
1760 destination_track = 0;
1763 // Insert data into destination track
1764 if( destination_track < destination_tracks.total &&
1765 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1766 Track *track = destination_tracks.values[destination_track];
1767 // Replace default keyframes if first EDL and new tracks were created.
1768 // This means data copied from one track and pasted to another won't retain
1769 // the camera position unless it's a keyframe. If it did, previous data in the
1770 // track might get unknowingly corrupted. Ideally we would detect when differing
1771 // default keyframes existed and create discrete keyframes for both.
1772 int replace_default = (i == 0) && need_new_tracks;
1773 // master tracks are the first track in each new edl when new tracks are created
1774 int master = track->master;
1775 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1776 // Insert new track at current position
1777 switch( load_mode ) {
1778 case LOADMODE_REPLACE_CONCATENATE:
1779 case LOADMODE_CONCATENATE:
1780 current_position = track->get_length();
1783 case LOADMODE_PASTE:
1784 current_position = paste_position[destination_track];
1785 paste_position[destination_track] += new_track->get_length();
1789 double length = overwrite >= 0 ?
1790 new_track->get_length() : total_length;
1791 track->clear(current_position,
1792 current_position + length,
1794 edit_labels, edit_plugins, edit_autos,
1798 track->insert_track(new_track, current_position, replace_default,
1799 edit_plugins, edit_autos, edl_length);
1800 if( master ) track->master = 1;
1804 // Get next destination track
1805 destination_track++;
1806 if( destination_track >= destination_tracks.total )
1807 destination_track = 0;
1811 if( load_mode == LOADMODE_PASTE )
1812 current_position += edl_length;
1816 // Move loading of clips and vwindow to the end - this fixes some
1817 // strange issue, for index not being shown
1818 // Assume any paste operation from the same EDL won't contain any clips.
1819 // If it did it would duplicate every clip here.
1820 for( int i=0; i<new_edls->total; ++i ) {
1821 EDL *new_edl = new_edls->get(i);
1823 for( int j=0; j<new_edl->clips.size(); ++j ) {
1824 edl->add_clip(new_edl->clips[j]);
1826 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1827 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1830 if( new_edl->total_vwindow_edls() ) {
1831 // if( edl->vwindow_edl )
1832 // edl->vwindow_edl->Garbage::remove_user();
1833 // edl->vwindow_edl = new EDL(edl);
1834 // edl->vwindow_edl->create_objects();
1835 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1837 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1838 EDL *vwindow_edl = new EDL(edl);
1839 vwindow_edl->create_objects();
1840 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1841 edl->append_vwindow_edl(vwindow_edl, 0);
1846 if( paste_position ) delete [] paste_position;
1848 // This is already done in load_filenames and everything else that uses paste_edls
1849 // update_project(load_mode);
1851 // Fix preview range
1852 // if( EQUIV(original_length, original_preview_end) )
1854 // edl->local_session->preview_end = edl->tracks->total_length();
1857 // Start examining next batch of index files
1858 mainindexes->start_build();
1860 // Don't save a backup after loading since the loaded file is on disk already.
1865 void MWindow::paste_silence()
1867 double start = edl->local_session->get_selectionstart();
1868 double end = edl->local_session->get_selectionend();
1869 if( EQUIV(start, end) ) {
1870 if( edl->session->frame_rate > 0 )
1871 end += 1./edl->session->frame_rate;
1873 undo_before(_("silence"), this);
1874 edl->paste_silence(start, end,
1875 edl->session->labels_follow_edits,
1876 edl->session->plugins_follow_edits,
1877 edl->session->autos_follow_edits);
1880 undo_after(_("silence"),
1881 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1883 update_plugin_guis();
1885 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1886 cwindow->update(1, 0, 0, 0, 1);
1887 cwindow->refresh_frame(CHANGE_EDL);
1890 void MWindow::detach_transition(Transition *transition)
1893 hide_plugin(transition, 1);
1894 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1895 transition->edit->detach_transition();
1897 undo_after(_("detach transition"), LOAD_ALL);
1899 if( is_video ) restart_brender();
1900 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1901 sync_parameters(CHANGE_EDL);
1904 void MWindow::detach_transitions()
1906 gui->lock_window("MWindow::detach_transitions 1");
1909 double start = edl->local_session->get_selectionstart();
1910 double end = edl->local_session->get_selectionend();
1911 edl->tracks->clear_transitions(start, end);
1914 undo_after(_("detach transitions"), LOAD_EDITS);
1916 sync_parameters(CHANGE_EDL);
1917 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1918 gui->unlock_window();
1921 void MWindow::paste_transition()
1923 // Only the first transition gets dropped.
1924 PluginServer *server = session->drag_pluginservers->values[0];
1927 edl->tracks->paste_transition(server, session->edit_highlighted);
1929 undo_after(_("transition"), LOAD_EDITS);
1931 if( server->video ) restart_brender();
1932 sync_parameters(CHANGE_ALL);
1935 void MWindow::paste_transitions(int track_type, char *title)
1937 gui->lock_window("MWindow::detach_transitions 1");
1940 double start = edl->local_session->get_selectionstart();
1941 double end = edl->local_session->get_selectionend();
1942 edl->tracks->paste_transitions(start, end, track_type, title);
1944 undo_after(_("attach transitions"), LOAD_EDITS);
1946 sync_parameters(CHANGE_EDL);
1947 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1948 gui->unlock_window();
1951 void MWindow::paste_transition_cwindow(Track *dest_track)
1953 PluginServer *server = session->drag_pluginservers->values[0];
1955 edl->tracks->paste_video_transition(server, 1);
1957 undo_after(_("transition"), LOAD_EDITS);
1959 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1960 sync_parameters(CHANGE_ALL);
1963 void MWindow::paste_audio_transition()
1965 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1968 char string[BCTEXTLEN];
1969 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1970 gui->show_message(string);
1975 edl->tracks->paste_audio_transition(server);
1977 undo_after(_("transition"), LOAD_EDITS);
1979 sync_parameters(CHANGE_EDL);
1980 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1983 void MWindow::paste_video_transition()
1985 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1988 char string[BCTEXTLEN];
1989 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1990 gui->show_message(string);
1996 edl->tracks->paste_video_transition(server);
1998 undo_after(_("transition"), LOAD_EDITS);
2000 sync_parameters(CHANGE_EDL);
2002 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2005 void MWindow::shuffle_edits()
2007 gui->lock_window("MWindow::shuffle_edits 1");
2010 double start = edl->local_session->get_selectionstart();
2011 double end = edl->local_session->get_selectionend();
2013 edl->tracks->shuffle_edits(start, end);
2016 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
2018 sync_parameters(CHANGE_EDL);
2020 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2021 gui->unlock_window();
2024 void MWindow::reverse_edits()
2026 gui->lock_window("MWindow::reverse_edits 1");
2029 double start = edl->local_session->get_selectionstart();
2030 double end = edl->local_session->get_selectionend();
2032 edl->tracks->reverse_edits(start, end);
2035 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
2037 sync_parameters(CHANGE_EDL);
2039 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2040 gui->unlock_window();
2043 void MWindow::align_edits()
2045 gui->lock_window("MWindow::align_edits 1");
2048 double start = edl->local_session->get_selectionstart();
2049 double end = edl->local_session->get_selectionend();
2051 edl->tracks->align_edits(start, end);
2054 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
2056 sync_parameters(CHANGE_EDL);
2058 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2059 gui->unlock_window();
2062 void MWindow::set_edit_length(double length)
2064 gui->lock_window("MWindow::set_edit_length 1");
2067 double start = edl->local_session->get_selectionstart();
2068 double end = edl->local_session->get_selectionend();
2070 edl->tracks->set_edit_length(start, end, length);
2073 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
2075 sync_parameters(CHANGE_EDL);
2077 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2078 gui->unlock_window();
2082 void MWindow::set_transition_length(Transition *transition, double length)
2084 gui->lock_window("MWindow::set_transition_length 1");
2087 //double start = edl->local_session->get_selectionstart();
2088 //double end = edl->local_session->get_selectionend();
2090 edl->tracks->set_transition_length(transition, length);
2093 undo_after(_("transition length"), LOAD_EDITS);
2095 edl->session->default_transition_length = length;
2096 sync_parameters(CHANGE_PARAMS);
2097 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2098 gui->unlock_window();
2101 void MWindow::set_transition_length(double length)
2103 gui->lock_window("MWindow::set_transition_length 2");
2106 double start = edl->local_session->get_selectionstart();
2107 double end = edl->local_session->get_selectionend();
2109 edl->tracks->set_transition_length(start, end, length);
2112 undo_after(_("transition length"), LOAD_EDITS);
2114 edl->session->default_transition_length = length;
2115 sync_parameters(CHANGE_PARAMS);
2117 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2118 gui->unlock_window();
2122 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2124 calling_window_gui->unlock_window();
2126 if( undo->redo_load_flags() & LOAD_SESSION )
2129 cwindow->gui->lock_window("MWindow::redo_entry 1");
2130 for( int i=0; i<vwindows.size(); ++i ) {
2131 if( vwindows.get(i)->is_running() ) {
2132 if( calling_window_gui != vwindows.get(i)->gui ) {
2133 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2137 gui->lock_window("MWindow::redo_entry 3");
2143 update_plugin_states();
2144 update_plugin_guis();
2146 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2147 gui->update_proxy_toggle();
2148 gui->unlock_window();
2149 cwindow->gui->unlock_window();
2150 cwindow->update(1, 1, 1, 1, 1);
2152 for( int i=0; i < vwindows.size(); ++i ) {
2153 if( vwindows.get(i)->is_running() ) {
2154 if( calling_window_gui != vwindows.get(i)->gui ) {
2155 vwindows.get(i)->gui->unlock_window();
2160 awindow->gui->async_update_assets();
2162 cwindow->refresh_frame(CHANGE_ALL);
2163 calling_window_gui->lock_window("MWindow::redo_entry 4");
2167 void MWindow::resize_track(Track *track, int w, int h)
2170 // We have to move all maskpoints so they do not move in relation to image areas
2171 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2172 (w - track->track_w) / 2,
2173 (h - track->track_h) / 2);
2176 undo_after(_("resize track"), LOAD_ALL);
2180 sync_parameters(CHANGE_EDL);
2184 void MWindow::set_inpoint()
2187 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2189 undo_after(_("in point"), LOAD_TIMEBAR);
2190 gui->update_timebar(1);
2192 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2193 cwindow->gui->timebar->update(1);
2194 cwindow->gui->unlock_window();
2197 void MWindow::set_outpoint()
2200 edl->set_outpoint(edl->local_session->get_selectionend(1));
2202 undo_after(_("out point"), LOAD_TIMEBAR);
2204 gui->update_timebar(1);
2205 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2206 cwindow->gui->timebar->update(1);
2207 cwindow->gui->unlock_window();
2210 void MWindow::unset_inoutpoint()
2213 edl->unset_inoutpoint();
2215 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2217 gui->update_timebar(1);
2218 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2219 cwindow->gui->timebar->update(1);
2220 cwindow->gui->unlock_window();
2223 void MWindow::splice(EDL *source, int all)
2226 LocalSession *src = source->local_session;
2229 double source_start = all ? 0 :
2230 src->inpoint_valid() ? src->get_inpoint() :
2231 src->outpoint_valid() ? 0 : src->get_selectionstart();
2232 double source_end = all ? source->tracks->total_length() :
2233 src->outpoint_valid() ? src->get_outpoint() :
2234 src->inpoint_valid() ? source->tracks->total_length() :
2235 src->get_selectionend();
2236 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2238 double start = edl->local_session->get_selectionstart();
2239 //double end = edl->local_session->get_selectionend();
2241 paste(start, start, &file,
2242 edl->session->labels_follow_edits,
2243 edl->session->plugins_follow_edits,
2244 edl->session->autos_follow_edits,
2247 // Position at end of clip
2248 edl->local_session->set_selectionstart(start + source_end - source_start);
2249 edl->local_session->set_selectionend(start + source_end - source_start);
2252 undo_after(_("splice"),
2253 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
2254 update_plugin_guis();
2256 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2257 sync_parameters(CHANGE_EDL);
2260 void MWindow::save_clip(EDL *new_edl, const char *txt)
2262 new_edl->local_session->set_selectionstart(0);
2263 new_edl->local_session->set_selectionend(0);
2264 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2265 session->clip_number++);
2266 char duration[BCTEXTLEN];
2267 Units::totext(duration, new_edl->tracks->total_length(),
2268 new_edl->session->time_format,
2269 new_edl->session->sample_rate,
2270 new_edl->session->frame_rate,
2271 new_edl->session->frames_per_foot);
2273 Track *track = new_edl->tracks->first;
2274 const char *path = edl->path;
2275 for( ; (!path || !*path) && track; track=track->next ) {
2276 if( !track->is_armed() ) continue;
2277 Edit *edit = track->edits->first;
2278 if( !edit ) continue;
2279 Indexable *indexable = edit->get_source();
2280 if( !indexable ) continue;
2281 path = indexable->path;
2284 time_t now; time(&now);
2285 struct tm dtm; localtime_r(&now, &dtm);
2286 char *cp = new_edl->local_session->clip_notes;
2287 char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2289 cp += snprintf(cp, ep-cp, "%s", txt);
2290 cp += snprintf(cp, ep-cp,
2291 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2292 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2293 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2294 if( path && *path ) {
2296 char title[BCTEXTLEN];
2297 fs.extract_name(title, path);
2298 cp += snprintf(cp, ep-cp, "%s", title);
2300 sprintf(new_edl->local_session->clip_icon,
2301 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2302 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2303 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2305 new_edl->folder_no = AW_CLIP_FOLDER;
2306 edl->update_assets(new_edl);
2308 gui->get_abs_cursor(cur_x, cur_y, 0);
2309 gui->unlock_window();
2311 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2312 new_edl->remove_user();
2314 gui->lock_window("MWindow::save_clip");
2318 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2321 LocalSession *src = edl->local_session;
2323 gui->lock_window("MWindow::to_clip 1");
2324 double start = all ? 0 :
2325 src->inpoint_valid() ? src->get_inpoint() :
2326 src->outpoint_valid() ? 0 : src->get_selectionstart();
2327 double end = all ? edl->tracks->total_length() :
2328 src->outpoint_valid() ? src->get_outpoint() :
2329 src->inpoint_valid() ? edl->tracks->total_length() :
2330 src->get_selectionend();
2331 if( EQUIV(end, start) ) {
2333 end = edl->tracks->total_length();
2336 // Don't copy all since we don't want the clips twice.
2337 edl->copy(copy_flags(), start, end, &file, "", 1);
2339 EDL *new_edl = new EDL(edl);
2340 new_edl->create_objects();
2341 new_edl->load_xml(&file, LOAD_ALL);
2342 save_clip(new_edl, txt);
2343 gui->unlock_window();
2346 int MWindow::toggle_label()
2348 double position1, position2;
2351 position1 = edl->local_session->get_selectionstart(1);
2352 position2 = edl->local_session->get_selectionend(1);
2353 position1 = edl->align_to_frame(position1, 0);
2354 position2 = edl->align_to_frame(position2, 0);
2356 edl->labels->toggle_label(position1, position2);
2359 gui->update_timebar(0);
2360 gui->activate_timeline();
2363 cwindow->gui->lock_window("MWindow::toggle_label 2");
2364 cwindow->gui->timebar->update(1);
2365 cwindow->gui->unlock_window();
2366 awindow->gui->async_update_assets();
2368 undo_after(_("label"), LOAD_TIMEBAR);
2372 void MWindow::trim_selection()
2377 edl->trim_selection(edl->local_session->get_selectionstart(),
2378 edl->local_session->get_selectionend(),
2379 edl->session->labels_follow_edits,
2380 edl->session->plugins_follow_edits,
2381 edl->session->autos_follow_edits);
2384 undo_after(_("trim selection"),
2385 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
2386 update_plugin_guis();
2387 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2388 cwindow->update(1, 0, 0, 0, 1);
2389 awindow->gui->async_update_assets();
2391 cwindow->refresh_frame(CHANGE_EDL);
2395 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2397 calling_window_gui->unlock_window();
2399 if( undo->undo_load_flags() & LOAD_SESSION )
2402 cwindow->gui->lock_window("MWindow::undo_entry 1");
2403 for( int i=0; i<vwindows.size(); ++i ) {
2404 if( vwindows.get(i)->is_running() ) {
2405 if( calling_window_gui != vwindows.get(i)->gui ) {
2406 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2410 gui->lock_window("MWindow::undo_entry 2");
2416 update_plugin_states();
2417 update_plugin_guis();
2419 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2420 gui->update_proxy_toggle();
2421 gui->unlock_window();
2422 cwindow->gui->unlock_window();
2423 cwindow->update(1, 1, 1, 1, 1);
2425 for( int i=0; i<vwindows.size(); ++i ) {
2426 if( vwindows.get(i)->is_running() ) {
2427 if( calling_window_gui != vwindows.get(i)->gui ) {
2428 vwindows.get(i)->gui->unlock_window();
2433 awindow->gui->async_update_assets();
2435 cwindow->refresh_frame(CHANGE_ALL);
2436 calling_window_gui->lock_window("MWindow::undo_entry 4");
2440 void MWindow::new_folder(const char *new_folder, int is_clips)
2443 if( edl->new_folder(new_folder, is_clips) ) {
2444 MainError::show_error(_("create new folder failed"));
2446 undo_after(_("new folder"), LOAD_ALL);
2447 awindow->gui->async_update_assets();
2450 void MWindow::delete_folder(char *folder)
2453 if( edl->delete_folder(folder) < 0 ) {
2454 MainError::show_error(_("delete folder failed"));
2456 undo_after(_("del folder"), LOAD_ALL);
2457 awindow->gui->async_update_assets();
2460 void MWindow::select_point(double position)
2462 gui->unlock_window();
2463 gui->stop_drawing();
2464 cwindow->stop_playback(0);
2465 gui->lock_window("MWindow::select_point");
2467 edl->local_session->set_selectionstart(position);
2468 edl->local_session->set_selectionend(position);
2471 cwindow->update(1, 0, 0, 0, 1);
2473 update_plugin_guis();
2474 gui->update_patchbay();
2475 gui->hide_cursor(0);
2476 gui->draw_cursor(0);
2477 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2478 gui->zoombar->update();
2479 gui->update_timebar(0);
2480 gui->flash_canvas(0);
2487 void MWindow::map_audio(int pattern)
2490 remap_audio(pattern);
2492 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2494 sync_parameters(CHANGE_PARAMS);
2495 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2498 void MWindow::remap_audio(int pattern)
2500 int current_channel = 0;
2501 int current_track = 0;
2502 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2503 if( current->data_type == TRACK_AUDIO &&
2504 current->is_armed() ) {
2505 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2506 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2508 for( int i=0; i < MAXCHANNELS; ++i ) {
2509 pan_auto->values[i] = 0.0;
2512 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2513 pan_auto->values[current_channel] = 1.0;
2516 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2517 switch( current_track ) {
2520 pan_auto->values[0] = 1;
2524 pan_auto->values[1] = 1;
2528 pan_auto->values[0] = 0.5;
2529 pan_auto->values[1] = 0.5;
2534 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2535 edl->session->achannel_positions, pan_auto->values,
2536 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2540 if( current_channel >= edl->session->audio_channels )
2541 current_channel = 0;
2547 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2549 edl->rescale_proxy(orig_scale, new_scale);
2552 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2554 edl->add_proxy(orig_assets, proxy_assets);
2557 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2558 float beep, int to_proxy, int remove_originals)
2560 if( !convert_render )
2561 convert_render = new ConvertRender(this);
2562 convert_render->set_format(format_asset, suffix, to_proxy);
2563 int found = convert_render->find_convertable_assets(edl);
2564 if( convert_render->needed_idxbls.size() > 0 )
2565 convert_render->start_convert(beep, remove_originals);
2566 else if( found > 0 )
2567 finish_convert(remove_originals);
2568 else if( found < 0 )
2569 eprintf(_("convert assets format error"));
2571 eprintf(_("No convertable assets found"));
2574 void MWindow::finish_convert(int remove_originals)
2576 gui->lock_window("MWindow::finish_convert");
2578 edl->replace_assets(
2579 convert_render->orig_idxbls,
2580 convert_render->orig_copies);
2581 if( remove_originals ) {
2582 remove_assets_from_project(0, 0, 0,
2583 &convert_render->orig_idxbls, 0);
2586 undo_after(_("convert"), LOAD_ALL);
2588 update_plugin_guis();
2589 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2590 cwindow->update(1, 0, 0, 0, 1);
2591 awindow->gui->async_update_assets();
2592 cwindow->refresh_frame(CHANGE_EDL);
2593 gui->unlock_window();
2596 void MWindow::cut_commercials()
2598 #ifdef HAVE_COMMERCIAL
2600 commercials->scan_media();
2603 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2606 update_plugin_guis();
2607 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2608 cwindow->update(1, 0, 0, 0, 1);
2609 cwindow->refresh_frame(CHANGE_EDL);
2613 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl, int edit_speed)
2615 int edit_plugins = edl->session->plugins_follow_edits;
2616 int edit_autos = edl->session->autos_follow_edits;
2617 int edit_labels = edl->session->labels_follow_edits;
2618 if( !edit_autos ) edit_speed = 0;
2619 int result = 0, first_track = 1;
2620 Track *old_track = old_edl->tracks->first;
2621 Track *new_track = new_edl->tracks->first;
2622 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2623 if( old_track->data_type != new_track->data_type ) continue;
2624 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2625 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2626 if( !old_speeds || !new_speeds ) continue;
2627 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2628 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2629 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2630 old_speed = (FloatAuto *)old_speed->next;
2631 new_speed = (FloatAuto *)new_speed->next;
2633 if( !old_speed && !new_speed ) continue;
2636 Autos *old_autos = old_track->automation->autos[AUTOMATION_SPEED];
2637 Autos *new_autos = new_track->automation->autos[AUTOMATION_SPEED];
2638 Auto *old_auto = old_autos ? old_autos->first : 0;
2639 for( ; old_auto; old_auto=old_auto->next ) {
2640 Auto *new_auto = new_autos->get_auto(old_auto->orig_id);
2641 if( !new_auto ) continue;
2642 int64_t auto_pos = old_auto->position;
2643 double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
2644 auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2645 new_auto->position = auto_pos;
2648 Edit *old_edit = old_track->edits->first;
2649 for( ; old_edit; old_edit=old_edit->next ) {
2650 Edit *new_edit = new_track->edits->get_edit(old_edit->orig_id);
2651 if( !new_edit ) continue;
2652 int64_t edit_start = old_edit->startproject;
2653 int64_t edit_end = edit_start + old_edit->length;
2654 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2655 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2656 edit_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
2657 edit_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
2658 new_edit->startproject = edit_start;
2659 new_edit->length = edit_end - edit_start;
2661 if( first_track && old_track->is_armed() ) {
2662 Labels *old_labels = old_edl->labels;
2663 Labels *new_labels = new_edl->labels;
2664 if( edit_labels && old_labels && new_labels ) {
2665 Label *old_label = old_labels->first;
2666 for( ; old_label; old_label=old_label->next ) {
2667 Label *new_label = new_labels->get_label(old_label->orig_id);
2668 if( !new_label ) continue;
2669 int64_t label_pos = old_track->to_units(old_label->position, 1);
2670 double orig_pos = old_speeds->automation_integral(0, label_pos, PLAY_FORWARD);
2671 label_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2672 new_label->position = new_track->from_units(label_pos);
2677 if( edit_plugins ) {
2678 int old_size = old_track->plugin_set.size();
2679 int new_size = new_track->plugin_set.size();
2680 int n = bmin(old_size, new_size);
2681 for( int i=0; i<n; ++i ) {
2682 PluginSet *old_plugin_set = old_track->plugin_set[i];
2683 if( !old_plugin_set ) continue;
2684 PluginSet *new_plugin_set = new_track->plugin_set[i];
2685 if( !new_plugin_set ) continue;
2686 Plugin *old_plugin = (Plugin *)old_plugin_set->first;
2687 for( ; old_plugin; old_plugin=(Plugin *)old_plugin->next ) {
2688 Plugin *new_plugin = (Plugin *)new_plugin_set->get_edit(old_plugin->orig_id);
2689 if( !new_plugin ) continue;
2690 int64_t plugin_start = old_plugin->startproject;
2691 int64_t plugin_end = plugin_start + old_plugin->length;
2692 double orig_start = old_speeds->automation_integral(0, plugin_start, PLAY_FORWARD);
2693 double orig_end = old_speeds->automation_integral(0, plugin_end, PLAY_FORWARD);
2694 plugin_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
2695 plugin_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
2696 new_plugin->startproject = plugin_start;
2697 new_plugin->length = plugin_end - plugin_start;
2699 KeyFrames *old_keyframes = old_plugin->keyframes;
2700 if( !old_keyframes ) continue;
2701 KeyFrames *new_keyframes = new_plugin->keyframes;
2702 if( !new_keyframes ) continue;
2703 Auto *old_auto = old_keyframes->first;
2704 for( ; old_auto; old_auto=old_auto->next ) {
2705 Auto *new_auto = new_keyframes->get_auto(old_auto->orig_id);
2706 if( !new_auto ) continue;
2707 int64_t auto_pos = old_auto->position;
2708 double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
2709 auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2710 new_auto->position = auto_pos;
2711 old_auto = old_auto->next;
2717 if( edit_autos ) { // speed must be last
2718 for( int i=0; i<AUTOMATION_SPEED; ++i ) {
2719 Autos *old_autos = old_track->automation->autos[i];
2720 if( !old_autos ) continue;
2721 Autos *new_autos = new_track->automation->autos[i];
2722 if( !new_autos ) continue;
2723 Auto *old_auto = old_autos->first;
2724 for( ; old_auto; old_auto=old_auto->next ) {
2725 Auto *new_auto = new_autos->get_auto(old_auto->orig_id);
2726 if( !new_auto ) continue;
2727 int64_t auto_pos = old_auto->position;
2728 double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
2729 auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2730 new_auto->position = auto_pos;
2738 void MWindow::speed_before()
2741 speed_edl = new EDL;
2742 speed_edl->create_objects();
2744 speed_edl->copy_all(edl);
2747 int MWindow::speed_after(int done, int edit_speed)
2752 result = normalize_speed(speed_edl, edl, edit_speed);
2754 speed_edl->remove_user();
2761 void MWindow::collect_effects()
2764 const char *file_string = "";
2766 int ret = edl->collect_effects(group);
2768 case COLLECT_EFFECTS_RECORD:
2769 eprintf(_("Selected edit track not armed."));
2771 case COLLECT_EFFECTS_MULTIPLE:
2772 eprintf(_("More than one edit selected on a track."));
2774 case COLLECT_EFFECTS_MISSING:
2775 eprintf(_("No effects under selected edit."));
2777 case COLLECT_EFFECTS_EMPTY:
2778 eprintf(_("No edits selected."));
2780 case COLLECT_EFFECTS_MASTER:
2781 eprintf(_("Shared effect added without master."));
2784 group->save_xml(&file, "");
2785 file_string = file.string();
2786 group->remove_user();
2788 long file_length = strlen(file_string);
2789 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2790 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2793 void MWindow::paste_effects()
2796 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2798 string = new char[len];
2799 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2801 if( !string || !string[0] ) {
2802 eprintf(_("Error clipboard buffer empty."));
2806 file.read_from_string(string);
2807 EDL *group = new EDL();
2808 group->create_objects();
2809 if( !group->load_xml(&file, LOAD_ALL) ) {
2811 int ret = edl->insert_effects(group);
2813 case INSERT_EFFECTS_RECORD:
2814 eprintf(_("Selected edit track not armed."));
2816 case INSERT_EFFECTS_TYPE:
2817 eprintf(_("Track type mismatched."));
2819 case INSERT_EFFECTS_MULTIPLE:
2820 eprintf(_("More than one edit selected on a track."));
2822 case INSERT_EFFECTS_MISSING:
2823 eprintf(_("Too few target edits to add group effects."));
2825 case INSERT_EFFECTS_EXTRA:
2826 eprintf(_("Too many target edits to add group effects."));
2828 case INSERT_EFFECTS_MASTER:
2829 eprintf(_("Shared effect added without master."));
2835 undo_after(_("paste effects"), LOAD_ALL);
2837 cwindow->refresh_frame(CHANGE_EDL);
2838 update_plugin_guis();
2839 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2842 eprintf(_("Error loading clip from clipboard buffer."));
2844 group->remove_user();
2847 void MWindow::align_timecodes()
2850 double offset = edl->tracks->align_timecodes();
2851 set_timecode_offset(offset);
2853 undo_after(_("align timecodes"), LOAD_ALL);
2855 cwindow->refresh_frame(CHANGE_EDL);
2856 update_plugin_guis();
2860 int MWindow::masters_to_mixers()
2862 Track *master_track = edl->tracks->first;
2863 while( master_track && !master_track->master )
2864 master_track = master_track->next;
2865 while( master_track ) { // test for track/mixer conflicts
2867 Track *mixer_last = master_track;
2868 Track *track = master_track->next;
2869 for( ; track && !track->master; track=track->next )
2871 Track *next_track = track;
2872 if( !master_track->armed ) {
2873 master_track = next_track;
2876 Mixer *master_mixer = 0;
2877 for( int i=0, n=edl->mixers.size(); i<n; ++i ) {
2878 if( master_track->index_in(edl->mixers[i]) >= 0 ) {
2879 master_mixer = edl->mixers[i];
2883 if( master_mixer ) { // existing mixer track group
2884 for( track=master_track; !failed && track; track=track->next ) {
2885 if( track->index_in(master_mixer) < 0 ) {
2886 eprintf("Mixer: %s missing track: %s",
2887 master_mixer->title, track->title);
2890 if( track == mixer_last ) break;
2892 for( int i=0, n=master_mixer->mixer_ids.size(); !failed && i<n; ++i ) {
2893 int mixer_id = master_mixer->mixer_ids[i], found = 0;
2894 for( track=master_track; track; track=track->next ) {
2895 if( track->mixer_id == mixer_id ) {
2899 if( track == mixer_last ) break;
2902 eprintf("Mixer: %s track missing: %s",
2903 master_mixer->title, track->title);
2908 else { // create mixer
2909 for( track=master_track->next; !failed && track; track=track->next ) {
2910 for( int i=0, n=edl->mixers.size(); !failed && i<n; ++i ) {
2911 Mixer *mixer = edl->mixers[i];
2912 if( track->index_in(mixer) >= 0 ) {
2913 eprintf("Track: %s already exists in mixer: %s",
2914 track->title, mixer->title);
2919 if( track == mixer_last ) break;
2921 if( !failed ) { // new mixer
2922 ZWindow *zwindow = get_mixer(master_mixer);
2923 zwindow->set_title(master_track->title);
2924 sprintf(master_track->title, _("Mixer %d"), zwindow->idx);
2925 for( track=master_track; track; track=track->next ) {
2926 track->play = track->armed = 0;
2927 master_mixer->mixer_ids.append(track->get_mixer_id());
2928 if( track == mixer_last ) break;
2933 master_track = next_track;
2938 void MWindow::mix_masters()
2941 masters_to_mixers();
2942 undo_after(_("mix masters"), LOAD_ALL);
2945 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
2946 gui->activate_timeline();
2947 cwindow->refresh_frame(CHANGE_EDL);
2951 void MWindow::create_keyframes(int mask, int mode)
2954 double start = edl->local_session->get_selectionstart();
2955 edl->tracks->create_keyframes(start, mask, mode);
2956 double end = edl->local_session->get_selectionend();
2958 edl->tracks->create_keyframes(end, mask, mode);
2959 undo_after(_("create kyfrms"), LOAD_AUTOMATION);
2962 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
2963 gui->activate_timeline();
2964 cwindow->refresh_frame(CHANGE_EDL);