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"
30 #include "cplayback.h"
33 #include "cwindowgui.h"
36 #include "edlsession.h"
37 #include "filesystem.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
42 #include "gwindowgui.h"
44 #include "keyframes.h"
47 #include "levelwindow.h"
48 #include "localsession.h"
49 #include "mainclock.h"
50 #include "maincursor.h"
51 #include "mainerror.h"
52 #include "mainindexes.h"
54 #include "mainsession.h"
56 #include "maskautos.h"
58 #include "mwindowgui.h"
62 #include "playbackengine.h"
63 #include "pluginset.h"
64 #include "recordlabel.h"
65 #include "samplescroll.h"
66 #include "trackcanvas.h"
68 #include "trackscroll.h"
70 #include "transition.h"
71 #include "transportque.h"
73 #include "undostackitem.h"
74 #include "vplayback.h"
76 #include "vwindowgui.h"
79 #include "automation.h"
80 #include "maskautos.h"
84 void MWindow::add_audio_track_entry(int above, Track *dst)
87 add_audio_track(above, dst);
89 undo_after(_("add track"), LOAD_ALL);
92 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
93 gui->activate_timeline();
95 // gui->get_scrollbars(0);
96 // gui->canvas->draw();
97 // gui->patchbay->update();
98 // gui->cursor->draw(1);
99 // gui->canvas->flash();
100 // gui->canvas->activate();
101 cwindow->refresh_frame(CHANGE_EDL);
104 void MWindow::add_video_track_entry(Track *dst)
107 add_video_track(1, dst);
108 undo_after(_("add track"), LOAD_ALL);
112 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
113 gui->activate_timeline();
114 // gui->get_scrollbars(0);
115 // gui->canvas->draw();
116 // gui->patchbay->update();
117 // gui->cursor->draw(1);
118 // gui->canvas->flash();
119 // gui->canvas->activate();
120 cwindow->refresh_frame(CHANGE_EDL);
124 void MWindow::add_subttl_track_entry(Track *dst)
127 add_subttl_track(1, dst);
128 undo_after(_("add track"), LOAD_ALL);
132 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
133 gui->activate_timeline();
134 // gui->get_scrollbars(0);
135 // gui->canvas->draw();
136 // gui->patchbay->update();
137 // gui->cursor->draw(1);
138 // gui->canvas->flash();
139 // gui->canvas->activate();
140 cwindow->refresh_frame(CHANGE_EDL);
145 int MWindow::add_audio_track(int above, Track *dst)
147 edl->tracks->add_audio_track(above, dst);
148 edl->tracks->update_y_pixels(theme);
153 int MWindow::add_video_track(int above, Track *dst)
155 edl->tracks->add_video_track(above, dst);
156 edl->tracks->update_y_pixels(theme);
161 int MWindow::add_subttl_track(int above, Track *dst)
163 edl->tracks->add_subttl_track(above, dst);
164 edl->tracks->update_y_pixels(theme);
169 void MWindow::asset_to_all()
171 if( !session->drag_assets->size() ) return;
172 Indexable *indexable = session->drag_assets->get(0);
174 // if( indexable->have_video() )
181 w = indexable->get_w();
182 h = indexable->get_h();
183 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
184 double old_framerate = edl->session->frame_rate;
185 int old_samplerate = edl->session->sample_rate;
186 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
189 if( indexable->have_video() ) {
190 edl->session->output_w = w;
191 edl->session->output_h = h;
192 edl->session->frame_rate = new_framerate;
194 edl->session->aspect_w,
195 edl->session->aspect_h,
198 for( Track *current=edl->tracks->first; current; current=NEXT ) {
199 if( current->data_type == TRACK_VIDEO /* &&
200 current->record */ ) {
201 current->track_w = w;
202 current->track_h = h;
207 if( ((edl->session->output_w % 4) ||
208 (edl->session->output_h % 4)) &&
209 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
210 MainError::show_error(
211 _("This project's dimensions are not multiples of 4 so\n"
212 "it can't be rendered by OpenGL."));
216 if( defaults->get("AUTOASPECT", 0) ) {
218 edl->session->aspect_w,
219 edl->session->aspect_h,
224 if( indexable->have_audio() ) {
225 edl->session->sample_rate = new_samplerate;
226 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
227 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
232 undo_after(_("asset to all"), LOAD_ALL);
234 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
235 sync_parameters(CHANGE_ALL);
239 void MWindow::asset_to_size()
241 if( !session->drag_assets->size() ) return;
242 Indexable *indexable = session->drag_assets->get(0);
244 if( indexable->have_video() ) {
249 w = indexable->get_w();
250 h = indexable->get_h();
251 edl->session->output_w = w;
252 edl->session->output_h = h;
254 if( ((edl->session->output_w % 4) ||
255 (edl->session->output_h % 4)) &&
256 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
257 MainError::show_error(
258 _("This project's dimensions are not multiples of 4 so\n"
259 "it can't be rendered by OpenGL."));
263 if( defaults->get("AUTOASPECT", 0) ) {
264 create_aspect_ratio(edl->session->aspect_w,
265 edl->session->aspect_h,
272 undo_after(_("asset to size"), LOAD_ALL);
274 sync_parameters(CHANGE_ALL);
279 void MWindow::asset_to_rate()
281 if( session->drag_assets->size() &&
282 session->drag_assets->get(0)->have_video() ) {
283 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
284 double old_framerate = edl->session->frame_rate;
287 edl->session->frame_rate = new_framerate;
288 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
292 undo_after(_("asset to rate"), LOAD_ALL);
294 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
295 sync_parameters(CHANGE_ALL);
300 void MWindow::clear_entry()
307 undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
310 update_plugin_guis();
311 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
312 cwindow->update(1, 0, 0, 0, 1);
313 cwindow->refresh_frame(CHANGE_EDL);
316 void MWindow::clear(int clear_handle)
318 double start = edl->local_session->get_selectionstart();
319 double end = edl->local_session->get_selectionend();
320 if( clear_handle || !EQUIV(start, end) ) {
323 edl->session->labels_follow_edits,
324 edl->session->plugins_follow_edits,
325 edl->session->autos_follow_edits);
329 void MWindow::update_gui(int changed_edl)
332 update_plugin_guis();
334 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
335 cwindow->update(1, 0, 0, 0, 1);
336 cwindow->refresh_frame(CHANGE_EDL);
339 gui->draw_overlays(1);
340 sync_parameters(CHANGE_PARAMS);
341 gui->update_patchbay();
342 cwindow->update(1, 0, 0);
346 void MWindow::set_automation_mode(int mode)
350 edl->tracks->set_automation_mode(
351 edl->local_session->get_selectionstart(),
352 edl->local_session->get_selectionend(),
354 int changed_edl = speed_after(1);
356 char string[BCSTRLEN];
357 sprintf(string,"set %s", FloatAuto::curve_name(mode));
359 !changed_edl ? LOAD_AUTOMATION :
360 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
361 update_gui(changed_edl);
364 void MWindow::clear_automation()
368 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
369 edl->local_session->get_selectionend());
370 int changed_edl = speed_after(1);
372 undo_after(_("clear keyframes"),
373 !changed_edl ? LOAD_AUTOMATION :
374 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
375 update_gui(changed_edl);
378 int MWindow::clear_default_keyframe()
382 edl->tracks->clear_default_keyframe();
383 int changed_edl = speed_after(1);
385 undo_after(_("clear default keyframe"),
386 !changed_edl ? LOAD_AUTOMATION :
387 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
388 update_gui(changed_edl);
392 void MWindow::clear_labels()
395 clear_labels(edl->local_session->get_selectionstart(),
396 edl->local_session->get_selectionend());
397 undo_after(_("clear labels"), LOAD_TIMEBAR);
399 gui->update_timebar(1);
400 cwindow->update(0, 0, 0, 0, 1);
404 int MWindow::clear_labels(double start, double end)
408 end = edl->tracks->total_length();
410 edl->labels->clear(start, end, 0);
414 void MWindow::clear_hard_edges()
417 clear_hard_edges(edl->local_session->get_selectionstart(),
418 edl->local_session->get_selectionend());
421 undo_after(_("clear hard edges"), LOAD_EDITS);
423 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
424 cwindow->refresh_frame(CHANGE_EDL);
427 int MWindow::clear_hard_edges(double start, double end)
431 end = edl->tracks->total_length();
433 edl->clear_hard_edges(start, end);
437 void MWindow::clear_select()
439 edl->tracks->clear_selected_edits();
440 gui->draw_overlays(1);
443 void MWindow::concatenate_tracks()
446 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
447 edl->session->autos_follow_edits);
449 undo_after(_("concatenate tracks"), LOAD_EDITS);
452 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
453 cwindow->refresh_frame(CHANGE_EDL);
457 int MWindow::copy_flags(int copy_flags)
459 if( !edl->session->labels_follow_edits )
460 copy_flags &= ~COPY_LABELS;
461 if( !edl->session->autos_follow_edits )
462 copy_flags &= ~COPY_AUTOS;
463 if( !edl->session->plugins_follow_edits )
464 copy_flags &= ~COPY_PLUGINS;
470 copy(edl->local_session->get_selectionstart(),
471 edl->local_session->get_selectionend());
474 int MWindow::copy(double start, double end)
476 if( start == end ) return 1;
479 edl->copy(copy_flags(), start, end, &file, "", 1);
480 const char *file_string = file.string();
481 long file_length = strlen(file_string);
482 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
483 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
488 int MWindow::copy_automation()
491 double start = edl->local_session->get_selectionstart();
492 double end = edl->local_session->get_selectionend();
493 edl->tracks->copy_automation(start, end, &file, 0, 1);
494 const char *file_string = file.string();
495 long file_length = strlen(file_string);
496 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
497 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
501 int MWindow::copy_default_keyframe()
504 double start = edl->local_session->get_selectionstart();
505 double end = edl->local_session->get_selectionend();
506 edl->tracks->copy_automation(start, end, &file, 1, 0);
507 const char *file_string = file.string();
508 long file_length = strlen(file_string);
509 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
510 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
515 // Uses cropping coordinates in edl session to crop and translate video.
516 // We modify the projector since camera automation depends on the track size.
517 void MWindow::crop_video()
521 // Clamp EDL crop region
522 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
523 edl->session->crop_x1 ^= edl->session->crop_x2;
524 edl->session->crop_x2 ^= edl->session->crop_x1;
525 edl->session->crop_x1 ^= edl->session->crop_x2;
527 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
528 edl->session->crop_y1 ^= edl->session->crop_y2;
529 edl->session->crop_y2 ^= edl->session->crop_y1;
530 edl->session->crop_y1 ^= edl->session->crop_y2;
533 float old_projector_x = (float)edl->session->output_w / 2;
534 float old_projector_y = (float)edl->session->output_h / 2;
535 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
536 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
537 float projector_offset_x = -(new_projector_x - old_projector_x);
538 float projector_offset_y = -(new_projector_y - old_projector_y);
540 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
542 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
543 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
544 edl->session->crop_x1 = 0;
545 edl->session->crop_y1 = 0;
546 edl->session->crop_x2 = edl->session->output_w;
547 edl->session->crop_y2 = edl->session->output_h;
549 // Recalculate aspect ratio
550 if( defaults->get("AUTOASPECT", 0) ) {
551 create_aspect_ratio(edl->session->aspect_w,
552 edl->session->aspect_h,
553 edl->session->output_w,
554 edl->session->output_h);
557 undo_after(_("crop"), LOAD_ALL);
560 cwindow->refresh_frame(CHANGE_ALL);
566 double start = edl->local_session->get_selectionstart();
567 double end = edl->local_session->get_selectionend();
568 if( EQUIV(start,end) )
574 void MWindow::blade(double position)
577 edl->blade(position);
580 undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
582 update_plugin_guis();
583 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
584 cwindow->update(1, 0, 0, 0, 1);
585 awindow->gui->async_update_assets();
586 cwindow->refresh_frame(CHANGE_EDL);
589 void MWindow::cut(double start, double end, double new_position)
593 edl->clear(start, end,
594 edl->session->labels_follow_edits,
595 edl->session->plugins_follow_edits,
596 edl->session->autos_follow_edits);
600 undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
601 if( new_position >= 0 ) {
602 edl->local_session->set_selectionstart(new_position);
603 edl->local_session->set_selectionend(new_position);
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_left_edit()
615 double start_pos = edl->local_session->get_selectionstart(1);
616 double position = edl->prev_edit(start_pos);
617 if( position < start_pos )
618 cut(position, start_pos, position);
621 void MWindow::cut_right_edit()
623 double end_pos = edl->local_session->get_selectionend(1);
624 double position = edl->next_edit(end_pos);
625 if( end_pos < position )
626 cut(end_pos, position, end_pos);
629 void MWindow::cut_left_label()
631 double start_pos = edl->local_session->get_selectionstart(1);
632 Label *left_label = edl->labels->prev_label(start_pos);
633 if( !left_label ) return;
634 double position = left_label->position;
635 if( position < start_pos )
636 cut(position, start_pos, position);
639 void MWindow::cut_right_label()
641 double end_pos = edl->local_session->get_selectionend(1);
642 Label *right_label = edl->labels->next_label(end_pos);
643 if( !right_label ) return;
644 double position = right_label->position;
645 if( end_pos < position )
646 cut(end_pos, position, end_pos);
649 int MWindow::cut_automation()
654 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
655 edl->local_session->get_selectionend());
656 int changed_edl = speed_after(1);
658 undo_after(_("cut keyframes"),
659 !changed_edl ? LOAD_AUTOMATION :
660 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
661 update_gui(changed_edl);
665 int MWindow::cut_default_keyframe()
670 copy_default_keyframe();
671 edl->tracks->clear_default_keyframe();
672 int changed_edl = speed_after(1);
674 undo_after(_("cut default keyframe"),
675 !changed_edl ? LOAD_AUTOMATION :
676 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
677 update_gui(changed_edl);
682 void MWindow::delete_tracks()
685 edl->tracks->delete_tracks();
686 undo_after(_("delete tracks"), LOAD_ALL);
690 update_plugin_states();
692 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
693 cwindow->refresh_frame(CHANGE_EDL);
696 void MWindow::delete_track(Track *track)
699 edl->tracks->delete_track(track);
700 undo_after(_("delete track"), LOAD_ALL);
703 update_plugin_states();
705 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
706 cwindow->refresh_frame(CHANGE_EDL);
711 // Insert data from clipboard
712 void MWindow::insert(double position, FileXML *file,
713 int edit_labels, int edit_plugins, int edit_autos,
714 EDL *parent_edl, Track *first_track, int overwrite)
716 // For clipboard pasting make the new edl use a separate session
717 // from the master EDL. Then it can be resampled to the master rates.
718 // For splice, overwrite, and dragging need same session to get the assets.
719 EDL *edl = new EDL(parent_edl);
720 ArrayList<EDL*> new_edls;
721 uint32_t load_flags = LOAD_ALL;
724 new_edls.append(edl);
725 edl->create_objects();
730 if( parent_edl ) load_flags &= ~LOAD_SESSION;
731 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
732 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
734 edl->load_xml(file, load_flags);
737 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
741 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
742 edit_labels, edit_plugins, edit_autos, overwrite);
743 // if( vwindow->edl )
744 // printf("MWindow::insert 5 %f %f\n",
745 // vwindow->edl->local_session->in_point,
746 // vwindow->edl->local_session->out_point);
747 new_edls.remove_all();
748 edl->Garbage::remove_user();
749 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
752 void MWindow::insert_effects_canvas(double start,
755 Track *dest_track = session->track_highlighted;
756 if( !dest_track ) return;
760 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
761 PluginServer *plugin = session->drag_pluginservers->values[i];
762 insert_effect(plugin->title, 0, dest_track,
763 i == 0 ? session->pluginset_highlighted : 0,
764 start, length, PLUGIN_STANDALONE);
768 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
770 sync_parameters(CHANGE_EDL);
771 // GUI updated in TrackCanvas, after current_operations are reset
774 void MWindow::insert_effects_cwindow(Track *dest_track)
776 if( !dest_track ) return;
781 double length = dest_track->get_length();
783 if( edl->local_session->get_selectionend() >
784 edl->local_session->get_selectionstart() ) {
785 start = edl->local_session->get_selectionstart();
786 length = edl->local_session->get_selectionend() -
787 edl->local_session->get_selectionstart();
790 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
791 PluginServer *plugin = session->drag_pluginservers->values[i];
792 insert_effect(plugin->title, 0, dest_track, 0,
793 start, length, PLUGIN_STANDALONE);
797 undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
799 sync_parameters(CHANGE_EDL);
800 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
803 void MWindow::insert_effect(char *title,
804 SharedLocation *shared_location,
807 int single_standalone)
809 Track *current = edl->tracks->first;
810 SharedLocation shared_location_local;
811 shared_location_local.copy_from(shared_location);
813 for( ; current; current=NEXT ) {
814 if( current->data_type == data_type &&
816 insert_effect(title, &shared_location_local,
817 current, 0, 0, 0, plugin_type);
820 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
821 plugin_type = PLUGIN_SHAREDPLUGIN;
822 shared_location_local.module = edl->tracks->number_of(current);
823 shared_location_local.plugin = current->plugin_set.total - 1;
832 void MWindow::insert_effect(char *title,
833 SharedLocation *shared_location,
835 PluginSet *plugin_set,
840 KeyFrame *default_keyframe = 0;
841 PluginServer *server = 0;
842 // Get default keyframe
843 if( plugin_type == PLUGIN_STANDALONE ) {
844 default_keyframe = new KeyFrame;
845 server = new PluginServer(*scan_plugindb(title, track->data_type));
847 server->open_plugin(0, preferences, edl, 0);
848 server->save_data(default_keyframe);
850 // Insert plugin object
851 track->insert_effect(title, shared_location,
852 default_keyframe, plugin_set,
853 start, length, plugin_type);
856 if( plugin_type == PLUGIN_STANDALONE ) {
857 server->close_plugin();
859 delete default_keyframe;
863 int MWindow::modify_edithandles()
866 int handle_mode = edl->session->edit_handle_mode[session->drag_button];
867 edl->modify_edithandles(session->drag_start,
868 session->drag_position, session->drag_handle, handle_mode,
869 edl->session->labels_follow_edits,
870 edl->session->plugins_follow_edits,
871 edl->session->autos_follow_edits,
872 session->drag_edit->group_id);
873 finish_modify_handles();
874 //printf("MWindow::modify_handles 1\n");
878 int MWindow::modify_pluginhandles()
882 edl->modify_pluginhandles(session->drag_start,
883 session->drag_position,
884 session->drag_handle,
885 edl->session->edit_handle_mode[session->drag_button],
886 edl->session->labels_follow_edits,
887 edl->session->autos_follow_edits,
888 session->trim_edits);
890 finish_modify_handles();
896 // Common to edithandles and plugin handles
897 void MWindow::finish_modify_handles()
899 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
900 double position = -1;
901 switch( edit_mode ) {
903 position = !session->drag_handle ?
904 session->drag_start : session->drag_position;
908 position = session->drag_position;
912 position = session->drag_start;
915 if( position >= 0 ) {
916 edl->local_session->set_selectionstart(position);
917 edl->local_session->set_selectionend(position);
919 undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
923 sync_parameters(CHANGE_EDL);
924 update_plugin_guis();
925 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
926 // label list can be modified
927 awindow->gui->async_update_assets();
928 cwindow->update(1, 0, 0, 0, 1);
931 void MWindow::match_output_size(Track *track)
934 track->track_w = edl->session->output_w;
935 track->track_h = edl->session->output_h;
937 undo_after(_("match output size"), LOAD_ALL);
940 sync_parameters(CHANGE_EDL);
944 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
946 ArrayList<Edit*> edits;
948 delete_edits(&edits, msg, collapse);
951 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
953 if( !edits->size() ) return;
955 if( edl->session->labels_follow_edits )
956 edl->delete_edit_labels(edits, collapse);
957 edl->delete_edits(edits, collapse);
960 undo_after(msg, LOAD_EDITS);
963 cwindow->refresh_frame(CHANGE_EDL);
964 update_plugin_guis();
965 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
968 void MWindow::delete_edits(int collapse)
970 ArrayList<Edit*> edits;
971 edl->tracks->get_selected_edits(&edits);
972 delete_edits(&edits,_("del edit"), collapse);
975 // collapse - delete from timeline, not collapse replace with silence
976 // packed - omit unselected from selection, unpacked - replace unselected with silence
977 void MWindow::cut_selected_edits(int collapse, int packed)
979 selected_edits_to_clipboard(packed);
980 ArrayList<Edit*> edits;
981 edl->tracks->get_selected_edits(&edits);
982 delete_edits(&edits, _("cut edit"), collapse);
986 void MWindow::move_edits(ArrayList<Edit*> *edits,
987 Track *track, double position, int mode)
990 // lockout timebar labels update
991 // labels can be deleted with tooltip repeater running
992 cwindow->gui->lock_window("Tracks::move_edits");
993 edl->tracks->move_edits(edits, track, position,
994 edl->session->labels_follow_edits,
995 edl->session->plugins_follow_edits,
996 edl->session->autos_follow_edits, mode);
997 cwindow->gui->timebar->update(1);
998 cwindow->gui->unlock_window();
1001 undo_after(_("move edit"), LOAD_ALL);
1004 cwindow->refresh_frame(CHANGE_EDL);
1006 update_plugin_guis();
1007 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1010 void MWindow::selected_edits_to_clipboard(int packed)
1012 EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1013 edl->session->labels_follow_edits,
1014 edl->session->autos_follow_edits,
1015 edl->session->plugins_follow_edits);
1016 if( !new_edl ) return;
1018 new_edl->copy(COPY_EDL, &file, "", 1);
1019 const char *file_string = file.string();
1020 long file_length = strlen(file_string);
1021 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1022 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1023 new_edl->remove_user();
1026 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1027 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1029 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1031 char *string = new char[len];
1032 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1034 file.read_from_string(string);
1036 EDL *clip = new EDL();
1037 clip->create_objects();
1038 if( !clip->load_xml(&file, LOAD_ALL) ) {
1040 edl->paste_edits(clip, first_track, position, overwrite,
1041 edit_edits, edit_labels, edit_autos, edit_plugins);
1043 undo_after(_("paste clip"), LOAD_ALL);
1045 cwindow->refresh_frame(CHANGE_EDL);
1047 update_plugin_guis();
1048 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1050 clip->remove_user();
1053 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1056 // lockout timebar labels update
1057 // labels can be deleted with tooltip repeater running
1058 cwindow->gui->lock_window("Tracks::move_group");
1060 ArrayList<Edit *>edits;
1061 edl->tracks->get_selected_edits(&edits);
1062 if( edl->session->labels_follow_edits )
1063 edl->delete_edit_labels(&edits, 0);
1064 edl->delete_edits(&edits, 0);
1065 edl->paste_edits(group, first_track, position, overwrite, 1,
1066 edl->session->labels_follow_edits,
1067 edl->session->autos_follow_edits,
1068 edl->session->plugins_follow_edits);
1069 cwindow->gui->timebar->update(1);
1070 cwindow->gui->unlock_window();
1071 // big debate over whether to do this, must either clear selected, or no tweaking
1072 // edl->tracks->clear_selected_edits();
1075 undo_after(_("move group"), LOAD_ALL);
1077 cwindow->refresh_frame(CHANGE_EDL);
1079 update_plugin_guis();
1080 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1083 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1086 edl->tracks->move_effect(plugin, track, position);
1088 undo_after(_("paste effect"), LOAD_ALL);
1091 cwindow->refresh_frame(CHANGE_EDL);
1092 update_plugin_guis();
1093 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1096 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1099 edl->tracks->move_effect(plugin, plugin_set, position);
1101 undo_after(_("move effect"), LOAD_ALL);
1104 cwindow->refresh_frame(CHANGE_EDL);
1105 update_plugin_guis();
1106 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1109 void MWindow::move_plugins_up(PluginSet *plugin_set)
1113 plugin_set->track->move_plugins_up(plugin_set);
1116 undo_after(_("move effect up"), LOAD_ALL);
1118 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1119 sync_parameters(CHANGE_EDL);
1122 void MWindow::move_plugins_down(PluginSet *plugin_set)
1126 plugin_set->track->move_plugins_down(plugin_set);
1129 undo_after(_("move effect down"), LOAD_ALL);
1131 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1132 sync_parameters(CHANGE_EDL);
1135 void MWindow::move_track_down(Track *track)
1138 edl->tracks->move_track_down(track);
1140 undo_after(_("move track down"), LOAD_ALL);
1143 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1144 sync_parameters(CHANGE_EDL);
1148 void MWindow::move_tracks_down()
1151 edl->tracks->move_tracks_down();
1153 undo_after(_("move tracks down"), LOAD_ALL);
1156 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1157 sync_parameters(CHANGE_EDL);
1161 void MWindow::move_track_up(Track *track)
1164 edl->tracks->move_track_up(track);
1166 undo_after(_("move track up"), LOAD_ALL);
1168 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1169 sync_parameters(CHANGE_EDL);
1173 void MWindow::move_tracks_up()
1176 edl->tracks->move_tracks_up();
1178 undo_after(_("move tracks up"), LOAD_ALL);
1180 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1181 sync_parameters(CHANGE_EDL);
1185 void MWindow::mute_selection()
1187 double start = edl->local_session->get_selectionstart();
1188 double end = edl->local_session->get_selectionend();
1189 if( start != end ) {
1191 edl->clear(start, end, 0,
1192 edl->session->plugins_follow_edits,
1193 edl->session->autos_follow_edits);
1194 edl->local_session->set_selectionend(end);
1195 edl->local_session->set_selectionstart(start);
1196 edl->paste_silence(start, end, 0,
1197 edl->session->plugins_follow_edits,
1198 edl->session->autos_follow_edits);
1201 undo_after(_("mute"), LOAD_EDITS);
1204 update_plugin_guis();
1205 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1206 cwindow->refresh_frame(CHANGE_EDL);
1211 void MWindow::overwrite(EDL *source, int all)
1215 LocalSession *src = source->local_session;
1216 double src_start = all ? 0 :
1217 src->inpoint_valid() ? src->get_inpoint() :
1218 src->outpoint_valid() ? 0 :
1219 src->get_selectionstart();
1220 double src_end = all ? source->tracks->total_length() :
1221 src->outpoint_valid() ? src->get_outpoint() :
1222 src->inpoint_valid() ? source->tracks->total_length() :
1223 src->get_selectionend();
1224 double overwrite_len = src_end - src_start;
1225 double dst_start = edl->local_session->get_selectionstart();
1226 double dst_len = edl->local_session->get_selectionend() - dst_start;
1229 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1230 // in/out points or selection present and shorter than overwrite range
1231 // shorten the copy range
1232 overwrite_len = dst_len;
1235 source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1237 // HACK around paste_edl get_start/endselection on its own
1238 // so we need to clear only when not using both io points
1239 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1240 if( edl->local_session->get_inpoint() < 0 ||
1241 edl->local_session->get_outpoint() < 0 )
1242 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1244 paste(dst_start, dst_start + overwrite_len, &file, 0, 0, 0, 0, 0);
1246 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1247 edl->local_session->set_selectionend(dst_start + overwrite_len);
1250 undo_after(_("overwrite"), LOAD_EDITS);
1253 update_plugin_guis();
1254 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1255 sync_parameters(CHANGE_EDL);
1258 // For splice and overwrite
1259 int MWindow::paste(double start, double end, FileXML *file,
1260 int edit_labels, int edit_plugins, int edit_autos,
1261 Track *first_track, int overwrite)
1265 // Want to insert with assets shared with the master EDL.
1267 edit_labels, edit_plugins, edit_autos,
1268 edl, first_track, overwrite);
1273 // For editing using insertion point
1274 void MWindow::paste()
1276 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1279 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1281 //double end = edl->local_session->get_selectionend();
1282 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1285 char *string = new char[len];
1287 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1289 file.read_from_string(string);
1290 if( clear_selection ) clear(0);
1292 insert(start, &file,
1293 edl->session->labels_follow_edits,
1294 edl->session->plugins_follow_edits,
1295 edl->session->autos_follow_edits,
1296 0, first_track, overwrite);
1303 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1305 update_plugin_guis();
1306 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1307 awindow->gui->async_update_assets();
1308 sync_parameters(CHANGE_EDL);
1313 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1318 if( session->drag_assets->total ) {
1319 load_assets(session->drag_assets,
1320 position, LOADMODE_PASTE, dest_track, 0,
1321 edl->session->labels_follow_edits,
1322 edl->session->plugins_follow_edits,
1323 edl->session->autos_follow_edits,
1328 if( session->drag_clips->total ) {
1329 paste_edls(session->drag_clips,
1330 LOADMODE_PASTE, dest_track, position,
1331 edl->session->labels_follow_edits,
1332 edl->session->plugins_follow_edits,
1333 edl->session->autos_follow_edits,
1340 undo_after(_("paste assets"), LOAD_EDITS);
1342 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1343 sync_parameters(CHANGE_EDL);
1347 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1348 double position, int load_mode, Track *first_track, RecordLabels *labels,
1349 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1351 if( load_mode == LOADMODE_RESOURCESONLY )
1352 load_mode = LOADMODE_ASSETSONLY;
1353 const int debug = 0;
1354 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1356 position = edl->local_session->get_selectionstart();
1358 ArrayList<EDL*> new_edls;
1359 for( int i=0; i<new_assets->total; ++i ) {
1360 Indexable *indexable = new_assets->get(i);
1361 if( indexable->is_asset ) {
1362 remove_asset_from_caches((Asset*)indexable);
1364 EDL *new_edl = new EDL;
1365 new_edl->create_objects();
1366 new_edl->copy_session(edl);
1367 if( !indexable->is_asset ) {
1368 EDL *nested_edl = (EDL*)indexable;
1369 new_edl->create_nested(nested_edl);
1370 new_edl->set_path(indexable->path);
1373 Asset *asset = (Asset*)indexable;
1374 asset_to_edl(new_edl, asset);
1376 new_edls.append(new_edl);
1379 for( RecordLabel *label=labels->first; label; label=label->next ) {
1380 new_edl->labels->toggle_label(label->position, label->position);
1384 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1386 paste_edls(&new_edls, load_mode, first_track, position,
1387 edit_labels, edit_plugins, edit_autos, overwrite);
1388 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1391 for( int i=0; i<new_edls.size(); ++i )
1392 new_edls.get(i)->Garbage::remove_user();
1394 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1397 int MWindow::paste_automation()
1399 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1404 char *string = new char[len];
1405 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1407 file.read_from_string(string);
1409 double start = edl->local_session->get_selectionstart();
1410 double end = edl->local_session->get_selectionend();
1411 edl->tracks->clear_automation(start, end);
1412 edl->tracks->paste_automation(start, &file, 0, 1,
1413 edl->session->typeless_keyframes);
1414 int changed_edl = speed_after(1);
1416 undo_after(_("paste keyframes"),
1417 !changed_edl ? LOAD_AUTOMATION :
1418 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1419 update_gui(changed_edl);
1425 int MWindow::paste_default_keyframe()
1427 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1432 char *string = new char[len];
1433 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1435 file.read_from_string(string);
1437 double start = edl->local_session->get_selectionstart();
1438 edl->tracks->paste_automation(start, &file, 1, 0,
1439 edl->session->typeless_keyframes);
1440 // edl->tracks->paste_default_keyframe(&file);
1441 int changed_edl = speed_after(1);
1442 undo_after(_("paste default keyframe"),
1443 !changed_edl ? LOAD_AUTOMATION :
1444 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1446 update_gui(changed_edl);
1453 // Insert edls with project deletion and index file generation.
1454 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1455 Track *first_track, double current_position,
1456 int edit_labels, int edit_plugins, int edit_autos,
1460 ArrayList<Track*> destination_tracks;
1461 int need_new_tracks = 0;
1464 if( !new_edls->total ) return 0;
1467 // double original_length = edl->tracks->total_length();
1468 // double original_preview_end = edl->local_session->preview_end;
1471 // Delete current project
1472 if( load_mode == LOADMODE_REPLACE ||
1473 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1475 edl->save_defaults(defaults);
1477 edl->Garbage::remove_user();
1479 edl->create_objects();
1480 edl->copy_session(new_edls->values[0]);
1481 edl->copy_mixers(new_edls->values[0]);
1482 gui->mainmenu->update_toggles(0);
1483 gui->unlock_window();
1484 gwindow->gui->update_toggles(1);
1485 gui->lock_window("MWindow::paste_edls");
1487 // Insert labels for certain modes constitutively
1491 // Force reset of preview
1492 // original_length = 0;
1493 // original_preview_end = -1;
1499 // Create new tracks in master EDL
1500 if( load_mode == LOADMODE_REPLACE ||
1501 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1502 load_mode == LOADMODE_NEW_TRACKS ) {
1504 need_new_tracks = 1;
1505 for( int i=0; i<new_edls->total; ++i ) {
1506 EDL *new_edl = new_edls->values[i];
1507 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1508 switch( current->data_type ) {
1510 edl->tracks->add_video_track(0, 0);
1511 if( current->draw ) edl->tracks->last->draw = 1;
1514 edl->tracks->add_audio_track(0, 0);
1516 case TRACK_SUBTITLE:
1517 edl->tracks->add_subttl_track(0, 0);
1522 // re-label only if not already labeled
1523 if( new_edl->local_session->asset2edl )
1524 strcpy(current->title, edl->tracks->last->title);
1525 destination_tracks.append(edl->tracks->last);
1528 // Base track count on first EDL only for concatenation
1529 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1531 edl->session->highlighted_track = edl->tracks->total() - 1;
1534 // Recycle existing tracks of master EDL
1535 if( load_mode == LOADMODE_CONCATENATE ||
1536 load_mode == LOADMODE_PASTE ||
1537 load_mode == LOADMODE_NESTED ) {
1538 Track *current = first_track ? first_track : edl->tracks->first;
1539 for( ; current; current=NEXT ) {
1540 if( current->record ) {
1541 destination_tracks.append(current);
1547 int destination_track = 0;
1548 double *paste_position = new double[destination_tracks.total];
1550 // Iterate through the edls
1551 for( int i=0; i<new_edls->total; ++i ) {
1553 EDL *new_edl = new_edls->values[i];
1554 double edl_length = new_edl->local_session->clipboard_length ?
1555 new_edl->local_session->clipboard_length :
1556 new_edl->tracks->total_length();
1557 // printf("MWindow::paste_edls 2 %f %f\n",
1558 // new_edl->local_session->clipboard_length,
1559 // new_edl->tracks->total_length());
1563 // Convert EDL to master rates
1564 new_edl->resample(new_edl->session->sample_rate,
1565 edl->session->sample_rate,
1567 new_edl->resample(new_edl->session->frame_rate,
1568 edl->session->frame_rate,
1571 // Add assets and prepare index files
1572 for( Asset *new_asset=new_edl->assets->first;
1573 new_asset; new_asset=new_asset->next ) {
1574 mainindexes->add_next_asset(0, new_asset);
1576 // Capture index file status from mainindex test
1577 edl->update_assets(new_edl);
1579 // Get starting point of insertion. Need this to paste labels.
1580 switch( load_mode ) {
1581 case LOADMODE_REPLACE:
1582 current_position = 0;
1584 case LOADMODE_NEW_TRACKS:
1586 current_position = 0;
1589 case LOADMODE_CONCATENATE:
1590 case LOADMODE_REPLACE_CONCATENATE:
1591 destination_track = 0;
1592 if( destination_tracks.total )
1593 current_position = destination_tracks.values[0]->get_length();
1595 current_position = 0;
1598 case LOADMODE_PASTE:
1599 case LOADMODE_NESTED:
1600 destination_track = 0;
1602 for( int j=0; j<destination_tracks.total; ++j ) {
1603 paste_position[j] = (current_position >= 0) ?
1605 edl->local_session->get_selectionstart();
1610 case LOADMODE_RESOURCESONLY:
1611 edl->add_clip(new_edl);
1615 if( load_mode != LOADMODE_RESOURCESONLY &&
1616 load_mode != LOADMODE_ASSETSONLY ) {
1619 if( load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED )
1620 edl->labels->insert_labels(new_edl->labels,
1621 destination_tracks.total ? paste_position[0] : 0.0,
1624 edl->labels->insert_labels(new_edl->labels, current_position,
1627 double total_length = new_edl->tracks->total_length();
1628 for( Track *new_track=new_edl->tracks->first;
1629 new_track; new_track=new_track->next ) {
1630 // Get destination track of same type as new_track
1632 k < destination_tracks.total &&
1633 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1634 ++k, ++destination_track ) {
1635 if( destination_track >= destination_tracks.total - 1 )
1636 destination_track = 0;
1639 // Insert data into destination track
1640 if( destination_track < destination_tracks.total &&
1641 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1642 Track *track = destination_tracks.values[destination_track];
1644 // Replace default keyframes if first EDL and new tracks were created.
1645 // This means data copied from one track and pasted to another won't retain
1646 // the camera position unless it's a keyframe. If it did, previous data in the
1647 // track might get unknowingly corrupted. Ideally we would detect when differing
1648 // default keyframes existed and create discrete keyframes for both.
1649 int replace_default = (i == 0) && need_new_tracks;
1651 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1652 // Insert new track at current position
1653 switch( load_mode ) {
1654 case LOADMODE_REPLACE_CONCATENATE:
1655 case LOADMODE_CONCATENATE:
1656 current_position = track->get_length();
1659 case LOADMODE_PASTE:
1660 case LOADMODE_NESTED:
1661 current_position = paste_position[destination_track];
1662 paste_position[destination_track] += new_track->get_length();
1666 double length = overwrite >= 0 ?
1667 new_track->get_length() : total_length;
1668 track->clear(current_position,
1669 current_position + length,
1671 edit_labels, edit_plugins, edit_autos,
1675 track->insert_track(new_track, current_position, replace_default,
1676 edit_plugins, edit_autos, edl_length);
1680 // Get next destination track
1681 destination_track++;
1682 if( destination_track >= destination_tracks.total )
1683 destination_track = 0;
1687 if( load_mode == LOADMODE_PASTE ||
1688 load_mode == LOADMODE_NESTED )
1689 current_position += edl_length;
1693 // Move loading of clips and vwindow to the end - this fixes some
1694 // strange issue, for index not being shown
1695 // Assume any paste operation from the same EDL won't contain any clips.
1696 // If it did it would duplicate every clip here.
1697 for( int i=0; i<new_edls->total; ++i ) {
1698 EDL *new_edl = new_edls->get(i);
1700 for( int j=0; j<new_edl->clips.size(); ++j ) {
1701 edl->add_clip(new_edl->clips[j]);
1703 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1704 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1707 if( new_edl->total_vwindow_edls() ) {
1708 // if( edl->vwindow_edl )
1709 // edl->vwindow_edl->Garbage::remove_user();
1710 // edl->vwindow_edl = new EDL(edl);
1711 // edl->vwindow_edl->create_objects();
1712 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1714 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1715 EDL *vwindow_edl = new EDL(edl);
1716 vwindow_edl->create_objects();
1717 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1718 edl->append_vwindow_edl(vwindow_edl, 0);
1723 if( paste_position ) delete [] paste_position;
1725 // This is already done in load_filenames and everything else that uses paste_edls
1726 // update_project(load_mode);
1728 // Fix preview range
1729 // if( EQUIV(original_length, original_preview_end) )
1731 // edl->local_session->preview_end = edl->tracks->total_length();
1734 // Start examining next batch of index files
1735 mainindexes->start_build();
1737 // Don't save a backup after loading since the loaded file is on disk already.
1742 void MWindow::paste_silence()
1744 double start = edl->local_session->get_selectionstart();
1745 double end = edl->local_session->get_selectionend();
1746 if( EQUIV(start, end) ) {
1747 if( edl->session->frame_rate > 0 )
1748 end += 1./edl->session->frame_rate;
1750 undo_before(_("silence"), this);
1751 edl->paste_silence(start, end,
1752 edl->session->labels_follow_edits,
1753 edl->session->plugins_follow_edits,
1754 edl->session->autos_follow_edits);
1757 undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1759 update_plugin_guis();
1761 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1762 cwindow->update(1, 0, 0, 0, 1);
1763 cwindow->refresh_frame(CHANGE_EDL);
1766 void MWindow::detach_transition(Transition *transition)
1769 hide_plugin(transition, 1);
1770 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1771 transition->edit->detach_transition();
1773 undo_after(_("detach transition"), LOAD_ALL);
1775 if( is_video ) restart_brender();
1776 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1777 sync_parameters(CHANGE_EDL);
1780 void MWindow::detach_transitions()
1782 gui->lock_window("MWindow::detach_transitions 1");
1785 double start = edl->local_session->get_selectionstart();
1786 double end = edl->local_session->get_selectionend();
1787 edl->tracks->clear_transitions(start, end);
1790 undo_after(_("detach transitions"), LOAD_EDITS);
1792 sync_parameters(CHANGE_EDL);
1793 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1794 gui->unlock_window();
1797 void MWindow::paste_transition()
1799 // Only the first transition gets dropped.
1800 PluginServer *server = session->drag_pluginservers->values[0];
1803 edl->tracks->paste_transition(server, session->edit_highlighted);
1805 undo_after(_("transition"), LOAD_EDITS);
1807 if( server->video ) restart_brender();
1808 sync_parameters(CHANGE_ALL);
1811 void MWindow::paste_transitions(int track_type, char *title)
1813 gui->lock_window("MWindow::detach_transitions 1");
1816 double start = edl->local_session->get_selectionstart();
1817 double end = edl->local_session->get_selectionend();
1818 edl->tracks->paste_transitions(start, end, track_type, title);
1820 undo_after(_("attach transitions"), LOAD_EDITS);
1822 sync_parameters(CHANGE_EDL);
1823 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1824 gui->unlock_window();
1827 void MWindow::paste_transition_cwindow(Track *dest_track)
1829 PluginServer *server = session->drag_pluginservers->values[0];
1831 edl->tracks->paste_video_transition(server, 1);
1833 undo_after(_("transition"), LOAD_EDITS);
1835 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1836 sync_parameters(CHANGE_ALL);
1839 void MWindow::paste_audio_transition()
1841 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1844 char string[BCTEXTLEN];
1845 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1846 gui->show_message(string);
1851 edl->tracks->paste_audio_transition(server);
1853 undo_after(_("transition"), LOAD_EDITS);
1855 sync_parameters(CHANGE_EDL);
1856 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1859 void MWindow::paste_video_transition()
1861 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1864 char string[BCTEXTLEN];
1865 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1866 gui->show_message(string);
1872 edl->tracks->paste_video_transition(server);
1874 undo_after(_("transition"), LOAD_EDITS);
1876 sync_parameters(CHANGE_EDL);
1878 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1881 void MWindow::shuffle_edits()
1883 gui->lock_window("MWindow::shuffle_edits 1");
1886 double start = edl->local_session->get_selectionstart();
1887 double end = edl->local_session->get_selectionend();
1889 edl->tracks->shuffle_edits(start, end);
1892 undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1894 sync_parameters(CHANGE_EDL);
1896 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1897 gui->unlock_window();
1900 void MWindow::reverse_edits()
1902 gui->lock_window("MWindow::reverse_edits 1");
1905 double start = edl->local_session->get_selectionstart();
1906 double end = edl->local_session->get_selectionend();
1908 edl->tracks->reverse_edits(start, end);
1911 undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1913 sync_parameters(CHANGE_EDL);
1915 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1916 gui->unlock_window();
1919 void MWindow::align_edits()
1921 gui->lock_window("MWindow::align_edits 1");
1924 double start = edl->local_session->get_selectionstart();
1925 double end = edl->local_session->get_selectionend();
1927 edl->tracks->align_edits(start, end);
1930 undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1932 sync_parameters(CHANGE_EDL);
1934 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1935 gui->unlock_window();
1938 void MWindow::set_edit_length(double length)
1940 gui->lock_window("MWindow::set_edit_length 1");
1943 double start = edl->local_session->get_selectionstart();
1944 double end = edl->local_session->get_selectionend();
1946 edl->tracks->set_edit_length(start, end, length);
1949 undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1951 sync_parameters(CHANGE_EDL);
1953 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1954 gui->unlock_window();
1958 void MWindow::set_transition_length(Transition *transition, double length)
1960 gui->lock_window("MWindow::set_transition_length 1");
1963 //double start = edl->local_session->get_selectionstart();
1964 //double end = edl->local_session->get_selectionend();
1966 edl->tracks->set_transition_length(transition, length);
1969 undo_after(_("transition length"), LOAD_EDITS);
1971 edl->session->default_transition_length = length;
1972 sync_parameters(CHANGE_PARAMS);
1973 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1974 gui->unlock_window();
1977 void MWindow::set_transition_length(double length)
1979 gui->lock_window("MWindow::set_transition_length 2");
1982 double start = edl->local_session->get_selectionstart();
1983 double end = edl->local_session->get_selectionend();
1985 edl->tracks->set_transition_length(start, end, length);
1988 undo_after(_("transition length"), LOAD_EDITS);
1990 edl->session->default_transition_length = length;
1991 sync_parameters(CHANGE_PARAMS);
1993 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1994 gui->unlock_window();
1998 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2000 calling_window_gui->unlock_window();
2002 if( undo->redo_load_flags() & LOAD_SESSION )
2005 cwindow->gui->lock_window("MWindow::redo_entry 1");
2006 for( int i=0; i<vwindows.size(); ++i ) {
2007 if( vwindows.get(i)->is_running() ) {
2008 if( calling_window_gui != vwindows.get(i)->gui ) {
2009 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2013 gui->lock_window("MWindow::redo_entry 3");
2019 update_plugin_states();
2020 update_plugin_guis();
2022 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2023 gui->update_proxy_toggle();
2024 gui->unlock_window();
2025 cwindow->gui->unlock_window();
2026 cwindow->update(1, 1, 1, 1, 1);
2028 for( int i=0; i < vwindows.size(); ++i ) {
2029 if( vwindows.get(i)->is_running() ) {
2030 if( calling_window_gui != vwindows.get(i)->gui ) {
2031 vwindows.get(i)->gui->unlock_window();
2036 awindow->gui->async_update_assets();
2038 cwindow->refresh_frame(CHANGE_ALL);
2039 calling_window_gui->lock_window("MWindow::redo_entry 4");
2043 void MWindow::resize_track(Track *track, int w, int h)
2046 // We have to move all maskpoints so they do not move in relation to image areas
2047 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2048 (w - track->track_w) / 2,
2049 (h - track->track_h) / 2);
2052 undo_after(_("resize track"), LOAD_ALL);
2056 sync_parameters(CHANGE_EDL);
2060 void MWindow::set_inpoint()
2063 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2065 undo_after(_("in point"), LOAD_TIMEBAR);
2066 gui->update_timebar(1);
2068 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2069 cwindow->gui->timebar->update(1);
2070 cwindow->gui->unlock_window();
2073 void MWindow::set_outpoint()
2076 edl->set_outpoint(edl->local_session->get_selectionend(1));
2078 undo_after(_("out point"), LOAD_TIMEBAR);
2080 gui->update_timebar(1);
2081 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2082 cwindow->gui->timebar->update(1);
2083 cwindow->gui->unlock_window();
2086 void MWindow::unset_inoutpoint()
2089 edl->unset_inoutpoint();
2091 undo_after(_("clear in/out"), LOAD_TIMEBAR);
2093 gui->update_timebar(1);
2094 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2095 cwindow->gui->timebar->update(1);
2096 cwindow->gui->unlock_window();
2099 void MWindow::splice(EDL *source, int all)
2102 LocalSession *src = source->local_session;
2105 double source_start = all ? 0 :
2106 src->inpoint_valid() ? src->get_inpoint() :
2107 src->outpoint_valid() ? 0 : src->get_selectionstart();
2108 double source_end = all ? source->tracks->total_length() :
2109 src->outpoint_valid() ? src->get_outpoint() :
2110 src->inpoint_valid() ? source->tracks->total_length() :
2111 src->get_selectionend();
2112 source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2114 double start = edl->local_session->get_selectionstart();
2115 //double end = edl->local_session->get_selectionend();
2117 paste(start, start, &file,
2118 edl->session->labels_follow_edits,
2119 edl->session->plugins_follow_edits,
2120 edl->session->autos_follow_edits,
2123 // Position at end of clip
2124 edl->local_session->set_selectionstart(start + source_end - source_start);
2125 edl->local_session->set_selectionend(start + source_end - source_start);
2128 undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2129 update_plugin_guis();
2131 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2132 sync_parameters(CHANGE_EDL);
2135 void MWindow::save_clip(EDL *new_edl, const char *txt)
2137 new_edl->local_session->set_selectionstart(0);
2138 new_edl->local_session->set_selectionend(0);
2139 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2140 session->clip_number++);
2141 char duration[BCTEXTLEN];
2142 Units::totext(duration, new_edl->tracks->total_length(),
2143 new_edl->session->time_format,
2144 new_edl->session->sample_rate,
2145 new_edl->session->frame_rate,
2146 new_edl->session->frames_per_foot);
2148 Track *track = new_edl->tracks->first;
2149 const char *path = edl->path;
2150 for( ; (!path || !*path) && track; track=track->next ) {
2151 if( !track->record ) continue;
2152 Edit *edit = track->edits->first;
2153 if( !edit ) continue;
2154 Indexable *indexable = edit->get_source();
2155 if( !indexable ) continue;
2156 path = indexable->path;
2159 time_t now; time(&now);
2160 struct tm dtm; localtime_r(&now, &dtm);
2161 char *cp = new_edl->local_session->clip_notes;
2162 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2164 n = snprintf(cp, sz, "%s", txt);
2167 n = snprintf(cp, sz,
2168 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2169 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2170 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2172 if( path && *path ) {
2174 char title[BCTEXTLEN];
2175 fs.extract_name(title, path);
2176 n = snprintf(cp, sz, "%s", title);
2180 sprintf(new_edl->local_session->clip_icon,
2181 "clip_%02d%02d%02d-%02d%02d%02d.png",
2182 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2183 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
2184 new_edl->folder_no = AW_CLIP_FOLDER;
2185 edl->update_assets(new_edl);
2187 gui->get_abs_cursor(cur_x, cur_y, 0);
2188 gui->unlock_window();
2190 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2191 new_edl->remove_user();
2193 gui->lock_window("MWindow::save_clip");
2197 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2200 LocalSession *src = edl->local_session;
2202 gui->lock_window("MWindow::to_clip 1");
2203 double start = all ? 0 :
2204 src->inpoint_valid() ? src->get_inpoint() :
2205 src->outpoint_valid() ? 0 : src->get_selectionstart();
2206 double end = all ? edl->tracks->total_length() :
2207 src->outpoint_valid() ? src->get_outpoint() :
2208 src->inpoint_valid() ? edl->tracks->total_length() :
2209 src->get_selectionend();
2210 if( EQUIV(end, start) ) {
2212 end = edl->tracks->total_length();
2215 // Don't copy all since we don't want the clips twice.
2216 edl->copy(copy_flags(), start, end, &file, "", 1);
2218 EDL *new_edl = new EDL(edl);
2219 new_edl->create_objects();
2220 new_edl->load_xml(&file, LOAD_ALL);
2221 save_clip(new_edl, txt);
2222 gui->unlock_window();
2225 int MWindow::toggle_label()
2227 double position1, position2;
2230 position1 = edl->local_session->get_selectionstart(1);
2231 position2 = edl->local_session->get_selectionend(1);
2232 position1 = edl->align_to_frame(position1, 0);
2233 position2 = edl->align_to_frame(position2, 0);
2235 edl->labels->toggle_label(position1, position2);
2238 gui->update_timebar(0);
2239 gui->activate_timeline();
2242 cwindow->gui->lock_window("MWindow::toggle_label 2");
2243 cwindow->gui->timebar->update(1);
2244 cwindow->gui->unlock_window();
2245 awindow->gui->async_update_assets();
2247 undo_after(_("label"), LOAD_TIMEBAR);
2251 void MWindow::trim_selection()
2256 edl->trim_selection(edl->local_session->get_selectionstart(),
2257 edl->local_session->get_selectionend(),
2258 edl->session->labels_follow_edits,
2259 edl->session->plugins_follow_edits,
2260 edl->session->autos_follow_edits);
2263 undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2264 update_plugin_guis();
2265 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2266 cwindow->update(1, 0, 0, 0, 1);
2267 awindow->gui->async_update_assets();
2269 cwindow->refresh_frame(CHANGE_EDL);
2273 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2275 calling_window_gui->unlock_window();
2277 if( undo->undo_load_flags() & LOAD_SESSION )
2280 cwindow->gui->lock_window("MWindow::undo_entry 1");
2281 for( int i=0; i<vwindows.size(); ++i ) {
2282 if( vwindows.get(i)->is_running() ) {
2283 if( calling_window_gui != vwindows.get(i)->gui ) {
2284 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2288 gui->lock_window("MWindow::undo_entry 2");
2294 update_plugin_states();
2295 update_plugin_guis();
2297 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2298 gui->update_proxy_toggle();
2299 gui->unlock_window();
2300 cwindow->gui->unlock_window();
2301 cwindow->update(1, 1, 1, 1, 1);
2303 for( int i=0; i<vwindows.size(); ++i ) {
2304 if( vwindows.get(i)->is_running() ) {
2305 if( calling_window_gui != vwindows.get(i)->gui ) {
2306 vwindows.get(i)->gui->unlock_window();
2311 awindow->gui->async_update_assets();
2313 cwindow->refresh_frame(CHANGE_ALL);
2314 calling_window_gui->lock_window("MWindow::undo_entry 4");
2318 void MWindow::new_folder(const char *new_folder, int is_clips)
2321 if( edl->new_folder(new_folder, is_clips) ) {
2322 MainError::show_error(_("create new folder failed"));
2324 undo_after(_("new folder"), LOAD_ALL);
2325 awindow->gui->async_update_assets();
2328 void MWindow::delete_folder(char *folder)
2331 if( edl->delete_folder(folder) < 0 ) {
2332 MainError::show_error(_("delete folder failed"));
2334 undo_after(_("del folder"), LOAD_ALL);
2335 awindow->gui->async_update_assets();
2338 void MWindow::select_point(double position)
2340 gui->unlock_window();
2341 gui->stop_drawing();
2342 cwindow->stop_playback(0);
2343 gui->lock_window("MWindow::select_point");
2345 edl->local_session->set_selectionstart(position);
2346 edl->local_session->set_selectionend(position);
2349 cwindow->update(1, 0, 0, 0, 1);
2351 update_plugin_guis();
2352 gui->update_patchbay();
2353 gui->hide_cursor(0);
2354 gui->draw_cursor(0);
2355 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2356 gui->zoombar->update();
2357 gui->update_timebar(0);
2358 gui->flash_canvas(0);
2365 void MWindow::map_audio(int pattern)
2368 remap_audio(pattern);
2370 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2372 sync_parameters(CHANGE_PARAMS);
2373 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2376 void MWindow::remap_audio(int pattern)
2378 int current_channel = 0;
2379 int current_track = 0;
2380 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2381 if( current->data_type == TRACK_AUDIO &&
2383 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2384 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2386 for( int i=0; i < MAXCHANNELS; ++i ) {
2387 pan_auto->values[i] = 0.0;
2390 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2391 pan_auto->values[current_channel] = 1.0;
2394 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2395 switch( current_track ) {
2398 pan_auto->values[0] = 1;
2402 pan_auto->values[1] = 1;
2406 pan_auto->values[0] = 0.5;
2407 pan_auto->values[1] = 0.5;
2412 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2413 edl->session->achannel_positions, pan_auto->values,
2414 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2418 if( current_channel >= edl->session->audio_channels )
2419 current_channel = 0;
2425 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2427 edl->rescale_proxy(orig_scale, new_scale);
2430 void MWindow::add_proxy(int use_scaler,
2431 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2433 edl->add_proxy(use_scaler, orig_assets, proxy_assets);
2436 void MWindow::cut_commercials()
2438 #ifdef HAVE_COMMERCIAL
2440 commercials->scan_media();
2443 undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2446 update_plugin_guis();
2447 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2448 cwindow->update(1, 0, 0, 0, 1);
2449 cwindow->refresh_frame(CHANGE_EDL);
2453 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2456 Track *old_track = old_edl->tracks->first;
2457 Track *new_track = new_edl->tracks->first;
2458 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2459 if( old_track->data_type != new_track->data_type ) continue;
2460 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2461 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2462 if( !old_speeds || !new_speeds ) continue;
2463 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2464 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2465 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2466 old_speed = (FloatAuto *)old_speed->next;
2467 new_speed = (FloatAuto *)new_speed->next;
2469 Edit *old_edit = old_track->edits->first;
2470 Edit *new_edit = new_track->edits->first;
2471 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2472 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2473 if( old_speed || new_speed ) {
2474 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2475 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2476 edit_start = new_speeds->speed_position(orig_start);
2477 edit_end = new_speeds->speed_position(orig_end);
2480 new_edit->startproject = edit_start;
2481 new_edit->length = edit_end - edit_start;
2487 void MWindow::speed_before()
2490 speed_edl = new EDL;
2491 speed_edl->create_objects();
2493 speed_edl->copy_all(edl);
2496 int MWindow::speed_after(int done)
2501 result = normalize_speed(speed_edl, edl);
2503 speed_edl->remove_user();