r136: This commit was manufactured by cvs2svn to create tag 'hv_1_1_8'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindowedit.C
blob1bc07ce1cd6ec87902891cf5253e46fdb5be6153
1 #include "asset.h"
2 #include "assets.h"
3 #include "awindowgui.h"
4 #include "awindow.h"
5 #include "cache.h"
6 #include "clip.h"
7 #include "clipedit.h"
8 #include "cplayback.h"
9 #include "ctimebar.h"
10 #include "cwindow.h"
11 #include "cwindowgui.h"
12 #include "edl.h"
13 #include "edlsession.h"
14 #include "filexml.h"
15 #include "keyframe.h"
16 #include "labels.h"
17 #include "levelwindow.h"
18 #include "localsession.h"
19 #include "mainclock.h"
20 #include "mainindexes.h"
21 #include "mainmenu.h"
22 #include "mainsession.h"
23 #include "mainundo.h"
24 #include "mtimebar.h"
25 #include "mwindowgui.h"
26 #include "mwindow.h"
27 #include "patchbay.h"
28 #include "playbackengine.h"
29 #include "pluginset.h"
30 #include "recordlabel.h"
31 #include "samplescroll.h"
32 #include "trackcanvas.h"
33 #include "track.h"
34 #include "trackscroll.h"
35 #include "tracks.h"
36 #include "transition.h"
37 #include "transportque.h"
38 #include "units.h"
39 #include "vplayback.h"
40 #include "vwindow.h"
41 #include "vwindowgui.h"
42 #include "zoombar.h"
46 #include <string.h>
53 void MWindow::add_audio_track_entry(int above, Track *dst)
55         undo->update_undo_before("add track", LOAD_ALL);
56         add_audio_track(above, dst);
57         save_backup();
58         undo->update_undo_after();
60         restart_brender();
61         gui->get_scrollbars();
62         gui->canvas->draw();
63         gui->patchbay->update();
64         gui->cursor->draw();
65         gui->canvas->flash();
66         gui->canvas->activate();
67         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
68                 CHANGE_EDL,
69                 edl,
70                 1);
73 void MWindow::add_video_track_entry(Track *dst)
75         undo->update_undo_before(_("add track"), LOAD_ALL);
76         add_video_track(1, dst);
77         undo->update_undo_after();
79         restart_brender();
80         gui->get_scrollbars();
81         gui->canvas->draw();
82         gui->patchbay->update();
83         gui->cursor->draw();
84         gui->canvas->flash();
85         gui->canvas->activate();
86         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
87                                                         CHANGE_EDL,
88                                                         edl,
89                                                         1);
90         save_backup();
94 int MWindow::add_audio_track(int above, Track *dst)
96         edl->tracks->add_audio_track(above, dst);
97         edl->tracks->update_y_pixels(theme);
98         save_backup();
99         return 0;
102 int MWindow::add_video_track(int above, Track *dst)
104         edl->tracks->add_video_track(above, dst);
105         edl->tracks->update_y_pixels(theme);
106         save_backup();
107         return 0;
114 void MWindow::asset_to_size()
116         if(session->drag_assets->total &&
117                 session->drag_assets->values[0]->video_data)
118         {
119                 int w, h;
121                 w = session->drag_assets->values[0]->width;
122                 h = session->drag_assets->values[0]->height;
124                 undo->update_undo_before(_("asset to size"), LOAD_ALL);
125                 edl->session->output_w = w;
126                 edl->session->output_h = h;
127                 save_backup();
129                 undo->update_undo_after();
130                 restart_brender();
131                 sync_parameters(CHANGE_ALL);
132         }
137 void MWindow::clear_entry()
139         undo->update_undo_before(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
140         clear(1);
142         edl->optimize();
143         save_backup();
144         undo->update_undo_after();
146         restart_brender();
147         update_plugin_guis();
148         gui->update(1, 2, 1, 1, 1, 1, 0);
149         cwindow->update(1, 0, 0, 0, 1);
150         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
151                            CHANGE_EDL,
152                            edl,
153                            1);
156 void MWindow::clear(int clear_handle)
158         double start = edl->local_session->get_selectionstart();
159         double end = edl->local_session->get_selectionend();
160         if(clear_handle || !EQUIV(start, end))
161         {
162                 edl->clear(start, 
163                         end, 
164                         edl->session->labels_follow_edits, 
165                         edl->session->plugins_follow_edits);
166         }
169 void MWindow::clear_automation()
171         undo->update_undo_before(_("clear keyframes"), LOAD_AUTOMATION); 
172         edl->tracks->clear_automation(edl->local_session->get_selectionstart(), 
173                 edl->local_session->get_selectionend()); 
174         save_backup();
175         undo->update_undo_after(); 
177         restart_brender();
178         update_plugin_guis();
179         gui->canvas->draw_overlays();
180         gui->canvas->flash();
181         sync_parameters(CHANGE_PARAMS);
182         gui->patchbay->update();
183         cwindow->update(1, 0, 0);
186 int MWindow::clear_default_keyframe()
188         undo->update_undo_before(_("clear default keyframe"), LOAD_AUTOMATION); 
189         edl->tracks->clear_default_keyframe();
190         save_backup();
191         undo->update_undo_after();
192         
193         restart_brender();
194         gui->canvas->draw_overlays();
195         gui->canvas->flash();
196         sync_parameters(CHANGE_PARAMS);
197         gui->patchbay->update();
198         cwindow->update(1, 0, 0);
199         
200         return 0;
203 void MWindow::clear_labels()
205         undo->update_undo_before(_("clear"), LOAD_TIMEBAR);
206         clear_labels(edl->local_session->get_selectionstart(), 
207                 edl->local_session->get_selectionend()); 
208         undo->update_undo_after(); 
209         
210         gui->timebar->update();
211         cwindow->update(0, 0, 0, 0, 1);
212         save_backup();
215 int MWindow::clear_labels(double start, double end)
217         edl->labels->clear(start, end, 0);
218         return 0;
221 void MWindow::concatenate_tracks()
223         undo->update_undo_before(_("concatenate tracks"), LOAD_EDITS);
224         edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits);
225         save_backup();
226         undo->update_undo_after();
228         restart_brender();
229         gui->update(1, 1, 0, 0, 1, 0, 0);
230         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
231                 CHANGE_EDL,
232                 edl,
233                 1);
237 void MWindow::copy()
239         copy(edl->local_session->get_selectionstart(), 
240                 edl->local_session->get_selectionend());
243 int MWindow::copy(double start, double end)
245         if(start == end) return 1;
247 //printf("MWindow::copy 1\n");
248         FileXML file;
249 //printf("MWindow::copy 1\n");
250         edl->copy(start, 
251                 end, 
252                 0,
253                 0,
254                 0,
255                 &file, 
256                 plugindb,
257                 "",
258                 1);
259 //printf("MWindow::copy 1\n");
261 // File is now terminated and rewound
263 //printf("MWindow::copy 1\n");
264         gui->get_clipboard()->to_clipboard(file.string, strlen(file.string), SECONDARY_SELECTION);
265 //printf("MWindow::copy\n%s\n", file.string);
266 //printf("MWindow::copy 2\n");
267         save_backup();
268         return 0;
271 int MWindow::copy_automation()
273         FileXML file;
274         edl->tracks->copy_automation(edl->local_session->get_selectionstart(), 
275                 edl->local_session->get_selectionend(),
276                 &file,
277                 0,
278                 0); 
279         gui->get_clipboard()->to_clipboard(file.string, 
280                 strlen(file.string), 
281                 SECONDARY_SELECTION);
282         return 0;
285 int MWindow::copy_default_keyframe()
287         FileXML file;
288         edl->tracks->copy_default_keyframe(&file);
289         gui->get_clipboard()->to_clipboard(file.string,
290                 strlen(file.string),
291                 SECONDARY_SELECTION);
292         return 0;
296 // Uses cropping coordinates in edl session to crop and translate video.
297 // We modify the projector since camera automation depends on the track size.
298 void MWindow::crop_video()
300         undo->update_undo_before(_("crop"), LOAD_ALL);
303         float old_projector_x = (float)edl->session->output_w / 2;
304         float old_projector_y = (float)edl->session->output_h / 2;
305         float new_projector_x = (float)(edl->session->crop_x1 + edl->session->crop_x2) / 2;
306         float new_projector_y = (float)(edl->session->crop_y1 + edl->session->crop_y2) / 2;
307         float projector_offset_x = -(new_projector_x - old_projector_x);
308         float projector_offset_y = -(new_projector_y - old_projector_y);
310         edl->tracks->translate_projector(projector_offset_x, projector_offset_y);
312         edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
313         edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
314         edl->session->crop_x1 = 0;
315         edl->session->crop_y1 = 0;
316         edl->session->crop_x2 = edl->session->output_w;
317         edl->session->crop_y2 = edl->session->output_h;
318         undo->update_undo_after();
320         restart_brender();
321         cwindow->playback_engine->que->send_command(CURRENT_FRAME,
322                 CHANGE_ALL,
323                 edl,
324                 1);
325         save_backup();
328 void MWindow::cut()
330         undo->update_undo_before(_("cut"), LOAD_EDITS | LOAD_TIMEBAR);
332         double start = edl->local_session->get_selectionstart();
333         double end = edl->local_session->get_selectionend();
335         copy(start, end);
336         edl->clear(start, 
337                 end,
338                 edl->session->labels_follow_edits, 
339                 edl->session->plugins_follow_edits);
342         edl->optimize();
343         save_backup();
344         undo->update_undo_after();
346         restart_brender();
347         update_plugin_guis();
348         gui->update(1, 2, 1, 1, 1, 1, 0);
349         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
350                                                         CHANGE_EDL,
351                                                         edl,
352                                                         1);
355 int MWindow::cut_automation()
357         undo->update_undo_before(_("cut keyframes"), LOAD_AUTOMATION);
358         
359         copy_automation();
361         edl->tracks->clear_automation(edl->local_session->get_selectionstart(), 
362                 edl->local_session->get_selectionend()); 
363         save_backup();
364         undo->update_undo_after(); 
367         restart_brender();
368         update_plugin_guis();
369         gui->canvas->draw_overlays();
370         gui->canvas->flash();
371         sync_parameters(CHANGE_PARAMS);
372         gui->patchbay->update();
373         cwindow->update(1, 0, 0);
374         return 0;
377 int MWindow::cut_default_keyframe()
379         undo->update_undo_before(_("cut default keyframe"), LOAD_AUTOMATION);
381         copy_default_keyframe();
382         edl->tracks->clear_default_keyframe();
383         undo->update_undo_after();
385         restart_brender();
386         gui->canvas->draw_overlays();
387         gui->canvas->flash();
388         sync_parameters(CHANGE_PARAMS);
389         gui->patchbay->update();
390         cwindow->update(1, 0, 0);
391         save_backup();
394         return 0;
397 void MWindow::delete_inpoint()
399         edl->local_session->in_point = -1;
400         save_backup();
403 void MWindow::delete_outpoint()
405         edl->local_session->out_point = -1;
406         save_backup();
409 void MWindow::delete_track()
411         undo->update_undo_before(_("delete track"), LOAD_ALL);
412         edl->tracks->delete_track();
413         undo->update_undo_after();
414         save_backup();
416         restart_brender();
417         update_plugin_states();
418         gui->update(1, 1, 1, 0, 1, 0, 0);
419         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
420                            CHANGE_EDL,
421                            edl,
422                            1);
425 void MWindow::delete_tracks()
427         undo->update_undo_before(_("delete tracks"), LOAD_ALL);
428         edl->tracks->delete_tracks();
429         undo->update_undo_after();
430         save_backup();
432         restart_brender();
433         update_plugin_states();
434         gui->update(1, 1, 1, 0, 1, 0, 0);
435         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
436                            CHANGE_EDL,
437                            edl,
438                            1);
439 //printf("MWindow::delete_tracks 5\n");
442 void MWindow::delete_track(Track *track)
444         undo->update_undo_before(_("delete track"), LOAD_ALL);
445         edl->tracks->delete_track(track);
446         undo->update_undo_after();
448         restart_brender();
449         update_plugin_states();
450         gui->update(1, 1, 1, 0, 1, 0, 0);
451         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
452                            CHANGE_EDL,
453                            edl,
454                            1);
455         save_backup();
458 void MWindow::detach_transition(Transition *transition)
460         undo->update_undo_before(_("detach transition"), LOAD_ALL);
461         hide_plugin(transition, 1);
462         int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
463         transition->edit->detach_transition();
464         save_backup();
465         undo->update_undo_after();
467         if(is_video) restart_brender();
468         gui->update(0,
469                 1,
470                 0,
471                 0,
472                 0, 
473                 0,
474                 0);
475         sync_parameters(CHANGE_EDL);
482 // Insert data from clipboard
483 void MWindow::insert(double position, 
484         FileXML *file,
485         int edit_labels,
486         int edit_plugins,
487         EDL *parent_edl)
489 // For clipboard pasting make the new edl use a separate session 
490 // from the master EDL.  Then it can be resampled to the master rates.
491 // For splice, overwrite, and dragging need same session to get the assets.
492         EDL edl(parent_edl);
493         ArrayList<EDL*> new_edls;
494         uint32_t load_flags = LOAD_ALL;
496         new_edls.append(&edl);
497         edl.create_objects();
501         if(parent_edl) load_flags &= ~LOAD_SESSION;
502         if(!edl.session->autos_follow_edits) load_flags &= ~LOAD_AUTOMATION;
503         if(!edl.session->labels_follow_edits) load_flags &= ~LOAD_TIMEBAR;
504         edl.load_xml(plugindb, file, load_flags);
510         paste_edls(&new_edls, 
511                 LOAD_PASTE, 
512                 0, 
513                 position,
514                 edit_labels,
515                 edit_plugins);
516 // if(vwindow->edl)
517 // printf("MWindow::insert 5 %f %f\n", 
518 // vwindow->edl->local_session->in_point,
519 // vwindow->edl->local_session->out_point);
520         new_edls.remove_all();
521 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
524 void MWindow::insert_effects_canvas(double start,
525         double length)
527         Track *dest_track = session->track_highlighted;
528         if(!dest_track) return;
530         undo->update_undo_before(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
532         for(int i = 0; i < session->drag_pluginservers->total; i++)
533         {
534                 PluginServer *plugin = session->drag_pluginservers->values[i];
536                 insert_effect(plugin->title,
537                         0,
538                         dest_track,
539                         i == 0 ? session->pluginset_highlighted : 0,
540                         start,
541                         length,
542                         PLUGIN_STANDALONE);
543         }
545         save_backup();
546         undo->update_undo_after();
547         restart_brender();
548         sync_parameters(CHANGE_EDL);
549 // GUI updated in TrackCanvas, after current_operations are reset
552 void MWindow::insert_effects_cwindow(Track *dest_track)
554         if(!dest_track) return;
556         undo->update_undo_before(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
558         double start = 0;
559         double length = dest_track->get_length();
561         if(edl->local_session->get_selectionend() > 
562                 edl->local_session->get_selectionstart())
563         {
564                 start = edl->local_session->get_selectionstart();
565                 length = edl->local_session->get_selectionend() - 
566                         edl->local_session->get_selectionstart();
567         }
569         for(int i = 0; i < session->drag_pluginservers->total; i++)
570         {
571                 PluginServer *plugin = session->drag_pluginservers->values[i];
574                 insert_effect(plugin->title,
575                         0,
576                         dest_track,
577                         0,
578                         start,
579                         length,
580                         PLUGIN_STANDALONE);
581         }
583         save_backup();
584         undo->update_undo_after();
585         restart_brender();
586         sync_parameters(CHANGE_EDL);
587         gui->update(1,
588                 1,
589                 0,
590                 0,
591                 1,
592                 0,
593                 0);
598 void MWindow::insert_effect(char *title, 
599         SharedLocation *shared_location, 
600         Track *track,
601         PluginSet *plugin_set,
602         double start,
603         double length,
604         int plugin_type)
606         KeyFrame *default_keyframe = 0;
607         PluginServer *server = 0;
614 // Get default keyframe
615         if(plugin_type == PLUGIN_STANDALONE)
616         {
617                 default_keyframe = new KeyFrame;
618                 server = new PluginServer(*scan_plugindb(title));
620                 server->open_plugin(0, preferences, edl, 0, -1);
621                 server->save_data(default_keyframe);
622         }
626 // Insert plugin object
627         track->insert_effect(title, 
628                 shared_location, 
629                 default_keyframe, 
630                 plugin_set,
631                 start,
632                 length,
633                 plugin_type);
635         track->optimize();
638         if(plugin_type == PLUGIN_STANDALONE)
639         {
640                 server->close_plugin();
641                 delete server;
642                 delete default_keyframe;
643         }
646 int MWindow::modify_edithandles()
648         undo->update_undo_before(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
654         edl->modify_edithandles(session->drag_start, 
655                 session->drag_position, 
656                 session->drag_handle, 
657                 edl->session->edit_handle_mode[session->drag_button],
658                 edl->session->labels_follow_edits, 
659                 edl->session->plugins_follow_edits);
661         finish_modify_handles();
664 //printf("MWindow::modify_handles 1\n");
665         return 0;
668 int MWindow::modify_pluginhandles()
670         undo->update_undo_before(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
672         edl->modify_pluginhandles(session->drag_start, 
673                 session->drag_position, 
674                 session->drag_handle, 
675                 edl->session->edit_handle_mode[session->drag_button],
676                 edl->session->labels_follow_edits);
678         finish_modify_handles();
680         return 0;
684 // Common to edithandles and plugin handles
685 void MWindow::finish_modify_handles()
687         int edit_mode = edl->session->edit_handle_mode[session->drag_button];
689 //printf("TrackCanvas::end_handle_selection 1\n");
690         if((session->drag_handle == 1 && edit_mode != MOVE_NO_EDITS) ||
691                 (session->drag_handle == 0 && edit_mode == MOVE_ONE_EDIT))
692         {
693                 edl->local_session->selectionstart = 
694                         edl->local_session->selectionend = 
695                         session->drag_position;
696         }
697         else
698         if(edit_mode != MOVE_NO_EDITS)
699         {
700                 edl->local_session->selectionstart = 
701                         edl->local_session->selectionend = 
702                         session->drag_start;
703         }
705 //printf("TrackCanvas::end_handle_selection 1\n");
706         if(edl->local_session->selectionstart < 0) 
707                 edl->local_session->selectionstart = 
708                         edl->local_session->selectionend = 0;
709 //printf("TrackCanvas::end_handle_selection 1\n");
711         save_backup();
712         undo->update_undo_after();
713         restart_brender();
714         sync_parameters(CHANGE_EDL);
715 //printf("TrackCanvas::end_handle_selection 1\n");
716         update_plugin_guis();
717         gui->update(1, 2, 1, 1, 1, 1, 0);
718         cwindow->update(1, 0, 0, 0, 1);
719 //printf("TrackCanvas::end_handle_selection 2\n");
724 void MWindow::match_output_size(Track *track)
726     undo->update_undo_before(_("match output size"), LOAD_ALL);
727         track->track_w = edl->session->output_w;
728         track->track_h = edl->session->output_h;
729         save_backup();
730         undo->update_undo_after();
732         restart_brender();
733         sync_parameters(CHANGE_EDL);
737 void MWindow::move_edits(ArrayList<Edit*> *edits, 
738                 Track *track,
739                 double position)
741         undo->update_undo_before(_("move edit"), LOAD_ALL);
743         edl->tracks->move_edits(edits, 
744                 track, 
745                 position,
746                 edl->session->labels_follow_edits, 
747                 edl->session->plugins_follow_edits);
749         save_backup();
750         undo->update_undo_after();
752         restart_brender();
753         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
754                 CHANGE_EDL,
755                 edl,
756                 1);
758         update_plugin_guis();
759         gui->update(1,
760                 1,      // 1 for incremental drawing.  2 for full refresh
761                 1,
762                 0,
763                 0, 
764                 0,
765                 0);
768 void MWindow::move_effect(Plugin *plugin,
769         PluginSet *dest_plugin_set,
770         Track *dest_track,
771         int64_t dest_position)
773         undo->update_undo_before(_("move effect"), LOAD_ALL);
775         edl->tracks->move_effect(plugin, 
776                 dest_plugin_set, 
777                 dest_track, 
778                 dest_position);
780         save_backup();
781         undo->update_undo_after();
783         restart_brender();
784         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
785                 CHANGE_EDL,
786                 edl,
787                 1);
789         update_plugin_guis();
790         gui->update(1,
791                 1,      // 1 for incremental drawing.  2 for full refresh
792                 0,
793                 0,
794                 0, 
795                 0,
796                 0);
799 void MWindow::move_plugins_up(PluginSet *plugin_set)
801         undo->update_undo_before(_("move effect up"), LOAD_ALL);
803         plugin_set->track->move_plugins_up(plugin_set);
805         save_backup();
806         undo->update_undo_after();
807         restart_brender();
808         gui->update(1,
809                 1,      // 1 for incremental drawing.  2 for full refresh
810                 0,
811                 0,
812                 0, 
813                 0,
814                 0);
815         sync_parameters(CHANGE_EDL);
818 void MWindow::move_plugins_down(PluginSet *plugin_set)
820         undo->update_undo_before(_("move effect down"), LOAD_ALL);
822         plugin_set->track->move_plugins_down(plugin_set);
824         save_backup();
825         undo->update_undo_after();
826         restart_brender();
827         gui->update(1,
828                 1,      // 1 for incremental drawing.  2 for full refresh
829                 0,
830                 0,
831                 0, 
832                 0,
833                 0);
834         sync_parameters(CHANGE_EDL);
837 void MWindow::move_track_down(Track *track)
839         undo->update_undo_before(_("move track down"), LOAD_ALL);
840         edl->tracks->move_track_down(track);
841         save_backup();
842         undo->update_undo_after();
844         restart_brender();
845         gui->update(1, 1, 0, 0, 1, 0, 0);
846         sync_parameters(CHANGE_EDL);
847         save_backup();
850 void MWindow::move_tracks_down()
852         undo->update_undo_before(_("move tracks down"), LOAD_ALL);
853         edl->tracks->move_tracks_down();
854         save_backup();
855         undo->update_undo_after();
857         restart_brender();
858         gui->update(1, 1, 0, 0, 1, 0, 0);
859         sync_parameters(CHANGE_EDL);
860         save_backup();
863 void MWindow::move_track_up(Track *track)
865         undo->update_undo_before(_("move track up"), LOAD_ALL);
866         edl->tracks->move_track_up(track);
867         save_backup();
868         undo->update_undo_after();
869         restart_brender();
870         gui->update(1, 1, 0, 0, 1, 0, 0);
871         sync_parameters(CHANGE_EDL);
872         save_backup();
875 void MWindow::move_tracks_up()
877         undo->update_undo_before(_("move tracks up"), LOAD_ALL);
878         edl->tracks->move_tracks_up();
879         save_backup();
880         undo->update_undo_after();
881         restart_brender();
882         gui->update(1, 1, 0, 0, 1, 0, 0);
883         sync_parameters(CHANGE_EDL);
887 void MWindow::mute_selection()
889         double start = edl->local_session->get_selectionstart();
890         double end = edl->local_session->get_selectionend();
891         if(start != end)
892         {
893                 undo->update_undo_before(_("mute"), LOAD_EDITS);
896                 edl->clear(start, 
897                         end, 
898                         0, 
899                         edl->session->plugins_follow_edits);
900                 edl->local_session->selectionend = end;
901                 edl->local_session->selectionstart = start;
902                 edl->paste_silence(start, end, 0, edl->session->plugins_follow_edits);
903                 save_backup();
904                 undo->update_undo_after();
906                 restart_brender();
907                 update_plugin_guis();
908                 gui->update(1, 2, 1, 1, 1, 1, 0);
909                 cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
910                                                                 CHANGE_EDL,
911                                                                 edl,
912                                                                 1);
913         }
918 void MWindow::overwrite(EDL *source)
920         FileXML file;
921         source->copy(source->local_session->in_point, 
922                 source->local_session->out_point, 
923                 1,
924                 0,
925                 0,
926                 &file,
927                 plugindb,
928                 "",
929                 1);
930         undo->update_undo_before(_("overwrite"), LOAD_EDITS);
932         double start = edl->local_session->get_selectionstart();
933         double end = edl->local_session->get_selectionend();
934 // Calculate overwrite length from length of source
935         if(EQUIV(end, start))
936         {
937                 end = start + 
938                         source->local_session->out_point - 
939                         source->local_session->in_point;
940         }
943         paste(start, 
944                 end, 
945                 &file,
946                 0,
947                 0);
948         edl->local_session->selectionstart = 
949                 edl->local_session->selectionend =
950                 start + 
951                 source->local_session->out_point - 
952                 source->local_session->in_point;
953         save_backup();
954         undo->update_undo_after();
956         restart_brender();
957         update_plugin_guis();
958         gui->update(1, 1, 1, 1, 0, 1, 0);
959         sync_parameters(CHANGE_EDL);
962 // For splice and overwrite
963 int MWindow::paste(double start, 
964         double end, 
965         FileXML *file,
966         int edit_labels,
967         int edit_plugins)
969 //printf("MWindow::paste 1\n");
970         clear(0);
972 // Want to insert with assets shared with the master EDL.
973         insert(start, 
974                         file,
975                         edit_labels,
976                         edit_plugins,
977                         edl);
979 //printf("MWindow::paste 2\n");
980         return 0;
983 // For editing use insertion point position
984 void MWindow::paste()
986         double start = edl->local_session->get_selectionstart();
987         double end = edl->local_session->get_selectionend();
988         int64_t len = gui->get_clipboard()->clipboard_len(SECONDARY_SELECTION);
989         char *string = new char[len + 1];
991         gui->get_clipboard()->from_clipboard(string, 
992                 len, 
993                 SECONDARY_SELECTION);
994         FileXML file;
995         file.read_from_string(string);
998         undo->update_undo_before(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1000         clear(0);
1001         insert(start, 
1002                 &file, 
1003                 edl->session->labels_follow_edits, 
1004                 edl->session->plugins_follow_edits);
1005         edl->optimize();
1007         delete [] string;
1010         save_backup();
1013         undo->update_undo_after();
1014         restart_brender();
1015         update_plugin_guis();
1016         gui->update(1, 2, 1, 1, 0, 1, 0);
1017         awindow->gui->update_assets();
1018         sync_parameters(CHANGE_EDL);
1021 int MWindow::paste_assets(double position, Track *dest_track)
1023         int result = 0;
1025         undo->update_undo_before(_("paste assets"), LOAD_EDITS);
1029         if(session->drag_assets->total)
1030         {
1031                 load_assets(session->drag_assets, 
1032                         position, 
1033                         LOAD_PASTE,
1034                         dest_track, 
1035                         0,
1036                         edl->session->labels_follow_edits, 
1037                         edl->session->plugins_follow_edits);
1038                 result = 1;
1039         }
1042         if(session->drag_clips->total)
1043         {
1044                 paste_edls(session->drag_clips, 
1045                         LOAD_PASTE, 
1046                         dest_track,
1047                         position, 
1048                         edl->session->labels_follow_edits, 
1049                         edl->session->plugins_follow_edits);
1050                 result = 1;
1051         }
1054         save_backup();
1056         undo->update_undo_after();
1057         restart_brender();
1058         gui->update(1, 
1059                 2,
1060                 1,
1061                 0,
1062                 0,
1063                 1,
1064                 0);
1065         sync_parameters(CHANGE_EDL);
1066         return result;
1069 void MWindow::load_assets(ArrayList<Asset*> *new_assets, 
1070         double position, 
1071         int load_mode,
1072         Track *first_track,
1073         RecordLabels *labels,
1074         int edit_labels,
1075         int edit_plugins)
1077 //printf("MWindow::load_assets 1\n");
1078         if(position < 0) position = edl->local_session->get_selectionstart();
1080         ArrayList<EDL*> new_edls;
1081         for(int i = 0; i < new_assets->total; i++)
1082         {
1083                 EDL *new_edl = new EDL;
1084                 new_edl->create_objects();
1085                 new_edl->copy_session(edl);
1086                 new_edls.append(new_edl);
1089 //printf("MWindow::load_assets 2 %d %d\n", new_assets->values[i]->audio_length, new_assets->values[i]->video_length);
1090                 asset_to_edl(new_edl, new_assets->values[i]);
1093                 if(labels)
1094                         for(RecordLabel *label = labels->first; label; label = label->next)
1095                         {
1096                                 new_edl->labels->toggle_label(label->position, label->position);
1097                         }
1098         }
1099 //printf("MWindow::load_assets 3\n");
1101         paste_edls(&new_edls, 
1102                 load_mode, 
1103                 first_track,
1104                 position,
1105                 edit_labels,
1106                 edit_plugins);
1107 //printf("MWindow::load_assets 4\n");
1110         save_backup();
1111         new_edls.remove_all_objects();
1115 int MWindow::paste_automation()
1117         int64_t len = gui->get_clipboard()->clipboard_len(SECONDARY_SELECTION);
1119         char *string = new char[len + 1];
1120         gui->get_clipboard()->from_clipboard(string, 
1121                 len, 
1122                 SECONDARY_SELECTION);
1123         FileXML file;
1124         file.read_from_string(string);
1126         undo->update_undo_before(_("paste keyframes"), LOAD_AUTOMATION); 
1127         edl->tracks->clear_automation(edl->local_session->get_selectionstart(), 
1128                 edl->local_session->get_selectionend()); 
1129         edl->tracks->paste_automation(edl->local_session->get_selectionstart(), 
1130                 &file,
1131                 0); 
1132         save_backup();
1133         undo->update_undo_after(); 
1134         delete [] string;
1137         restart_brender();
1138         update_plugin_guis();
1139         gui->canvas->draw_overlays();
1140         gui->canvas->flash();
1141         sync_parameters(CHANGE_PARAMS);
1142         gui->patchbay->update();
1143         cwindow->update(1, 0, 0);
1145         return 0;
1148 int MWindow::paste_default_keyframe()
1150         int64_t len = gui->get_clipboard()->clipboard_len(SECONDARY_SELECTION);
1151         char *string = new char[len + 1];
1152         gui->get_clipboard()->from_clipboard(string, 
1153                 len, 
1154                 SECONDARY_SELECTION);
1155         FileXML file;
1156         file.read_from_string(string);
1157         undo->update_undo_before(_("paste default keyframe"), LOAD_AUTOMATION); 
1158         edl->tracks->paste_default_keyframe(&file); 
1159         undo->update_undo_after(); 
1162         restart_brender();
1163         update_plugin_guis();
1164         gui->canvas->draw_overlays();
1165         gui->canvas->flash();
1166         sync_parameters(CHANGE_PARAMS);
1167         gui->patchbay->update();
1168         cwindow->update(1, 0, 0);
1169         delete [] string;
1170         save_backup();
1172         return 0;
1176 // Insert edls with project deletion and index file generation.
1177 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, 
1178         int load_mode, 
1179         Track *first_track,
1180         double current_position,
1181         int edit_labels,
1182         int edit_plugins)
1184         ArrayList<Track*> destination_tracks;
1185         int need_new_tracks = 0;
1187         if(!new_edls->total) return 0;
1188 //printf("MWindow::paste_edls 1\n");
1190 // Delete current project
1191         if(load_mode == LOAD_REPLACE ||
1192                 load_mode == LOAD_REPLACE_CONCATENATE)
1193         {
1194                 edl->save_defaults(defaults);
1195                 hide_plugins();
1196 // this has to be cleaned because patches[x]->track points nowhere 
1197 // after next call
1198                 patches->delete_all_patches();    
1199                 delete edl;
1200                 edl = new EDL;
1201                 edl->create_objects();
1202                 edl->copy_session(new_edls->values[0]);
1203                 gui->mainmenu->update_toggles();
1205 // Insert labels for certain modes constitutively
1206                 edit_labels = 1;
1207                 edit_plugins = 1;
1208         }
1209 //printf("MWindow::paste_edls 2\n");
1211 // Assume any paste operation from the same EDL won't contain any clips.
1212 // If it did it would duplicate every clip here.
1213         for(int i = 0; i < new_edls->total; i++)
1214         {
1215                 EDL *new_edl = new_edls->values[i];
1217                 for(int j = 0; j < new_edl->clips.total; j++)
1218                 {
1219                         edl->add_clip(new_edl->clips.values[j]);
1220                 }
1222                 if(new_edl->vwindow_edl)
1223                 {
1224                         if(edl->vwindow_edl) delete edl->vwindow_edl;
1225                         edl->vwindow_edl = new EDL(edl);
1226                         edl->vwindow_edl->create_objects();
1227                         edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1228                 }
1229         }
1230 //printf("MWindow::paste_edls 2\n");
1232 // Create new tracks in master EDL
1233         if(load_mode == LOAD_REPLACE || 
1234                 load_mode == LOAD_REPLACE_CONCATENATE ||
1235                 load_mode == LOAD_NEW_TRACKS)
1236         {
1237                 need_new_tracks = 1;
1238                 for(int i = 0; i < new_edls->total; i++)
1239                 {
1240                         EDL *new_edl = new_edls->values[i];
1241                         for(Track *current = new_edl->tracks->first;
1242                                 current;
1243                                 current = NEXT)
1244                         {
1245                                 if(current->data_type == TRACK_VIDEO)
1246                                 {
1247                                         edl->tracks->add_video_track(0, 0);
1248                                         if(current->draw) edl->tracks->last->draw = 1;
1249                                         destination_tracks.append(edl->tracks->last);
1250                                 }
1251                                 else
1252                                 if(current->data_type == TRACK_AUDIO)
1253                                 {
1254                                         edl->tracks->add_audio_track(0, 0);
1255                                         destination_tracks.append(edl->tracks->last);
1256                                 }
1257                                 edl->session->highlighted_track = edl->tracks->total() - 1;
1258                         }
1260 // Base track count on first EDL only for concatenation
1261                         if(load_mode == LOAD_REPLACE_CONCATENATE) break;
1262                 }
1263         }
1264         else
1265 // Recycle existing tracks of master EDL
1266         if(load_mode == LOAD_CONCATENATE || load_mode == LOAD_PASTE)
1267         {
1268 // The point of this is to shift forward labels after the selection so they can
1269 // then be shifted back to their original locations without recursively
1270 // shifting back every paste.
1271                 if(load_mode == LOAD_PASTE && edl->session->labels_follow_edits)
1272                         edl->labels->clear(edl->local_session->get_selectionstart(),
1273                                                 edl->local_session->get_selectionend(),
1274                                                 1);
1275         
1276                 Track *current = first_track ? first_track : edl->tracks->first;
1277                 for( ; current; current = NEXT)
1278                 {
1279                         if(current->record)
1280                         {
1281                                 destination_tracks.append(current);
1283 // This should be done in the caller so we don't get recursive clear disease.
1284 //                              if(load_mode == LOAD_PASTE)
1285 //                                      current->clear(edl->local_session->get_selectionstart(),
1286 //                                              edl->local_session->get_selectionend(),
1287 //                                              1,
1288 //                                              edl->session->labels_follow_edits, 
1289 //                                              edl->session->plugins_follow_edits,
1290 //                                              1);
1291                         }
1292                 }
1293         }
1296 //printf("MWindow::paste_edls 2\n");
1298         int destination_track = 0;
1299         double *paste_position = new double[destination_tracks.total];
1305 // Iterate through the edls
1306         for(int i = 0; i < new_edls->total; i++)
1307         {
1308                 EDL *new_edl = new_edls->values[i];
1309                 double edl_length = new_edl->local_session->clipboard_length ?
1310                         new_edl->local_session->clipboard_length :
1311                         new_edl->tracks->total_length();
1312 // printf("MWindow::paste_edls 2\n");
1313 // new_edl->dump();
1317 // Resample EDL to master rates
1318                 new_edl->resample(new_edl->session->sample_rate, 
1319                         edl->session->sample_rate, 
1320                         TRACK_AUDIO);
1321                 new_edl->resample(new_edl->session->frame_rate, 
1322                         edl->session->frame_rate, 
1323                         TRACK_VIDEO);
1327 //printf("MWindow::paste_edls 2 %d\n", new_edl->assets->total());
1328 // Add assets and prepare index files
1329                 edl->update_assets(new_edl);
1330                 for(Asset *new_asset = edl->assets->first;
1331                         new_asset;
1332                         new_asset = new_asset->next)
1333                 {
1334                         mainindexes->add_next_asset(new_asset);
1335                 }
1338 // Get starting point of insertion.  Need this to paste labels.
1339                 switch(load_mode)
1340                 {
1341                         case LOAD_REPLACE:
1342                         case LOAD_NEW_TRACKS:
1343                                 current_position = 0;
1344                                 break;
1346                         case LOAD_CONCATENATE:
1347                         case LOAD_REPLACE_CONCATENATE:
1348                                 destination_track = 0;
1349                                 if(destination_tracks.total)
1350                                         current_position = destination_tracks.values[0]->get_length();
1351                                 else
1352                                         current_position = 0;
1353                                 break;
1355                         case LOAD_PASTE:
1356                                 destination_track = 0;
1357                                 if(i == 0)
1358                                 {
1359                                         for(int j = 0; j < destination_tracks.total; j++)
1360                                         {
1361                                                 paste_position[j] = (current_position >= 0) ? 
1362                                                         current_position :
1363                                                         edl->local_session->get_selectionstart();
1364                                         }
1365                                 }
1366                                 break;
1368                         case LOAD_RESOURCESONLY:
1369                                 edl->add_clip(new_edl);
1370                                 break;
1371                 }
1376 // Insert edl
1377                 if(load_mode != LOAD_RESOURCESONLY)
1378                 {
1379 // Insert labels
1380 //printf("MWindow::paste_edls %f %f\n", current_position, edl_length);
1381                         if(load_mode == LOAD_PASTE)
1382                                 edl->labels->insert_labels(new_edl->labels, 
1383                                         destination_tracks.total ? paste_position[0] : 0.0,
1384                                         edl_length,
1385                                         edit_labels);
1386                         else
1387                                 edl->labels->insert_labels(new_edl->labels, 
1388                                         current_position,
1389                                         edl_length,
1390                                         edit_labels);
1392                         for(Track *new_track = new_edl->tracks->first; 
1393                                 new_track; 
1394                                 new_track = new_track->next)
1395                         {
1396 // Get destination track of same type as new_track
1397                                 for(int k = 0; 
1398                                         k < destination_tracks.total &&
1399                                         destination_tracks.values[destination_track]->data_type != new_track->data_type;
1400                                         k++, destination_track++)
1401                                 {
1402                                         if(destination_track >= destination_tracks.total - 1)
1403                                                 destination_track = 0;
1404                                 }
1406 // Insert data into destination track
1407                                 if(destination_track < destination_tracks.total &&
1408                                         destination_tracks.values[destination_track]->data_type == new_track->data_type)
1409                                 {
1410                                         Track *track = destination_tracks.values[destination_track];
1412 // Replace default keyframes if first EDL and new tracks were created.
1413 // This means data copied from one track and pasted to another won't retain
1414 // the camera position unless it's a keyframe.  If it did, previous data in the
1415 // track might get unknowingly corrupted.  Ideally we would detect when differing
1416 // default keyframes existed and create discrete keyframes for both.
1417                                         int replace_default = (i == 0) && need_new_tracks;
1419 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1420 // Insert new track at current position
1421                                         switch(load_mode)
1422                                         {
1423                                                 case LOAD_REPLACE_CONCATENATE:
1424                                                 case LOAD_CONCATENATE:
1425                                                         current_position = track->get_length();
1426                                                         break;
1428                                                 case LOAD_PASTE:
1429                                                         current_position = paste_position[destination_track];
1430                                                         paste_position[destination_track] += new_track->get_length();
1431                                                         break;
1432                                         }
1434                                         track->insert_track(new_track, 
1435                                                 current_position, 
1436                                                 replace_default,
1437                                                 edit_plugins);
1438                                 }
1440 // Get next destination track
1441                                 destination_track++;
1442                                 if(destination_track >= destination_tracks.total)
1443                                         destination_track = 0;
1444                         }
1445                 }
1447                 if(load_mode == LOAD_PASTE)
1448                         current_position += edl_length;
1449         }
1450 //printf("MWindow::paste_edls 3\n");
1452         if(paste_position) delete [] paste_position;
1454 // This is already done in load_filenames and everything else that uses paste_edls
1455 //      update_project(load_mode);
1457 //printf("MWindow::paste_edls 5\n");
1459 // Start examining next batch of index files
1460         mainindexes->start_build();
1461 //printf("MWindow::paste_edls 6\n");
1463 // Don't save a backup after loading since the loaded file is on disk already.
1465         return 0;
1468 void MWindow::paste_silence()
1470         double start = edl->local_session->get_selectionstart();
1471         double end = edl->local_session->get_selectionend();
1472     undo->update_undo_before(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1473         edl->paste_silence(start, 
1474                 end, 
1475                 edl->session->labels_follow_edits, 
1476                 edl->session->plugins_follow_edits);
1477         edl->optimize();
1478         save_backup();
1479         undo->update_undo_after();
1481         update_plugin_guis();
1482         restart_brender();
1483         gui->update(1, 2, 1, 1, 1, 1, 0);
1484         cwindow->update(1, 0, 0, 0, 1);
1485         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1486                                                         CHANGE_EDL,
1487                                                         edl,
1488                                                         1);
1491 void MWindow::paste_transition()
1493     undo->update_undo_before(_("transition"), LOAD_EDITS);
1494 // Only the first transition gets dropped.
1495         PluginServer *server = session->drag_pluginservers->values[0];
1496         if(server->audio)
1497                 strcpy(edl->session->default_atransition, server->title);
1498         else
1499                 strcpy(edl->session->default_vtransition, server->title);
1501         edl->tracks->paste_transition(server, session->edit_highlighted);
1502         save_backup();
1503         undo->update_undo_after();
1505         if(server->video) restart_brender();
1506         sync_parameters(CHANGE_ALL);
1509 void MWindow::paste_transition_cwindow(Track *dest_track)
1511         undo->update_undo_before(_("transition"), LOAD_EDITS);
1512         PluginServer *server = session->drag_pluginservers->values[0];
1513         edl->tracks->paste_video_transition(server, 1);
1514         save_backup();
1515         restart_brender();
1516         gui->update(0, 1, 0, 0, 0, 0, 0);
1517         sync_parameters(CHANGE_ALL);
1520 void MWindow::paste_audio_transition()
1522         PluginServer *server = scan_plugindb(edl->session->default_atransition);
1523         if(!server)
1524         {
1525                 char string[BCTEXTLEN];
1526                 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1527                 gui->show_message(string);
1528                 return;
1529         }
1531     undo->update_undo_before(_("paste transition"), LOAD_EDITS);
1532         edl->tracks->paste_audio_transition(server);
1533         save_backup();
1534         undo->update_undo_after();
1536         sync_parameters(CHANGE_ALL);
1537         gui->update(0, 1, 0, 0, 0, 0, 0);
1540 void MWindow::paste_video_transition()
1542         PluginServer *server = scan_plugindb(edl->session->default_vtransition);
1543         if(!server)
1544         {
1545                 char string[BCTEXTLEN];
1546                 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1547                 gui->show_message(string);
1548                 return;
1549         }
1552     undo->update_undo_before(_("paste transition"), LOAD_EDITS);
1553         edl->tracks->paste_video_transition(server);
1554         save_backup();
1555         undo->update_undo_after();
1557         sync_parameters(CHANGE_ALL);
1558         restart_brender();
1559         gui->update(0, 1, 0, 0, 0, 0, 0);
1562 void MWindow::redo_entry(int is_mwindow)
1564         if(is_mwindow)
1565                 gui->unlock_window();
1566         else
1567                 cwindow->gui->unlock_window();
1570         cwindow->playback_engine->que->send_command(STOP,
1571                 CHANGE_NONE, 
1572                 0,
1573                 0);
1574         vwindow->playback_engine->que->send_command(STOP,
1575                 CHANGE_NONE, 
1576                 0,
1577                 0);
1578         cwindow->playback_engine->interrupt_playback(0);
1579         vwindow->playback_engine->interrupt_playback(0);
1582         cwindow->gui->lock_window("MWindow::redo_entry");
1583         gui->lock_window();
1585         undo->redo(); 
1587         save_backup();
1588         update_plugin_states();
1589         update_plugin_guis();
1590         restart_brender();
1591         gui->update(1, 2, 1, 1, 1, 1, 0);
1592         cwindow->update(1, 1, 1, 1, 1);
1594         if(is_mwindow)
1595                 cwindow->gui->unlock_window();
1596         else
1597                 gui->unlock_window();
1599         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1600                            CHANGE_ALL,
1601                            edl,
1602                            1);
1603         
1607 void MWindow::resize_track(Track *track, int w, int h)
1609         undo->update_undo_before(_("resize track"), LOAD_ALL);
1610         track->track_w = w;
1611         track->track_h = h;
1612         undo->update_undo_after();
1613         save_backup();
1615         restart_brender();
1616         sync_parameters(CHANGE_EDL);
1620 void MWindow::set_inpoint(int is_mwindow)
1622         undo->update_undo_before(_("in point"), LOAD_TIMEBAR);
1623         edl->set_inpoint(edl->local_session->selectionstart);
1624         save_backup();
1625         undo->update_undo_after();
1628         if(!is_mwindow)
1629         {
1630                 gui->lock_window("MWindow::set_inpoint 1");
1631         }
1632         gui->timebar->update();
1633         gui->flush();
1634         if(!is_mwindow)
1635         {
1636                 gui->unlock_window();
1637         }
1639         if(is_mwindow)
1640         {
1641                 cwindow->gui->lock_window("MWindow::set_inpoint 2");
1642         }
1643         cwindow->gui->timebar->update();
1644         cwindow->gui->flush();
1645         if(is_mwindow)
1646         {
1647                 cwindow->gui->unlock_window();
1648         }
1651 void MWindow::set_outpoint(int is_mwindow)
1653         undo->update_undo_before(_("out point"), LOAD_TIMEBAR);
1654         edl->set_outpoint(edl->local_session->selectionend);
1655         save_backup();
1656         undo->update_undo_after();
1659         if(!is_mwindow)
1660         {
1661                 gui->lock_window("MWindow::set_outpoint 1");
1662         }
1663         gui->timebar->update();
1664         gui->flush();
1665         if(!is_mwindow)
1666         {
1667                 gui->unlock_window();
1668         }
1670         if(is_mwindow)
1671         {
1672                 cwindow->gui->lock_window("MWindow::set_outpoint 2");
1673         }
1674         cwindow->gui->timebar->update();
1675         cwindow->gui->flush();
1676         if(is_mwindow)
1677         {
1678                 cwindow->gui->unlock_window();
1679         }
1682 void MWindow::splice(EDL *source)
1684         FileXML file;
1686         source->copy(source->local_session->in_point, 
1687                 source->local_session->out_point, 
1688                 1,
1689                 0,
1690                 0,
1691                 &file,
1692                 plugindb,
1693                 "",
1694                 1);
1696         undo->update_undo_before(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
1699 //file.dump();
1700         double start = edl->local_session->get_selectionstart();
1701         double end = edl->local_session->get_selectionend();
1703         paste(start, 
1704                 start, 
1705                 &file,
1706                 edl->session->labels_follow_edits,
1707                 edl->session->plugins_follow_edits);
1709         edl->local_session->selectionstart = 
1710                 edl->local_session->selectionend =
1711                 start + 
1712                 source->local_session->out_point - 
1713                 source->local_session->in_point;
1715         save_backup();
1716         undo->update_undo_after();
1717         update_plugin_guis();
1718         restart_brender();
1719         gui->update(1, 1, 1, 1, 0, 1, 0);
1720         sync_parameters(CHANGE_EDL);
1723 void MWindow::to_clip()
1725         FileXML file;
1726         double start, end;
1727         
1728         start = edl->local_session->get_selectionstart();
1729         end = edl->local_session->get_selectionend();
1731         if(EQUIV(end, start)) 
1732         {
1733                 start = 0;
1734                 end = edl->tracks->total_length();
1735         }
1737 // Don't copy all since we don't want the clips twice.
1738         edl->copy(start, 
1739                 end, 
1740                 0,
1741                 0,
1742                 0,
1743                 &file,
1744                 plugindb,
1745                 "",
1746                 1);
1748 //printf("MWindow::to_clip 1 %s\n", edl->local_session->clip_title);
1750 //file.dump();
1753         EDL *new_edl = new EDL(edl);
1754         new_edl->create_objects();
1755         new_edl->load_xml(plugindb, &file, LOAD_ALL);
1756         sprintf(new_edl->local_session->clip_title, _("Clip %d\n"), session->clip_number++);
1758 //printf("VWindowEditing::to_clip 2 %d\n", edl->assets->total());
1759         awindow->clip_edit->create_clip(new_edl);
1760         save_backup();
1761 //printf("VWindowEditing::to_clip 3 %d\n", edl->assets->total());
1767 int MWindow::toggle_label(int is_mwindow)
1769         double position1, position2;
1771 //printf("MWindow::toggle_label 1\n");
1772         undo->update_undo_before(_("label"), LOAD_TIMEBAR);
1773 //printf("MWindow::toggle_label 1\n");
1775         if(cwindow->playback_engine->is_playing_back)
1776         {
1777                 position1 = position2 = 
1778                         cwindow->playback_engine->get_tracking_position();
1779         }
1780         else
1781         {
1782                 position1 = edl->local_session->selectionstart;
1783                 position2 = edl->local_session->selectionend;
1784         }
1786 //printf("MWindow::toggle_label 1 %f %f\n", position1,position2 );
1787         position1 = edl->align_to_frame(position1, 0);
1788         position2 = edl->align_to_frame(position2, 0);
1790 //printf("MWindow::toggle_label 1\n");
1791         edl->labels->toggle_label(position1, position2);
1792         save_backup();
1794 //printf("MWindow::toggle_label 1\n");
1795         if(!is_mwindow)
1796         {
1797                 gui->lock_window("MWindow::toggle_label 1");
1798         }
1799         gui->timebar->update();
1800         gui->canvas->activate();
1801         gui->flush();
1802         if(!is_mwindow)
1803         {
1804                 gui->unlock_window();
1805         }
1807 //printf("MWindow::toggle_label 1\n");
1808         if(is_mwindow)
1809         {
1810                 cwindow->gui->lock_window("MWindow::toggle_label 2");
1811         }
1812         cwindow->gui->timebar->update();
1813         cwindow->gui->flush();
1814         if(is_mwindow)
1815         {
1816                 cwindow->gui->unlock_window();
1817         }
1819 //printf("MWindow::toggle_label 1\n");
1820         undo->update_undo_after();
1821 //printf("MWindow::toggle_label 2\n");
1822         return 0;
1825 void MWindow::trim_selection()
1827         undo->update_undo_before("trim selection", LOAD_EDITS | LOAD_TIMEBAR);
1830         edl->trim_selection(edl->local_session->get_selectionstart(), 
1831                 edl->local_session->get_selectionend(), 
1832                 edl->session->labels_follow_edits, 
1833                 edl->session->plugins_follow_edits);
1835         save_backup();
1836         undo->update_undo_after();
1837         update_plugin_guis();
1838         gui->update(1, 2, 1, 1, 1, 1, 0);
1839         restart_brender();
1840         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1841                                                         CHANGE_EDL,
1842                                                         edl,
1843                                                         1);
1848 void MWindow::undo_entry(int is_mwindow)
1850         if(is_mwindow)
1851                 gui->unlock_window();
1852         else
1853                 cwindow->gui->unlock_window();
1855         cwindow->playback_engine->que->send_command(STOP,
1856                 CHANGE_NONE, 
1857                 0,
1858                 0);
1859         vwindow->playback_engine->que->send_command(STOP,
1860                 CHANGE_NONE, 
1861                 0,
1862                 0);
1863         cwindow->playback_engine->interrupt_playback(0);
1864         vwindow->playback_engine->interrupt_playback(0);
1866         cwindow->gui->lock_window("MWindow::undo_entry 1");
1867         gui->lock_window("MWindow::undo_entry 2");
1869         undo->undo(); 
1871         save_backup();
1872         restart_brender();
1873         update_plugin_states();
1874         update_plugin_guis();
1875         gui->update(1, 2, 1, 1, 1, 1, 0);
1876         cwindow->update(1, 1, 1, 1, 1);
1878         if(is_mwindow)
1879                 cwindow->gui->unlock_window();
1880         else
1881                 gui->unlock_window();
1883         awindow->gui->lock_window("MWindow::undo_entry 3");
1884         awindow->gui->update_assets();
1885         awindow->gui->flush();
1886         awindow->gui->unlock_window();
1887         cwindow->playback_engine->que->send_command(CURRENT_FRAME, 
1888                            CHANGE_ALL,
1889                            edl,
1890                            1);
1895 void MWindow::new_folder(char *new_folder)
1897         undo->update_undo_before(_("new folder"), LOAD_ALL);
1898         edl->new_folder(new_folder);
1899         undo->update_undo_after();
1900         awindow->gui->lock_window("MWindow::new_folder");
1901         awindow->gui->update_assets();
1902         awindow->gui->unlock_window();
1905 void MWindow::delete_folder(char *folder)
1907         undo->update_undo_before(_("new folder"), LOAD_ALL);
1908         undo->update_undo_after();
1911 void MWindow::select_point(double position)
1913         edl->local_session->selectionstart = 
1914                 edl->local_session->selectionend = position;
1915 // Que the CWindow
1916         cwindow->update(1, 0, 0, 0, 1);
1917         update_plugin_guis();
1918         gui->patchbay->update();
1919         gui->cursor->hide();
1920         gui->cursor->draw();
1921         gui->mainclock->update(edl->local_session->selectionstart);
1922         gui->zoombar->update();
1923         gui->canvas->flash();
1924         gui->flush();