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));
76 int x1 = x + xmargin4;
77 win = add_subwindow(new BC_Title(x1, y + 5, _("Use HW Device:")));
78 x1 += win->get_w() + 5;
79 PrefsUseHWDev *use_hw_dev = new PrefsUseHWDev(pwindow, this, x1, y);
80 use_hw_dev->create_objects();
83 win = add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
84 if((curw = win->get_w()) > maxw)
88 cache_size = new CICacheSize(maxw, y0, pwindow, this);
89 cache_size->create_objects();
91 add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
92 PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow, this, maxw, y1);
93 preroll->create_objects();
97 BC_Title *smp_title = new BC_Title(x1, y + 5, _("Project SMP cpus:"));
98 add_subwindow(smp_title);
99 x1 += smp_title->get_w() + 5;
100 PrefsProjectSMP *proj_smp = new PrefsProjectSMP(pwindow, this, x1, y);
101 proj_smp->create_objects();
103 PrefsForceUniprocessor *force_1cpu = new PrefsForceUniprocessor(pwindow, x, y);
104 add_subwindow(force_1cpu);
107 // Background rendering
108 add_subwindow(new BC_Bar(5, y, get_w() - 10));
112 add_subwindow(new BC_Title(x, y, _("Background Rendering (Video only)"), LARGEFONT, resources->text_default));
115 win = add_subwindow(new PrefsUseBRender(pwindow, x, y));
117 y += win->get_h() + 10;
118 win = add_subwindow(new BC_Title(x, y, _("Frames per background rendering job:")));
119 y += win->get_h() + 5;
120 PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow, this,
122 brender_fragment->create_objects();
123 y += brender_fragment->get_h() + 5;
124 win = add_subwindow(new BC_Title(x, y, _("Frames to preroll background:")));
125 y += win->get_h() + 5;
126 PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow, this,
127 x + xmargin3, y + 5);
128 bpreroll->create_objects();
129 y += bpreroll->get_h() + 20;
132 add_subwindow(new BC_Title(x, y1, _("Output for background rendering:")));
134 brender_tools = new FormatTools(mwindow, this,
135 pwindow->thread->preferences->brender_asset);
136 brender_tools->create_objects(x, y1,
137 0, // Include tools for audio
138 1, // Include tools for video
139 0, // Include checkbox for audio
140 0, // Include checkbox for video
143 0, // Select compressors to be offered
144 0, // Prompt for recording options
145 0, // prompt for use labels
146 1); // Supply file formats for background rendering
151 add_subwindow(new BC_Bar(5, y, get_w() - 10));
153 add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, resources->text_default));
154 x1 = get_w() - BC_GenericButton::calculate_w(this, _("Reset rates")) - x;
155 add_subwindow(new PrefsRenderFarmReset(pwindow, this, x1, y));
157 BC_Title *node_title = new BC_Title(x1, y, _("Nodes:"));
158 add_subwindow(node_title);
159 x1 += node_title->get_w() + 15;
160 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
161 pwindow->thread->preferences->local_rate);
162 add_subwindow(master_rate = new BC_Title(x1, y, string));
163 add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow, this, x + xmargin4, y+=25));
164 add_subwindow(new PrefsRenderFarm(pwindow, x, y+=5));
165 add_subwindow(new BC_Title(x, y+=30, _("Hostname:")));
166 add_subwindow(new BC_Title(x + xmargin3, y, _("Port:")));
167 add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow, this, x, y+=25));
168 edit_port = new PrefsRenderFarmPort(pwindow, this, x+xmargin3, y);
169 edit_port->create_objects();
171 add_subwindow(new PrefsRenderFarmReplaceNode(pwindow, this, x, y+=30));
172 add_subwindow(new PrefsRenderFarmNewNode(pwindow, this, x+xmargin2, y));
173 add_subwindow(new PrefsRenderFarmSortNodes(pwindow, this, x, y+=30));
174 add_subwindow(new PrefsRenderFarmDelNode(pwindow, this, x+xmargin2, y));
175 add_subwindow(new BC_Title(x, y+=35, _("Client Watchdog Timeout:")));
176 renderfarm_watchdog = new PrefsRenderFarmWatchdog(pwindow, this, x+xmargin3, y-5);
177 renderfarm_watchdog->create_objects();
178 add_subwindow(new BC_Title(x, y+=35, _("Total jobs to create:")));
179 PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow, this,
181 jobs->create_objects();
182 y += jobs->get_h() + 5;
183 win = add_subwindow(new BC_Title(x, y,
184 _("(overridden if new file at each label is checked)")));
185 // y += win->get_h() + 5;
186 // add_subwindow(new PrefsRenderFarmVFS(pwindow, this, x, y));
187 // add_subwindow(new BC_Title(x, y,
188 // _("Filesystem prefix on remote nodes:")));
189 // add_subwindow(new PrefsRenderFarmMountpoint(pwindow, this, x + xmargin3, y));
193 void PerformancePrefs::generate_node_list()
195 int selected_row = node_list ? node_list->get_selection_number(0, 0) : -1;
197 for(int i = 0; i < TOTAL_COLUMNS; i++)
198 nodes[i].remove_all_objects();
201 i < pwindow->thread->preferences->renderfarm_nodes.size();
204 BC_ListBoxItem *item;
205 nodes[ENABLED_COLUMN].append(item = new BC_ListBoxItem(
206 (char*)(pwindow->thread->preferences->renderfarm_enabled.get(i) ? "X" : " ")));
207 if(i == selected_row) item->set_selected(1);
209 nodes[HOSTNAME_COLUMN].append(item = new BC_ListBoxItem(
210 pwindow->thread->preferences->renderfarm_nodes.get(i)));
211 if(i == selected_row) item->set_selected(1);
213 char string[BCTEXTLEN];
214 sprintf(string, "%d", pwindow->thread->preferences->renderfarm_ports.get(i));
215 nodes[PORT_COLUMN].append(item = new BC_ListBoxItem(string));
216 if(i == selected_row) item->set_selected(1);
218 sprintf(string, "%0.3f", pwindow->thread->preferences->renderfarm_rate.get(i));
219 nodes[RATE_COLUMN].append(item = new BC_ListBoxItem(string));
220 if(i == selected_row) item->set_selected(1);
225 static const char *default_titles[] = {
226 N_("On"), N_("Hostname"), N_("Port"), N_("Framerate")
229 static int default_widths[] = {
234 void PerformancePrefs::update_node_list()
236 node_list->update_list();
239 void PrefsRenderFarmNodes::update_list()
241 update(subwindow->nodes, titles, widths, PerformancePrefs::TOTAL_COLUMNS,
242 get_xposition(), get_yposition(), get_selection_number(0, 0));
246 void PerformancePrefs::update_rates()
248 //printf("PerformancePrefs::update_rates %d\n", __LINE__);
249 char string[BCTEXTLEN];
251 i < mwindow->preferences->renderfarm_rate.size();
254 if(i < nodes[RATE_COLUMN].size())
256 sprintf(string, "%0.3f", mwindow->preferences->renderfarm_rate.get(i));
257 nodes[RATE_COLUMN].get(i)->set_text(string);
261 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
262 mwindow->preferences->local_rate);
263 master_rate->update(string);
269 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow,
274 pwindow->thread->preferences->use_brender,
275 _("Use background rendering"))
277 this->pwindow = pwindow;
280 int PrefsUseBRender::handle_event()
282 pwindow->thread->redraw_overlays = 1;
283 pwindow->thread->redraw_times = 1;
284 pwindow->thread->preferences->use_brender = get_value();
289 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow,
290 PerformancePrefs *subwindow, int x, int y)
291 : BC_TumbleTextBox(subwindow,
292 (int64_t)pwindow->thread->preferences->brender_fragment,
293 (int64_t)1, (int64_t)65535, x, y, 100)
295 this->pwindow = pwindow;
297 int PrefsBRenderFragment::handle_event()
299 pwindow->thread->preferences->brender_fragment = atol(get_text());
303 CICacheSize::CICacheSize(int x, int y,
304 PreferencesWindow *pwindow, PerformancePrefs *subwindow)
305 : BC_TumbleTextBox(subwindow,
306 (int64_t)pwindow->thread->preferences->cache_size / 0x100000,
307 (int64_t)MIN_CACHE_SIZE / 0x100000,
308 (int64_t)MAX_CACHE_SIZE / 0x100000,
311 this->pwindow = pwindow;
315 int CICacheSize::handle_event()
318 result = (int64_t)atol(get_text()) * 0x100000;
319 CLAMP(result, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
320 pwindow->thread->preferences->cache_size = result;
325 PrefsUseHWDev::PrefsUseHWDev(PreferencesWindow *pwindow,
326 PerformancePrefs *subwindow, int x, int y)
327 : BC_PopupTextBox(subwindow,0,0,x,y,100,80,LISTBOX_TEXT)
329 this->pwindow = pwindow;
332 void PrefsUseHWDev::create_objects()
334 BC_PopupTextBox::create_objects();
335 hw_dev_names.append(new BC_ListBoxItem(_("none")));
336 hw_dev_names.append(new BC_ListBoxItem("vaapi"));
337 hw_dev_names.append(new BC_ListBoxItem("vdpau"));
338 hw_dev_names.append(new BC_ListBoxItem(""));
339 update_list(&hw_dev_names);
340 update(&pwindow->thread->preferences->use_hw_dev[0]);
343 int PrefsUseHWDev::handle_event()
345 strncpy(&pwindow->thread->preferences->use_hw_dev[0],
346 get_text(), sizeof(pwindow->thread->preferences->use_hw_dev));
350 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow,
351 PerformancePrefs *subwindow,
354 : BC_TumbleTextBox(subwindow,
355 (float)pwindow->thread->preferences->render_preroll,
362 this->pwindow = pwindow;
365 PrefsRenderPreroll::~PrefsRenderPreroll()
368 int PrefsRenderPreroll::handle_event()
370 pwindow->thread->preferences->render_preroll = atof(get_text());
375 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow,
376 PerformancePrefs *subwindow,
379 : BC_TumbleTextBox(subwindow,
380 (int64_t)pwindow->thread->preferences->brender_preroll,
387 this->pwindow = pwindow;
389 int PrefsBRenderPreroll::handle_event()
391 pwindow->thread->preferences->brender_preroll = atol(get_text());
396 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int 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();
414 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
417 pwindow->thread->preferences->force_uniprocessor,
418 _("Force single processor use"))
420 this->pwindow = pwindow;
422 PrefsForceUniprocessor::~PrefsForceUniprocessor()
425 int PrefsForceUniprocessor::handle_event()
427 pwindow->thread->preferences->force_uniprocessor = get_value();
433 PrefsRenderFarmConsolidate::PrefsRenderFarmConsolidate(PreferencesWindow *pwindow, int x, int y)
436 pwindow->thread->preferences->renderfarm_consolidate,
437 _("Consolidate output files on completion"))
439 this->pwindow = pwindow;
441 PrefsRenderFarmConsolidate::~PrefsRenderFarmConsolidate()
444 int PrefsRenderFarmConsolidate::handle_event()
446 pwindow->thread->preferences->renderfarm_consolidate = get_value();
451 PrefsRenderFarmPort::PrefsRenderFarmPort(PreferencesWindow *pwindow,
452 PerformancePrefs *subwindow,
455 : BC_TumbleTextBox(subwindow,
456 (int64_t)pwindow->thread->preferences->renderfarm_port,
463 this->pwindow = pwindow;
466 PrefsRenderFarmPort::~PrefsRenderFarmPort()
470 int PrefsRenderFarmPort::handle_event()
472 pwindow->thread->preferences->renderfarm_port = atol(get_text());
478 PrefsRenderFarmNodes::PrefsRenderFarmNodes(PreferencesWindow *pwindow,
479 PerformancePrefs *subwindow, int x, int y)
480 : BC_ListBox(x, y, 340, 230, LISTBOX_TEXT, 0,0,0,1, 0,0, LISTBOX_MULTIPLE)
482 for( int i=0; i<PerformancePrefs::TOTAL_COLUMNS; ++i ) {
483 titles[i] = _(default_titles[i]);
484 widths[i] = default_widths[i];
486 update(subwindow->nodes, titles, widths, PerformancePrefs::TOTAL_COLUMNS,
488 this->subwindow = subwindow;
489 this->pwindow = pwindow;
491 PrefsRenderFarmNodes::~PrefsRenderFarmNodes()
495 int PrefsRenderFarmNodes::column_resize_event()
497 for( int i=0; i<PerformancePrefs::TOTAL_COLUMNS; ++i )
498 widths[i] = get_column_width(i);
502 int PrefsRenderFarmNodes::handle_event()
505 if(get_selection_number(0, 0) >= 0)
507 subwindow->hot_node = get_selection_number(1, 0);
508 subwindow->edit_node->update(get_selection(1, 0)->get_text());
509 const char *text = get_selection(2, 0)->get_text();
510 subwindow->edit_port->update(text);
511 pwindow->thread->preferences->renderfarm_port = atol(text);
512 if(get_cursor_x() < widths[0])
514 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node] =
515 !pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node];
516 subwindow->generate_node_list();
517 subwindow->update_node_list();
522 subwindow->hot_node = -1;
523 subwindow->edit_node->update("");
528 int PrefsRenderFarmNodes::selection_changed()
535 PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
536 : BC_TextBox(x, y, 240, 1, "")
538 this->pwindow = pwindow;
539 this->subwindow = subwindow;
542 PrefsRenderFarmEditNode::~PrefsRenderFarmEditNode()
546 int PrefsRenderFarmEditNode::handle_event()
552 PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
553 : BC_GenericButton(x, y, _("Add Nodes"))
555 this->pwindow = pwindow;
556 this->subwindow = subwindow;
558 PrefsRenderFarmNewNode::~PrefsRenderFarmNewNode()
561 int PrefsRenderFarmNewNode::handle_event()
563 const char *name = subwindow->edit_node->get_text();
564 char *cp = (char*)subwindow->edit_port->get_text();
565 int64_t start_port = strtol(cp, &cp, 0), end_port = start_port;
566 while( isspace(*cp) ) ++cp;
568 end_port = strtol(cp, &cp, 0);
569 for( int port=start_port; port<=end_port; ++port ) {
570 pwindow->thread->preferences->add_node(name, port, 1, 0.0);
572 pwindow->thread->preferences->renderfarm_port = end_port;
573 subwindow->edit_port->update(end_port);
574 pwindow->thread->preferences->reset_rates();
575 subwindow->generate_node_list();
576 subwindow->update_node_list();
577 subwindow->hot_node = -1;
582 PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
583 : BC_GenericButton(x, y, _("Apply Changes"))
585 this->pwindow = pwindow;
586 this->subwindow = subwindow;
588 PrefsRenderFarmReplaceNode::~PrefsRenderFarmReplaceNode()
591 int PrefsRenderFarmReplaceNode::handle_event()
593 if(subwindow->hot_node >= 0)
595 pwindow->thread->preferences->edit_node(subwindow->hot_node,
596 subwindow->edit_node->get_text(),
597 pwindow->thread->preferences->renderfarm_port,
598 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node]);
599 subwindow->generate_node_list();
600 subwindow->update_node_list();
606 PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
607 : BC_GenericButton(x, y, _("Delete Nodes"))
609 this->pwindow = pwindow;
610 this->subwindow = subwindow;
612 PrefsRenderFarmDelNode::~PrefsRenderFarmDelNode()
615 int PrefsRenderFarmDelNode::handle_event()
617 ArrayList<BC_ListBoxItem *> &item_list = subwindow->nodes[0];
618 for( int i=item_list.size(); --i>=0; ) {
619 if( !item_list[i]->get_selected() ) continue;
620 pwindow->thread->preferences->delete_node(i);
622 subwindow->generate_node_list();
623 subwindow->update_node_list();
624 subwindow->hot_node = -1;
629 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow,
630 PerformancePrefs *subwindow,
633 : BC_GenericButton(x, y, _("Sort nodes"))
635 this->pwindow = pwindow;
636 this->subwindow = subwindow;
639 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
643 int PrefsRenderFarmSortNodes::handle_event()
645 pwindow->thread->preferences->sort_nodes();
646 subwindow->generate_node_list();
647 subwindow->update_node_list();
648 subwindow->hot_node = -1;
653 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow,
654 PerformancePrefs *subwindow, int x, int y)
655 : BC_GenericButton(x, y, _("Reset rates"))
657 this->pwindow = pwindow;
658 this->subwindow = subwindow;
661 int PrefsRenderFarmReset::handle_event()
663 pwindow->thread->preferences->reset_rates();
664 subwindow->generate_node_list();
665 subwindow->update_node_list();
667 char string[BCTEXTLEN];
669 _(MASTER_NODE_FRAMERATE_TEXT),
670 pwindow->thread->preferences->local_rate);
671 subwindow->master_rate->update(string);
672 subwindow->hot_node = -1;
677 PrefsProjectSMP::PrefsProjectSMP(PreferencesWindow *pwindow,
678 PerformancePrefs *subwindow, int x, int y)
679 : BC_TumbleTextBox(subwindow,
680 (int64_t)pwindow->thread->preferences->project_smp,
681 (int64_t)1, (int64_t)100, x, y, 100)
683 this->pwindow = pwindow;
685 PrefsProjectSMP::~PrefsProjectSMP()
688 int PrefsProjectSMP::handle_event()
690 pwindow->thread->preferences->project_smp = atol(get_text());
695 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow,
696 PerformancePrefs *subwindow,
699 : BC_TumbleTextBox(subwindow,
700 (int64_t)pwindow->thread->preferences->renderfarm_job_count,
701 (int64_t)1, (int64_t)100, x, y, 100)
703 this->pwindow = pwindow;
705 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
708 int PrefsRenderFarmJobs::handle_event()
710 pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
715 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow,
716 PerformancePrefs *subwindow, int x, int y)
717 : BC_TextBox(x, y, 100, 1,
718 pwindow->thread->preferences->renderfarm_mountpoint)
720 this->pwindow = pwindow;
721 this->subwindow = subwindow;
723 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
726 int PrefsRenderFarmMountpoint::handle_event()
728 strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
733 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
734 PerformancePrefs *subwindow, int x, int y)
735 : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs,
736 _("Use virtual filesystem"))
738 this->pwindow = pwindow;
739 this->subwindow = subwindow;
742 int PrefsRenderFarmVFS::handle_event()
744 pwindow->thread->preferences->renderfarm_vfs = get_value();
749 PrefsRenderFarmWatchdog::PrefsRenderFarmWatchdog(PreferencesWindow *pwindow,
750 PerformancePrefs *subwindow, int x, int y)
751 : BC_TumbleTextBox(subwindow,
752 (int64_t)pwindow->thread->preferences->renderfarm_watchdog_timeout,
753 (int64_t)0, (int64_t)1000, x, y, 100)
755 this->pwindow = pwindow;
759 int PrefsRenderFarmWatchdog::handle_event()
761 pwindow->thread->preferences->renderfarm_watchdog_timeout = atol(get_text());