shift keypad toggles audio, xtion masks, render+prefs widget placement
[goodguy/history.git] / cinelerra-5.1 / cinelerra / interfaceprefs.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "deleteallindexes.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "file.h"
26 #include "filesystem.h"
27 #include "language.h"
28 #include "mwindow.h"
29 #include "preferences.h"
30 #include "preferencesthread.h"
31 #include "probeprefs.h"
32 #include "interfaceprefs.h"
33 #include "shbtnprefs.h"
34 #include "theme.h"
35
36 #if 0
37 N_("Drag all following edits")
38 N_("Drag only one edit")
39 N_("Drag source only")
40 N_("No effect")
41 #endif
42
43 #define MOVE_ALL_EDITS_TITLE "Drag all following edits"
44 #define MOVE_ONE_EDIT_TITLE "Drag only one edit"
45 #define MOVE_NO_EDITS_TITLE "Drag source only"
46 #define MOVE_EDITS_DISABLED_TITLE "No effect"
47
48 InterfacePrefs::InterfacePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
49  : PreferencesDialog(mwindow, pwindow)
50 {
51         min_db = 0;
52         max_db = 0;
53         shbtn_dialog = 0;
54         file_probe_dialog = 0;
55 }
56
57 InterfacePrefs::~InterfacePrefs()
58 {
59         delete min_db;
60         delete max_db;
61         delete shbtn_dialog;
62         delete file_probe_dialog;
63 }
64
65
66 void InterfacePrefs::create_objects()
67 {
68         BC_Resources *resources = BC_WindowBase::get_resources();
69         int margin = mwindow->theme->widget_border;
70         char string[BCTEXTLEN];
71         int x0 = mwindow->theme->preferencesoptions_x;
72         int y0 = mwindow->theme->preferencesoptions_y;
73         int x = x0, y = y0;
74
75         add_subwindow(new BC_Title(x, y, _("Editing:"), LARGEFONT,
76                 resources->text_default));
77         y += 35;
78
79         int x2 = get_w()/2, y2 = y;
80         x = x2;
81         BC_Title *title;
82         add_subwindow(title = new BC_Title(x, y, _("Keyframe reticle:")));
83         y += title->get_h() + 5;
84         keyframe_reticle = new KeyframeReticle(pwindow, this, x, y,
85                 &pwindow->thread->preferences->keyframe_reticle);
86         add_subwindow(keyframe_reticle);
87         keyframe_reticle->create_objects();
88
89         x = x0;  y = y2;
90         add_subwindow(new BC_Title(x, y, _("Clicking on edit boundaries does what:")));
91         y += 25;
92         add_subwindow(new BC_Title(x, y, _("Button 1:")));
93
94         int x1 = x + 100;
95         ViewBehaviourText *text;
96         add_subwindow(text = new ViewBehaviourText(x1, y - 5,
97                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[0]),
98                         pwindow,
99                         &(pwindow->thread->edl->session->edit_handle_mode[0])));
100         text->create_objects();
101         y += 30;
102         add_subwindow(new BC_Title(x, y, _("Button 2:")));
103         add_subwindow(text = new ViewBehaviourText(x1,
104                 y - 5,
105                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[1]),
106                         pwindow,
107                         &(pwindow->thread->edl->session->edit_handle_mode[1])));
108         text->create_objects();
109         y += 30;
110         add_subwindow(new BC_Title(x, y, _("Button 3:")));
111         add_subwindow(text = new ViewBehaviourText(x1, y - 5,
112                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[2]),
113                         pwindow,
114                         &(pwindow->thread->edl->session->edit_handle_mode[2])));
115         text->create_objects();
116         y += text->get_h() + 30;
117
118         x = x0;
119         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
120         y += 5;
121         add_subwindow(new BC_Title(x, y, _("Operation:"), LARGEFONT,
122                 resources->text_default));
123         y += 35;
124
125         int y1 = y;
126         AndroidRemote *android_remote = new AndroidRemote(pwindow, x2, y);
127         add_subwindow(android_remote);
128         y += android_remote->get_h() + 10;
129         add_subwindow(title = new BC_Title(x2, y, _("Port:")));
130         int x3 = x2 + title->get_w() + margin;
131         AndroidPort *android_port = new AndroidPort(pwindow, x3, y);
132         add_subwindow(android_port);
133         y += title->get_h() + 10;
134         add_subwindow(title = new BC_Title(x2, y, _("PIN:")));
135         AndroidPIN *android_pin = new AndroidPIN(pwindow, x3, y);
136         add_subwindow(android_pin);
137         y += title->get_h() + 30;
138
139         ShBtnPrefs *shbtn_prefs = new ShBtnPrefs(pwindow, this, x2, y);
140         add_subwindow(shbtn_prefs);
141         y += shbtn_prefs->get_h() + 30;
142
143         y2 = y;
144         x = x0;  y = y1;
145         add_subwindow(file_probes = new PrefsFileProbes(pwindow, this, x, y));
146         y += 30;
147
148         PrefsTrapSigSEGV *trap_segv = new PrefsTrapSigSEGV(this, x, y);
149         add_subwindow(trap_segv);
150         x1 = x + trap_segv->get_w() + 10;
151         add_subwindow(new BC_Title(x1, y, _("(must be root)"), MEDIUMFONT, RED));
152         y += 30;
153
154         PrefsTrapSigINTR *trap_intr = new PrefsTrapSigINTR(this, x, y);
155         add_subwindow(trap_intr);
156         add_subwindow(new BC_Title(x1, y, _("(must be root)"), MEDIUMFONT, RED));
157         y += 30;
158
159         yuv420p_dvdlace = new PrefsYUV420P_DVDlace(pwindow, this, x, y);
160         add_subwindow(yuv420p_dvdlace);
161         y += 30;
162
163         if( y2 > y ) y = y2;
164         add_subwindow(title = new BC_Title(x, y + 5, _("Min DB for meter:")));
165         x += title->get_w() + 10;
166         sprintf(string, "%d", pwindow->thread->edl->session->min_meter_db);
167         add_subwindow(min_db = new MeterMinDB(pwindow, string, x, y));
168         x += min_db->get_w() + 10;
169         add_subwindow(title = new BC_Title(x, y + 5, _("Max DB:")));
170         x += title->get_w() + 10;
171         sprintf(string, "%d", pwindow->thread->edl->session->max_meter_db);
172         add_subwindow(max_db = new MeterMaxDB(pwindow, string, x, y));
173         y += 30;
174
175         StillImageUseDuration *use_stduration = new StillImageUseDuration(pwindow,
176                 pwindow->thread->edl->session->si_useduration, x2, y2);
177         add_subwindow(use_stduration);
178         int tw = 0, th = 0;
179         BC_CheckBox::calculate_extents(this, &tw, &th, 0, 0);
180         x2 += tw + 3;
181         y2 += use_stduration->get_h() + 3;
182         StillImageDuration *stduration = new StillImageDuration(pwindow, x2, y2);
183         add_subwindow(stduration);
184         x2 += stduration->get_w() + 10;
185         y2 += 3;
186         add_subwindow(new BC_Title(x2, y2, _("Seconds")));
187         y2 += 30;
188
189         x = x0;  y = y2;
190         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
191         y += 5;
192
193
194         add_subwindow(new BC_Title(x, y, _("Index files:"), LARGEFONT, resources->text_default));
195         y += 30;
196
197         add_subwindow(new BC_Title(x, y + 5,
198                 _("Index files go here:"), MEDIUMFONT, resources->text_default));
199         x1 = x + 230;
200         add_subwindow(ipathtext = new IndexPathText(x1, y, pwindow,
201                 pwindow->thread->preferences->index_directory));
202         x1 +=  ipathtext->get_w();
203         add_subwindow(ipath = new BrowseButton(mwindow->theme, this, ipathtext, x1, y,
204                 pwindow->thread->preferences->index_directory,
205                 _("Index Path"), _("Select the directory for index files"), 1));
206
207         y += 30;
208         add_subwindow(new BC_Title(x, y + 5, _("Size of index file:"),
209                 MEDIUMFONT, resources->text_default));
210         sprintf(string, "%jd", pwindow->thread->preferences->index_size);
211         add_subwindow(isize = new IndexSize(x + 230, y, pwindow, string));
212         add_subwindow(new ScanCommercials(pwindow, 400,y));
213
214         y += 30;
215         add_subwindow(new BC_Title(x, y + 5, _("Number of index files to keep:"),
216                 MEDIUMFONT, resources->text_default));
217         sprintf(string, "%ld", (long)pwindow->thread->preferences->index_count);
218         add_subwindow(icount = new IndexCount(x + 230, y, pwindow, string));
219         add_subwindow(deleteall = new DeleteAllIndexes(mwindow, pwindow, 400, y));
220         y += 30;
221         add_subwindow(ffmpeg_marker_files = new IndexFFMPEGMarkerFiles(this, x, y));
222         y += 35;
223 }
224
225 const char* InterfacePrefs::behavior_to_text(int mode)
226 {
227         switch(mode) {
228                 case MOVE_ALL_EDITS: return _(MOVE_ALL_EDITS_TITLE);
229                 case MOVE_ONE_EDIT:  return _(MOVE_ONE_EDIT_TITLE);
230                 case MOVE_NO_EDITS:  return _(MOVE_NO_EDITS_TITLE);
231                 case MOVE_EDITS_DISABLED: return _(MOVE_EDITS_DISABLED_TITLE);
232                 default: return "";
233         }
234 }
235
236 IndexPathText::IndexPathText(int x, int y, PreferencesWindow *pwindow, char *text)
237  : BC_TextBox(x, y, 240, 1, text)
238 {
239         this->pwindow = pwindow;
240 }
241
242 IndexPathText::~IndexPathText() {}
243
244 int IndexPathText::handle_event()
245 {
246         strcpy(pwindow->thread->preferences->index_directory, get_text());
247         return 1;
248 }
249
250
251
252
253 IndexSize::IndexSize(int x, int y, PreferencesWindow *pwindow, char *text)
254  : BC_TextBox(x, y, 100, 1, text)
255 {
256         this->pwindow = pwindow;
257 }
258
259 int IndexSize::handle_event()
260 {
261         long result;
262
263         result = atol(get_text());
264         if(result < 64000) result = 64000;
265         //if(result < 500000) result = 500000;
266         pwindow->thread->preferences->index_size = result;
267         return 0;
268 }
269
270
271
272 IndexCount::IndexCount(int x, int y, PreferencesWindow *pwindow, char *text)
273  : BC_TextBox(x, y, 100, 1, text)
274 {
275         this->pwindow = pwindow;
276 }
277
278 int IndexCount::handle_event()
279 {
280         long result;
281
282         result = atol(get_text());
283         if(result < 1) result = 1;
284         pwindow->thread->preferences->index_count = result;
285         return 0;
286 }
287
288
289
290 IndexFFMPEGMarkerFiles::IndexFFMPEGMarkerFiles(InterfacePrefs *iface_prefs, int x, int y)
291  : BC_CheckBox(x, y,
292         iface_prefs->pwindow->thread->preferences->ffmpeg_marker_indexes,
293         _("build ffmpeg marker indexes"))
294 {
295         this->iface_prefs = iface_prefs;
296 }
297 IndexFFMPEGMarkerFiles::~IndexFFMPEGMarkerFiles()
298 {
299 }
300
301 int IndexFFMPEGMarkerFiles::handle_event()
302 {
303         iface_prefs->pwindow->thread->preferences->ffmpeg_marker_indexes = get_value();
304         return 1;
305 }
306
307
308 ViewBehaviourText::ViewBehaviourText(int x, int y, const char *text, PreferencesWindow *pwindow,
309         int *output)
310  : BC_PopupMenu(x, y, 200, text)
311 {
312         this->output = output;
313 }
314
315 ViewBehaviourText::~ViewBehaviourText()
316 {
317 }
318
319 int ViewBehaviourText::handle_event()
320 {
321         return 0;
322 }
323
324 void ViewBehaviourText::create_objects()
325 {
326         add_item(new ViewBehaviourItem(this, _(MOVE_ALL_EDITS_TITLE), MOVE_ALL_EDITS));
327         add_item(new ViewBehaviourItem(this, _(MOVE_ONE_EDIT_TITLE), MOVE_ONE_EDIT));
328         add_item(new ViewBehaviourItem(this, _(MOVE_NO_EDITS_TITLE), MOVE_NO_EDITS));
329         add_item(new ViewBehaviourItem(this, _(MOVE_EDITS_DISABLED_TITLE), MOVE_EDITS_DISABLED));
330 }
331
332
333 ViewBehaviourItem::ViewBehaviourItem(ViewBehaviourText *popup, char *text, int behaviour)
334  : BC_MenuItem(text)
335 {
336         this->popup = popup;
337         this->behaviour = behaviour;
338 }
339
340 ViewBehaviourItem::~ViewBehaviourItem()
341 {
342 }
343
344 int ViewBehaviourItem::handle_event()
345 {
346         popup->set_text(get_text());
347         *(popup->output) = behaviour;
348         return 1;
349 }
350
351
352 MeterMinDB::MeterMinDB(PreferencesWindow *pwindow, char *text, int x, int y)
353  : BC_TextBox(x, y, 50, 1, text)
354 {
355         this->pwindow = pwindow;
356 }
357
358 int MeterMinDB::handle_event()
359 {
360         pwindow->thread->redraw_meters = 1;
361         pwindow->thread->edl->session->min_meter_db = atol(get_text());
362         return 0;
363 }
364
365
366 MeterMaxDB::MeterMaxDB(PreferencesWindow *pwindow, char *text, int x, int y)
367  : BC_TextBox(x, y, 50, 1, text)
368 {
369         this->pwindow = pwindow;
370 }
371
372 int MeterMaxDB::handle_event()
373 {
374         pwindow->thread->redraw_meters = 1;
375         pwindow->thread->edl->session->max_meter_db = atol(get_text());
376         return 0;
377 }
378
379
380 ScanCommercials::ScanCommercials(PreferencesWindow *pwindow, int x, int y)
381  : BC_CheckBox(x,
382         y,
383         pwindow->thread->preferences->scan_commercials,
384         _("Scan for commercials during toc build"))
385 {
386         this->pwindow = pwindow;
387 }
388 int ScanCommercials::handle_event()
389 {
390         pwindow->thread->preferences->scan_commercials = get_value();
391         return 1;
392 }
393
394
395 AndroidRemote::AndroidRemote(PreferencesWindow *pwindow, int x, int y)
396  : BC_CheckBox(x, y,
397         pwindow->thread->preferences->android_remote,
398         _("Android Remote Control"))
399 {
400         this->pwindow = pwindow;
401 }
402 int AndroidRemote::handle_event()
403 {
404         pwindow->thread->preferences->android_remote = get_value();
405         return 1;
406 }
407
408 AndroidPIN::AndroidPIN(PreferencesWindow *pwindow, int x, int y)
409  : BC_TextBox(x, y, 240, 1, pwindow->thread->preferences->android_pin)
410 {
411         this->pwindow = pwindow;
412 }
413
414 int AndroidPIN::handle_event()
415 {
416         char *txt = pwindow->thread->preferences->android_pin;
417         int len = sizeof(pwindow->thread->preferences->android_pin);
418         strncpy(txt, get_text(), len);
419         return 1;
420 }
421
422
423 AndroidPort::AndroidPort(PreferencesWindow *pwindow, int x, int y)
424  : BC_TextBox(x, y, 72, 1, pwindow->thread->preferences->android_port)
425 {
426         this->pwindow = pwindow;
427 }
428
429 int AndroidPort::handle_event()
430 {
431         unsigned short port = atoi(get_text());
432         if( port < 1024 ) port = 1024;
433         pwindow->thread->preferences->android_port = port;
434         char str[BCSTRLEN];
435         sprintf(str,"%u",port);
436         update(str);
437         return 1;
438 }
439
440 int InterfacePrefs::start_shbtn_dialog()
441 {
442         if( !shbtn_dialog )
443                 shbtn_dialog = new ShBtnEditDialog(pwindow);
444         shbtn_dialog->start();
445         return 1;
446 }
447
448 ShBtnPrefs::ShBtnPrefs(PreferencesWindow *pwindow, InterfacePrefs *iface_prefs, int x, int y)
449  : BC_GenericButton(x, y, _("Shell Commands"))
450 {
451         this->pwindow = pwindow;
452         this->iface_prefs = iface_prefs;
453         set_tooltip(_("Main Menu Shell Commands"));
454 }
455
456 int ShBtnPrefs::handle_event()
457 {
458         return iface_prefs->start_shbtn_dialog();
459 }
460
461
462 StillImageUseDuration::StillImageUseDuration(PreferencesWindow *pwindow, int value, int x, int y)
463  : BC_CheckBox(x, y, value, _("Import images with a duration of"))
464 {
465         this->pwindow = pwindow;
466 }
467
468 int StillImageUseDuration::handle_event()
469 {
470         pwindow->thread->edl->session->si_useduration = get_value();
471         return 1;
472 }
473
474 StillImageDuration::StillImageDuration(PreferencesWindow *pwindow, int x, int y)
475  : BC_TextBox(x, y, 70, 1, pwindow->thread->edl->session->si_duration)
476 {
477         this->pwindow = pwindow;
478 }
479 int StillImageDuration::handle_event()
480 {
481         pwindow->thread->edl->session->si_duration = atof(get_text());
482         return 1;
483 }
484
485
486 HairlineItem::HairlineItem(KeyframeReticle *popup, int hairline)
487  : BC_MenuItem(popup->hairline_to_string(hairline))
488 {
489         this->popup = popup;
490         this->hairline = hairline;
491 }
492
493 HairlineItem::~HairlineItem()
494 {
495 }
496
497 int HairlineItem::handle_event()
498 {
499         popup->pwindow->thread->redraw_overlays = 1;
500         popup->set_text(get_text());
501         *(popup->output) = hairline;
502         return 1;
503 }
504
505
506 KeyframeReticle::KeyframeReticle(PreferencesWindow *pwindow,
507         InterfacePrefs *iface_prefs, int x, int y, int *output)
508  : BC_PopupMenu(x, y, 220, hairline_to_string(*output))
509 {
510         this->pwindow = pwindow;
511         this->iface_prefs = iface_prefs;
512         this->output = output;
513 }
514
515 KeyframeReticle::~KeyframeReticle()
516 {
517 }
518
519 const char *KeyframeReticle::hairline_to_string(int type)
520 {
521         switch( type ) {
522         case HAIRLINE_NEVER:    return _("Never");
523         case HAIRLINE_DRAGGING: return _("Dragging");
524         case HAIRLINE_ALWAYS:   return _("Always");
525         }
526         return _("Unknown");
527 }
528
529 void KeyframeReticle::create_objects()
530 {
531         add_item(new HairlineItem(this, HAIRLINE_NEVER));
532         add_item(new HairlineItem(this, HAIRLINE_DRAGGING));
533         add_item(new HairlineItem(this, HAIRLINE_ALWAYS));
534 }
535
536 PrefsTrapSigSEGV::PrefsTrapSigSEGV(InterfacePrefs *subwindow, int x, int y)
537  : BC_CheckBox(x, y,
538         subwindow->pwindow->thread->preferences->trap_sigsegv,
539         _("trap sigSEGV"))
540 {
541         this->subwindow = subwindow;
542 }
543 PrefsTrapSigSEGV::~PrefsTrapSigSEGV()
544 {
545 }
546 int PrefsTrapSigSEGV::handle_event()
547 {
548         subwindow->pwindow->thread->preferences->trap_sigsegv = get_value();
549         return 1;
550 }
551
552 PrefsTrapSigINTR::PrefsTrapSigINTR(InterfacePrefs *subwindow, int x, int y)
553  : BC_CheckBox(x, y,
554         subwindow->pwindow->thread->preferences->trap_sigintr,
555         _("trap sigINT"))
556 {
557         this->subwindow = subwindow;
558 }
559 PrefsTrapSigINTR::~PrefsTrapSigINTR()
560 {
561 }
562 int PrefsTrapSigINTR::handle_event()
563 {
564         subwindow->pwindow->thread->preferences->trap_sigintr = get_value();
565         return 1;
566 }
567
568
569 void InterfacePrefs::start_probe_dialog()
570 {
571         if( !file_probe_dialog )
572                 file_probe_dialog = new FileProbeDialog(pwindow);
573         file_probe_dialog->start();
574 }
575
576 PrefsFileProbes::PrefsFileProbes(PreferencesWindow *pwindow,
577                 InterfacePrefs *subwindow, int x, int y)
578  : BC_GenericButton(x, y, _("Probe Order"))
579 {
580         this->pwindow = pwindow;
581         this->subwindow = subwindow;
582         set_tooltip(_("File Open Probe Ordering"));
583 }
584
585 int PrefsFileProbes::handle_event()
586 {
587         subwindow->start_probe_dialog();
588         return 1;
589 }
590
591
592 PrefsYUV420P_DVDlace::PrefsYUV420P_DVDlace(PreferencesWindow *pwindow,
593         InterfacePrefs *subwindow, int x, int y)
594  : BC_CheckBox(x, y, pwindow->thread->preferences->dvd_yuv420p_interlace,
595         _("Use yuv420p dvd interlace format"))
596 {
597         this->pwindow = pwindow;
598         this->subwindow = subwindow;
599 }
600
601 int PrefsYUV420P_DVDlace::handle_event()
602 {
603         pwindow->thread->preferences->dvd_yuv420p_interlace = get_value();
604         return 1;
605 }
606