r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / performanceprefs.C
blob35558e152f25ffd9a92d88599e7ef6e5566df4bd
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "formattools.h"
4 #include "mwindow.h"
5 #include "performanceprefs.h"
6 #include "preferences.h"
7 #include <string.h>
9 #include <libintl.h>
10 #define _(String) gettext(String)
11 #define gettext_noop(String) String
12 #define N_(String) gettext_noop (String)
15 PerformancePrefs::PerformancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
16  : PreferencesDialog(mwindow, pwindow)
18         hot_node = -1;
21 PerformancePrefs::~PerformancePrefs()
23         delete brender_tools;
24         nodes[0].remove_all_objects();
25         nodes[1].remove_all_objects();
26         nodes[2].remove_all_objects();
27         nodes[3].remove_all_objects();
30 int PerformancePrefs::create_objects()
32         int x = 5, y = 5;
33         int xmargin1 = 5;
34         int xmargin2 = 170;
35         int xmargin3 = 250;
36         int xmargin4 = 380;
37         char string[BCTEXTLEN];
39         node_list = 0;
40         generate_node_list();
42 //      add_border(get_resources()->get_bg_shadow1(),
43 //              get_resources()->get_bg_shadow2(),
44 //              get_resources()->get_bg_color(),
45 //              get_resources()->get_bg_light2(),
46 //              get_resources()->get_bg_light1());
47         add_subwindow(new BC_Title(x, y, _("Performance"), LARGEFONT, BLACK));
49         y += 30;
50         add_subwindow(new BC_Title(x, y + 5, _("Cache items:"), MEDIUMFONT, BLACK));
51         sprintf(string, "%ld", pwindow->thread->preferences->cache_size);
52         add_subwindow(csize = new CICacheSize(x + 230, y, pwindow, string));
53         y += 30;
54         add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
55         PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow, 
56                 this, 
57                 x + 230, 
58                 y);
59         preroll->create_objects();
60         y += 30;
61         add_subwindow(new PrefsForceUniprocessor(pwindow, x, y));
63         y += 35;
66         add_subwindow(new BC_Title(x, y, _("Background Rendering"), LARGEFONT, BLACK));
67         y += 30;
69         add_subwindow(new PrefsUseBRender(pwindow, 
70                 x,
71                 y));
74         add_subwindow(new BC_Title(x, y + 40, _("Frames per background rendering job:")));
75         PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow, 
76                 this, 
77                 x, 
78                 y + 60);
79         brender_fragment->create_objects();
80         add_subwindow(new BC_Title(x, y + 95, _("Frames to preroll background:")));
81         PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow, 
82                 this, 
83                 x + xmargin3, 
84                 y + 90);
85         bpreroll->create_objects();
88         x += xmargin4;
89         add_subwindow(new BC_Title(x, y, _("Output for background rendering:")));
90         y += 20;
91         brender_tools = 
92                 new FormatTools(mwindow,
93                         this, 
94                         pwindow->thread->preferences->brender_asset);
95         brender_tools->create_objects(x, 
96                 y, 
97                 0,    // Include tools for audio
98                 1,   // Include tools for video
99                 0,  // Include checkbox for audio
100                 0,  // Include checkbox for video
101                 0,
102                 1,
103                 0,  // Select compressors to be offered
104                 0, // Change captions for recording
105                 0, // If nonzero, prompt for insertion strategy
106                 1); // Supply file formats for background rendering
107         x = xmargin1;
109         add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, BLACK));
110         y += 25;
112         add_subwindow(new PrefsRenderFarm(pwindow, x, y));
113         add_subwindow(new BC_Title(x + xmargin4, y, _("Nodes:")));
114         y += 30;
115         add_subwindow(new BC_Title(x, y, _("Hostname:")));
116         add_subwindow(new BC_Title(x + xmargin3, y, _("Port:")));
117         add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow, 
118                 this, 
119                 x + xmargin4, 
120                 y - 5));
121 #if 0
122 N_("Master node framerate: %0.3f")
123 #endif
124 #define MASTER_NODE_FRAMERATE_TEXT "Master node framerate: %0.3f"
125         sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT), 
126                 pwindow->thread->preferences->local_rate);
127         add_subwindow(master_rate = new BC_Title(x + xmargin4, y + node_list->get_h(), string));
129         y += 25;
130         add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow, 
131                 this, 
132                 x, 
133                 y));
134         edit_port = new PrefsRenderFarmPort(pwindow, 
135                 this, 
136                 x + xmargin3, 
137                 y);
138         edit_port->create_objects();
140         y += 30;
143         add_subwindow(new PrefsRenderFarmReplaceNode(pwindow, 
144                 this, 
145                 x, 
146                 y));
147         add_subwindow(new PrefsRenderFarmNewNode(pwindow, 
148                 this, 
149                 x + xmargin2, 
150                 y));
151         y += 30;
152         add_subwindow(new PrefsRenderFarmDelNode(pwindow, 
153                 this, 
154                 x + xmargin2, 
155                 y));
156         add_subwindow(new PrefsRenderFarmSortNodes(pwindow, 
157                 this, 
158                 x, 
159                 y));
160         y += 30;
161         add_subwindow(new PrefsRenderFarmReset(pwindow, 
162                 this, 
163                 x, 
164                 y));
165         y += 35;
166         add_subwindow(new BC_Title(x, 
167                 y, 
168                 _("Total jobs to create:")));
169         add_subwindow(new BC_Title(x, 
170                 y + 30, 
171                 _("(overridden if new file at each label is checked)")));
172         PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow, 
173                 this, 
174                 x + xmargin3, 
175                 y);
176         jobs->create_objects();
177         y += 55;
178         add_subwindow(new PrefsRenderFarmVFS(pwindow,
179                 this,
180                 x,
181                 y));
182 //      add_subwindow(new BC_Title(x, 
183 //              y, 
184 //              _("Filesystem prefix on remote nodes:")));
185 //      add_subwindow(new PrefsRenderFarmMountpoint(pwindow, 
186 //              this, 
187 //              x + xmargin3, 
188 //              y));
189 //      y += 30;
191         return 0;
194 void PerformancePrefs::generate_node_list()
196         int selected_row = node_list ? node_list->get_selection_number(0, 0) : -1;
197         nodes[0].remove_all_objects();
198         nodes[1].remove_all_objects();
199         nodes[2].remove_all_objects();
200         nodes[3].remove_all_objects();
201         for(int i = 0; 
202                 i < pwindow->thread->preferences->renderfarm_nodes.total; 
203                 i++)
204         {
205                 BC_ListBoxItem *item;
206                 nodes[0].append(item = new BC_ListBoxItem(
207                         (char*)(pwindow->thread->preferences->renderfarm_enabled.values[i] ? "X" : " ")));
208                 if(i == selected_row) item->set_selected(1);
210                 nodes[1].append(item = new BC_ListBoxItem(
211                         pwindow->thread->preferences->renderfarm_nodes.values[i]));
212                 if(i == selected_row) item->set_selected(1);
214                 char string[BCTEXTLEN];
215                 sprintf(string, "%d", pwindow->thread->preferences->renderfarm_ports.values[i]);
216                 nodes[2].append(item = new BC_ListBoxItem(string));
217                 if(i == selected_row) item->set_selected(1);
219                 sprintf(string, "%0.3f", pwindow->thread->preferences->renderfarm_rate.values[i]);
220                 nodes[3].append(item = new BC_ListBoxItem(string));
221                 if(i == selected_row) item->set_selected(1);
222         }
225 static char *titles[] = 
227         N_("On"),
228         N_("Hostname"),
229         N_("Port"),
230         N_("Framerate")
233 static int widths[] = 
235         30,
236         150,
237         50,
238         50
242 void PerformancePrefs::update_node_list()
244         node_list->update(nodes,
245                                                 titles,
246                                                 widths,
247                                                 4,
248                                                 node_list->get_xposition(),
249                                                 node_list->get_yposition(),
250                                                 node_list->get_selection_number(0, 0));
255 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow, 
256         int x,
257         int y)
258  : BC_CheckBox(x, 
259         y, 
260         pwindow->thread->preferences->use_brender, 
261         _("Use background rendering"))
263         this->pwindow = pwindow;
266 int PrefsUseBRender::handle_event()
268         pwindow->thread->redraw_overlays = 1;
269         pwindow->thread->redraw_times = 1;
270         pwindow->thread->preferences->use_brender = get_value();
271         return 1;
279 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow, 
280         PerformancePrefs *subwindow, 
281         int x, 
282         int y)
283  : BC_TumbleTextBox(subwindow, 
284         (int64_t)pwindow->thread->preferences->brender_fragment,
285         (int64_t)1, 
286         (int64_t)65535,
287         x,
288         y,
289         100)
291         this->pwindow = pwindow;
293 int PrefsBRenderFragment::handle_event()
295         pwindow->thread->preferences->brender_fragment = atol(get_text());
296         return 1;
308 PrefsSMP::PrefsSMP(int x, int y, PreferencesWindow *pwindow)
309  : BC_TextBox(x, y, 100, 1, pwindow->thread->edl->session->smp + 1)
311         this->pwindow = pwindow;
314 PrefsSMP::~PrefsSMP()
318 int PrefsSMP::handle_event()
320         pwindow->thread->edl->session->smp = atol(get_text()) - 1;
321         if(pwindow->thread->edl->session->smp < 0) pwindow->thread->edl->session->smp = 0;
322         return 0;
326 CICacheSize::CICacheSize(int x, int y, PreferencesWindow *pwindow, char *text)
327  : BC_TextBox(x, y, 100, 1, text)
329         this->pwindow = pwindow; 
332 int CICacheSize::handle_event()
334         int64_t result;
336         result = atol(get_text());
337         pwindow->thread->preferences->cache_size = result;
338         return 0;
342 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow, 
343                 PerformancePrefs *subwindow, 
344                 int x, 
345                 int y)
346  : BC_TumbleTextBox(subwindow, 
347         (float)pwindow->thread->preferences->render_preroll,
348         (float)0, 
349         (float)100,
350         x,
351         y,
352         100)
354         this->pwindow = pwindow;
356 PrefsRenderPreroll::~PrefsRenderPreroll()
359 int PrefsRenderPreroll::handle_event()
361         pwindow->thread->preferences->render_preroll = atof(get_text());
362         return 1;
366 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow, 
367                 PerformancePrefs *subwindow, 
368                 int x, 
369                 int y)
370  : BC_TumbleTextBox(subwindow, 
371         (int64_t)pwindow->thread->preferences->brender_preroll,
372         (int64_t)0, 
373         (int64_t)100,
374         x,
375         y,
376         100)
378         this->pwindow = pwindow;
380 int PrefsBRenderPreroll::handle_event()
382         pwindow->thread->preferences->brender_preroll = atol(get_text());
383         return 1;
396 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y)
397  : BC_CheckBox(x, 
398         y, 
399         pwindow->thread->preferences->use_renderfarm,
400         _("Use render farm"))
402         this->pwindow = pwindow;
404 PrefsRenderFarm::~PrefsRenderFarm()
407 int PrefsRenderFarm::handle_event()
409         pwindow->thread->preferences->use_renderfarm = get_value();
410         return 1;
416 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
417  : BC_CheckBox(x, 
418         y, 
419         pwindow->thread->edl->session->force_uniprocessor,
420         _("Force single processor use"))
422         this->pwindow = pwindow;
424 PrefsForceUniprocessor::~PrefsForceUniprocessor()
427 int PrefsForceUniprocessor::handle_event()
429         pwindow->thread->edl->session->force_uniprocessor = get_value();
430         return 1;
439 PrefsRenderFarmConsolidate::PrefsRenderFarmConsolidate(PreferencesWindow *pwindow, int x, int y)
440  : BC_CheckBox(x, 
441         y, 
442         pwindow->thread->preferences->renderfarm_consolidate,
443         _("Consolidate output files on completion"))
445         this->pwindow = pwindow;
447 PrefsRenderFarmConsolidate::~PrefsRenderFarmConsolidate()
450 int PrefsRenderFarmConsolidate::handle_event()
452         pwindow->thread->preferences->renderfarm_consolidate = get_value();
453         return 1;
460 PrefsRenderFarmPort::PrefsRenderFarmPort(PreferencesWindow *pwindow, 
461         PerformancePrefs *subwindow, 
462         int x, 
463         int y)
464  : BC_TumbleTextBox(subwindow, 
465         (int64_t)pwindow->thread->preferences->renderfarm_port,
466         (int64_t)1, 
467         (int64_t)65535,
468         x,
469         y,
470         100)
472         this->pwindow = pwindow;
475 PrefsRenderFarmPort::~PrefsRenderFarmPort()
479 int PrefsRenderFarmPort::handle_event()
481         pwindow->thread->preferences->renderfarm_port = atol(get_text());
482         return 1;
487 PrefsRenderFarmNodes::PrefsRenderFarmNodes(PreferencesWindow *pwindow, 
488         PerformancePrefs *subwindow, int x, int y)
489  : BC_ListBox(x, 
490                 y, 
491                 340, 
492                 230,
493                 LISTBOX_TEXT,                         // Display text list or icons
494                 subwindow->nodes,
495                 titles,
496                 widths,
497                 4)
499         this->subwindow = subwindow;
500         this->pwindow = pwindow;
502 PrefsRenderFarmNodes::~PrefsRenderFarmNodes()
506 int PrefsRenderFarmNodes::column_resize_event()
508         for(int i = 0; i < 3; i++)
509                 widths[i] = get_column_width(i);
510         return 1;
513 int PrefsRenderFarmNodes::handle_event()
515         if(get_selection_number(0, 0) >= 0)
516         {
517                 subwindow->hot_node = get_selection_number(1, 0);
518                 subwindow->edit_node->update(get_selection(1, 0)->get_text());
519                 subwindow->edit_port->update(get_selection(2, 0)->get_text());
520                 if(get_cursor_x() < widths[0])
521                 {
522                         pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node] = 
523                                 !pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node];
524                         subwindow->generate_node_list();
525                         subwindow->update_node_list();
526                 }
527         }
528         else
529         {
530                 subwindow->hot_node = -1;
531                 subwindow->edit_node->update("");
532         }
533         return 1;
534 }       
535 int PrefsRenderFarmNodes::selection_changed()
537         handle_event();
538         return 1;
547 PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
548  : BC_TextBox(x, y, 240, 1, "")
550         this->pwindow = pwindow;
551         this->subwindow = subwindow;
554 PrefsRenderFarmEditNode::~PrefsRenderFarmEditNode()
558 int PrefsRenderFarmEditNode::handle_event()
560         return 1;
568 PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
569  : BC_GenericButton(x, y, _("Add Node"))
571         this->pwindow = pwindow;
572         this->subwindow = subwindow;
574 PrefsRenderFarmNewNode::~PrefsRenderFarmNewNode()
577 int PrefsRenderFarmNewNode::handle_event()
579         pwindow->thread->preferences->add_node(subwindow->edit_node->get_text(),
580                 pwindow->thread->preferences->renderfarm_port,
581                 1,
582                 0.0);
583         pwindow->thread->preferences->reset_rates();
584         subwindow->generate_node_list();
585         subwindow->update_node_list();
586         subwindow->hot_node = -1;
587         return 1;
596 PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
597  : BC_GenericButton(x, y, _("Apply Changes"))
599         this->pwindow = pwindow;
600         this->subwindow = subwindow;
602 PrefsRenderFarmReplaceNode::~PrefsRenderFarmReplaceNode()
605 int PrefsRenderFarmReplaceNode::handle_event()
607         if(subwindow->hot_node >= 0)
608         {
609                 pwindow->thread->preferences->edit_node(subwindow->hot_node, 
610                         subwindow->edit_node->get_text(),
611                         pwindow->thread->preferences->renderfarm_port,
612                         pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node]);
613                 subwindow->generate_node_list();
614                 subwindow->update_node_list();
615         }
616         return 1;
623 PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
624  : BC_GenericButton(x, y, _("Delete Node"))
626         this->pwindow = pwindow;
627         this->subwindow = subwindow;
629 PrefsRenderFarmDelNode::~PrefsRenderFarmDelNode()
632 int PrefsRenderFarmDelNode::handle_event()
634         if(strlen(subwindow->edit_node->get_text()))
635         {
636                 pwindow->thread->preferences->delete_node(subwindow->hot_node);
637                 subwindow->generate_node_list();
638                 subwindow->update_node_list();
639                 subwindow->hot_node = -1;
640         }
641         return 1;
648 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow, 
649         PerformancePrefs *subwindow, 
650         int x, 
651         int y)
652  : BC_GenericButton(x, y, _("Sort nodes"))
654         this->pwindow = pwindow;
655         this->subwindow = subwindow;
658 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
662 int PrefsRenderFarmSortNodes::handle_event()
664         pwindow->thread->preferences->sort_nodes();
665         subwindow->generate_node_list();
666         subwindow->update_node_list();
667         subwindow->hot_node = -1;
668         return 1;
675 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow, 
676         PerformancePrefs *subwindow, 
677         int x, 
678         int y)
679  : BC_GenericButton(x, y, _("Reset rates"))
681         this->pwindow = pwindow;
682         this->subwindow = subwindow;
685 int PrefsRenderFarmReset::handle_event()
687         pwindow->thread->preferences->reset_rates();
688         subwindow->generate_node_list();
689         subwindow->update_node_list();
691         char string[BCTEXTLEN];
692         sprintf(string, 
693                 MASTER_NODE_FRAMERATE_TEXT, 
694                 pwindow->thread->preferences->local_rate);
695         subwindow->master_rate->update(string);
696         subwindow->hot_node = -1;
697         return 1;
706 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow, 
707                 PerformancePrefs *subwindow, 
708                 int x, 
709                 int y)
710  : BC_TumbleTextBox(subwindow, 
711         (int64_t)pwindow->thread->preferences->renderfarm_job_count,
712         (int64_t)1, 
713         (int64_t)100,
714         x,
715         y,
716         100)
718         this->pwindow = pwindow;
720 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
723 int PrefsRenderFarmJobs::handle_event()
725         pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
726         return 1;
731 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow, 
732                 PerformancePrefs *subwindow, 
733                 int x, 
734                 int y)
735  : BC_TextBox(x, 
736         y, 
737         100,
738         1,
739         pwindow->thread->preferences->renderfarm_mountpoint)
741         this->pwindow = pwindow;
742         this->subwindow = subwindow;
744 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
747 int PrefsRenderFarmMountpoint::handle_event()
749         strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
750         return 1;
756 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
757         PerformancePrefs *subwindow,
758         int x,
759         int y)
760  : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs, _("Use virtual filesystem"))
762         this->pwindow = pwindow;
763         this->subwindow = subwindow;
766 int PrefsRenderFarmVFS::handle_event()
768         pwindow->thread->preferences->renderfarm_vfs = get_value();
769         return 1;