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)
86 undo->update_undo_before();
87 add_audio_track(above, dst);
89 undo->update_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)
106 undo->update_undo_before();
107 add_video_track(1, dst);
108 undo->update_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)
126 undo->update_undo_before();
127 add_subttl_track(1, dst);
128 undo->update_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() )
178 undo->update_undo_before();
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->update_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() ) {
246 undo->update_undo_before();
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->update_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;
285 undo->update_undo_before();
287 edl->session->frame_rate = new_framerate;
288 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
292 undo->update_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()
302 undo->update_undo_before();
307 undo->update_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)
348 undo->update_undo_before();
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));
358 undo->update_undo_after(string,
359 !changed_edl ? LOAD_AUTOMATION :
360 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
361 update_gui(changed_edl);
364 void MWindow::clear_automation()
366 undo->update_undo_before();
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->update_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()
380 undo->update_undo_before();
382 edl->tracks->clear_default_keyframe();
383 int changed_edl = speed_after(1);
385 undo->update_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()
394 undo->update_undo_before();
395 clear_labels(edl->local_session->get_selectionstart(),
396 edl->local_session->get_selectionend());
397 undo->update_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)
406 edl->labels->clear(start, end, 0);
410 void MWindow::concatenate_tracks()
412 undo->update_undo_before();
413 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
414 edl->session->autos_follow_edits);
416 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
419 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
420 cwindow->refresh_frame(CHANGE_EDL);
426 copy(edl->local_session->get_selectionstart(),
427 edl->local_session->get_selectionend());
430 int MWindow::copy(double start, double end)
432 if( start == end ) return 1;
435 edl->copy(start, end, 0, &file, "", 1);
436 const char *file_string = file.string();
437 long file_length = strlen(file_string);
438 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
439 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
444 int MWindow::copy_automation()
447 double start = edl->local_session->get_selectionstart();
448 double end = edl->local_session->get_selectionend();
449 edl->tracks->copy_automation(start, end, &file, 0, 1);
450 const char *file_string = file.string();
451 long file_length = strlen(file_string);
452 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
453 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
457 int MWindow::copy_default_keyframe()
460 double start = edl->local_session->get_selectionstart();
461 double end = edl->local_session->get_selectionend();
462 edl->tracks->copy_automation(start, end, &file, 1, 0);
463 const char *file_string = file.string();
464 long file_length = strlen(file_string);
465 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
466 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
471 // Uses cropping coordinates in edl session to crop and translate video.
472 // We modify the projector since camera automation depends on the track size.
473 void MWindow::crop_video()
476 undo->update_undo_before();
477 // Clamp EDL crop region
478 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
479 edl->session->crop_x1 ^= edl->session->crop_x2;
480 edl->session->crop_x2 ^= edl->session->crop_x1;
481 edl->session->crop_x1 ^= edl->session->crop_x2;
483 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
484 edl->session->crop_y1 ^= edl->session->crop_y2;
485 edl->session->crop_y2 ^= edl->session->crop_y1;
486 edl->session->crop_y1 ^= edl->session->crop_y2;
489 float old_projector_x = (float)edl->session->output_w / 2;
490 float old_projector_y = (float)edl->session->output_h / 2;
491 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
492 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
493 float projector_offset_x = -(new_projector_x - old_projector_x);
494 float projector_offset_y = -(new_projector_y - old_projector_y);
496 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
498 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
499 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
500 edl->session->crop_x1 = 0;
501 edl->session->crop_y1 = 0;
502 edl->session->crop_x2 = edl->session->output_w;
503 edl->session->crop_y2 = edl->session->output_h;
505 // Recalculate aspect ratio
506 if( defaults->get("AUTOASPECT", 0) ) {
507 create_aspect_ratio(edl->session->aspect_w,
508 edl->session->aspect_h,
509 edl->session->output_w,
510 edl->session->output_h);
513 undo->update_undo_after(_("crop"), LOAD_ALL);
516 cwindow->refresh_frame(CHANGE_ALL);
522 double start = edl->local_session->get_selectionstart();
523 double end = edl->local_session->get_selectionend();
524 if( EQUIV(start,end) )
530 void MWindow::blade(double position)
532 undo->update_undo_before();
533 edl->blade(position);
536 undo->update_undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
538 update_plugin_guis();
539 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
540 cwindow->update(1, 0, 0, 0, 1);
541 awindow->gui->async_update_assets();
542 cwindow->refresh_frame(CHANGE_EDL);
545 void MWindow::cut(double start, double end, double new_position)
547 undo->update_undo_before();
549 edl->clear(start, end,
550 edl->session->labels_follow_edits,
551 edl->session->plugins_follow_edits,
552 edl->session->autos_follow_edits);
556 undo->update_undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
557 if( new_position >= 0 ) {
558 edl->local_session->set_selectionstart(new_position);
559 edl->local_session->set_selectionend(new_position);
562 update_plugin_guis();
563 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
564 cwindow->update(1, 0, 0, 0, 1);
565 awindow->gui->async_update_assets();
566 cwindow->refresh_frame(CHANGE_EDL);
569 void MWindow::cut_left_edit()
571 double start_pos = edl->local_session->get_selectionstart(1);
572 double position = edl->prev_edit(start_pos);
573 if( position < start_pos )
574 cut(position, start_pos, position);
577 void MWindow::cut_right_edit()
579 double end_pos = edl->local_session->get_selectionend(1);
580 double position = edl->next_edit(end_pos);
581 if( end_pos < position )
582 cut(end_pos, position, end_pos);
585 void MWindow::cut_left_label()
587 double start_pos = edl->local_session->get_selectionstart(1);
588 Label *left_label = edl->labels->prev_label(start_pos);
589 if( !left_label ) return;
590 double position = left_label->position;
591 if( position < start_pos )
592 cut(position, start_pos, position);
595 void MWindow::cut_right_label()
597 double end_pos = edl->local_session->get_selectionend(1);
598 Label *right_label = edl->labels->next_label(end_pos);
599 if( !right_label ) return;
600 double position = right_label->position;
601 if( end_pos < position )
602 cut(end_pos, position, end_pos);
605 int MWindow::cut_automation()
607 undo->update_undo_before();
610 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
611 edl->local_session->get_selectionend());
612 int changed_edl = speed_after(1);
614 undo->update_undo_after(_("cut keyframes"),
615 !changed_edl ? LOAD_AUTOMATION :
616 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
617 update_gui(changed_edl);
621 int MWindow::cut_default_keyframe()
624 undo->update_undo_before();
626 copy_default_keyframe();
627 edl->tracks->clear_default_keyframe();
628 int changed_edl = speed_after(1);
630 undo->update_undo_after(_("cut default keyframe"),
631 !changed_edl ? LOAD_AUTOMATION :
632 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
633 update_gui(changed_edl);
638 void MWindow::delete_track()
640 if( edl->tracks->last )
641 delete_track(edl->tracks->last);
644 void MWindow::delete_tracks()
646 undo->update_undo_before();
647 edl->tracks->delete_tracks();
648 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
652 update_plugin_states();
654 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
655 cwindow->refresh_frame(CHANGE_EDL);
658 void MWindow::delete_track(Track *track)
660 undo->update_undo_before();
661 edl->tracks->delete_track(track);
662 undo->update_undo_after(_("delete track"), LOAD_ALL);
665 update_plugin_states();
667 gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
668 cwindow->refresh_frame(CHANGE_EDL);
673 // Insert data from clipboard
674 void MWindow::insert(double position, FileXML *file,
675 int edit_labels, int edit_plugins, int edit_autos,
676 EDL *parent_edl, Track *first_track, int overwrite)
678 // For clipboard pasting make the new edl use a separate session
679 // from the master EDL. Then it can be resampled to the master rates.
680 // For splice, overwrite, and dragging need same session to get the assets.
681 EDL *edl = new EDL(parent_edl);
682 ArrayList<EDL*> new_edls;
683 uint32_t load_flags = LOAD_ALL;
686 new_edls.append(edl);
687 edl->create_objects();
692 if( parent_edl ) load_flags &= ~LOAD_SESSION;
693 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
694 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
696 edl->load_xml(file, load_flags);
699 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
703 paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
704 edit_labels, edit_plugins, edit_autos, overwrite);
705 // if( vwindow->edl )
706 // printf("MWindow::insert 5 %f %f\n",
707 // vwindow->edl->local_session->in_point,
708 // vwindow->edl->local_session->out_point);
709 new_edls.remove_all();
710 edl->Garbage::remove_user();
711 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
714 void MWindow::insert_effects_canvas(double start,
717 Track *dest_track = session->track_highlighted;
718 if( !dest_track ) return;
720 undo->update_undo_before();
722 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
723 PluginServer *plugin = session->drag_pluginservers->values[i];
724 insert_effect(plugin->title, 0, dest_track,
725 i == 0 ? session->pluginset_highlighted : 0,
726 start, length, PLUGIN_STANDALONE);
730 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
732 sync_parameters(CHANGE_EDL);
733 // GUI updated in TrackCanvas, after current_operations are reset
736 void MWindow::insert_effects_cwindow(Track *dest_track)
738 if( !dest_track ) return;
740 undo->update_undo_before();
743 double length = dest_track->get_length();
745 if( edl->local_session->get_selectionend() >
746 edl->local_session->get_selectionstart() ) {
747 start = edl->local_session->get_selectionstart();
748 length = edl->local_session->get_selectionend() -
749 edl->local_session->get_selectionstart();
752 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
753 PluginServer *plugin = session->drag_pluginservers->values[i];
754 insert_effect(plugin->title, 0, dest_track, 0,
755 start, length, PLUGIN_STANDALONE);
759 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
761 sync_parameters(CHANGE_EDL);
762 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
765 void MWindow::insert_effect(char *title,
766 SharedLocation *shared_location,
769 int single_standalone)
771 Track *current = edl->tracks->first;
772 SharedLocation shared_location_local;
773 shared_location_local.copy_from(shared_location);
775 for( ; current; current=NEXT ) {
776 if( current->data_type == data_type &&
778 insert_effect(title, &shared_location_local,
779 current, 0, 0, 0, plugin_type);
782 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
783 plugin_type = PLUGIN_SHAREDPLUGIN;
784 shared_location_local.module = edl->tracks->number_of(current);
785 shared_location_local.plugin = current->plugin_set.total - 1;
794 void MWindow::insert_effect(char *title,
795 SharedLocation *shared_location,
797 PluginSet *plugin_set,
802 KeyFrame *default_keyframe = 0;
803 PluginServer *server = 0;
804 // Get default keyframe
805 if( plugin_type == PLUGIN_STANDALONE ) {
806 default_keyframe = new KeyFrame;
807 server = new PluginServer(*scan_plugindb(title, track->data_type));
809 server->open_plugin(0, preferences, edl, 0);
810 server->save_data(default_keyframe);
812 // Insert plugin object
813 track->insert_effect(title, shared_location,
814 default_keyframe, plugin_set,
815 start, length, plugin_type);
818 if( plugin_type == PLUGIN_STANDALONE ) {
819 server->close_plugin();
821 delete default_keyframe;
825 int MWindow::modify_edithandles()
827 undo->update_undo_before();
828 edl->modify_edithandles(session->drag_start,
829 session->drag_position,
830 session->drag_handle,
831 edl->session->edit_handle_mode[session->drag_button],
832 edl->session->labels_follow_edits,
833 edl->session->plugins_follow_edits,
834 edl->session->autos_follow_edits);
836 finish_modify_handles();
837 //printf("MWindow::modify_handles 1\n");
841 int MWindow::modify_pluginhandles()
843 undo->update_undo_before();
845 edl->modify_pluginhandles(session->drag_start,
846 session->drag_position,
847 session->drag_handle,
848 edl->session->edit_handle_mode[session->drag_button],
849 edl->session->labels_follow_edits,
850 edl->session->autos_follow_edits,
851 session->trim_edits);
853 finish_modify_handles();
859 // Common to edithandles and plugin handles
860 void MWindow::finish_modify_handles()
862 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
864 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
865 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
866 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
867 edl->local_session->set_selectionstart(session->drag_position);
868 edl->local_session->set_selectionend(session->drag_position);
871 if( edit_mode != MOVE_NO_EDITS ) {
872 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
873 edl->local_session->set_selectionstart(session->drag_start);
874 edl->local_session->set_selectionend(session->drag_start);
877 // clamp the selection to 0
878 if( edl->local_session->get_selectionstart(1) < 0 ) {
879 edl->local_session->set_selectionstart(0);
880 edl->local_session->set_selectionend(0);
882 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
886 sync_parameters(CHANGE_EDL);
887 update_plugin_guis();
888 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
889 // label list can be modified
890 awindow->gui->async_update_assets();
891 cwindow->update(1, 0, 0, 0, 1);
894 void MWindow::match_output_size(Track *track)
896 undo->update_undo_before();
897 track->track_w = edl->session->output_w;
898 track->track_h = edl->session->output_h;
900 undo->update_undo_after(_("match output size"), LOAD_ALL);
903 sync_parameters(CHANGE_EDL);
907 EDL *MWindow::selected_edits_to_clip(int packed,
908 double *start_position, Track **start_track,
909 int edit_labels, int edit_autos, int edit_plugins)
911 double start = DBL_MAX, end = DBL_MIN;
912 Track *first_track=0, *last_track = 0;
913 for( Track *track=edl->tracks->first; track; track=track->next ) {
914 if( !track->record ) continue;
916 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
917 if( !edit->is_selected || edit->silence() ) continue;
918 double edit_pos = track->from_units(edit->startproject);
919 if( start > edit_pos ) start = edit_pos;
920 if( end < (edit_pos+=edit->length) ) end = edit_pos;
923 if( empty ) continue;
924 if( !first_track ) first_track = track;
927 if( start_position ) *start_position = start;
928 if( start_track ) *start_track = first_track;
929 if( !first_track ) return 0;
930 EDL *new_edl = new EDL();
931 new_edl->create_objects();
932 new_edl->copy_session(edl);
933 const char *text = _("new_edl edit");
934 new_edl->set_path(text);
935 strcpy(new_edl->local_session->clip_title, text);
936 strcpy(new_edl->local_session->clip_notes, text);
937 new_edl->session->video_tracks = 0;
938 new_edl->session->audio_tracks = 0;
939 for( Track *track=edl->tracks->first; track; track=track->next ) {
940 if( !track->record ) continue;
942 if( first_track != track ) continue;
945 Track *new_track = 0;
947 new_track = new_edl->add_new_track(track->data_type);
948 int64_t start_pos = track->to_units(start, 0);
949 int64_t end_pos = track->to_units(end, 0);
950 int64_t startproject = 0;
951 Edit *edit = track->edits->first;
952 for( ; edit; edit=edit->next ) {
953 if( !edit->is_selected || edit->silence() ) continue;
954 if( edit->startproject < start_pos ) continue;
955 if( edit->startproject >= end_pos ) break;
956 int64_t edit_start_pos = edit->startproject;
957 int64_t edit_end_pos = edit->startproject + edit->length;
959 new_track = new_edl->add_new_track(track->data_type);
960 int64_t edit_pos = edit_start_pos - start_pos;
962 if( edit_pos > startproject ) {
963 Edit *silence = new Edit(new_edl, new_track);
964 silence->startproject = startproject;
965 silence->length = edit_pos - startproject;
966 new_track->edits->append(silence);
967 startproject = edit_pos;
970 int64_t clip_start_pos = startproject;
971 Edit *clip_edit = new Edit(new_edl, new_track);
972 clip_edit->copy_from(edit);
973 clip_edit->startproject = startproject;
974 startproject += clip_edit->length;
975 new_track->edits->append(clip_edit);
977 double edit_start = track->from_units(edit_start_pos);
978 double edit_end = track->from_units(edit_end_pos);
979 double clip_start = new_track->from_units(clip_start_pos);
980 Label *label = edl->labels->first;
981 for( ; label; label=label->next ) {
982 if( label->position < edit_start ) continue;
983 if( label->position >= edit_end ) break;
984 double clip_position = label->position - edit_start + clip_start;
985 Label *clip_label = new_edl->labels->first;
986 while( clip_label && clip_label->position<clip_position )
987 clip_label = clip_label->next;
988 if( clip_label && clip_label->position == clip_position ) continue;
989 Label *new_label = new Label(new_edl,
990 new_edl->labels, clip_position, label->textstr);
991 new_edl->labels->insert_before(clip_label, new_label);
995 Automation *automation = track->automation;
996 Automation *new_automation = new_track->automation;
997 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
998 Autos *autos = automation->autos[i];
999 if( !autos ) continue;
1000 Autos *new_autos = new_automation->autos[i];
1001 new_autos->default_auto->copy_from(autos->default_auto);
1002 Auto *aut0 = autos->first;
1003 for( ; aut0; aut0=aut0->next ) {
1004 if( aut0->position < edit_start_pos ) continue;
1005 if( aut0->position >= edit_end_pos ) break;
1006 Auto *new_auto = new_autos->new_auto();
1007 new_auto->copy_from(aut0);
1008 int64_t clip_position = aut0->position - edit_start_pos + clip_start_pos;
1009 new_auto->position = clip_position;
1010 new_autos->append(new_auto);
1014 if( edit_plugins ) {
1015 while( new_track->plugin_set.size() < track->plugin_set.size() )
1016 new_track->plugin_set.append(0);
1017 for( int i=0; i<track->plugin_set.total; ++i ) {
1018 PluginSet *plugin_set = track->plugin_set[i];
1019 if( !plugin_set ) continue;
1020 PluginSet *new_plugin_set = new_track->plugin_set[i];
1021 if( !new_plugin_set ) {
1022 new_plugin_set = new PluginSet(new_edl, new_track);
1023 new_track->plugin_set[i] = new_plugin_set;
1025 Plugin *plugin = (Plugin*)plugin_set->first;
1026 int64_t startplugin = 0;
1027 for( ; plugin ; plugin=(Plugin*)plugin->next ) {
1028 if( plugin->silence() ) continue;
1029 int64_t plugin_start_pos = plugin->startproject;
1030 int64_t plugin_end_pos = plugin_start_pos + plugin->length;
1031 if( plugin_end_pos < start_pos ) continue;
1032 if( plugin_start_pos > end_pos ) break;
1033 if( plugin_start_pos < edit_start_pos )
1034 plugin_start_pos = edit_start_pos;
1035 if( plugin_end_pos > edit_end_pos )
1036 plugin_end_pos = edit_end_pos;
1037 if( plugin_start_pos >= plugin_end_pos ) continue;
1038 int64_t plugin_pos = plugin_start_pos - start_pos;
1039 if( plugin_pos > startplugin ) {
1040 Plugin *silence = new Plugin(new_edl, new_track, "");
1041 silence->startproject = startplugin;
1042 silence->length = plugin_pos - startplugin;
1043 new_plugin_set->append(silence);
1044 startplugin = plugin_pos;
1046 Plugin *new_plugin = new Plugin(new_edl, new_track, plugin->title);
1047 new_plugin->copy_base(plugin);
1048 new_plugin->startproject = startplugin;
1049 new_plugin->length = plugin_end_pos - plugin_start_pos;
1050 startplugin += new_plugin->length;
1051 new_plugin_set->append(new_plugin);
1052 KeyFrames *keyframes = plugin->keyframes;
1053 KeyFrames *new_keyframes = new_plugin->keyframes;
1054 new_keyframes->default_auto->copy_from(keyframes->default_auto);
1055 new_keyframes->default_auto->position = startplugin;
1056 KeyFrame *keyframe = (KeyFrame*)keyframes->first;
1057 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
1058 if( keyframe->position < edit_start_pos ) continue;
1059 if( keyframe->position >= edit_end_pos ) break;
1060 KeyFrame *clip_keyframe = new KeyFrame(new_edl, new_keyframes);
1061 clip_keyframe->copy_from(keyframe);
1062 int64_t clip_position = keyframe->position - start_pos;
1063 clip_keyframe->position = clip_position;
1064 new_keyframes->append(clip_keyframe);
1070 if( last_track == track ) break;
1075 void MWindow::selected_edits_to_clipboard(int packed)
1077 EDL *new_edl = selected_edits_to_clip(packed, 0, 0,
1078 edl->session->labels_follow_edits,
1079 edl->session->autos_follow_edits,
1080 edl->session->plugins_follow_edits);
1081 if( !new_edl ) return;
1082 double length = new_edl->tracks->total_length();
1084 new_edl->copy(0, length, 1, &file, "", 1);
1085 const char *file_string = file.string();
1086 long file_length = strlen(file_string);
1087 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1088 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1089 new_edl->remove_user();
1092 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
1094 ArrayList<Edit*> edits;
1096 delete_edits(&edits, msg, collapse);
1099 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
1101 if( !edits->size() ) return;
1102 undo->update_undo_before();
1103 edl->delete_edits(edits, collapse);
1105 undo->update_undo_after(msg, LOAD_EDITS);
1108 cwindow->refresh_frame(CHANGE_EDL);
1109 update_plugin_guis();
1110 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1113 void MWindow::delete_edits(int collapse)
1115 ArrayList<Edit*> edits;
1116 edl->tracks->get_selected_edits(&edits);
1117 delete_edits(&edits,_("del edit"), collapse);
1120 // collapse - delete from timeline, not collapse replace with silence
1121 // packed - omit unselected from selection, unpacked - replace unselected with silence
1122 void MWindow::cut_selected_edits(int collapse, int packed)
1124 selected_edits_to_clipboard(packed);
1125 ArrayList<Edit*> edits;
1126 edl->tracks->get_selected_edits(&edits);
1127 delete_edits(&edits, _("cut edit"), collapse);
1131 void MWindow::move_edits(ArrayList<Edit*> *edits,
1136 undo->update_undo_before();
1138 edl->tracks->move_edits(edits,
1141 edl->session->labels_follow_edits,
1142 edl->session->plugins_follow_edits,
1143 edl->session->autos_follow_edits,
1147 undo->update_undo_after(_("move edit"), LOAD_ALL);
1150 cwindow->refresh_frame(CHANGE_EDL);
1152 update_plugin_guis();
1153 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1156 void MWindow::move_group(EDL *group, Track *first_track, double position)
1158 undo->update_undo_before();
1159 if( edl->session->labels_follow_edits ) {
1160 ArrayList<Edit *>edits;
1161 edl->tracks->get_selected_edits(&edits);
1162 double dist = position - session->drag_group_position;
1163 edl->move_edit_labels(&edits, dist);
1165 for( Track *track=edl->tracks->first; track; track=track->next ) {
1166 if( !track->record ) continue;
1167 Edit *edit = track->edits->first;
1168 for( Edit *next=0; edit; edit=next ) {
1170 if( !edit->is_selected ) continue;
1171 edit->is_selected = 0;
1173 int64_t start = edit->startproject;
1174 int64_t end = start + edit->length;
1175 track->clear(start, end, 1, 0,
1176 edl->session->plugins_follow_edits,
1177 edl->session->autos_follow_edits, 0);
1178 track->paste_silence(start, end,
1179 edl->session->plugins_follow_edits,
1180 edl->session->autos_follow_edits);
1181 next = track->edits->first;
1184 Track *src = group->tracks->first;
1185 for( Track *track=first_track; track && src; track=track->next ) {
1186 if( !track->record ) continue;
1187 int64_t pos = track->to_units(position, 0);
1188 for( Edit *edit=src->edits->first; edit; edit=edit->next ) {
1189 if( edit->silence() ) continue;
1190 int64_t start = pos + edit->startproject;
1191 int64_t end = start + edit->length;
1192 track->edits->clear(start, end);
1193 Edit *dst = track->edits->insert_new_edit(start);
1194 dst->copy_from(edit);
1195 dst->startproject = start;
1196 dst->is_selected = 1;
1197 while( (dst=dst->next) != 0 )
1198 dst->startproject += edit->length;
1200 if( edl->session->autos_follow_edits ) {
1201 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
1202 Autos *src_autos = src->automation->autos[i];
1203 if( !src_autos ) continue;
1204 Autos *autos = track->automation->autos[i];
1205 for( Auto *aut0=src_autos->first; aut0; aut0=aut0->next ) {
1206 int64_t position = pos + aut0->position;
1207 autos->insert_auto(position, aut0);
1211 if( edl->session->plugins_follow_edits ) {
1212 for( int i=0; i<src->plugin_set.size(); ++i ) {
1213 PluginSet *plugin_set = src->plugin_set[i];
1214 if( !plugin_set ) continue;
1215 while( track->plugin_set.size() < i )
1216 track->plugin_set.append(0);
1217 PluginSet *dst_plugin_set = track->plugin_set[i];
1218 if( !dst_plugin_set ) {
1219 dst_plugin_set = new PluginSet(edl, track);
1220 track->plugin_set[i] = dst_plugin_set;
1222 Plugin *plugin = (Plugin *)plugin_set->first;
1223 for( ; plugin; plugin=(Plugin *)plugin->next ) {
1224 int64_t start = pos + plugin->startproject;
1225 int64_t end = start + plugin->length;
1226 dst_plugin_set->clear(start, end, 1);
1227 Plugin *dst = dst_plugin_set->insert_plugin(
1228 plugin->title, start, end-start,
1229 plugin->plugin_type, &plugin->shared_location,
1230 (KeyFrame*)plugin->keyframes->default_auto, 0);
1231 KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
1232 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
1233 int64_t position = pos + keyframe->position;
1234 dst->keyframes->insert_auto(position, keyframe);
1242 edl->tracks->clear_selected_edits();
1245 undo->update_undo_after(_("move group"), LOAD_ALL);
1247 cwindow->refresh_frame(CHANGE_EDL);
1249 update_plugin_guis();
1250 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1253 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1255 undo->update_undo_before();
1256 edl->tracks->move_effect(plugin, track, position);
1258 undo->update_undo_after(_("paste effect"), LOAD_ALL);
1261 cwindow->refresh_frame(CHANGE_EDL);
1262 update_plugin_guis();
1263 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1266 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1268 undo->update_undo_before();
1269 edl->tracks->move_effect(plugin, plugin_set, position);
1271 undo->update_undo_after(_("move effect"), LOAD_ALL);
1274 cwindow->refresh_frame(CHANGE_EDL);
1275 update_plugin_guis();
1276 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1279 void MWindow::move_plugins_up(PluginSet *plugin_set)
1282 undo->update_undo_before();
1283 plugin_set->track->move_plugins_up(plugin_set);
1286 undo->update_undo_after(_("move effect up"), LOAD_ALL);
1288 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1289 sync_parameters(CHANGE_EDL);
1292 void MWindow::move_plugins_down(PluginSet *plugin_set)
1294 undo->update_undo_before();
1296 plugin_set->track->move_plugins_down(plugin_set);
1299 undo->update_undo_after(_("move effect down"), LOAD_ALL);
1301 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1302 sync_parameters(CHANGE_EDL);
1305 void MWindow::move_track_down(Track *track)
1307 undo->update_undo_before();
1308 edl->tracks->move_track_down(track);
1310 undo->update_undo_after(_("move track down"), LOAD_ALL);
1313 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1314 sync_parameters(CHANGE_EDL);
1318 void MWindow::move_tracks_down()
1320 undo->update_undo_before();
1321 edl->tracks->move_tracks_down();
1323 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1326 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1327 sync_parameters(CHANGE_EDL);
1331 void MWindow::move_track_up(Track *track)
1333 undo->update_undo_before();
1334 edl->tracks->move_track_up(track);
1336 undo->update_undo_after(_("move track up"), LOAD_ALL);
1338 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1339 sync_parameters(CHANGE_EDL);
1343 void MWindow::move_tracks_up()
1345 undo->update_undo_before();
1346 edl->tracks->move_tracks_up();
1348 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1350 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1351 sync_parameters(CHANGE_EDL);
1355 void MWindow::mute_selection()
1357 double start = edl->local_session->get_selectionstart();
1358 double end = edl->local_session->get_selectionend();
1359 if( start != end ) {
1360 undo->update_undo_before();
1361 edl->clear(start, end, 0,
1362 edl->session->plugins_follow_edits,
1363 edl->session->autos_follow_edits);
1364 edl->local_session->set_selectionend(end);
1365 edl->local_session->set_selectionstart(start);
1366 edl->paste_silence(start, end, 0,
1367 edl->session->plugins_follow_edits,
1368 edl->session->autos_follow_edits);
1371 undo->update_undo_after(_("mute"), LOAD_EDITS);
1374 update_plugin_guis();
1375 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1376 cwindow->refresh_frame(CHANGE_EDL);
1381 void MWindow::overwrite(EDL *source, int all)
1385 LocalSession *src = source->local_session;
1386 double src_start = all ? 0 :
1387 src->inpoint_valid() ? src->get_inpoint() :
1388 src->outpoint_valid() ? 0 :
1389 src->get_selectionstart();
1390 double src_end = all ? source->tracks->total_length() :
1391 src->outpoint_valid() ? src->get_outpoint() :
1392 src->inpoint_valid() ? source->tracks->total_length() :
1393 src->get_selectionend();
1394 double overwrite_len = src_end - src_start;
1395 double dst_start = edl->local_session->get_selectionstart();
1396 double dst_len = edl->local_session->get_selectionend() - dst_start;
1398 undo->update_undo_before();
1399 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1400 // in/out points or selection present and shorter than overwrite range
1401 // shorten the copy range
1402 overwrite_len = dst_len;
1405 source->copy(src_start, src_start + overwrite_len, 0, &file, "", 1);
1407 // HACK around paste_edl get_start/endselection on its own
1408 // so we need to clear only when not using both io points
1409 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1410 if( edl->local_session->get_inpoint() < 0 ||
1411 edl->local_session->get_outpoint() < 0 )
1412 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1414 paste(dst_start, dst_start + overwrite_len, &file, 0, 0, 0, 0, 0);
1416 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1417 edl->local_session->set_selectionend(dst_start + overwrite_len);
1420 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1423 update_plugin_guis();
1424 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1425 sync_parameters(CHANGE_EDL);
1428 // For splice and overwrite
1429 int MWindow::paste(double start, double end, FileXML *file,
1430 int edit_labels, int edit_plugins, int edit_autos,
1431 Track *first_track, int overwrite)
1435 // Want to insert with assets shared with the master EDL.
1437 edit_labels, edit_plugins, edit_autos,
1438 edl, first_track, overwrite);
1443 // For editing using insertion point
1444 void MWindow::paste()
1446 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1449 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1451 //double end = edl->local_session->get_selectionend();
1452 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1455 char *string = new char[len];
1456 undo->update_undo_before();
1457 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1459 file.read_from_string(string);
1460 if( clear_selection ) clear(0);
1462 insert(start, &file,
1463 edl->session->labels_follow_edits,
1464 edl->session->plugins_follow_edits,
1465 edl->session->autos_follow_edits,
1466 0, first_track, overwrite);
1473 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1475 update_plugin_guis();
1476 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1477 awindow->gui->async_update_assets();
1478 sync_parameters(CHANGE_EDL);
1483 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1486 undo->update_undo_before();
1488 if( session->drag_assets->total ) {
1489 load_assets(session->drag_assets,
1490 position, LOADMODE_PASTE, dest_track, 0,
1491 edl->session->labels_follow_edits,
1492 edl->session->plugins_follow_edits,
1493 edl->session->autos_follow_edits,
1498 if( session->drag_clips->total ) {
1499 paste_edls(session->drag_clips,
1500 LOADMODE_PASTE, dest_track, position,
1501 edl->session->labels_follow_edits,
1502 edl->session->plugins_follow_edits,
1503 edl->session->autos_follow_edits,
1510 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1512 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1513 sync_parameters(CHANGE_EDL);
1517 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1518 double position, int load_mode, Track *first_track, RecordLabels *labels,
1519 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1521 if( load_mode == LOADMODE_RESOURCESONLY )
1522 load_mode = LOADMODE_ASSETSONLY;
1523 const int debug = 0;
1524 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1525 if( position < 0 ) position = edl->local_session->get_selectionstart();
1527 ArrayList<EDL*> new_edls;
1528 for( int i=0; i<new_assets->total; ++i ) {
1529 Indexable *indexable = new_assets->get(i);
1530 if( indexable->is_asset ) {
1531 remove_asset_from_caches((Asset*)indexable);
1533 EDL *new_edl = new EDL;
1534 new_edl->create_objects();
1535 new_edl->copy_session(edl);
1536 if( !indexable->is_asset ) {
1537 EDL *nested_edl = (EDL*)indexable;
1538 new_edl->create_nested(nested_edl);
1539 new_edl->set_path(indexable->path);
1542 Asset *asset = (Asset*)indexable;
1543 asset_to_edl(new_edl, asset);
1545 new_edls.append(new_edl);
1548 for( RecordLabel *label=labels->first; label; label=label->next ) {
1549 new_edl->labels->toggle_label(label->position, label->position);
1553 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1555 paste_edls(&new_edls, load_mode, first_track, position,
1556 edit_labels, edit_plugins, edit_autos, overwrite);
1557 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1560 for( int i=0; i<new_edls.size(); ++i )
1561 new_edls.get(i)->Garbage::remove_user();
1563 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1566 int MWindow::paste_automation()
1568 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1571 undo->update_undo_before();
1573 char *string = new char[len];
1574 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1576 file.read_from_string(string);
1578 double start = edl->local_session->get_selectionstart();
1579 double end = edl->local_session->get_selectionend();
1580 edl->tracks->clear_automation(start, end);
1581 edl->tracks->paste_automation(start, &file, 0, 1,
1582 edl->session->typeless_keyframes);
1583 int changed_edl = speed_after(1);
1585 undo->update_undo_after(_("paste keyframes"),
1586 !changed_edl ? LOAD_AUTOMATION :
1587 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1588 update_gui(changed_edl);
1594 int MWindow::paste_default_keyframe()
1596 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1599 undo->update_undo_before();
1601 char *string = new char[len];
1602 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1604 file.read_from_string(string);
1606 double start = edl->local_session->get_selectionstart();
1607 edl->tracks->paste_automation(start, &file, 1, 0,
1608 edl->session->typeless_keyframes);
1609 // edl->tracks->paste_default_keyframe(&file);
1610 int changed_edl = speed_after(1);
1611 undo->update_undo_after(_("paste default keyframe"),
1612 !changed_edl ? LOAD_AUTOMATION :
1613 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1615 update_gui(changed_edl);
1622 // Insert edls with project deletion and index file generation.
1623 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1624 Track *first_track, double current_position,
1625 int edit_labels, int edit_plugins, int edit_autos,
1629 ArrayList<Track*> destination_tracks;
1630 int need_new_tracks = 0;
1633 if( !new_edls->total ) return 0;
1636 // double original_length = edl->tracks->total_length();
1637 // double original_preview_end = edl->local_session->preview_end;
1640 // Delete current project
1641 if( load_mode == LOADMODE_REPLACE ||
1642 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1644 edl->save_defaults(defaults);
1646 edl->Garbage::remove_user();
1648 edl->create_objects();
1649 edl->copy_session(new_edls->values[0]);
1650 edl->copy_mixers(new_edls->values[0]);
1651 gui->mainmenu->update_toggles(0);
1652 gui->unlock_window();
1653 gwindow->gui->update_toggles(1);
1654 gui->lock_window("MWindow::paste_edls");
1656 // Insert labels for certain modes constitutively
1660 // Force reset of preview
1661 // original_length = 0;
1662 // original_preview_end = -1;
1668 // Create new tracks in master EDL
1669 if( load_mode == LOADMODE_REPLACE ||
1670 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1671 load_mode == LOADMODE_NEW_TRACKS ) {
1673 need_new_tracks = 1;
1674 for( int i=0; i<new_edls->total; ++i ) {
1675 EDL *new_edl = new_edls->values[i];
1676 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1677 switch( current->data_type ) {
1679 edl->tracks->add_video_track(0, 0);
1680 if( current->draw ) edl->tracks->last->draw = 1;
1683 edl->tracks->add_audio_track(0, 0);
1685 case TRACK_SUBTITLE:
1686 edl->tracks->add_subttl_track(0, 0);
1691 destination_tracks.append(edl->tracks->last);
1694 // Base track count on first EDL only for concatenation
1695 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1697 edl->session->highlighted_track = edl->tracks->total() - 1;
1700 // Recycle existing tracks of master EDL
1701 if( load_mode == LOADMODE_CONCATENATE ||
1702 load_mode == LOADMODE_PASTE ||
1703 load_mode == LOADMODE_NESTED ) {
1706 // The point of this is to shift forward labels after the selection so they can
1707 // then be shifted back to their original locations without recursively
1708 // shifting back every paste.
1709 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1710 edl->session->labels_follow_edits )
1711 edl->labels->clear(edl->local_session->get_selectionstart(),
1712 edl->local_session->get_selectionend(), 1);
1714 Track *current = first_track ? first_track : edl->tracks->first;
1715 for( ; current; current=NEXT ) {
1716 if( current->record ) {
1717 destination_tracks.append(current);
1724 int destination_track = 0;
1725 double *paste_position = new double[destination_tracks.total];
1727 // Iterate through the edls
1728 for( int i=0; i<new_edls->total; ++i ) {
1730 EDL *new_edl = new_edls->values[i];
1731 double edl_length = new_edl->local_session->clipboard_length ?
1732 new_edl->local_session->clipboard_length :
1733 new_edl->tracks->total_length();
1734 // printf("MWindow::paste_edls 2 %f %f\n",
1735 // new_edl->local_session->clipboard_length,
1736 // new_edl->tracks->total_length());
1740 // Convert EDL to master rates
1741 new_edl->resample(new_edl->session->sample_rate,
1742 edl->session->sample_rate,
1744 new_edl->resample(new_edl->session->frame_rate,
1745 edl->session->frame_rate,
1748 // Add assets and prepare index files
1749 for( Asset *new_asset=new_edl->assets->first;
1750 new_asset; new_asset=new_asset->next ) {
1751 mainindexes->add_next_asset(0, new_asset);
1753 // Capture index file status from mainindex test
1754 edl->update_assets(new_edl);
1756 // Get starting point of insertion. Need this to paste labels.
1757 switch( load_mode ) {
1758 case LOADMODE_REPLACE:
1759 case LOADMODE_NEW_TRACKS:
1760 current_position = 0;
1763 case LOADMODE_CONCATENATE:
1764 case LOADMODE_REPLACE_CONCATENATE:
1765 destination_track = 0;
1766 if( destination_tracks.total )
1767 current_position = destination_tracks.values[0]->get_length();
1769 current_position = 0;
1772 case LOADMODE_PASTE:
1773 case LOADMODE_NESTED:
1774 destination_track = 0;
1776 for( int j=0; j<destination_tracks.total; ++j ) {
1777 paste_position[j] = (current_position >= 0) ?
1779 edl->local_session->get_selectionstart();
1784 case LOADMODE_RESOURCESONLY:
1785 edl->add_clip(new_edl);
1790 if( load_mode != LOADMODE_RESOURCESONLY &&
1791 load_mode != LOADMODE_ASSETSONLY ) {
1793 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1794 if( load_mode == LOADMODE_PASTE ||
1795 load_mode == LOADMODE_NESTED )
1796 edl->labels->insert_labels(new_edl->labels,
1797 destination_tracks.total ? paste_position[0] : 0.0,
1801 edl->labels->insert_labels(new_edl->labels,
1806 double total_length = new_edl->tracks->total_length();
1807 for( Track *new_track=new_edl->tracks->first;
1808 new_track; new_track=new_track->next ) {
1809 // Get destination track of same type as new_track
1811 k < destination_tracks.total &&
1812 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1813 ++k, ++destination_track ) {
1814 if( destination_track >= destination_tracks.total - 1 )
1815 destination_track = 0;
1818 // Insert data into destination track
1819 if( destination_track < destination_tracks.total &&
1820 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1821 Track *track = destination_tracks.values[destination_track];
1823 // Replace default keyframes if first EDL and new tracks were created.
1824 // This means data copied from one track and pasted to another won't retain
1825 // the camera position unless it's a keyframe. If it did, previous data in the
1826 // track might get unknowingly corrupted. Ideally we would detect when differing
1827 // default keyframes existed and create discrete keyframes for both.
1828 int replace_default = (i == 0) && need_new_tracks;
1830 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1831 // Insert new track at current position
1832 switch( load_mode ) {
1833 case LOADMODE_REPLACE_CONCATENATE:
1834 case LOADMODE_CONCATENATE:
1835 current_position = track->get_length();
1838 case LOADMODE_PASTE:
1839 case LOADMODE_NESTED:
1840 current_position = paste_position[destination_track];
1841 paste_position[destination_track] += new_track->get_length();
1845 double length = overwrite >= 0 ?
1846 new_track->get_length() : total_length;
1847 track->clear(current_position,
1848 current_position + length,
1850 edit_labels, edit_plugins, edit_autos,
1854 track->insert_track(new_track, current_position, replace_default,
1855 edit_plugins, edit_autos, edl_length);
1859 // Get next destination track
1860 destination_track++;
1861 if( destination_track >= destination_tracks.total )
1862 destination_track = 0;
1866 if( load_mode == LOADMODE_PASTE ||
1867 load_mode == LOADMODE_NESTED )
1868 current_position += edl_length;
1872 // Move loading of clips and vwindow to the end - this fixes some
1873 // strange issue, for index not being shown
1874 // Assume any paste operation from the same EDL won't contain any clips.
1875 // If it did it would duplicate every clip here.
1876 for( int i=0; i<new_edls->total; ++i ) {
1877 EDL *new_edl = new_edls->get(i);
1879 for( int j=0; j<new_edl->clips.size(); ++j ) {
1880 edl->add_clip(new_edl->clips[j]);
1882 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1883 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1886 if( new_edl->total_vwindow_edls() ) {
1887 // if( edl->vwindow_edl )
1888 // edl->vwindow_edl->Garbage::remove_user();
1889 // edl->vwindow_edl = new EDL(edl);
1890 // edl->vwindow_edl->create_objects();
1891 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1893 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1894 EDL *vwindow_edl = new EDL(edl);
1895 vwindow_edl->create_objects();
1896 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1897 edl->append_vwindow_edl(vwindow_edl, 0);
1902 if( paste_position ) delete [] paste_position;
1904 // This is already done in load_filenames and everything else that uses paste_edls
1905 // update_project(load_mode);
1907 // Fix preview range
1908 // if( EQUIV(original_length, original_preview_end) )
1910 // edl->local_session->preview_end = edl->tracks->total_length();
1913 // Start examining next batch of index files
1914 mainindexes->start_build();
1916 // Don't save a backup after loading since the loaded file is on disk already.
1921 void MWindow::paste_silence()
1923 double start = edl->local_session->get_selectionstart();
1924 double end = edl->local_session->get_selectionend();
1925 if( EQUIV(start, end) ) {
1926 if( edl->session->frame_rate > 0 )
1927 end += 1./edl->session->frame_rate;
1929 undo->update_undo_before(_("silence"), this);
1930 edl->paste_silence(start, end,
1931 edl->session->labels_follow_edits,
1932 edl->session->plugins_follow_edits,
1933 edl->session->autos_follow_edits);
1936 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1938 update_plugin_guis();
1940 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1941 cwindow->update(1, 0, 0, 0, 1);
1942 cwindow->refresh_frame(CHANGE_EDL);
1945 void MWindow::detach_transition(Transition *transition)
1947 undo->update_undo_before();
1948 hide_plugin(transition, 1);
1949 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1950 transition->edit->detach_transition();
1952 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1954 if( is_video ) restart_brender();
1955 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1956 sync_parameters(CHANGE_EDL);
1959 void MWindow::detach_transitions()
1961 gui->lock_window("MWindow::detach_transitions 1");
1963 undo->update_undo_before();
1964 double start = edl->local_session->get_selectionstart();
1965 double end = edl->local_session->get_selectionend();
1966 edl->tracks->clear_transitions(start, end);
1969 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1971 sync_parameters(CHANGE_EDL);
1972 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1973 gui->unlock_window();
1976 void MWindow::paste_transition()
1978 // Only the first transition gets dropped.
1979 PluginServer *server = session->drag_pluginservers->values[0];
1981 undo->update_undo_before();
1982 edl->tracks->paste_transition(server, session->edit_highlighted);
1984 undo->update_undo_after(_("transition"), LOAD_EDITS);
1986 if( server->video ) restart_brender();
1987 sync_parameters(CHANGE_ALL);
1990 void MWindow::paste_transitions(int track_type, char *title)
1992 gui->lock_window("MWindow::detach_transitions 1");
1994 undo->update_undo_before();
1995 double start = edl->local_session->get_selectionstart();
1996 double end = edl->local_session->get_selectionend();
1997 edl->tracks->paste_transitions(start, end, track_type, title);
1999 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
2001 sync_parameters(CHANGE_EDL);
2002 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2003 gui->unlock_window();
2006 void MWindow::paste_transition_cwindow(Track *dest_track)
2008 PluginServer *server = session->drag_pluginservers->values[0];
2009 undo->update_undo_before();
2010 edl->tracks->paste_video_transition(server, 1);
2012 undo->update_undo_after(_("transition"), LOAD_EDITS);
2014 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2015 sync_parameters(CHANGE_ALL);
2018 void MWindow::paste_audio_transition()
2020 PluginServer *server = scan_plugindb(edl->session->default_atransition,
2023 char string[BCTEXTLEN];
2024 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
2025 gui->show_message(string);
2029 undo->update_undo_before();
2030 edl->tracks->paste_audio_transition(server);
2032 undo->update_undo_after(_("transition"), LOAD_EDITS);
2034 sync_parameters(CHANGE_EDL);
2035 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2038 void MWindow::paste_video_transition()
2040 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
2043 char string[BCTEXTLEN];
2044 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
2045 gui->show_message(string);
2049 undo->update_undo_before();
2051 edl->tracks->paste_video_transition(server);
2053 undo->update_undo_after(_("transition"), LOAD_EDITS);
2055 sync_parameters(CHANGE_EDL);
2057 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2060 void MWindow::shuffle_edits()
2062 gui->lock_window("MWindow::shuffle_edits 1");
2064 undo->update_undo_before();
2065 double start = edl->local_session->get_selectionstart();
2066 double end = edl->local_session->get_selectionend();
2068 edl->tracks->shuffle_edits(start, end);
2071 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
2073 sync_parameters(CHANGE_EDL);
2075 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2076 gui->unlock_window();
2079 void MWindow::reverse_edits()
2081 gui->lock_window("MWindow::reverse_edits 1");
2083 undo->update_undo_before();
2084 double start = edl->local_session->get_selectionstart();
2085 double end = edl->local_session->get_selectionend();
2087 edl->tracks->reverse_edits(start, end);
2090 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
2092 sync_parameters(CHANGE_EDL);
2094 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2095 gui->unlock_window();
2098 void MWindow::align_edits()
2100 gui->lock_window("MWindow::align_edits 1");
2102 undo->update_undo_before();
2103 double start = edl->local_session->get_selectionstart();
2104 double end = edl->local_session->get_selectionend();
2106 edl->tracks->align_edits(start, end);
2109 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
2111 sync_parameters(CHANGE_EDL);
2113 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2114 gui->unlock_window();
2117 void MWindow::set_edit_length(double length)
2119 gui->lock_window("MWindow::set_edit_length 1");
2121 undo->update_undo_before();
2122 double start = edl->local_session->get_selectionstart();
2123 double end = edl->local_session->get_selectionend();
2125 edl->tracks->set_edit_length(start, end, length);
2128 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
2130 sync_parameters(CHANGE_EDL);
2132 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2133 gui->unlock_window();
2137 void MWindow::set_transition_length(Transition *transition, double length)
2139 gui->lock_window("MWindow::set_transition_length 1");
2141 undo->update_undo_before();
2142 //double start = edl->local_session->get_selectionstart();
2143 //double end = edl->local_session->get_selectionend();
2145 edl->tracks->set_transition_length(transition, length);
2148 undo->update_undo_after(_("transition length"), LOAD_EDITS);
2150 edl->session->default_transition_length = length;
2151 sync_parameters(CHANGE_PARAMS);
2152 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2153 gui->unlock_window();
2156 void MWindow::set_transition_length(double length)
2158 gui->lock_window("MWindow::set_transition_length 2");
2160 undo->update_undo_before();
2161 double start = edl->local_session->get_selectionstart();
2162 double end = edl->local_session->get_selectionend();
2164 edl->tracks->set_transition_length(start, end, length);
2167 undo->update_undo_after(_("transition length"), LOAD_EDITS);
2169 edl->session->default_transition_length = length;
2170 sync_parameters(CHANGE_PARAMS);
2172 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2173 gui->unlock_window();
2177 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2179 calling_window_gui->unlock_window();
2181 if( undo->redo_load_flags() & LOAD_SESSION )
2184 cwindow->gui->lock_window("MWindow::redo_entry 1");
2185 for( int i=0; i<vwindows.size(); ++i ) {
2186 if( vwindows.get(i)->is_running() ) {
2187 if( calling_window_gui != vwindows.get(i)->gui ) {
2188 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2192 gui->lock_window("MWindow::redo_entry 3");
2198 update_plugin_states();
2199 update_plugin_guis();
2201 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2202 gui->update_proxy_toggle();
2203 gui->unlock_window();
2204 cwindow->update(1, 1, 1, 1, 1);
2205 cwindow->gui->unlock_window();
2207 for( int i=0; i < vwindows.size(); ++i ) {
2208 if( vwindows.get(i)->is_running() ) {
2209 if( calling_window_gui != vwindows.get(i)->gui ) {
2210 vwindows.get(i)->gui->unlock_window();
2215 awindow->gui->async_update_assets();
2217 cwindow->refresh_frame(CHANGE_ALL);
2218 calling_window_gui->lock_window("MWindow::redo_entry 4");
2222 void MWindow::resize_track(Track *track, int w, int h)
2224 undo->update_undo_before();
2225 // We have to move all maskpoints so they do not move in relation to image areas
2226 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2227 (w - track->track_w) / 2,
2228 (h - track->track_h) / 2);
2231 undo->update_undo_after(_("resize track"), LOAD_ALL);
2235 sync_parameters(CHANGE_EDL);
2239 void MWindow::set_inpoint(int is_mwindow)
2241 undo->update_undo_before();
2242 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2244 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
2247 gui->lock_window("MWindow::set_inpoint 1");
2249 gui->update_timebar(1);
2251 gui->unlock_window();
2255 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2257 cwindow->gui->timebar->update(1);
2259 cwindow->gui->unlock_window();
2263 void MWindow::set_outpoint(int is_mwindow)
2265 undo->update_undo_before();
2266 edl->set_outpoint(edl->local_session->get_selectionend(1));
2268 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
2271 gui->lock_window("MWindow::set_outpoint 1");
2273 gui->update_timebar(1);
2275 gui->unlock_window();
2279 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2281 cwindow->gui->timebar->update(1);
2283 cwindow->gui->unlock_window();
2287 void MWindow::unset_inoutpoint(int is_mwindow)
2289 undo->update_undo_before();
2290 edl->unset_inoutpoint();
2292 undo->update_undo_after(_("clear in/out"), LOAD_TIMEBAR);
2295 gui->lock_window("MWindow::unset_inoutpoint 1");
2297 gui->update_timebar(1);
2299 gui->unlock_window();
2303 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2305 cwindow->gui->timebar->update(1);
2307 cwindow->gui->unlock_window();
2311 void MWindow::splice(EDL *source, int all)
2314 LocalSession *src = source->local_session;
2316 undo->update_undo_before();
2317 double source_start = all ? 0 :
2318 src->inpoint_valid() ? src->get_inpoint() :
2319 src->outpoint_valid() ? 0 : src->get_selectionstart();
2320 double source_end = all ? source->tracks->total_length() :
2321 src->outpoint_valid() ? src->get_outpoint() :
2322 src->inpoint_valid() ? source->tracks->total_length() :
2323 src->get_selectionend();
2324 source->copy(source_start, source_end, 1, &file, "", 1);
2326 double start = edl->local_session->get_selectionstart();
2327 //double end = edl->local_session->get_selectionend();
2329 paste(start, start, &file,
2330 edl->session->labels_follow_edits,
2331 edl->session->plugins_follow_edits,
2332 edl->session->autos_follow_edits,
2335 // Position at end of clip
2336 edl->local_session->set_selectionstart(start + source_end - source_start);
2337 edl->local_session->set_selectionend(start + source_end - source_start);
2340 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2341 update_plugin_guis();
2343 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2344 sync_parameters(CHANGE_EDL);
2347 void MWindow::save_clip(EDL *new_edl, const char *txt)
2349 new_edl->local_session->set_selectionstart(0);
2350 new_edl->local_session->set_selectionend(0);
2351 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2352 session->clip_number++);
2353 char duration[BCTEXTLEN];
2354 Units::totext(duration, new_edl->tracks->total_length(),
2355 new_edl->session->time_format,
2356 new_edl->session->sample_rate,
2357 new_edl->session->frame_rate,
2358 new_edl->session->frames_per_foot);
2360 Track *track = new_edl->tracks->first;
2361 const char *path = edl->path;
2362 for( ; (!path || !*path) && track; track=track->next ) {
2363 if( !track->record ) continue;
2364 Edit *edit = track->edits->first;
2365 if( !edit ) continue;
2366 Indexable *indexable = edit->get_source();
2367 if( !indexable ) continue;
2368 path = indexable->path;
2371 time_t now; time(&now);
2372 struct tm dtm; localtime_r(&now, &dtm);
2373 char *cp = new_edl->local_session->clip_notes;
2374 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2376 n = snprintf(cp, sz, "%s", txt);
2379 n = snprintf(cp, sz,
2380 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2381 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2382 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2384 if( path && *path ) {
2386 char title[BCTEXTLEN];
2387 fs.extract_name(title, path);
2388 n = snprintf(cp, sz, "%s", title);
2392 sprintf(new_edl->local_session->clip_icon,
2393 "clip_%02d%02d%02d-%02d%02d%02d.png",
2394 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2395 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
2396 new_edl->folder_no = AW_CLIP_FOLDER;
2397 edl->update_assets(new_edl);
2399 gui->get_abs_cursor(cur_x, cur_y, 0);
2400 gui->unlock_window();
2402 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2403 new_edl->remove_user();
2405 gui->lock_window("MWindow::save_clip");
2409 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2412 LocalSession *src = edl->local_session;
2414 gui->lock_window("MWindow::to_clip 1");
2415 double start = all ? 0 :
2416 src->inpoint_valid() ? src->get_inpoint() :
2417 src->outpoint_valid() ? 0 : src->get_selectionstart();
2418 double end = all ? edl->tracks->total_length() :
2419 src->outpoint_valid() ? src->get_outpoint() :
2420 src->inpoint_valid() ? edl->tracks->total_length() :
2421 src->get_selectionend();
2422 if( EQUIV(end, start) ) {
2424 end = edl->tracks->total_length();
2427 // Don't copy all since we don't want the clips twice.
2428 edl->copy(start, end, 0, &file, "", 1);
2430 EDL *new_edl = new EDL(edl);
2431 new_edl->create_objects();
2432 new_edl->load_xml(&file, LOAD_ALL);
2433 save_clip(new_edl, txt);
2434 gui->unlock_window();
2437 int MWindow::toggle_label(int is_mwindow)
2439 double position1, position2;
2440 undo->update_undo_before();
2442 if( cwindow->playback_engine->is_playing_back ) {
2443 position1 = position2 =
2444 cwindow->playback_engine->get_tracking_position();
2447 position1 = edl->local_session->get_selectionstart(1);
2448 position2 = edl->local_session->get_selectionend(1);
2451 position1 = edl->align_to_frame(position1, 0);
2452 position2 = edl->align_to_frame(position2, 0);
2454 //printf("MWindow::toggle_label 1\n");
2456 edl->labels->toggle_label(position1, position2);
2460 gui->lock_window("MWindow::toggle_label 1");
2462 gui->update_timebar(0);
2463 gui->activate_timeline();
2466 gui->unlock_window();
2470 cwindow->gui->lock_window("MWindow::toggle_label 2");
2472 cwindow->gui->timebar->update(1);
2474 cwindow->gui->unlock_window();
2477 awindow->gui->async_update_assets();
2479 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2483 void MWindow::trim_selection()
2485 undo->update_undo_before();
2488 edl->trim_selection(edl->local_session->get_selectionstart(),
2489 edl->local_session->get_selectionend(),
2490 edl->session->labels_follow_edits,
2491 edl->session->plugins_follow_edits,
2492 edl->session->autos_follow_edits);
2495 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2496 update_plugin_guis();
2497 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2498 cwindow->update(1, 0, 0, 0, 1);
2499 awindow->gui->async_update_assets();
2501 cwindow->refresh_frame(CHANGE_EDL);
2505 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2507 calling_window_gui->unlock_window();
2509 if( undo->undo_load_flags() & LOAD_SESSION )
2512 cwindow->gui->lock_window("MWindow::undo_entry 1");
2513 for( int i=0; i<vwindows.size(); ++i ) {
2514 if( vwindows.get(i)->is_running() ) {
2515 if( calling_window_gui != vwindows.get(i)->gui ) {
2516 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2520 gui->lock_window("MWindow::undo_entry 2");
2526 update_plugin_states();
2527 update_plugin_guis();
2529 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2530 gui->update_proxy_toggle();
2531 gui->unlock_window();
2532 cwindow->update(1, 1, 1, 1, 1);
2533 cwindow->gui->unlock_window();
2535 for( int i=0; i<vwindows.size(); ++i ) {
2536 if( vwindows.get(i)->is_running() ) {
2537 if( calling_window_gui != vwindows.get(i)->gui ) {
2538 vwindows.get(i)->gui->unlock_window();
2543 awindow->gui->async_update_assets();
2545 cwindow->refresh_frame(CHANGE_ALL);
2546 calling_window_gui->lock_window("MWindow::undo_entry 4");
2550 void MWindow::new_folder(const char *new_folder, int is_clips)
2552 undo->update_undo_before();
2553 if( edl->new_folder(new_folder, is_clips) ) {
2554 MainError::show_error(_("create new folder failed"));
2556 undo->update_undo_after(_("new folder"), LOAD_ALL);
2557 awindow->gui->async_update_assets();
2560 void MWindow::delete_folder(char *folder)
2562 undo->update_undo_before();
2563 if( edl->delete_folder(folder) < 0 ) {
2564 MainError::show_error(_("delete folder failed"));
2566 undo->update_undo_after(_("del folder"), LOAD_ALL);
2567 awindow->gui->async_update_assets();
2570 void MWindow::select_point(double position)
2572 gui->unlock_window();
2573 gui->stop_drawing();
2574 cwindow->stop_playback(0);
2575 gui->lock_window("MWindow::select_point");
2577 edl->local_session->set_selectionstart(position);
2578 edl->local_session->set_selectionend(position);
2581 cwindow->update(1, 0, 0, 0, 1);
2583 update_plugin_guis();
2584 gui->update_patchbay();
2585 gui->hide_cursor(0);
2586 gui->draw_cursor(0);
2587 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2588 gui->zoombar->update();
2589 gui->update_timebar(0);
2590 gui->flash_canvas(0);
2597 void MWindow::map_audio(int pattern)
2599 undo->update_undo_before();
2600 remap_audio(pattern);
2601 undo->update_undo_after(
2602 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2604 sync_parameters(CHANGE_PARAMS);
2605 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2608 void MWindow::remap_audio(int pattern)
2610 int current_channel = 0;
2611 int current_track = 0;
2612 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2613 if( current->data_type == TRACK_AUDIO &&
2615 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2616 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2618 for( int i=0; i < MAXCHANNELS; ++i ) {
2619 pan_auto->values[i] = 0.0;
2622 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2623 pan_auto->values[current_channel] = 1.0;
2626 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2627 switch( current_track ) {
2630 pan_auto->values[0] = 1;
2634 pan_auto->values[1] = 1;
2638 pan_auto->values[0] = 0.5;
2639 pan_auto->values[1] = 0.5;
2644 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2645 edl->session->achannel_positions, pan_auto->values,
2646 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2650 if( current_channel >= edl->session->audio_channels )
2651 current_channel = 0;
2657 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2659 edl->rescale_proxy(orig_scale, new_scale);
2662 void MWindow::add_proxy(int use_scaler,
2663 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2665 edl->add_proxy(use_scaler, orig_assets, proxy_assets);
2668 void MWindow::cut_commercials()
2670 #ifdef HAVE_COMMERCIAL
2671 undo->update_undo_before();
2672 commercials->scan_media();
2675 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2678 update_plugin_guis();
2679 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2680 cwindow->update(1, 0, 0, 0, 1);
2681 cwindow->refresh_frame(CHANGE_EDL);
2685 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2688 Track *old_track = old_edl->tracks->first;
2689 Track *new_track = new_edl->tracks->first;
2690 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2691 if( old_track->data_type != new_track->data_type ) continue;
2692 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2693 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2694 if( !old_speeds || !new_speeds ) continue;
2695 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2696 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2697 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2698 old_speed = (FloatAuto *)old_speed->next;
2699 new_speed = (FloatAuto *)new_speed->next;
2701 Edit *old_edit = old_track->edits->first;
2702 Edit *new_edit = new_track->edits->first;
2703 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2704 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2705 if( old_speed || new_speed ) {
2706 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2707 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2708 edit_start = new_speeds->speed_position(orig_start);
2709 edit_end = new_speeds->speed_position(orig_end);
2712 new_edit->startproject = edit_start;
2713 new_edit->length = edit_end - edit_start;
2719 void MWindow::speed_before()
2722 speed_edl = new EDL;
2723 speed_edl->create_objects();
2725 speed_edl->copy_all(edl);
2728 int MWindow::speed_after(int done)
2733 result = normalize_speed(speed_edl, edl);
2735 speed_edl->remove_user();