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"
31 #include "probeprefs.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)
44 file_probe_dialog = 0;
47 PerformancePrefs::~PerformancePrefs()
50 delete file_probe_dialog;
51 nodes[0].remove_all_objects();
52 nodes[1].remove_all_objects();
53 nodes[2].remove_all_objects();
54 nodes[3].remove_all_objects();
57 void PerformancePrefs::create_objects()
64 char string[BCTEXTLEN];
65 BC_Resources *resources = BC_WindowBase::get_resources();
72 xmargin1 = x = mwindow->theme->preferencesoptions_x;
73 y = mwindow->theme->preferencesoptions_y;
75 // add_subwindow(new BC_Title(x,
79 // resources->text_default));
81 // y += get_text_height(LARGEFONT) + 5;
85 win = add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default));
89 win = add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
90 if((curw = win->get_w()) > maxw)
94 cache_size = new CICacheSize(maxw, y0, pwindow, this);
95 cache_size->create_objects();
96 int x1 = cache_size->get_x() + cache_size->get_w() + 30;
97 add_subwindow(file_probes = new PrefsFileProbes(pwindow, this, x1, y0));
99 add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
100 PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow, this, maxw, y1);
101 preroll->create_objects();
102 BC_Title *smp_title = new BC_Title(x1, y + 5, _("Project SMP cpus:"));
103 add_subwindow(smp_title);
104 int x2 = x1 + smp_title->get_w() + 5;
105 PrefsProjectSMP *proj_smp = new PrefsProjectSMP(pwindow, this, x2, y);
106 proj_smp->create_objects();
109 PrefsForceUniprocessor *force_1cpu = new PrefsForceUniprocessor(pwindow, x, y);
110 add_subwindow(force_1cpu);
112 x1 = force_1cpu->get_x() + force_1cpu->get_w() + 120;
114 PrefsTrapSigSEGV *trap_segv = new PrefsTrapSigSEGV(this, x1, y);
115 add_subwindow(trap_segv);
116 x2 = x1 + trap_segv->get_w() + 10;
117 add_subwindow(new BC_Title(x2, y, _("(must be root)"), MEDIUMFONT, RED));
120 PrefsTrapSigINTR *trap_intr = new PrefsTrapSigINTR(this, x1, y);
121 add_subwindow(trap_intr);
122 add_subwindow(new BC_Title(x2, y, _("(must be root)"), MEDIUMFONT, RED));
125 yuv420p_dvdlace = new PrefsYUV420P_DVDlace(pwindow, this, x1, y);
126 add_subwindow(yuv420p_dvdlace);
129 // Background rendering
130 add_subwindow(new BC_Bar(5, y, get_w() - 10));
134 add_subwindow(new BC_Title(x, y, _("Background Rendering (Video only)"), LARGEFONT, resources->text_default));
137 win = add_subwindow(new PrefsUseBRender(pwindow,
141 y += win->get_h() + 10;
142 win = add_subwindow(new BC_Title(x, y, _("Frames per background rendering job:")));
143 y += win->get_h() + 5;
144 PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow,
148 brender_fragment->create_objects();
149 y += brender_fragment->get_h() + 5;
150 win = add_subwindow(new BC_Title(x, y, _("Frames to preroll background:")));
151 y += win->get_h() + 5;
152 PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow,
156 bpreroll->create_objects();
157 y += bpreroll->get_h() + 20;
161 add_subwindow(new BC_Title(x, y1, _("Output for background rendering:")));
164 new FormatTools(mwindow,
166 pwindow->thread->preferences->brender_asset);
167 brender_tools->create_objects(x,
169 0, // Include tools for audio
170 1, // Include tools for video
171 0, // Include checkbox for audio
172 0, // Include checkbox for video
175 0, // Select compressors to be offered
176 0, // Prompt for recording options
177 0, // If nonzero, prompt for insertion strategy
178 1); // Supply file formats for background rendering
183 add_subwindow(new BC_Bar(5, y, get_w() - 10));
185 add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, resources->text_default));
187 BC_Title *node_title = new BC_Title(x1, y, _("Nodes:"));
188 add_subwindow(node_title);
189 x1 += node_title->get_w() + 25;
190 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
191 pwindow->thread->preferences->local_rate);
192 add_subwindow(master_rate = new BC_Title(x1, y, string));
194 add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow,
199 add_subwindow(new PrefsRenderFarm(pwindow, x, y));
201 add_subwindow(new BC_Title(x, y, _("Hostname:")));
202 add_subwindow(new BC_Title(x + xmargin3, y, _("Port:")));
205 add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow,
209 edit_port = new PrefsRenderFarmPort(pwindow,
213 edit_port->create_objects();
218 add_subwindow(new PrefsRenderFarmReplaceNode(pwindow,
222 add_subwindow(new PrefsRenderFarmNewNode(pwindow,
227 add_subwindow(new PrefsRenderFarmDelNode(pwindow,
231 add_subwindow(new PrefsRenderFarmSortNodes(pwindow,
236 add_subwindow(new PrefsRenderFarmReset(pwindow,
241 add_subwindow(new BC_Title(x,
243 _("Total jobs to create:")));
244 add_subwindow(new BC_Title(x,
246 _("(overridden if new file at each label is checked)")));
247 PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow,
251 jobs->create_objects();
253 // add_subwindow(new PrefsRenderFarmVFS(pwindow,
257 // add_subwindow(new BC_Title(x,
259 // _("Filesystem prefix on remote nodes:")));
260 // add_subwindow(new PrefsRenderFarmMountpoint(pwindow,
267 void PerformancePrefs::generate_node_list()
269 int selected_row = node_list ? node_list->get_selection_number(0, 0) : -1;
271 for(int i = 0; i < TOTAL_COLUMNS; i++)
272 nodes[i].remove_all_objects();
275 i < pwindow->thread->preferences->renderfarm_nodes.size();
278 BC_ListBoxItem *item;
279 nodes[ENABLED_COLUMN].append(item = new BC_ListBoxItem(
280 (char*)(pwindow->thread->preferences->renderfarm_enabled.get(i) ? "X" : " ")));
281 if(i == selected_row) item->set_selected(1);
283 nodes[HOSTNAME_COLUMN].append(item = new BC_ListBoxItem(
284 pwindow->thread->preferences->renderfarm_nodes.get(i)));
285 if(i == selected_row) item->set_selected(1);
287 char string[BCTEXTLEN];
288 sprintf(string, "%d", pwindow->thread->preferences->renderfarm_ports.get(i));
289 nodes[PORT_COLUMN].append(item = new BC_ListBoxItem(string));
290 if(i == selected_row) item->set_selected(1);
292 sprintf(string, "%0.3f", pwindow->thread->preferences->renderfarm_rate.get(i));
293 nodes[RATE_COLUMN].append(item = new BC_ListBoxItem(string));
294 if(i == selected_row) item->set_selected(1);
298 static const char *titles[] =
306 static int widths[] =
315 void PerformancePrefs::update_node_list()
317 node_list->update(nodes,
321 node_list->get_xposition(),
322 node_list->get_yposition(),
323 node_list->get_selection_number(0, 0));
327 void PerformancePrefs::update_rates()
329 //printf("PerformancePrefs::update_rates %d\n", __LINE__);
330 char string[BCTEXTLEN];
332 i < mwindow->preferences->renderfarm_rate.size();
335 if(i < nodes[RATE_COLUMN].size())
337 sprintf(string, "%0.3f", mwindow->preferences->renderfarm_rate.get(i));
338 nodes[RATE_COLUMN].get(i)->set_text(string);
342 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
343 mwindow->preferences->local_rate);
344 master_rate->update(string);
349 void PerformancePrefs::start_probe_dialog()
351 if( !file_probe_dialog )
352 file_probe_dialog = new FileProbeDialog(pwindow);
353 file_probe_dialog->start();
356 PrefsFileProbes::PrefsFileProbes(PreferencesWindow *pwindow,
357 PerformancePrefs *perf_prefs, int x, int y)
358 : BC_GenericButton(x, y, _("Probe Order"))
360 this->pwindow = pwindow;
361 this->perf_prefs = perf_prefs;
362 set_tooltip(_("File Open Probe Ordering"));
365 int PrefsFileProbes::handle_event()
367 perf_prefs->start_probe_dialog();
373 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow,
378 pwindow->thread->preferences->use_brender,
379 _("Use background rendering"))
381 this->pwindow = pwindow;
384 int PrefsUseBRender::handle_event()
386 pwindow->thread->redraw_overlays = 1;
387 pwindow->thread->redraw_times = 1;
388 pwindow->thread->preferences->use_brender = get_value();
397 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow,
398 PerformancePrefs *subwindow,
401 : BC_TumbleTextBox(subwindow,
402 (int64_t)pwindow->thread->preferences->brender_fragment,
409 this->pwindow = pwindow;
411 int PrefsBRenderFragment::handle_event()
413 pwindow->thread->preferences->brender_fragment = atol(get_text());
427 CICacheSize::CICacheSize(int x,
429 PreferencesWindow *pwindow,
430 PerformancePrefs *subwindow)
431 : BC_TumbleTextBox(subwindow,
432 (int64_t)pwindow->thread->preferences->cache_size / 0x100000,
433 (int64_t)MIN_CACHE_SIZE / 0x100000,
434 (int64_t)MAX_CACHE_SIZE / 0x100000,
439 this->pwindow = pwindow;
443 int CICacheSize::handle_event()
446 result = (int64_t)atol(get_text()) * 0x100000;
447 CLAMP(result, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
448 pwindow->thread->preferences->cache_size = result;
453 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow,
454 PerformancePrefs *subwindow,
457 : BC_TumbleTextBox(subwindow,
458 (float)pwindow->thread->preferences->render_preroll,
465 this->pwindow = pwindow;
468 PrefsRenderPreroll::~PrefsRenderPreroll()
471 int PrefsRenderPreroll::handle_event()
473 pwindow->thread->preferences->render_preroll = atof(get_text());
478 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow,
479 PerformancePrefs *subwindow,
482 : BC_TumbleTextBox(subwindow,
483 (int64_t)pwindow->thread->preferences->brender_preroll,
490 this->pwindow = pwindow;
492 int PrefsBRenderPreroll::handle_event()
494 pwindow->thread->preferences->brender_preroll = atol(get_text());
508 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y)
511 pwindow->thread->preferences->use_renderfarm,
512 _("Use render farm"))
514 this->pwindow = pwindow;
516 PrefsRenderFarm::~PrefsRenderFarm()
519 int PrefsRenderFarm::handle_event()
521 pwindow->thread->preferences->use_renderfarm = get_value();
528 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
531 pwindow->thread->preferences->force_uniprocessor,
532 _("Force single processor use"))
534 this->pwindow = pwindow;
536 PrefsForceUniprocessor::~PrefsForceUniprocessor()
539 int PrefsForceUniprocessor::handle_event()
541 pwindow->thread->preferences->force_uniprocessor = get_value();
545 PrefsTrapSigSEGV::PrefsTrapSigSEGV(PerformancePrefs *perf_prefs, int x, int y)
547 perf_prefs->pwindow->thread->preferences->trap_sigsegv,
550 this->perf_prefs = perf_prefs;
552 PrefsTrapSigSEGV::~PrefsTrapSigSEGV()
555 int PrefsTrapSigSEGV::handle_event()
557 perf_prefs->pwindow->thread->preferences->trap_sigsegv = get_value();
561 PrefsTrapSigINTR::PrefsTrapSigINTR(PerformancePrefs *perf_prefs, int x, int y)
563 perf_prefs->pwindow->thread->preferences->trap_sigintr,
566 this->perf_prefs = perf_prefs;
568 PrefsTrapSigINTR::~PrefsTrapSigINTR()
571 int PrefsTrapSigINTR::handle_event()
573 perf_prefs->pwindow->thread->preferences->trap_sigintr = get_value();
580 PrefsRenderFarmConsolidate::PrefsRenderFarmConsolidate(PreferencesWindow *pwindow, int x, int y)
583 pwindow->thread->preferences->renderfarm_consolidate,
584 _("Consolidate output files on completion"))
586 this->pwindow = pwindow;
588 PrefsRenderFarmConsolidate::~PrefsRenderFarmConsolidate()
591 int PrefsRenderFarmConsolidate::handle_event()
593 pwindow->thread->preferences->renderfarm_consolidate = get_value();
598 PrefsRenderFarmPort::PrefsRenderFarmPort(PreferencesWindow *pwindow,
599 PerformancePrefs *subwindow,
602 : BC_TumbleTextBox(subwindow,
603 (int64_t)pwindow->thread->preferences->renderfarm_port,
610 this->pwindow = pwindow;
613 PrefsRenderFarmPort::~PrefsRenderFarmPort()
617 int PrefsRenderFarmPort::handle_event()
619 pwindow->thread->preferences->renderfarm_port = atol(get_text());
625 PrefsRenderFarmNodes::PrefsRenderFarmNodes(PreferencesWindow *pwindow,
626 PerformancePrefs *subwindow,
633 LISTBOX_TEXT, // Display text list or icons
639 this->subwindow = subwindow;
640 this->pwindow = pwindow;
642 PrefsRenderFarmNodes::~PrefsRenderFarmNodes()
646 int PrefsRenderFarmNodes::column_resize_event()
648 for(int i = 0; i < 3; i++)
649 widths[i] = get_column_width(i);
653 int PrefsRenderFarmNodes::handle_event()
656 if(get_selection_number(0, 0) >= 0)
658 subwindow->hot_node = get_selection_number(1, 0);
659 subwindow->edit_node->update(get_selection(1, 0)->get_text());
660 subwindow->edit_port->update(get_selection(2, 0)->get_text());
661 if(get_cursor_x() < widths[0])
663 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node] =
664 !pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node];
665 subwindow->generate_node_list();
666 subwindow->update_node_list();
671 subwindow->hot_node = -1;
672 subwindow->edit_node->update("");
677 int PrefsRenderFarmNodes::selection_changed()
689 PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
690 : BC_TextBox(x, y, 240, 1, "")
692 this->pwindow = pwindow;
693 this->subwindow = subwindow;
696 PrefsRenderFarmEditNode::~PrefsRenderFarmEditNode()
700 int PrefsRenderFarmEditNode::handle_event()
710 PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
711 : BC_GenericButton(x, y, _("Add Node"))
713 this->pwindow = pwindow;
714 this->subwindow = subwindow;
716 PrefsRenderFarmNewNode::~PrefsRenderFarmNewNode()
719 int PrefsRenderFarmNewNode::handle_event()
721 pwindow->thread->preferences->add_node(subwindow->edit_node->get_text(),
722 pwindow->thread->preferences->renderfarm_port,
725 pwindow->thread->preferences->reset_rates();
726 subwindow->generate_node_list();
727 subwindow->update_node_list();
728 subwindow->hot_node = -1;
738 PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
739 : BC_GenericButton(x, y, _("Apply Changes"))
741 this->pwindow = pwindow;
742 this->subwindow = subwindow;
744 PrefsRenderFarmReplaceNode::~PrefsRenderFarmReplaceNode()
747 int PrefsRenderFarmReplaceNode::handle_event()
749 if(subwindow->hot_node >= 0)
751 pwindow->thread->preferences->edit_node(subwindow->hot_node,
752 subwindow->edit_node->get_text(),
753 pwindow->thread->preferences->renderfarm_port,
754 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node]);
755 subwindow->generate_node_list();
756 subwindow->update_node_list();
765 PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
766 : BC_GenericButton(x, y, _("Delete Node"))
768 this->pwindow = pwindow;
769 this->subwindow = subwindow;
771 PrefsRenderFarmDelNode::~PrefsRenderFarmDelNode()
774 int PrefsRenderFarmDelNode::handle_event()
776 if( subwindow->hot_node >= 0 ) {
777 pwindow->thread->preferences->delete_node(subwindow->hot_node);
779 subwindow->generate_node_list();
780 subwindow->update_node_list();
781 subwindow->hot_node = -1;
790 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow,
791 PerformancePrefs *subwindow,
794 : BC_GenericButton(x, y, _("Sort nodes"))
796 this->pwindow = pwindow;
797 this->subwindow = subwindow;
800 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
804 int PrefsRenderFarmSortNodes::handle_event()
806 pwindow->thread->preferences->sort_nodes();
807 subwindow->generate_node_list();
808 subwindow->update_node_list();
809 subwindow->hot_node = -1;
817 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow,
818 PerformancePrefs *subwindow,
821 : BC_GenericButton(x, y, _("Reset rates"))
823 this->pwindow = pwindow;
824 this->subwindow = subwindow;
827 int PrefsRenderFarmReset::handle_event()
829 pwindow->thread->preferences->reset_rates();
830 subwindow->generate_node_list();
831 subwindow->update_node_list();
833 char string[BCTEXTLEN];
835 MASTER_NODE_FRAMERATE_TEXT,
836 pwindow->thread->preferences->local_rate);
837 subwindow->master_rate->update(string);
838 subwindow->hot_node = -1;
846 PrefsProjectSMP::PrefsProjectSMP(PreferencesWindow *pwindow,
847 PerformancePrefs *subwindow, int x, int y)
848 : BC_TumbleTextBox(subwindow,
849 (int64_t)pwindow->thread->preferences->project_smp,
850 (int64_t)1, (int64_t)100, x, y, 100)
852 this->pwindow = pwindow;
854 PrefsProjectSMP::~PrefsProjectSMP()
857 int PrefsProjectSMP::handle_event()
859 pwindow->thread->preferences->project_smp = atol(get_text());
867 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow,
868 PerformancePrefs *subwindow,
871 : BC_TumbleTextBox(subwindow,
872 (int64_t)pwindow->thread->preferences->renderfarm_job_count,
879 this->pwindow = pwindow;
881 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
884 int PrefsRenderFarmJobs::handle_event()
886 pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
892 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow,
893 PerformancePrefs *subwindow,
900 pwindow->thread->preferences->renderfarm_mountpoint)
902 this->pwindow = pwindow;
903 this->subwindow = subwindow;
905 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
908 int PrefsRenderFarmMountpoint::handle_event()
910 strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
917 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
918 PerformancePrefs *subwindow, int x, int y)
919 : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs,
920 _("Use virtual filesystem"))
922 this->pwindow = pwindow;
923 this->subwindow = subwindow;
926 int PrefsRenderFarmVFS::handle_event()
928 pwindow->thread->preferences->renderfarm_vfs = get_value();
933 PrefsYUV420P_DVDlace::PrefsYUV420P_DVDlace(PreferencesWindow *pwindow,
934 PerformancePrefs *subwindow, int x, int y)
935 : BC_CheckBox(x, y, pwindow->thread->preferences->dvd_yuv420p_interlace,
936 _("Use yuv420p dvd interlace format"))
938 this->pwindow = pwindow;
939 this->subwindow = subwindow;
942 int PrefsYUV420P_DVDlace::handle_event()
944 pwindow->thread->preferences->dvd_yuv420p_interlace = get_value();