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"
46 #include "levelwindow.h"
47 #include "localsession.h"
48 #include "mainclock.h"
49 #include "maincursor.h"
50 #include "mainerror.h"
51 #include "mainindexes.h"
53 #include "mainsession.h"
55 #include "maskautos.h"
57 #include "mwindowgui.h"
61 #include "playbackengine.h"
62 #include "pluginset.h"
63 #include "recordlabel.h"
64 #include "samplescroll.h"
65 #include "trackcanvas.h"
67 #include "trackscroll.h"
69 #include "transition.h"
70 #include "transportque.h"
72 #include "undostackitem.h"
73 #include "vplayback.h"
75 #include "vwindowgui.h"
77 #include "automation.h"
78 #include "maskautos.h"
82 void MWindow::add_audio_track_entry(int above, Track *dst)
84 undo->update_undo_before();
85 add_audio_track(above, dst);
87 undo->update_undo_after(_("add track"), LOAD_ALL);
90 gui->update(1, 1, 0, 0, 1, 0, 0);
91 gui->activate_timeline();
93 // gui->get_scrollbars(0);
94 // gui->canvas->draw();
95 // gui->patchbay->update();
96 // gui->cursor->draw(1);
97 // gui->canvas->flash();
98 // gui->canvas->activate();
99 cwindow->playback_engine->que->
100 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
103 void MWindow::add_video_track_entry(Track *dst)
105 undo->update_undo_before();
106 add_video_track(1, dst);
107 undo->update_undo_after(_("add track"), LOAD_ALL);
111 gui->update(1, 1, 0, 0, 1, 0, 0);
112 gui->activate_timeline();
113 // gui->get_scrollbars(0);
114 // gui->canvas->draw();
115 // gui->patchbay->update();
116 // gui->cursor->draw(1);
117 // gui->canvas->flash();
118 // gui->canvas->activate();
119 cwindow->playback_engine->que->
120 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
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, 1, 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->playback_engine->que->
141 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
146 int MWindow::add_audio_track(int above, Track *dst)
148 edl->tracks->add_audio_track(above, dst);
149 edl->tracks->update_y_pixels(theme);
154 int MWindow::add_video_track(int above, Track *dst)
156 edl->tracks->add_video_track(above, dst);
157 edl->tracks->update_y_pixels(theme);
162 int MWindow::add_subttl_track(int above, Track *dst)
164 edl->tracks->add_subttl_track(above, dst);
165 edl->tracks->update_y_pixels(theme);
170 void MWindow::asset_to_all()
172 if( !session->drag_assets->size() ) return;
173 Indexable *indexable = session->drag_assets->get(0);
175 // if( indexable->have_video() )
179 undo->update_undo_before();
182 w = indexable->get_w();
183 h = indexable->get_h();
184 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
185 double old_framerate = edl->session->frame_rate;
186 int old_samplerate = edl->session->sample_rate;
187 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
190 if( indexable->have_video() ) {
191 edl->session->output_w = w;
192 edl->session->output_h = h;
193 edl->session->frame_rate = new_framerate;
195 edl->session->aspect_w,
196 edl->session->aspect_h,
199 for( Track *current = edl->tracks->first; current; current = NEXT ) {
200 if( current->data_type == TRACK_VIDEO /* &&
201 current->record */ ) {
202 current->track_w = w;
203 current->track_h = h;
208 if( ((edl->session->output_w % 4) ||
209 (edl->session->output_h % 4)) &&
210 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
211 MainError::show_error(
212 _("This project's dimensions are not multiples of 4 so\n"
213 "it can't be rendered by OpenGL."));
217 if( defaults->get("AUTOASPECT", 0) ) {
219 edl->session->aspect_w,
220 edl->session->aspect_h,
225 if( indexable->have_audio() ) {
226 edl->session->sample_rate = new_samplerate;
227 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
228 edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
233 undo->update_undo_after(_("asset to all"), LOAD_ALL);
235 gui->update(1, 2, 1, 1, 1, 1, 0);
236 sync_parameters(CHANGE_ALL);
240 void MWindow::asset_to_size()
242 if( !session->drag_assets->size() ) return;
243 Indexable *indexable = session->drag_assets->get(0);
245 if( indexable->have_video() ) {
247 undo->update_undo_before();
250 w = indexable->get_w();
251 h = indexable->get_h();
252 edl->session->output_w = w;
253 edl->session->output_h = h;
255 if( ((edl->session->output_w % 4) ||
256 (edl->session->output_h % 4)) &&
257 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
258 MainError::show_error(
259 _("This project's dimensions are not multiples of 4 so\n"
260 "it can't be rendered by OpenGL."));
264 if( defaults->get("AUTOASPECT", 0) ) {
265 create_aspect_ratio(edl->session->aspect_w,
266 edl->session->aspect_h,
273 undo->update_undo_after(_("asset to size"), LOAD_ALL);
275 sync_parameters(CHANGE_ALL);
280 void MWindow::asset_to_rate()
282 if( session->drag_assets->size() &&
283 session->drag_assets->get(0)->have_video() ) {
284 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
285 double old_framerate = edl->session->frame_rate;
286 undo->update_undo_before();
288 edl->session->frame_rate = new_framerate;
289 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
293 undo->update_undo_after(_("asset to rate"), LOAD_ALL);
295 gui->update(1, 2, 1, 1, 1, 1, 0);
296 sync_parameters(CHANGE_ALL);
301 void MWindow::clear_entry()
303 undo->update_undo_before();
308 undo->update_undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
311 update_plugin_guis();
312 gui->update(1, 2, 1, 1, 1, 1, 0);
313 cwindow->update(1, 0, 0, 0, 1);
314 cwindow->playback_engine->que->
315 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
318 void MWindow::clear(int clear_handle)
320 double start = edl->local_session->get_selectionstart();
321 double end = edl->local_session->get_selectionend();
322 if( clear_handle || !EQUIV(start, end) ) {
325 edl->session->labels_follow_edits,
326 edl->session->plugins_follow_edits,
327 edl->session->autos_follow_edits);
331 void MWindow::set_automation_mode(int mode)
333 undo->update_undo_before();
334 edl->tracks->set_automation_mode(
335 edl->local_session->get_selectionstart(),
336 edl->local_session->get_selectionend(),
339 char string[BCSTRLEN];
340 sprintf(string,"set %s", FloatAuto::curve_name(mode));
341 undo->update_undo_after(string, LOAD_AUTOMATION);
344 update_plugin_guis();
345 gui->draw_overlays(1);
346 sync_parameters(CHANGE_PARAMS);
347 gui->update_patchbay();
348 cwindow->update(1, 0, 0);
351 void MWindow::clear_automation()
353 undo->update_undo_before();
354 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
355 edl->local_session->get_selectionend());
357 undo->update_undo_after(_("clear keyframes"), LOAD_AUTOMATION);
360 update_plugin_guis();
361 gui->draw_overlays(1);
362 sync_parameters(CHANGE_PARAMS);
363 gui->update_patchbay();
364 cwindow->update(1, 0, 0);
367 int MWindow::clear_default_keyframe()
369 undo->update_undo_before();
370 edl->tracks->clear_default_keyframe();
372 undo->update_undo_after(_("clear default keyframe"), LOAD_AUTOMATION);
375 gui->draw_overlays(1);
376 sync_parameters(CHANGE_PARAMS);
377 gui->update_patchbay();
378 cwindow->update(1, 0, 0);
383 void MWindow::clear_labels()
385 undo->update_undo_before();
386 clear_labels(edl->local_session->get_selectionstart(),
387 edl->local_session->get_selectionend());
388 undo->update_undo_after(_("clear labels"), LOAD_TIMEBAR);
390 gui->update_timebar(1);
391 cwindow->update(0, 0, 0, 0, 1);
395 int MWindow::clear_labels(double start, double end)
397 edl->labels->clear(start, end, 0);
401 void MWindow::concatenate_tracks()
403 undo->update_undo_before();
404 edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
405 edl->session->autos_follow_edits);
407 undo->update_undo_after(_("concatenate tracks"), LOAD_EDITS);
410 gui->update(1, 1, 0, 0, 1, 0, 0);
411 cwindow->playback_engine->que->
412 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
418 copy(edl->local_session->get_selectionstart(),
419 edl->local_session->get_selectionend());
422 int MWindow::copy(double start, double end)
424 if( start == end ) return 1;
427 edl->copy(start, end, 0, 0, 0, &file, "", 1);
428 const char *file_string = file.string();
429 long file_length = strlen(file_string);
430 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
431 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
436 int MWindow::copy_automation()
439 double start = edl->local_session->get_selectionstart();
440 double end = edl->local_session->get_selectionend();
441 edl->tracks->copy_automation(start, end, &file, 0, 1);
442 const char *file_string = file.string();
443 long file_length = strlen(file_string);
444 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
445 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
449 int MWindow::copy_default_keyframe()
452 double start = edl->local_session->get_selectionstart();
453 double end = edl->local_session->get_selectionend();
454 edl->tracks->copy_automation(start, end, &file, 1, 0);
455 const char *file_string = file.string();
456 long file_length = strlen(file_string);
457 gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
458 gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
463 // Uses cropping coordinates in edl session to crop and translate video.
464 // We modify the projector since camera automation depends on the track size.
465 void MWindow::crop_video()
468 undo->update_undo_before();
469 // Clamp EDL crop region
470 if( edl->session->crop_x1 > edl->session->crop_x2 ) {
471 edl->session->crop_x1 ^= edl->session->crop_x2;
472 edl->session->crop_x2 ^= edl->session->crop_x1;
473 edl->session->crop_x1 ^= edl->session->crop_x2;
475 if( edl->session->crop_y1 > edl->session->crop_y2 ) {
476 edl->session->crop_y1 ^= edl->session->crop_y2;
477 edl->session->crop_y2 ^= edl->session->crop_y1;
478 edl->session->crop_y1 ^= edl->session->crop_y2;
481 float old_projector_x = (float)edl->session->output_w / 2;
482 float old_projector_y = (float)edl->session->output_h / 2;
483 float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
484 float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
485 float projector_offset_x = -(new_projector_x - old_projector_x);
486 float projector_offset_y = -(new_projector_y - old_projector_y);
488 edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
490 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
491 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
492 edl->session->crop_x1 = 0;
493 edl->session->crop_y1 = 0;
494 edl->session->crop_x2 = edl->session->output_w;
495 edl->session->crop_y2 = edl->session->output_h;
497 // Recalculate aspect ratio
498 if( defaults->get("AUTOASPECT", 0) ) {
499 create_aspect_ratio(edl->session->aspect_w,
500 edl->session->aspect_h,
501 edl->session->output_w,
502 edl->session->output_h);
505 undo->update_undo_after(_("crop"), LOAD_ALL);
508 cwindow->playback_engine->que->
509 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
515 double start = edl->local_session->get_selectionstart();
516 double end = edl->local_session->get_selectionend();
517 if( EQUIV(start,end) )
523 void MWindow::blade(double position)
525 undo->update_undo_before();
526 edl->blade(position);
529 undo->update_undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
531 update_plugin_guis();
532 gui->update(1, 2, 1, 1, 1, 1, 0);
533 cwindow->update(1, 0, 0, 0, 1);
534 awindow->gui->async_update_assets();
535 cwindow->playback_engine->que->
536 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
539 void MWindow::cut(double start, double end, double new_position)
541 undo->update_undo_before();
543 edl->clear(start, end,
544 edl->session->labels_follow_edits,
545 edl->session->plugins_follow_edits,
546 edl->session->autos_follow_edits);
550 undo->update_undo_after(_("cut"), LOAD_EDITS | LOAD_TIMEBAR);
551 if( new_position >= 0 ) {
552 edl->local_session->set_selectionstart(new_position);
553 edl->local_session->set_selectionend(new_position);
556 update_plugin_guis();
557 gui->update(1, 2, 1, 1, 1, 1, 0);
558 cwindow->update(1, 0, 0, 0, 1);
559 awindow->gui->async_update_assets();
560 cwindow->playback_engine->que->
561 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
564 void MWindow::snap_left_edit()
566 double start_pos = edl->local_session->get_selectionstart(1);
567 double position = edl->prev_edit(start_pos);
568 if( position < start_pos )
569 cut(position, start_pos, position);
572 void MWindow::snap_right_edit()
574 double end_pos = edl->local_session->get_selectionend(1);
575 double position = edl->next_edit(end_pos);
576 if( end_pos < position )
577 cut(end_pos, position, end_pos);
580 void MWindow::snap_left_label()
582 double start_pos = edl->local_session->get_selectionstart(1);
583 Label *left_label = edl->labels->prev_label(start_pos);
584 if( !left_label ) return;
585 double position = left_label->position;
586 if( position < start_pos )
587 cut(position, start_pos, position);
590 void MWindow::snap_right_label()
592 double end_pos = edl->local_session->get_selectionend(1);
593 Label *right_label = edl->labels->next_label(end_pos);
594 if( !right_label ) return;
595 double position = right_label->position;
596 if( end_pos < position )
597 cut(end_pos, position, end_pos);
600 int MWindow::cut_automation()
602 undo->update_undo_before();
606 edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
607 edl->local_session->get_selectionend());
609 undo->update_undo_after(_("cut keyframes"), LOAD_AUTOMATION);
613 update_plugin_guis();
614 gui->draw_overlays(1);
615 sync_parameters(CHANGE_PARAMS);
616 gui->update_patchbay();
617 cwindow->update(1, 0, 0);
621 int MWindow::cut_default_keyframe()
624 undo->update_undo_before();
625 copy_default_keyframe();
626 edl->tracks->clear_default_keyframe();
627 undo->update_undo_after(_("cut default keyframe"), LOAD_AUTOMATION);
630 gui->draw_overlays(1);
631 sync_parameters(CHANGE_PARAMS);
632 gui->update_patchbay();
633 cwindow->update(1, 0, 0);
641 void MWindow::delete_inpoint()
643 edl->local_session->unset_inpoint();
647 void MWindow::delete_outpoint()
649 edl->local_session->unset_outpoint();
654 void MWindow::delete_track()
656 if( edl->tracks->last )
657 delete_track(edl->tracks->last);
660 void MWindow::delete_tracks()
662 undo->update_undo_before();
663 edl->tracks->delete_tracks();
664 undo->update_undo_after(_("delete tracks"), LOAD_ALL);
668 update_plugin_states();
670 gui->update(1, 1, 1, 0, 1, 0, 0);
671 cwindow->playback_engine->que->
672 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
675 void MWindow::delete_track(Track *track)
677 undo->update_undo_before();
678 edl->tracks->delete_track(track);
679 undo->update_undo_after(_("delete track"), LOAD_ALL);
682 update_plugin_states();
684 gui->update(1, 1, 1, 0, 1, 0, 0);
685 cwindow->playback_engine->que->
686 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
691 // Insert data from clipboard
692 void MWindow::insert(double position, FileXML *file,
693 int edit_labels, int edit_plugins, int edit_autos,
696 // For clipboard pasting make the new edl use a separate session
697 // from the master EDL. Then it can be resampled to the master rates.
698 // For splice, overwrite, and dragging need same session to get the assets.
699 EDL *edl = new EDL(parent_edl);
700 ArrayList<EDL*> new_edls;
701 uint32_t load_flags = LOAD_ALL;
704 new_edls.append(edl);
705 edl->create_objects();
710 if( parent_edl ) load_flags &= ~LOAD_SESSION;
711 if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
712 if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
714 edl->load_xml(file, load_flags);
717 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
721 paste_edls(&new_edls, LOADMODE_PASTE, 0, position,
722 edit_labels, edit_plugins, edit_autos, 0); // overwrite
723 // if( vwindow->edl )
724 // printf("MWindow::insert 5 %f %f\n",
725 // vwindow->edl->local_session->in_point,
726 // vwindow->edl->local_session->out_point);
727 new_edls.remove_all();
728 edl->Garbage::remove_user();
729 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
732 void MWindow::insert_effects_canvas(double start,
735 Track *dest_track = session->track_highlighted;
736 if( !dest_track ) return;
738 undo->update_undo_before();
740 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
741 PluginServer *plugin = session->drag_pluginservers->values[i];
742 insert_effect(plugin->title, 0, dest_track,
743 i == 0 ? session->pluginset_highlighted : 0,
744 start, length, PLUGIN_STANDALONE);
748 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
750 sync_parameters(CHANGE_EDL);
751 // GUI updated in TrackCanvas, after current_operations are reset
754 void MWindow::insert_effects_cwindow(Track *dest_track)
756 if( !dest_track ) return;
758 undo->update_undo_before();
761 double length = dest_track->get_length();
763 if( edl->local_session->get_selectionend() >
764 edl->local_session->get_selectionstart() ) {
765 start = edl->local_session->get_selectionstart();
766 length = edl->local_session->get_selectionend() -
767 edl->local_session->get_selectionstart();
770 for( int i = 0; i < session->drag_pluginservers->total; i++ ) {
771 PluginServer *plugin = session->drag_pluginservers->values[i];
772 insert_effect(plugin->title, 0, dest_track, 0,
773 start, length, PLUGIN_STANDALONE);
777 undo->update_undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
779 sync_parameters(CHANGE_EDL);
780 gui->update(1, 1, 0, 0, 1, 0, 0);
783 void MWindow::insert_effect(char *title,
784 SharedLocation *shared_location,
787 int single_standalone)
789 Track *current = edl->tracks->first;
790 SharedLocation shared_location_local;
791 shared_location_local.copy_from(shared_location);
793 for( ; current; current = NEXT) {
794 if( current->data_type == data_type &&
796 insert_effect(title, &shared_location_local,
797 current, 0, 0, 0, plugin_type);
800 if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
801 plugin_type = PLUGIN_SHAREDPLUGIN;
802 shared_location_local.module = edl->tracks->number_of(current);
803 shared_location_local.plugin = current->plugin_set.total - 1;
812 void MWindow::insert_effect(char *title,
813 SharedLocation *shared_location,
815 PluginSet *plugin_set,
820 KeyFrame *default_keyframe = 0;
821 PluginServer *server = 0;
822 // Get default keyframe
823 if( plugin_type == PLUGIN_STANDALONE ) {
824 default_keyframe = new KeyFrame;
825 server = new PluginServer(*scan_plugindb(title, track->data_type));
827 server->open_plugin(0, preferences, edl, 0);
828 server->save_data(default_keyframe);
830 // Insert plugin object
831 track->insert_effect(title, shared_location,
832 default_keyframe, plugin_set,
833 start, length, plugin_type);
836 if( plugin_type == PLUGIN_STANDALONE ) {
837 server->close_plugin();
839 delete default_keyframe;
843 int MWindow::modify_edithandles()
845 undo->update_undo_before();
846 edl->modify_edithandles(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->plugins_follow_edits,
852 edl->session->autos_follow_edits);
854 finish_modify_handles();
855 //printf("MWindow::modify_handles 1\n");
859 int MWindow::modify_pluginhandles()
861 undo->update_undo_before();
863 edl->modify_pluginhandles(session->drag_start,
864 session->drag_position,
865 session->drag_handle,
866 edl->session->edit_handle_mode[session->drag_button],
867 edl->session->labels_follow_edits,
868 edl->session->autos_follow_edits,
869 session->trim_edits);
871 finish_modify_handles();
877 // Common to edithandles and plugin handles
878 void MWindow::finish_modify_handles()
880 int edit_mode = edl->session->edit_handle_mode[session->drag_button];
882 if( (session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
883 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT) ) {
884 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
885 edl->local_session->set_selectionstart(session->drag_position);
886 edl->local_session->set_selectionend(session->drag_position);
889 if( edit_mode != MOVE_NO_EDITS ) {
890 //printf("MWindow::finish_modify_handles %d\n", __LINE__);
891 edl->local_session->set_selectionstart(session->drag_start);
892 edl->local_session->set_selectionend(session->drag_start);
895 // clamp the selection to 0
896 if( edl->local_session->get_selectionstart(1) < 0 ) {
897 edl->local_session->set_selectionstart(0);
898 edl->local_session->set_selectionend(0);
900 undo->update_undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
904 sync_parameters(CHANGE_EDL);
905 update_plugin_guis();
906 gui->update(1, 2, 1, 1, 1, 1, 0);
907 // label list can be modified
908 awindow->gui->async_update_assets();
909 cwindow->update(1, 0, 0, 0, 1);
912 void MWindow::match_output_size(Track *track)
914 undo->update_undo_before();
915 track->track_w = edl->session->output_w;
916 track->track_h = edl->session->output_h;
918 undo->update_undo_after(_("match output size"), LOAD_ALL);
921 sync_parameters(CHANGE_EDL);
925 void MWindow::move_edits(ArrayList<Edit*> *edits,
930 undo->update_undo_before();
932 edl->tracks->move_edits(edits,
935 edl->session->labels_follow_edits,
936 edl->session->plugins_follow_edits,
937 edl->session->autos_follow_edits,
941 undo->update_undo_after(_("move edit"), LOAD_ALL);
944 cwindow->playback_engine->que->
945 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
947 update_plugin_guis();
948 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
952 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
954 undo->update_undo_before();
955 edl->tracks->move_effect(plugin, track, position);
957 undo->update_undo_after(_("paste effect"), LOAD_ALL);
960 cwindow->playback_engine->que->
961 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
962 update_plugin_guis();
963 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
967 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
969 undo->update_undo_before();
970 edl->tracks->move_effect(plugin, plugin_set, position);
972 undo->update_undo_after(_("move effect"), LOAD_ALL);
975 cwindow->playback_engine->que->
976 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
977 update_plugin_guis();
978 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
982 void MWindow::move_plugins_up(PluginSet *plugin_set)
985 undo->update_undo_before();
986 plugin_set->track->move_plugins_up(plugin_set);
989 undo->update_undo_after(_("move effect up"), LOAD_ALL);
991 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
993 sync_parameters(CHANGE_EDL);
996 void MWindow::move_plugins_down(PluginSet *plugin_set)
998 undo->update_undo_before();
1000 plugin_set->track->move_plugins_down(plugin_set);
1003 undo->update_undo_after(_("move effect down"), LOAD_ALL);
1005 gui->update(1, 1, // 1 for incremental drawing. 2 for full refresh
1007 sync_parameters(CHANGE_EDL);
1010 void MWindow::move_track_down(Track *track)
1012 undo->update_undo_before();
1013 edl->tracks->move_track_down(track);
1015 undo->update_undo_after(_("move track down"), LOAD_ALL);
1018 gui->update(1, 1, 0, 0, 1, 0, 0);
1019 sync_parameters(CHANGE_EDL);
1023 void MWindow::move_tracks_down()
1025 undo->update_undo_before();
1026 edl->tracks->move_tracks_down();
1028 undo->update_undo_after(_("move tracks down"), LOAD_ALL);
1031 gui->update(1, 1, 0, 0, 1, 0, 0);
1032 sync_parameters(CHANGE_EDL);
1036 void MWindow::move_track_up(Track *track)
1038 undo->update_undo_before();
1039 edl->tracks->move_track_up(track);
1041 undo->update_undo_after(_("move track up"), LOAD_ALL);
1043 gui->update(1, 1, 0, 0, 1, 0, 0);
1044 sync_parameters(CHANGE_EDL);
1048 void MWindow::move_tracks_up()
1050 undo->update_undo_before();
1051 edl->tracks->move_tracks_up();
1053 undo->update_undo_after(_("move tracks up"), LOAD_ALL);
1055 gui->update(1, 1, 0, 0, 1, 0, 0);
1056 sync_parameters(CHANGE_EDL);
1060 void MWindow::mute_selection()
1062 double start = edl->local_session->get_selectionstart();
1063 double end = edl->local_session->get_selectionend();
1064 if( start != end ) {
1065 undo->update_undo_before();
1066 edl->clear(start, end, 0,
1067 edl->session->plugins_follow_edits,
1068 edl->session->autos_follow_edits);
1069 edl->local_session->set_selectionend(end);
1070 edl->local_session->set_selectionstart(start);
1071 edl->paste_silence(start, end, 0,
1072 edl->session->plugins_follow_edits,
1073 edl->session->autos_follow_edits);
1076 undo->update_undo_after(_("mute"), LOAD_EDITS);
1079 update_plugin_guis();
1080 gui->update(1, 2, 1, 1, 1, 1, 0);
1081 cwindow->playback_engine->que->
1082 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1087 void MWindow::overwrite(EDL *source)
1091 double src_start = source->local_session->get_selectionstart();
1092 double overwrite_len = source->local_session->get_selectionend() - src_start;
1093 double dst_start = edl->local_session->get_selectionstart();
1094 double dst_len = edl->local_session->get_selectionend() - dst_start;
1096 undo->update_undo_before();
1097 if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1098 // in/out points or selection present and shorter than overwrite range
1099 // shorten the copy range
1100 overwrite_len = dst_len;
1103 source->copy(src_start, src_start + overwrite_len,
1104 0, 0, 0, &file, "", 1);
1106 // HACK around paste_edl get_start/endselection on its own
1107 // so we need to clear only when not using both io points
1108 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1109 if( edl->local_session->get_inpoint() < 0 ||
1110 edl->local_session->get_outpoint() < 0 )
1111 edl->clear(dst_start, dst_start + overwrite_len, 0, 0, 0);
1113 paste(dst_start, dst_start + overwrite_len,
1116 edl->local_session->set_selectionstart(dst_start + overwrite_len);
1117 edl->local_session->set_selectionend(dst_start + overwrite_len);
1120 undo->update_undo_after(_("overwrite"), LOAD_EDITS);
1123 update_plugin_guis();
1124 gui->update(1, 1, 1, 1, 0, 1, 0);
1125 sync_parameters(CHANGE_EDL);
1128 // For splice and overwrite
1129 int MWindow::paste(double start,
1138 // Want to insert with assets shared with the master EDL.
1140 edit_labels, edit_plugins, edit_autos,
1146 // For editing using insertion point
1147 void MWindow::paste()
1149 double start = edl->local_session->get_selectionstart();
1150 //double end = edl->local_session->get_selectionend();
1151 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1154 char *string = new char[len];
1155 undo->update_undo_before();
1156 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1158 file.read_from_string(string);
1161 insert(start, &file,
1162 edl->session->labels_follow_edits,
1163 edl->session->plugins_follow_edits,
1164 edl->session->autos_follow_edits,
1172 undo->update_undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1174 update_plugin_guis();
1175 gui->update(1, 2, 1, 1, 0, 1, 0);
1176 awindow->gui->async_update_assets();
1177 sync_parameters(CHANGE_EDL);
1182 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1185 undo->update_undo_before();
1187 if( session->drag_assets->total ) {
1188 load_assets(session->drag_assets,
1189 position, LOADMODE_PASTE, dest_track, 0,
1190 edl->session->labels_follow_edits,
1191 edl->session->plugins_follow_edits,
1192 edl->session->autos_follow_edits,
1197 if( session->drag_clips->total ) {
1198 paste_edls(session->drag_clips,
1199 LOADMODE_PASTE, dest_track, position,
1200 edl->session->labels_follow_edits,
1201 edl->session->plugins_follow_edits,
1202 edl->session->autos_follow_edits,
1209 undo->update_undo_after(_("paste assets"), LOAD_EDITS);
1211 gui->update(1, 2, 1, 0, 0, 1, 0);
1212 sync_parameters(CHANGE_EDL);
1216 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1217 double position, int load_mode, Track *first_track, RecordLabels *labels,
1218 int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1220 if( load_mode == LOADMODE_RESOURCESONLY )
1221 load_mode = LOADMODE_ASSETSONLY;
1222 const int debug = 0;
1223 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1224 if( position < 0 ) position = edl->local_session->get_selectionstart();
1226 ArrayList<EDL*> new_edls;
1227 for( int i = 0; i < new_assets->total; i++ ) {
1228 Indexable *indexable = new_assets->get(i);
1229 if( indexable->is_asset ) {
1230 remove_asset_from_caches((Asset*)indexable);
1232 EDL *new_edl = new EDL;
1233 new_edl->create_objects();
1234 new_edl->copy_session(edl);
1235 new_edls.append(new_edl);
1238 if( indexable->is_asset ) {
1239 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1240 if( debug ) ((Asset*)indexable)->dump();
1241 asset_to_edl(new_edl, (Asset*)indexable);
1244 edl_to_nested(new_edl, (EDL*)indexable);
1245 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1249 for( RecordLabel *label = labels->first; label; label = label->next ) {
1250 new_edl->labels->toggle_label(label->position, label->position);
1254 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1256 paste_edls(&new_edls, load_mode, first_track, position,
1257 edit_labels, edit_plugins, edit_autos, overwrite);
1258 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1261 for( int i = 0; i < new_edls.size(); i++ )
1262 new_edls.get(i)->Garbage::remove_user();
1264 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1267 int MWindow::paste_automation()
1269 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1272 undo->update_undo_before();
1273 char *string = new char[len];
1274 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1276 file.read_from_string(string);
1278 double start = edl->local_session->get_selectionstart();
1279 double end = edl->local_session->get_selectionend();
1280 edl->tracks->clear_automation(start, end);
1281 edl->tracks->paste_automation(start, &file, 0, 1,
1282 edl->session->typeless_keyframes);
1284 undo->update_undo_after(_("paste keyframes"), LOAD_AUTOMATION);
1288 update_plugin_guis();
1289 gui->draw_overlays(1);
1290 sync_parameters(CHANGE_PARAMS);
1291 gui->update_patchbay();
1292 cwindow->update(1, 0, 0);
1298 int MWindow::paste_default_keyframe()
1300 int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1303 undo->update_undo_before();
1304 char *string = new char[len];
1305 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1307 file.read_from_string(string);
1308 double start = edl->local_session->get_selectionstart();
1309 edl->tracks->paste_automation(start, &file, 1, 0,
1310 edl->session->typeless_keyframes);
1311 // edl->tracks->paste_default_keyframe(&file);
1312 undo->update_undo_after(_("paste default keyframe"), LOAD_AUTOMATION);
1315 update_plugin_guis();
1316 gui->draw_overlays(1);
1317 sync_parameters(CHANGE_PARAMS);
1318 gui->update_patchbay();
1319 cwindow->update(1, 0, 0);
1328 // Insert edls with project deletion and index file generation.
1329 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1330 Track *first_track, double current_position,
1331 int edit_labels, int edit_plugins, int edit_autos,
1335 ArrayList<Track*> destination_tracks;
1336 int need_new_tracks = 0;
1339 if( !new_edls->total ) return 0;
1342 // double original_length = edl->tracks->total_length();
1343 // double original_preview_end = edl->local_session->preview_end;
1346 // Delete current project
1347 if( load_mode == LOADMODE_REPLACE ||
1348 load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1350 edl->save_defaults(defaults);
1352 edl->Garbage::remove_user();
1354 edl->create_objects();
1355 edl->copy_session(new_edls->values[0]);
1356 edl->copy_mixers(new_edls->values[0]);
1357 gui->mainmenu->update_toggles(0);
1358 gui->unlock_window();
1359 gwindow->gui->update_toggles(1);
1360 gui->lock_window("MWindow::paste_edls");
1362 // Insert labels for certain modes constitutively
1366 // Force reset of preview
1367 // original_length = 0;
1368 // original_preview_end = -1;
1374 // Create new tracks in master EDL
1375 if( load_mode == LOADMODE_REPLACE ||
1376 load_mode == LOADMODE_REPLACE_CONCATENATE ||
1377 load_mode == LOADMODE_NEW_TRACKS ) {
1379 need_new_tracks = 1;
1380 for( int i = 0; i < new_edls->total; i++ ) {
1381 EDL *new_edl = new_edls->values[i];
1382 for( Track *current = new_edl->tracks->first;
1385 if( current->data_type == TRACK_VIDEO ) {
1386 edl->tracks->add_video_track(0, 0);
1387 if( current->draw ) edl->tracks->last->draw = 1;
1388 destination_tracks.append(edl->tracks->last);
1391 if( current->data_type == TRACK_AUDIO ) {
1392 edl->tracks->add_audio_track(0, 0);
1393 destination_tracks.append(edl->tracks->last);
1396 if( current->data_type == TRACK_SUBTITLE ) {
1397 edl->tracks->add_subttl_track(0, 0);
1398 destination_tracks.append(edl->tracks->last);
1400 edl->session->highlighted_track = edl->tracks->total() - 1;
1403 // Base track count on first EDL only for concatenation
1404 if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1409 // Recycle existing tracks of master EDL
1410 if( load_mode == LOADMODE_CONCATENATE ||
1411 load_mode == LOADMODE_PASTE ||
1412 load_mode == LOADMODE_NESTED ) {
1415 // The point of this is to shift forward labels after the selection so they can
1416 // then be shifted back to their original locations without recursively
1417 // shifting back every paste.
1418 if( (load_mode == LOADMODE_PASTE || load_mode == LOADMODE_NESTED) &&
1419 edl->session->labels_follow_edits )
1420 edl->labels->clear(edl->local_session->get_selectionstart(),
1421 edl->local_session->get_selectionend(),
1424 Track *current = first_track ? first_track : edl->tracks->first;
1425 for( ; current; current = NEXT) {
1426 if( current->record ) {
1427 destination_tracks.append(current);
1434 int destination_track = 0;
1435 double *paste_position = new double[destination_tracks.total];
1437 // Iterate through the edls
1438 for( int i = 0; i < new_edls->total; i++ ) {
1440 EDL *new_edl = new_edls->values[i];
1441 double edl_length = new_edl->local_session->clipboard_length ?
1442 new_edl->local_session->clipboard_length :
1443 new_edl->tracks->total_length();
1444 // printf("MWindow::paste_edls 2 %f %f\n",
1445 // new_edl->local_session->clipboard_length,
1446 // new_edl->tracks->total_length());
1450 // Convert EDL to master rates
1451 new_edl->resample(new_edl->session->sample_rate,
1452 edl->session->sample_rate,
1454 new_edl->resample(new_edl->session->frame_rate,
1455 edl->session->frame_rate,
1458 // Add assets and prepare index files
1459 for( Asset *new_asset = new_edl->assets->first;
1461 new_asset = new_asset->next ) {
1462 mainindexes->add_next_asset(0, new_asset);
1464 // Capture index file status from mainindex test
1465 edl->update_assets(new_edl);
1467 // Get starting point of insertion. Need this to paste labels.
1468 switch( load_mode ) {
1469 case LOADMODE_REPLACE:
1470 case LOADMODE_NEW_TRACKS:
1471 current_position = 0;
1474 case LOADMODE_CONCATENATE:
1475 case LOADMODE_REPLACE_CONCATENATE:
1476 destination_track = 0;
1477 if( destination_tracks.total )
1478 current_position = destination_tracks.values[0]->get_length();
1480 current_position = 0;
1483 case LOADMODE_PASTE:
1484 case LOADMODE_NESTED:
1485 destination_track = 0;
1487 for( int j = 0; j < destination_tracks.total; j++ ) {
1488 paste_position[j] = (current_position >= 0) ?
1490 edl->local_session->get_selectionstart();
1495 case LOADMODE_RESOURCESONLY:
1496 edl->add_clip(new_edl);
1501 if( load_mode != LOADMODE_RESOURCESONLY &&
1502 load_mode != LOADMODE_ASSETSONLY ) {
1504 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1505 if( load_mode == LOADMODE_PASTE ||
1506 load_mode == LOADMODE_NESTED )
1507 edl->labels->insert_labels(new_edl->labels,
1508 destination_tracks.total ? paste_position[0] : 0.0,
1512 edl->labels->insert_labels(new_edl->labels,
1518 for( Track *new_track = new_edl->tracks->first;
1520 new_track = new_track->next ) {
1521 // Get destination track of same type as new_track
1523 k < destination_tracks.total &&
1524 destination_tracks.values[destination_track]->data_type != new_track->data_type;
1525 k++, destination_track++ ) {
1526 if( destination_track >= destination_tracks.total - 1 )
1527 destination_track = 0;
1530 // Insert data into destination track
1531 if( destination_track < destination_tracks.total &&
1532 destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1533 Track *track = destination_tracks.values[destination_track];
1535 // Replace default keyframes if first EDL and new tracks were created.
1536 // This means data copied from one track and pasted to another won't retain
1537 // the camera position unless it's a keyframe. If it did, previous data in the
1538 // track might get unknowingly corrupted. Ideally we would detect when differing
1539 // default keyframes existed and create discrete keyframes for both.
1540 int replace_default = (i == 0) && need_new_tracks;
1542 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1543 // Insert new track at current position
1544 switch( load_mode ) {
1545 case LOADMODE_REPLACE_CONCATENATE:
1546 case LOADMODE_CONCATENATE:
1547 current_position = track->get_length();
1550 case LOADMODE_PASTE:
1551 case LOADMODE_NESTED:
1552 current_position = paste_position[destination_track];
1553 paste_position[destination_track] += new_track->get_length();
1557 track->clear(current_position,
1558 current_position + new_track->get_length(),
1560 edit_labels, edit_plugins, edit_autos,
1565 track->insert_track(new_track, current_position, replace_default,
1566 edit_plugins, edit_autos, edl_length);
1570 // Get next destination track
1571 destination_track++;
1572 if( destination_track >= destination_tracks.total )
1573 destination_track = 0;
1577 if( load_mode == LOADMODE_PASTE ||
1578 load_mode == LOADMODE_NESTED )
1579 current_position += edl_length;
1583 // Move loading of clips and vwindow to the end - this fixes some
1584 // strange issue, for index not being shown
1585 // Assume any paste operation from the same EDL won't contain any clips.
1586 // If it did it would duplicate every clip here.
1587 for( int i = 0; i < new_edls->total; i++ ) {
1588 EDL *new_edl = new_edls->values[i];
1590 for( int j = 0; j < new_edl->clips.total; j++ ) {
1591 edl->add_clip(new_edl->clips.values[j]);
1594 if( new_edl->total_vwindow_edls() ) {
1595 // if( edl->vwindow_edl )
1596 // edl->vwindow_edl->Garbage::remove_user();
1597 // edl->vwindow_edl = new EDL(edl);
1598 // edl->vwindow_edl->create_objects();
1599 // edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1601 for( int j = 0; j < new_edl->total_vwindow_edls(); j++ ) {
1602 EDL *vwindow_edl = new EDL(edl);
1603 vwindow_edl->create_objects();
1604 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1605 edl->append_vwindow_edl(vwindow_edl, 0);
1610 if( paste_position ) delete [] paste_position;
1612 // This is already done in load_filenames and everything else that uses paste_edls
1613 // update_project(load_mode);
1615 // Fix preview range
1616 // if( EQUIV(original_length, original_preview_end) )
1618 // edl->local_session->preview_end = edl->tracks->total_length();
1621 // Start examining next batch of index files
1622 mainindexes->start_build();
1624 // Don't save a backup after loading since the loaded file is on disk already.
1629 void MWindow::paste_silence()
1631 double start = edl->local_session->get_selectionstart();
1632 double end = edl->local_session->get_selectionend();
1633 undo->update_undo_before();
1634 edl->paste_silence(start, end,
1635 edl->session->labels_follow_edits,
1636 edl->session->plugins_follow_edits,
1637 edl->session->autos_follow_edits);
1640 undo->update_undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1642 update_plugin_guis();
1644 gui->update(1, 2, 1, 1, 1, 1, 0);
1645 cwindow->update(1, 0, 0, 0, 1);
1646 cwindow->playback_engine->que->
1647 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
1650 void MWindow::detach_transition(Transition *transition)
1652 undo->update_undo_before();
1653 hide_plugin(transition, 1);
1654 int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1655 transition->edit->detach_transition();
1657 undo->update_undo_after(_("detach transition"), LOAD_ALL);
1659 if( is_video ) restart_brender();
1660 gui->update(0, 1, 0, 0, 0, 0, 0);
1661 sync_parameters(CHANGE_EDL);
1664 void MWindow::detach_transitions()
1666 gui->lock_window("MWindow::detach_transitions 1");
1668 undo->update_undo_before();
1669 double start = edl->local_session->get_selectionstart();
1670 double end = edl->local_session->get_selectionend();
1671 edl->tracks->clear_transitions(start, end);
1674 undo->update_undo_after(_("detach transitions"), LOAD_EDITS);
1676 sync_parameters(CHANGE_EDL);
1677 gui->update(0, 1, 0, 0, 0, 0, 0);
1678 gui->unlock_window();
1681 void MWindow::paste_transition()
1683 // Only the first transition gets dropped.
1684 PluginServer *server = session->drag_pluginservers->values[0];
1686 undo->update_undo_before();
1688 strcpy(edl->session->default_atransition, server->title);
1690 strcpy(edl->session->default_vtransition, server->title);
1692 edl->tracks->paste_transition(server, session->edit_highlighted);
1694 undo->update_undo_after(_("transition"), LOAD_EDITS);
1696 if( server->video ) restart_brender();
1697 sync_parameters(CHANGE_ALL);
1700 void MWindow::paste_transitions(int track_type, char *title)
1702 gui->lock_window("MWindow::detach_transitions 1");
1704 undo->update_undo_before();
1705 double start = edl->local_session->get_selectionstart();
1706 double end = edl->local_session->get_selectionend();
1707 edl->tracks->paste_transitions(start, end, track_type, title);
1710 undo->update_undo_after(_("attach transitions"), LOAD_EDITS);
1712 sync_parameters(CHANGE_EDL);
1713 gui->update(0, 1, 0, 0, 0, 0, 0);
1714 gui->unlock_window();
1717 void MWindow::paste_transition_cwindow(Track *dest_track)
1719 PluginServer *server = session->drag_pluginservers->values[0];
1720 undo->update_undo_before();
1721 edl->tracks->paste_video_transition(server, 1);
1723 undo->update_undo_after(_("transition"), LOAD_EDITS);
1725 gui->update(0, 1, 0, 0, 0, 0, 0);
1726 sync_parameters(CHANGE_ALL);
1729 void MWindow::paste_audio_transition()
1731 PluginServer *server = scan_plugindb(edl->session->default_atransition,
1734 char string[BCTEXTLEN];
1735 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1736 gui->show_message(string);
1740 undo->update_undo_before();
1741 edl->tracks->paste_audio_transition(server);
1743 undo->update_undo_after(_("transition"), LOAD_EDITS);
1745 sync_parameters(CHANGE_EDL);
1746 gui->update(0, 1, 0, 0, 0, 0, 0);
1749 void MWindow::paste_video_transition()
1751 PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1754 char string[BCTEXTLEN];
1755 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1756 gui->show_message(string);
1760 undo->update_undo_before();
1762 edl->tracks->paste_video_transition(server);
1764 undo->update_undo_after(_("transition"), LOAD_EDITS);
1766 sync_parameters(CHANGE_EDL);
1768 gui->update(0, 1, 0, 0, 0, 0, 0);
1771 void MWindow::shuffle_edits()
1773 gui->lock_window("MWindow::shuffle_edits 1");
1775 undo->update_undo_before();
1776 double start = edl->local_session->get_selectionstart();
1777 double end = edl->local_session->get_selectionend();
1779 edl->tracks->shuffle_edits(start, end);
1782 undo->update_undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1784 sync_parameters(CHANGE_EDL);
1786 gui->update(0, 1, 1, 0, 0, 0, 0);
1787 gui->unlock_window();
1790 void MWindow::reverse_edits()
1792 gui->lock_window("MWindow::reverse_edits 1");
1794 undo->update_undo_before();
1795 double start = edl->local_session->get_selectionstart();
1796 double end = edl->local_session->get_selectionend();
1798 edl->tracks->reverse_edits(start, end);
1801 undo->update_undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1803 sync_parameters(CHANGE_EDL);
1805 gui->update(0, 1, 1, 0, 0, 0, 0);
1806 gui->unlock_window();
1809 void MWindow::align_edits()
1811 gui->lock_window("MWindow::align_edits 1");
1813 undo->update_undo_before();
1814 double start = edl->local_session->get_selectionstart();
1815 double end = edl->local_session->get_selectionend();
1817 edl->tracks->align_edits(start, end);
1820 undo->update_undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1822 sync_parameters(CHANGE_EDL);
1824 gui->update(0, 1, 1, 0, 0, 0, 0);
1825 gui->unlock_window();
1828 void MWindow::set_edit_length(double length)
1830 gui->lock_window("MWindow::detach_transitions 1");
1832 undo->update_undo_before();
1833 double start = edl->local_session->get_selectionstart();
1834 double end = edl->local_session->get_selectionend();
1836 edl->tracks->set_edit_length(start, end, length);
1839 undo->update_undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1841 sync_parameters(CHANGE_EDL);
1843 gui->update(0, 1, 1, 0, 0, 0, 0);
1844 gui->unlock_window();
1848 void MWindow::set_transition_length(Transition *transition, double length)
1850 gui->lock_window("MWindow::detach_transitions 1");
1852 undo->update_undo_before();
1853 //double start = edl->local_session->get_selectionstart();
1854 //double end = edl->local_session->get_selectionend();
1856 edl->tracks->set_transition_length(transition, length);
1859 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1861 edl->session->default_transition_length = length;
1862 sync_parameters(CHANGE_PARAMS);
1863 gui->update(0, 1, 0, 0, 0, 0, 0);
1864 gui->unlock_window();
1867 void MWindow::set_transition_length(double length)
1869 gui->lock_window("MWindow::detach_transitions 1");
1871 undo->update_undo_before();
1872 double start = edl->local_session->get_selectionstart();
1873 double end = edl->local_session->get_selectionend();
1875 edl->tracks->set_transition_length(start, end, length);
1878 undo->update_undo_after(_("transition length"), LOAD_EDITS);
1880 edl->session->default_transition_length = length;
1881 sync_parameters(CHANGE_PARAMS);
1883 gui->update(0, 1, 0, 0, 0, 0, 0);
1884 gui->unlock_window();
1888 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
1890 calling_window_gui->unlock_window();
1893 cwindow->gui->lock_window("MWindow::redo_entry");
1894 for( int i = 0; i < vwindows.size(); i++ ) {
1895 if( vwindows.get(i)->is_running() ) {
1896 if( calling_window_gui != vwindows.get(i)->gui ) {
1897 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
1906 update_plugin_states();
1907 update_plugin_guis();
1908 awindow->gui->async_update_assets();
1910 gui->update(1, 2, 1, 1, 1, 1, 1);
1911 cwindow->update(1, 1, 1, 1, 1);
1913 if( calling_window_gui != cwindow->gui )
1914 cwindow->gui->unlock_window();
1915 if( calling_window_gui != gui )
1916 gui->unlock_window();
1919 for( int i = 0; i < vwindows.size(); i++ ) {
1920 if( vwindows.get(i)->is_running() ) {
1921 if( calling_window_gui != vwindows.get(i)->gui ) {
1922 vwindows.get(i)->gui->unlock_window();
1927 cwindow->playback_engine->que->
1928 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
1932 void MWindow::resize_track(Track *track, int w, int h)
1934 undo->update_undo_before();
1935 // We have to move all maskpoints so they do not move in relation to image areas
1936 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
1937 (w - track->track_w) / 2,
1938 (h - track->track_h) / 2);
1941 undo->update_undo_after(_("resize track"), LOAD_ALL);
1945 sync_parameters(CHANGE_EDL);
1949 void MWindow::set_inpoint(int is_mwindow)
1951 undo->update_undo_before();
1952 edl->set_inpoint(edl->local_session->get_selectionstart(1));
1954 undo->update_undo_after(_("in point"), LOAD_TIMEBAR);
1957 gui->lock_window("MWindow::set_inpoint 1");
1959 gui->update_timebar(1);
1961 gui->unlock_window();
1965 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1967 cwindow->gui->timebar->update(1);
1969 cwindow->gui->unlock_window();
1973 void MWindow::set_outpoint(int is_mwindow)
1975 undo->update_undo_before();
1976 edl->set_outpoint(edl->local_session->get_selectionend(1));
1978 undo->update_undo_after(_("out point"), LOAD_TIMEBAR);
1981 gui->lock_window("MWindow::set_outpoint 1");
1983 gui->update_timebar(1);
1985 gui->unlock_window();
1989 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1991 cwindow->gui->timebar->update(1);
1993 cwindow->gui->unlock_window();
1997 void MWindow::splice(EDL *source)
2001 undo->update_undo_before();
2002 double source_start = source->local_session->get_selectionstart();
2003 double source_end = source->local_session->get_selectionend();
2004 source->copy(source_start, source_end, 1, 0, 0, &file, "", 1);
2006 double start = edl->local_session->get_selectionstart();
2007 //double end = edl->local_session->get_selectionend();
2009 paste(start, start, &file,
2010 edl->session->labels_follow_edits,
2011 edl->session->plugins_follow_edits,
2012 edl->session->autos_follow_edits);
2014 // Position at end of clip
2015 edl->local_session->set_selectionstart(start + source_end - source_start);
2016 edl->local_session->set_selectionend(start + source_end - source_start);
2019 undo->update_undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2020 update_plugin_guis();
2022 gui->update(1, 1, 1, 1, 0, 1, 0);
2023 sync_parameters(CHANGE_EDL);
2026 void MWindow::save_clip(EDL *new_edl, const char *txt)
2028 new_edl->local_session->set_selectionstart(0);
2029 new_edl->local_session->set_selectionend(0);
2030 sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2031 session->clip_number++);
2032 char duration[BCTEXTLEN];
2033 Units::totext(duration, new_edl->tracks->total_length(),
2034 new_edl->session->time_format,
2035 new_edl->session->sample_rate,
2036 new_edl->session->frame_rate,
2037 new_edl->session->frames_per_foot);
2039 Track *track = new_edl->tracks->first;
2040 const char *path = edl->path;
2041 for( ; (!path || !*path) && track; track=track->next ) {
2042 if( !track->record ) continue;
2043 Edit *edit = track->edits->first;
2044 if( !edit ) continue;
2045 Indexable *indexable = edit->get_source();
2046 if( !indexable ) continue;
2047 path = indexable->path;
2050 time_t now; time(&now);
2051 struct tm *tm = localtime(&now);
2052 char *cp = new_edl->local_session->clip_notes;
2053 int n, sz = sizeof(new_edl->local_session->clip_notes)-1;
2055 n = snprintf(cp, sz, "%s", txt);
2058 n = snprintf(cp, sz,
2059 "%02d/%02d/%02d %02d:%02d:%02d, +%s\n",
2060 tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
2061 tm->tm_hour, tm->tm_min, tm->tm_sec, duration);
2063 if( path && *path ) {
2065 char title[BCTEXTLEN];
2066 fs.extract_name(title, path);
2067 n = snprintf(cp, sz, "%s", title);
2072 edl->update_assets(new_edl);
2074 gui->get_abs_cursor(cur_x, cur_y, 0);
2075 gui->unlock_window();
2077 awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2079 gui->lock_window("MWindow::save_clip");
2083 void MWindow::to_clip(EDL *edl, const char *txt)
2088 gui->lock_window("MWindow::to_clip 1");
2089 start = edl->local_session->get_selectionstart();
2090 end = edl->local_session->get_selectionend();
2092 if( EQUIV(end, start) ) {
2094 end = edl->tracks->total_length();
2097 // Don't copy all since we don't want the clips twice.
2098 edl->copy(start, end, 0, 0, 0, &file, "", 1);
2100 EDL *new_edl = new EDL(edl);
2101 new_edl->create_objects();
2102 new_edl->load_xml(&file, LOAD_ALL);
2103 save_clip(new_edl, txt);
2104 gui->unlock_window();
2107 int MWindow::toggle_label(int is_mwindow)
2109 double position1, position2;
2110 undo->update_undo_before();
2112 if( cwindow->playback_engine->is_playing_back ) {
2113 position1 = position2 =
2114 cwindow->playback_engine->get_tracking_position();
2117 position1 = edl->local_session->get_selectionstart(1);
2118 position2 = edl->local_session->get_selectionend(1);
2121 position1 = edl->align_to_frame(position1, 0);
2122 position2 = edl->align_to_frame(position2, 0);
2124 //printf("MWindow::toggle_label 1\n");
2126 edl->labels->toggle_label(position1, position2);
2130 gui->lock_window("MWindow::toggle_label 1");
2132 gui->update_timebar(0);
2133 gui->activate_timeline();
2136 gui->unlock_window();
2140 cwindow->gui->lock_window("MWindow::toggle_label 2");
2142 cwindow->gui->timebar->update(1);
2144 cwindow->gui->unlock_window();
2147 awindow->gui->async_update_assets();
2149 undo->update_undo_after(_("label"), LOAD_TIMEBAR);
2153 void MWindow::trim_selection()
2155 undo->update_undo_before();
2158 edl->trim_selection(edl->local_session->get_selectionstart(),
2159 edl->local_session->get_selectionend(),
2160 edl->session->labels_follow_edits,
2161 edl->session->plugins_follow_edits,
2162 edl->session->autos_follow_edits);
2165 undo->update_undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2166 update_plugin_guis();
2167 gui->update(1, 2, 1, 1, 1, 1, 0);
2168 cwindow->update(1, 0, 0, 0, 1);
2169 awindow->gui->async_update_assets();
2171 cwindow->playback_engine->que->
2172 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);
2176 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2178 calling_window_gui->unlock_window();
2181 cwindow->gui->lock_window("MWindow::undo_entry 1");
2182 for( int i = 0; i < vwindows.size(); i++ ) {
2183 if( vwindows.get(i)->is_running() ) {
2184 if( calling_window_gui != vwindows.get(i)->gui ) {
2185 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2189 gui->lock_window("MWindow::undo_entry 2");
2195 update_plugin_states();
2196 update_plugin_guis();
2198 gui->update(1, 2, 1, 1, 1, 1, 1);
2199 gui->unlock_window();
2200 cwindow->update(1, 1, 1, 1, 1);
2201 cwindow->gui->unlock_window();
2203 for( int i = 0; i < vwindows.size(); i++ ) {
2204 if( vwindows.get(i)->is_running() ) {
2205 if( calling_window_gui != vwindows.get(i)->gui ) {
2206 vwindows.get(i)->gui->unlock_window();
2211 if( calling_window_gui != gui )
2212 gui->unlock_window();
2214 awindow->gui->async_update_assets();
2216 cwindow->playback_engine->que->
2217 send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
2218 calling_window_gui->lock_window("MWindow::undo_entry 4");
2222 void MWindow::new_folder(const char *new_folder)
2224 undo->update_undo_before();
2225 edl->new_folder(new_folder);
2226 undo->update_undo_after(_("new folder"), LOAD_ALL);
2227 awindow->gui->async_update_assets();
2230 void MWindow::delete_folder(char *folder)
2232 // undo->update_undo_after(_("delete folder"), LOAD_ALL);
2235 void MWindow::select_point(double position)
2237 edl->local_session->set_selectionstart(position);
2238 edl->local_session->set_selectionend(position);
2241 cwindow->update(1, 0, 0, 0, 1);
2243 update_plugin_guis();
2244 gui->update_patchbay();
2245 gui->hide_cursor(0);
2246 gui->draw_cursor(0);
2247 gui->mainclock->update(edl->local_session->get_selectionstart(1));
2248 gui->zoombar->update();
2249 gui->update_timebar(0);
2250 gui->flash_canvas(0);
2257 void MWindow::map_audio(int pattern)
2259 undo->update_undo_before();
2260 remap_audio(pattern);
2261 undo->update_undo_after(
2262 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2264 sync_parameters(CHANGE_PARAMS);
2265 gui->update(0, 1, 0, 0, 1, 0, 0);
2268 void MWindow::remap_audio(int pattern)
2270 int current_channel = 0;
2271 int current_track = 0;
2272 for( Track *current = edl->tracks->first; current; current = NEXT ) {
2273 if( current->data_type == TRACK_AUDIO &&
2275 Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2276 PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2278 for( int i = 0; i < MAXCHANNELS; i++ ) {
2279 pan_auto->values[i] = 0.0;
2282 if( pattern == MWindow::AUDIO_1_TO_1 ) {
2283 pan_auto->values[current_channel] = 1.0;
2286 if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2287 switch( current_track ) {
2289 pan_auto->values[0] = 0.5;
2290 pan_auto->values[1] = 0.5;
2293 pan_auto->values[0] = 1;
2296 pan_auto->values[1] = 1;
2299 pan_auto->values[0] = 1;
2302 pan_auto->values[1] = 1;
2305 pan_auto->values[0] = 0.5;
2306 pan_auto->values[1] = 0.5;
2311 BC_Pan::calculate_stick_position(edl->session->audio_channels,
2312 edl->session->achannel_positions, pan_auto->values,
2313 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2317 if( current_channel >= edl->session->audio_channels )
2318 current_channel = 0;
2323 void MWindow::set_proxy(int use_scaler, int new_scale, int auto_scale,
2324 ArrayList<Indexable*> *orig_assets,
2325 ArrayList<Indexable*> *proxy_assets)
2327 int orig_use_scaler = edl->session->proxy_use_scaler;
2328 int orig_scale = edl->session->proxy_scale;
2329 // rescale to full size asset in read_frame
2330 edl->session->proxy_use_scaler = use_scaler;
2331 edl->session->proxy_scale = new_scale;
2332 edl->session->proxy_auto_scale = auto_scale;
2335 for( int i=0; i<proxy_assets->size(); ++i ) {
2336 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2337 proxy_asset->width = orig_assets->get(i)->get_w();
2338 proxy_asset->height = orig_assets->get(i)->get_h();
2343 if( !orig_use_scaler && new_scale != orig_scale ) {
2345 float orig_w = (float)edl->session->output_w * orig_scale;
2346 float orig_h = (float)edl->session->output_h * orig_scale;
2347 edl->session->output_w = Units::round(orig_w / new_scale);
2348 edl->session->output_h = Units::round(orig_h / new_scale);
2351 for( Track *track=edl->tracks->first; track; track=track->next ) {
2352 if( track->data_type != TRACK_VIDEO ) continue;
2353 orig_w = (float)track->track_w * orig_scale;
2354 orig_h = (float)track->track_h * orig_scale;
2355 track->track_w = Units::round(orig_w / new_scale);
2356 track->track_h = Units::round(orig_h / new_scale);
2357 ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->
2358 set_proxy(orig_scale, new_scale);
2359 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_X])->
2360 set_proxy(orig_scale, new_scale);
2361 ((FloatAutos*)track->automation->autos[AUTOMATION_CAMERA_Y])->
2362 set_proxy(orig_scale, new_scale);
2363 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_X])->
2364 set_proxy(orig_scale, new_scale);
2365 ((FloatAutos*)track->automation->autos[AUTOMATION_PROJECTOR_Y])->
2366 set_proxy(orig_scale, new_scale);
2370 // change original assets to proxy assets
2371 int awindow_folder = use_scaler || new_scale != 1 ? AW_PROXY_FOLDER : AW_MEDIA_FOLDER;
2372 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2373 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2374 proxy_asset->awindow_folder = awindow_folder;
2375 // replace track contents
2376 for( Track *track = edl->tracks->first; track; track = track->next ) {
2377 if( track->data_type != TRACK_VIDEO ) continue;
2378 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2379 if( !edit->asset ) continue;
2380 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2381 edit->asset = proxy_asset;
2388 void MWindow::add_proxy(int use_scaler,
2389 ArrayList<Indexable*> *orig_assets,
2390 ArrayList<Indexable*> *proxy_assets)
2393 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2394 Asset *proxy_asset = (Asset *)proxy_assets->get(i);
2395 proxy_asset->width = orig_assets->get(i)->get_w();
2396 proxy_asset->height = orig_assets->get(i)->get_h();
2400 // change original assets to proxy assets
2401 for( int i=0,n=proxy_assets->size(); i<n; ++i ) {
2402 Asset *proxy_asset = edl->assets->update((Asset *)proxy_assets->get(i));
2403 proxy_asset->awindow_folder = AW_PROXY_FOLDER;
2404 // replace track contents
2405 for( Track *track = edl->tracks->first; track; track = track->next ) {
2406 if( track->data_type != TRACK_VIDEO ) continue;
2407 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
2408 if( !edit->asset ) continue;
2409 if( !strcmp(edit->asset->path, orig_assets->get(i)->path) ) {
2410 edit->asset = proxy_asset;
2417 void MWindow::cut_commercials()
2419 undo->update_undo_before();
2420 commercials->scan_media();
2423 undo->update_undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2426 update_plugin_guis();
2427 gui->update(1, 2, 1, 1, 1, 1, 0);
2428 cwindow->update(1, 0, 0, 0, 1);
2429 cwindow->playback_engine->que->
2430 send_command(CURRENT_FRAME, CHANGE_EDL, edl, 1);