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,
835 session->drag_edit->group_id);
837 finish_modify_handles();
838 //printf("MWindow::modify_handles 1\n");
842 int MWindow::modify_pluginhandles()
844 undo->update_undo_before();
846 edl->modify_pluginhandles(session->drag_start,
847 session->drag_position,
848 session->drag_handle,
849 edl->session->edit_handle_mode[session->drag_button],
850 edl->session->labels_follow_edits,
851 edl->session->autos_follow_edits,
852 session->trim_edits);
854 finish_modify_handles();
860 // Common to edithandles and plugin handles
861 void MWindow::finish_modify_handles()
863 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
865 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
866 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
867 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
868 edl->local_session->set_selectionstart(session->drag_position);
869 edl->local_session->set_selectionend(session->drag_position);
872 if( edit_mode != MOVE_NO_EDITS ) {
873 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
874 edl->local_session->set_selectionstart(session->drag_start);
875 edl->local_session->set_selectionend(session->drag_start);
878 // clamp the selection to 0
879 if( edl->local_session->get_selectionstart(1) < 0 ) {
880 edl->local_session->set_selectionstart(0);
881 edl->local_session->set_selectionend(0);
883 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
887 sync_parameters(CHANGE_EDL);
888 update_plugin_guis();
889 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
890 // label list can be modified
891 awindow->gui->async_update_assets();
892 cwindow->update(1, 0, 0, 0, 1);
895 void MWindow::match_output_size(Track *track)
897 undo->update_undo_before();
898 track->track_w = edl->session->output_w;
899 track->track_h = edl->session->output_h;
901 undo->update_undo_after(_("match output size"), LOAD_ALL);
904 sync_parameters(CHANGE_EDL);
908 EDL *MWindow::selected_edits_to_clip(int packed,
909 double *start_position, Track **start_track,
910 int edit_labels, int edit_autos, int edit_plugins)
912 double start = DBL_MAX, end = DBL_MIN;
913 Track *first_track=0, *last_track = 0;
914 for( Track *track=edl->tracks->first; track; track=track->next ) {
915 if( !track->record ) continue;
917 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
918 if( !edit->is_selected || edit->silence() ) continue;
919 double edit_pos = track->from_units(edit->startproject);
920 if( start > edit_pos ) start = edit_pos;
921 if( end < (edit_pos+=edit->length) ) end = edit_pos;
924 if( empty ) continue;
925 if( !first_track ) first_track = track;
928 if( start_position ) *start_position = start;
929 if( start_track ) *start_track = first_track;
930 if( !first_track ) return 0;
931 EDL *new_edl = new EDL();
932 new_edl->create_objects();
933 new_edl->copy_session(edl);
934 const char *text = _("new_edl edit");
935 new_edl->set_path(text);
936 strcpy(new_edl->local_session->clip_title, text);
937 strcpy(new_edl->local_session->clip_notes, text);
938 new_edl->session->video_tracks = 0;
939 new_edl->session->audio_tracks = 0;
940 for( Track *track=edl->tracks->first; track; track=track->next ) {
941 if( !track->record ) continue;
943 if( first_track != track ) continue;
946 Track *new_track = 0;
948 new_track = new_edl->add_new_track(track->data_type);
949 int64_t start_pos = track->to_units(start, 0);
950 int64_t end_pos = track->to_units(end, 0);
951 int64_t startproject = 0;
952 Edit *edit = track->edits->first;
953 for( ; edit; edit=edit->next ) {
954 if( !edit->is_selected || edit->silence() ) continue;
955 if( edit->startproject < start_pos ) continue;
956 if( edit->startproject >= end_pos ) break;
957 int64_t edit_start_pos = edit->startproject;
958 int64_t edit_end_pos = edit->startproject + edit->length;
960 new_track = new_edl->add_new_track(track->data_type);
961 int64_t edit_pos = edit_start_pos - start_pos;
962 if( !packed && 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;
969 int64_t clip_start_pos = startproject;
970 Edit *clip_edit = new Edit(new_edl, new_track);
971 clip_edit->copy_from(edit);
972 clip_edit->startproject = startproject;
973 startproject += clip_edit->length;
974 new_track->edits->append(clip_edit);
976 double edit_start = track->from_units(edit_start_pos);
977 double edit_end = track->from_units(edit_end_pos);
978 double clip_start = new_track->from_units(clip_start_pos);
979 Label *label = edl->labels->first;
980 for( ; label; label=label->next ) {
981 if( label->position < edit_start ) continue;
982 if( label->position >= edit_end ) break;
983 double clip_position = label->position - edit_start + clip_start;
984 Label *clip_label = new_edl->labels->first;
985 while( clip_label && clip_label->position<clip_position )
986 clip_label = clip_label->next;
987 if( clip_label && clip_label->position == clip_position ) continue;
988 Label *new_label = new Label(new_edl,
989 new_edl->labels, clip_position, label->textstr);
990 new_edl->labels->insert_before(clip_label, new_label);
994 Automation *automation = track->automation;
995 Automation *new_automation = new_track->automation;
996 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
997 Autos *autos = automation->autos[i];
998 if( !autos ) continue;
999 Autos *new_autos = new_automation->autos[i];
1000 new_autos->default_auto->copy_from(autos->default_auto);
1001 Auto *aut0 = autos->first;
1002 for( ; aut0; aut0=aut0->next ) {
1003 if( aut0->position < edit_start_pos ) continue;
1004 if( aut0->position >= edit_end_pos ) break;
1005 Auto *new_auto = new_autos->new_auto();
1006 new_auto->copy_from(aut0);
1007 int64_t clip_position = aut0->position - edit_start_pos + clip_start_pos;
1008 new_auto->position = clip_position;
1009 new_autos->append(new_auto);
1013 if( edit_plugins ) {
1014 while( new_track->plugin_set.size() < track->plugin_set.size() )
1015 new_track->plugin_set.append(0);
1016 for( int i=0; i<track->plugin_set.total; ++i ) {
1017 PluginSet *plugin_set = track->plugin_set[i];
1018 if( !plugin_set ) continue;
1019 PluginSet *new_plugin_set = new_track->plugin_set[i];
1020 if( !new_plugin_set ) {
1021 new_plugin_set = new PluginSet(new_edl, new_track);
1022 new_track->plugin_set[i] = new_plugin_set;
1024 Plugin *plugin = (Plugin*)plugin_set->first;
1025 int64_t startplugin = new_plugin_set->length();
1026 for( ; plugin ; plugin=(Plugin*)plugin->next ) {
1027 if( plugin->silence() ) continue;
1028 int64_t plugin_start_pos = plugin->startproject;
1029 int64_t plugin_end_pos = plugin_start_pos + plugin->length;
1030 if( plugin_end_pos < start_pos ) continue;
1031 if( plugin_start_pos > end_pos ) break;
1032 if( plugin_start_pos < edit_start_pos )
1033 plugin_start_pos = edit_start_pos;
1034 if( plugin_end_pos > edit_end_pos )
1035 plugin_end_pos = edit_end_pos;
1036 if( plugin_start_pos >= plugin_end_pos ) continue;
1037 int64_t plugin_pos = plugin_start_pos - start_pos;
1038 if( !packed && plugin_pos > startplugin ) {
1039 Plugin *silence = new Plugin(new_edl, new_track, "");
1040 silence->startproject = startplugin;
1041 silence->length = plugin_pos - startplugin;
1042 new_plugin_set->append(silence);
1043 startplugin = plugin_pos;
1045 Plugin *new_plugin = new Plugin(new_edl, new_track, plugin->title);
1046 new_plugin->copy_base(plugin);
1047 new_plugin->startproject = startplugin;
1048 new_plugin->length = plugin_end_pos - plugin_start_pos;
1049 startplugin += new_plugin->length;
1050 new_plugin_set->append(new_plugin);
1051 KeyFrames *keyframes = plugin->keyframes;
1052 KeyFrames *new_keyframes = new_plugin->keyframes;
1053 new_keyframes->default_auto->copy_from(keyframes->default_auto);
1054 new_keyframes->default_auto->position = new_plugin->startproject;
1055 KeyFrame *keyframe = (KeyFrame*)keyframes->first;
1056 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
1057 if( keyframe->position < edit_start_pos ) continue;
1058 if( keyframe->position >= edit_end_pos ) break;
1059 KeyFrame *clip_keyframe = new KeyFrame(new_edl, new_keyframes);
1060 clip_keyframe->copy_from(keyframe);
1061 int64_t key_position = keyframe->position - start_pos;
1063 key_position += new_plugin->startproject - plugin_pos;
1064 clip_keyframe->position = key_position;
1065 new_keyframes->append(clip_keyframe);
1071 if( last_track == track ) break;
1076 void MWindow::selected_edits_to_clipboard(int packed)
1078 EDL *new_edl = selected_edits_to_clip(packed, 0, 0,
1079 edl->session->labels_follow_edits,
1080 edl->session->autos_follow_edits,
1081 edl->session->plugins_follow_edits);
1082 if( !new_edl ) return;
1083 double length = new_edl->tracks->total_length();
1085 new_edl->copy(0, length, 1, &file, "", 1);
1086 const char *file_string = file.string();
1087 long file_length = strlen(file_string);
1088 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1089 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1090 new_edl->remove_user();
1093 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
1095 ArrayList<Edit*> edits;
1097 delete_edits(&edits, msg, collapse);
1100 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
1102 if( !edits->size() ) return;
1103 undo->update_undo_before();
1104 if( edl->session->labels_follow_edits )
1105 edl->delete_edit_labels(edits, collapse);
1106 edl->delete_edits(edits, collapse);
1109 undo->update_undo_after(msg, LOAD_EDITS);
1112 cwindow->refresh_frame(CHANGE_EDL);
1113 update_plugin_guis();
1114 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1117 void MWindow::delete_edits(int collapse)
1119 ArrayList<Edit*> edits;
1120 edl->tracks->get_selected_edits(&edits);
1121 delete_edits(&edits,_("del edit"), collapse);
1124 // collapse - delete from timeline, not collapse replace with silence
1125 // packed - omit unselected from selection, unpacked - replace unselected with silence
1126 void MWindow::cut_selected_edits(int collapse, int packed)
1128 selected_edits_to_clipboard(packed);
1129 ArrayList<Edit*> edits;
1130 edl->tracks->get_selected_edits(&edits);
1131 delete_edits(&edits, _("cut edit"), collapse);
1135 void MWindow::move_edits(ArrayList<Edit*> *edits,
1136 Track *track, double position, int mode)
1138 undo->update_undo_before();
1139 // lockout timebar labels update
1140 // labels can be deleted with tooltip repeater running
1141 cwindow->gui->lock_window("Tracks::move_edits");
1142 edl->tracks->move_edits(edits, track, position,
1143 edl->session->labels_follow_edits,
1144 edl->session->plugins_follow_edits,
1145 edl->session->autos_follow_edits, mode);
1146 cwindow->gui->timebar->update(1);
1147 cwindow->gui->unlock_window();
1150 undo->update_undo_after(_("move edit"), LOAD_ALL);
1153 cwindow->refresh_frame(CHANGE_EDL);
1155 update_plugin_guis();
1156 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1159 void MWindow::paste_edits(EDL *clip, Track *first_track, double position, int overwrite,
1160 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1163 first_track = edl->tracks->first;
1164 Track *src = clip->tracks->first;
1165 for( Track *track=first_track; track && src; track=track->next ) {
1166 if( !track->record ) continue;
1167 int64_t pos = track->to_units(position, 0);
1169 for( Edit *edit=src->edits->first; edit; edit=edit->next ) {
1170 if( edit->silence() ) continue;
1171 int64_t start = pos + edit->startproject;
1172 int64_t len = edit->length, end = start + len;
1174 track->edits->clear(start, end);
1175 Edit *dst = track->edits->insert_new_edit(start);
1176 dst->copy_from(edit);
1177 dst->startproject = start;
1178 dst->is_selected = 1;
1179 while( (dst=dst->next) != 0 )
1180 dst->startproject += edit->length;
1181 if( overwrite ) continue;
1182 if( edit_labels && track == first_track ) {
1183 double dst_pos = track->from_units(start);
1184 double dst_len = track->from_units(len);
1185 for( Label *label=edl->labels->first; label; label=label->next ) {
1186 if( label->position >= dst_pos )
1187 label->position += dst_len;
1191 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
1192 Autos *autos = track->automation->autos[i];
1193 if( !autos ) continue;
1194 for( Auto *aut0=autos->first; aut0; aut0=aut0->next ) {
1195 if( aut0->position >= start )
1196 aut0->position += edit->length;
1200 if( edit_plugins ) {
1201 for( int i=0; i<track->plugin_set.size(); ++i ) {
1202 PluginSet *plugin_set = track->plugin_set[i];
1203 Plugin *plugin = (Plugin *)plugin_set->first;
1204 for( ; plugin; plugin=(Plugin *)plugin->next ) {
1205 if( plugin->startproject >= start )
1206 plugin->startproject += edit->length;
1207 else if( plugin->startproject+plugin->length > end )
1208 plugin->length += edit->length;
1209 Auto *default_keyframe = plugin->keyframes->default_auto;
1210 if( default_keyframe->position >= start )
1211 default_keyframe->position += edit->length;
1212 KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
1213 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
1214 if( keyframe->position >= start )
1215 keyframe->position += edit->length;
1218 plugin_set->optimize();
1224 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
1225 Autos *src_autos = src->automation->autos[i];
1226 if( !src_autos ) continue;
1227 Autos *autos = track->automation->autos[i];
1228 for( Auto *aut0=src_autos->first; aut0; aut0=aut0->next ) {
1229 int64_t auto_pos = pos + aut0->position;
1230 autos->insert_auto(auto_pos, aut0);
1234 if( edit_plugins ) {
1235 for( int i=0; i<src->plugin_set.size(); ++i ) {
1236 PluginSet *plugin_set = src->plugin_set[i];
1237 if( !plugin_set ) continue;
1238 while( i >= track->plugin_set.size() )
1239 track->plugin_set.append(0);
1240 PluginSet *dst_plugin_set = track->plugin_set[i];
1241 if( !dst_plugin_set ) {
1242 dst_plugin_set = new PluginSet(edl, track);
1243 track->plugin_set[i] = dst_plugin_set;
1245 Plugin *plugin = (Plugin *)plugin_set->first;
1246 if( plugin ) track->expand_view = 1;
1247 for( ; plugin; plugin=(Plugin *)plugin->next ) {
1248 int64_t start = pos + plugin->startproject;
1249 int64_t end = start + plugin->length;
1250 if( overwrite || edit_edits )
1251 dst_plugin_set->clear(start, end, 1);
1252 Plugin *new_plugin = dst_plugin_set->insert_plugin(plugin->title,
1253 start, end-start, plugin->plugin_type, &plugin->shared_location,
1254 (KeyFrame*)plugin->keyframes->default_auto, 0);
1255 KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
1256 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next ) {
1257 int64_t keyframe_pos = pos + keyframe->position;
1258 new_plugin->keyframes->insert_auto(keyframe_pos, keyframe);
1260 while( (new_plugin=(Plugin *)new_plugin->next) ) {
1261 KeyFrame *keyframe = (KeyFrame*)new_plugin->keyframes->first;
1262 for( ; keyframe; keyframe=(KeyFrame*)keyframe->next )
1263 keyframe->position += plugin->length;
1271 Label *edl_label = edl->labels->first;
1272 for( Label *label=clip->labels->first; label; label=label->next ) {
1273 double label_pos = position + label->position;
1276 !(exists=edl->equivalent(edl_label->position, label_pos)) &&
1277 edl_label->position < position ) edl_label = edl_label->next;
1278 if( exists ) continue;
1279 edl->labels->insert_before(edl_label,
1280 new Label(edl, edl->labels, label_pos, label->textstr));
1286 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1287 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1289 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1291 char *string = new char[len];
1292 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1294 file.read_from_string(string);
1296 EDL *clip = new EDL();
1297 clip->create_objects();
1298 if( !clip->load_xml(&file, LOAD_ALL) ) {
1299 undo->update_undo_before();
1300 paste_edits(clip, first_track, position, overwrite,
1301 edit_edits, edit_labels, edit_autos, edit_plugins);
1303 undo->update_undo_after(_("paste clip"), LOAD_ALL);
1305 cwindow->refresh_frame(CHANGE_EDL);
1307 update_plugin_guis();
1308 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1310 clip->remove_user();
1313 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1315 undo->update_undo_before();
1316 // lockout timebar labels update
1317 // labels can be deleted with tooltip repeater running
1318 cwindow->gui->lock_window("Tracks::move_group");
1320 ArrayList<Edit *>edits;
1321 edl->tracks->get_selected_edits(&edits);
1322 if( edl->session->labels_follow_edits )
1323 edl->delete_edit_labels(&edits, 0);
1324 edl->delete_edits(&edits, 0);
1325 paste_edits(group, first_track, position, overwrite, 1,
1326 edl->session->labels_follow_edits,
1327 edl->session->autos_follow_edits,
1328 edl->session->plugins_follow_edits);
1329 cwindow->gui->timebar->update(1);
1330 cwindow->gui->unlock_window();
1331 // big debate over whether to do this, must either clear selected, or no tweaking
1332 // edl->tracks->clear_selected_edits();
1335 undo->update_undo_after(_("move group"), LOAD_ALL);
1337 cwindow->refresh_frame(CHANGE_EDL);
1339 update_plugin_guis();
1340 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1343 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1345 undo->update_undo_before();
1346 edl->tracks->move_effect(plugin, track, position);
1348 undo->update_undo_after(_("paste effect"), LOAD_ALL);
1351 cwindow->refresh_frame(CHANGE_EDL);
1352 update_plugin_guis();
1353 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1356 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1358 undo->update_undo_before();
1359 edl->tracks->move_effect(plugin, plugin_set, position);
1361 undo->update_undo_after(_("move effect"), LOAD_ALL);
1364 cwindow->refresh_frame(CHANGE_EDL);
1365 update_plugin_guis();
1366 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1369 void MWindow::move_plugins_up(PluginSet *plugin_set)
1372 undo->update_undo_before();
1373 plugin_set->track->move_plugins_up(plugin_set);
1376 undo->update_undo_after(_("move effect up"), LOAD_ALL);
1378 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1379 sync_parameters(CHANGE_EDL);
1382 void MWindow::move_plugins_down(PluginSet *plugin_set)
1384 undo->update_undo_before();
1386 plugin_set->track->move_plugins_down(plugin_set);
1389 undo->update_undo_after(_("move effect down"), LOAD_ALL);
1391 gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1392 sync_parameters(CHANGE_EDL);
1395 void MWindow::move_track_down(Track *track)
1397 undo->update_undo_before();
1398 edl->tracks->move_track_down(track);
1400 undo->update_undo_after(_("move track down"), LOAD_ALL);
1403 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1404 sync_parameters(CHANGE_EDL);
1408 void MWindow::move_tracks_down()
1410 undo->update_undo_before();
1411 edl->tracks->move_tracks_down();
1413 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1416 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1417 sync_parameters(CHANGE_EDL);
1421 void MWindow::move_track_up(Track *track)
1423 undo->update_undo_before();
1424 edl->tracks->move_track_up(track);
1426 undo->update_undo_after(_("move track up"), LOAD_ALL);
1428 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1429 sync_parameters(CHANGE_EDL);
1433 void MWindow::move_tracks_up()
1435 undo->update_undo_before();
1436 edl->tracks->move_tracks_up();
1438 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1440 gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1441 sync_parameters(CHANGE_EDL);
1445 void MWindow::mute_selection()
1447 double start = edl->local_session->get_selectionstart();
1448 double end = edl->local_session->get_selectionend();
1449 if( start != end ) {
1450 undo->update_undo_before();
1451 edl->clear(start, end, 0,
1452 edl->session->plugins_follow_edits,
1453 edl->session->autos_follow_edits);
1454 edl->local_session->set_selectionend(end);
1455 edl->local_session->set_selectionstart(start);
1456 edl->paste_silence(start, end, 0,
1457 edl->session->plugins_follow_edits,
1458 edl->session->autos_follow_edits);
1461 undo->update_undo_after(_("mute"), LOAD_EDITS);
1464 update_plugin_guis();
1465 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1466 cwindow->refresh_frame(CHANGE_EDL);
1471 void MWindow::overwrite(EDL *source, int all)
1475 LocalSession *src = source->local_session;
1476 double src_start = all ? 0 :
1477 src->inpoint_valid() ? src->get_inpoint() :
1478 src->outpoint_valid() ? 0 :
1479 src->get_selectionstart();
1480 double src_end = all ? source->tracks->total_length() :
1481 src->outpoint_valid() ? src->get_outpoint() :
1482 src->inpoint_valid() ? source->tracks->total_length() :
1483 src->get_selectionend();
1484 double overwrite_len = src_end - src_start;
1485 double dst_start = edl->local_session->get_selectionstart();
1486 double dst_len = edl->local_session->get_selectionend() - dst_start;
1488 undo->update_undo_before();
1489 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1490 // in/out points or selection present and shorter than overwrite range
1491 // shorten the copy range
1492 overwrite_len = dst_len;
1495 source->copy(src_start, src_start + overwrite_len, 0, &file, "", 1);
1497 // HACK around paste_edl get_start/endselection on its own
1498 // so we need to clear only when not using both io points
1499 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1500 if( edl->local_session->get_inpoint() < 0 ||
1501 edl->local_session->get_outpoint() < 0 )
1502 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1504 paste(dst_start, dst_start + overwrite_len, &file, 0, 0, 0, 0, 0);
1506 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1507 edl->local_session->set_selectionend(dst_start + overwrite_len);
1510 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1513 update_plugin_guis();
1514 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1515 sync_parameters(CHANGE_EDL);
1518 // For splice and overwrite
1519 int MWindow::paste(double start, double end, FileXML *file,
1520 int edit_labels, int edit_plugins, int edit_autos,
1521 Track *first_track, int overwrite)
1525 // Want to insert with assets shared with the master EDL.
1527 edit_labels, edit_plugins, edit_autos,
1528 edl, first_track, overwrite);
1533 // For editing using insertion point
1534 void MWindow::paste()
1536 paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1539 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1541 //double end = edl->local_session->get_selectionend();
1542 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1545 char *string = new char[len];
1546 undo->update_undo_before();
1547 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1549 file.read_from_string(string);
1550 if( clear_selection ) clear(0);
1552 insert(start, &file,
1553 edl->session->labels_follow_edits,
1554 edl->session->plugins_follow_edits,
1555 edl->session->autos_follow_edits,
1556 0, first_track, overwrite);
1563 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1565 update_plugin_guis();
1566 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1567 awindow->gui->async_update_assets();
1568 sync_parameters(CHANGE_EDL);
1573 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1576 undo->update_undo_before();
1578 if( session->drag_assets->total ) {
1579 load_assets(session->drag_assets,
1580 position, LOADMODE_PASTE, dest_track, 0,
1581 edl->session->labels_follow_edits,
1582 edl->session->plugins_follow_edits,
1583 edl->session->autos_follow_edits,
1588 if( session->drag_clips->total ) {
1589 paste_edls(session->drag_clips,
1590 LOADMODE_PASTE, dest_track, position,
1591 edl->session->labels_follow_edits,
1592 edl->session->plugins_follow_edits,
1593 edl->session->autos_follow_edits,
1600 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1602 gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1603 sync_parameters(CHANGE_EDL);
1607 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1608 double position, int load_mode, Track *first_track, RecordLabels *labels,
1609 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1611 if( load_mode == LOADMODE_RESOURCESONLY )
1612 load_mode = LOADMODE_ASSETSONLY;
1613 const int debug = 0;
1614 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1615 if( position < 0 ) position = edl->local_session->get_selectionstart();
1617 ArrayList<EDL*> new_edls;
1618 for( int i=0; i<new_assets->total; ++i ) {
1619 Indexable *indexable = new_assets->get(i);
1620 if( indexable->is_asset ) {
1621 remove_asset_from_caches((Asset*)indexable);
1623 EDL *new_edl = new EDL;
1624 new_edl->create_objects();
1625 new_edl->copy_session(edl);
1626 if( !indexable->is_asset ) {
1627 EDL *nested_edl = (EDL*)indexable;
1628 new_edl->create_nested(nested_edl);
1629 new_edl->set_path(indexable->path);
1632 Asset *asset = (Asset*)indexable;
1633 asset_to_edl(new_edl, asset);
1635 new_edls.append(new_edl);
1638 for( RecordLabel *label=labels->first; label; label=label->next ) {
1639 new_edl->labels->toggle_label(label->position, label->position);
1643 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1645 paste_edls(&new_edls, load_mode, first_track, position,
1646 edit_labels, edit_plugins, edit_autos, overwrite);
1647 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1650 for( int i=0; i<new_edls.size(); ++i )
1651 new_edls.get(i)->Garbage::remove_user();
1653 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1656 int MWindow::paste_automation()
1658 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1661 undo->update_undo_before();
1663 char *string = new char[len];
1664 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1666 file.read_from_string(string);
1668 double start = edl->local_session->get_selectionstart();
1669 double end = edl->local_session->get_selectionend();
1670 edl->tracks->clear_automation(start, end);
1671 edl->tracks->paste_automation(start, &file, 0, 1,
1672 edl->session->typeless_keyframes);
1673 int changed_edl = speed_after(1);
1675 undo->update_undo_after(_("paste keyframes"),
1676 !changed_edl ? LOAD_AUTOMATION :
1677 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1678 update_gui(changed_edl);
1684 int MWindow::paste_default_keyframe()
1686 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1689 undo->update_undo_before();
1691 char *string = new char[len];
1692 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1694 file.read_from_string(string);
1696 double start = edl->local_session->get_selectionstart();
1697 edl->tracks->paste_automation(start, &file, 1, 0,
1698 edl->session->typeless_keyframes);
1699 // edl->tracks->paste_default_keyframe(&file);
1700 int changed_edl = speed_after(1);
1701 undo->update_undo_after(_("paste default keyframe"),
1702 !changed_edl ? LOAD_AUTOMATION :
1703 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1705 update_gui(changed_edl);
1712 // Insert edls with project deletion and index file generation.
1713 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1714 Track *first_track, double current_position,
1715 int edit_labels, int edit_plugins, int edit_autos,
1719 ArrayList<Track*> destination_tracks;
1720 int need_new_tracks = 0;
1723 if( !new_edls->total ) return 0;
1726 // double original_length = edl->tracks->total_length();
1727 // double original_preview_end = edl->local_session->preview_end;
1730 // Delete current project
1731 if( load_mode == LOADMODE_REPLACE ||
1732 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1734 edl->save_defaults(defaults);
1736 edl->Garbage::remove_user();
1738 edl->create_objects();
1739 edl->copy_session(new_edls->values[0]);
1740 edl->copy_mixers(new_edls->values[0]);
1741 gui->mainmenu->update_toggles(0);
1742 gui->unlock_window();
1743 gwindow->gui->update_toggles(1);
1744 gui->lock_window("MWindow::paste_edls");
1746 // Insert labels for certain modes constitutively
1750 // Force reset of preview
1751 // original_length = 0;
1752 // original_preview_end = -1;
1758 // Create new tracks in master EDL
1759 if( load_mode == LOADMODE_REPLACE ||
1760 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1761 load_mode == LOADMODE_NEW_TRACKS ) {
1763 need_new_tracks = 1;
1764 for( int i=0; i<new_edls->total; ++i ) {
1765 EDL *new_edl = new_edls->values[i];
1766 for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1767 switch( current->data_type ) {
1769 edl->tracks->add_video_track(0, 0);
1770 if( current->draw ) edl->tracks->last->draw = 1;
1773 edl->tracks->add_audio_track(0, 0);
1775 case TRACK_SUBTITLE:
1776 edl->tracks->add_subttl_track(0, 0);
1781 destination_tracks.append(edl->tracks->last);
1784 // Base track count on first EDL only for concatenation
1785 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1787 edl->session->highlighted_track = edl->tracks->total() - 1;
1790 // Recycle existing tracks of master EDL
1791 if( load_mode == LOADMODE_CONCATENATE ||
1792 load_mode == LOADMODE_PASTE ||
1793 load_mode == LOADMODE_NESTED ) {
1796 // The point of this is to shift forward labels after the selection so they can
1797 // then be shifted back to their original locations without recursively
1798 // shifting back every paste.
1799 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1800 edl->session->labels_follow_edits )
1801 edl->labels->clear(edl->local_session->get_selectionstart(),
1802 edl->local_session->get_selectionend(), 1);
1804 Track *current = first_track ? first_track : edl->tracks->first;
1805 for( ; current; current=NEXT ) {
1806 if( current->record ) {
1807 destination_tracks.append(current);
1814 int destination_track = 0;
1815 double *paste_position = new double[destination_tracks.total];
1817 // Iterate through the edls
1818 for( int i=0; i<new_edls->total; ++i ) {
1820 EDL *new_edl = new_edls->values[i];
1821 double edl_length = new_edl->local_session->clipboard_length ?
1822 new_edl->local_session->clipboard_length :
1823 new_edl->tracks->total_length();
1824 // printf("MWindow::paste_edls 2 %f %f\n",
1825 // new_edl->local_session->clipboard_length,
1826 // new_edl->tracks->total_length());
1830 // Convert EDL to master rates
1831 new_edl->resample(new_edl->session->sample_rate,
1832 edl->session->sample_rate,
1834 new_edl->resample(new_edl->session->frame_rate,
1835 edl->session->frame_rate,
1838 // Add assets and prepare index files
1839 for( Asset *new_asset=new_edl->assets->first;
1840 new_asset; new_asset=new_asset->next ) {
1841 mainindexes->add_next_asset(0, new_asset);
1843 // Capture index file status from mainindex test
1844 edl->update_assets(new_edl);
1846 // Get starting point of insertion. Need this to paste labels.
1847 switch( load_mode ) {
1848 case LOADMODE_REPLACE:
1849 case LOADMODE_NEW_TRACKS:
1850 current_position = 0;
1853 case LOADMODE_CONCATENATE:
1854 case LOADMODE_REPLACE_CONCATENATE:
1855 destination_track = 0;
1856 if( destination_tracks.total )
1857 current_position = destination_tracks.values[0]->get_length();
1859 current_position = 0;
1862 case LOADMODE_PASTE:
1863 case LOADMODE_NESTED:
1864 destination_track = 0;
1866 for( int j=0; j<destination_tracks.total; ++j ) {
1867 paste_position[j] = (current_position >= 0) ?
1869 edl->local_session->get_selectionstart();
1874 case LOADMODE_RESOURCESONLY:
1875 edl->add_clip(new_edl);
1880 if( load_mode != LOADMODE_RESOURCESONLY &&
1881 load_mode != LOADMODE_ASSETSONLY ) {
1883 if( edl->session->labels_follow_edits ) {
1884 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1885 if( load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED )
1886 edl->labels->insert_labels(new_edl->labels,
1887 destination_tracks.total ? paste_position[0] : 0.0,
1888 edl_length, edit_labels);
1890 edl->labels->insert_labels(new_edl->labels, current_position,
1891 edl_length, edit_labels);
1894 double total_length = new_edl->tracks->total_length();
1895 for( Track *new_track=new_edl->tracks->first;
1896 new_track; new_track=new_track->next ) {
1897 // Get destination track of same type as new_track
1899 k < destination_tracks.total &&
1900 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1901 ++k, ++destination_track ) {
1902 if( destination_track >= destination_tracks.total - 1 )
1903 destination_track = 0;
1906 // Insert data into destination track
1907 if( destination_track < destination_tracks.total &&
1908 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1909 Track *track = destination_tracks.values[destination_track];
1911 // Replace default keyframes if first EDL and new tracks were created.
1912 // This means data copied from one track and pasted to another won't retain
1913 // the camera position unless it's a keyframe. If it did, previous data in the
1914 // track might get unknowingly corrupted. Ideally we would detect when differing
1915 // default keyframes existed and create discrete keyframes for both.
1916 int replace_default = (i == 0) && need_new_tracks;
1918 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1919 // Insert new track at current position
1920 switch( load_mode ) {
1921 case LOADMODE_REPLACE_CONCATENATE:
1922 case LOADMODE_CONCATENATE:
1923 current_position = track->get_length();
1926 case LOADMODE_PASTE:
1927 case LOADMODE_NESTED:
1928 current_position = paste_position[destination_track];
1929 paste_position[destination_track] += new_track->get_length();
1933 double length = overwrite >= 0 ?
1934 new_track->get_length() : total_length;
1935 track->clear(current_position,
1936 current_position + length,
1938 edit_labels, edit_plugins, edit_autos,
1942 track->insert_track(new_track, current_position, replace_default,
1943 edit_plugins, edit_autos, edl_length);
1947 // Get next destination track
1948 destination_track++;
1949 if( destination_track >= destination_tracks.total )
1950 destination_track = 0;
1954 if( load_mode == LOADMODE_PASTE ||
1955 load_mode == LOADMODE_NESTED )
1956 current_position += edl_length;
1960 // Move loading of clips and vwindow to the end - this fixes some
1961 // strange issue, for index not being shown
1962 // Assume any paste operation from the same EDL won't contain any clips.
1963 // If it did it would duplicate every clip here.
1964 for( int i=0; i<new_edls->total; ++i ) {
1965 EDL *new_edl = new_edls->get(i);
1967 for( int j=0; j<new_edl->clips.size(); ++j ) {
1968 edl->add_clip(new_edl->clips[j]);
1970 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1971 edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1974 if( new_edl->total_vwindow_edls() ) {
1975 // if( edl->vwindow_edl )
1976 // edl->vwindow_edl->Garbage::remove_user();
1977 // edl->vwindow_edl = new EDL(edl);
1978 // edl->vwindow_edl->create_objects();
1979 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1981 for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1982 EDL *vwindow_edl = new EDL(edl);
1983 vwindow_edl->create_objects();
1984 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1985 edl->append_vwindow_edl(vwindow_edl, 0);
1990 if( paste_position ) delete [] paste_position;
1992 // This is already done in load_filenames and everything else that uses paste_edls
1993 // update_project(load_mode);
1995 // Fix preview range
1996 // if( EQUIV(original_length, original_preview_end) )
1998 // edl->local_session->preview_end = edl->tracks->total_length();
2001 // Start examining next batch of index files
2002 mainindexes->start_build();
2004 // Don't save a backup after loading since the loaded file is on disk already.
2009 void MWindow::paste_silence()
2011 double start = edl->local_session->get_selectionstart();
2012 double end = edl->local_session->get_selectionend();
2013 if( EQUIV(start, end) ) {
2014 if( edl->session->frame_rate > 0 )
2015 end += 1./edl->session->frame_rate;
2017 undo->update_undo_before(_("silence"), this);
2018 edl->paste_silence(start, end,
2019 edl->session->labels_follow_edits,
2020 edl->session->plugins_follow_edits,
2021 edl->session->autos_follow_edits);
2024 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
2026 update_plugin_guis();
2028 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2029 cwindow->update(1, 0, 0, 0, 1);
2030 cwindow->refresh_frame(CHANGE_EDL);
2033 void MWindow::detach_transition(Transition *transition)
2035 undo->update_undo_before();
2036 hide_plugin(transition, 1);
2037 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
2038 transition->edit->detach_transition();
2040 undo->update_undo_after(_("detach transition"), LOAD_ALL);
2042 if( is_video ) restart_brender();
2043 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2044 sync_parameters(CHANGE_EDL);
2047 void MWindow::detach_transitions()
2049 gui->lock_window("MWindow::detach_transitions 1");
2051 undo->update_undo_before();
2052 double start = edl->local_session->get_selectionstart();
2053 double end = edl->local_session->get_selectionend();
2054 edl->tracks->clear_transitions(start, end);
2057 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
2059 sync_parameters(CHANGE_EDL);
2060 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2061 gui->unlock_window();
2064 void MWindow::paste_transition()
2066 // Only the first transition gets dropped.
2067 PluginServer *server = session->drag_pluginservers->values[0];
2069 undo->update_undo_before();
2070 edl->tracks->paste_transition(server, session->edit_highlighted);
2072 undo->update_undo_after(_("transition"), LOAD_EDITS);
2074 if( server->video ) restart_brender();
2075 sync_parameters(CHANGE_ALL);
2078 void MWindow::paste_transitions(int track_type, char *title)
2080 gui->lock_window("MWindow::detach_transitions 1");
2082 undo->update_undo_before();
2083 double start = edl->local_session->get_selectionstart();
2084 double end = edl->local_session->get_selectionend();
2085 edl->tracks->paste_transitions(start, end, track_type, title);
2087 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
2089 sync_parameters(CHANGE_EDL);
2090 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2091 gui->unlock_window();
2094 void MWindow::paste_transition_cwindow(Track *dest_track)
2096 PluginServer *server = session->drag_pluginservers->values[0];
2097 undo->update_undo_before();
2098 edl->tracks->paste_video_transition(server, 1);
2100 undo->update_undo_after(_("transition"), LOAD_EDITS);
2102 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2103 sync_parameters(CHANGE_ALL);
2106 void MWindow::paste_audio_transition()
2108 PluginServer *server = scan_plugindb(edl->session->default_atransition,
2111 char string[BCTEXTLEN];
2112 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
2113 gui->show_message(string);
2117 undo->update_undo_before();
2118 edl->tracks->paste_audio_transition(server);
2120 undo->update_undo_after(_("transition"), LOAD_EDITS);
2122 sync_parameters(CHANGE_EDL);
2123 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2126 void MWindow::paste_video_transition()
2128 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
2131 char string[BCTEXTLEN];
2132 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
2133 gui->show_message(string);
2137 undo->update_undo_before();
2139 edl->tracks->paste_video_transition(server);
2141 undo->update_undo_after(_("transition"), LOAD_EDITS);
2143 sync_parameters(CHANGE_EDL);
2145 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2148 void MWindow::shuffle_edits()
2150 gui->lock_window("MWindow::shuffle_edits 1");
2152 undo->update_undo_before();
2153 double start = edl->local_session->get_selectionstart();
2154 double end = edl->local_session->get_selectionend();
2156 edl->tracks->shuffle_edits(start, end);
2159 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
2161 sync_parameters(CHANGE_EDL);
2163 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2164 gui->unlock_window();
2167 void MWindow::reverse_edits()
2169 gui->lock_window("MWindow::reverse_edits 1");
2171 undo->update_undo_before();
2172 double start = edl->local_session->get_selectionstart();
2173 double end = edl->local_session->get_selectionend();
2175 edl->tracks->reverse_edits(start, end);
2178 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
2180 sync_parameters(CHANGE_EDL);
2182 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2183 gui->unlock_window();
2186 void MWindow::align_edits()
2188 gui->lock_window("MWindow::align_edits 1");
2190 undo->update_undo_before();
2191 double start = edl->local_session->get_selectionstart();
2192 double end = edl->local_session->get_selectionend();
2194 edl->tracks->align_edits(start, end);
2197 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
2199 sync_parameters(CHANGE_EDL);
2201 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2202 gui->unlock_window();
2205 void MWindow::set_edit_length(double length)
2207 gui->lock_window("MWindow::set_edit_length 1");
2209 undo->update_undo_before();
2210 double start = edl->local_session->get_selectionstart();
2211 double end = edl->local_session->get_selectionend();
2213 edl->tracks->set_edit_length(start, end, length);
2216 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
2218 sync_parameters(CHANGE_EDL);
2220 gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
2221 gui->unlock_window();
2225 void MWindow::set_transition_length(Transition *transition, double length)
2227 gui->lock_window("MWindow::set_transition_length 1");
2229 undo->update_undo_before();
2230 //double start = edl->local_session->get_selectionstart();
2231 //double end = edl->local_session->get_selectionend();
2233 edl->tracks->set_transition_length(transition, length);
2236 undo->update_undo_after(_("transition length"), LOAD_EDITS);
2238 edl->session->default_transition_length = length;
2239 sync_parameters(CHANGE_PARAMS);
2240 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2241 gui->unlock_window();
2244 void MWindow::set_transition_length(double length)
2246 gui->lock_window("MWindow::set_transition_length 2");
2248 undo->update_undo_before();
2249 double start = edl->local_session->get_selectionstart();
2250 double end = edl->local_session->get_selectionend();
2252 edl->tracks->set_transition_length(start, end, length);
2255 undo->update_undo_after(_("transition length"), LOAD_EDITS);
2257 edl->session->default_transition_length = length;
2258 sync_parameters(CHANGE_PARAMS);
2260 gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2261 gui->unlock_window();
2265 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2267 calling_window_gui->unlock_window();
2269 if( undo->redo_load_flags() & LOAD_SESSION )
2272 cwindow->gui->lock_window("MWindow::redo_entry 1");
2273 for( int i=0; i<vwindows.size(); ++i ) {
2274 if( vwindows.get(i)->is_running() ) {
2275 if( calling_window_gui != vwindows.get(i)->gui ) {
2276 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2280 gui->lock_window("MWindow::redo_entry 3");
2286 update_plugin_states();
2287 update_plugin_guis();
2289 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2290 gui->update_proxy_toggle();
2291 gui->unlock_window();
2292 cwindow->update(1, 1, 1, 1, 1);
2293 cwindow->gui->unlock_window();
2295 for( int i=0; i < vwindows.size(); ++i ) {
2296 if( vwindows.get(i)->is_running() ) {
2297 if( calling_window_gui != vwindows.get(i)->gui ) {
2298 vwindows.get(i)->gui->unlock_window();
2303 awindow->gui->async_update_assets();
2305 cwindow->refresh_frame(CHANGE_ALL);
2306 calling_window_gui->lock_window("MWindow::redo_entry 4");
2310 void MWindow::resize_track(Track *track, int w, int h)
2312 undo->update_undo_before();
2313 // We have to move all maskpoints so they do not move in relation to image areas
2314 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2315 (w - track->track_w) / 2,
2316 (h - track->track_h) / 2);
2319 undo->update_undo_after(_("resize track"), LOAD_ALL);
2323 sync_parameters(CHANGE_EDL);
2327 void MWindow::set_inpoint(int is_mwindow)
2329 undo->update_undo_before();
2330 edl->set_inpoint(edl->local_session->get_selectionstart(1));
2332 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
2335 gui->lock_window("MWindow::set_inpoint 1");
2337 gui->update_timebar(1);
2339 gui->unlock_window();
2343 cwindow->gui->lock_window("MWindow::set_inpoint 2");
2345 cwindow->gui->timebar->update(1);
2347 cwindow->gui->unlock_window();
2351 void MWindow::set_outpoint(int is_mwindow)
2353 undo->update_undo_before();
2354 edl->set_outpoint(edl->local_session->get_selectionend(1));
2356 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
2359 gui->lock_window("MWindow::set_outpoint 1");
2361 gui->update_timebar(1);
2363 gui->unlock_window();
2367 cwindow->gui->lock_window("MWindow::set_outpoint 2");
2369 cwindow->gui->timebar->update(1);
2371 cwindow->gui->unlock_window();
2375 void MWindow::unset_inoutpoint(int is_mwindow)
2377 undo->update_undo_before();
2378 edl->unset_inoutpoint();
2380 undo->update_undo_after(_("clear in/out"), LOAD_TIMEBAR);
2383 gui->lock_window("MWindow::unset_inoutpoint 1");
2385 gui->update_timebar(1);
2387 gui->unlock_window();
2391 cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2393 cwindow->gui->timebar->update(1);
2395 cwindow->gui->unlock_window();
2399 void MWindow::splice(EDL *source, int all)
2402 LocalSession *src = source->local_session;
2404 undo->update_undo_before();
2405 double source_start = all ? 0 :
2406 src->inpoint_valid() ? src->get_inpoint() :
2407 src->outpoint_valid() ? 0 : src->get_selectionstart();
2408 double source_end = all ? source->tracks->total_length() :
2409 src->outpoint_valid() ? src->get_outpoint() :
2410 src->inpoint_valid() ? source->tracks->total_length() :
2411 src->get_selectionend();
2412 source->copy(source_start, source_end, 1, &file, "", 1);
2414 double start = edl->local_session->get_selectionstart();
2415 //double end = edl->local_session->get_selectionend();
2417 paste(start, start, &file,
2418 edl->session->labels_follow_edits,
2419 edl->session->plugins_follow_edits,
2420 edl->session->autos_follow_edits,
2423 // Position at end of clip
2424 edl->local_session->set_selectionstart(start + source_end - source_start);
2425 edl->local_session->set_selectionend(start + source_end - source_start);
2428 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2429 update_plugin_guis();
2431 gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2432 sync_parameters(CHANGE_EDL);
2435 void MWindow::save_clip(EDL *new_edl, const char *txt)
2437 new_edl->local_session->set_selectionstart(0);
2438 new_edl->local_session->set_selectionend(0);
2439 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2440 session->clip_number++);
2441 char duration[BCTEXTLEN];
2442 Units::totext(duration, new_edl->tracks->total_length(),
2443 new_edl->session->time_format,
2444 new_edl->session->sample_rate,
2445 new_edl->session->frame_rate,
2446 new_edl->session->frames_per_foot);
2448 Track *track = new_edl->tracks->first;
2449 const char *path = edl->path;
2450 for( ; (!path || !*path) && track; track=track->next ) {
2451 if( !track->record ) continue;
2452 Edit *edit = track->edits->first;
2453 if( !edit ) continue;
2454 Indexable *indexable = edit->get_source();
2455 if( !indexable ) continue;
2456 path = indexable->path;
2459 time_t now; time(&now);
2460 struct tm dtm; localtime_r(&now, &dtm);
2461 char *cp = new_edl->local_session->clip_notes;
2462 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2464 n = snprintf(cp, sz, "%s", txt);
2467 n = snprintf(cp, sz,
2468 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2469 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2470 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2472 if( path && *path ) {
2474 char title[BCTEXTLEN];
2475 fs.extract_name(title, path);
2476 n = snprintf(cp, sz, "%s", title);
2480 sprintf(new_edl->local_session->clip_icon,
2481 "clip_%02d%02d%02d-%02d%02d%02d.png",
2482 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2483 dtm.tm_hour, dtm.tm_min, dtm.tm_sec);
2484 new_edl->folder_no = AW_CLIP_FOLDER;
2485 edl->update_assets(new_edl);
2487 gui->get_abs_cursor(cur_x, cur_y, 0);
2488 gui->unlock_window();
2490 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2491 new_edl->remove_user();
2493 gui->lock_window("MWindow::save_clip");
2497 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2500 LocalSession *src = edl->local_session;
2502 gui->lock_window("MWindow::to_clip 1");
2503 double start = all ? 0 :
2504 src->inpoint_valid() ? src->get_inpoint() :
2505 src->outpoint_valid() ? 0 : src->get_selectionstart();
2506 double end = all ? edl->tracks->total_length() :
2507 src->outpoint_valid() ? src->get_outpoint() :
2508 src->inpoint_valid() ? edl->tracks->total_length() :
2509 src->get_selectionend();
2510 if( EQUIV(end, start) ) {
2512 end = edl->tracks->total_length();
2515 // Don't copy all since we don't want the clips twice.
2516 edl->copy(start, end, 0, &file, "", 1);
2518 EDL *new_edl = new EDL(edl);
2519 new_edl->create_objects();
2520 new_edl->load_xml(&file, LOAD_ALL);
2521 save_clip(new_edl, txt);
2522 gui->unlock_window();
2525 int MWindow::toggle_label(int is_mwindow)
2527 double position1, position2;
2528 undo->update_undo_before();
2530 if( cwindow->playback_engine->is_playing_back ) {
2531 position1 = position2 =
2532 cwindow->playback_engine->get_tracking_position();
2535 position1 = edl->local_session->get_selectionstart(1);
2536 position2 = edl->local_session->get_selectionend(1);
2539 position1 = edl->align_to_frame(position1, 0);
2540 position2 = edl->align_to_frame(position2, 0);
2542 //printf("MWindow::toggle_label 1\n");
2544 edl->labels->toggle_label(position1, position2);
2548 gui->lock_window("MWindow::toggle_label 1");
2550 gui->update_timebar(0);
2551 gui->activate_timeline();
2554 gui->unlock_window();
2558 cwindow->gui->lock_window("MWindow::toggle_label 2");
2560 cwindow->gui->timebar->update(1);
2562 cwindow->gui->unlock_window();
2565 awindow->gui->async_update_assets();
2567 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2571 void MWindow::trim_selection()
2573 undo->update_undo_before();
2576 edl->trim_selection(edl->local_session->get_selectionstart(),
2577 edl->local_session->get_selectionend(),
2578 edl->session->labels_follow_edits,
2579 edl->session->plugins_follow_edits,
2580 edl->session->autos_follow_edits);
2583 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2584 update_plugin_guis();
2585 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2586 cwindow->update(1, 0, 0, 0, 1);
2587 awindow->gui->async_update_assets();
2589 cwindow->refresh_frame(CHANGE_EDL);
2593 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2595 calling_window_gui->unlock_window();
2597 if( undo->undo_load_flags() & LOAD_SESSION )
2600 cwindow->gui->lock_window("MWindow::undo_entry 1");
2601 for( int i=0; i<vwindows.size(); ++i ) {
2602 if( vwindows.get(i)->is_running() ) {
2603 if( calling_window_gui != vwindows.get(i)->gui ) {
2604 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2608 gui->lock_window("MWindow::undo_entry 2");
2614 update_plugin_states();
2615 update_plugin_guis();
2617 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2618 gui->update_proxy_toggle();
2619 gui->unlock_window();
2620 cwindow->update(1, 1, 1, 1, 1);
2621 cwindow->gui->unlock_window();
2623 for( int i=0; i<vwindows.size(); ++i ) {
2624 if( vwindows.get(i)->is_running() ) {
2625 if( calling_window_gui != vwindows.get(i)->gui ) {
2626 vwindows.get(i)->gui->unlock_window();
2631 awindow->gui->async_update_assets();
2633 cwindow->refresh_frame(CHANGE_ALL);
2634 calling_window_gui->lock_window("MWindow::undo_entry 4");
2638 void MWindow::new_folder(const char *new_folder, int is_clips)
2640 undo->update_undo_before();
2641 if( edl->new_folder(new_folder, is_clips) ) {
2642 MainError::show_error(_("create new folder failed"));
2644 undo->update_undo_after(_("new folder"), LOAD_ALL);
2645 awindow->gui->async_update_assets();
2648 void MWindow::delete_folder(char *folder)
2650 undo->update_undo_before();
2651 if( edl->delete_folder(folder) < 0 ) {
2652 MainError::show_error(_("delete folder failed"));
2654 undo->update_undo_after(_("del folder"), LOAD_ALL);
2655 awindow->gui->async_update_assets();
2658 void MWindow::select_point(double position)
2660 gui->unlock_window();
2661 gui->stop_drawing();
2662 cwindow->stop_playback(0);
2663 gui->lock_window("MWindow::select_point");
2665 edl->local_session->set_selectionstart(position);
2666 edl->local_session->set_selectionend(position);
2669 cwindow->update(1, 0, 0, 0, 1);
2671 update_plugin_guis();
2672 gui->update_patchbay();
2673 gui->hide_cursor(0);
2674 gui->draw_cursor(0);
2675 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2676 gui->zoombar->update();
2677 gui->update_timebar(0);
2678 gui->flash_canvas(0);
2685 void MWindow::map_audio(int pattern)
2687 undo->update_undo_before();
2688 remap_audio(pattern);
2689 undo->update_undo_after(
2690 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2692 sync_parameters(CHANGE_PARAMS);
2693 gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2696 void MWindow::remap_audio(int pattern)
2698 int current_channel = 0;
2699 int current_track = 0;
2700 for( Track *current=edl->tracks->first; current; current=NEXT ) {
2701 if( current->data_type == TRACK_AUDIO &&
2703 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2704 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2706 for( int i=0; i < MAXCHANNELS; ++i ) {
2707 pan_auto->values[i] = 0.0;
2710 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2711 pan_auto->values[current_channel] = 1.0;
2714 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2715 switch( current_track ) {
2718 pan_auto->values[0] = 1;
2722 pan_auto->values[1] = 1;
2726 pan_auto->values[0] = 0.5;
2727 pan_auto->values[1] = 0.5;
2732 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2733 edl->session->achannel_positions, pan_auto->values,
2734 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2738 if( current_channel >= edl->session->audio_channels )
2739 current_channel = 0;
2745 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2747 edl->rescale_proxy(orig_scale, new_scale);
2750 void MWindow::add_proxy(int use_scaler,
2751 ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2753 edl->add_proxy(use_scaler, orig_assets, proxy_assets);
2756 void MWindow::cut_commercials()
2758 #ifdef HAVE_COMMERCIAL
2759 undo->update_undo_before();
2760 commercials->scan_media();
2763 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2766 update_plugin_guis();
2767 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2768 cwindow->update(1, 0, 0, 0, 1);
2769 cwindow->refresh_frame(CHANGE_EDL);
2773 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2776 Track *old_track = old_edl->tracks->first;
2777 Track *new_track = new_edl->tracks->first;
2778 for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2779 if( old_track->data_type != new_track->data_type ) continue;
2780 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2781 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2782 if( !old_speeds || !new_speeds ) continue;
2783 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2784 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2785 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2786 old_speed = (FloatAuto *)old_speed->next;
2787 new_speed = (FloatAuto *)new_speed->next;
2789 Edit *old_edit = old_track->edits->first;
2790 Edit *new_edit = new_track->edits->first;
2791 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2792 int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2793 if( old_speed || new_speed ) {
2794 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2795 double orig_end = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2796 edit_start = new_speeds->speed_position(orig_start);
2797 edit_end = new_speeds->speed_position(orig_end);
2800 new_edit->startproject = edit_start;
2801 new_edit->length = edit_end - edit_start;
2807 void MWindow::speed_before()
2810 speed_edl = new EDL;
2811 speed_edl->create_objects();
2813 speed_edl->copy_all(edl);
2816 int MWindow::speed_after(int done)
2821 result = normalize_speed(speed_edl, edl);
2823 speed_edl->remove_user();