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();
69 xmargin1 = x = mwindow->theme->preferencesoptions_x;
70 y = mwindow->theme->preferencesoptions_y;
72 // add_subwindow(new BC_Title(x,
76 // resources->text_default));
78 // y += get_text_height(LARGEFONT) + 5;
83 win = add_subwindow(new BC_Title(x, y + 5, _("Cache size (MB):"), MEDIUMFONT, resources->text_default));
87 win = add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
88 if((curw = win->get_w()) > maxw)
92 cache_size = new CICacheSize(maxw,
96 cache_size->create_objects();
97 add_subwindow(new BC_Title(x, y + 5, _("Seconds to preroll renders:")));
98 PrefsRenderPreroll *preroll = new PrefsRenderPreroll(pwindow,
102 preroll->create_objects();
104 PrefsForceUniprocessor *force_1cpu = new PrefsForceUniprocessor(pwindow, x, y);
105 add_subwindow(force_1cpu);
107 int x1 = force_1cpu->get_x() + force_1cpu->get_w() + 50;
109 PrefsTrapSigSEGV *trap_segv = new PrefsTrapSigSEGV(this, x1, y);
110 add_subwindow(trap_segv);
111 int x2 = x1 + trap_segv->get_w() + 10;
112 add_subwindow(new BC_Title(x2, y, _("(must be root)"), MEDIUMFONT, RED));
115 PrefsTrapSigINTR *trap_intr = new PrefsTrapSigINTR(this, x1, y);
116 add_subwindow(trap_intr);
117 add_subwindow(new BC_Title(x2, y, _("(must be root)"), MEDIUMFONT, RED));
118 ffmpeg_marker_indexes = new PrefsFFMPEGMarkerIndecies(this, x, y);
119 add_subwindow(ffmpeg_marker_indexes);
122 ffmpeg_early_probe = new PrefsFFMPEGEarlyProbe(this, x, y);
123 add_subwindow(ffmpeg_early_probe);
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);
350 PrefsUseBRender::PrefsUseBRender(PreferencesWindow *pwindow,
355 pwindow->thread->preferences->use_brender,
356 _("Use background rendering"))
358 this->pwindow = pwindow;
361 int PrefsUseBRender::handle_event()
363 pwindow->thread->redraw_overlays = 1;
364 pwindow->thread->redraw_times = 1;
365 pwindow->thread->preferences->use_brender = get_value();
374 PrefsBRenderFragment::PrefsBRenderFragment(PreferencesWindow *pwindow,
375 PerformancePrefs *subwindow,
378 : BC_TumbleTextBox(subwindow,
379 (int64_t)pwindow->thread->preferences->brender_fragment,
386 this->pwindow = pwindow;
388 int PrefsBRenderFragment::handle_event()
390 pwindow->thread->preferences->brender_fragment = atol(get_text());
404 CICacheSize::CICacheSize(int x,
406 PreferencesWindow *pwindow,
407 PerformancePrefs *subwindow)
408 : BC_TumbleTextBox(subwindow,
409 (int64_t)pwindow->thread->preferences->cache_size / 0x100000,
410 (int64_t)MIN_CACHE_SIZE / 0x100000,
411 (int64_t)MAX_CACHE_SIZE / 0x100000,
416 this->pwindow = pwindow;
420 int CICacheSize::handle_event()
423 result = (int64_t)atol(get_text()) * 0x100000;
424 CLAMP(result, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
425 pwindow->thread->preferences->cache_size = result;
430 PrefsRenderPreroll::PrefsRenderPreroll(PreferencesWindow *pwindow,
431 PerformancePrefs *subwindow,
434 : BC_TumbleTextBox(subwindow,
435 (float)pwindow->thread->preferences->render_preroll,
442 this->pwindow = pwindow;
445 PrefsRenderPreroll::~PrefsRenderPreroll()
448 int PrefsRenderPreroll::handle_event()
450 pwindow->thread->preferences->render_preroll = atof(get_text());
455 PrefsBRenderPreroll::PrefsBRenderPreroll(PreferencesWindow *pwindow,
456 PerformancePrefs *subwindow,
459 : BC_TumbleTextBox(subwindow,
460 (int64_t)pwindow->thread->preferences->brender_preroll,
467 this->pwindow = pwindow;
469 int PrefsBRenderPreroll::handle_event()
471 pwindow->thread->preferences->brender_preroll = atol(get_text());
485 PrefsRenderFarm::PrefsRenderFarm(PreferencesWindow *pwindow, int x, int y)
488 pwindow->thread->preferences->use_renderfarm,
489 _("Use render farm"))
491 this->pwindow = pwindow;
493 PrefsRenderFarm::~PrefsRenderFarm()
496 int PrefsRenderFarm::handle_event()
498 pwindow->thread->preferences->use_renderfarm = get_value();
505 PrefsForceUniprocessor::PrefsForceUniprocessor(PreferencesWindow *pwindow, int x, int y)
508 pwindow->thread->preferences->force_uniprocessor,
509 _("Force single processor use"))
511 this->pwindow = pwindow;
513 PrefsForceUniprocessor::~PrefsForceUniprocessor()
516 int PrefsForceUniprocessor::handle_event()
518 pwindow->thread->preferences->force_uniprocessor = get_value();
522 PrefsTrapSigSEGV::PrefsTrapSigSEGV(PerformancePrefs *perf_prefs, int x, int y)
524 perf_prefs->pwindow->thread->preferences->trap_sigsegv,
527 this->perf_prefs = perf_prefs;
529 PrefsTrapSigSEGV::~PrefsTrapSigSEGV()
532 int PrefsTrapSigSEGV::handle_event()
534 perf_prefs->pwindow->thread->preferences->trap_sigsegv = get_value();
538 PrefsTrapSigINTR::PrefsTrapSigINTR(PerformancePrefs *perf_prefs, int x, int y)
540 perf_prefs->pwindow->thread->preferences->trap_sigintr,
543 this->perf_prefs = perf_prefs;
545 PrefsTrapSigINTR::~PrefsTrapSigINTR()
548 int PrefsTrapSigINTR::handle_event()
550 perf_prefs->pwindow->thread->preferences->trap_sigintr = get_value();
555 PrefsFFMPEGEarlyProbe::PrefsFFMPEGEarlyProbe(PerformancePrefs *perf_prefs, int x, int y)
557 perf_prefs->pwindow->thread->preferences->ffmpeg_early_probe,
558 _("On file open, ffmpeg probes early"))
560 this->perf_prefs = perf_prefs;
562 PrefsFFMPEGEarlyProbe::~PrefsFFMPEGEarlyProbe()
566 int PrefsFFMPEGEarlyProbe::handle_event()
568 perf_prefs->pwindow->thread->preferences->ffmpeg_early_probe = get_value();
573 PrefsFFMPEGMarkerIndecies::PrefsFFMPEGMarkerIndecies(PerformancePrefs *perf_prefs, int x, int y)
575 perf_prefs->pwindow->thread->preferences->ffmpeg_marker_indexes,
576 _("build ffmpeg marker indexes"))
578 this->perf_prefs = perf_prefs;
580 PrefsFFMPEGMarkerIndecies::~PrefsFFMPEGMarkerIndecies()
584 int PrefsFFMPEGMarkerIndecies::handle_event()
586 perf_prefs->pwindow->thread->preferences->ffmpeg_marker_indexes = 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( subwindow->hot_node >= 0 ) {
795 pwindow->thread->preferences->delete_node(subwindow->hot_node);
797 subwindow->generate_node_list();
798 subwindow->update_node_list();
799 subwindow->hot_node = -1;
808 PrefsRenderFarmSortNodes::PrefsRenderFarmSortNodes(PreferencesWindow *pwindow,
809 PerformancePrefs *subwindow,
812 : BC_GenericButton(x, y, _("Sort nodes"))
814 this->pwindow = pwindow;
815 this->subwindow = subwindow;
818 PrefsRenderFarmSortNodes::~PrefsRenderFarmSortNodes()
822 int PrefsRenderFarmSortNodes::handle_event()
824 pwindow->thread->preferences->sort_nodes();
825 subwindow->generate_node_list();
826 subwindow->update_node_list();
827 subwindow->hot_node = -1;
835 PrefsRenderFarmReset::PrefsRenderFarmReset(PreferencesWindow *pwindow,
836 PerformancePrefs *subwindow,
839 : BC_GenericButton(x, y, _("Reset rates"))
841 this->pwindow = pwindow;
842 this->subwindow = subwindow;
845 int PrefsRenderFarmReset::handle_event()
847 pwindow->thread->preferences->reset_rates();
848 subwindow->generate_node_list();
849 subwindow->update_node_list();
851 char string[BCTEXTLEN];
853 MASTER_NODE_FRAMERATE_TEXT,
854 pwindow->thread->preferences->local_rate);
855 subwindow->master_rate->update(string);
856 subwindow->hot_node = -1;
866 PrefsRenderFarmJobs::PrefsRenderFarmJobs(PreferencesWindow *pwindow,
867 PerformancePrefs *subwindow,
870 : BC_TumbleTextBox(subwindow,
871 (int64_t)pwindow->thread->preferences->renderfarm_job_count,
878 this->pwindow = pwindow;
880 PrefsRenderFarmJobs::~PrefsRenderFarmJobs()
883 int PrefsRenderFarmJobs::handle_event()
885 pwindow->thread->preferences->renderfarm_job_count = atol(get_text());
891 PrefsRenderFarmMountpoint::PrefsRenderFarmMountpoint(PreferencesWindow *pwindow,
892 PerformancePrefs *subwindow,
899 pwindow->thread->preferences->renderfarm_mountpoint)
901 this->pwindow = pwindow;
902 this->subwindow = subwindow;
904 PrefsRenderFarmMountpoint::~PrefsRenderFarmMountpoint()
907 int PrefsRenderFarmMountpoint::handle_event()
909 strcpy(pwindow->thread->preferences->renderfarm_mountpoint, get_text());
916 PrefsRenderFarmVFS::PrefsRenderFarmVFS(PreferencesWindow *pwindow,
917 PerformancePrefs *subwindow,
920 : BC_CheckBox(x, y, pwindow->thread->preferences->renderfarm_vfs, _("Use virtual filesystem"))
922 this->pwindow = pwindow;
923 this->subwindow = subwindow;
926 int PrefsRenderFarmVFS::handle_event()
928 pwindow->thread->preferences->renderfarm_vfs = get_value();