39e7ef0c680c9e28c0d42a2f1c8e935786f90199
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mainmenu.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "assets.h"
23 #include "auto.h"
24 #include "batchrender.h"
25 #include "bcdisplayinfo.h"
26 #include "bchash.h"
27 #include "bcsignals.h"
28 #include "bdcreate.h"
29 #include "cache.h"
30 #include "channelinfo.h"
31 #include "convert.h"
32 #include "cplayback.h"
33 #include "cropvideo.h"
34 #include "cwindow.h"
35 #include "cwindowgui.h"
36 #include "dbwindow.h"
37 #include "dvdcreate.h"
38 #include "edl.h"
39 #include "edlsession.h"
40 #include "file.h"
41 #include "filesystem.h"
42 #include "filexml.h"
43 #include "floatauto.h"
44 #include "keys.h"
45 #include "language.h"
46 #include "levelwindow.h"
47 #include "loadfile.h"
48 #include "localsession.h"
49 #include "mainclock.h"
50 #include "mainmenu.h"
51 #include "mainsession.h"
52 #include "mainundo.h"
53 #include "menuattacheffect.h"
54 #include "menuattachtransition.h"
55 #include "menuaeffects.h"
56 #include "menueditlength.h"
57 #include "menutransitionlength.h"
58 #include "menuveffects.h"
59 #include "mixersalign.h"
60 #include "mwindowgui.h"
61 #include "mwindow.h"
62 #include "new.h"
63 #include "patchbay.h"
64 #include "playbackengine.h"
65 #include "preferences.h"
66 #include "proxy.h"
67 #include "preferencesthread.h"
68 #include "quit.h"
69 #include "record.h"
70 #include "render.h"
71 #include "savefile.h"
72 #include "setformat.h"
73 #include "swindow.h"
74 #include "timebar.h"
75 #include "trackcanvas.h"
76 #include "tracks.h"
77 #include "transition.h"
78 #include "transportque.h"
79 #include "viewmenu.h"
80 #include "zoombar.h"
81 #include "exportedl.h"
82
83 #include <string.h>
84
85
86 MainMenu::MainMenu(MWindow *mwindow, MWindowGUI *gui, int w)
87  : BC_MenuBar(0, 0, w)
88 {
89         this->gui = gui;
90         this->mwindow = mwindow;
91 }
92
93 MainMenu::~MainMenu()
94 {
95 }
96
97 void MainMenu::create_objects()
98 {
99         BC_Menu *viewmenu, *windowmenu, *settingsmenu, *trackmenu;
100         PreferencesMenuitem *preferences;
101
102         add_menu(filemenu = new BC_Menu(_("File")));
103         filemenu->add_item(new_project = new NewProject(mwindow));
104         new_project->create_objects();
105
106 // file loaders
107         filemenu->add_item(load_file = new Load(mwindow, this));
108         load_file->create_objects();
109         filemenu->add_item(load_recent = new LoadRecent(mwindow, this));
110         load_recent->create_objects();
111
112 // new and load can be undone so no need to prompt save
113         Save *save;                   //  affected by saveas
114         filemenu->add_item(save = new Save(mwindow));
115         SaveAs *saveas;
116         filemenu->add_item(saveas = new SaveAs(mwindow));
117         save->create_objects(saveas);
118         saveas->set_mainmenu(this);
119         SaveProject *save_project;
120         filemenu->add_item(save_project = new SaveProject(mwindow));
121
122         filemenu->add_item(record_menu_item = new RecordMenuItem(mwindow));
123 #ifdef HAVE_DVB
124         filemenu->add_item(new ChannelScan(mwindow));
125 #endif
126 #ifdef HAVE_COMMERCIAL
127         if( mwindow->has_commercials() )
128                 filemenu->add_item(new DbWindowScan(mwindow));
129 #endif
130         filemenu->add_item(new SubttlSWin(mwindow));
131
132         filemenu->add_item(render = new RenderItem(mwindow));
133         filemenu->add_item(new ExportEDLItem(mwindow));
134         filemenu->add_item(new BatchRenderMenuItem(mwindow));
135         filemenu->add_item(new CreateBD_MenuItem(mwindow));
136         filemenu->add_item(new CreateDVD_MenuItem(mwindow));
137         filemenu->add_item(new BC_MenuItem("-"));
138         filemenu->add_item(quit_program = new Quit(mwindow));
139         quit_program->create_objects(save);
140         filemenu->add_item(dump_menu = new MainDumpsMenu(mwindow));
141         dump_menu->create_objects();
142         filemenu->add_item(new LoadBackup(mwindow));
143         filemenu->add_item(new SaveBackup(mwindow));
144
145         BC_Menu *editmenu;
146         add_menu(editmenu = new BC_Menu(_("Edit")));
147         editmenu->add_item(undo = new Undo(mwindow));
148         editmenu->add_item(redo = new Redo(mwindow));
149         editmenu->add_item(new BC_MenuItem("-"));
150         editmenu->add_item(new Cut(mwindow));
151         editmenu->add_item(new Copy(mwindow));
152         editmenu->add_item(new Paste(mwindow));
153         editmenu->add_item(new PasteSilence(mwindow));
154         editmenu->add_item(clear_menu = new EditClearMenu(mwindow));
155         clear_menu->create_objects();
156         editmenu->add_item(new TrimSelection(mwindow));
157         editmenu->add_item(new SelectAll(mwindow));
158         editmenu->add_item(new BC_MenuItem("-"));
159         editmenu->add_item(new MenuEditShuffle(mwindow));
160         editmenu->add_item(new MenuEditReverse(mwindow));
161         editmenu->add_item(new MenuEditLength(mwindow));
162         editmenu->add_item(new MenuEditAlign(mwindow));
163         editmenu->add_item(new MenuTransitionLength(mwindow));
164         editmenu->add_item(new DetachTransitions(mwindow));
165         editmenu->add_item(new BC_MenuItem("-"));
166         editmenu->add_item(new CutCommercials(mwindow));
167         editmenu->add_item(new PasteSubttl(mwindow));
168
169         BC_Menu *keyframemenu;
170         add_menu(keyframemenu = new BC_Menu(_("Keyframes")));
171         keyframemenu->add_item(new CutKeyframes(mwindow));
172         keyframemenu->add_item(new CopyKeyframes(mwindow));
173         keyframemenu->add_item(new PasteKeyframes(mwindow));
174         keyframemenu->add_item(new ClearKeyframes(mwindow));
175         keyframemenu->add_item(new StraightenKeyframes(mwindow));
176         keyframemenu->add_item(new BendKeyframes(mwindow));
177         keyframemenu->add_item(keyframe_curve_type = new KeyframeCurveType(mwindow));
178         keyframe_curve_type->create_objects();
179         keyframe_curve_type->update(mwindow->edl->local_session->floatauto_type);
180         keyframemenu->add_item(new BC_MenuItem("-"));
181         keyframemenu->add_item(new CopyDefaultKeyframe(mwindow));
182         keyframemenu->add_item(new PasteDefaultKeyframe(mwindow));
183
184
185
186
187         add_menu(audiomenu = new BC_Menu(_("Audio")));
188         audiomenu->add_item(new AddAudioTrack(mwindow));
189         audiomenu->add_item(new DefaultATransition(mwindow));
190         audiomenu->add_item(new MapAudio1(mwindow));
191         audiomenu->add_item(new MapAudio2(mwindow));
192         audiomenu->add_item(new MenuAttachTransition(mwindow, TRACK_AUDIO));
193         audiomenu->add_item(new MenuAttachEffect(mwindow, TRACK_AUDIO));
194         audiomenu->add_item(aeffects = new MenuAEffects(mwindow));
195
196         add_menu(videomenu = new BC_Menu(_("Video")));
197         videomenu->add_item(new AddVideoTrack(mwindow));
198         videomenu->add_item(new DefaultVTransition(mwindow));
199         videomenu->add_item(new MenuAttachTransition(mwindow, TRACK_VIDEO));
200         videomenu->add_item(new MenuAttachEffect(mwindow, TRACK_VIDEO));
201         videomenu->add_item(veffects = new MenuVEffects(mwindow));
202
203         add_menu(trackmenu = new BC_Menu(_("Tracks")));
204         trackmenu->add_item(new MoveTracksUp(mwindow));
205         trackmenu->add_item(new MoveTracksDown(mwindow));
206         trackmenu->add_item(new DeleteTracks(mwindow));
207         trackmenu->add_item(new DeleteFirstTrack(mwindow));
208         trackmenu->add_item(new DeleteLastTrack(mwindow));
209         trackmenu->add_item(new ConcatenateTracks(mwindow));
210         AppendTracks *append_tracks;
211         trackmenu->add_item(append_tracks = new AppendTracks(mwindow));
212         append_tracks->create_objects();
213         trackmenu->add_item(new AddSubttlTrack(mwindow));
214
215         add_menu(settingsmenu = new BC_Menu(_("Settings")));
216
217         settingsmenu->add_item(new SetFormat(mwindow));
218         settingsmenu->add_item(preferences = new PreferencesMenuitem(mwindow));
219         ProxyMenuItem *proxy;
220         settingsmenu->add_item(proxy = new ProxyMenuItem(mwindow));
221         proxy->create_objects();
222         ConvertMenuItem *convert;
223         settingsmenu->add_item(convert = new ConvertMenuItem(mwindow));
224         convert->create_objects();
225         mwindow->preferences_thread = preferences->thread;
226         settingsmenu->add_item(cursor_on_frames = new CursorOnFrames(mwindow));
227         settingsmenu->add_item(labels_follow_edits = new LabelsFollowEdits(mwindow));
228         settingsmenu->add_item(plugins_follow_edits = new PluginsFollowEdits(mwindow));
229         settingsmenu->add_item(keyframes_follow_edits = new KeyframesFollowEdits(mwindow));
230         settingsmenu->add_item(typeless_keyframes = new TypelessKeyframes(mwindow));
231         settingsmenu->add_item(new BC_MenuItem("-"));
232         settingsmenu->add_item(new SaveSettingsNow(mwindow));
233         settingsmenu->add_item(loop_playback = new LoopPlayback(mwindow));
234         settingsmenu->add_item(brender_active = new SetBRenderActive(mwindow));
235 // set scrubbing speed
236 //      ScrubSpeed *scrub_speed;
237 //      settingsmenu->add_item(scrub_speed = new ScrubSpeed(mwindow));
238 //      if(mwindow->edl->session->scrub_speed == .5)
239 //              scrub_speed->set_text(_("Fast Shuttle"));
240
241
242
243
244
245
246         add_menu(viewmenu = new BC_Menu(_("View")));
247         viewmenu->add_item(show_assets = new ShowAssets(mwindow, "0"));
248         viewmenu->add_item(show_titles = new ShowTitles(mwindow, "1"));
249         viewmenu->add_item(show_transitions = new ShowTransitions(mwindow, "2"));
250         viewmenu->add_item(fade_automation = new ShowAutomation(mwindow, _("Fade"), "3", AUTOMATION_FADE));
251         viewmenu->add_item(mute_automation = new ShowAutomation(mwindow, _("Mute"), "4", AUTOMATION_MUTE));
252         viewmenu->add_item(mode_automation = new ShowAutomation(mwindow, _("Overlay mode"), "5", AUTOMATION_MODE));
253         viewmenu->add_item(pan_automation = new ShowAutomation(mwindow, _("Pan"), "6", AUTOMATION_PAN));
254         viewmenu->add_item(plugin_automation = new PluginAutomation(mwindow, "7"));
255         viewmenu->add_item(mask_automation = new ShowAutomation(mwindow, _("Mask"), "8", AUTOMATION_MASK));
256         viewmenu->add_item(speed_automation = new ShowAutomation(mwindow, _("Speed"), "9", AUTOMATION_SPEED));
257
258         camera_x = new ShowAutomation(mwindow, _("Camera X"), "Ctrl-Shift-X", AUTOMATION_CAMERA_X);
259         camera_x->set_ctrl();  camera_x->set_shift();   viewmenu->add_item(camera_x);
260         camera_y = new ShowAutomation(mwindow, _("Camera Y"), "Ctrl-Shift-Y", AUTOMATION_CAMERA_Y);
261         camera_y->set_ctrl();  camera_y->set_shift();   viewmenu->add_item(camera_y);
262         camera_z = new ShowAutomation(mwindow, _("Camera Z"), "Ctrl-Shift-Z", AUTOMATION_CAMERA_Z);
263         camera_z->set_ctrl();  camera_z->set_shift();  viewmenu->add_item(camera_z);
264         project_x = new ShowAutomation(mwindow, _("Projector X"), "Alt-Shift-X", AUTOMATION_PROJECTOR_X);
265         project_x->set_alt();  project_x->set_shift();  viewmenu->add_item(project_x);
266         project_y = new ShowAutomation(mwindow, _("Projector Y"), "Alt-Shift-Y", AUTOMATION_PROJECTOR_Y);
267         project_y->set_alt();  project_y->set_shift();  viewmenu->add_item(project_y);
268         project_z = new ShowAutomation(mwindow, _("Projector Z"), "Alt-Shift-Z", AUTOMATION_PROJECTOR_Z);
269         project_z->set_alt();  project_z->set_shift();  viewmenu->add_item(project_z);
270
271         add_menu(windowmenu = new BC_Menu(_("Window")));
272         windowmenu->add_item(show_vwindow = new ShowVWindow(mwindow));
273         windowmenu->add_item(show_awindow = new ShowAWindow(mwindow));
274         windowmenu->add_item(show_cwindow = new ShowCWindow(mwindow));
275         windowmenu->add_item(show_gwindow = new ShowGWindow(mwindow));
276         windowmenu->add_item(show_lwindow = new ShowLWindow(mwindow));
277         windowmenu->add_item(new BC_MenuItem("-"));
278         windowmenu->add_item(split_x = new SplitX(mwindow));
279         windowmenu->add_item(split_y = new SplitY(mwindow));
280         windowmenu->add_item(mixer_items = new MixerItems(mwindow));
281         mixer_items->create_objects();
282         windowmenu->add_item(new TileWindows(mwindow,_("Tile left"),0));
283         windowmenu->add_item(new TileWindows(mwindow,_("Tile right"),1));
284         windowmenu->add_item(new BC_MenuItem("-"));
285
286         windowmenu->add_item(new TileWindows(mwindow,_("Default positions"),-1,_("Ctrl-P"),'p'));
287         windowmenu->add_item(load_layout = new LoadLayout(mwindow, _("Load layout..."),LAYOUT_LOAD));
288         load_layout->create_objects();
289         windowmenu->add_item(save_layout = new LoadLayout(mwindow, _("Save layout..."),LAYOUT_SAVE));
290         save_layout->create_objects();
291 }
292
293 int MainMenu::load_defaults(BC_Hash *defaults)
294 {
295         init_loads(defaults);
296         init_aeffects(defaults);
297         init_veffects(defaults);
298         return 0;
299 }
300
301 void MainMenu::update_toggles(int use_lock)
302 {
303         if(use_lock) lock_window("MainMenu::update_toggles");
304         labels_follow_edits->set_checked(mwindow->edl->session->labels_follow_edits);
305         plugins_follow_edits->set_checked(mwindow->edl->session->plugins_follow_edits);
306         keyframes_follow_edits->set_checked(mwindow->edl->session->autos_follow_edits);
307         typeless_keyframes->set_checked(mwindow->edl->session->typeless_keyframes);
308         cursor_on_frames->set_checked(mwindow->edl->session->cursor_on_frames);
309         loop_playback->set_checked(mwindow->edl->local_session->loop_playback);
310
311         show_assets->set_checked(mwindow->edl->session->show_assets);
312         show_titles->set_checked(mwindow->edl->session->show_titles);
313         show_transitions->set_checked(mwindow->edl->session->auto_conf->transitions);
314         fade_automation->update_toggle();
315         mute_automation->update_toggle();
316         pan_automation->update_toggle();
317         camera_x->update_toggle();
318         camera_y->update_toggle();
319         camera_z->update_toggle();
320         project_x->update_toggle();
321         project_y->update_toggle();
322         project_z->update_toggle();
323         plugin_automation->set_checked(mwindow->edl->session->auto_conf->plugins);
324         mode_automation->update_toggle();
325         mask_automation->update_toggle();
326         speed_automation->update_toggle();
327         split_x->set_checked(mwindow->gui->pane[TOP_RIGHT_PANE] != 0);
328         split_y->set_checked(mwindow->gui->pane[BOTTOM_LEFT_PANE] != 0);
329
330         if(use_lock) mwindow->gui->unlock_window();
331 }
332
333 int MainMenu::save_defaults(BC_Hash *defaults)
334 {
335         save_loads(defaults);
336         save_aeffects(defaults);
337         save_veffects(defaults);
338         return 0;
339 }
340
341
342
343
344
345 int MainMenu::quit()
346 {
347         quit_program->handle_event();
348         return 0;
349 }
350
351
352
353
354
355 // ================================== load most recent
356
357 int MainMenu::init_aeffects(BC_Hash *defaults)
358 {
359         total_aeffects = defaults->get((char*)"TOTAL_AEFFECTS", 0);
360
361         char string[BCTEXTLEN], title[BCTEXTLEN];
362         if(total_aeffects) audiomenu->add_item(new BC_MenuItem("-"));
363
364         for(int i = 0; i < total_aeffects; i++)
365         {
366                 sprintf(string, "AEFFECTRECENT%d", i);
367                 defaults->get(string, title);
368                 audiomenu->add_item(aeffect[i] = new MenuAEffectItem(aeffects, title));
369         }
370         return 0;
371 }
372
373 int MainMenu::init_veffects(BC_Hash *defaults)
374 {
375         total_veffects = defaults->get((char*)"TOTAL_VEFFECTS", 0);
376
377         char string[BCTEXTLEN], title[BCTEXTLEN];
378         if(total_veffects) videomenu->add_item(new BC_MenuItem("-"));
379
380         for(int i = 0; i < total_veffects; i++)
381         {
382                 sprintf(string, "VEFFECTRECENT%d", i);
383                 defaults->get(string, title);
384                 videomenu->add_item(veffect[i] = new MenuVEffectItem(veffects, title));
385         }
386         return 0;
387 }
388
389 void MainMenu::init_loads(BC_Hash *defaults)
390 {
391 // total_loads for legacy xml
392         int total_loads = defaults->get((char*)"TOTAL_LOADS", 0);
393         int loads_total = defaults->get((char*)"LOADS_TOTAL", 0);
394         if( loads_total < total_loads ) loads_total = total_loads;
395
396         char string[BCTEXTLEN], path[BCTEXTLEN];
397         FileSystem dir;
398 //printf("MainMenu::init_loads 2\n");
399
400         for( int i=0; i<loads_total; ++i ) {
401                 sprintf(string, "LOADPREVIOUS%d", i);
402 //printf("MainMenu::init_loads 3\n");
403                 defaults->get(string, path);
404                 if( load.size() < TOTAL_LOADS )
405                         load.append(new LoadRecentItem(path));
406         }
407 }
408
409 // ============================ save most recent
410
411 int MainMenu::save_aeffects(BC_Hash *defaults)
412 {
413         defaults->update((char*)"TOTAL_AEFFECTS", total_aeffects);
414         char string[BCTEXTLEN];
415         for(int i = 0; i < total_aeffects; i++)
416         {
417                 sprintf(string, "AEFFECTRECENT%d", i);
418                 defaults->update(string, aeffect[i]->get_text());
419         }
420         return 0;
421 }
422
423 int MainMenu::save_veffects(BC_Hash *defaults)
424 {
425         defaults->update((char*)"TOTAL_VEFFECTS", total_veffects);
426         char string[BCTEXTLEN];
427         for(int i = 0; i < total_veffects; i++)
428         {
429                 sprintf(string, "VEFFECTRECENT%d", i);
430                 defaults->update(string, veffect[i]->get_text());
431         }
432         return 0;
433 }
434
435 int MainMenu::save_loads(BC_Hash *defaults)
436 {
437 // legacy to prevent segv, older code cant tolerate total_loads>10
438         int loads_total = load.size();
439         int total_loads = MIN(10, loads_total);
440         defaults->update((char*)"LOADS_TOTAL", loads_total);
441         defaults->update((char*)"TOTAL_LOADS", total_loads);
442         char string[BCTEXTLEN];
443         for( int i=0; i<loads_total; ++i ) {
444                 sprintf(string, "LOADPREVIOUS%d", i);
445                 defaults->update(string, load[i]->path);
446         }
447         return 0;
448 }
449
450 // =================================== add most recent
451
452 int MainMenu::add_aeffect(char *title)
453 {
454 // add bar for first effect
455         if(total_aeffects == 0)
456         {
457                 audiomenu->add_item(new BC_MenuItem("-"));
458         }
459
460 // test for existing copy of effect
461         for(int i = 0; i < total_aeffects; i++)
462         {
463                 if(!strcmp(aeffect[i]->get_text(), title))     // already exists
464                 {                                // swap for top effect
465                         for(int j = i; j > 0; j--)   // move preceeding effects down
466                         {
467                                 aeffect[j]->set_text(aeffect[j - 1]->get_text());
468                         }
469                         aeffect[0]->set_text(title);
470                         return 1;
471                 }
472         }
473
474 // add another blank effect
475         if(total_aeffects < TOTAL_EFFECTS)
476         {
477                 audiomenu->add_item(
478                         aeffect[total_aeffects] = new MenuAEffectItem(aeffects, (char*)""));
479                 total_aeffects++;
480         }
481
482 // cycle effect down
483         for(int i = total_aeffects - 1; i > 0; i--)
484         {
485         // set menu item text
486                 aeffect[i]->set_text(aeffect[i - 1]->get_text());
487         }
488
489 // set up the new effect
490         aeffect[0]->set_text(title);
491         return 0;
492 }
493
494 int MainMenu::add_veffect(char *title)
495 {
496 // add bar for first effect
497         if(total_veffects == 0)
498         {
499                 videomenu->add_item(new BC_MenuItem("-"));
500         }
501
502 // test for existing copy of effect
503         for(int i = 0; i < total_veffects; i++)
504         {
505                 if(!strcmp(veffect[i]->get_text(), title))     // already exists
506                 {                                // swap for top effect
507                         for(int j = i; j > 0; j--)   // move preceeding effects down
508                         {
509                                 veffect[j]->set_text(veffect[j - 1]->get_text());
510                         }
511                         veffect[0]->set_text(title);
512                         return 1;
513                 }
514         }
515
516 // add another blank effect
517         if(total_veffects < TOTAL_EFFECTS)
518         {
519                 videomenu->add_item(veffect[total_veffects] =
520                         new MenuVEffectItem(veffects, (char*)""));
521                 total_veffects++;
522         }
523
524 // cycle effect down
525         for(int i = total_veffects - 1; i > 0; i--)
526         {
527 // set menu item text
528                 veffect[i]->set_text(veffect[i - 1]->get_text());
529         }
530
531 // set up the new effect
532         veffect[0]->set_text(title);
533         return 0;
534 }
535
536 int MainMenu::add_load(char *path)
537 {
538         return load.add_load(path);
539 }
540
541
542
543 // ================================== menu items
544
545 MainDumpsSubMenu::MainDumpsSubMenu(BC_MenuItem *menu_item)
546  : BC_SubMenu()
547 {
548         this->menu_item = menu_item;
549 }
550 MainDumpsSubMenu::~MainDumpsSubMenu()
551 {
552 }
553
554
555 MainDumpsMenu::MainDumpsMenu(MWindow *mwindow)
556  : BC_MenuItem(_("Dumps..."))
557 {
558         this->mwindow = mwindow;
559         this->dumps_menu = 0;
560 }
561 MainDumpsMenu::~MainDumpsMenu()
562 {
563 }
564
565 void MainDumpsMenu::create_objects()
566 {
567         add_submenu(dumps_menu = new MainDumpsSubMenu(this));
568 //      dumps_menu->add_item(new DumpCICache(mwindow));
569         dumps_menu->add_item(new DumpEDL(mwindow));
570         dumps_menu->add_item(new DumpPlugins(mwindow));
571         dumps_menu->add_item(new DumpAssets(mwindow));
572         dumps_menu->add_item(new DumpUndo(mwindow));
573 };
574
575
576 DumpCICache::DumpCICache(MWindow *mwindow)
577  : BC_MenuItem(_("Dump CICache"))
578 { this->mwindow = mwindow; }
579
580 int DumpCICache::handle_event()
581 {
582 //      mwindow->cache->dump();
583         return 1;
584 }
585
586 DumpEDL::DumpEDL(MWindow *mwindow)
587  : BC_MenuItem(_("Dump EDL"))
588 {
589         this->mwindow = mwindow;
590 }
591
592 int DumpEDL::handle_event()
593 {
594         mwindow->dump_edl();
595         return 1;
596 }
597
598 DumpPlugins::DumpPlugins(MWindow *mwindow)
599  : BC_MenuItem(_("Dump Plugins"))
600 {
601         this->mwindow = mwindow;
602 }
603
604 int DumpPlugins::handle_event()
605 {
606         mwindow->dump_plugins();
607         return 1;
608 }
609
610 DumpAssets::DumpAssets(MWindow *mwindow)
611  : BC_MenuItem(_("Dump Assets"))
612 { this->mwindow = mwindow; }
613
614 int DumpAssets::handle_event()
615 {
616         mwindow->edl->assets->dump();
617         return 1;
618 }
619
620 DumpUndo::DumpUndo(MWindow *mwindow)
621  : BC_MenuItem(_("Dump Undo"))
622 {
623         this->mwindow = mwindow;
624 }
625
626 int DumpUndo::handle_event()
627 {
628         mwindow->dump_undo();
629         return 1;
630 }
631
632 // ================================================= edit
633
634 Undo::Undo(MWindow *mwindow) : BC_MenuItem(_("Undo"), "z", 'z')
635 {
636         this->mwindow = mwindow;
637 }
638 int Undo::handle_event()
639 {
640         if( mwindow->session->current_operation == NO_OPERATION )
641                 mwindow->undo_entry(mwindow->gui);
642         return 1;
643 }
644 int Undo::update_caption(const char *new_caption)
645 {
646         char string[BCTEXTLEN];
647         sprintf(string, _("Undo %s"), new_caption);
648         set_text(string);
649         return 0;
650 }
651
652
653 Redo::Redo(MWindow *mwindow) : BC_MenuItem(_("Redo"), _("Shift-Z"), 'Z')
654 {
655         set_shift(1);
656         this->mwindow = mwindow;
657 }
658
659 int Redo::handle_event()
660 {
661         if( mwindow->session->current_operation == NO_OPERATION )
662                 mwindow->redo_entry(mwindow->gui);
663         return 1;
664 }
665 int Redo::update_caption(const char *new_caption)
666 {
667         char string[BCTEXTLEN];
668         sprintf(string, _("Redo %s"), new_caption);
669         set_text(string);
670         return 0;
671 }
672
673 CutKeyframes::CutKeyframes(MWindow *mwindow)
674  : BC_MenuItem(_("Cut keyframes"), _("Shift-X"), 'X')
675 {
676         set_shift();
677         this->mwindow = mwindow;
678 }
679
680 int CutKeyframes::handle_event()
681 {
682         if( mwindow->session->current_operation == NO_OPERATION )
683                 mwindow->cut_automation();
684         return 1;
685 }
686
687 CopyKeyframes::CopyKeyframes(MWindow *mwindow)
688  : BC_MenuItem(_("Copy keyframes"), _("Shift-C"), 'C')
689 {
690         set_shift();
691         this->mwindow = mwindow;
692 }
693
694 int CopyKeyframes::handle_event()
695 {
696         if( mwindow->session->current_operation == NO_OPERATION )
697                 mwindow->copy_automation();
698         return 1;
699 }
700
701 PasteKeyframes::PasteKeyframes(MWindow *mwindow)
702  : BC_MenuItem(_("Paste keyframes"), _("Shift-V"), 'V')
703 {
704         set_shift();
705         this->mwindow = mwindow;
706 }
707
708 int PasteKeyframes::handle_event()
709 {
710         if( mwindow->session->current_operation == NO_OPERATION )
711                 mwindow->paste_automation();
712         return 1;
713 }
714
715 ClearKeyframes::ClearKeyframes(MWindow *mwindow)
716  : BC_MenuItem(_("Clear keyframes"), _("Shift-Del"), DELETE)
717 {
718         set_shift();
719         this->mwindow = mwindow;
720 }
721
722 int ClearKeyframes::handle_event()
723 {
724         if( mwindow->session->current_operation == NO_OPERATION )
725                 mwindow->clear_automation();
726         return 1;
727 }
728
729
730
731 StraightenKeyframes::StraightenKeyframes(MWindow *mwindow)
732  : BC_MenuItem(_("Change to linear"))
733 {
734         this->mwindow = mwindow;
735 }
736
737 int StraightenKeyframes::handle_event()
738 {
739         mwindow->set_automation_mode(FloatAuto::LINEAR);
740         return 1;
741 }
742
743
744
745
746 BendKeyframes::BendKeyframes(MWindow *mwindow)
747  : BC_MenuItem(_("Change to smooth"))
748 {
749         this->mwindow = mwindow;
750 }
751
752 int BendKeyframes::handle_event()
753 {
754         mwindow->set_automation_mode(FloatAuto::SMOOTH);
755         return 1;
756 }
757
758
759
760 KeyframeCurveType::KeyframeCurveType(MWindow *mwindow)
761  : BC_MenuItem(_("Create curve type..."))
762 {
763         this->mwindow = mwindow;
764         this->curve_menu = 0;
765 }
766 KeyframeCurveType::~KeyframeCurveType()
767 {
768 }
769
770 void KeyframeCurveType::create_objects()
771 {
772         add_submenu(curve_menu = new KeyframeCurveTypeMenu(this));
773         for( int i=FloatAuto::SMOOTH; i<=FloatAuto::FREE; ++i ) {
774                 KeyframeCurveTypeItem *curve_type_item = new KeyframeCurveTypeItem(i, this);
775                 curve_menu->add_submenuitem(curve_type_item);
776         }
777 }
778
779 void KeyframeCurveType::update(int curve_type)
780 {
781         for( int i=0; i<curve_menu->total_items(); ++i ) {
782                 KeyframeCurveTypeItem *curve_type_item = (KeyframeCurveTypeItem *)curve_menu->get_item(i);
783                 curve_type_item->set_checked(curve_type_item->type == curve_type);
784         }
785 }
786
787 int KeyframeCurveType::handle_event()
788 {
789         return 1;
790 }
791
792 KeyframeCurveTypeMenu::KeyframeCurveTypeMenu(KeyframeCurveType *menu_item)
793  : BC_SubMenu()
794 {
795         this->menu_item = menu_item;
796 }
797 KeyframeCurveTypeMenu::~KeyframeCurveTypeMenu()
798 {
799 }
800
801 KeyframeCurveTypeItem::KeyframeCurveTypeItem(int type, KeyframeCurveType *main_item)
802  : BC_MenuItem(FloatAuto::curve_name(type))
803 {
804         this->type = type;
805         this->main_item = main_item;
806 }
807 KeyframeCurveTypeItem::~KeyframeCurveTypeItem()
808 {
809 }
810
811 int KeyframeCurveTypeItem::handle_event()
812 {
813         main_item->update(type);
814         main_item->mwindow->set_keyframe_type(type);
815         return 1;
816 }
817
818
819 CutDefaultKeyframe::CutDefaultKeyframe(MWindow *mwindow)
820  : BC_MenuItem(_("Cut default keyframe"), _("Alt-x"), 'x')
821 {
822         set_alt();
823         this->mwindow = mwindow;
824 }
825
826 int CutDefaultKeyframe::handle_event()
827 {
828         if( mwindow->session->current_operation == NO_OPERATION )
829                 mwindow->cut_default_keyframe();
830         return 1;
831 }
832
833 CopyDefaultKeyframe::CopyDefaultKeyframe(MWindow *mwindow)
834  : BC_MenuItem(_("Copy default keyframe"), _("Alt-c"), 'c')
835 {
836         set_alt();
837         this->mwindow = mwindow;
838 }
839
840 int CopyDefaultKeyframe::handle_event()
841 {
842         if( mwindow->session->current_operation == NO_OPERATION )
843                 mwindow->copy_default_keyframe();
844         return 1;
845 }
846
847 PasteDefaultKeyframe::PasteDefaultKeyframe(MWindow *mwindow)
848  : BC_MenuItem(_("Paste default keyframe"), _("Alt-v"), 'v')
849 {
850         set_alt();
851         this->mwindow = mwindow;
852 }
853
854 int PasteDefaultKeyframe::handle_event()
855 {
856         if( mwindow->session->current_operation == NO_OPERATION )
857                 mwindow->paste_default_keyframe();
858         return 1;
859 }
860
861 ClearDefaultKeyframe::ClearDefaultKeyframe(MWindow *mwindow)
862  : BC_MenuItem(_("Clear default keyframe"), _("Alt-Del"), DELETE)
863 {
864         set_alt();
865         this->mwindow = mwindow;
866 }
867
868 int ClearDefaultKeyframe::handle_event()
869 {
870         if( mwindow->session->current_operation == NO_OPERATION )
871                 mwindow->clear_default_keyframe();
872         return 1;
873 }
874
875 Cut::Cut(MWindow *mwindow)
876  : BC_MenuItem(_("Split | Cut"), "x", 'x')
877 {
878         this->mwindow = mwindow;
879 }
880
881 int Cut::handle_event()
882 {
883         if( mwindow->session->current_operation == NO_OPERATION )
884                 mwindow->cut();
885         return 1;
886 }
887
888 Copy::Copy(MWindow *mwindow)
889  : BC_MenuItem(_("Copy"), "c", 'c')
890 {
891         this->mwindow = mwindow;
892 }
893
894 int Copy::handle_event()
895 {
896         if( mwindow->session->current_operation == NO_OPERATION )
897                 mwindow->copy();
898         return 1;
899 }
900
901 Paste::Paste(MWindow *mwindow)
902  : BC_MenuItem(_("Paste"), "v", 'v')
903 {
904         this->mwindow = mwindow;
905 }
906
907 int Paste::handle_event()
908 {
909         if( mwindow->session->current_operation == NO_OPERATION )
910                 mwindow->paste();
911         return 1;
912 }
913
914 EditClearSubMenu::EditClearSubMenu(BC_MenuItem *menu_item)
915  : BC_SubMenu()
916 {
917         this->menu_item = menu_item;
918 }
919 EditClearSubMenu::~EditClearSubMenu()
920 {
921 }
922
923 EditClearMenu::EditClearMenu(MWindow *mwindow)
924  : BC_MenuItem(_("Clear..."))
925 {
926         this->mwindow = mwindow;
927         this->clear_sub_menu = 0;
928 }
929 EditClearMenu::~EditClearMenu()
930 {
931 }
932
933 void EditClearMenu::create_objects()
934 {
935         add_submenu(clear_sub_menu = new EditClearSubMenu(this));
936         clear_sub_menu->add_item(new Clear(mwindow));
937         clear_sub_menu->add_item(new MuteSelection(mwindow));
938         clear_sub_menu->add_item(new ClearSelect(mwindow));
939         clear_sub_menu->add_item(new ClearLabels(mwindow));
940         clear_sub_menu->add_item(new ClearHardEdges(mwindow));
941 };
942
943 Clear::Clear(MWindow *mwindow)
944  : BC_MenuItem(_("Clear"), _("Del"), DELETE)
945 {
946         this->mwindow = mwindow;
947 }
948
949 int Clear::handle_event()
950 {
951         if( mwindow->session->current_operation == NO_OPERATION ) {
952                 mwindow->cwindow->gui->lock_window("Clear::handle_event");
953                 mwindow->clear_entry();
954                 mwindow->cwindow->gui->unlock_window();
955         }
956         return 1;
957 }
958
959 PasteSilence::PasteSilence(MWindow *mwindow)
960  : BC_MenuItem(_("Paste silence"), _("Shift-Space"), ' ')
961 {
962         this->mwindow = mwindow;
963         set_shift();
964 }
965
966 int PasteSilence::handle_event()
967 {
968         if( mwindow->session->current_operation == NO_OPERATION )
969                 mwindow->paste_silence();
970         return 1;
971 }
972
973 SelectAll::SelectAll(MWindow *mwindow)
974  : BC_MenuItem(_("Select All"), "a", 'a')
975 {
976         this->mwindow = mwindow;
977 }
978
979 int SelectAll::handle_event()
980 {
981         if( mwindow->session->current_operation == NO_OPERATION )
982                 mwindow->select_all();
983         return 1;
984 }
985
986 ClearHardEdges::ClearHardEdges(MWindow *mwindow) : BC_MenuItem(_("Clear Hard Edges"))
987 {
988         this->mwindow = mwindow;
989 }
990
991 int ClearHardEdges::handle_event()
992 {
993         mwindow->clear_hard_edges();
994         return 1;
995 }
996
997 ClearLabels::ClearLabels(MWindow *mwindow) : BC_MenuItem(_("Clear labels"))
998 {
999         this->mwindow = mwindow;
1000 }
1001
1002 int ClearLabels::handle_event()
1003 {
1004         mwindow->clear_labels();
1005         return 1;
1006 }
1007
1008 ClearSelect::ClearSelect(MWindow *mwindow) : BC_MenuItem(_("Clear Select"),"Ctrl-Shift-A",'A')
1009 {
1010         set_ctrl(1);
1011         set_shift(1);
1012         this->mwindow = mwindow;
1013 }
1014
1015 int ClearSelect::handle_event()
1016 {
1017         mwindow->clear_select();
1018         return 1;
1019 }
1020
1021 CutCommercials::CutCommercials(MWindow *mwindow) : BC_MenuItem(_("Cut ads"))
1022 {
1023         this->mwindow = mwindow;
1024 }
1025
1026 int CutCommercials::handle_event()
1027 {
1028         mwindow->cut_commercials();
1029         return 1;
1030 }
1031
1032 DetachTransitions::DetachTransitions(MWindow *mwindow)
1033  : BC_MenuItem(_("Detach transitions"))
1034 {
1035         this->mwindow = mwindow;
1036 }
1037
1038 int DetachTransitions::handle_event()
1039 {
1040         mwindow->detach_transitions();
1041         return 1;
1042 }
1043
1044 MuteSelection::MuteSelection(MWindow *mwindow)
1045  : BC_MenuItem(_("Mute Region"), "m", 'm')
1046 {
1047         this->mwindow = mwindow;
1048 }
1049
1050 int MuteSelection::handle_event()
1051 {
1052         if( mwindow->session->current_operation == NO_OPERATION )
1053                 mwindow->mute_selection();
1054         return 1;
1055 }
1056
1057
1058 TrimSelection::TrimSelection(MWindow *mwindow)
1059  : BC_MenuItem(_("Trim Selection"))
1060 {
1061         this->mwindow = mwindow;
1062 }
1063
1064 int TrimSelection::handle_event()
1065 {
1066         mwindow->trim_selection();
1067         return 1;
1068 }
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081 // ============================================= audio
1082
1083 AddAudioTrack::AddAudioTrack(MWindow *mwindow)
1084  : BC_MenuItem(_("Add track"), "t", 't')
1085 {
1086         this->mwindow = mwindow;
1087 }
1088
1089 int AddAudioTrack::handle_event()
1090 {
1091         if( mwindow->session->current_operation == NO_OPERATION )
1092                 mwindow->add_audio_track_entry(0, 0);
1093         return 1;
1094 }
1095
1096 DeleteAudioTrack::DeleteAudioTrack(MWindow *mwindow)
1097  : BC_MenuItem(_("Delete track"))
1098 {
1099         this->mwindow = mwindow;
1100 }
1101
1102 int DeleteAudioTrack::handle_event()
1103 {
1104         return 1;
1105 }
1106
1107 DefaultATransition::DefaultATransition(MWindow *mwindow)
1108  : BC_MenuItem(_("Default Transition"), "u", 'u')
1109 {
1110         this->mwindow = mwindow;
1111 }
1112
1113 int DefaultATransition::handle_event()
1114 {
1115         if( mwindow->session->current_operation == NO_OPERATION )
1116                 mwindow->paste_audio_transition();
1117         return 1;
1118 }
1119
1120
1121 MapAudio1::MapAudio1(MWindow *mwindow)
1122  : BC_MenuItem(_("Map 1:1"))
1123 {
1124         this->mwindow = mwindow;
1125 }
1126
1127 int MapAudio1::handle_event()
1128 {
1129         mwindow->map_audio(MWindow::AUDIO_1_TO_1);
1130         return 1;
1131 }
1132
1133 MapAudio2::MapAudio2(MWindow *mwindow)
1134  : BC_MenuItem(_("Map 5.1:2"))
1135 {
1136         this->mwindow = mwindow;
1137 }
1138
1139 int MapAudio2::handle_event()
1140 {
1141         mwindow->map_audio(MWindow::AUDIO_5_1_TO_2);
1142         return 1;
1143 }
1144
1145
1146
1147
1148 // ============================================= video
1149
1150
1151 AddVideoTrack::AddVideoTrack(MWindow *mwindow)
1152  : BC_MenuItem(_("Add track"), _("Shift-T"), 'T')
1153 {
1154         set_shift();
1155         this->mwindow = mwindow;
1156 }
1157
1158 int AddVideoTrack::handle_event()
1159 {
1160         if( mwindow->session->current_operation == NO_OPERATION )
1161                 mwindow->add_video_track_entry();
1162         return 1;
1163 }
1164
1165
1166 DeleteVideoTrack::DeleteVideoTrack(MWindow *mwindow)
1167  : BC_MenuItem(_("Delete track"))
1168 {
1169         this->mwindow = mwindow;
1170 }
1171
1172 int DeleteVideoTrack::handle_event()
1173 {
1174         return 1;
1175 }
1176
1177
1178
1179 ResetTranslation::ResetTranslation(MWindow *mwindow)
1180  : BC_MenuItem(_("Reset Translation"))
1181 {
1182         this->mwindow = mwindow;
1183 }
1184
1185 int ResetTranslation::handle_event()
1186 {
1187         return 1;
1188 }
1189
1190
1191
1192 DefaultVTransition::DefaultVTransition(MWindow *mwindow)
1193  : BC_MenuItem(_("Default Transition"), _("Shift-U"), 'U')
1194 {
1195         set_shift();
1196         this->mwindow = mwindow;
1197 }
1198
1199 int DefaultVTransition::handle_event()
1200 {
1201         if( mwindow->session->current_operation == NO_OPERATION )
1202                 mwindow->paste_video_transition();
1203         return 1;
1204 }
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219 // ============================================ settings
1220
1221 DeleteTracks::DeleteTracks(MWindow *mwindow)
1222  : BC_MenuItem(_("Delete tracks"))
1223 {
1224         this->mwindow = mwindow;
1225 }
1226
1227 int DeleteTracks::handle_event()
1228 {
1229         mwindow->delete_tracks();
1230         return 1;
1231 }
1232
1233 DeleteFirstTrack::DeleteFirstTrack(MWindow *mwindow)
1234  : BC_MenuItem(_("Delete first track"), "Shift-D", 'D')
1235 {
1236         set_shift(1);
1237         this->mwindow = mwindow;
1238 }
1239
1240 int DeleteFirstTrack::handle_event()
1241 {
1242         if( mwindow->session->current_operation == NO_OPERATION ) {
1243                 Track *track = mwindow->edl->tracks->first;
1244                 if( track ) mwindow->delete_track(track);
1245         }
1246         return 1;
1247 }
1248
1249 DeleteLastTrack::DeleteLastTrack(MWindow *mwindow)
1250  : BC_MenuItem(_("Delete last track"), "Ctrl-Shift-D", 'D')
1251 {
1252         set_ctrl(1);
1253         set_shift(1);
1254         this->mwindow = mwindow;
1255 }
1256
1257 int DeleteLastTrack::handle_event()
1258 {
1259         if( mwindow->session->current_operation == NO_OPERATION ) {
1260                 Track *track = mwindow->edl->tracks->last;
1261                 if( track ) mwindow->delete_track(track);
1262         }
1263         return 1;
1264 }
1265
1266 MoveTracksUp::MoveTracksUp(MWindow *mwindow)
1267  : BC_MenuItem(_("Move tracks up"), _("Shift-Up"), UP)
1268 {
1269         this->mwindow = mwindow;
1270         set_shift();
1271 }
1272
1273 int MoveTracksUp::handle_event()
1274 {
1275         if( mwindow->session->current_operation == NO_OPERATION )
1276                 mwindow->move_tracks_up();
1277         return 1;
1278 }
1279
1280 MoveTracksDown::MoveTracksDown(MWindow *mwindow)
1281  : BC_MenuItem(_("Move tracks down"), _("Shift-Down"), DOWN)
1282 {
1283         set_shift(); this->mwindow = mwindow;
1284 }
1285
1286 int MoveTracksDown::handle_event()
1287 {
1288         if( mwindow->session->current_operation == NO_OPERATION )
1289                 mwindow->move_tracks_down();
1290         return 1;
1291 }
1292
1293
1294
1295
1296 ConcatenateTracks::ConcatenateTracks(MWindow *mwindow)
1297  : BC_MenuItem(_("Concatenate tracks"))
1298 {
1299         set_shift();
1300         this->mwindow = mwindow;
1301 }
1302
1303 int ConcatenateTracks::handle_event()
1304 {
1305         mwindow->concatenate_tracks();
1306         return 1;
1307 }
1308
1309
1310
1311
1312
1313 LoopPlayback::LoopPlayback(MWindow *mwindow)
1314  : BC_MenuItem(_("Loop Playback"), _("Shift-L"), 'L')
1315 {
1316         this->mwindow = mwindow;
1317         set_checked(mwindow->edl->local_session->loop_playback);
1318         set_shift();
1319 }
1320
1321 int LoopPlayback::handle_event()
1322 {
1323         if( mwindow->session->current_operation == NO_OPERATION ) {
1324                 mwindow->toggle_loop_playback();
1325                 set_checked(mwindow->edl->local_session->loop_playback);
1326         }
1327         return 1;
1328 }
1329
1330
1331
1332 // ============================================= subtitle
1333
1334
1335 AddSubttlTrack::AddSubttlTrack(MWindow *mwindow)
1336  : BC_MenuItem(_("Add subttl"), _("Shift-Y"), 'Y')
1337 {
1338         set_shift();
1339         this->mwindow = mwindow;
1340 }
1341
1342 int AddSubttlTrack::handle_event()
1343 {
1344         if( mwindow->session->current_operation == NO_OPERATION )
1345                 mwindow->add_subttl_track_entry();
1346         return 1;
1347 }
1348
1349 PasteSubttl::PasteSubttl(MWindow *mwindow)
1350  : BC_MenuItem(_("paste subttl"), "y", 'y')
1351 {
1352         this->mwindow = mwindow;
1353 }
1354
1355 int PasteSubttl::handle_event()
1356 {
1357         if( mwindow->session->current_operation == NO_OPERATION )
1358                 mwindow->gui->swindow->paste_subttl();
1359         return 1;
1360 }
1361
1362
1363 SetBRenderActive::SetBRenderActive(MWindow *mwindow)
1364  : BC_MenuItem(_("Toggle background rendering"),_("Shift-G"),'G')
1365 {
1366         this->mwindow = mwindow;
1367         set_shift(1);
1368 }
1369
1370 int SetBRenderActive::handle_event()
1371 {
1372         if( mwindow->session->current_operation == NO_OPERATION ) {
1373                 int v = mwindow->brender_active ? 0 : 1;
1374                 set_checked(v);
1375                 mwindow->set_brender_active(v);
1376         }
1377         return 1;
1378 }
1379
1380
1381 LabelsFollowEdits::LabelsFollowEdits(MWindow *mwindow)
1382  : BC_MenuItem(_("Edit labels"))
1383 {
1384         this->mwindow = mwindow;
1385         set_checked(mwindow->edl->session->labels_follow_edits);
1386 }
1387
1388 int LabelsFollowEdits::handle_event()
1389 {
1390         set_checked(get_checked() ^ 1);
1391         mwindow->set_labels_follow_edits(get_checked());
1392         return 1;
1393 }
1394
1395
1396
1397
1398 PluginsFollowEdits::PluginsFollowEdits(MWindow *mwindow)
1399  : BC_MenuItem(_("Edit effects"))
1400 {
1401         this->mwindow = mwindow;
1402         set_checked(mwindow->edl->session->plugins_follow_edits);
1403 }
1404
1405 int PluginsFollowEdits::handle_event()
1406 {
1407         set_checked(get_checked() ^ 1);
1408         mwindow->edl->session->plugins_follow_edits = get_checked();
1409         return 1;
1410 }
1411
1412
1413
1414
1415 KeyframesFollowEdits::KeyframesFollowEdits(MWindow *mwindow)
1416  : BC_MenuItem(_("Keyframes follow edits"))
1417 {
1418         this->mwindow = mwindow;
1419         set_checked(mwindow->edl->session->autos_follow_edits);
1420 }
1421
1422 int KeyframesFollowEdits::handle_event()
1423 {
1424         mwindow->edl->session->autos_follow_edits ^= 1;
1425         set_checked(!get_checked());
1426         return 1;
1427 }
1428
1429
1430 CursorOnFrames::CursorOnFrames(MWindow *mwindow)
1431  : BC_MenuItem(_("Align cursor on frames"),_("Ctrl-a"),'a')
1432 {
1433         this->mwindow = mwindow;
1434         set_checked(mwindow->edl->session->cursor_on_frames);
1435         set_ctrl(1);
1436 }
1437
1438 int CursorOnFrames::handle_event()
1439 {
1440         mwindow->edl->session->cursor_on_frames = !mwindow->edl->session->cursor_on_frames;
1441         set_checked(mwindow->edl->session->cursor_on_frames);
1442         return 1;
1443 }
1444
1445
1446 TypelessKeyframes::TypelessKeyframes(MWindow *mwindow)
1447  : BC_MenuItem(_("Typeless keyframes"))
1448 {
1449         this->mwindow = mwindow;
1450         set_checked(mwindow->edl->session->typeless_keyframes);
1451 }
1452
1453 int TypelessKeyframes::handle_event()
1454 {
1455         mwindow->edl->session->typeless_keyframes = !mwindow->edl->session->typeless_keyframes;
1456         set_checked(mwindow->edl->session->typeless_keyframes);
1457         return 1;
1458 }
1459
1460
1461 ScrubSpeed::ScrubSpeed(MWindow *mwindow)
1462  : BC_MenuItem(_("Slow Shuttle"))
1463 {
1464         this->mwindow = mwindow;
1465 }
1466
1467 int ScrubSpeed::handle_event()
1468 {
1469         if(mwindow->edl->session->scrub_speed == .5)
1470         {
1471                 mwindow->edl->session->scrub_speed = 2;
1472                 set_text(_("Slow Shuttle"));
1473         }
1474         else
1475         {
1476                 mwindow->edl->session->scrub_speed = .5;
1477                 set_text(_("Fast Shuttle"));
1478         }
1479         return 1;
1480 }
1481
1482 SaveSettingsNow::SaveSettingsNow(MWindow *mwindow)
1483  : BC_MenuItem(_("Save settings now"),_("Ctrl-s"),'s')
1484 {
1485         this->mwindow = mwindow;
1486         set_ctrl(1);
1487 }
1488
1489 int SaveSettingsNow::handle_event()
1490 {
1491         mwindow->save_defaults();
1492         mwindow->save_backup();
1493         mwindow->gui->show_message(_("Saved settings."));
1494         return 1;
1495 }
1496
1497
1498
1499 // ============================================ window
1500
1501
1502
1503
1504
1505 ShowVWindow::ShowVWindow(MWindow *mwindow)
1506  : BC_MenuItem(_("Show Viewer"))
1507 {
1508         this->mwindow = mwindow;
1509         set_checked(mwindow->session->show_vwindow);
1510 }
1511 int ShowVWindow::handle_event()
1512 {
1513         mwindow->show_vwindow();
1514         return 1;
1515 }
1516
1517 ShowAWindow::ShowAWindow(MWindow *mwindow)
1518  : BC_MenuItem(_("Show Resources"))
1519 {
1520         this->mwindow = mwindow;
1521         set_checked(mwindow->session->show_awindow);
1522 }
1523 int ShowAWindow::handle_event()
1524 {
1525         mwindow->show_awindow();
1526         return 1;
1527 }
1528
1529 ShowCWindow::ShowCWindow(MWindow *mwindow)
1530  : BC_MenuItem(_("Show Compositor"))
1531 {
1532         this->mwindow = mwindow;
1533         set_checked(mwindow->session->show_cwindow);
1534 }
1535 int ShowCWindow::handle_event()
1536 {
1537         mwindow->show_cwindow();
1538         return 1;
1539 }
1540
1541
1542 ShowGWindow::ShowGWindow(MWindow *mwindow)
1543  : BC_MenuItem(_("Show Overlays"), _("Ctrl-0"), '0')
1544 {
1545         this->mwindow = mwindow;
1546         set_ctrl(1);
1547         set_checked(mwindow->session->show_gwindow);
1548 }
1549 int ShowGWindow::handle_event()
1550 {
1551         if( mwindow->session->current_operation == NO_OPERATION ) {
1552                 if( !mwindow->session->show_gwindow )
1553                         mwindow->show_gwindow();
1554                 else
1555                         mwindow->hide_gwindow();
1556                 set_checked(mwindow->session->show_gwindow);
1557         }
1558         return 1;
1559 }
1560
1561
1562 ShowLWindow::ShowLWindow(MWindow *mwindow)
1563  : BC_MenuItem(_("Show Levels"))
1564 {
1565         this->mwindow = mwindow;
1566         set_checked(mwindow->session->show_lwindow);
1567 }
1568 int ShowLWindow::handle_event()
1569 {
1570         mwindow->show_lwindow();
1571         return 1;
1572 }
1573
1574 TileWindows::TileWindows(MWindow *mwindow, const char *item_title, int config,
1575                 const char *hot_keytext, int hot_key)
1576  : BC_MenuItem(item_title, hot_keytext, hot_key)
1577 {
1578         this->mwindow = mwindow;
1579         this->config = config;
1580         if( hot_key ) set_ctrl(1);
1581 }
1582 int TileWindows::handle_event()
1583 {
1584         if( mwindow->session->current_operation == NO_OPERATION ) {
1585                 int window_config = config >= 0 ? config :
1586                         mwindow->session->window_config;
1587                 if( mwindow->tile_windows(window_config) ) {
1588                         mwindow->restart_status = 1;
1589                         mwindow->gui->set_done(0);
1590                 }
1591         }
1592         return 1;
1593 }
1594
1595 SplitX::SplitX(MWindow *mwindow)
1596  : BC_MenuItem(_("Split X pane"), _("Ctrl-1"), '1')
1597 {
1598         this->mwindow = mwindow;
1599         set_ctrl(1);
1600         set_checked(mwindow->gui->pane[TOP_RIGHT_PANE] != 0);
1601 }
1602 int SplitX::handle_event()
1603 {
1604         if( mwindow->session->current_operation == NO_OPERATION )
1605                 mwindow->split_x();
1606         return 1;
1607 }
1608
1609 SplitY::SplitY(MWindow *mwindow)
1610  : BC_MenuItem(_("Split Y pane"), _("Ctrl-2"), '2')
1611 {
1612         this->mwindow = mwindow;
1613         set_ctrl(1);
1614         set_checked(mwindow->gui->pane[BOTTOM_LEFT_PANE] != 0);
1615 }
1616 int SplitY::handle_event()
1617 {
1618         if( mwindow->session->current_operation == NO_OPERATION )
1619                 mwindow->split_y();
1620         return 1;
1621 }
1622
1623
1624 MixerItems::MixerItems(MWindow *mwindow)
1625  : BC_MenuItem(_("Mixers..."))
1626 {
1627         this->mwindow = mwindow;
1628 }
1629
1630 void MixerItems::create_objects()
1631 {
1632         BC_SubMenu *mixer_submenu = new BC_SubMenu();
1633         add_submenu(mixer_submenu);
1634         mixer_submenu->add_submenuitem(new MixerViewer(mwindow));
1635         mixer_submenu->add_submenuitem(new TileMixers(mwindow));
1636         mixer_submenu->add_submenuitem(new AlignMixers(mwindow));
1637 }
1638
1639 MixerViewer::MixerViewer(MWindow *mwindow)
1640  : BC_MenuItem(_("Mixer Viewer"), _("Shift-M"), 'M')
1641 {
1642         this->mwindow = mwindow;
1643         set_shift(1);
1644 }
1645
1646 int MixerViewer::handle_event()
1647 {
1648         mwindow->start_mixer();
1649         return 1;
1650 }
1651
1652 TileMixers::TileMixers(MWindow *mwindow)
1653  : BC_MenuItem(_("Tile mixers"), "Alt-t", 't')
1654 {
1655         this->mwindow = mwindow;
1656         set_alt();
1657 }
1658
1659 int TileMixers::handle_event()
1660 {
1661         mwindow->tile_mixers();
1662         return 1;
1663 }
1664
1665 AlignMixers::AlignMixers(MWindow *mwindow)
1666  : BC_MenuItem(_("Align mixers"))
1667 {
1668         this->mwindow = mwindow;
1669 }
1670
1671 int AlignMixers::handle_event()
1672 {
1673         int wx, wy;
1674         mwindow->gui->get_abs_cursor(wx, wy);
1675         mwindow->mixers_align->start_dialog(wx, wy);
1676         return 1;
1677 }
1678
1679
1680 LoadLayoutItem::LoadLayoutItem(LoadLayout *load_layout, const char *text, int idx, int hotkey)
1681  : BC_MenuItem(text, "", hotkey)
1682 {
1683         this->idx = idx;
1684         this->load_layout = load_layout;
1685         if( hotkey ) {
1686                 char hot_txt[BCSTRLEN];
1687                 sprintf(hot_txt, _("Ctrl-Shift+F%d"), hotkey-KEY_F1+1);
1688                 set_ctrl();  set_shift();
1689                 set_hotkey_text(hot_txt);
1690         }
1691 }
1692
1693
1694 int LoadLayoutItem::handle_event()
1695 {
1696 // key_press hotkey skips over activate_submenu
1697         load_layout->update();
1698         MWindow *mwindow = load_layout->mwindow;
1699         switch( load_layout->action ) {
1700         case LAYOUT_LOAD:
1701                 mwindow->load_layout(layout_file);
1702                 break;
1703         case LAYOUT_SAVE: {
1704                 int wx = 0, wy = 0;
1705                 mwindow->gui->get_abs_cursor(wx, wy);
1706                 load_layout->layout_dialog->start_confirm_dialog(wx, wy, idx);
1707                 break; }
1708         }
1709         return 1;
1710 }
1711
1712 LoadLayout::LoadLayout(MWindow *mwindow, const char *text, int action)
1713  : BC_MenuItem(text)
1714 {
1715         this->mwindow = mwindow;
1716         this->action = action;
1717         this->layout_dialog = new LoadLayoutDialog(this);
1718 }
1719
1720 LoadLayout::~LoadLayout()
1721 {
1722         delete layout_dialog;
1723 }
1724
1725 void LoadLayout::create_objects()
1726 {
1727         BC_SubMenu *layout_submenu = new BC_SubMenu();
1728         add_submenu(layout_submenu);
1729
1730         for( int i=0; i<LAYOUTS_MAX; ++i ) {
1731                 char text[BCSTRLEN];
1732                 sprintf(text, _("Layout %d"), i+1);
1733                 LoadLayoutItem *item = new LoadLayoutItem(this, text, i,
1734                                 action==LAYOUT_LOAD ? KEY_F1+i : 0);
1735                 layout_submenu->add_submenuitem(item);
1736         }
1737 }
1738
1739 int LoadLayout::activate_submenu()
1740 {
1741         update();
1742         return BC_MenuItem::activate_submenu();
1743 }
1744
1745 void LoadLayout::update()
1746 {
1747         FileSystem fs;
1748         fs.set_filter("layout*_rc");
1749         int ret = fs.update(File::get_config_path());
1750         int sz = !ret ? fs.dir_list.size() : 0;
1751         BC_SubMenu *layout_submenu = get_submenu();
1752
1753         for( int i=0; i<LAYOUTS_MAX; ++i ) {
1754                 LoadLayoutItem* item = (LoadLayoutItem *)
1755                         layout_submenu->get_item(i);
1756                 char layout_text[BCSTRLEN];  layout_text[0] = 0;
1757                 int n = sz, id = i+1;
1758                 while( --n >= 0 ) {
1759                         char *np = fs.dir_list[n]->name;
1760                         char *cp = strrchr(np, '_'), *bp = 0;
1761                         int no = strtol(np+6, &bp, 10);
1762                         if( no != id || !bp ) continue;
1763                         if( bp == cp ) {  n = -1;  break; }
1764                         if( *bp++ == '_' && bp < cp && !strcmp(cp, "_rc") ) {
1765                                 int k = cp - bp;  char *tp = layout_text;
1766                                 if( k > LAYOUT_NAME_LEN ) k = LAYOUT_NAME_LEN;
1767                                 while( --k >= 0 ) *tp++ = *bp++;
1768                                 *tp = 0;
1769                                 break;
1770                         }
1771                 }
1772                 strcpy(item->layout_text, layout_text);
1773                 char *lp = item->layout_file;
1774                 int k = sprintf(lp, LAYOUT_FILE, id);
1775                 if( n >= 0 && layout_text[0] )
1776                         sprintf(lp + k-2, "%s_rc", layout_text);
1777                 else
1778                         sprintf(layout_text, _("Layout %d"), id);
1779                 item->set_text(layout_text);
1780         }
1781 }
1782
1783 LoadLayoutDialog::LoadLayoutDialog(LoadLayout *load_layout)
1784 {
1785         this->load_layout = load_layout;
1786         wx = 0;  wy = 0;
1787         idx = -1;
1788         lgui = 0;
1789 }
1790
1791 LoadLayoutDialog::~LoadLayoutDialog()
1792 {
1793         close_window();
1794 }
1795
1796 void LoadLayoutDialog::handle_done_event(int result)
1797 {
1798         if( result ) return;
1799         char layout_file[BCSTRLEN];
1800         BC_SubMenu *layout_submenu = load_layout->get_submenu();
1801         LoadLayoutItem* item =
1802                 (LoadLayoutItem *) layout_submenu->get_item(idx);
1803         snprintf(layout_file, sizeof(layout_file), "%s", item->layout_file);
1804         load_layout->mwindow->delete_layout(layout_file);
1805         int k = sprintf(layout_file, LAYOUT_FILE, idx+1);
1806         const char *text = lgui->name_text->get_text();
1807         if( text[0] )
1808                 snprintf(layout_file + k-2, sizeof(layout_file)-k+2, "%s_rc", text);
1809         load_layout->mwindow->save_layout(layout_file);
1810 }
1811
1812 void LoadLayoutDialog::handle_close_event(int result)
1813 {
1814         lgui = 0;
1815 }
1816
1817 BC_Window *LoadLayoutDialog::new_gui()
1818 {
1819         lgui = new LoadLayoutConfirm(this, wx, wy);
1820         lgui->create_objects();
1821         return lgui;
1822 }
1823
1824 void LoadLayoutDialog::start_confirm_dialog(int wx, int wy, int idx)
1825 {
1826         close_window();
1827         this->wx = wx;  this->wy = wy;
1828         this->idx = idx;
1829         start();
1830 }
1831
1832 LoadLayoutNameText::LoadLayoutNameText(LoadLayoutConfirm *confirm,
1833                 int x, int y, int w, const char *text)
1834  : BC_TextBox(x, y, w, 1, text)
1835 {
1836         this->confirm = confirm;
1837 }
1838
1839 LoadLayoutNameText::~LoadLayoutNameText()
1840 {
1841 }
1842
1843 int LoadLayoutNameText::handle_event()
1844 {
1845         const char *text = get_text();
1846         int len = strlen(text), k = 0;
1847         char new_text[BCTEXTLEN];
1848         for( int i=0; i<len; ++i ) {
1849                 int ch = text[i];
1850                 if( (ch>='A' && ch<='Z') || (ch>='a' && ch<='z') ||
1851                     (ch>='0' && ch<='9') || ch=='_' )
1852                         new_text[k++] = ch;
1853         }
1854         new_text[k] = 0;  len = k;
1855         int i = len - LAYOUT_NAME_LEN;
1856         if( i >= 0 ) {
1857                 k = 0;
1858                 while( i < len ) new_text[k++] = new_text[i++];
1859                 new_text[k] = 0;
1860         }
1861         update(new_text);
1862         return 1;
1863 }
1864
1865 LoadLayoutConfirm::LoadLayoutConfirm(LoadLayoutDialog *layout_dialog, int x, int y)
1866  : BC_Window(_(PROGRAM_NAME ": Layout"), x, y, xS(300),yS(140), xS(300),yS(140), 0)
1867 {
1868         this->layout_dialog = layout_dialog;
1869 }
1870
1871 LoadLayoutConfirm::~LoadLayoutConfirm()
1872 {
1873 }
1874
1875 void LoadLayoutConfirm::create_objects()
1876 {
1877         int xs10 = xS(10), xs20 = xS(20);
1878         int ys10 = yS(10);
1879         lock_window("LoadLayoutConfirm::create_objects");
1880         int x = xs10, y = ys10;
1881         BC_SubMenu *layout_submenu = layout_dialog->load_layout->get_submenu();
1882         LoadLayoutItem *item = (LoadLayoutItem *)
1883                 layout_submenu->get_item(layout_dialog->idx);
1884         BC_Title *title;
1885         add_subwindow(title = new BC_Title(x, y, _("Layout Name:")));
1886         int x1 = x + title->get_w() + xs10;
1887         add_subwindow(title = new BC_Title(x1, y, item->get_text()));
1888         y += title->get_h() + ys10;
1889         add_subwindow(name_text = new LoadLayoutNameText(this,
1890                 x, y, get_w()-x-xs20, item->layout_text));
1891         y += name_text->get_h();
1892         x1 = x + xS(80);
1893         char legend[BCTEXTLEN];
1894         sprintf(legend, _("a-z,A-Z,0-9_ only, %dch max"), LAYOUT_NAME_LEN);
1895         add_subwindow(title = new BC_Title(x1, y, legend));
1896         add_subwindow(new BC_OKButton(this));
1897         add_subwindow(new BC_CancelButton(this));
1898         unlock_window();
1899 }
1900
1901
1902 LoadRecentItem::LoadRecentItem(const char *path)
1903 {
1904         this->path = cstrdup(path);
1905 }
1906
1907 LoadRecentItem::~LoadRecentItem()
1908 {
1909         delete [] path;
1910 }
1911
1912 int LoadRecentItems::add_load(char *path)
1913 {
1914 // test for existing copy
1915         FileSystem fs;
1916         char name[BCTEXTLEN], text[BCTEXTLEN];
1917         fs.extract_name(name, path);
1918         int loads_total = size();
1919         int ret = 0, k = loads_total;
1920         LoadRecentItem *load_item = 0;
1921
1922         for( int i=0; !ret && i<loads_total; ++i ) {
1923                 load_item = get(i);
1924                 fs.extract_name(text, load_item->path);
1925                 if( strcmp(name, text) ) continue;
1926                 k = i;  ret = 1; // already exists, move to top
1927         }
1928         if( !ret ) { // adding a new one
1929                 while( loads_total >= TOTAL_LOADS )
1930                         remove_object_number(--loads_total);
1931                 insert(new LoadRecentItem(path), 0);
1932         }
1933         else if( k > 0 ) { // cycle loads
1934                 while( --k >= 0 ) set(k+1, get(k));
1935                 set(0, load_item);
1936         }
1937         return ret;
1938 }
1939
1940 LoadRecentItems::LoadRecentItems()
1941 {
1942 }
1943
1944 LoadRecentItems::~LoadRecentItems()
1945 {
1946         remove_all_objects();
1947 }
1948
1949 LoadRecent::LoadRecent(MWindow *mwindow, MainMenu *main_menu)
1950  : BC_MenuItem(_("Load Recent..."))
1951 {
1952         this->mwindow = mwindow;
1953         this->main_menu = main_menu;
1954         total_items = 0;
1955 }
1956 LoadRecent::~LoadRecent()
1957 {
1958 }
1959
1960 void LoadRecent::create_objects()
1961 {
1962         add_submenu(submenu = new LoadRecentSubMenu(this));
1963 }
1964
1965 LoadPrevious *LoadRecent::get_next_item()
1966 {
1967         int k = total_items++;
1968         if( k < submenu->total_items() )
1969                 return (LoadPrevious *)submenu->get_item(k);
1970         LoadPrevious *load_prev = new LoadPrevious(mwindow, main_menu->load_file);
1971         submenu->add_item(load_prev);
1972         return load_prev;
1973 }
1974
1975 int LoadRecent::activate_submenu()
1976 {
1977         total_items = 0;
1978         scan_items(1);
1979         if( total_items > 0 ) {
1980                 LoadPrevious *load_prev = get_next_item();
1981                 load_prev->set_text("-");
1982                 load_prev->set_path("");
1983         }
1984         scan_items(0);
1985         while( total_items < submenu->total_items() )
1986                 submenu->del_item(0);
1987         return BC_MenuItem::activate_submenu();
1988 }
1989
1990 void LoadRecent::scan_items(int use_xml)
1991 {
1992         FileSystem fs;
1993         int loads_total = main_menu->load.size();
1994         for( int i=0; i<loads_total; ++i ) {
1995                 LoadRecentItem *recent = main_menu->load[i];
1996                 char name[BCTEXTLEN];
1997                 fs.extract_name(name, recent->path);
1998                 const char *cp = strrchr(name, '.');
1999                 if( !cp || strcasecmp(cp+1,"xml") ? use_xml : !use_xml ) continue;
2000                 LoadPrevious *load_prev = get_next_item();
2001                 load_prev->set_text(name);
2002                 load_prev->set_path(recent->path);
2003         }
2004 }
2005
2006 LoadRecentSubMenu::LoadRecentSubMenu(LoadRecent *load_recent)
2007  : BC_SubMenu()
2008 {
2009         this->load_recent = load_recent;
2010 }
2011
2012 LoadRecentSubMenu::~LoadRecentSubMenu()
2013 {
2014 }
2015