4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcsignals.h"
25 #include "edlsession.h"
26 #include "formattools.h"
29 #include "performanceprefs.h"
30 #include "preferences.h"
35 #define MASTER_NODE_FRAMERATE_TEXT "Master node framerate: %0.3f"
37 N_(MASTER_NODE_FRAMERATE_TEXT)
40 PerformancePrefs::PerformancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
41 : PreferencesDialog(mwindow, pwindow)
46 PerformancePrefs::~PerformancePrefs()
49 nodes[0].remove_all_objects();
50 nodes[1].remove_all_objects();
51 nodes[2].remove_all_objects();
52 nodes[3].remove_all_objects();
55 void PerformancePrefs::create_objects()
62 char string[BCTEXTLEN];
63 BC_Resources *resources = BC_WindowBase::get_resources();
70 xmargin1 = x = mwindow->theme->preferencesoptions_x;
71 y = mwindow->theme->preferencesoptions_y;
74 win = add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default));
78 win = add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
79 if((curw = win->get_w()) > maxw)
83 cache_size = new CICacheSize(maxw, y0, pwindow, this);
84 cache_size->create_objects();
86 add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
87 PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow, this, maxw, y1);
88 preroll->create_objects();
91 int x1 = x + xmargin4;
92 BC_Title *smp_title = new BC_Title(x1, y + 5, _("Project SMP cpus:"));
93 add_subwindow(smp_title);
94 int x2 = x1 + smp_title->get_w() + 5;
95 PrefsProjectSMP *proj_smp = new PrefsProjectSMP(pwindow, this, x2, y);
96 proj_smp->create_objects();
98 PrefsForceUniprocessor *force_1cpu = new PrefsForceUniprocessor(pwindow, x, y);
99 add_subwindow(force_1cpu);
102 // Background rendering
103 add_subwindow(new BC_Bar(5, y, get_w() - 10));
107 add_subwindow(new BC_Title(x, y, _("Background Rendering (Video only)"), LARGEFONT, resources->text_default));
110 win = add_subwindow(new PrefsUseBRender(pwindow, x, y));
112 y += win->get_h() + 10;
113 win = add_subwindow(new BC_Title(x, y, _("Frames per background rendering job:")));
114 y += win->get_h() + 5;
115 PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow, this,
117 brender_fragment->create_objects();
118 y += brender_fragment->get_h() + 5;
119 win = add_subwindow(new BC_Title(x, y, _("Frames to preroll background:")));
120 y += win->get_h() + 5;
121 PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow, this,
122 x + xmargin3, y + 5);
123 bpreroll->create_objects();
124 y += bpreroll->get_h() + 20;
127 add_subwindow(new BC_Title(x, y1, _("Output for background rendering:")));
129 brender_tools = new FormatTools(mwindow, this,
130 pwindow->thread->preferences->brender_asset);
131 brender_tools->create_objects(x, y1,
132 0, // Include tools for audio
133 1, // Include tools for video
134 0, // Include checkbox for audio
135 0, // Include checkbox for video
138 0, // Select compressors to be offered
139 0, // Prompt for recording options
140 0, // prompt for use labels
141 1); // Supply file formats for background rendering
146 add_subwindow(new BC_Bar(5, y, get_w() - 10));
148 add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, resources->text_default));
149 x1 = get_w() - BC_GenericButton::calculate_w(this, _("Reset rates")) - x;
150 add_subwindow(new PrefsRenderFarmReset(pwindow, this, x1, y));
152 BC_Title *node_title = new BC_Title(x1, y, _("Nodes:"));
153 add_subwindow(node_title);
154 x1 += node_title->get_w() + 15;
155 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
156 pwindow->thread->preferences->local_rate);
157 add_subwindow(master_rate = new BC_Title(x1, y, string));
158 add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow, this, x + xmargin4, y+=25));
159 add_subwindow(new PrefsRenderFarm(pwindow, x, y+=5));
160 add_subwindow(new BC_Title(x, y+=30, _("Hostname:")));
161 add_subwindow(new BC_Title(x + xmargin3, y, _("Port:")));
162 add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow, this, x, y+=25));
163 edit_port = new PrefsRenderFarmPort(pwindow, this, x+xmargin3, y);
164 edit_port->create_objects();
166 add_subwindow(new PrefsRenderFarmReplaceNode(pwindow, this, x, y+=30));
167 add_subwindow(new PrefsRenderFarmNewNode(pwindow, this, x+xmargin2, y));
168 add_subwindow(new PrefsRenderFarmSortNodes(pwindow, this, x, y+=30));
169 add_subwindow(new PrefsRenderFarmDelNode(pwindow, this, x+xmargin2, y));
170 add_subwindow(new BC_Title(x, y+=35, _("Client Watchdog Timeout:")));
171 renderfarm_watchdog = new PrefsRenderFarmWatchdog(pwindow, this, x+xmargin3, y-5);
172 renderfarm_watchdog->create_objects();
173 add_subwindow(new BC_Title(x, y+=35, _("Total jobs to create:")));
174 PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow, this,
176 jobs->create_objects();
177 y += jobs->get_h() + 5;
178 win = add_subwindow(new BC_Title(x, y,
179 _("(overridden if new file at each label is checked)")));
180 // y += win->get_h() + 5;
181 // add_subwindow(new PrefsRenderFarmVFS(pwindow, this, x, y));
182 // add_subwindow(new BC_Title(x, y,
183 // _("Filesystem prefix on remote nodes:")));
184 // add_subwindow(new PrefsRenderFarmMountpoint(pwindow, this, x + xmargin3, y));
188 void PerformancePrefs::generate_node_list()
190 int selected_row = node_list ? node_list->get_selection_number(0, 0) : -1;
192 for(int i = 0; i < TOTAL_COLUMNS; i++)
193 nodes[i].remove_all_objects();
196 i < pwindow->thread->preferences->renderfarm_nodes.size();
199 BC_ListBoxItem *item;
200 nodes[ENABLED_COLUMN].append(item = new BC_ListBoxItem(
201 (char*)(pwindow->thread->preferences->renderfarm_enabled.get(i) ? "X" : " ")));
202 if(i == selected_row) item->set_selected(1);
204 nodes[HOSTNAME_COLUMN].append(item = new BC_ListBoxItem(
205 pwindow->thread->preferences->renderfarm_nodes.get(i)));
206 if(i == selected_row) item->set_selected(1);
208 char string[BCTEXTLEN];
209 sprintf(string, "%d", pwindow->thread->preferences->renderfarm_ports.get(i));
210 nodes[PORT_COLUMN].append(item = new BC_ListBoxItem(string));
211 if(i == selected_row) item->set_selected(1);
213 sprintf(string, "%0.3f", pwindow->thread->preferences->renderfarm_rate.get(i));
214 nodes[RATE_COLUMN].append(item = new BC_ListBoxItem(string));
215 if(i == selected_row) item->set_selected(1);
220 static const char *default_titles[] = {
221 N_("On"), N_("Hostname"), N_("Port"), N_("Framerate")
224 static int default_widths[] = {
229 void PerformancePrefs::update_node_list()
231 node_list->update_list();
234 void PrefsRenderFarmNodes::update_list()
236 update(subwindow->nodes, titles, widths, PerformancePrefs::TOTAL_COLUMNS,
237 get_xposition(), get_yposition(), get_selection_number(0, 0));
241 void PerformancePrefs::update_rates()
243 //printf("PerformancePrefs::update_rates %d\n", __LINE__);
244 char string[BCTEXTLEN];
246 i < mwindow->preferences->renderfarm_rate.size();
249 if(i < nodes[RATE_COLUMN].size())
251 sprintf(string, "%0.3f", mwindow->preferences->renderfarm_rate.get(i));
252 nodes[RATE_COLUMN].get(i)->set_text(string);
256 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
257 mwindow->preferences->local_rate);
258 master_rate->update(string);
264 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow,
269 pwindow->thread->preferences->use_brender,
270 _("Use background rendering"))
272 this->pwindow = pwindow;
275 int PrefsUseBRender::handle_event()
277 pwindow->thread->redraw_overlays = 1;
278 pwindow->thread->redraw_times = 1;
279 pwindow->thread->preferences->use_brender = get_value();
284 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow,
285 PerformancePrefs *subwindow, int x, int y)
286 : BC_TumbleTextBox(subwindow,
287 (int64_t)pwindow->thread->preferences->brender_fragment,
288 (int64_t)1, (int64_t)65535, x, y, 100)
290 this->pwindow = pwindow;
292 int PrefsBRenderFragment::handle_event()
294 pwindow->thread->preferences->brender_fragment = atol(get_text());
298 CICacheSize::CICacheSize(int x, int y,
299 PreferencesWindow *pwindow, PerformancePrefs *subwindow)
300 : BC_TumbleTextBox(subwindow,
301 (int64_t)pwindow->thread->preferences->cache_size / 0x100000,
302 (int64_t)MIN_CACHE_SIZE / 0x100000,
303 (int64_t)MAX_CACHE_SIZE / 0x100000,
306 this->pwindow = pwindow;
310 int CICacheSize::handle_event()
313 result = (int64_t)atol(get_text()) * 0x100000;
314 CLAMP(result, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
315 pwindow->thread->preferences->cache_size = result;
320 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow,
321 PerformancePrefs *subwindow,
324 : BC_TumbleTextBox(subwindow,
325 (float)pwindow->thread->preferences->render_preroll,
332 this->pwindow = pwindow;
335 PrefsRenderPreroll::~PrefsRenderPreroll()
338 int PrefsRenderPreroll::handle_event()
340 pwindow->thread->preferences->render_preroll = atof(get_text());
345 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow,
346 PerformancePrefs *subwindow,
349 : BC_TumbleTextBox(subwindow,
350 (int64_t)pwindow->thread->preferences->brender_preroll,
357 this->pwindow = pwindow;
359 int PrefsBRenderPreroll::handle_event()
361 pwindow->thread->preferences->brender_preroll = atol(get_text());
366 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y)
369 pwindow->thread->preferences->use_renderfarm,
370 _("Use render farm"))
372 this->pwindow = pwindow;
374 PrefsRenderFarm::~PrefsRenderFarm()
377 int PrefsRenderFarm::handle_event()
379 pwindow->thread->preferences->use_renderfarm = get_value();
384 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
387 pwindow->thread->preferences->force_uniprocessor,
388 _("Force single processor use"))
390 this->pwindow = pwindow;
392 PrefsForceUniprocessor::~PrefsForceUniprocessor()
395 int PrefsForceUniprocessor::handle_event()
397 pwindow->thread->preferences->force_uniprocessor = get_value();
403 PrefsRenderFarmConsolidate::PrefsRenderFarmConsolidate(PreferencesWindow *pwindow, int x, int y)
406 pwindow->thread->preferences->renderfarm_consolidate,
407 _("Consolidate output files on completion"))
409 this->pwindow = pwindow;
411 PrefsRenderFarmConsolidate::~PrefsRenderFarmConsolidate()
414 int PrefsRenderFarmConsolidate::handle_event()
416 pwindow->thread->preferences->renderfarm_consolidate = get_value();
421 PrefsRenderFarmPort::PrefsRenderFarmPort(PreferencesWindow *pwindow,
422 PerformancePrefs *subwindow,
425 : BC_TumbleTextBox(subwindow,
426 (int64_t)pwindow->thread->preferences->renderfarm_port,
433 this->pwindow = pwindow;
436 PrefsRenderFarmPort::~PrefsRenderFarmPort()
440 int PrefsRenderFarmPort::handle_event()
442 pwindow->thread->preferences->renderfarm_port = atol(get_text());
448 PrefsRenderFarmNodes::PrefsRenderFarmNodes(PreferencesWindow *pwindow,
449 PerformancePrefs *subwindow, int x, int y)
450 : BC_ListBox(x, y, 340, 230, LISTBOX_TEXT, 0,0,0,1, 0,0, LISTBOX_MULTIPLE)
452 for( int i=0; i<PerformancePrefs::TOTAL_COLUMNS; ++i ) {
453 titles[i] = _(default_titles[i]);
454 widths[i] = default_widths[i];
456 update(subwindow->nodes, titles, widths, PerformancePrefs::TOTAL_COLUMNS,
458 this->subwindow = subwindow;
459 this->pwindow = pwindow;
461 PrefsRenderFarmNodes::~PrefsRenderFarmNodes()
465 int PrefsRenderFarmNodes::column_resize_event()
467 for( int i=0; i<PerformancePrefs::TOTAL_COLUMNS; ++i )
468 widths[i] = get_column_width(i);
472 int PrefsRenderFarmNodes::handle_event()
475 if(get_selection_number(0, 0) >= 0)
477 subwindow->hot_node = get_selection_number(1, 0);
478 subwindow->edit_node->update(get_selection(1, 0)->get_text());
479 const char *text = get_selection(2, 0)->get_text();
480 subwindow->edit_port->update(text);
481 pwindow->thread->preferences->renderfarm_port = atol(text);
482 if(get_cursor_x() < widths[0])
484 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node] =
485 !pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node];
486 subwindow->generate_node_list();
487 subwindow->update_node_list();
492 subwindow->hot_node = -1;
493 subwindow->edit_node->update("");
498 int PrefsRenderFarmNodes::selection_changed()
505 PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
506 : BC_TextBox(x, y, 240, 1, "")
508 this->pwindow = pwindow;
509 this->subwindow = subwindow;
512 PrefsRenderFarmEditNode::~PrefsRenderFarmEditNode()
516 int PrefsRenderFarmEditNode::handle_event()
522 PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
523 : BC_GenericButton(x, y, _("Add Nodes"))
525 this->pwindow = pwindow;
526 this->subwindow = subwindow;
528 PrefsRenderFarmNewNode::~PrefsRenderFarmNewNode()
531 int PrefsRenderFarmNewNode::handle_event()
533 const char *name = subwindow->edit_node->get_text();
534 char *cp = (char*)subwindow->edit_port->get_text();
535 int64_t start_port = strtol(cp, &cp, 0), end_port = start_port;
536 while( isspace(*cp) ) ++cp;
538 end_port = strtol(cp, &cp, 0);
539 for( int port=start_port; port<=end_port; ++port ) {
540 pwindow->thread->preferences->add_node(name, port, 1, 0.0);
542 pwindow->thread->preferences->renderfarm_port = end_port;
543 subwindow->edit_port->update(end_port);
544 pwindow->thread->preferences->reset_rates();
545 subwindow->generate_node_list();
546 subwindow->update_node_list();
547 subwindow->hot_node = -1;
552 PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
553 : BC_GenericButton(x, y, _("Apply Changes"))
555 this->pwindow = pwindow;
556 this->subwindow = subwindow;
558 PrefsRenderFarmReplaceNode::~PrefsRenderFarmReplaceNode()
561 int PrefsRenderFarmReplaceNode::handle_event()
563 if(subwindow->hot_node >= 0)
565 pwindow->thread->preferences->edit_node(subwindow->hot_node,
566 subwindow->edit_node->get_text(),
567 pwindow->thread->preferences->renderfarm_port,
568 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node]);
569 subwindow->generate_node_list();
570 subwindow->update_node_list();
576 PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
577 : BC_GenericButton(x, y, _("Delete Nodes"))
579 this->pwindow = pwindow;
580 this->subwindow = subwindow;
582 PrefsRenderFarmDelNode::~PrefsRenderFarmDelNode()
585 int PrefsRenderFarmDelNode::handle_event()
587 ArrayList<BC_ListBoxItem *> &item_list = subwindow->nodes[0];
588 for( int i=item_list.size(); --i>=0; ) {
589 if( !item_list[i]->get_selected() ) continue;
590 pwindow->thread->preferences->delete_node(i);
592 subwindow->generate_node_list();
593 subwindow->update_node_list();
594 subwindow->hot_node = -1;
599 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow,
600 PerformancePrefs *subwindow,
603 : BC_GenericButton(x, y, _("Sort nodes"))
605 this->pwindow = pwindow;
606 this->subwindow = subwindow;
609 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
613 int PrefsRenderFarmSortNodes::handle_event()
615 pwindow->thread->preferences->sort_nodes();
616 subwindow->generate_node_list();
617 subwindow->update_node_list();
618 subwindow->hot_node = -1;
623 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow,
624 PerformancePrefs *subwindow, int x, int y)
625 : BC_GenericButton(x, y, _("Reset rates"))
627 this->pwindow = pwindow;
628 this->subwindow = subwindow;
631 int PrefsRenderFarmReset::handle_event()
633 pwindow->thread->preferences->reset_rates();
634 subwindow->generate_node_list();
635 subwindow->update_node_list();
637 char string[BCTEXTLEN];
639 _(MASTER_NODE_FRAMERATE_TEXT),
640 pwindow->thread->preferences->local_rate);
641 subwindow->master_rate->update(string);
642 subwindow->hot_node = -1;
647 PrefsProjectSMP::PrefsProjectSMP(PreferencesWindow *pwindow,
648 PerformancePrefs *subwindow, int x, int y)
649 : BC_TumbleTextBox(subwindow,
650 (int64_t)pwindow->thread->preferences->project_smp,
651 (int64_t)1, (int64_t)100, x, y, 100)
653 this->pwindow = pwindow;
655 PrefsProjectSMP::~PrefsProjectSMP()
658 int PrefsProjectSMP::handle_event()
660 pwindow->thread->preferences->project_smp = atol(get_text());
665 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow,
666 PerformancePrefs *subwindow,
669 : BC_TumbleTextBox(subwindow,
670 (int64_t)pwindow->thread->preferences->renderfarm_job_count,
671 (int64_t)1, (int64_t)100, x, y, 100)
673 this->pwindow = pwindow;
675 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
678 int PrefsRenderFarmJobs::handle_event()
680 pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
685 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow,
686 PerformancePrefs *subwindow, int x, int y)
687 : BC_TextBox(x, y, 100, 1,
688 pwindow->thread->preferences->renderfarm_mountpoint)
690 this->pwindow = pwindow;
691 this->subwindow = subwindow;
693 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
696 int PrefsRenderFarmMountpoint::handle_event()
698 strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
703 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
704 PerformancePrefs *subwindow, int x, int y)
705 : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs,
706 _("Use virtual filesystem"))
708 this->pwindow = pwindow;
709 this->subwindow = subwindow;
712 int PrefsRenderFarmVFS::handle_event()
714 pwindow->thread->preferences->renderfarm_vfs = get_value();
719 PrefsRenderFarmWatchdog::PrefsRenderFarmWatchdog(PreferencesWindow *pwindow,
720 PerformancePrefs *subwindow, int x, int y)
721 : BC_TumbleTextBox(subwindow,
722 (int64_t)pwindow->thread->preferences->renderfarm_watchdog_timeout,
723 (int64_t)0, (int64_t)1000, x, y, 100)
725 this->pwindow = pwindow;
729 int PrefsRenderFarmWatchdog::handle_event()
731 pwindow->thread->preferences->renderfarm_watchdog_timeout = atol(get_text());