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"
34 #define MASTER_NODE_FRAMERATE_TEXT "Master node framerate: %0.3f"
36 N_(MASTER_NODE_FRAMERATE_TEXT)
39 PerformancePrefs::PerformancePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
40 : PreferencesDialog(mwindow, pwindow)
45 PerformancePrefs::~PerformancePrefs()
48 nodes[0].remove_all_objects();
49 nodes[1].remove_all_objects();
50 nodes[2].remove_all_objects();
51 nodes[3].remove_all_objects();
54 void PerformancePrefs::create_objects()
61 char string[BCTEXTLEN];
62 BC_Resources *resources = BC_WindowBase::get_resources();
67 xmargin1 = x = mwindow->theme->preferencesoptions_x;
68 y = mwindow->theme->preferencesoptions_y;
70 // add_subwindow(new BC_Title(x,
74 // resources->text_default));
76 // y += get_text_height(LARGEFONT) + 5;
78 add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default));
79 cache_size = new CICacheSize(x + 230,
83 cache_size->create_objects();
85 add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
86 PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow,
90 preroll->create_objects();
92 PrefsForceUniprocessor *force_1cpu = new PrefsForceUniprocessor(pwindow, x, y);
93 add_subwindow(force_1cpu);
95 int x1 = force_1cpu->get_x() + force_1cpu->get_w() + 50;
96 int y1 = force_1cpu->get_y();
98 PrefsTrapSigSEGV *trap_segv = new PrefsTrapSigSEGV(this, x1, y1);
99 add_subwindow(trap_segv);
100 int x2 = x1 + trap_segv->get_w() + 10;
101 add_subwindow(new BC_Title(x2, y1, _("(must be root)"), MEDIUMFONT, RED));
103 PrefsTrapSigINTR *trap_intr = new PrefsTrapSigINTR(this, x1, y1);
104 add_subwindow(trap_intr);
105 add_subwindow(new BC_Title(x2, y1, _("(must be root)"), MEDIUMFONT, RED));
108 file_forking = new PrefsFileForking(this, x, y);
109 add_subwindow(file_forking);
110 file_forking->check_enable();
113 ffmpeg_early_probe = new PrefsFFMPEGEarlyProbe(this, x, y);
114 add_subwindow(ffmpeg_early_probe);
120 // Background rendering
121 add_subwindow(new BC_Bar(5, y, get_w() - 10));
125 add_subwindow(new BC_Title(x, y, _("Background Rendering (Video only)"), LARGEFONT, resources->text_default));
128 add_subwindow(new PrefsUseBRender(pwindow,
133 add_subwindow(new BC_Title(x, y + 40, _("Frames per background rendering job:")));
134 PrefsBRenderFragment *brender_fragment = new PrefsBRenderFragment(pwindow,
138 brender_fragment->create_objects();
139 add_subwindow(new BC_Title(x, y + 95, _("Frames to preroll background:")));
140 PrefsBRenderPreroll *bpreroll = new PrefsBRenderPreroll(pwindow,
144 bpreroll->create_objects();
148 add_subwindow(new BC_Title(x, y, _("Output for background rendering:")));
151 new FormatTools(mwindow,
153 pwindow->thread->preferences->brender_asset);
154 brender_tools->create_objects(x,
156 0, // Include tools for audio
157 1, // Include tools for video
158 0, // Include checkbox for audio
159 0, // Include checkbox for video
162 0, // Select compressors to be offered
163 0, // Prompt for recording options
164 0, // If nonzero, prompt for insertion strategy
165 1); // Supply file formats for background rendering
170 add_subwindow(new BC_Bar(5, y, get_w() - 10));
172 add_subwindow(new BC_Title(x, y, _("Render Farm"), LARGEFONT, resources->text_default));
174 BC_Title *node_title = new BC_Title(x1, y, _("Nodes:"));
175 add_subwindow(node_title);
176 x1 += node_title->get_w() + 25;
177 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
178 pwindow->thread->preferences->local_rate);
179 add_subwindow(master_rate = new BC_Title(x1, y, string));
181 add_subwindow(node_list = new PrefsRenderFarmNodes(pwindow,
186 add_subwindow(new PrefsRenderFarm(pwindow, x, y));
188 add_subwindow(new BC_Title(x, y, _("Hostname:")));
189 add_subwindow(new BC_Title(x + xmargin3, y, _("Port:")));
192 add_subwindow(edit_node = new PrefsRenderFarmEditNode(pwindow,
196 edit_port = new PrefsRenderFarmPort(pwindow,
200 edit_port->create_objects();
205 add_subwindow(new PrefsRenderFarmReplaceNode(pwindow,
209 add_subwindow(new PrefsRenderFarmNewNode(pwindow,
214 add_subwindow(new PrefsRenderFarmDelNode(pwindow,
218 add_subwindow(new PrefsRenderFarmSortNodes(pwindow,
223 add_subwindow(new PrefsRenderFarmReset(pwindow,
228 add_subwindow(new BC_Title(x,
230 _("Total jobs to create:")));
231 add_subwindow(new BC_Title(x,
233 _("(overridden if new file at each label is checked)")));
234 PrefsRenderFarmJobs *jobs = new PrefsRenderFarmJobs(pwindow,
238 jobs->create_objects();
240 // add_subwindow(new PrefsRenderFarmVFS(pwindow,
244 // add_subwindow(new BC_Title(x,
246 // _("Filesystem prefix on remote nodes:")));
247 // add_subwindow(new PrefsRenderFarmMountpoint(pwindow,
254 void PerformancePrefs::generate_node_list()
256 int selected_row = node_list ? node_list->get_selection_number(0, 0) : -1;
258 for(int i = 0; i < TOTAL_COLUMNS; i++)
259 nodes[i].remove_all_objects();
262 i < pwindow->thread->preferences->renderfarm_nodes.size();
265 BC_ListBoxItem *item;
266 nodes[ENABLED_COLUMN].append(item = new BC_ListBoxItem(
267 (char*)(pwindow->thread->preferences->renderfarm_enabled.get(i) ? "X" : " ")));
268 if(i == selected_row) item->set_selected(1);
270 nodes[HOSTNAME_COLUMN].append(item = new BC_ListBoxItem(
271 pwindow->thread->preferences->renderfarm_nodes.get(i)));
272 if(i == selected_row) item->set_selected(1);
274 char string[BCTEXTLEN];
275 sprintf(string, "%d", pwindow->thread->preferences->renderfarm_ports.get(i));
276 nodes[PORT_COLUMN].append(item = new BC_ListBoxItem(string));
277 if(i == selected_row) item->set_selected(1);
279 sprintf(string, "%0.3f", pwindow->thread->preferences->renderfarm_rate.get(i));
280 nodes[RATE_COLUMN].append(item = new BC_ListBoxItem(string));
281 if(i == selected_row) item->set_selected(1);
285 static const char *titles[] =
293 static int widths[] =
302 void PerformancePrefs::update_node_list()
304 node_list->update(nodes,
308 node_list->get_xposition(),
309 node_list->get_yposition(),
310 node_list->get_selection_number(0, 0));
314 void PerformancePrefs::update_rates()
316 //printf("PerformancePrefs::update_rates %d\n", __LINE__);
317 char string[BCTEXTLEN];
319 i < mwindow->preferences->renderfarm_rate.size();
322 if(i < nodes[RATE_COLUMN].size())
324 sprintf(string, "%0.3f", mwindow->preferences->renderfarm_rate.get(i));
325 nodes[RATE_COLUMN].get(i)->set_text(string);
329 sprintf(string, _(MASTER_NODE_FRAMERATE_TEXT),
330 mwindow->preferences->local_rate);
331 master_rate->update(string);
337 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow,
342 pwindow->thread->preferences->use_brender,
343 _("Use background rendering"))
345 this->pwindow = pwindow;
348 int PrefsUseBRender::handle_event()
350 pwindow->thread->redraw_overlays = 1;
351 pwindow->thread->redraw_times = 1;
352 pwindow->thread->preferences->use_brender = get_value();
361 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow,
362 PerformancePrefs *subwindow,
365 : BC_TumbleTextBox(subwindow,
366 (int64_t)pwindow->thread->preferences->brender_fragment,
373 this->pwindow = pwindow;
375 int PrefsBRenderFragment::handle_event()
377 pwindow->thread->preferences->brender_fragment = atol(get_text());
391 CICacheSize::CICacheSize(int x,
393 PreferencesWindow *pwindow,
394 PerformancePrefs *subwindow)
395 : BC_TumbleTextBox(subwindow,
396 (int64_t)pwindow->thread->preferences->cache_size / 0x100000,
397 (int64_t)MIN_CACHE_SIZE / 0x100000,
398 (int64_t)MAX_CACHE_SIZE / 0x100000,
403 this->pwindow = pwindow;
407 int CICacheSize::handle_event()
410 result = (int64_t)atol(get_text()) * 0x100000;
411 CLAMP(result, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
412 pwindow->thread->preferences->cache_size = result;
417 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow,
418 PerformancePrefs *subwindow,
421 : BC_TumbleTextBox(subwindow,
422 (float)pwindow->thread->preferences->render_preroll,
429 this->pwindow = pwindow;
432 PrefsRenderPreroll::~PrefsRenderPreroll()
435 int PrefsRenderPreroll::handle_event()
437 pwindow->thread->preferences->render_preroll = atof(get_text());
442 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow,
443 PerformancePrefs *subwindow,
446 : BC_TumbleTextBox(subwindow,
447 (int64_t)pwindow->thread->preferences->brender_preroll,
454 this->pwindow = pwindow;
456 int PrefsBRenderPreroll::handle_event()
458 pwindow->thread->preferences->brender_preroll = atol(get_text());
472 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y)
475 pwindow->thread->preferences->use_renderfarm,
476 _("Use render farm"))
478 this->pwindow = pwindow;
480 PrefsRenderFarm::~PrefsRenderFarm()
483 int PrefsRenderFarm::handle_event()
485 pwindow->thread->preferences->use_renderfarm = get_value();
492 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
495 pwindow->thread->preferences->force_uniprocessor,
496 _("Force single processor use"))
498 this->pwindow = pwindow;
500 PrefsForceUniprocessor::~PrefsForceUniprocessor()
503 int PrefsForceUniprocessor::handle_event()
505 pwindow->thread->preferences->force_uniprocessor = get_value();
509 PrefsTrapSigSEGV::PrefsTrapSigSEGV(PerformancePrefs *perf_prefs, int x, int y)
511 perf_prefs->pwindow->thread->preferences->trap_sigsegv,
514 this->perf_prefs = perf_prefs;
516 PrefsTrapSigSEGV::~PrefsTrapSigSEGV()
519 int PrefsTrapSigSEGV::handle_event()
521 perf_prefs->pwindow->thread->preferences->trap_sigsegv = get_value();
522 perf_prefs->file_forking->check_enable();
526 PrefsTrapSigINTR::PrefsTrapSigINTR(PerformancePrefs *perf_prefs, int x, int y)
528 perf_prefs->pwindow->thread->preferences->trap_sigintr,
531 this->perf_prefs = perf_prefs;
533 PrefsTrapSigINTR::~PrefsTrapSigINTR()
536 int PrefsTrapSigINTR::handle_event()
538 perf_prefs->pwindow->thread->preferences->trap_sigintr = get_value();
539 perf_prefs->file_forking->check_enable();
544 PrefsFileForking::PrefsFileForking(PerformancePrefs *perf_prefs, int x, int y)
546 perf_prefs->pwindow->thread->preferences->file_forking,
547 _("enable/disable file fork"))
549 this->perf_prefs = perf_prefs;
551 PrefsFileForking::~PrefsFileForking()
554 int PrefsFileForking::handle_event()
556 perf_prefs->pwindow->thread->preferences->file_forking = get_value();
560 void PrefsFileForking::check_enable()
562 Preferences *preferences = perf_prefs->pwindow->thread->preferences;
563 if( preferences->trap_sigsegv || preferences->trap_sigintr ) {
564 preferences->file_forking = 0;
568 else if( !preferences->trap_sigsegv && !preferences->trap_sigintr ) {
574 PrefsFFMPEGEarlyProbe::PrefsFFMPEGEarlyProbe(PerformancePrefs *perf_prefs, int x, int y)
576 perf_prefs->pwindow->thread->preferences->ffmpeg_early_probe,
577 _("On file open, ffmpeg probes early"))
579 this->perf_prefs = perf_prefs;
581 PrefsFFMPEGEarlyProbe::~PrefsFFMPEGEarlyProbe()
584 int PrefsFFMPEGEarlyProbe::handle_event()
586 perf_prefs->pwindow->thread->preferences->ffmpeg_early_probe = get_value();
595 PrefsRenderFarmConsolidate::PrefsRenderFarmConsolidate(PreferencesWindow *pwindow, int x, int y)
598 pwindow->thread->preferences->renderfarm_consolidate,
599 _("Consolidate output files on completion"))
601 this->pwindow = pwindow;
603 PrefsRenderFarmConsolidate::~PrefsRenderFarmConsolidate()
606 int PrefsRenderFarmConsolidate::handle_event()
608 pwindow->thread->preferences->renderfarm_consolidate = get_value();
616 PrefsRenderFarmPort::PrefsRenderFarmPort(PreferencesWindow *pwindow,
617 PerformancePrefs *subwindow,
620 : BC_TumbleTextBox(subwindow,
621 (int64_t)pwindow->thread->preferences->renderfarm_port,
628 this->pwindow = pwindow;
631 PrefsRenderFarmPort::~PrefsRenderFarmPort()
635 int PrefsRenderFarmPort::handle_event()
637 pwindow->thread->preferences->renderfarm_port = atol(get_text());
643 PrefsRenderFarmNodes::PrefsRenderFarmNodes(PreferencesWindow *pwindow,
644 PerformancePrefs *subwindow,
651 LISTBOX_TEXT, // Display text list or icons
657 this->subwindow = subwindow;
658 this->pwindow = pwindow;
660 PrefsRenderFarmNodes::~PrefsRenderFarmNodes()
664 int PrefsRenderFarmNodes::column_resize_event()
666 for(int i = 0; i < 3; i++)
667 widths[i] = get_column_width(i);
671 int PrefsRenderFarmNodes::handle_event()
674 if(get_selection_number(0, 0) >= 0)
676 subwindow->hot_node = get_selection_number(1, 0);
677 subwindow->edit_node->update(get_selection(1, 0)->get_text());
678 subwindow->edit_port->update(get_selection(2, 0)->get_text());
679 if(get_cursor_x() < widths[0])
681 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node] =
682 !pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node];
683 subwindow->generate_node_list();
684 subwindow->update_node_list();
689 subwindow->hot_node = -1;
690 subwindow->edit_node->update("");
695 int PrefsRenderFarmNodes::selection_changed()
707 PrefsRenderFarmEditNode::PrefsRenderFarmEditNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
708 : BC_TextBox(x, y, 240, 1, "")
710 this->pwindow = pwindow;
711 this->subwindow = subwindow;
714 PrefsRenderFarmEditNode::~PrefsRenderFarmEditNode()
718 int PrefsRenderFarmEditNode::handle_event()
728 PrefsRenderFarmNewNode::PrefsRenderFarmNewNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
729 : BC_GenericButton(x, y, _("Add Node"))
731 this->pwindow = pwindow;
732 this->subwindow = subwindow;
734 PrefsRenderFarmNewNode::~PrefsRenderFarmNewNode()
737 int PrefsRenderFarmNewNode::handle_event()
739 pwindow->thread->preferences->add_node(subwindow->edit_node->get_text(),
740 pwindow->thread->preferences->renderfarm_port,
743 pwindow->thread->preferences->reset_rates();
744 subwindow->generate_node_list();
745 subwindow->update_node_list();
746 subwindow->hot_node = -1;
756 PrefsRenderFarmReplaceNode::PrefsRenderFarmReplaceNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
757 : BC_GenericButton(x, y, _("Apply Changes"))
759 this->pwindow = pwindow;
760 this->subwindow = subwindow;
762 PrefsRenderFarmReplaceNode::~PrefsRenderFarmReplaceNode()
765 int PrefsRenderFarmReplaceNode::handle_event()
767 if(subwindow->hot_node >= 0)
769 pwindow->thread->preferences->edit_node(subwindow->hot_node,
770 subwindow->edit_node->get_text(),
771 pwindow->thread->preferences->renderfarm_port,
772 pwindow->thread->preferences->renderfarm_enabled.values[subwindow->hot_node]);
773 subwindow->generate_node_list();
774 subwindow->update_node_list();
783 PrefsRenderFarmDelNode::PrefsRenderFarmDelNode(PreferencesWindow *pwindow, PerformancePrefs *subwindow, int x, int y)
784 : BC_GenericButton(x, y, _("Delete Node"))
786 this->pwindow = pwindow;
787 this->subwindow = subwindow;
789 PrefsRenderFarmDelNode::~PrefsRenderFarmDelNode()
792 int PrefsRenderFarmDelNode::handle_event()
794 if(strlen(subwindow->edit_node->get_text()) &&
795 subwindow->hot_node >= 0)
798 pwindow->thread->preferences->delete_node(subwindow->hot_node);
800 subwindow->generate_node_list();
801 subwindow->update_node_list();
802 subwindow->hot_node = -1;
811 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow,
812 PerformancePrefs *subwindow,
815 : BC_GenericButton(x, y, _("Sort nodes"))
817 this->pwindow = pwindow;
818 this->subwindow = subwindow;
821 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
825 int PrefsRenderFarmSortNodes::handle_event()
827 pwindow->thread->preferences->sort_nodes();
828 subwindow->generate_node_list();
829 subwindow->update_node_list();
830 subwindow->hot_node = -1;
838 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow,
839 PerformancePrefs *subwindow,
842 : BC_GenericButton(x, y, _("Reset rates"))
844 this->pwindow = pwindow;
845 this->subwindow = subwindow;
848 int PrefsRenderFarmReset::handle_event()
850 pwindow->thread->preferences->reset_rates();
851 subwindow->generate_node_list();
852 subwindow->update_node_list();
854 char string[BCTEXTLEN];
856 MASTER_NODE_FRAMERATE_TEXT,
857 pwindow->thread->preferences->local_rate);
858 subwindow->master_rate->update(string);
859 subwindow->hot_node = -1;
869 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow,
870 PerformancePrefs *subwindow,
873 : BC_TumbleTextBox(subwindow,
874 (int64_t)pwindow->thread->preferences->renderfarm_job_count,
881 this->pwindow = pwindow;
883 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
886 int PrefsRenderFarmJobs::handle_event()
888 pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
894 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow,
895 PerformancePrefs *subwindow,
902 pwindow->thread->preferences->renderfarm_mountpoint)
904 this->pwindow = pwindow;
905 this->subwindow = subwindow;
907 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
910 int PrefsRenderFarmMountpoint::handle_event()
912 strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
919 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
920 PerformancePrefs *subwindow,
923 : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs, _("Use virtual filesystem"))
925 this->pwindow = pwindow;
926 this->subwindow = subwindow;
929 int PrefsRenderFarmVFS::handle_event()
931 pwindow->thread->preferences->renderfarm_vfs = get_value();