update internationalization data
[goodguy/history.git] / cinelerra-5.0 / cinelerra / preferencesthread.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 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 "aboutprefs.h"
23 #include "asset.h"
24 #include "audiodevice.inc"
25 #include "bcsignals.h"
26 #include "cache.h"
27 #include "cplayback.h"
28 #include "cwindow.h"
29 #include "cwindowgui.h"
30 #include "bchash.h"
31 #include "edl.h"
32 #include "edlsession.h"
33 #include "filesystem.h"
34 #include "fonts.h"
35 #include "interfaceprefs.h"
36 #include "keys.h"
37 #include "language.h"
38 #include "levelwindow.h"
39 #include "levelwindowgui.h"
40 #include "mainerror.h"
41 #include "mbuttons.h"
42 #include "meterpanel.h"
43 #include "mutex.h"
44 #include "mwindow.h"
45 #include "mwindowgui.h"
46 #include "patchbay.h"
47 #include "performanceprefs.h"
48 #include "playbackengine.h"
49 #include "playbackprefs.h"
50 #include "preferences.h"
51 #include "recordprefs.h"
52 #include "theme.h"
53 #include "trackcanvas.h"
54 #include "transportque.h"
55 #include "vwindow.h"
56 #include "vwindowgui.h"
57
58 #include <string.h>
59
60
61
62 #define WIDTH 750
63 #define HEIGHT 670
64
65
66 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
67  : BC_MenuItem(_("Preferences..."), _("Shift+P"), 'P')
68 {
69         this->mwindow = mwindow; 
70
71         set_shift(1);
72         thread = new PreferencesThread(mwindow);
73 }
74
75 PreferencesMenuitem::~PreferencesMenuitem()
76 {
77         delete thread;
78 }
79
80
81 int PreferencesMenuitem::handle_event() 
82 {
83         mwindow->gui->unlock_window();
84         thread->start();
85         mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
86         return 1;
87 }
88
89
90
91
92 PreferencesThread::PreferencesThread(MWindow *mwindow)
93  : BC_DialogThread()
94 {
95         this->mwindow = mwindow;
96         window = 0;
97         thread_running = 0;
98 }
99
100 PreferencesThread::~PreferencesThread()
101 {
102 }
103
104 BC_Window* PreferencesThread::new_gui()
105 {
106
107         preferences = new Preferences;
108         edl = new EDL;
109         edl->create_objects();
110         current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
111         preferences->copy_from(mwindow->preferences);
112         edl->copy_session(mwindow->edl);
113         redraw_indexes = 0;
114         redraw_meters = 0;
115         redraw_times = 0;
116         redraw_overlays = 0;
117         close_assets = 0;
118         reload_plugins = 0;
119         //int need_new_indexes = 0;
120         rerender = 0;
121
122         mwindow->gui->lock_window("NewThread::new_gui");
123         int scr_x = mwindow->gui->get_screen_x(0, -1);
124         int scr_w = mwindow->gui->get_screen_w(0, -1);
125         int scr_h = mwindow->gui->get_screen_h(0, -1);
126
127         int x = scr_x + scr_w / 2 - WIDTH / 2;
128         int y = scr_h / 2 - HEIGHT / 2;
129
130         window = new PreferencesWindow(mwindow, this, x, y);
131         window->create_objects();
132         mwindow->gui->unlock_window();
133
134         thread_running = 1;
135         return window;
136 }
137
138 void PreferencesThread::handle_close_event(int result)
139 {
140         thread_running = 0;
141         if(!result)
142         {
143                 apply_settings();
144                 mwindow->save_defaults();
145         }
146
147         window = 0;
148         delete preferences;
149         edl->Garbage::remove_user();
150         preferences = 0;
151         edl = 0;
152
153         mwindow->defaults->update("DEFAULTPREF", current_dialog);
154 }
155
156
157
158 int PreferencesThread::update_framerate()
159 {
160         if(thread_running)
161         {
162                 lock_gui("PreferencesThread::update_framerate");
163                 PreferencesWindow *window = (PreferencesWindow*)get_gui();
164                 if(window) window->update_framerate();
165                 unlock_gui();
166         }
167         return 0;
168 }
169
170
171 void PreferencesThread::update_rates()
172 {
173         if(thread_running)
174         {
175                 lock_gui("PreferencesThread::update_framerate");
176                 PreferencesWindow *window = (PreferencesWindow*)get_gui();
177                 if(window) window->update_rates();
178                 unlock_gui();
179         }
180 }
181
182 int PreferencesThread::apply_settings()
183 {
184 // Compare sessions                                                                                     
185
186         PlaybackConfig *this_playback_config = edl->session->playback_config;
187         AudioOutConfig *this_aconfig = this_playback_config->aconfig;
188         VideoOutConfig *this_vconfig = this_playback_config->vconfig;
189         PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
190         AudioOutConfig *aconfig = playback_config->aconfig;
191         VideoOutConfig *vconfig = playback_config->vconfig;
192
193         rerender = 
194                 edl->session->need_rerender(mwindow->edl->session) ||
195                 (preferences->force_uniprocessor != preferences->force_uniprocessor) ||
196                 this_playback_config->active_config != playback_config->active_config ||
197                 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
198                 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1);
199
200         if( preferences->file_forking != mwindow->preferences->file_forking ) {
201                 MainError::show_error(
202                         _("Reseting file forking requires restarting cinelerra"));
203         }
204         mwindow->edl->copy_session(edl, 1);
205         mwindow->preferences->copy_from(preferences);
206         mwindow->init_brender();
207
208         BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
209         BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
210
211         mwindow->reset_android_remote();
212         mwindow->gui->mbuttons->ffmpeg_toggle->update(mwindow->preferences->ffmpeg_early_probe);
213
214 //edl->session->recording_format->dump();
215 //mwindow->edl->session->recording_format->dump();
216
217         if(((mwindow->edl->session->output_w % 4) || 
218                 (mwindow->edl->session->output_h % 4)) && 
219                 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
220         {
221                 MainError::show_error(
222                         _("This project's dimensions are not multiples of 4 so\n"
223                         "it can't be rendered by OpenGL."));
224         }
225
226
227         if(redraw_meters)
228         {
229                 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
230                 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
231                         edl->session->min_meter_db,
232                         edl->session->max_meter_db);
233                 mwindow->cwindow->gui->unlock_window();
234
235
236
237                 for(int i = 0; i < mwindow->vwindows.size(); i++)
238                 {
239                         VWindow *vwindow = mwindow->vwindows.get(i);
240                         vwindow->gui->lock_window("PreferencesThread::apply_settings");
241                         vwindow->gui->meters->change_format(edl->session->meter_format,
242                                 edl->session->min_meter_db,
243                                 edl->session->max_meter_db);
244                         vwindow->gui->unlock_window();
245
246                 }
247
248
249                 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
250                 mwindow->gui->set_meter_format(edl->session->meter_format,
251                         edl->session->min_meter_db,
252                         edl->session->max_meter_db);
253                 mwindow->gui->unlock_window();
254
255
256
257                 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
258                 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
259                         edl->session->min_meter_db,
260                         edl->session->max_meter_db);
261                 mwindow->lwindow->gui->unlock_window();
262         }
263
264         if(redraw_overlays)
265         {
266                 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
267                 mwindow->gui->draw_overlays(1);
268                 mwindow->gui->unlock_window();
269         }
270
271         if(redraw_times)
272         {
273                 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
274                 mwindow->gui->update(0, 0, 1, 0, 0, 1, 0);
275                 mwindow->gui->redraw_time_dependancies();
276                 mwindow->gui->unlock_window();
277         }
278
279         if(rerender)
280         {
281 //printf("PreferencesThread::apply_settings 1\n");
282 // This doesn't stop and restart, only reloads the assets before
283 // the next play command.
284                 mwindow->cwindow->playback_engine->que->send_command(CURRENT_FRAME,
285                         CHANGE_ALL,
286                         mwindow->edl,
287                         1);
288 //printf("PreferencesThread::apply_settings 10\n");
289         }
290
291         if(redraw_times || redraw_overlays)
292         {
293                 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
294                 mwindow->gui->flush();
295                 mwindow->gui->unlock_window();
296         }
297
298         return 0;
299 }
300
301 const char* PreferencesThread::category_to_text(int category)
302 {
303         PlaybackConfig *playback_config = edl->session->playback_config;
304         switch(category)
305         {
306                 case PLAYBACK_A:
307                         return playback_config->active_config==0 ?
308                                  _("*Playback A") : _("Playback A");
309                 case PLAYBACK_B:
310                         return playback_config->active_config==1 ?
311                                  _("*Playback B") : _("Playback B");
312                 case RECORD:
313                         return _("Recording");
314                 case PERFORMANCE:
315                         return _("Performance");
316                 case INTERFACE:
317                         return _("Interface");
318                 case ABOUT:
319                         return _("About");
320         }
321         return "";
322 }
323
324 int PreferencesThread::text_to_category(const char *category)
325 {
326 SET_TRACE
327         int min_result = -1, result, result_num = 0;
328         for(int i = 0; i < CATEGORIES; i++)
329         {
330                 result = labs(strcmp(category_to_text(i), category));
331                 if(result < min_result || min_result < 0) 
332                 {
333                         min_result = result;
334                         result_num = i;
335                 }
336         }
337 SET_TRACE
338         return result_num;
339 }
340
341
342
343
344
345
346
347
348 PreferencesWindow::PreferencesWindow(MWindow *mwindow, 
349         PreferencesThread *thread,
350         int x,
351         int y)
352  : BC_Window(_(PROGRAM_NAME ": Preferences"), 
353         x,
354         y,
355         WIDTH, 
356         HEIGHT,
357         (int)BC_INFINITY,
358         (int)BC_INFINITY,
359         0,
360         0,
361         1)
362 {
363         this->mwindow = mwindow;
364         this->thread = thread;
365         dialog = 0;
366         category = 0;
367 }
368
369 PreferencesWindow::~PreferencesWindow()
370 {
371         lock_window("PreferencesWindow::~PreferencesWindow");
372         delete category;
373
374
375         if(dialog) delete dialog;
376
377
378         for(int i = 0; i < categories.total; i++)
379                 delete categories.values[i];
380         unlock_window();
381 }
382
383 void PreferencesWindow::create_objects()
384 {
385         BC_Button *button;
386
387
388
389         lock_window("PreferencesWindow::create_objects");
390
391         mwindow->theme->draw_preferences_bg(this);
392         flash();
393
394         int x = mwindow->theme->preferencescategory_x;
395         int y = mwindow->theme->preferencescategory_y;
396         for(int i = 0; i < CATEGORIES; i++)
397         {
398                 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
399                         thread,
400                         x,
401                         y,
402                         i,
403                         thread->category_to_text(i),
404                         (i == thread->current_dialog) ?
405                                 mwindow->theme->get_image_set("category_button_checked") : 
406                                 mwindow->theme->get_image_set("category_button")));
407                 x += category_button[i]->get_w() -
408                         mwindow->theme->preferences_category_overlap;
409         }
410
411
412 //      for(int i = 0; i < CATEGORIES; i++)
413 //              categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
414 //      category = new PreferencesCategory(mwindow, 
415 //              thread, 
416 //              mwindow->theme->preferencescategory_x, 
417 //              mwindow->theme->preferencescategory_y);
418 //      category->create_objects();
419
420
421         add_subwindow(button = new PreferencesOK(mwindow, thread));
422         add_subwindow(new PreferencesApply(mwindow, thread));
423         add_subwindow(new PreferencesCancel(mwindow, thread));
424
425         set_current_dialog(thread->current_dialog);
426
427         show_window();
428         unlock_window();
429 }
430
431 int PreferencesWindow::update_framerate()
432 {
433         lock_window("PreferencesWindow::update_framerate");
434         if(thread->current_dialog < PreferencesThread::RECORD)
435         {
436                 dialog->draw_framerate(1);
437 //              flash();
438         }
439         unlock_window();
440         return 0;
441 }
442
443
444 void PreferencesWindow::update_rates()
445 {
446         lock_window("PreferencesWindow::update_rates");
447         if(thread->current_dialog == PreferencesThread::PERFORMANCE)
448         {
449                 dialog->update_rates();
450         }
451         unlock_window();
452 }
453
454
455 int PreferencesWindow::set_current_dialog(int number)
456 {
457         if(dialog) delete dialog;
458         dialog = 0;
459         thread->current_dialog = number;
460
461 //PRINT_TRACE
462         PreferencesDialog *dialog2 = dialog;
463         dialog = 0;
464 //PRINT_TRACE
465
466 // Redraw category buttons
467         for(int i = 0; i < CATEGORIES; i++)
468         {
469                 if(i == number)
470                 {
471                         category_button[i]->set_images(
472                                 mwindow->theme->get_image_set("category_button_checked"));
473                 }
474                 else
475                 {
476                         category_button[i]->set_images(
477                                 mwindow->theme->get_image_set("category_button"));
478                 }
479                 category_button[i]->draw_face(0);
480
481 // Copy face to background for next button's overlap.
482 // Still can't do state changes right.
483         }
484
485
486 //PRINT_TRACE
487         PlaybackConfig *playback_config = thread->edl->session->playback_config;
488         switch(number)
489         {
490                 case PreferencesThread::PLAYBACK_A:
491                 case PreferencesThread::PLAYBACK_B:
492                         playback_config->load_defaults(mwindow->defaults,
493                                 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
494                         add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
495                         break;
496         
497                 case PreferencesThread::RECORD:
498                         add_subwindow(dialog = new RecordPrefs(mwindow, this));
499                         break;
500         
501                 case PreferencesThread::PERFORMANCE:
502                         add_subwindow(dialog = new PerformancePrefs(mwindow, this));
503                         break;
504         
505                 case PreferencesThread::INTERFACE:
506                         add_subwindow(dialog = new InterfacePrefs(mwindow, this));
507                         break;
508         
509                 case PreferencesThread::ABOUT:
510                         add_subwindow(dialog = new AboutPrefs(mwindow, this));
511                         break;
512         }
513
514 //PRINT_TRACE
515         if(dialog)
516         {
517                 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
518 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
519                 dialog->create_objects();
520 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
521                 dialog->show_window(0);
522         }
523
524         if(dialog2) 
525         {
526                 dialog2->hide_window(0);
527                 delete dialog2;
528         }
529
530         return 0;
531 }
532
533
534
535
536
537
538
539
540
541
542
543 PreferencesButton::PreferencesButton(MWindow *mwindow, 
544         PreferencesThread *thread, 
545         int x, 
546         int y,
547         int category,
548         const char *text,
549         VFrame **images)
550  : BC_GenericButton(x, y, text, images)
551 {
552         this->mwindow = mwindow;
553         this->thread = thread;
554         this->category = category;
555 }
556
557 int PreferencesButton::handle_event()
558 {
559         thread->window->set_current_dialog(category);
560         return 1;
561 }
562
563
564
565
566
567
568
569
570
571 PreferencesDialog::PreferencesDialog(MWindow *mwindow, 
572         PreferencesWindow *pwindow)
573  : BC_SubWindow(10, 
574         40, 
575         pwindow->get_w() - 20, 
576         pwindow->get_h() - BC_GenericButton::calculate_h() - 10 - 40)
577 {
578         this->pwindow = pwindow;
579         this->mwindow = mwindow;
580         preferences = pwindow->thread->preferences;
581 }
582
583 PreferencesDialog::~PreferencesDialog()
584 {
585 }
586
587 // ============================== category window
588
589
590
591
592 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
593  : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2, 
594         thread->window->get_h() - BC_GenericButton::calculate_h() - 10, 
595         _("Apply"))
596 {
597         this->mwindow = mwindow;
598         this->thread = thread;
599 }
600
601 int PreferencesApply::handle_event()
602 {
603         thread->apply_settings();
604         return 1;
605 }
606
607
608
609
610 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
611  : BC_GenericButton(10, 
612         thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
613         _("OK"))
614 {
615         this->mwindow = mwindow;
616         this->thread = thread;
617 }
618
619 int PreferencesOK::keypress_event()
620 {
621         if(get_keypress() == RETURN)
622         {
623                 thread->window->set_done(0);
624                 return 1;
625         }
626         return 0;
627 }
628 int PreferencesOK::handle_event()
629 {
630         thread->window->set_done(0);
631         return 1;
632 }
633
634
635
636 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
637  : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - 10,
638         thread->window->get_h() - BC_GenericButton::calculate_h() - 10,
639         _("Cancel"))
640 {
641         this->mwindow = mwindow;
642         this->thread = thread;
643 }
644 int PreferencesCancel::keypress_event()
645 {
646         if(get_keypress() == ESC)
647         {
648                 thread->window->set_done(1);
649                 return 1;
650         }
651         return 0;
652 }
653
654 int PreferencesCancel::handle_event()
655 {
656         thread->window->set_done(1);
657         return 1;
658 }
659
660
661
662
663
664
665
666
667
668
669 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
670  : BC_PopupTextBox(thread->window, 
671                 &thread->window->categories,
672                 thread->category_to_text(thread->current_dialog),
673                 x, 
674                 y, 
675                 200,
676                 150)
677 {
678         this->mwindow = mwindow;
679         this->thread = thread;
680 }
681
682 PreferencesCategory::~PreferencesCategory()
683 {
684 }
685
686 int PreferencesCategory::handle_event()
687 {
688 SET_TRACE
689         thread->window->set_current_dialog(thread->text_to_category(get_text()));
690 SET_TRACE
691         return 1;
692 }