r956: README.BUILD - add more library recommendations
[cinelerra_cv/ct.git] / cinelerra / performanceprefs.C
blob2184b080abac0fdb216f2373d88ffee5776330cb
1 #include "bcsignals.h"
2 #include "clip.h"
3 #include "edl.h"
4 #include "edlsession.h"
5 #include "formattools.h"
6 #include "language.h"
7 #include "mwindow.h"
8 #include "performanceprefs.h"
9 #include "preferences.h"
10 #include <string.h>
11 #include "theme.h"
14 PerformancePrefs::PerformancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
15  : PreferencesDialog(mwindow, pwindow)
17         hot_node = -1;
20 PerformancePrefs::~PerformancePrefs()
22         delete brender_tools;
23         nodes[0].remove_all_objects();
24         nodes[1].remove_all_objects();
25         nodes[2].remove_all_objects();
26         nodes[3].remove_all_objects();
29 int PerformancePrefs::create_objects()
31         int x, y;
32         int xmargin1;
33         int xmargin2 = 170;
34         int xmargin3 = 250;
35         int xmargin4 = 380;
36         char string[BCTEXTLEN];
37         BC_Resources *resources = BC_WindowBase::get_resources();
39         node_list = 0;
40         generate_node_list();
42         xmargin1 = x = mwindow->theme->preferencesoptions_x;
43         y = mwindow->theme->preferencesoptions_y;
44         
45 //      add_subwindow(new BC_Title(x, 
46 //              y, 
47 //              _("Time Format"), 
48 //              LARGEFONT, 
49 //              resources->text_default));
50 // 
51 //      y += get_text_height(LARGEFONT) + 5;
53         add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default));
54         cache_size = new CICacheSize(x + 230, 
55                 y, 
56                 pwindow, 
57                 this);
58         cache_size->create_objects();
60         y += 30;
61         add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
62         PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow, 
63                 this, 
64                 x + 230, 
65                 y);
66         preroll->create_objects();
67         y += 30;
68         add_subwindow(new PrefsForceUniprocessor(pwindow, x, y));
70         y += 35;
75 // Background rendering
76         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
77         y += 5;
80         add_subwindow(new BC_Title(x, y, _("Background Rendering (Video only)"), LARGEFONT, resources->text_default));
81         y += 30;
83         add_subwindow(new PrefsUseBRender(pwindow, 
84                 x,
85                 y));
88         add_subwindow(new BC_Title(x, y + 40, _("Frames per background rendering job:")));
89         PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow, 
90                 this, 
91                 x, 
92                 y + 60);
93         brender_fragment->create_objects();
94         add_subwindow(new BC_Title(x, y + 95, _("Frames to preroll background:")));
95         PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow, 
96                 this, 
97                 x + xmargin3, 
98                 y + 90);
99         bpreroll->create_objects();
102         x += xmargin4;
103         add_subwindow(new BC_Title(x, y, _("Output for background rendering:")));
104         y += 20;
105         brender_tools = 
106                 new FormatTools(mwindow,
107                         this, 
108                         pwindow->thread->preferences->brender_asset);
109         brender_tools->create_objects(x, 
110                 y, 
111                 0,  // Include tools for audio
112                 1,  // Include tools for video
113                 0,  // Include checkbox for audio
114                 0,  // Include checkbox for video
115                 0,
116                 1,
117                 0,  // Select compressors to be offered
118                 0,  // Prompt for recording options
119                 0,  // If nonzero, prompt for insertion strategy
120                 1); // Supply file formats for background rendering
121         x = xmargin1;
124 // Renderfarm
125         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
126         y += 5;
129         add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, resources->text_default));
130         y += 25;
132         add_subwindow(new PrefsRenderFarm(pwindow, x, y));
133         add_subwindow(new BC_Title(x + xmargin4, y, _("Nodes:")));
134         y += 30;
135         add_subwindow(new BC_Title(x, y, _("Hostname:")));
136         add_subwindow(new BC_Title(x + xmargin3, y, _("Port:")));
137         add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow, 
138                 this, 
139                 x + xmargin4, 
140                 y - 5));
141 #if 0
142 N_("Master node framerate: %0.3f")
143 #endif
144 #define MASTER_NODE_FRAMERATE_TEXT "Master node framerate: %0.3f"
145         sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT), 
146                 pwindow->thread->preferences->local_rate);
147         add_subwindow(master_rate = new BC_Title(x + xmargin4, y + node_list->get_h(), string));
149         y += 25;
150         add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow, 
151                 this, 
152                 x, 
153                 y));
154         edit_port = new PrefsRenderFarmPort(pwindow, 
155                 this, 
156                 x + xmargin3, 
157                 y);
158         edit_port->create_objects();
160         y += 30;
163         add_subwindow(new PrefsRenderFarmReplaceNode(pwindow, 
164                 this, 
165                 x, 
166                 y));
167         add_subwindow(new PrefsRenderFarmNewNode(pwindow, 
168                 this, 
169                 x + xmargin2, 
170                 y));
171         y += 30;
172         add_subwindow(new PrefsRenderFarmDelNode(pwindow, 
173                 this, 
174                 x + xmargin2, 
175                 y));
176         add_subwindow(new PrefsRenderFarmSortNodes(pwindow, 
177                 this, 
178                 x, 
179                 y));
180         y += 30;
181         add_subwindow(new PrefsRenderFarmReset(pwindow, 
182                 this, 
183                 x, 
184                 y));
185         y += 35;
186         add_subwindow(new BC_Title(x, 
187                 y, 
188                 _("Total jobs to create:")));
189         add_subwindow(new BC_Title(x, 
190                 y + 30, 
191                 _("(overridden if new file at each label is checked)")));
192         PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow, 
193                 this, 
194                 x + xmargin3, 
195                 y);
196         jobs->create_objects();
197         y += 55;
198 //      add_subwindow(new PrefsRenderFarmVFS(pwindow,
199 //              this,
200 //              x,
201 //              y));
202 //      add_subwindow(new BC_Title(x, 
203 //              y, 
204 //              _("Filesystem prefix on remote nodes:")));
205 //      add_subwindow(new PrefsRenderFarmMountpoint(pwindow, 
206 //              this, 
207 //              x + xmargin3, 
208 //              y));
209 //      y += 30;
211         return 0;
214 void PerformancePrefs::generate_node_list()
216         int selected_row = node_list ? node_list->get_selection_number(0, 0) : -1;
217         nodes[0].remove_all_objects();
218         nodes[1].remove_all_objects();
219         nodes[2].remove_all_objects();
220         nodes[3].remove_all_objects();
221         for(int i = 0; 
222                 i < pwindow->thread->preferences->renderfarm_nodes.total; 
223                 i++)
224         {
225                 BC_ListBoxItem *item;
226                 nodes[0].append(item = new BC_ListBoxItem(
227                         (char*)(pwindow->thread->preferences->renderfarm_enabled.values[i] ? "X" : " ")));
228                 if(i == selected_row) item->set_selected(1);
230                 nodes[1].append(item = new BC_ListBoxItem(
231                         pwindow->thread->preferences->renderfarm_nodes.values[i]));
232                 if(i == selected_row) item->set_selected(1);
234                 char string[BCTEXTLEN];
235                 sprintf(string, "%d", pwindow->thread->preferences->renderfarm_ports.values[i]);
236                 nodes[2].append(item = new BC_ListBoxItem(string));
237                 if(i == selected_row) item->set_selected(1);
239                 sprintf(string, "%0.3f", pwindow->thread->preferences->renderfarm_rate.values[i]);
240                 nodes[3].append(item = new BC_ListBoxItem(string));
241                 if(i == selected_row) item->set_selected(1);
242         }
245 static char *titles[] = 
247         N_("On"),
248         N_("Hostname"),
249         N_("Port"),
250         N_("Framerate")
253 static int widths[] = 
255         30,
256         150,
257         50,
258         50
262 void PerformancePrefs::update_node_list()
264         node_list->update(nodes,
265                                                 titles,
266                                                 widths,
267                                                 4,
268                                                 node_list->get_xposition(),
269                                                 node_list->get_yposition(),
270                                                 node_list->get_selection_number(0, 0));
275 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow, 
276         int x,
277         int y)
278  : BC_CheckBox(x, 
279         y, 
280         pwindow->thread->preferences->use_brender, 
281         _("Use background rendering"))
283         this->pwindow = pwindow;
286 int PrefsUseBRender::handle_event()
288         pwindow->thread->redraw_overlays = 1;
289         pwindow->thread->redraw_times = 1;
290         pwindow->thread->preferences->use_brender = get_value();
291         return 1;
299 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow, 
300         PerformancePrefs *subwindow, 
301         int x, 
302         int y)
303  : BC_TumbleTextBox(subwindow, 
304         (int64_t)pwindow->thread->preferences->brender_fragment,
305         (int64_t)1, 
306         (int64_t)65535,
307         x,
308         y,
309         100)
311         this->pwindow = pwindow;
313 int PrefsBRenderFragment::handle_event()
315         pwindow->thread->preferences->brender_fragment = atol(get_text());
316         return 1;
329 CICacheSize::CICacheSize(int x, 
330         int y, 
331         PreferencesWindow *pwindow, 
332         PerformancePrefs *subwindow)
333  : BC_TumbleTextBox(subwindow,
334         (int64_t)pwindow->thread->preferences->cache_size / 0x100000,
335         (int64_t)MIN_CACHE_SIZE / 0x100000,
336         (int64_t)MAX_CACHE_SIZE / 0x100000,
337         x, 
338         y, 
339         100)
341         this->pwindow = pwindow;
342         set_increment(1);
345 int CICacheSize::handle_event()
347         int64_t result;
348         result = (int64_t)atol(get_text()) * 0x100000;
349         CLAMP(result, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
350         pwindow->thread->preferences->cache_size = result;
351         return 0;
355 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow, 
356                 PerformancePrefs *subwindow, 
357                 int x, 
358                 int y)
359  : BC_TumbleTextBox(subwindow, 
360         (float)pwindow->thread->preferences->render_preroll,
361         (float)0, 
362         (float)100,
363         x,
364         y,
365         100)
367         this->pwindow = pwindow;
368         set_increment(0.1);
370 PrefsRenderPreroll::~PrefsRenderPreroll()
373 int PrefsRenderPreroll::handle_event()
375         pwindow->thread->preferences->render_preroll = atof(get_text());
376         return 1;
380 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow, 
381                 PerformancePrefs *subwindow, 
382                 int x, 
383                 int y)
384  : BC_TumbleTextBox(subwindow, 
385         (int64_t)pwindow->thread->preferences->brender_preroll,
386         (int64_t)0, 
387         (int64_t)100,
388         x,
389         y,
390         100)
392         this->pwindow = pwindow;
394 int PrefsBRenderPreroll::handle_event()
396         pwindow->thread->preferences->brender_preroll = atol(get_text());
397         return 1;
410 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y)
411  : BC_CheckBox(x, 
412         y, 
413         pwindow->thread->preferences->use_renderfarm,
414         _("Use render farm"))
416         this->pwindow = pwindow;
418 PrefsRenderFarm::~PrefsRenderFarm()
421 int PrefsRenderFarm::handle_event()
423         pwindow->thread->preferences->use_renderfarm = get_value();
424         return 1;
430 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
431  : BC_CheckBox(x, 
432         y, 
433         pwindow->thread->preferences->force_uniprocessor,
434         _("Force single processor use"))
436         this->pwindow = pwindow;
438 PrefsForceUniprocessor::~PrefsForceUniprocessor()
441 int PrefsForceUniprocessor::handle_event()
443         pwindow->thread->preferences->force_uniprocessor = get_value();
444         return 1;
453 PrefsRenderFarmConsolidate::PrefsRenderFarmConsolidate(PreferencesWindow *pwindow, int x, int y)
454  : BC_CheckBox(x, 
455         y, 
456         pwindow->thread->preferences->renderfarm_consolidate,
457         _("Consolidate output files on completion"))
459         this->pwindow = pwindow;
461 PrefsRenderFarmConsolidate::~PrefsRenderFarmConsolidate()
464 int PrefsRenderFarmConsolidate::handle_event()
466         pwindow->thread->preferences->renderfarm_consolidate = get_value();
467         return 1;
474 PrefsRenderFarmPort::PrefsRenderFarmPort(PreferencesWindow *pwindow, 
475         PerformancePrefs *subwindow, 
476         int x, 
477         int y)
478  : BC_TumbleTextBox(subwindow, 
479         (int64_t)pwindow->thread->preferences->renderfarm_port,
480         (int64_t)1, 
481         (int64_t)65535,
482         x,
483         y,
484         100)
486         this->pwindow = pwindow;
489 PrefsRenderFarmPort::~PrefsRenderFarmPort()
493 int PrefsRenderFarmPort::handle_event()
495         pwindow->thread->preferences->renderfarm_port = atol(get_text());
496         return 1;
501 PrefsRenderFarmNodes::PrefsRenderFarmNodes(PreferencesWindow *pwindow, 
502         PerformancePrefs *subwindow, int x, int y)
503  : BC_ListBox(x, 
504                 y, 
505                 340, 
506                 230,
507                 LISTBOX_TEXT,                         // Display text list or icons
508                 subwindow->nodes,
509                 titles,
510                 widths,
511                 4)
513         this->subwindow = subwindow;
514         this->pwindow = pwindow;
516 PrefsRenderFarmNodes::~PrefsRenderFarmNodes()
520 int PrefsRenderFarmNodes::column_resize_event()
522         for(int i = 0; i < 3; i++)
523                 widths[i] = get_column_width(i);
524         return 1;
527 int PrefsRenderFarmNodes::handle_event()
529 SET_TRACE
530         if(get_selection_number(0, 0) >= 0)
531         {
532                 subwindow->hot_node = get_selection_number(1, 0);
533                 subwindow->edit_node->update(get_selection(1, 0)->get_text());
534                 subwindow->edit_port->update(get_selection(2, 0)->get_text());
535                 if(get_cursor_x() < widths[0])
536                 {
537                         pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node] = 
538                                 !pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node];
539                         subwindow->generate_node_list();
540                         subwindow->update_node_list();
541                 }
542         }
543         else
544         {
545                 subwindow->hot_node = -1;
546                 subwindow->edit_node->update("");
547         }
548 SET_TRACE
549         return 1;
550 }       
551 int PrefsRenderFarmNodes::selection_changed()
553         handle_event();
554         return 1;
563 PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
564  : BC_TextBox(x, y, 240, 1, "")
566         this->pwindow = pwindow;
567         this->subwindow = subwindow;
570 PrefsRenderFarmEditNode::~PrefsRenderFarmEditNode()
574 int PrefsRenderFarmEditNode::handle_event()
576         return 1;
584 PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
585  : BC_GenericButton(x, y, _("Add Node"))
587         this->pwindow = pwindow;
588         this->subwindow = subwindow;
590 PrefsRenderFarmNewNode::~PrefsRenderFarmNewNode()
593 int PrefsRenderFarmNewNode::handle_event()
595         pwindow->thread->preferences->add_node(subwindow->edit_node->get_text(),
596                 pwindow->thread->preferences->renderfarm_port,
597                 1,
598                 0.0);
599         pwindow->thread->preferences->reset_rates();
600         subwindow->generate_node_list();
601         subwindow->update_node_list();
602         subwindow->hot_node = -1;
603         return 1;
612 PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
613  : BC_GenericButton(x, y, _("Apply Changes"))
615         this->pwindow = pwindow;
616         this->subwindow = subwindow;
618 PrefsRenderFarmReplaceNode::~PrefsRenderFarmReplaceNode()
621 int PrefsRenderFarmReplaceNode::handle_event()
623         if(subwindow->hot_node >= 0)
624         {
625                 pwindow->thread->preferences->edit_node(subwindow->hot_node, 
626                         subwindow->edit_node->get_text(),
627                         pwindow->thread->preferences->renderfarm_port,
628                         pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node]);
629                 subwindow->generate_node_list();
630                 subwindow->update_node_list();
631         }
632         return 1;
639 PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
640  : BC_GenericButton(x, y, _("Delete Node"))
642         this->pwindow = pwindow;
643         this->subwindow = subwindow;
645 PrefsRenderFarmDelNode::~PrefsRenderFarmDelNode()
648 int PrefsRenderFarmDelNode::handle_event()
650         if(strlen(subwindow->edit_node->get_text()))
651         {
652                 pwindow->thread->preferences->delete_node(subwindow->hot_node);
653                 subwindow->generate_node_list();
654                 subwindow->update_node_list();
655                 subwindow->hot_node = -1;
656         }
657         return 1;
664 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow, 
665         PerformancePrefs *subwindow, 
666         int x, 
667         int y)
668  : BC_GenericButton(x, y, _("Sort nodes"))
670         this->pwindow = pwindow;
671         this->subwindow = subwindow;
674 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
678 int PrefsRenderFarmSortNodes::handle_event()
680         pwindow->thread->preferences->sort_nodes();
681         subwindow->generate_node_list();
682         subwindow->update_node_list();
683         subwindow->hot_node = -1;
684         return 1;
691 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow, 
692         PerformancePrefs *subwindow, 
693         int x, 
694         int y)
695  : BC_GenericButton(x, y, _("Reset rates"))
697         this->pwindow = pwindow;
698         this->subwindow = subwindow;
701 int PrefsRenderFarmReset::handle_event()
703         pwindow->thread->preferences->reset_rates();
704         subwindow->generate_node_list();
705         subwindow->update_node_list();
707         char string[BCTEXTLEN];
708         sprintf(string, 
709                 MASTER_NODE_FRAMERATE_TEXT, 
710                 pwindow->thread->preferences->local_rate);
711         subwindow->master_rate->update(string);
712         subwindow->hot_node = -1;
713         return 1;
722 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow, 
723                 PerformancePrefs *subwindow, 
724                 int x, 
725                 int y)
726  : BC_TumbleTextBox(subwindow, 
727         (int64_t)pwindow->thread->preferences->renderfarm_job_count,
728         (int64_t)1, 
729         (int64_t)100,
730         x,
731         y,
732         100)
734         this->pwindow = pwindow;
736 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
739 int PrefsRenderFarmJobs::handle_event()
741         pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
742         return 1;
747 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow, 
748                 PerformancePrefs *subwindow, 
749                 int x, 
750                 int y)
751  : BC_TextBox(x, 
752         y, 
753         100,
754         1,
755         pwindow->thread->preferences->renderfarm_mountpoint)
757         this->pwindow = pwindow;
758         this->subwindow = subwindow;
760 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
763 int PrefsRenderFarmMountpoint::handle_event()
765         strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
766         return 1;
772 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
773         PerformancePrefs *subwindow,
774         int x,
775         int y)
776  : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs, _("Use virtual filesystem"))
778         this->pwindow = pwindow;
779         this->subwindow = subwindow;
782 int PrefsRenderFarmVFS::handle_event()
784         pwindow->thread->preferences->renderfarm_vfs = get_value();
785         return 1;