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()
431 double start = edl->local_session->get_selectionstart();
432 double end = edl->local_session->get_selectionend();
433 edl->tracks->select_edits(start, end);
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->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(1);
845 double end_pos = edl->local_session->get_selectionend(1);
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 void MWindow::match_output_size(Track *track)
966 track->track_w = edl->session->output_w;
967 track->track_h = edl->session->output_h;
969 undo_after(_("match output size"), LOAD_ALL);
972 sync_parameters(CHANGE_EDL);
976 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
978 ArrayList<Edit*> edits;
980 delete_edits(&edits, msg, collapse);
983 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
985 if( !edits->size() ) return;
987 if( edl->session->labels_follow_edits )
988 edl->delete_edit_labels(edits, collapse);
989 edl->delete_edits(edits, collapse);
992 undo_after(msg, LOAD_EDITS);
995 cwindow->refresh_frame(CHANGE_EDL);
996 update_plugin_guis();
997 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1000 void MWindow::delete_edits(int collapse)
1002 ArrayList<Edit*> edits;
1003 edl->tracks->get_selected_edits(&edits);
1004 delete_edits(&edits,_("del edit"), collapse);
1007 // collapse - delete from timeline, not collapse replace with silence
1008 // packed - omit unselected from selection, unpacked - replace unselected with silence
1009 void MWindow::cut_selected_edits(int collapse, int packed)
1011 selected_edits_to_clipboard(packed);
1012 ArrayList<Edit*> edits;
1013 edl->tracks->get_selected_edits(&edits);
1014 delete_edits(&edits, _("cut edit"), collapse);
1018 void MWindow::move_edits(ArrayList<Edit*> *edits,
1019 Track *track, double position, int mode)
1022 // lockout timebar labels update
1023 // labels can be deleted with tooltip repeater running
1024 cwindow->gui->lock_window("Tracks::move_edits");
1025 edl->tracks->move_edits(edits, track, position,
1026 edl->session->labels_follow_edits,
1027 edl->session->plugins_follow_edits,
1028 edl->session->autos_follow_edits, mode);
1029 cwindow->gui->timebar->update(1);
1030 cwindow->gui->unlock_window();
1033 undo_after(_("move edit"), LOAD_ALL);
1036 cwindow->refresh_frame(CHANGE_EDL);
1038 update_plugin_guis();
1039 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1042 void MWindow::selected_edits_to_clipboard(int packed)
1044 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1045 edl->session->labels_follow_edits,
1046 edl->session->autos_follow_edits,
1047 edl->session->plugins_follow_edits);
1048 if( !new_edl ) return;
1050 new_edl->copy(COPY_EDL, &file, "", 1);
1051 const char *file_string = file.string();
1052 long file_length = strlen(file_string);
1053 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1054 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1055 new_edl->remove_user();
1058 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1059 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1061 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1063 char *string = new char[len];
1064 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1066 file.read_from_string(string);
1068 EDL *clip = new EDL();
1069 clip->create_objects();
1070 if( !clip->load_xml(&file, LOAD_ALL) ) {
1072 edl->paste_edits(clip, first_track, position, overwrite,
1073 edit_edits, edit_labels, edit_autos, edit_plugins);
1075 undo_after(_("paste clip"), LOAD_ALL);
1077 cwindow->refresh_frame(CHANGE_EDL);
1079 update_plugin_guis();
1080 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1082 clip->remove_user();
1085 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1088 // lockout timebar labels update
1089 // labels can be deleted with tooltip repeater running
1090 cwindow->gui->lock_window("Tracks::move_group");
1092 ArrayList<Edit *>edits;
1093 edl->tracks->get_selected_edits(&edits);
1094 if( edl->session->labels_follow_edits )
1095 edl->delete_edit_labels(&edits, 0);
1096 edl->delete_edits(&edits, 0);
1097 edl->paste_edits(group, first_track, position, overwrite, 1,
1098 edl->session->labels_follow_edits,
1099 edl->session->autos_follow_edits,
1100 edl->session->plugins_follow_edits);
1101 cwindow->gui->timebar->update(1);
1102 cwindow->gui->unlock_window();
1103 // big debate over whether to do this, must either clear selected, or no tweaking
1104 // edl->tracks->clear_selected_edits();
1107 undo_after(_("move group"), LOAD_ALL);
1109 cwindow->refresh_frame(CHANGE_EDL);
1111 update_plugin_guis();
1112 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1115 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1118 edl->tracks->move_effect(plugin, track, position);
1120 undo_after(_("paste effect"), LOAD_ALL);
1123 cwindow->refresh_frame(CHANGE_EDL);
1124 update_plugin_guis();
1125 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1128 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1131 edl->tracks->move_effect(plugin, plugin_set, position);
1133 undo_after(_("move effect"), LOAD_ALL);
1136 cwindow->refresh_frame(CHANGE_EDL);
1137 update_plugin_guis();
1138 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1141 void MWindow::move_plugins_up(PluginSet *plugin_set)
1145 plugin_set->track->move_plugins_up(plugin_set);
1148 undo_after(_("move effect up"), LOAD_ALL);
1150 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1151 sync_parameters(CHANGE_EDL);
1154 void MWindow::move_plugins_down(PluginSet *plugin_set)
1158 plugin_set->track->move_plugins_down(plugin_set);
1161 undo_after(_("move effect down"), LOAD_ALL);
1163 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1164 sync_parameters(CHANGE_EDL);
1167 void MWindow::move_track_down(Track *track)
1170 edl->tracks->move_track_down(track);
1172 undo_after(_("move track down"), LOAD_ALL);
1175 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1176 sync_parameters(CHANGE_EDL);
1180 void MWindow::move_tracks_down()
1183 edl->tracks->move_tracks_down();
1185 undo_after(_("move tracks down"), LOAD_ALL);
1188 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1189 sync_parameters(CHANGE_EDL);
1193 void MWindow::move_track_up(Track *track)
1196 edl->tracks->move_track_up(track);
1198 undo_after(_("move track up"), LOAD_ALL);
1200 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1201 sync_parameters(CHANGE_EDL);
1205 void MWindow::move_tracks_up()
1208 edl->tracks->move_tracks_up();
1210 undo_after(_("move tracks up"), LOAD_ALL);
1212 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1213 sync_parameters(CHANGE_EDL);
1217 void MWindow::swap_track_down(Track *track)
1220 edl->tracks->swap_track_down(track);
1222 undo_after(_("swap track down"), LOAD_ALL);
1225 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1226 sync_parameters(CHANGE_EDL);
1230 void MWindow::swap_tracks_down()
1233 edl->tracks->swap_tracks_down();
1235 undo_after(_("swap tracks down"), LOAD_ALL);
1238 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1239 sync_parameters(CHANGE_EDL);
1243 void MWindow::swap_track_up(Track *track)
1246 edl->tracks->swap_track_up(track);
1248 undo_after(_("swap track up"), LOAD_ALL);
1250 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1251 sync_parameters(CHANGE_EDL);
1255 void MWindow::swap_tracks_up()
1258 edl->tracks->swap_tracks_up();
1260 undo_after(_("swap tracks up"), LOAD_ALL);
1262 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1263 sync_parameters(CHANGE_EDL);
1267 void MWindow::mute_selection()
1269 double start = edl->local_session->get_selectionstart();
1270 double end = edl->local_session->get_selectionend();
1271 if( start != end ) {
1273 edl->clear(start, end, 0,
1274 edl->session->plugins_follow_edits,
1275 edl->session->autos_follow_edits);
1276 edl->local_session->set_selectionend(end);
1277 edl->local_session->set_selectionstart(start);
1278 edl->paste_silence(start, end, 0,
1279 edl->session->plugins_follow_edits,
1280 edl->session->autos_follow_edits);
1283 undo_after(_("mute"), LOAD_EDITS);
1286 update_plugin_guis();
1287 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1288 cwindow->refresh_frame(CHANGE_EDL);
1293 void MWindow::overwrite(EDL *source, int all)
1297 LocalSession *src = source->local_session;
1298 double src_start = all ? 0 :
1299 src->inpoint_valid() ? src->get_inpoint() :
1300 src->outpoint_valid() ? 0 :
1301 src->get_selectionstart();
1302 double src_end = all ? source->tracks->total_length() :
1303 src->outpoint_valid() ? src->get_outpoint() :
1304 src->inpoint_valid() ? source->tracks->total_length() :
1305 src->get_selectionend();
1306 double overwrite_len = src_end - src_start;
1307 double dst_start = edl->local_session->get_selectionstart();
1308 double dst_len = edl->local_session->get_selectionend() - dst_start;
1311 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1312 // in/out points or selection present and shorter than overwrite range
1313 // shorten the copy range
1314 overwrite_len = dst_len;
1317 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1319 // HACK around paste_edl get_start/endselection on its own
1320 // so we need to clear only when not using both io points
1321 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1322 if( edl->local_session->get_inpoint() < 0 ||
1323 edl->local_session->get_outpoint() < 0 )
1324 edl->clear(dst_start, dst_start + overwrite_len,
1325 edl->session->labels_follow_edits,
1326 edl->session->plugins_follow_edits,
1327 edl->session->autos_follow_edits);
1329 paste(dst_start, dst_start + overwrite_len, &file,
1330 edl->session->labels_follow_edits,
1331 edl->session->plugins_follow_edits,
1332 edl->session->autos_follow_edits, 0, 0);
1334 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1335 edl->local_session->set_selectionend(dst_start + overwrite_len);
1338 undo_after(_("overwrite"),
1339 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1342 update_plugin_guis();
1343 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1344 sync_parameters(CHANGE_EDL);
1347 // For splice and overwrite
1348 int MWindow::paste(double start, double end, FileXML *file,
1349 int edit_labels, int edit_plugins, int edit_autos,
1350 Track *first_track, int overwrite)
1354 // Want to insert with assets shared with the master EDL.
1356 edit_labels, edit_plugins, edit_autos,
1357 edl, first_track, overwrite);
1362 // For editing using insertion point
1363 void MWindow::paste()
1365 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1368 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1370 //double end = edl->local_session->get_selectionend();
1371 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1374 char *string = new char[len];
1376 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1378 file.read_from_string(string);
1379 if( clear_selection ) clear(0);
1381 insert(start, &file,
1382 edl->session->labels_follow_edits,
1383 edl->session->plugins_follow_edits,
1384 edl->session->autos_follow_edits,
1385 0, first_track, overwrite);
1392 undo_after(_("paste"),
1393 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1395 update_plugin_guis();
1396 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1397 awindow->gui->async_update_assets();
1398 sync_parameters(CHANGE_EDL);
1403 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1408 if( session->drag_assets->total ) {
1409 load_assets(session->drag_assets,
1410 position, LOADMODE_PASTE, dest_track, 0,
1411 edl->session->labels_follow_edits,
1412 edl->session->plugins_follow_edits,
1413 edl->session->autos_follow_edits,
1418 if( session->drag_clips->total ) {
1419 paste_edls(session->drag_clips,
1420 LOADMODE_PASTE, dest_track, position,
1421 edl->session->labels_follow_edits,
1422 edl->session->plugins_follow_edits,
1423 edl->session->autos_follow_edits,
1430 undo_after(_("paste assets"),
1431 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1433 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1434 sync_parameters(CHANGE_EDL);
1438 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1439 double position, int load_mode, Track *first_track, RecordLabels *labels,
1440 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1442 if( load_mode == LOADMODE_RESOURCESONLY )
1443 load_mode = LOADMODE_ASSETSONLY;
1444 const int debug = 0;
1445 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1447 position = edl->local_session->get_selectionstart();
1449 ArrayList<EDL*> new_edls;
1450 for( int i=0; i<new_assets->total; ++i ) {
1451 Indexable *indexable = new_assets->get(i);
1452 if( indexable->is_asset ) {
1453 remove_from_caches(indexable);
1455 EDL *new_edl = new EDL;
1456 new_edl->create_objects();
1457 new_edl->copy_session(edl);
1458 if( !indexable->is_asset ) {
1459 EDL *nested_edl = (EDL*)indexable;
1460 new_edl->create_nested(nested_edl);
1461 new_edl->set_path(indexable->path);
1464 Asset *asset = (Asset*)indexable;
1465 asset_to_edl(new_edl, asset);
1467 new_edls.append(new_edl);
1470 for( RecordLabel *label=labels->first; label; label=label->next ) {
1471 new_edl->labels->toggle_label(label->position, label->position);
1475 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1477 paste_edls(&new_edls, load_mode, first_track, position,
1478 edit_labels, edit_plugins, edit_autos, overwrite);
1479 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1482 for( int i=0; i<new_edls.size(); ++i )
1483 new_edls.get(i)->Garbage::remove_user();
1485 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1488 int MWindow::paste_automation()
1490 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1495 char *string = new char[len];
1496 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1498 file.read_from_string(string);
1500 double start = edl->local_session->get_selectionstart();
1501 double end = edl->local_session->get_selectionend();
1502 edl->tracks->clear_automation(start, end);
1503 edl->tracks->paste_automation(start, &file, 0, 1,
1504 edl->session->typeless_keyframes);
1505 int changed_edl = speed_after(1, 0);
1507 undo_after(_("paste keyframes"),
1508 !changed_edl ? LOAD_AUTOMATION :
1509 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1510 update_gui(changed_edl);
1516 int MWindow::paste_default_keyframe()
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 edl->tracks->paste_automation(start, &file, 1, 0,
1530 edl->session->typeless_keyframes);
1531 // edl->tracks->paste_default_keyframe(&file);
1532 int changed_edl = speed_after(1, 1);
1533 undo_after(_("paste default keyframe"),
1534 !changed_edl ? LOAD_AUTOMATION :
1535 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1537 update_gui(changed_edl);
1544 // Insert edls with project deletion and index file generation.
1545 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1546 Track *first_track, double current_position,
1547 int edit_labels, int edit_plugins, int edit_autos,
1551 ArrayList<Track*> destination_tracks;
1552 int need_new_tracks = 0;
1555 if( !new_edls->total ) return 0;
1558 // double original_length = edl->tracks->total_length();
1559 // double original_preview_end = edl->local_session->preview_end;
1562 // Delete current project
1563 if( load_mode == LOADMODE_REPLACE ||
1564 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1566 edl->save_defaults(defaults);
1568 edl->Garbage::remove_user();
1570 edl->create_objects();
1571 edl->copy_session(new_edls->values[0]);
1572 edl->copy_mixers(new_edls->values[0]);
1573 gui->mainmenu->update_toggles(0);
1574 gui->unlock_window();
1575 gwindow->gui->update_toggles(1);
1576 gui->lock_window("MWindow::paste_edls");
1578 // Insert labels for certain modes constitutively
1582 // Force reset of preview
1583 // original_length = 0;
1584 // original_preview_end = -1;
1590 // Create new tracks in master EDL
1591 if( load_mode == LOADMODE_REPLACE ||
1592 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1593 load_mode == LOADMODE_NEW_TRACKS ) {
1595 need_new_tracks = 1;
1596 for( int i=0; i<new_edls->total; ++i ) {
1597 EDL *new_edl = new_edls->values[i];
1598 int first_track = 1;
1599 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1600 switch( current->data_type ) {
1602 edl->tracks->add_video_track(0, 0);
1603 if( current->draw ) edl->tracks->last->draw = 1;
1606 edl->tracks->add_audio_track(0, 0);
1608 case TRACK_SUBTITLE:
1609 edl->tracks->add_subttl_track(0, 0);
1615 edl->tracks->last->master = 1;
1618 // re-label only if not already labeled
1619 if( new_edl->local_session->asset2edl )
1620 strcpy(current->title, edl->tracks->last->title);
1621 destination_tracks.append(edl->tracks->last);
1624 // Base track count on first EDL only for concatenation
1625 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1627 edl->session->highlighted_track = edl->tracks->total() - 1;
1630 // Recycle existing tracks of master EDL
1631 if( load_mode == LOADMODE_CONCATENATE ||
1632 load_mode == LOADMODE_PASTE ) {
1633 Track *current = first_track ? first_track : edl->tracks->first;
1634 for( ; current; current=NEXT ) {
1635 if( current->is_armed() ) {
1636 destination_tracks.append(current);
1642 int destination_track = 0;
1643 double *paste_position = new double[destination_tracks.total];
1645 // Iterate through the edls
1646 for( int i=0; i<new_edls->total; ++i ) {
1648 EDL *new_edl = new_edls->values[i];
1649 double edl_length = new_edl->local_session->clipboard_length ?
1650 new_edl->local_session->clipboard_length :
1651 new_edl->tracks->total_length();
1652 // printf("MWindow::paste_edls 2 %f %f\n",
1653 // new_edl->local_session->clipboard_length,
1654 // new_edl->tracks->total_length());
1658 // Convert EDL to master rates
1659 new_edl->resample(new_edl->session->sample_rate,
1660 edl->session->sample_rate,
1662 new_edl->resample(new_edl->session->frame_rate,
1663 edl->session->frame_rate,
1666 // Add assets and prepare index files
1667 for( Asset *new_asset=new_edl->assets->first;
1668 new_asset; new_asset=new_asset->next ) {
1669 mainindexes->add_indexable(new_asset);
1671 // Capture index file status from mainindex test
1672 edl->update_assets(new_edl);
1674 // Get starting point of insertion. Need this to paste labels.
1675 switch( load_mode ) {
1676 case LOADMODE_NOTHING:
1678 case LOADMODE_REPLACE:
1679 current_position = 0;
1681 case LOADMODE_NEW_TRACKS:
1683 current_position = 0;
1686 case LOADMODE_CONCATENATE:
1687 case LOADMODE_REPLACE_CONCATENATE:
1688 destination_track = 0;
1689 if( destination_tracks.total )
1690 current_position = destination_tracks.values[0]->get_length();
1692 current_position = 0;
1695 case LOADMODE_PASTE:
1696 destination_track = 0;
1698 for( int j=0; j<destination_tracks.total; ++j ) {
1699 paste_position[j] = (current_position >= 0) ?
1701 edl->local_session->get_selectionstart();
1706 case LOADMODE_RESOURCESONLY:
1707 edl->add_clip(new_edl);
1711 if( load_mode != LOADMODE_RESOURCESONLY &&
1712 load_mode != LOADMODE_ASSETSONLY ) {
1715 if( load_mode == LOADMODE_PASTE )
1716 edl->labels->insert_labels(new_edl->labels,
1717 destination_tracks.total ? paste_position[0] : 0.0,
1720 edl->labels->insert_labels(new_edl->labels, current_position,
1723 double total_length = new_edl->tracks->total_length();
1724 for( Track *new_track=new_edl->tracks->first;
1725 new_track; new_track=new_track->next ) {
1726 // Get destination track of same type as new_track
1728 k < destination_tracks.total &&
1729 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1730 ++k, ++destination_track ) {
1731 if( destination_track >= destination_tracks.total - 1 )
1732 destination_track = 0;
1735 // Insert data into destination track
1736 if( destination_track < destination_tracks.total &&
1737 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1738 Track *track = destination_tracks.values[destination_track];
1739 // Replace default keyframes if first EDL and new tracks were created.
1740 // This means data copied from one track and pasted to another won't retain
1741 // the camera position unless it's a keyframe. If it did, previous data in the
1742 // track might get unknowingly corrupted. Ideally we would detect when differing
1743 // default keyframes existed and create discrete keyframes for both.
1744 int replace_default = (i == 0) && need_new_tracks;
1745 // master tracks are the first track in each new edl when new tracks are created
1746 int master = track->master;
1747 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1748 // Insert new track at current position
1749 switch( load_mode ) {
1750 case LOADMODE_REPLACE_CONCATENATE:
1751 case LOADMODE_CONCATENATE:
1752 current_position = track->get_length();
1755 case LOADMODE_PASTE:
1756 current_position = paste_position[destination_track];
1757 paste_position[destination_track] += new_track->get_length();
1761 double length = overwrite >= 0 ?
1762 new_track->get_length() : total_length;
1763 track->clear(current_position,
1764 current_position + length,
1766 edit_labels, edit_plugins, edit_autos,
1770 track->insert_track(new_track, current_position, replace_default,
1771 edit_plugins, edit_autos, edl_length);
1772 if( master ) track->master = 1;
1776 // Get next destination track
1777 destination_track++;
1778 if( destination_track >= destination_tracks.total )
1779 destination_track = 0;
1783 if( load_mode == LOADMODE_PASTE )
1784 current_position += edl_length;
1788 // Move loading of clips and vwindow to the end - this fixes some
1789 // strange issue, for index not being shown
1790 // Assume any paste operation from the same EDL won't contain any clips.
1791 // If it did it would duplicate every clip here.
1792 for( int i=0; i<new_edls->total; ++i ) {
1793 EDL *new_edl = new_edls->get(i);
1795 for( int j=0; j<new_edl->clips.size(); ++j ) {
1796 edl->add_clip(new_edl->clips[j]);
1798 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1799 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1802 if( new_edl->total_vwindow_edls() ) {
1803 // if( edl->vwindow_edl )
1804 // edl->vwindow_edl->Garbage::remove_user();
1805 // edl->vwindow_edl = new EDL(edl);
1806 // edl->vwindow_edl->create_objects();
1807 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1809 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1810 EDL *vwindow_edl = new EDL(edl);
1811 vwindow_edl->create_objects();
1812 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1813 edl->append_vwindow_edl(vwindow_edl, 0);
1818 if( paste_position ) delete [] paste_position;
1820 // This is already done in load_filenames and everything else that uses paste_edls
1821 // update_project(load_mode);
1823 // Fix preview range
1824 // if( EQUIV(original_length, original_preview_end) )
1826 // edl->local_session->preview_end = edl->tracks->total_length();
1829 // Start examining next batch of index files
1830 mainindexes->start_build();
1832 // Don't save a backup after loading since the loaded file is on disk already.
1837 void MWindow::paste_silence()
1839 double start = edl->local_session->get_selectionstart();
1840 double end = edl->local_session->get_selectionend();
1841 if( EQUIV(start, end) ) {
1842 if( edl->session->frame_rate > 0 )
1843 end += 1./edl->session->frame_rate;
1845 undo_before(_("silence"), this);
1846 edl->paste_silence(start, end,
1847 edl->session->labels_follow_edits,
1848 edl->session->plugins_follow_edits,
1849 edl->session->autos_follow_edits);
1852 undo_after(_("silence"),
1853 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1855 update_plugin_guis();
1857 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1858 cwindow->update(1, 0, 0, 0, 1);
1859 cwindow->refresh_frame(CHANGE_EDL);
1862 void MWindow::detach_transition(Transition *transition)
1865 hide_plugin(transition, 1);
1866 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1867 transition->edit->detach_transition();
1869 undo_after(_("detach transition"), LOAD_ALL);
1871 if( is_video ) restart_brender();
1872 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1873 sync_parameters(CHANGE_EDL);
1876 void MWindow::detach_transitions()
1878 gui->lock_window("MWindow::detach_transitions 1");
1881 double start = edl->local_session->get_selectionstart();
1882 double end = edl->local_session->get_selectionend();
1883 edl->tracks->clear_transitions(start, end);
1886 undo_after(_("detach transitions"), LOAD_EDITS);
1888 sync_parameters(CHANGE_EDL);
1889 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1890 gui->unlock_window();
1893 void MWindow::paste_transition()
1895 // Only the first transition gets dropped.
1896 PluginServer *server = session->drag_pluginservers->values[0];
1899 edl->tracks->paste_transition(server, session->edit_highlighted);
1901 undo_after(_("transition"), LOAD_EDITS);
1903 if( server->video ) restart_brender();
1904 sync_parameters(CHANGE_ALL);
1907 void MWindow::paste_transitions(int track_type, char *title)
1909 gui->lock_window("MWindow::detach_transitions 1");
1912 double start = edl->local_session->get_selectionstart();
1913 double end = edl->local_session->get_selectionend();
1914 edl->tracks->paste_transitions(start, end, track_type, title);
1916 undo_after(_("attach transitions"), LOAD_EDITS);
1918 sync_parameters(CHANGE_EDL);
1919 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1920 gui->unlock_window();
1923 void MWindow::paste_transition_cwindow(Track *dest_track)
1925 PluginServer *server = session->drag_pluginservers->values[0];
1927 edl->tracks->paste_video_transition(server, 1);
1929 undo_after(_("transition"), LOAD_EDITS);
1931 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1932 sync_parameters(CHANGE_ALL);
1935 void MWindow::paste_audio_transition()
1937 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1940 char string[BCTEXTLEN];
1941 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1942 gui->show_message(string);
1947 edl->tracks->paste_audio_transition(server);
1949 undo_after(_("transition"), LOAD_EDITS);
1951 sync_parameters(CHANGE_EDL);
1952 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1955 void MWindow::paste_video_transition()
1957 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1960 char string[BCTEXTLEN];
1961 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1962 gui->show_message(string);
1968 edl->tracks->paste_video_transition(server);
1970 undo_after(_("transition"), LOAD_EDITS);
1972 sync_parameters(CHANGE_EDL);
1974 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1977 void MWindow::shuffle_edits()
1979 gui->lock_window("MWindow::shuffle_edits 1");
1982 double start = edl->local_session->get_selectionstart();
1983 double end = edl->local_session->get_selectionend();
1985 edl->tracks->shuffle_edits(start, end);
1988 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1990 sync_parameters(CHANGE_EDL);
1992 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1993 gui->unlock_window();
1996 void MWindow::reverse_edits()
1998 gui->lock_window("MWindow::reverse_edits 1");
2001 double start = edl->local_session->get_selectionstart();
2002 double end = edl->local_session->get_selectionend();
2004 edl->tracks->reverse_edits(start, end);
2007 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
2009 sync_parameters(CHANGE_EDL);
2011 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2012 gui->unlock_window();
2015 void MWindow::align_edits()
2017 gui->lock_window("MWindow::align_edits 1");
2020 double start = edl->local_session->get_selectionstart();
2021 double end = edl->local_session->get_selectionend();
2023 edl->tracks->align_edits(start, end);
2026 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
2028 sync_parameters(CHANGE_EDL);
2030 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2031 gui->unlock_window();
2034 void MWindow::set_edit_length(double length)
2036 gui->lock_window("MWindow::set_edit_length 1");
2039 double start = edl->local_session->get_selectionstart();
2040 double end = edl->local_session->get_selectionend();
2042 edl->tracks->set_edit_length(start, end, length);
2045 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
2047 sync_parameters(CHANGE_EDL);
2049 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2050 gui->unlock_window();
2054 void MWindow::set_transition_length(Transition *transition, double length)
2056 gui->lock_window("MWindow::set_transition_length 1");
2059 //double start = edl->local_session->get_selectionstart();
2060 //double end = edl->local_session->get_selectionend();
2062 edl->tracks->set_transition_length(transition, length);
2065 undo_after(_("transition length"), LOAD_EDITS);
2067 edl->session->default_transition_length = length;
2068 sync_parameters(CHANGE_PARAMS);
2069 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2070 gui->unlock_window();
2073 void MWindow::set_transition_length(double length)
2075 gui->lock_window("MWindow::set_transition_length 2");
2078 double start = edl->local_session->get_selectionstart();
2079 double end = edl->local_session->get_selectionend();
2081 edl->tracks->set_transition_length(start, end, length);
2084 undo_after(_("transition length"), LOAD_EDITS);
2086 edl->session->default_transition_length = length;
2087 sync_parameters(CHANGE_PARAMS);
2089 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2090 gui->unlock_window();
2094 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2096 calling_window_gui->unlock_window();
2098 if( undo->redo_load_flags() & LOAD_SESSION )
2101 cwindow->gui->lock_window("MWindow::redo_entry 1");
2102 for( int i=0; i<vwindows.size(); ++i ) {
2103 if( vwindows.get(i)->is_running() ) {
2104 if( calling_window_gui != vwindows.get(i)->gui ) {
2105 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2109 gui->lock_window("MWindow::redo_entry 3");
2115 update_plugin_states();
2116 update_plugin_guis();
2118 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2119 gui->update_proxy_toggle();
2120 gui->unlock_window();
2121 cwindow->gui->unlock_window();
2122 cwindow->update(1, 1, 1, 1, 1);
2124 for( int i=0; i < vwindows.size(); ++i ) {
2125 if( vwindows.get(i)->is_running() ) {
2126 if( calling_window_gui != vwindows.get(i)->gui ) {
2127 vwindows.get(i)->gui->unlock_window();
2132 awindow->gui->async_update_assets();
2134 cwindow->refresh_frame(CHANGE_ALL);
2135 calling_window_gui->lock_window("MWindow::redo_entry 4");
2139 void MWindow::resize_track(Track *track, int w, int h)
2142 // We have to move all maskpoints so they do not move in relation to image areas
2143 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2144 (w - track->track_w) / 2,
2145 (h - track->track_h) / 2);
2148 undo_after(_("resize track"), LOAD_ALL);
2152 sync_parameters(CHANGE_EDL);
2156 void MWindow::set_inpoint()
2159 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2161 undo_after(_("in point"), LOAD_TIMEBAR);
2162 gui->update_timebar(1);
2164 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2165 cwindow->gui->timebar->update(1);
2166 cwindow->gui->unlock_window();
2169 void MWindow::set_outpoint()
2172 edl->set_outpoint(edl->local_session->get_selectionend(1));
2174 undo_after(_("out point"), LOAD_TIMEBAR);
2176 gui->update_timebar(1);
2177 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2178 cwindow->gui->timebar->update(1);
2179 cwindow->gui->unlock_window();
2182 void MWindow::unset_inoutpoint()
2185 edl->unset_inoutpoint();
2187 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2189 gui->update_timebar(1);
2190 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2191 cwindow->gui->timebar->update(1);
2192 cwindow->gui->unlock_window();
2195 void MWindow::splice(EDL *source, int all)
2198 LocalSession *src = source->local_session;
2201 double source_start = all ? 0 :
2202 src->inpoint_valid() ? src->get_inpoint() :
2203 src->outpoint_valid() ? 0 : src->get_selectionstart();
2204 double source_end = all ? source->tracks->total_length() :
2205 src->outpoint_valid() ? src->get_outpoint() :
2206 src->inpoint_valid() ? source->tracks->total_length() :
2207 src->get_selectionend();
2208 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2210 double start = edl->local_session->get_selectionstart();
2211 //double end = edl->local_session->get_selectionend();
2213 paste(start, start, &file,
2214 edl->session->labels_follow_edits,
2215 edl->session->plugins_follow_edits,
2216 edl->session->autos_follow_edits,
2219 // Position at end of clip
2220 edl->local_session->set_selectionstart(start + source_end - source_start);
2221 edl->local_session->set_selectionend(start + source_end - source_start);
2224 undo_after(_("splice"),
2225 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
2226 update_plugin_guis();
2228 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2229 sync_parameters(CHANGE_EDL);
2232 void MWindow::save_clip(EDL *new_edl, const char *txt)
2234 new_edl->local_session->set_selectionstart(0);
2235 new_edl->local_session->set_selectionend(0);
2236 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2237 session->clip_number++);
2238 char duration[BCTEXTLEN];
2239 Units::totext(duration, new_edl->tracks->total_length(),
2240 new_edl->session->time_format,
2241 new_edl->session->sample_rate,
2242 new_edl->session->frame_rate,
2243 new_edl->session->frames_per_foot);
2245 Track *track = new_edl->tracks->first;
2246 const char *path = edl->path;
2247 for( ; (!path || !*path) && track; track=track->next ) {
2248 if( !track->is_armed() ) continue;
2249 Edit *edit = track->edits->first;
2250 if( !edit ) continue;
2251 Indexable *indexable = edit->get_source();
2252 if( !indexable ) continue;
2253 path = indexable->path;
2256 time_t now; time(&now);
2257 struct tm dtm; localtime_r(&now, &dtm);
2258 char *cp = new_edl->local_session->clip_notes;
2259 char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2261 cp += snprintf(cp, ep-cp, "%s", txt);
2262 cp += snprintf(cp, ep-cp,
2263 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2264 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2265 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2266 if( path && *path ) {
2268 char title[BCTEXTLEN];
2269 fs.extract_name(title, path);
2270 cp += snprintf(cp, ep-cp, "%s", title);
2272 sprintf(new_edl->local_session->clip_icon,
2273 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2274 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2275 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2277 new_edl->folder_no = AW_CLIP_FOLDER;
2278 edl->update_assets(new_edl);
2280 gui->get_abs_cursor(cur_x, cur_y, 0);
2281 gui->unlock_window();
2283 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2284 new_edl->remove_user();
2286 gui->lock_window("MWindow::save_clip");
2290 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2293 LocalSession *src = edl->local_session;
2295 gui->lock_window("MWindow::to_clip 1");
2296 double start = all ? 0 :
2297 src->inpoint_valid() ? src->get_inpoint() :
2298 src->outpoint_valid() ? 0 : src->get_selectionstart();
2299 double end = all ? edl->tracks->total_length() :
2300 src->outpoint_valid() ? src->get_outpoint() :
2301 src->inpoint_valid() ? edl->tracks->total_length() :
2302 src->get_selectionend();
2303 if( EQUIV(end, start) ) {
2305 end = edl->tracks->total_length();
2308 // Don't copy all since we don't want the clips twice.
2309 edl->copy(copy_flags(), start, end, &file, "", 1);
2311 EDL *new_edl = new EDL(edl);
2312 new_edl->create_objects();
2313 new_edl->load_xml(&file, LOAD_ALL);
2314 save_clip(new_edl, txt);
2315 gui->unlock_window();
2318 int MWindow::toggle_label()
2320 double position1, position2;
2323 position1 = edl->local_session->get_selectionstart(1);
2324 position2 = edl->local_session->get_selectionend(1);
2325 position1 = edl->align_to_frame(position1, 0);
2326 position2 = edl->align_to_frame(position2, 0);
2328 edl->labels->toggle_label(position1, position2);
2331 gui->update_timebar(0);
2332 gui->activate_timeline();
2335 cwindow->gui->lock_window("MWindow::toggle_label 2");
2336 cwindow->gui->timebar->update(1);
2337 cwindow->gui->unlock_window();
2338 awindow->gui->async_update_assets();
2340 undo_after(_("label"), LOAD_TIMEBAR);
2344 void MWindow::trim_selection()
2349 edl->trim_selection(edl->local_session->get_selectionstart(),
2350 edl->local_session->get_selectionend(),
2351 edl->session->labels_follow_edits,
2352 edl->session->plugins_follow_edits,
2353 edl->session->autos_follow_edits);
2356 undo_after(_("trim selection"),
2357 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
2358 update_plugin_guis();
2359 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2360 cwindow->update(1, 0, 0, 0, 1);
2361 awindow->gui->async_update_assets();
2363 cwindow->refresh_frame(CHANGE_EDL);
2367 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2369 calling_window_gui->unlock_window();
2371 if( undo->undo_load_flags() & LOAD_SESSION )
2374 cwindow->gui->lock_window("MWindow::undo_entry 1");
2375 for( int i=0; i<vwindows.size(); ++i ) {
2376 if( vwindows.get(i)->is_running() ) {
2377 if( calling_window_gui != vwindows.get(i)->gui ) {
2378 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2382 gui->lock_window("MWindow::undo_entry 2");
2388 update_plugin_states();
2389 update_plugin_guis();
2391 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2392 gui->update_proxy_toggle();
2393 gui->unlock_window();
2394 cwindow->gui->unlock_window();
2395 cwindow->update(1, 1, 1, 1, 1);
2397 for( int i=0; i<vwindows.size(); ++i ) {
2398 if( vwindows.get(i)->is_running() ) {
2399 if( calling_window_gui != vwindows.get(i)->gui ) {
2400 vwindows.get(i)->gui->unlock_window();
2405 awindow->gui->async_update_assets();
2407 cwindow->refresh_frame(CHANGE_ALL);
2408 calling_window_gui->lock_window("MWindow::undo_entry 4");
2412 void MWindow::new_folder(const char *new_folder, int is_clips)
2415 if( edl->new_folder(new_folder, is_clips) ) {
2416 MainError::show_error(_("create new folder failed"));
2418 undo_after(_("new folder"), LOAD_ALL);
2419 awindow->gui->async_update_assets();
2422 void MWindow::delete_folder(char *folder)
2425 if( edl->delete_folder(folder) < 0 ) {
2426 MainError::show_error(_("delete folder failed"));
2428 undo_after(_("del folder"), LOAD_ALL);
2429 awindow->gui->async_update_assets();
2432 void MWindow::select_point(double position)
2434 gui->unlock_window();
2435 gui->stop_drawing();
2436 cwindow->stop_playback(0);
2437 gui->lock_window("MWindow::select_point");
2439 edl->local_session->set_selectionstart(position);
2440 edl->local_session->set_selectionend(position);
2443 cwindow->update(1, 0, 0, 0, 1);
2445 update_plugin_guis();
2446 gui->update_patchbay();
2447 gui->hide_cursor(0);
2448 gui->draw_cursor(0);
2449 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2450 gui->zoombar->update();
2451 gui->update_timebar(0);
2452 gui->flash_canvas(0);
2459 void MWindow::map_audio(int pattern)
2462 remap_audio(pattern);
2464 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2466 sync_parameters(CHANGE_PARAMS);
2467 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2470 void MWindow::remap_audio(int pattern)
2472 int current_channel = 0;
2473 int current_track = 0;
2474 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2475 if( current->data_type == TRACK_AUDIO &&
2476 current->is_armed() ) {
2477 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2478 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2480 for( int i=0; i < MAXCHANNELS; ++i ) {
2481 pan_auto->values[i] = 0.0;
2484 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2485 pan_auto->values[current_channel] = 1.0;
2488 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2489 switch( current_track ) {
2492 pan_auto->values[0] = 1;
2496 pan_auto->values[1] = 1;
2500 pan_auto->values[0] = 0.5;
2501 pan_auto->values[1] = 0.5;
2506 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2507 edl->session->achannel_positions, pan_auto->values,
2508 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2512 if( current_channel >= edl->session->audio_channels )
2513 current_channel = 0;
2519 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2521 edl->rescale_proxy(orig_scale, new_scale);
2524 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2526 edl->add_proxy(orig_assets, proxy_assets);
2529 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2530 float beep, int to_proxy, int remove_originals)
2532 if( !convert_render )
2533 convert_render = new ConvertRender(this);
2534 convert_render->set_format(format_asset, suffix, to_proxy);
2535 int found = convert_render->find_convertable_assets(edl);
2536 if( convert_render->needed_idxbls.size() > 0 )
2537 convert_render->start_convert(beep, remove_originals);
2538 else if( found > 0 )
2539 finish_convert(remove_originals);
2540 else if( found < 0 )
2541 eprintf(_("convert assets format error"));
2543 eprintf(_("No convertable assets found"));
2546 void MWindow::finish_convert(int remove_originals)
2548 gui->lock_window("MWindow::finish_convert");
2550 edl->replace_assets(
2551 convert_render->orig_idxbls,
2552 convert_render->orig_copies);
2553 if( remove_originals ) {
2554 remove_assets_from_project(0, 0, 0,
2555 &convert_render->orig_idxbls, 0);
2558 undo_after(_("convert"), LOAD_ALL);
2560 update_plugin_guis();
2561 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2562 cwindow->update(1, 0, 0, 0, 1);
2563 awindow->gui->async_update_assets();
2564 cwindow->refresh_frame(CHANGE_EDL);
2565 gui->unlock_window();
2568 void MWindow::cut_commercials()
2570 #ifdef HAVE_COMMERCIAL
2572 commercials->scan_media();
2575 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2578 update_plugin_guis();
2579 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2580 cwindow->update(1, 0, 0, 0, 1);
2581 cwindow->refresh_frame(CHANGE_EDL);
2585 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl, int edit_speed)
2587 int edit_plugins = edl->session->plugins_follow_edits;
2588 int edit_autos = edl->session->autos_follow_edits;
2589 int edit_labels = edl->session->labels_follow_edits;
2590 if( !edit_autos ) edit_speed = 0;
2591 int result = 0, first_track = 1;
2592 Track *old_track = old_edl->tracks->first;
2593 Track *new_track = new_edl->tracks->first;
2594 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2595 if( old_track->data_type != new_track->data_type ) continue;
2596 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2597 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2598 if( !old_speeds || !new_speeds ) continue;
2599 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2600 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2601 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2602 old_speed = (FloatAuto *)old_speed->next;
2603 new_speed = (FloatAuto *)new_speed->next;
2605 if( !old_speed && !new_speed ) continue;
2608 Autos *old_autos = old_track->automation->autos[AUTOMATION_SPEED];
2609 Autos *new_autos = new_track->automation->autos[AUTOMATION_SPEED];
2610 Auto *old_auto = old_autos ? old_autos->first : 0;
2611 for( ; old_auto; old_auto=old_auto->next ) {
2612 Auto *new_auto = new_autos->get_auto(old_auto->orig_id);
2613 if( !new_auto ) continue;
2614 int64_t auto_pos = old_auto->position;
2615 double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
2616 auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2617 new_auto->position = auto_pos;
2620 Edit *old_edit = old_track->edits->first;
2621 for( ; old_edit; old_edit=old_edit->next ) {
2622 Edit *new_edit = new_track->edits->get_edit(old_edit->orig_id);
2623 if( !new_edit ) continue;
2624 int64_t edit_start = old_edit->startproject;
2625 int64_t edit_end = edit_start + old_edit->length;
2626 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2627 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2628 edit_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
2629 edit_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
2630 new_edit->startproject = edit_start;
2631 new_edit->length = edit_end - edit_start;
2633 if( first_track && old_track->is_armed() ) {
2634 Labels *old_labels = old_edl->labels;
2635 Labels *new_labels = new_edl->labels;
2636 if( edit_labels && old_labels && new_labels ) {
2637 Label *old_label = old_labels->first;
2638 for( ; old_label; old_label=old_label->next ) {
2639 Label *new_label = new_labels->get_label(old_label->orig_id);
2640 if( !new_label ) continue;
2641 int64_t label_pos = old_track->to_units(old_label->position, 1);
2642 double orig_pos = old_speeds->automation_integral(0, label_pos, PLAY_FORWARD);
2643 label_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2644 new_label->position = new_track->from_units(label_pos);
2649 if( edit_plugins ) {
2650 int old_size = old_track->plugin_set.size();
2651 int new_size = new_track->plugin_set.size();
2652 int n = bmin(old_size, new_size);
2653 for( int i=0; i<n; ++i ) {
2654 PluginSet *old_plugin_set = old_track->plugin_set[i];
2655 if( !old_plugin_set ) continue;
2656 PluginSet *new_plugin_set = new_track->plugin_set[i];
2657 if( !new_plugin_set ) continue;
2658 Plugin *old_plugin = (Plugin *)old_plugin_set->first;
2659 for( ; old_plugin; old_plugin=(Plugin *)old_plugin->next ) {
2660 Plugin *new_plugin = (Plugin *)new_plugin_set->get_edit(old_plugin->orig_id);
2661 if( !new_plugin ) continue;
2662 int64_t plugin_start = old_plugin->startproject;
2663 int64_t plugin_end = plugin_start + old_plugin->length;
2664 double orig_start = old_speeds->automation_integral(0, plugin_start, PLAY_FORWARD);
2665 double orig_end = old_speeds->automation_integral(0, plugin_end, PLAY_FORWARD);
2666 plugin_start = new_track->frame_align(new_speeds->speed_position(orig_start), 1);
2667 plugin_end = new_track->frame_align(new_speeds->speed_position(orig_end), 1);
2668 new_plugin->startproject = plugin_start;
2669 new_plugin->length = plugin_end - plugin_start;
2671 KeyFrames *old_keyframes = old_plugin->keyframes;
2672 if( !old_keyframes ) continue;
2673 KeyFrames *new_keyframes = new_plugin->keyframes;
2674 if( !new_keyframes ) continue;
2675 Auto *old_auto = old_keyframes->first;
2676 for( ; old_auto; old_auto=old_auto->next ) {
2677 Auto *new_auto = new_keyframes->get_auto(old_auto->orig_id);
2678 if( !new_auto ) continue;
2679 int64_t auto_pos = old_auto->position;
2680 double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
2681 auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2682 new_auto->position = auto_pos;
2683 old_auto = old_auto->next;
2689 if( edit_autos ) { // speed must be last
2690 for( int i=0; i<AUTOMATION_SPEED; ++i ) {
2691 Autos *old_autos = old_track->automation->autos[i];
2692 if( !old_autos ) continue;
2693 Autos *new_autos = new_track->automation->autos[i];
2694 if( !new_autos ) continue;
2695 Auto *old_auto = old_autos->first;
2696 for( ; old_auto; old_auto=old_auto->next ) {
2697 Auto *new_auto = new_autos->get_auto(old_auto->orig_id);
2698 if( !new_auto ) continue;
2699 int64_t auto_pos = old_auto->position;
2700 double orig_pos = old_speeds->automation_integral(0, auto_pos, PLAY_FORWARD);
2701 auto_pos = new_track->frame_align(new_speeds->speed_position(orig_pos), 1);
2702 new_auto->position = auto_pos;
2710 void MWindow::speed_before()
2713 speed_edl = new EDL;
2714 speed_edl->create_objects();
2716 speed_edl->copy_all(edl);
2719 int MWindow::speed_after(int done, int edit_speed)
2724 result = normalize_speed(speed_edl, edl, edit_speed);
2726 speed_edl->remove_user();
2733 void MWindow::collect_effects()
2736 const char *file_string = "";
2738 int ret = edl->collect_effects(group);
2740 case COLLECT_EFFECTS_RECORD:
2741 eprintf(_("Selected edit track not armed."));
2743 case COLLECT_EFFECTS_MULTIPLE:
2744 eprintf(_("More than one edit selected on a track."));
2746 case COLLECT_EFFECTS_MISSING:
2747 eprintf(_("No effects under selected edit."));
2749 case COLLECT_EFFECTS_EMPTY:
2750 eprintf(_("No edits selected."));
2752 case COLLECT_EFFECTS_MASTER:
2753 eprintf(_("Shared effect added without master."));
2756 group->save_xml(&file, "");
2757 file_string = file.string();
2758 group->remove_user();
2760 long file_length = strlen(file_string);
2761 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2762 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2765 void MWindow::paste_effects()
2768 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2770 string = new char[len];
2771 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2773 if( !string || !string[0] ) {
2774 eprintf(_("Error clipboard buffer empty."));
2778 file.read_from_string(string);
2779 EDL *group = new EDL();
2780 group->create_objects();
2781 if( !group->load_xml(&file, LOAD_ALL) ) {
2783 int ret = edl->insert_effects(group);
2785 case INSERT_EFFECTS_RECORD:
2786 eprintf(_("Selected edit track not armed."));
2788 case INSERT_EFFECTS_TYPE:
2789 eprintf(_("Track type mismatched."));
2791 case INSERT_EFFECTS_MULTIPLE:
2792 eprintf(_("More than one edit selected on a track."));
2794 case INSERT_EFFECTS_MISSING:
2795 eprintf(_("Too few target edits to add group effects."));
2797 case INSERT_EFFECTS_EXTRA:
2798 eprintf(_("Too many target edits to add group effects."));
2800 case INSERT_EFFECTS_MASTER:
2801 eprintf(_("Shared effect added without master."));
2807 undo_after(_("paste effects"), LOAD_ALL);
2809 cwindow->refresh_frame(CHANGE_EDL);
2810 update_plugin_guis();
2811 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2814 eprintf(_("Error loading clip from clipboard buffer."));
2816 group->remove_user();
2819 void MWindow::align_timecodes()
2822 double offset = edl->tracks->align_timecodes();
2823 set_timecode_offset(offset);
2825 undo_after(_("align timecodes"), LOAD_ALL);
2827 cwindow->refresh_frame(CHANGE_EDL);
2828 update_plugin_guis();
2832 int MWindow::masters_to_mixers()
2834 Track *master_track = edl->tracks->first;
2835 while( master_track && !master_track->master )
2836 master_track = master_track->next;
2837 while( master_track ) { // test for track/mixer conflicts
2839 Track *mixer_last = master_track;
2840 Track *track = master_track->next;
2841 for( ; track && !track->master; track=track->next )
2843 Track *next_track = track;
2844 Mixer *master_mixer = 0;
2845 for( int i=0, n=edl->mixers.size(); i<n; ++i ) {
2846 if( master_track->index_in(edl->mixers[i]) >= 0 ) {
2847 master_mixer = edl->mixers[i];
2851 if( master_mixer ) { // existing mixer track group
2852 for( track=master_track; !failed && track; track=track->next ) {
2853 if( track->index_in(master_mixer) < 0 ) {
2854 eprintf("Mixer: %s missing track: %s",
2855 master_mixer->title, track->title);
2858 if( track == mixer_last ) break;
2860 for( int i=0, n=master_mixer->mixer_ids.size(); !failed && i<n; ++i ) {
2861 int mixer_id = master_mixer->mixer_ids[i], found = 0;
2862 for( track=master_track; track; track=track->next ) {
2863 if( track->mixer_id == mixer_id ) {
2867 if( track == mixer_last ) break;
2870 eprintf("Mixer: %s track missing: %s",
2871 master_mixer->title, track->title);
2876 else { // create mixer
2877 for( track=master_track->next; !failed && track; track=track->next ) {
2878 for( int i=0, n=edl->mixers.size(); !failed && i<n; ++i ) {
2879 Mixer *mixer = edl->mixers[i];
2880 if( track->index_in(mixer) >= 0 ) {
2881 eprintf("Track: %s already exists in mixer: %s",
2882 track->title, mixer->title);
2887 if( track == mixer_last ) break;
2889 if( !failed ) { // new mixer
2890 ZWindow *zwindow = get_mixer(master_mixer);
2891 zwindow->set_title(master_track->title);
2892 sprintf(master_track->title, _("Mixer %d"), zwindow->idx);
2893 for( track=master_track; track; track=track->next ) {
2894 track->play = track->armed = 0;
2895 master_mixer->mixer_ids.append(track->get_mixer_id());
2896 if( track == mixer_last ) break;
2901 master_track = next_track;
2906 void MWindow::mix_masters()
2909 masters_to_mixers();
2910 undo_after(_("mix masters"), LOAD_ALL);
2913 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
2914 gui->activate_timeline();
2915 cwindow->refresh_frame(CHANGE_EDL);
2919 void MWindow::create_keyframes(int mask, int mode)
2922 double start = edl->local_session->get_selectionstart();
2923 edl->tracks->create_keyframes(start, mask, mode);
2924 double end = edl->local_session->get_selectionend();
2926 edl->tracks->create_keyframes(end, mask, mode);
2927 undo_after(_("create kyfrms"), LOAD_AUTOMATION);
2930 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
2931 gui->activate_timeline();
2932 cwindow->refresh_frame(CHANGE_EDL);