5e4b797be1f96ead14415d179af9467b3f04116b
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindowedit.C
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
4  *
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.
9  *
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.
14  *
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
18  *
19  */
20
21 #include "asset.h"
22 #include "assets.h"
23 #include "awindowgui.h"
24 #include "awindow.h"
25 #include "bcsignals.h"
26 #include "cache.h"
27 #include "clip.h"
28 #include "clipedit.h"
29 #include "commercials.h"
30 #include "convert.h"
31 #include "cplayback.h"
32 #include "ctimebar.h"
33 #include "cwindow.h"
34 #include "cwindowgui.h"
35 #include "bchash.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "filesystem.h"
39 #include "filexml.h"
40 #include "floatauto.h"
41 #include "floatautos.h"
42 #include "gwindow.h"
43 #include "gwindowgui.h"
44 #include "keyframe.h"
45 #include "keyframes.h"
46 #include "language.h"
47 #include "labels.h"
48 #include "levelwindow.h"
49 #include "localsession.h"
50 #include "mainclock.h"
51 #include "maincursor.h"
52 #include "mainerror.h"
53 #include "mainindexes.h"
54 #include "mainmenu.h"
55 #include "mainsession.h"
56 #include "mainundo.h"
57 #include "maskautos.h"
58 #include "mtimebar.h"
59 #include "mwindowgui.h"
60 #include "mwindow.h"
61 #include "panauto.h"
62 #include "patchbay.h"
63 #include "playbackengine.h"
64 #include "pluginset.h"
65 #include "recordlabel.h"
66 #include "samplescroll.h"
67 #include "trackcanvas.h"
68 #include "track.h"
69 #include "trackscroll.h"
70 #include "tracks.h"
71 #include "transition.h"
72 #include "transportque.h"
73 #include "units.h"
74 #include "undostackitem.h"
75 #include "vplayback.h"
76 #include "vwindow.h"
77 #include "vwindowgui.h"
78 #include "zoombar.h"
79 #include "zwindow.h"
80 #include "automation.h"
81 #include "maskautos.h"
82
83 #include <string.h>
84
85 void MWindow::add_audio_track_entry(int above, Track *dst)
86 {
87         undo_before();
88         Track *track = add_audio_track(above, dst);
89         track->master = 1;
90         save_backup();
91         undo_after(_("add track"), LOAD_ALL);
92
93         restart_brender();
94         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
95         gui->activate_timeline();
96         cwindow->refresh_frame(CHANGE_EDL);
97 }
98
99 void MWindow::add_video_track_entry(int above, Track *dst)
100 {
101         undo_before();
102         Track *track = add_video_track(above, dst);
103         track->master = 1;
104         undo_after(_("add track"), LOAD_ALL);
105
106         restart_brender();
107
108         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
109         gui->activate_timeline();
110         cwindow->refresh_frame(CHANGE_EDL);
111         save_backup();
112 }
113
114 void MWindow::add_subttl_track_entry(int above, Track *dst)
115 {
116         undo_before();
117         Track *track = add_subttl_track(above, dst);
118         track->master = 1;
119         undo_after(_("add track"), LOAD_ALL);
120
121         restart_brender();
122
123         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
124         gui->activate_timeline();
125         cwindow->refresh_frame(CHANGE_EDL);
126         save_backup();
127 }
128
129
130 Track *MWindow::add_audio_track(int above, Track *dst)
131 {
132         Track *track = edl->tracks->add_audio_track(above, dst);
133         edl->tracks->update_y_pixels(theme);
134         save_backup();
135         return track;
136 }
137
138 Track *MWindow::add_video_track(int above, Track *dst)
139 {
140         Track *track = edl->tracks->add_video_track(above, dst);
141         edl->tracks->update_y_pixels(theme);
142         save_backup();
143         return track;
144 }
145
146 Track *MWindow::add_subttl_track(int above, Track *dst)
147 {
148         Track *track = edl->tracks->add_subttl_track(above, dst);
149         edl->tracks->update_y_pixels(theme);
150         save_backup();
151         return track;
152 }
153
154 void MWindow::asset_to_all()
155 {
156         if( !session->drag_assets->size() ) return;
157         Indexable *indexable = session->drag_assets->get(0);
158
159 //      if( indexable->have_video() )
160         {
161                 int w, h;
162
163                 undo_before();
164
165 // Get w and h
166                 w = indexable->get_w();
167                 h = indexable->get_h();
168                 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
169                 double old_framerate = edl->session->frame_rate;
170                 int old_samplerate = edl->session->sample_rate;
171                 int new_samplerate = session->drag_assets->get(0)->get_sample_rate();
172
173
174                 if( indexable->have_video() ) {
175                         edl->session->output_w = w;
176                         edl->session->output_h = h;
177                         edl->session->frame_rate = new_framerate;
178                         create_aspect_ratio(
179                                 edl->session->aspect_w,
180                                 edl->session->aspect_h,
181                                 w, h);
182
183                         for( Track *current=edl->tracks->first; current; current=NEXT ) {
184                                 if( current->data_type == TRACK_VIDEO /* &&
185                                         current->is_armed() */  ) {
186                                         current->track_w = w;
187                                         current->track_h = h;
188                                 }
189                         }
190
191 #ifdef GLx4
192                         if( ((edl->session->output_w % 4) ||
193                                 (edl->session->output_h % 4)) &&
194                                 edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
195                                 MainError::show_error(
196                                         _("This project's dimensions are not multiples of 4 so\n"
197                                         "it can't be rendered by OpenGL."));
198                         }
199 #endif
200 // Get aspect ratio
201                         if( defaults->get("AUTOASPECT", 0) ) {
202                                 create_aspect_ratio(
203                                         edl->session->aspect_w,
204                                         edl->session->aspect_h,
205                                         w, h);
206                         }
207                 }
208
209                 if( indexable->have_audio() ) {
210                         edl->session->sample_rate = new_samplerate;
211                         edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
212                         edl->resample(old_samplerate, new_samplerate, TRACK_AUDIO);
213                 }
214
215                 save_backup();
216
217                 undo_after(_("asset to all"), LOAD_ALL);
218                 restart_brender();
219                 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
220                 sync_parameters(CHANGE_ALL);
221         }
222 }
223
224 void MWindow::asset_to_size()
225 {
226         if( !session->drag_assets->size() ) return;
227         Indexable *indexable = session->drag_assets->get(0);
228
229         if( indexable->have_video() ) {
230                 int w, h;
231                 undo_before();
232
233 // Get w and h
234                 w = indexable->get_w();
235                 h = indexable->get_h();
236                 edl->session->output_w = w;
237                 edl->session->output_h = h;
238 #ifdef GLx4
239                 if( ((edl->session->output_w % 4) ||
240                         (edl->session->output_h % 4)) &&
241                         edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL ) {
242                         MainError::show_error(
243                                 _("This project's dimensions are not multiples of 4 so\n"
244                                 "it can't be rendered by OpenGL."));
245                 }
246 #endif
247 // Get aspect ratio
248                 if( defaults->get("AUTOASPECT", 0) ) {
249                         create_aspect_ratio(edl->session->aspect_w,
250                                 edl->session->aspect_h,
251                                 w,
252                                 h);
253                 }
254
255                 save_backup();
256
257                 undo_after(_("asset to size"), LOAD_ALL);
258                 restart_brender();
259                 sync_parameters(CHANGE_ALL);
260         }
261 }
262
263
264 void MWindow::asset_to_rate()
265 {
266         if( session->drag_assets->size() &&
267                 session->drag_assets->get(0)->have_video() ) {
268                 double new_framerate = session->drag_assets->get(0)->get_frame_rate();
269                 double old_framerate = edl->session->frame_rate;
270                 undo_before();
271
272                 edl->session->frame_rate = new_framerate;
273                 edl->resample(old_framerate, new_framerate, TRACK_VIDEO);
274
275                 save_backup();
276
277                 undo_after(_("asset to rate"), LOAD_ALL);
278                 restart_brender();
279                 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
280                 sync_parameters(CHANGE_ALL);
281         }
282 }
283
284
285 void MWindow::clear_entry()
286 {
287         undo_before();
288         clear(1);
289
290         edl->optimize();
291         save_backup();
292         undo_after(_("clear"), LOAD_EDITS | LOAD_TIMEBAR);
293
294         restart_brender();
295         update_plugin_guis();
296         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
297         cwindow->update(1, 0, 0, 0, 1);
298         cwindow->refresh_frame(CHANGE_EDL);
299 }
300
301 void MWindow::clear(int clear_handle)
302 {
303         double start = edl->local_session->get_selectionstart();
304         double end = edl->local_session->get_selectionend();
305         if( clear_handle || !EQUIV(start, end) ) {
306                 edl->clear(start,
307                         end,
308                         edl->session->labels_follow_edits,
309                         edl->session->plugins_follow_edits,
310                         edl->session->autos_follow_edits);
311         }
312 }
313
314 void MWindow::update_gui(int changed_edl)
315 {
316         restart_brender();
317         update_plugin_guis();
318         if( changed_edl ) {
319                 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
320                 cwindow->update(1, 0, 0, 0, 1);
321                 cwindow->refresh_frame(CHANGE_EDL);
322         }
323         else {
324                 gui->draw_overlays(1);
325                 sync_parameters(CHANGE_PARAMS);
326                 gui->update_patchbay();
327                 cwindow->update(1, 0, 0);
328         }
329 }
330
331 void MWindow::set_automation_mode(int mode)
332 {
333         undo_before();
334         speed_before();
335         edl->tracks->set_automation_mode(
336                 edl->local_session->get_selectionstart(),
337                 edl->local_session->get_selectionend(),
338                 mode);
339         int changed_edl = speed_after(1);
340         save_backup();
341         char string[BCSTRLEN];
342         sprintf(string,"set %s", FloatAuto::curve_name(mode));
343         undo_after(string,
344                 !changed_edl ? LOAD_AUTOMATION :
345                         LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
346         update_gui(changed_edl);
347 }
348
349 void MWindow::clear_automation()
350 {
351         undo_before();
352         speed_before();
353         edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
354                 edl->local_session->get_selectionend());
355         int changed_edl = speed_after(1);
356         save_backup();
357         undo_after(_("clear keyframes"),
358                 !changed_edl ? LOAD_AUTOMATION :
359                         LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
360         update_gui(changed_edl);
361 }
362
363 int MWindow::clear_default_keyframe()
364 {
365         undo_before();
366         speed_before();
367         edl->tracks->clear_default_keyframe();
368         int changed_edl = speed_after(1);
369         save_backup();
370         undo_after(_("clear default keyframe"),
371                 !changed_edl ? LOAD_AUTOMATION :
372                         LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
373         update_gui(changed_edl);
374         return 0;
375 }
376
377 void MWindow::clear_labels()
378 {
379         undo_before();
380         clear_labels(edl->local_session->get_selectionstart(),
381                 edl->local_session->get_selectionend());
382         undo_after(_("clear labels"), LOAD_TIMEBAR);
383
384         gui->update_timebar(1);
385         cwindow->update(0, 0, 0, 0, 1);
386         save_backup();
387 }
388
389 int MWindow::clear_labels(double start, double end)
390 {
391         if( start == end ) {
392                 start = 0;
393                 end = edl->tracks->total_length();
394         }
395         edl->labels->clear(start, end, 0);
396         return 0;
397 }
398
399 void MWindow::clear_hard_edges()
400 {
401         undo_before();
402         clear_hard_edges(edl->local_session->get_selectionstart(),
403                 edl->local_session->get_selectionend());
404         edl->optimize();
405         save_backup();
406         undo_after(_("clear hard edges"), LOAD_EDITS);
407         restart_brender();
408         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
409         cwindow->refresh_frame(CHANGE_EDL);
410 }
411
412 int MWindow::clear_hard_edges(double start, double end)
413 {
414         if( start == end ) {
415                 start = 0;
416                 end = edl->tracks->total_length();
417         }
418         edl->clear_hard_edges(start, end);
419         return 0;
420 }
421
422 void MWindow::clear_select()
423 {
424         edl->tracks->clear_selected_edits();
425         gui->draw_overlays(1);
426 }
427
428 void MWindow::concatenate_tracks()
429 {
430         undo_before();
431         edl->tracks->concatenate_tracks(edl->session->plugins_follow_edits,
432                 edl->session->autos_follow_edits);
433         save_backup();
434         undo_after(_("concatenate tracks"), LOAD_EDITS);
435
436         restart_brender();
437         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
438         cwindow->refresh_frame(CHANGE_EDL);
439 }
440
441
442 int MWindow::copy_flags(int copy_flags)
443 {
444         if( !edl->session->labels_follow_edits )
445                 copy_flags &= ~COPY_LABELS;
446         if( !edl->session->autos_follow_edits )
447                 copy_flags &= ~COPY_AUTOS;
448         if( !edl->session->plugins_follow_edits )
449                 copy_flags &= ~COPY_PLUGINS;
450         return copy_flags;
451 }
452
453 void MWindow::copy()
454 {
455         copy(edl->local_session->get_selectionstart(),
456                 edl->local_session->get_selectionend());
457 }
458
459 int MWindow::copy(double start, double end)
460 {
461         if( start == end ) return 1;
462
463         FileXML file;
464         edl->copy(copy_flags(), start, end, &file, "", 1);
465         const char *file_string = file.string();
466         long file_length = strlen(file_string);
467         gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
468         gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
469         save_backup();
470         return 0;
471 }
472
473 int MWindow::copy_automation()
474 {
475         FileXML file;
476         double start = edl->local_session->get_selectionstart();
477         double end = edl->local_session->get_selectionend();
478         edl->tracks->copy_automation(start, end, &file, 0, 1);
479         const char *file_string = file.string();
480         long file_length = strlen(file_string);
481         gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
482         gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
483         return 0;
484 }
485
486 int MWindow::copy_default_keyframe()
487 {
488         FileXML file;
489         double start = edl->local_session->get_selectionstart();
490         double end = edl->local_session->get_selectionend();
491         edl->tracks->copy_automation(start, end, &file, 1, 0);
492         const char *file_string = file.string();
493         long file_length = strlen(file_string);
494         gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
495         gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
496         return 0;
497 }
498
499 // Uses cropping coordinates in edl session to crop and translate video.
500 // We modify the projector since camera automation depends on the track size.
501 void MWindow::crop_video(int mode)
502 {
503         undo_before();
504 // Clamp EDL crop region
505         if( edl->session->crop_x1 > edl->session->crop_x2 ) {
506                 edl->session->crop_x1 ^= edl->session->crop_x2;
507                 edl->session->crop_x2 ^= edl->session->crop_x1;
508                 edl->session->crop_x1 ^= edl->session->crop_x2;
509         }
510         if( edl->session->crop_y1 > edl->session->crop_y2 ) {
511                 edl->session->crop_y1 ^= edl->session->crop_y2;
512                 edl->session->crop_y2 ^= edl->session->crop_y1;
513                 edl->session->crop_y1 ^= edl->session->crop_y2;
514         }
515         switch( mode ) {
516         case CROP_REFORMAT: {
517                 float ctr_x = edl->session->output_w / 2.;
518                 float ctr_y = edl->session->output_h / 2.;
519                 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
520                 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
521                 float dx = -(new_x - ctr_x), dy = -(new_y - ctr_y);
522                 edl->tracks->translate_projector(dx, dy, 1);
523
524                 edl->session->output_w = edl->session->crop_x2 - edl->session->crop_x1;
525                 edl->session->output_h = edl->session->crop_y2 - edl->session->crop_y1;
526                 edl->session->crop_x1 = edl->session->crop_y1 = 0;
527                 edl->session->crop_x2 = edl->session->output_w;
528                 edl->session->crop_y2 = edl->session->output_h;
529                 break; }
530         case CROP_RESIZE: {
531                 float old_w = edl->session->output_w;
532                 float old_h = edl->session->output_h;
533                 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
534                 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
535                 if( !new_w ) new_w = 1;
536                 if( !new_h ) new_h = 1;
537                 float xzoom = old_w / new_w, yzoom = old_h / new_h;
538                 float new_z = bmin(xzoom, yzoom);
539                 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
540                 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
541                 edl->tracks->crop_resize(new_x, new_y, new_z);
542
543                 edl->session->crop_x1 = 0;
544                 edl->session->crop_y1 = 0;
545                 edl->session->crop_x2 = edl->session->output_w;
546                 edl->session->crop_y2 = edl->session->output_h;
547                 break; }
548         case CROP_SHRINK: {
549                 float old_w = edl->session->output_w;
550                 float old_h = edl->session->output_h;
551                 float new_w = edl->session->crop_x2 - edl->session->crop_x1;
552                 float new_h = edl->session->crop_y2 - edl->session->crop_y1;
553                 if( !new_w ) new_w = 1;
554                 if( !new_h ) new_h = 1;
555                 float xzoom = old_w / new_w, yzoom = old_h / new_h;
556                 float new_z = bmin(xzoom, yzoom);
557
558                 float new_x = (edl->session->crop_x1 + edl->session->crop_x2) / 2.;
559                 float new_y = (edl->session->crop_y1 + edl->session->crop_y2) / 2.;
560                 edl->tracks->crop_shrink(new_x, new_y, new_z);
561                 break; }
562         }
563
564 // Recalculate aspect ratio
565         if( defaults->get("AUTOASPECT", 0) ) {
566                 create_aspect_ratio(edl->session->aspect_w,
567                         edl->session->aspect_h,
568                         edl->session->output_w,
569                         edl->session->output_h);
570         }
571
572         undo_after(_("crop"), LOAD_ALL);
573
574         restart_brender();
575         cwindow->refresh_frame(CHANGE_ALL);
576         save_backup();
577 }
578
579 void MWindow::cut()
580 {
581         double start = edl->local_session->get_selectionstart();
582         double end = edl->local_session->get_selectionend();
583         if( EQUIV(start,end) )
584                 blade(start);
585         else
586                 cut(start, end);
587 }
588
589 void MWindow::blade(double position)
590 {
591         undo_before();
592         edl->blade(position);
593         edl->optimize();
594         save_backup();
595         undo_after(_("blade"), LOAD_EDITS | LOAD_TIMEBAR);
596         restart_brender();
597         update_plugin_guis();
598         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
599         cwindow->update(1, 0, 0, 0, 1);
600         awindow->gui->async_update_assets();
601         cwindow->refresh_frame(CHANGE_EDL);
602 }
603
604 void MWindow::cut(double start, double end, double new_position)
605 {
606         undo_before();
607         copy(start, end);
608         edl->clear(start, end,
609                 edl->session->labels_follow_edits,
610                 edl->session->plugins_follow_edits,
611                 edl->session->autos_follow_edits);
612
613         edl->optimize();
614         save_backup();
615         undo_after(_("split | cut"), LOAD_EDITS | LOAD_TIMEBAR);
616         if( new_position >= 0 ) {
617                 edl->local_session->set_selectionstart(new_position);
618                 edl->local_session->set_selectionend(new_position);
619         }
620         restart_brender();
621         update_plugin_guis();
622         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
623         cwindow->update(1, 0, 0, 0, 1);
624         awindow->gui->async_update_assets();
625         cwindow->refresh_frame(CHANGE_EDL);
626 }
627
628 void MWindow::cut_left_edit()
629 {
630         double start_pos = edl->local_session->get_selectionstart(1);
631         double position = edl->prev_edit(start_pos);
632         if( position < start_pos )
633                 cut(position, start_pos, position);
634 }
635
636 void MWindow::cut_right_edit()
637 {
638         double end_pos = edl->local_session->get_selectionend(1);
639         double position = edl->next_edit(end_pos);
640         if( end_pos < position )
641                 cut(end_pos, position, end_pos);
642 }
643
644 void MWindow::cut_left_label()
645 {
646         double start_pos = edl->local_session->get_selectionstart(1);
647         Label *left_label = edl->labels->prev_label(start_pos);
648         if( !left_label ) return;
649         double position = left_label->position;
650         if( position < start_pos )
651                 cut(position, start_pos, position);
652 }
653
654 void MWindow::cut_right_label()
655 {
656         double end_pos = edl->local_session->get_selectionend(1);
657         Label *right_label = edl->labels->next_label(end_pos);
658         if( !right_label ) return;
659         double position = right_label->position;
660         if( end_pos < position )
661                 cut(end_pos, position, end_pos);
662 }
663
664 int MWindow::cut_automation()
665 {
666         undo_before();
667         speed_before();
668         copy_automation();
669         edl->tracks->clear_automation(edl->local_session->get_selectionstart(),
670                 edl->local_session->get_selectionend());
671         int changed_edl = speed_after(1);
672         save_backup();
673         undo_after(_("cut keyframes"),
674                 !changed_edl ? LOAD_AUTOMATION :
675                         LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
676         update_gui(changed_edl);
677         return 0;
678 }
679
680 int MWindow::cut_default_keyframe()
681 {
682
683         undo_before();
684         speed_before();
685         copy_default_keyframe();
686         edl->tracks->clear_default_keyframe();
687         int changed_edl = speed_after(1);
688         save_backup();
689         undo_after(_("cut default keyframe"),
690                 !changed_edl ? LOAD_AUTOMATION :
691                         LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
692         update_gui(changed_edl);
693         return 0;
694 }
695
696
697 void MWindow::delete_tracks()
698 {
699         undo_before();
700         edl->tracks->delete_tracks();
701         undo_after(_("delete tracks"), LOAD_ALL);
702         save_backup();
703
704         restart_brender();
705         update_plugin_states();
706
707         gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
708         cwindow->refresh_frame(CHANGE_EDL);
709 }
710
711 void MWindow::delete_track(Track *track)
712 {
713         undo_before();
714         edl->tracks->delete_track(track);
715         undo_after(_("delete track"), LOAD_ALL);
716
717         restart_brender();
718         update_plugin_states();
719
720         gui->update(1, NORMAL_DRAW, 1, 0, 1, 0, 0);
721         cwindow->refresh_frame(CHANGE_EDL);
722         save_backup();
723 }
724
725
726 // Insert data from clipboard
727 void MWindow::insert(double position, FileXML *file,
728         int edit_labels, int edit_plugins, int edit_autos,
729         EDL *parent_edl, Track *first_track, int overwrite)
730 {
731 // For clipboard pasting make the new edl use a separate session
732 // from the master EDL.  Then it can be resampled to the master rates.
733 // For splice, overwrite, and dragging need same session to get the assets.
734         EDL *edl = new EDL(parent_edl);
735         ArrayList<EDL*> new_edls;
736         uint32_t load_flags = LOAD_ALL;
737
738
739         new_edls.append(edl);
740         edl->create_objects();
741
742
743
744
745         if( parent_edl ) load_flags &= ~LOAD_SESSION;
746         if( !edl->session->autos_follow_edits ) load_flags &= ~LOAD_AUTOMATION;
747         if( !edl->session->labels_follow_edits ) load_flags &= ~LOAD_TIMEBAR;
748
749         edl->load_xml(file, load_flags);
750
751
752 //printf("MWindow::insert %f\n", edl->local_session->clipboard_length);
753
754
755
756         paste_edls(&new_edls, LOADMODE_PASTE, first_track, position,
757                 edit_labels, edit_plugins, edit_autos, overwrite);
758 // if( vwindow->edl )
759 // printf("MWindow::insert 5 %f %f\n",
760 // vwindow->edl->local_session->in_point,
761 // vwindow->edl->local_session->out_point);
762         new_edls.remove_all();
763         edl->Garbage::remove_user();
764 //printf("MWindow::insert 6 %p\n", vwindow->get_edl());
765 }
766
767 void MWindow::insert_effects_canvas(Track *dest_track, double start, double length)
768 {
769         undo_before();
770
771         ArrayList<SharedLocation> shared_locations;
772         PluginSet *pluginset = session->pluginset_highlighted;
773         int gang = edl->session->gang_tracks != GANG_NONE ? 1 : 0;
774         int data_type = dest_track->data_type;
775         int first_track = 1;
776
777         for( Track *track=dest_track; track; track=track->next ) {
778                 if( gang && track->master && !first_track ) break;
779                 if( track->data_type != data_type ) continue;
780                 if( !track->is_armed() ) continue;
781                 int module = edl->tracks->number_of(track);
782                 for( int i=0; i<session->drag_pluginservers->total; ++i ) {
783                         PluginServer *plugin = session->drag_pluginservers->values[i];
784                         int shared = gang; // && plugin->multichannel ? 1 : 0;
785                         int plugin_type = !first_track && shared ?
786                                 PLUGIN_SHAREDPLUGIN : PLUGIN_STANDALONE;
787                         SharedLocation *shared_location = !first_track ?
788                                 &shared_locations[i] : &shared_locations.append();
789                         insert_effect(plugin->title, shared_location, track,
790                                         pluginset, start, length, plugin_type);
791                         if( first_track && shared ) {
792                                 shared_location->module = module;
793                                 shared_location->plugin = pluginset ?
794                                         track->plugin_set.number_of(pluginset) :
795                                         track->plugin_set.total-1 ;
796                         }
797                 }
798                 if( !gang ) break;
799                 first_track = 0;
800                 pluginset = 0;
801         }
802
803         save_backup();
804         undo_after(_("insert effect"), LOAD_EDITS | LOAD_PATCHES);
805         restart_brender();
806         sync_parameters(CHANGE_EDL);
807 // GUI updated in TrackCanvas, after current_operations are reset
808 }
809
810 void MWindow::insert_effects_cwindow(Track *dest_track)
811 {
812         if( !dest_track ) return;
813
814         double start = 0;
815         double length = dest_track->get_length();
816
817         if( edl->local_session->get_selectionend() >
818                 edl->local_session->get_selectionstart() ) {
819                 start = edl->local_session->get_selectionstart();
820                 length = edl->local_session->get_selectionend() -
821                         edl->local_session->get_selectionstart();
822         }
823
824         insert_effects_canvas(dest_track, start, length);
825         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
826 }
827
828 void MWindow::insert_effect(char *title, SharedLocation *shared_location,
829                 int data_type, int plugin_type, int single_standalone)
830 {
831         Track *current = edl->tracks->first;
832         SharedLocation shared_location_local;
833         shared_location_local.copy_from(shared_location);
834         int first_track = 1;
835         double start_pos = edl->local_session->get_selectionstart(1);
836         double end_pos = edl->local_session->get_selectionend(1);
837         for( ; current; current=NEXT ) {
838                 if( current->data_type != data_type ) continue;
839                 if( !current->is_armed() ) continue;
840                 double start = start_pos, end = end_pos;
841                 if( plugin_type == PLUGIN_STANDALONE && start >= end ) {
842                         start = 0;
843                         end = current->get_length();
844                 }
845                 double length = end - start;
846                 insert_effect(title, &shared_location_local,
847                                 current, 0, start, length, plugin_type);
848                 if( first_track ) {
849                         if( plugin_type == PLUGIN_STANDALONE && single_standalone ) {
850                                 plugin_type = PLUGIN_SHAREDPLUGIN;
851                                 shared_location_local.module = edl->tracks->number_of(current);
852                                 shared_location_local.plugin = current->plugin_set.total - 1;
853                                 start_pos = start;  end_pos = end;
854                         }
855                         first_track = 0;
856                 }
857         }
858 }
859
860 void MWindow::insert_effect(char *title,
861                 SharedLocation *shared_location, Track *track, PluginSet *plugin_set,
862                 double start, double length, int plugin_type)
863 {
864         KeyFrame *default_keyframe = 0;
865         PluginServer *server = 0;
866 // Get default keyframe
867         if( plugin_type == PLUGIN_STANDALONE ) {
868                 default_keyframe = new KeyFrame;
869                 server = new PluginServer(*scan_plugindb(title, track->data_type));
870
871                 server->open_plugin(0, preferences, edl, 0);
872                 server->save_data(default_keyframe);
873         }
874 // Insert plugin object
875         track->insert_effect(title, shared_location, default_keyframe,
876                         plugin_set, start, length, plugin_type);
877         track->optimize();
878
879         if( plugin_type == PLUGIN_STANDALONE ) {
880                 server->close_plugin();
881                 delete server;
882                 delete default_keyframe;
883         }
884 }
885
886 int MWindow::modify_edithandles()
887 {
888         undo_before();
889         int handle_mode = edl->session->edit_handle_mode[session->drag_button];
890         edl->modify_edithandles(session->drag_start,
891                 session->drag_position, session->drag_handle, handle_mode,
892                 edl->session->labels_follow_edits,
893                 edl->session->plugins_follow_edits,
894                 edl->session->autos_follow_edits,
895                 session->drag_edit->group_id);
896         finish_modify_handles();
897 //printf("MWindow::modify_handles 1\n");
898         return 0;
899 }
900
901 int MWindow::modify_pluginhandles()
902 {
903         undo_before();
904
905         edl->modify_pluginhandles(session->drag_start,
906                 session->drag_position,
907                 session->drag_handle,
908                 edl->session->edit_handle_mode[session->drag_button],
909                 edl->session->labels_follow_edits,
910                 edl->session->autos_follow_edits,
911                 session->trim_edits);
912
913         finish_modify_handles();
914
915         return 0;
916 }
917
918
919 // Common to edithandles and plugin handles
920 void MWindow::finish_modify_handles()
921 {
922         int edit_mode = edl->session->edit_handle_mode[session->drag_button];
923         double position = -1;
924         switch( edit_mode ) {
925         case MOVE_RIPPLE:
926                 position = !session->drag_handle ?
927                         session->drag_start : session->drag_position;
928                 break;
929         case MOVE_ROLL:
930         case MOVE_SLIDE:
931                 position = session->drag_position;
932                 break;
933         case MOVE_SLIP:
934         case MOVE_EDGE:
935                 position = session->drag_start;
936                 break;
937         }
938         if( position >= 0 ) {
939                 edl->local_session->set_selectionstart(position);
940                 edl->local_session->set_selectionend(position);
941         }
942         undo_after(_("drag handle"), LOAD_EDITS | LOAD_TIMEBAR);
943
944         save_backup();
945         restart_brender();
946         sync_parameters(CHANGE_EDL);
947         update_plugin_guis();
948         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
949 // label list can be modified
950         awindow->gui->async_update_assets();
951         cwindow->update(1, 0, 0, 0, 1);
952 }
953
954 void MWindow::match_output_size(Track *track)
955 {
956         undo_before();
957         track->track_w = edl->session->output_w;
958         track->track_h = edl->session->output_h;
959         save_backup();
960         undo_after(_("match output size"), LOAD_ALL);
961
962         restart_brender();
963         sync_parameters(CHANGE_EDL);
964 }
965
966
967 void MWindow::delete_edit(Edit *edit, const char *msg, int collapse)
968 {
969         ArrayList<Edit*> edits;
970         edits.append(edit);
971         delete_edits(&edits, msg, collapse);
972 }
973
974 void MWindow::delete_edits(ArrayList<Edit*> *edits, const char *msg, int collapse)
975 {
976         if( !edits->size() ) return;
977         undo_before();
978         if( edl->session->labels_follow_edits )
979                 edl->delete_edit_labels(edits, collapse);
980         edl->delete_edits(edits, collapse);
981         edl->optimize();
982         save_backup();
983         undo_after(msg, LOAD_EDITS);
984
985         restart_brender();
986         cwindow->refresh_frame(CHANGE_EDL);
987         update_plugin_guis();
988         gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
989 }
990
991 void MWindow::delete_edits(int collapse)
992 {
993         ArrayList<Edit*> edits;
994         edl->tracks->get_selected_edits(&edits);
995         delete_edits(&edits,_("del edit"), collapse);
996 }
997
998 // collapse - delete from timeline, not collapse replace with silence
999 // packed - omit unselected from selection, unpacked - replace unselected with silence
1000 void MWindow::cut_selected_edits(int collapse, int packed)
1001 {
1002         selected_edits_to_clipboard(packed);
1003         ArrayList<Edit*> edits;
1004         edl->tracks->get_selected_edits(&edits);
1005         delete_edits(&edits, _("cut edit"), collapse);
1006 }
1007
1008
1009 void MWindow::move_edits(ArrayList<Edit*> *edits,
1010                 Track *track, double position, int mode)
1011 {
1012         undo_before();
1013 // lockout timebar labels update
1014 //  labels can be deleted with tooltip repeater running
1015         cwindow->gui->lock_window("Tracks::move_edits");
1016         edl->tracks->move_edits(edits, track, position,
1017                 edl->session->labels_follow_edits,
1018                 edl->session->plugins_follow_edits,
1019                 edl->session->autos_follow_edits, mode);
1020         cwindow->gui->timebar->update(1);
1021         cwindow->gui->unlock_window();
1022
1023         save_backup();
1024         undo_after(_("move edit"), LOAD_ALL);
1025
1026         restart_brender();
1027         cwindow->refresh_frame(CHANGE_EDL);
1028
1029         update_plugin_guis();
1030         gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1031 }
1032
1033 void MWindow::selected_edits_to_clipboard(int packed)
1034 {
1035         EDL *new_edl = edl->selected_edits_to_clip(packed, 0, 0,
1036                 edl->session->labels_follow_edits,
1037                 edl->session->autos_follow_edits,
1038                 edl->session->plugins_follow_edits);
1039         if( !new_edl ) return;
1040         FileXML file;
1041         new_edl->copy(COPY_EDL, &file, "", 1);
1042         const char *file_string = file.string();
1043         long file_length = strlen(file_string);
1044         gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
1045         gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
1046         new_edl->remove_user();
1047 }
1048
1049 void MWindow::paste_clipboard(Track *first_track, double position, int overwrite,
1050                 int edit_edits, int edit_labels, int edit_autos, int edit_plugins)
1051 {
1052         int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1053         if( !len ) return;
1054         char *string = new char[len];
1055         gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1056         FileXML file;
1057         file.read_from_string(string);
1058         delete [] string;
1059         EDL *clip = new EDL();
1060         clip->create_objects();
1061         if( !clip->load_xml(&file, LOAD_ALL) ) {
1062                 undo_before();
1063                 edl->paste_edits(clip, first_track, position, overwrite,
1064                         edit_edits, edit_labels, edit_autos, edit_plugins);
1065                 save_backup();
1066                 undo_after(_("paste clip"), LOAD_ALL);
1067                 restart_brender();
1068                 cwindow->refresh_frame(CHANGE_EDL);
1069
1070                 update_plugin_guis();
1071                 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1072         }
1073         clip->remove_user();
1074 }
1075
1076 void MWindow::move_group(EDL *group, Track *first_track, double position, int overwrite)
1077 {
1078         undo_before();
1079 // lockout timebar labels update
1080 //  labels can be deleted with tooltip repeater running
1081         cwindow->gui->lock_window("Tracks::move_group");
1082
1083         ArrayList<Edit *>edits;
1084         edl->tracks->get_selected_edits(&edits);
1085         if( edl->session->labels_follow_edits )
1086                 edl->delete_edit_labels(&edits, 0);
1087         edl->delete_edits(&edits, 0);
1088         edl->paste_edits(group, first_track, position, overwrite, 1,
1089                 edl->session->labels_follow_edits,
1090                 edl->session->autos_follow_edits,
1091                 edl->session->plugins_follow_edits);
1092         cwindow->gui->timebar->update(1);
1093         cwindow->gui->unlock_window();
1094 // big debate over whether to do this, must either clear selected, or no tweaking
1095 //      edl->tracks->clear_selected_edits();
1096
1097         save_backup();
1098         undo_after(_("move group"), LOAD_ALL);
1099         restart_brender();
1100         cwindow->refresh_frame(CHANGE_EDL);
1101
1102         update_plugin_guis();
1103         gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
1104 }
1105
1106 void MWindow::move_effect(Plugin *plugin, Track *track, int64_t position)
1107 {
1108         undo_before();
1109         edl->tracks->move_effect(plugin, track, position);
1110         save_backup();
1111         undo_after(_("paste effect"), LOAD_ALL);
1112
1113         restart_brender();
1114         cwindow->refresh_frame(CHANGE_EDL);
1115         update_plugin_guis();
1116         gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1117 }
1118
1119 void MWindow::move_effect(Plugin *plugin, PluginSet *plugin_set, int64_t position)
1120 {
1121         undo_before();
1122         edl->tracks->move_effect(plugin, plugin_set, position);
1123         save_backup();
1124         undo_after(_("move effect"), LOAD_ALL);
1125
1126         restart_brender();
1127         cwindow->refresh_frame(CHANGE_EDL);
1128         update_plugin_guis();
1129         gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1130 }
1131
1132 void MWindow::move_plugins_up(PluginSet *plugin_set)
1133 {
1134
1135         undo_before();
1136         plugin_set->track->move_plugins_up(plugin_set);
1137
1138         save_backup();
1139         undo_after(_("move effect up"), LOAD_ALL);
1140         restart_brender();
1141         gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1142         sync_parameters(CHANGE_EDL);
1143 }
1144
1145 void MWindow::move_plugins_down(PluginSet *plugin_set)
1146 {
1147         undo_before();
1148
1149         plugin_set->track->move_plugins_down(plugin_set);
1150
1151         save_backup();
1152         undo_after(_("move effect down"), LOAD_ALL);
1153         restart_brender();
1154         gui->update(1, NORMAL_DRAW, 0, 0, 0, 0, 0);
1155         sync_parameters(CHANGE_EDL);
1156 }
1157
1158 void MWindow::move_track_down(Track *track)
1159 {
1160         undo_before();
1161         edl->tracks->move_track_down(track);
1162         save_backup();
1163         undo_after(_("move track down"), LOAD_ALL);
1164
1165         restart_brender();
1166         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1167         sync_parameters(CHANGE_EDL);
1168         save_backup();
1169 }
1170
1171 void MWindow::move_tracks_down()
1172 {
1173         undo_before();
1174         edl->tracks->move_tracks_down();
1175         save_backup();
1176         undo_after(_("move tracks down"), LOAD_ALL);
1177
1178         restart_brender();
1179         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1180         sync_parameters(CHANGE_EDL);
1181         save_backup();
1182 }
1183
1184 void MWindow::move_track_up(Track *track)
1185 {
1186         undo_before();
1187         edl->tracks->move_track_up(track);
1188         save_backup();
1189         undo_after(_("move track up"), LOAD_ALL);
1190         restart_brender();
1191         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1192         sync_parameters(CHANGE_EDL);
1193         save_backup();
1194 }
1195
1196 void MWindow::move_tracks_up()
1197 {
1198         undo_before();
1199         edl->tracks->move_tracks_up();
1200         save_backup();
1201         undo_after(_("move tracks up"), LOAD_ALL);
1202         restart_brender();
1203         gui->update(1, NORMAL_DRAW, 0, 0, 1, 0, 0);
1204         sync_parameters(CHANGE_EDL);
1205 }
1206
1207
1208 void MWindow::mute_selection()
1209 {
1210         double start = edl->local_session->get_selectionstart();
1211         double end = edl->local_session->get_selectionend();
1212         if( start != end ) {
1213                 undo_before();
1214                 edl->clear(start, end, 0,
1215                         edl->session->plugins_follow_edits,
1216                         edl->session->autos_follow_edits);
1217                 edl->local_session->set_selectionend(end);
1218                 edl->local_session->set_selectionstart(start);
1219                 edl->paste_silence(start, end, 0,
1220                         edl->session->plugins_follow_edits,
1221                         edl->session->autos_follow_edits);
1222
1223                 save_backup();
1224                 undo_after(_("mute"), LOAD_EDITS);
1225
1226                 restart_brender();
1227                 update_plugin_guis();
1228                 gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1229                 cwindow->refresh_frame(CHANGE_EDL);
1230         }
1231 }
1232
1233
1234 void MWindow::overwrite(EDL *source, int all)
1235 {
1236         FileXML file;
1237
1238         LocalSession *src = source->local_session;
1239         double src_start = all ? 0 :
1240                 src->inpoint_valid() ? src->get_inpoint() :
1241                 src->outpoint_valid() ? 0 :
1242                         src->get_selectionstart();
1243         double src_end = all ? source->tracks->total_length() :
1244                 src->outpoint_valid() ? src->get_outpoint() :
1245                 src->inpoint_valid() ? source->tracks->total_length() :
1246                         src->get_selectionend();
1247         double overwrite_len = src_end - src_start;
1248         double dst_start = edl->local_session->get_selectionstart();
1249         double dst_len = edl->local_session->get_selectionend() - dst_start;
1250
1251         undo_before();
1252         if( !EQUIV(dst_len, 0) && (dst_len < overwrite_len) ) {
1253 // in/out points or selection present and shorter than overwrite range
1254 // shorten the copy range
1255                 overwrite_len = dst_len;
1256         }
1257
1258         source->copy(copy_flags(), src_start, src_start + overwrite_len, &file, "", 1);
1259
1260 // HACK around paste_edl get_start/endselection on its own
1261 // so we need to clear only when not using both io points
1262 // FIXME: need to write simple overwrite_edl to be used for overwrite function
1263         if( edl->local_session->get_inpoint() < 0 ||
1264             edl->local_session->get_outpoint() < 0 )
1265                 edl->clear(dst_start, dst_start + overwrite_len,
1266                                 edl->session->labels_follow_edits,
1267                                 edl->session->plugins_follow_edits,
1268                                 edl->session->autos_follow_edits);
1269
1270         paste(dst_start, dst_start + overwrite_len, &file,
1271                                 edl->session->labels_follow_edits,
1272                                 edl->session->plugins_follow_edits,
1273                                 edl->session->autos_follow_edits, 0, 0);
1274
1275         edl->local_session->set_selectionstart(dst_start + overwrite_len);
1276         edl->local_session->set_selectionend(dst_start + overwrite_len);
1277
1278         save_backup();
1279         undo_after(_("overwrite"), LOAD_EDITS);
1280
1281         restart_brender();
1282         update_plugin_guis();
1283         gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
1284         sync_parameters(CHANGE_EDL);
1285 }
1286
1287 // For splice and overwrite
1288 int MWindow::paste(double start, double end, FileXML *file,
1289         int edit_labels, int edit_plugins, int edit_autos,
1290         Track *first_track, int overwrite)
1291 {
1292         clear(0);
1293
1294 // Want to insert with assets shared with the master EDL.
1295         insert(start, file,
1296                 edit_labels, edit_plugins, edit_autos,
1297                 edl, first_track, overwrite);
1298
1299         return 0;
1300 }
1301
1302 // For editing using insertion point
1303 void MWindow::paste()
1304 {
1305         paste(edl->local_session->get_selectionstart(), 0, 1, 0);
1306 }
1307
1308 void MWindow::paste(double start, Track *first_track, int clear_selection, int overwrite)
1309 {
1310         //double end = edl->local_session->get_selectionend();
1311         int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1312
1313         if( len ) {
1314                 char *string = new char[len];
1315                 undo_before();
1316                 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1317                 FileXML file;
1318                 file.read_from_string(string);
1319                 if( clear_selection ) clear(0);
1320
1321                 insert(start, &file,
1322                         edl->session->labels_follow_edits,
1323                         edl->session->plugins_follow_edits,
1324                         edl->session->autos_follow_edits,
1325                         0, first_track, overwrite);
1326
1327                 edl->optimize();
1328                 delete [] string;
1329
1330                 save_backup();
1331
1332                 undo_after(_("paste"), LOAD_EDITS | LOAD_TIMEBAR);
1333                 restart_brender();
1334                 update_plugin_guis();
1335                 gui->update(1, FORCE_REDRAW, 1, 1, 0, 1, 0);
1336                 awindow->gui->async_update_assets();
1337                 sync_parameters(CHANGE_EDL);
1338         }
1339
1340 }
1341
1342 int MWindow::paste_assets(double position, Track *dest_track, int overwrite)
1343 {
1344         int result = 0;
1345         undo_before();
1346
1347         if( session->drag_assets->total ) {
1348                 load_assets(session->drag_assets,
1349                         position, LOADMODE_PASTE, dest_track, 0,
1350                         edl->session->labels_follow_edits,
1351                         edl->session->plugins_follow_edits,
1352                         edl->session->autos_follow_edits,
1353                         overwrite);
1354                 result = 1;
1355         }
1356
1357         if( session->drag_clips->total ) {
1358                 paste_edls(session->drag_clips,
1359                         LOADMODE_PASTE, dest_track, position,
1360                         edl->session->labels_follow_edits,
1361                         edl->session->plugins_follow_edits,
1362                         edl->session->autos_follow_edits,
1363                         overwrite);
1364                 result = 1;
1365         }
1366
1367         save_backup();
1368
1369         undo_after(_("paste assets"), LOAD_EDITS);
1370         restart_brender();
1371         gui->update(1, FORCE_REDRAW, 1, 0, 0, 1, 0);
1372         sync_parameters(CHANGE_EDL);
1373         return result;
1374 }
1375
1376 void MWindow::load_assets(ArrayList<Indexable*> *new_assets,
1377         double position, int load_mode, Track *first_track, RecordLabels *labels,
1378         int edit_labels, int edit_plugins, int edit_autos, int overwrite)
1379 {
1380         if( load_mode == LOADMODE_RESOURCESONLY )
1381                 load_mode = LOADMODE_ASSETSONLY;
1382 const int debug = 0;
1383 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1384         if( position < 0 )
1385                 position = edl->local_session->get_selectionstart();
1386
1387         ArrayList<EDL*> new_edls;
1388         for( int i=0; i<new_assets->total; ++i ) {
1389                 Indexable *indexable = new_assets->get(i);
1390                 if( indexable->is_asset ) {
1391                         remove_from_caches(indexable);
1392                 }
1393                 EDL *new_edl = new EDL;
1394                 new_edl->create_objects();
1395                 new_edl->copy_session(edl);
1396                 if( !indexable->is_asset ) {
1397                         EDL *nested_edl = (EDL*)indexable;
1398                         new_edl->create_nested(nested_edl);
1399                         new_edl->set_path(indexable->path);
1400                 }
1401                 else {
1402                         Asset *asset = (Asset*)indexable;
1403                         asset_to_edl(new_edl, asset);
1404                 }
1405                 new_edls.append(new_edl);
1406
1407                 if( labels ) {
1408                         for( RecordLabel *label=labels->first; label; label=label->next ) {
1409                                 new_edl->labels->toggle_label(label->position, label->position);
1410                         }
1411                 }
1412         }
1413 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1414
1415         paste_edls(&new_edls, load_mode, first_track, position,
1416                 edit_labels, edit_plugins, edit_autos, overwrite);
1417 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1418
1419         save_backup();
1420         for( int i=0; i<new_edls.size(); ++i )
1421                 new_edls.get(i)->Garbage::remove_user();
1422
1423 if( debug ) printf("MWindow::load_assets %d\n", __LINE__);
1424 }
1425
1426 int MWindow::paste_automation()
1427 {
1428         int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1429
1430         if( len ) {
1431                 undo_before();
1432                 speed_before();
1433                 char *string = new char[len];
1434                 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1435                 FileXML file;
1436                 file.read_from_string(string);
1437                 delete [] string;
1438                 double start = edl->local_session->get_selectionstart();
1439                 double end = edl->local_session->get_selectionend();
1440                 edl->tracks->clear_automation(start, end);
1441                 edl->tracks->paste_automation(start, &file, 0, 1,
1442                         edl->session->typeless_keyframes);
1443                 int changed_edl = speed_after(1);
1444                 save_backup();
1445                 undo_after(_("paste keyframes"),
1446                         !changed_edl ? LOAD_AUTOMATION :
1447                                 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1448                 update_gui(changed_edl);
1449         }
1450
1451         return 0;
1452 }
1453
1454 int MWindow::paste_default_keyframe()
1455 {
1456         int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
1457
1458         if( len ) {
1459                 undo_before();
1460                 speed_before();
1461                 char *string = new char[len];
1462                 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
1463                 FileXML file;
1464                 file.read_from_string(string);
1465                 delete [] string;
1466                 double start = edl->local_session->get_selectionstart();
1467                 edl->tracks->paste_automation(start, &file, 1, 0,
1468                         edl->session->typeless_keyframes);
1469 //              edl->tracks->paste_default_keyframe(&file);
1470                 int changed_edl = speed_after(1);
1471                 undo_after(_("paste default keyframe"),
1472                         !changed_edl ? LOAD_AUTOMATION :
1473                                 LOAD_AUTOMATION + LOAD_EDITS + LOAD_TIMEBAR);
1474                 save_backup();
1475                 update_gui(changed_edl);
1476         }
1477
1478         return 0;
1479 }
1480
1481
1482 // Insert edls with project deletion and index file generation.
1483 int MWindow::paste_edls(ArrayList<EDL*> *new_edls, int load_mode,
1484         Track *first_track, double current_position,
1485         int edit_labels, int edit_plugins, int edit_autos,
1486         int overwrite)
1487 {
1488
1489         ArrayList<Track*> destination_tracks;
1490         int need_new_tracks = 0;
1491
1492 //PRINT_TRACE
1493         if( !new_edls->total ) return 0;
1494
1495 //PRINT_TRACE
1496 //      double original_length = edl->tracks->total_length();
1497 //      double original_preview_end = edl->local_session->preview_end;
1498 //PRINT_TRACE
1499
1500 // Delete current project
1501         if( load_mode == LOADMODE_REPLACE ||
1502             load_mode == LOADMODE_REPLACE_CONCATENATE ) {
1503                 reset_caches();
1504                 edl->save_defaults(defaults);
1505                 hide_plugins();
1506                 edl->Garbage::remove_user();
1507                 edl = new EDL;
1508                 edl->create_objects();
1509                 edl->copy_session(new_edls->values[0]);
1510                 edl->copy_mixers(new_edls->values[0]);
1511                 gui->mainmenu->update_toggles(0);
1512                 gui->unlock_window();
1513                 gwindow->gui->update_toggles(1);
1514                 gui->lock_window("MWindow::paste_edls");
1515
1516 // Insert labels for certain modes constitutively
1517                 edit_labels = 1;
1518                 edit_plugins = 1;
1519                 edit_autos = 1;
1520 // Force reset of preview
1521 //              original_length = 0;
1522 //              original_preview_end = -1;
1523         }
1524
1525
1526 //PRINT_TRACE
1527
1528 // Create new tracks in master EDL
1529         if( load_mode == LOADMODE_REPLACE ||
1530             load_mode == LOADMODE_REPLACE_CONCATENATE ||
1531             load_mode == LOADMODE_NEW_TRACKS ) {
1532
1533                 need_new_tracks = 1;
1534                 for( int i=0; i<new_edls->total; ++i ) {
1535                         EDL *new_edl = new_edls->values[i];
1536                         int first_track = 1;
1537                         for( Track *current=new_edl->tracks->first; current; current=NEXT ) {
1538                                 switch( current->data_type ) {
1539                                 case TRACK_VIDEO:
1540                                         edl->tracks->add_video_track(0, 0);
1541                                         if( current->draw ) edl->tracks->last->draw = 1;
1542                                         break;
1543                                 case TRACK_AUDIO:
1544                                         edl->tracks->add_audio_track(0, 0);
1545                                         break;
1546                                 case TRACK_SUBTITLE:
1547                                         edl->tracks->add_subttl_track(0, 0);
1548                                         break;
1549                                 default:
1550                                         continue;
1551                                 }
1552                                 if( first_track ) {
1553                                         edl->tracks->last->master = 1;
1554                                         first_track = 0;
1555                                 }
1556 // re-label only if not already labeled
1557                                 if( new_edl->local_session->asset2edl )
1558                                         strcpy(current->title, edl->tracks->last->title);
1559                                 destination_tracks.append(edl->tracks->last);
1560                         }
1561
1562 // Base track count on first EDL only for concatenation
1563                         if( load_mode == LOADMODE_REPLACE_CONCATENATE ) break;
1564                 }
1565                 edl->session->highlighted_track = edl->tracks->total() - 1;
1566         }
1567         else
1568 // Recycle existing tracks of master EDL
1569         if( load_mode == LOADMODE_CONCATENATE ||
1570             load_mode == LOADMODE_PASTE ) {
1571                 Track *current = first_track ? first_track : edl->tracks->first;
1572                 for( ; current; current=NEXT ) {
1573                         if( current->is_armed() ) {
1574                                 destination_tracks.append(current);
1575                         }
1576                 }
1577 //PRINT_TRACE
1578         }
1579 //PRINT_TRACE
1580         int destination_track = 0;
1581         double *paste_position = new double[destination_tracks.total];
1582
1583 // Iterate through the edls
1584         for( int i=0; i<new_edls->total; ++i ) {
1585
1586                 EDL *new_edl = new_edls->values[i];
1587                 double edl_length = new_edl->local_session->clipboard_length ?
1588                         new_edl->local_session->clipboard_length :
1589                         new_edl->tracks->total_length();
1590 // printf("MWindow::paste_edls 2 %f %f\n",
1591 // new_edl->local_session->clipboard_length,
1592 // new_edl->tracks->total_length());
1593 // new_edl->dump();
1594 //PRINT_TRACE
1595
1596 // Convert EDL to master rates
1597                 new_edl->resample(new_edl->session->sample_rate,
1598                         edl->session->sample_rate,
1599                         TRACK_AUDIO);
1600                 new_edl->resample(new_edl->session->frame_rate,
1601                         edl->session->frame_rate,
1602                         TRACK_VIDEO);
1603 //PRINT_TRACE
1604 // Add assets and prepare index files
1605                 for( Asset *new_asset=new_edl->assets->first;
1606                      new_asset; new_asset=new_asset->next ) {
1607                         mainindexes->add_indexable(new_asset);
1608                 }
1609 // Capture index file status from mainindex test
1610                 edl->update_assets(new_edl);
1611 //PRINT_TRACE
1612 // Get starting point of insertion.  Need this to paste labels.
1613                 switch( load_mode ) {
1614                 case LOADMODE_NOTHING:
1615                         continue;
1616                 case LOADMODE_REPLACE:
1617                         current_position = 0;
1618                         break;
1619                 case LOADMODE_NEW_TRACKS:
1620                         if( !overwrite )
1621                                 current_position = 0;
1622                         break;
1623
1624                 case LOADMODE_CONCATENATE:
1625                 case LOADMODE_REPLACE_CONCATENATE:
1626                         destination_track = 0;
1627                         if( destination_tracks.total )
1628                                 current_position = destination_tracks.values[0]->get_length();
1629                         else
1630                                 current_position = 0;
1631                         break;
1632
1633                 case LOADMODE_PASTE:
1634                         destination_track = 0;
1635                         if( i == 0 ) {
1636                                 for( int j=0; j<destination_tracks.total; ++j ) {
1637                                         paste_position[j] = (current_position >= 0) ?
1638                                                 current_position :
1639                                                 edl->local_session->get_selectionstart();
1640                                 }
1641                         }
1642                         break;
1643
1644                 case LOADMODE_RESOURCESONLY:
1645                         edl->add_clip(new_edl);
1646                         break;
1647                 }
1648 // Insert edl
1649                 if( load_mode != LOADMODE_RESOURCESONLY &&
1650                     load_mode != LOADMODE_ASSETSONLY ) {
1651 // Insert labels
1652                         if( edit_labels ) {
1653                                 if( load_mode == LOADMODE_PASTE )
1654                                         edl->labels->insert_labels(new_edl->labels,
1655                                                 destination_tracks.total ? paste_position[0] : 0.0,
1656                                                 edl_length, 1);
1657                                 else
1658                                         edl->labels->insert_labels(new_edl->labels, current_position,
1659                                                 edl_length, 1);
1660                         }
1661                         double total_length = new_edl->tracks->total_length();
1662                         for( Track *new_track=new_edl->tracks->first;
1663                              new_track; new_track=new_track->next ) {
1664 // Get destination track of same type as new_track
1665                                 for( int k = 0;
1666                                      k < destination_tracks.total &&
1667                                      destination_tracks.values[destination_track]->data_type != new_track->data_type;
1668                                      ++k, ++destination_track ) {
1669                                         if( destination_track >= destination_tracks.total - 1 )
1670                                                 destination_track = 0;
1671                                 }
1672
1673 // Insert data into destination track
1674                                 if( destination_track < destination_tracks.total &&
1675                                     destination_tracks.values[destination_track]->data_type == new_track->data_type ) {
1676                                         Track *track = destination_tracks.values[destination_track];
1677 // Replace default keyframes if first EDL and new tracks were created.
1678 // This means data copied from one track and pasted to another won't retain
1679 // the camera position unless it's a keyframe.  If it did, previous data in the
1680 // track might get unknowingly corrupted.  Ideally we would detect when differing
1681 // default keyframes existed and create discrete keyframes for both.
1682                                         int replace_default = (i == 0) && need_new_tracks;
1683 // master tracks are the first track in each new edl when new tracks are created
1684                                         int master = track->master;
1685 //printf("MWindow::paste_edls 1 %d\n", replace_default);
1686 // Insert new track at current position
1687                                         switch( load_mode ) {
1688                                         case LOADMODE_REPLACE_CONCATENATE:
1689                                         case LOADMODE_CONCATENATE:
1690                                                 current_position = track->get_length();
1691                                                 break;
1692
1693                                         case LOADMODE_PASTE:
1694                                                 current_position = paste_position[destination_track];
1695                                                 paste_position[destination_track] += new_track->get_length();
1696                                                 break;
1697                                         }
1698                                         if( overwrite ) {
1699                                                 double length = overwrite >= 0 ?
1700                                                         new_track->get_length() : total_length;
1701                                                 track->clear(current_position,
1702                                                         current_position + length,
1703                                                         1, // edit edits
1704                                                         edit_labels, edit_plugins, edit_autos,
1705                                                         0); // trim edits
1706                                         }
1707 //PRINT_TRACE
1708                                         track->insert_track(new_track, current_position, replace_default,
1709                                                 edit_plugins, edit_autos, edl_length);
1710                                         if( master ) track->master = 1;
1711 //PRINT_TRACE
1712                                 }
1713
1714 // Get next destination track
1715                                 destination_track++;
1716                                 if( destination_track >= destination_tracks.total )
1717                                         destination_track = 0;
1718                         }
1719                 }
1720
1721                 if( load_mode == LOADMODE_PASTE )
1722                         current_position += edl_length;
1723         }
1724
1725
1726 // Move loading of clips and vwindow to the end - this fixes some
1727 // strange issue, for index not being shown
1728 // Assume any paste operation from the same EDL won't contain any clips.
1729 // If it did it would duplicate every clip here.
1730         for( int i=0; i<new_edls->total; ++i ) {
1731                 EDL *new_edl = new_edls->get(i);
1732
1733                 for( int j=0; j<new_edl->clips.size(); ++j ) {
1734                         edl->add_clip(new_edl->clips[j]);
1735                 }
1736                 for( int j=0; j<new_edl->nested_edls.size(); ++j ) {
1737                         edl->nested_edls.get_nested(new_edl->nested_edls[j]);
1738                 }
1739
1740                 if( new_edl->total_vwindow_edls() ) {
1741 //                      if( edl->vwindow_edl )
1742 //                              edl->vwindow_edl->Garbage::remove_user();
1743 //                      edl->vwindow_edl = new EDL(edl);
1744 //                      edl->vwindow_edl->create_objects();
1745 //                      edl->vwindow_edl->copy_all(new_edl->vwindow_edl);
1746
1747                         for( int j=0; j<new_edl->total_vwindow_edls(); ++j ) {
1748                                 EDL *vwindow_edl = new EDL(edl);
1749                                 vwindow_edl->create_objects();
1750                                 vwindow_edl->copy_all(new_edl->get_vwindow_edl(j));
1751                                 edl->append_vwindow_edl(vwindow_edl, 0);
1752                         }
1753                 }
1754         }
1755
1756         if( paste_position ) delete [] paste_position;
1757
1758 // This is already done in load_filenames and everything else that uses paste_edls
1759 //      update_project(load_mode);
1760
1761 // Fix preview range
1762 //      if( EQUIV(original_length, original_preview_end) )
1763 //      {
1764 //              edl->local_session->preview_end = edl->tracks->total_length();
1765 //      }
1766
1767 // Start examining next batch of index files
1768         mainindexes->start_build();
1769
1770 // Don't save a backup after loading since the loaded file is on disk already.
1771 //PRINT_TRACE
1772         return 0;
1773 }
1774
1775 void MWindow::paste_silence()
1776 {
1777         double start = edl->local_session->get_selectionstart();
1778         double end = edl->local_session->get_selectionend();
1779         if( EQUIV(start, end) ) {
1780                 if( edl->session->frame_rate > 0 )
1781                         end += 1./edl->session->frame_rate;
1782         }
1783         undo_before(_("silence"), this);
1784         edl->paste_silence(start, end,
1785                 edl->session->labels_follow_edits,
1786                 edl->session->plugins_follow_edits,
1787                 edl->session->autos_follow_edits);
1788         edl->optimize();
1789         save_backup();
1790         undo_after(_("silence"), LOAD_EDITS | LOAD_TIMEBAR);
1791
1792         update_plugin_guis();
1793         restart_brender();
1794         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
1795         cwindow->update(1, 0, 0, 0, 1);
1796         cwindow->refresh_frame(CHANGE_EDL);
1797 }
1798
1799 void MWindow::detach_transition(Transition *transition)
1800 {
1801         undo_before();
1802         hide_plugin(transition, 1);
1803         int is_video = (transition->edit->track->data_type == TRACK_VIDEO);
1804         transition->edit->detach_transition();
1805         save_backup();
1806         undo_after(_("detach transition"), LOAD_ALL);
1807
1808         if( is_video ) restart_brender();
1809         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1810         sync_parameters(CHANGE_EDL);
1811 }
1812
1813 void MWindow::detach_transitions()
1814 {
1815         gui->lock_window("MWindow::detach_transitions 1");
1816
1817         undo_before();
1818         double start = edl->local_session->get_selectionstart();
1819         double end = edl->local_session->get_selectionend();
1820         edl->tracks->clear_transitions(start, end);
1821
1822         save_backup();
1823         undo_after(_("detach transitions"), LOAD_EDITS);
1824
1825         sync_parameters(CHANGE_EDL);
1826         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1827         gui->unlock_window();
1828 }
1829
1830 void MWindow::paste_transition()
1831 {
1832 // Only the first transition gets dropped.
1833         PluginServer *server = session->drag_pluginservers->values[0];
1834
1835         undo_before();
1836         edl->tracks->paste_transition(server, session->edit_highlighted);
1837         save_backup();
1838         undo_after(_("transition"), LOAD_EDITS);
1839
1840         if( server->video ) restart_brender();
1841         sync_parameters(CHANGE_ALL);
1842 }
1843
1844 void MWindow::paste_transitions(int track_type, char *title)
1845 {
1846         gui->lock_window("MWindow::detach_transitions 1");
1847
1848         undo_before();
1849         double start = edl->local_session->get_selectionstart();
1850         double end = edl->local_session->get_selectionend();
1851         edl->tracks->paste_transitions(start, end, track_type, title);
1852         save_backup();
1853         undo_after(_("attach transitions"), LOAD_EDITS);
1854
1855         sync_parameters(CHANGE_EDL);
1856         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1857         gui->unlock_window();
1858 }
1859
1860 void MWindow::paste_transition_cwindow(Track *dest_track)
1861 {
1862         PluginServer *server = session->drag_pluginservers->values[0];
1863         undo_before();
1864         edl->tracks->paste_video_transition(server, 1);
1865         save_backup();
1866         undo_after(_("transition"), LOAD_EDITS);
1867         restart_brender();
1868         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1869         sync_parameters(CHANGE_ALL);
1870 }
1871
1872 void MWindow::paste_audio_transition()
1873 {
1874         PluginServer *server = scan_plugindb(edl->session->default_atransition,
1875                 TRACK_AUDIO);
1876         if( !server ) {
1877                 char string[BCTEXTLEN];
1878                 sprintf(string, _("No default transition %s found."), edl->session->default_atransition);
1879                 gui->show_message(string);
1880                 return;
1881         }
1882
1883         undo_before();
1884         edl->tracks->paste_audio_transition(server);
1885         save_backup();
1886         undo_after(_("transition"), LOAD_EDITS);
1887
1888         sync_parameters(CHANGE_EDL);
1889         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1890 }
1891
1892 void MWindow::paste_video_transition()
1893 {
1894         PluginServer *server = scan_plugindb(edl->session->default_vtransition,
1895                 TRACK_VIDEO);
1896         if( !server ) {
1897                 char string[BCTEXTLEN];
1898                 sprintf(string, _("No default transition %s found."), edl->session->default_vtransition);
1899                 gui->show_message(string);
1900                 return;
1901         }
1902
1903         undo_before();
1904
1905         edl->tracks->paste_video_transition(server);
1906         save_backup();
1907         undo_after(_("transition"), LOAD_EDITS);
1908
1909         sync_parameters(CHANGE_EDL);
1910         restart_brender();
1911         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
1912 }
1913
1914 void MWindow::shuffle_edits()
1915 {
1916         gui->lock_window("MWindow::shuffle_edits 1");
1917
1918         undo_before();
1919         double start = edl->local_session->get_selectionstart();
1920         double end = edl->local_session->get_selectionend();
1921
1922         edl->tracks->shuffle_edits(start, end);
1923
1924         save_backup();
1925         undo_after(_("shuffle edits"), LOAD_EDITS | LOAD_TIMEBAR);
1926
1927         sync_parameters(CHANGE_EDL);
1928         restart_brender();
1929         gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1930         gui->unlock_window();
1931 }
1932
1933 void MWindow::reverse_edits()
1934 {
1935         gui->lock_window("MWindow::reverse_edits 1");
1936
1937         undo_before();
1938         double start = edl->local_session->get_selectionstart();
1939         double end = edl->local_session->get_selectionend();
1940
1941         edl->tracks->reverse_edits(start, end);
1942
1943         save_backup();
1944         undo_after(_("reverse edits"), LOAD_EDITS | LOAD_TIMEBAR);
1945
1946         sync_parameters(CHANGE_EDL);
1947         restart_brender();
1948         gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1949         gui->unlock_window();
1950 }
1951
1952 void MWindow::align_edits()
1953 {
1954         gui->lock_window("MWindow::align_edits 1");
1955
1956         undo_before();
1957         double start = edl->local_session->get_selectionstart();
1958         double end = edl->local_session->get_selectionend();
1959
1960         edl->tracks->align_edits(start, end);
1961
1962         save_backup();
1963         undo_after(_("align edits"), LOAD_EDITS | LOAD_TIMEBAR);
1964
1965         sync_parameters(CHANGE_EDL);
1966         restart_brender();
1967         gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1968         gui->unlock_window();
1969 }
1970
1971 void MWindow::set_edit_length(double length)
1972 {
1973         gui->lock_window("MWindow::set_edit_length 1");
1974
1975         undo_before();
1976         double start = edl->local_session->get_selectionstart();
1977         double end = edl->local_session->get_selectionend();
1978
1979         edl->tracks->set_edit_length(start, end, length);
1980
1981         save_backup();
1982         undo_after(_("edit length"), LOAD_EDITS | LOAD_TIMEBAR);
1983
1984         sync_parameters(CHANGE_EDL);
1985         restart_brender();
1986         gui->update(0, NORMAL_DRAW, 1, 0, 0, 0, 0);
1987         gui->unlock_window();
1988 }
1989
1990
1991 void MWindow::set_transition_length(Transition *transition, double length)
1992 {
1993         gui->lock_window("MWindow::set_transition_length 1");
1994
1995         undo_before();
1996         //double start = edl->local_session->get_selectionstart();
1997         //double end = edl->local_session->get_selectionend();
1998
1999         edl->tracks->set_transition_length(transition, length);
2000
2001         save_backup();
2002         undo_after(_("transition length"), LOAD_EDITS);
2003
2004         edl->session->default_transition_length = length;
2005         sync_parameters(CHANGE_PARAMS);
2006         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2007         gui->unlock_window();
2008 }
2009
2010 void MWindow::set_transition_length(double length)
2011 {
2012         gui->lock_window("MWindow::set_transition_length 2");
2013
2014         undo_before();
2015         double start = edl->local_session->get_selectionstart();
2016         double end = edl->local_session->get_selectionend();
2017
2018         edl->tracks->set_transition_length(start, end, length);
2019
2020         save_backup();
2021         undo_after(_("transition length"), LOAD_EDITS);
2022
2023         edl->session->default_transition_length = length;
2024         sync_parameters(CHANGE_PARAMS);
2025         restart_brender();
2026         gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
2027         gui->unlock_window();
2028 }
2029
2030
2031 void MWindow::redo_entry(BC_WindowBase *calling_window_gui)
2032 {
2033         calling_window_gui->unlock_window();
2034         stop_playback(0);
2035         if( undo->redo_load_flags() & LOAD_SESSION )
2036                 close_mixers();
2037
2038         cwindow->gui->lock_window("MWindow::redo_entry 1");
2039         for( int i=0; i<vwindows.size(); ++i ) {
2040                 if( vwindows.get(i)->is_running() ) {
2041                         if( calling_window_gui != vwindows.get(i)->gui ) {
2042                                 vwindows.get(i)->gui->lock_window("MWindow::redo_entry 2");
2043                         }
2044                 }
2045         }
2046         gui->lock_window("MWindow::redo_entry 3");
2047
2048         undo->redo();
2049
2050         save_backup();
2051         restart_brender();
2052         update_plugin_states();
2053         update_plugin_guis();
2054
2055         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2056         gui->update_proxy_toggle();
2057         gui->unlock_window();
2058         cwindow->gui->unlock_window();
2059         cwindow->update(1, 1, 1, 1, 1);
2060
2061         for( int i=0; i < vwindows.size(); ++i ) {
2062                 if( vwindows.get(i)->is_running() ) {
2063                         if( calling_window_gui != vwindows.get(i)->gui ) {
2064                                 vwindows.get(i)->gui->unlock_window();
2065                         }
2066                 }
2067         }
2068
2069         awindow->gui->async_update_assets();
2070
2071         cwindow->refresh_frame(CHANGE_ALL);
2072         calling_window_gui->lock_window("MWindow::redo_entry 4");
2073 }
2074
2075
2076 void MWindow::resize_track(Track *track, int w, int h)
2077 {
2078         undo_before();
2079 // We have to move all maskpoints so they do not move in relation to image areas
2080         ((MaskAutos*)track->automation->autos[AUTOMATION_MASK])->translate_masks(
2081                 (w - track->track_w) / 2,
2082                 (h - track->track_h) / 2);
2083         track->track_w = w;
2084         track->track_h = h;
2085         undo_after(_("resize track"), LOAD_ALL);
2086         save_backup();
2087
2088         restart_brender();
2089         sync_parameters(CHANGE_EDL);
2090 }
2091
2092
2093 void MWindow::set_inpoint()
2094 {
2095         undo_before();
2096         edl->set_inpoint(edl->local_session->get_selectionstart(1));
2097         save_backup();
2098         undo_after(_("in point"), LOAD_TIMEBAR);
2099         gui->update_timebar(1);
2100
2101         cwindow->gui->lock_window("MWindow::set_inpoint 2");
2102         cwindow->gui->timebar->update(1);
2103         cwindow->gui->unlock_window();
2104 }
2105
2106 void MWindow::set_outpoint()
2107 {
2108         undo_before();
2109         edl->set_outpoint(edl->local_session->get_selectionend(1));
2110         save_backup();
2111         undo_after(_("out point"), LOAD_TIMEBAR);
2112
2113         gui->update_timebar(1);
2114         cwindow->gui->lock_window("MWindow::set_outpoint 2");
2115         cwindow->gui->timebar->update(1);
2116         cwindow->gui->unlock_window();
2117 }
2118
2119 void MWindow::unset_inoutpoint()
2120 {
2121         undo_before();
2122         edl->unset_inoutpoint();
2123         save_backup();
2124         undo_after(_("clear in/out"), LOAD_TIMEBAR);
2125
2126         gui->update_timebar(1);
2127         cwindow->gui->lock_window("MWindow::unset_inoutpoint 2");
2128         cwindow->gui->timebar->update(1);
2129         cwindow->gui->unlock_window();
2130 }
2131
2132 void MWindow::splice(EDL *source, int all)
2133 {
2134         FileXML file;
2135         LocalSession *src = source->local_session;
2136
2137         undo_before();
2138         double source_start = all ? 0 :
2139                 src->inpoint_valid() ? src->get_inpoint() :
2140                 src->outpoint_valid() ? 0 : src->get_selectionstart();
2141         double source_end = all ? source->tracks->total_length() :
2142                 src->outpoint_valid() ? src->get_outpoint() :
2143                 src->inpoint_valid() ? source->tracks->total_length() :
2144                         src->get_selectionend();
2145         source->copy(COPY_EDL, source_start, source_end, &file, "", 1);
2146 //file.dump();
2147         double start = edl->local_session->get_selectionstart();
2148         //double end = edl->local_session->get_selectionend();
2149
2150         paste(start, start, &file,
2151                 edl->session->labels_follow_edits,
2152                 edl->session->plugins_follow_edits,
2153                 edl->session->autos_follow_edits,
2154                 0, 0);
2155
2156 // Position at end of clip
2157         edl->local_session->set_selectionstart(start + source_end - source_start);
2158         edl->local_session->set_selectionend(start + source_end - source_start);
2159
2160         save_backup();
2161         undo_after(_("splice"), LOAD_EDITS | LOAD_TIMEBAR);
2162         update_plugin_guis();
2163         restart_brender();
2164         gui->update(1, NORMAL_DRAW, 1, 1, 0, 1, 0);
2165         sync_parameters(CHANGE_EDL);
2166 }
2167
2168 void MWindow::save_clip(EDL *new_edl, const char *txt)
2169 {
2170         new_edl->local_session->set_selectionstart(0);
2171         new_edl->local_session->set_selectionend(0);
2172         sprintf(new_edl->local_session->clip_title, _("Clip %d"),
2173                 session->clip_number++);
2174         char duration[BCTEXTLEN];
2175         Units::totext(duration, new_edl->tracks->total_length(),
2176                 new_edl->session->time_format,
2177                 new_edl->session->sample_rate,
2178                 new_edl->session->frame_rate,
2179                 new_edl->session->frames_per_foot);
2180
2181         Track *track = new_edl->tracks->first;
2182         const char *path = edl->path;
2183         for( ; (!path || !*path) && track; track=track->next ) {
2184                 if( !track->is_armed() ) continue;
2185                 Edit *edit = track->edits->first;
2186                 if( !edit ) continue;
2187                 Indexable *indexable = edit->get_source();
2188                 if( !indexable ) continue;
2189                 path = indexable->path;
2190         }
2191
2192         time_t now;  time(&now);
2193         struct tm dtm;   localtime_r(&now, &dtm);
2194         char *cp = new_edl->local_session->clip_notes;
2195         char *ep = cp + sizeof(new_edl->local_session->clip_notes)-1;
2196         if( txt && *txt )
2197                 cp += snprintf(cp, ep-cp, "%s", txt);
2198         cp += snprintf(cp, ep-cp,
2199                 "%02d/%02d/%02d %02d:%02d:%02d,  +%s\n",
2200                 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2201                 dtm.tm_hour, dtm.tm_min, dtm.tm_sec, duration);
2202         if( path && *path ) {
2203                 FileSystem fs;
2204                 char title[BCTEXTLEN];
2205                 fs.extract_name(title, path);
2206                 cp += snprintf(cp, ep-cp, "%s", title);
2207         }
2208         sprintf(new_edl->local_session->clip_icon,
2209                 "clip_%02d%02d%02d-%02d%02d%02d-%d.png",
2210                 dtm.tm_year+1900, dtm.tm_mon+1, dtm.tm_mday,
2211                 dtm.tm_hour, dtm.tm_min, dtm.tm_sec,
2212                 new_edl->id);
2213         new_edl->folder_no = AW_CLIP_FOLDER;
2214         edl->update_assets(new_edl);
2215         int cur_x, cur_y;
2216         gui->get_abs_cursor(cur_x, cur_y, 0);
2217         gui->unlock_window();
2218
2219         awindow->clip_edit->create_clip(new_edl, cur_x, cur_y);
2220         new_edl->remove_user();
2221
2222         gui->lock_window("MWindow::save_clip");
2223         save_backup();
2224 }
2225
2226 void MWindow::to_clip(EDL *edl, const char *txt, int all)
2227 {
2228         FileXML file;
2229         LocalSession *src = edl->local_session;
2230
2231         gui->lock_window("MWindow::to_clip 1");
2232         double start = all ? 0 :
2233                 src->inpoint_valid() ? src->get_inpoint() :
2234                 src->outpoint_valid() ? 0 : src->get_selectionstart();
2235         double end = all ? edl->tracks->total_length() :
2236                 src->outpoint_valid() ? src->get_outpoint() :
2237                 src->inpoint_valid() ? edl->tracks->total_length() :
2238                         src->get_selectionend();
2239         if( EQUIV(end, start) ) {
2240                 start = 0;
2241                 end = edl->tracks->total_length();
2242         }
2243
2244 // Don't copy all since we don't want the clips twice.
2245         edl->copy(copy_flags(), start, end, &file, "", 1);
2246
2247         EDL *new_edl = new EDL(edl);
2248         new_edl->create_objects();
2249         new_edl->load_xml(&file, LOAD_ALL);
2250         save_clip(new_edl, txt);
2251         gui->unlock_window();
2252 }
2253
2254 int MWindow::toggle_label()
2255 {
2256         double position1, position2;
2257         undo_before();
2258
2259         position1 = edl->local_session->get_selectionstart(1);
2260         position2 = edl->local_session->get_selectionend(1);
2261         position1 = edl->align_to_frame(position1, 0);
2262         position2 = edl->align_to_frame(position2, 0);
2263
2264         edl->labels->toggle_label(position1, position2);
2265         save_backup();
2266
2267         gui->update_timebar(0);
2268         gui->activate_timeline();
2269         gui->flush();
2270
2271         cwindow->gui->lock_window("MWindow::toggle_label 2");
2272         cwindow->gui->timebar->update(1);
2273         cwindow->gui->unlock_window();
2274         awindow->gui->async_update_assets();
2275
2276         undo_after(_("label"), LOAD_TIMEBAR);
2277         return 0;
2278 }
2279
2280 void MWindow::trim_selection()
2281 {
2282         undo_before();
2283
2284
2285         edl->trim_selection(edl->local_session->get_selectionstart(),
2286                 edl->local_session->get_selectionend(),
2287                 edl->session->labels_follow_edits,
2288                 edl->session->plugins_follow_edits,
2289                 edl->session->autos_follow_edits);
2290
2291         save_backup();
2292         undo_after(_("trim selection"), LOAD_EDITS | LOAD_TIMEBAR);
2293         update_plugin_guis();
2294         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2295         cwindow->update(1, 0, 0, 0, 1);
2296         awindow->gui->async_update_assets();
2297         restart_brender();
2298         cwindow->refresh_frame(CHANGE_EDL);
2299 }
2300
2301
2302 void MWindow::undo_entry(BC_WindowBase *calling_window_gui)
2303 {
2304         calling_window_gui->unlock_window();
2305         stop_playback(0);
2306         if( undo->undo_load_flags() & LOAD_SESSION )
2307                 close_mixers();
2308
2309         cwindow->gui->lock_window("MWindow::undo_entry 1");
2310         for( int i=0; i<vwindows.size(); ++i ) {
2311                 if( vwindows.get(i)->is_running() ) {
2312                         if( calling_window_gui != vwindows.get(i)->gui ) {
2313                                 vwindows.get(i)->gui->lock_window("MWindow::undo_entry 4");
2314                         }
2315                 }
2316         }
2317         gui->lock_window("MWindow::undo_entry 2");
2318
2319         undo->undo();
2320
2321         save_backup();
2322         restart_brender();
2323         update_plugin_states();
2324         update_plugin_guis();
2325
2326         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 1);
2327         gui->update_proxy_toggle();
2328         gui->unlock_window();
2329         cwindow->gui->unlock_window();
2330         cwindow->update(1, 1, 1, 1, 1);
2331
2332         for( int i=0; i<vwindows.size(); ++i ) {
2333                 if( vwindows.get(i)->is_running() ) {
2334                         if( calling_window_gui != vwindows.get(i)->gui ) {
2335                                 vwindows.get(i)->gui->unlock_window();
2336                         }
2337                 }
2338         }
2339
2340         awindow->gui->async_update_assets();
2341
2342         cwindow->refresh_frame(CHANGE_ALL);
2343         calling_window_gui->lock_window("MWindow::undo_entry 4");
2344 }
2345
2346
2347 void MWindow::new_folder(const char *new_folder, int is_clips)
2348 {
2349         undo_before();
2350         if( edl->new_folder(new_folder, is_clips) ) {
2351                 MainError::show_error(_("create new folder failed"));
2352         }
2353         undo_after(_("new folder"), LOAD_ALL);
2354         awindow->gui->async_update_assets();
2355 }
2356
2357 void MWindow::delete_folder(char *folder)
2358 {
2359         undo_before();
2360         if( edl->delete_folder(folder) < 0 ) {
2361                 MainError::show_error(_("delete folder failed"));
2362         }
2363         undo_after(_("del folder"), LOAD_ALL);
2364         awindow->gui->async_update_assets();
2365 }
2366
2367 void MWindow::select_point(double position)
2368 {
2369         gui->unlock_window();
2370         gui->stop_drawing();
2371         cwindow->stop_playback(0);
2372         gui->lock_window("MWindow::select_point");
2373
2374         edl->local_session->set_selectionstart(position);
2375         edl->local_session->set_selectionend(position);
2376
2377 // Que the CWindow
2378         cwindow->update(1, 0, 0, 0, 1);
2379
2380         update_plugin_guis();
2381         gui->update_patchbay();
2382         gui->hide_cursor(0);
2383         gui->draw_cursor(0);
2384         gui->mainclock->update(edl->local_session->get_selectionstart(1));
2385         gui->zoombar->update();
2386         gui->update_timebar(0);
2387         gui->flash_canvas(0);
2388         gui->flush();
2389 }
2390
2391
2392
2393
2394 void MWindow::map_audio(int pattern)
2395 {
2396         undo_before();
2397         remap_audio(pattern);
2398         undo_after(
2399                 pattern == MWindow::AUDIO_1_TO_1 ? _("map 1:1") : _("map 5.1:2"),
2400                 LOAD_AUTOMATION);
2401         sync_parameters(CHANGE_PARAMS);
2402         gui->update(0, NORMAL_DRAW, 0, 0, 1, 0, 0);
2403 }
2404
2405 void MWindow::remap_audio(int pattern)
2406 {
2407         int current_channel = 0;
2408         int current_track = 0;
2409         for( Track *current=edl->tracks->first; current; current=NEXT ) {
2410                 if( current->data_type == TRACK_AUDIO &&
2411                         current->is_armed() ) {
2412                         Autos *pan_autos = current->automation->autos[AUTOMATION_PAN];
2413                         PanAuto *pan_auto = (PanAuto*)pan_autos->get_auto_for_editing(-1);
2414
2415                         for( int i=0; i < MAXCHANNELS; ++i ) {
2416                                 pan_auto->values[i] = 0.0;
2417                         }
2418
2419                         if( pattern == MWindow::AUDIO_1_TO_1 ) {
2420                                 pan_auto->values[current_channel] = 1.0;
2421                         }
2422                         else
2423                         if( pattern == MWindow::AUDIO_5_1_TO_2 ) {
2424                                 switch( current_track ) {
2425                                 case 0:
2426                                 case 4:
2427                                         pan_auto->values[0] = 1;
2428                                         break;
2429                                 case 1:
2430                                 case 5:
2431                                         pan_auto->values[1] = 1;
2432                                         break;
2433                                 case 2:
2434                                 case 3:
2435                                         pan_auto->values[0] = 0.5;
2436                                         pan_auto->values[1] = 0.5;
2437                                         break;
2438                                 }
2439                         }
2440
2441                         BC_Pan::calculate_stick_position(edl->session->audio_channels,
2442                                 edl->session->achannel_positions, pan_auto->values,
2443                                 MAX_PAN, PAN_RADIUS, pan_auto->handle_x, pan_auto->handle_y);
2444
2445                         current_channel++;
2446                         current_track++;
2447                         if( current_channel >= edl->session->audio_channels )
2448                                 current_channel = 0;
2449                 }
2450         }
2451 }
2452
2453
2454 void MWindow::rescale_proxy(EDL *clip, int orig_scale, int new_scale)
2455 {
2456         edl->rescale_proxy(orig_scale, new_scale);
2457 }
2458
2459 void MWindow::add_proxy(ArrayList<Indexable*> *orig_assets, ArrayList<Indexable*> *proxy_assets)
2460 {
2461         edl->add_proxy(orig_assets, proxy_assets);
2462 }
2463
2464 void MWindow::start_convert(Asset *format_asset, const char *suffix,
2465                 float beep, int to_proxy, int remove_originals)
2466 {
2467         if( !convert_render )
2468                 convert_render = new ConvertRender(this);
2469         convert_render->set_format(format_asset, suffix, to_proxy);
2470         int found = convert_render->find_convertable_assets(edl);
2471         if( convert_render->needed_idxbls.size() > 0 )
2472                 convert_render->start_convert(beep, remove_originals);
2473         else if( found > 0 )
2474                 finish_convert(remove_originals);
2475         else if( found < 0 )
2476                 eprintf(_("convert assets format error"));
2477         else
2478                 eprintf(_("No convertable assets found"));
2479 }
2480
2481 void MWindow::finish_convert(int remove_originals)
2482 {
2483         gui->lock_window("MWindow::finish_convert");
2484         undo_before();
2485         edl->replace_assets(
2486                 convert_render->orig_idxbls,
2487                 convert_render->orig_copies);
2488         if( remove_originals ) {
2489                 remove_assets_from_project(0, 0, 0,
2490                         &convert_render->orig_idxbls, 0);
2491         }
2492         save_backup();
2493         undo_after(_("convert"), LOAD_ALL);
2494
2495         update_plugin_guis();
2496         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2497         cwindow->update(1, 0, 0, 0, 1);
2498         awindow->gui->async_update_assets();
2499         cwindow->refresh_frame(CHANGE_EDL);
2500         gui->unlock_window();
2501 }
2502
2503 void MWindow::cut_commercials()
2504 {
2505 #ifdef HAVE_COMMERCIAL
2506         undo_before();
2507         commercials->scan_media();
2508         edl->optimize();
2509         save_backup();
2510         undo_after(_("cut ads"), LOAD_EDITS | LOAD_TIMEBAR);
2511
2512         restart_brender();
2513         update_plugin_guis();
2514         gui->update(1, FORCE_REDRAW, 1, 1, 1, 1, 0);
2515         cwindow->update(1, 0, 0, 0, 1);
2516         cwindow->refresh_frame(CHANGE_EDL);
2517 #endif
2518 }
2519
2520 int MWindow::normalize_speed(EDL *old_edl, EDL *new_edl)
2521 {
2522         int result = 0;
2523         Track *old_track = old_edl->tracks->first;
2524         Track *new_track = new_edl->tracks->first;
2525         for( ; old_track && new_track; old_track=old_track->next, new_track=new_track->next ) {
2526                 if( old_track->data_type != new_track->data_type ) continue;
2527                 FloatAutos *old_speeds = (FloatAutos *)old_track->automation->autos[AUTOMATION_SPEED];
2528                 FloatAutos *new_speeds = (FloatAutos *)new_track->automation->autos[AUTOMATION_SPEED];
2529                 if( !old_speeds || !new_speeds ) continue;
2530                 FloatAuto *old_speed = (FloatAuto *)old_speeds->first;
2531                 FloatAuto *new_speed = (FloatAuto *)new_speeds->first;
2532                 while( old_speed && new_speed && old_speed->equals(new_speed) ) {
2533                         old_speed = (FloatAuto *)old_speed->next;
2534                         new_speed = (FloatAuto *)new_speed->next;
2535                 }
2536                 Edit *old_edit = old_track->edits->first;
2537                 Edit *new_edit = new_track->edits->first;
2538                 for( ; old_edit && new_edit; old_edit=old_edit->next, new_edit=new_edit->next ) {
2539                         int64_t edit_start = old_edit->startproject, edit_end = edit_start + old_edit->length;
2540                         if( old_speed || new_speed ) {
2541                                 double orig_start = old_speeds->automation_integral(0, edit_start, PLAY_FORWARD);
2542                                 double orig_end   = old_speeds->automation_integral(0, edit_end, PLAY_FORWARD);
2543                                 edit_start = new_speeds->speed_position(orig_start);
2544                                 edit_end = new_speeds->speed_position(orig_end);
2545                                 result = 1;
2546                         }
2547                         new_edit->startproject = edit_start;
2548                         new_edit->length = edit_end - edit_start;
2549                 }
2550         }
2551         return result;
2552 }
2553
2554 void MWindow::speed_before()
2555 {
2556         if( !speed_edl ) {
2557                 speed_edl = new EDL;
2558                 speed_edl->create_objects();
2559         }
2560         speed_edl->copy_all(edl);
2561 }
2562
2563 int MWindow::speed_after(int done)
2564 {
2565         int result = 0;
2566         if( speed_edl ) {
2567                 if( done >= 0 )
2568                         result = normalize_speed(speed_edl, edl);
2569                 if( done != 0 ) {
2570                         speed_edl->remove_user();
2571                         speed_edl = 0;
2572                 }
2573         }
2574         return result;
2575 }
2576
2577 void MWindow::collect_effects()
2578 {
2579         FileXML file;
2580         const char *file_string = "";
2581         EDL *group = 0;
2582         int ret = edl->collect_effects(group);
2583         switch( ret ) {
2584         case COLLECT_EFFECTS_RECORD:
2585                 eprintf(_("Selected edit track not armed."));
2586                 break;
2587         case COLLECT_EFFECTS_MULTIPLE:
2588                 eprintf(_("More than one edit selected on a track."));
2589                 break;
2590         case COLLECT_EFFECTS_MISSING:
2591                 eprintf(_("No effects under selected edit."));
2592                 break;
2593         case COLLECT_EFFECTS_EMPTY:
2594                 eprintf(_("No edits selected."));
2595                 break;
2596         case COLLECT_EFFECTS_MASTER:
2597                 eprintf(_("Shared effect added without master."));
2598                 break;
2599         case 0:
2600                 group->save_xml(&file, "");
2601                 file_string = file.string();
2602                 group->remove_user();
2603         }
2604         long file_length = strlen(file_string);
2605         gui->to_clipboard(file_string, file_length, BC_PRIMARY_SELECTION);
2606         gui->to_clipboard(file_string, file_length, SECONDARY_SELECTION);
2607 }
2608
2609 void MWindow::paste_effects()
2610 {
2611         char *string = 0;
2612         int64_t len = gui->clipboard_len(BC_PRIMARY_SELECTION);
2613         if( len ) {
2614                 string = new char[len];
2615                 gui->from_clipboard(string, len, BC_PRIMARY_SELECTION);
2616         }
2617         if( !string || !string[0] ) {
2618                 eprintf(_("Error clipboard buffer empty."));
2619                 return;
2620         }
2621         FileXML file;
2622         file.read_from_string(string);
2623         EDL *group = new EDL();
2624         group->create_objects();
2625         if( !group->load_xml(&file, LOAD_ALL) ) {
2626                 undo_before();
2627                 int ret = edl->insert_effects(group);
2628                 switch( ret ) {
2629                 case INSERT_EFFECTS_RECORD:
2630                         eprintf(_("Selected edit track not armed."));
2631                         break;
2632                 case INSERT_EFFECTS_TYPE:
2633                         eprintf(_("Track type mismatched."));
2634                         break;
2635                 case INSERT_EFFECTS_MULTIPLE:
2636                         eprintf(_("More than one edit selected on a track."));
2637                         break;
2638                 case INSERT_EFFECTS_MISSING:
2639                         eprintf(_("Too few target edits to add group effects."));
2640                         break;
2641                 case INSERT_EFFECTS_EXTRA:
2642                         eprintf(_("Too many target edits to add group effects."));
2643                         break;
2644                 case INSERT_EFFECTS_MASTER:
2645                         eprintf(_("Shared effect added without master."));
2646                         break;
2647                 case 0:
2648                         break;
2649                 }
2650                 save_backup();
2651                 undo_after(_("paste effects"), LOAD_ALL);
2652                 restart_brender();
2653                 cwindow->refresh_frame(CHANGE_EDL);
2654                 update_plugin_guis();
2655                 gui->update(1, NORMAL_DRAW, 1, 0, 0, 0, 0);
2656         }
2657         else
2658                 eprintf(_("Error loading clip from clipboard buffer."));
2659         delete [] string;
2660         group->remove_user();
2661 }
2662