4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "audioconfig.h"
25 #include "audiodevice.inc"
26 #include "bcmeter.inc"
27 #include "bcsignals.h"
32 #include "filesystem.h"
34 #include "indexfile.h"
35 #include "maxchannels.h"
37 #include "preferences.h"
38 #include "probeprefs.h"
39 #include "shbtnprefs.h"
41 #include "videoconfig.h"
42 #include "videodevice.inc"
47 #include <sys/types.h>
51 Preferences::Preferences()
55 preferences_lock = new Mutex("Preferences::preferences_lock");
57 // initial plugin path from build -DPLUGIN_DIR="..."
58 sprintf(plugin_dir, "%s/", File::get_plugin_path());
59 sprintf(index_directory, "%s/", File::get_config_path());
60 if( strlen(index_directory) )
61 fs.complete_path(index_directory);
62 cache_size = 0x10000000;
63 cache_transitions = 1;
64 index_size = 0x400000;
67 keyframe_reticle = HAIRLINE_DRAGGING;
68 perpetual_session = 0;
69 strcpy(lv2_path, DEFAULT_LV2_PATH);
70 strcpy(nested_proxy_path, DEFAULT_NESTED_PROXY_PATH);
75 layout_scale = 0; // auto scale
77 vicon_color_mode = VICON_COLOR_MODE_LOW;
79 strcpy(locale, DEFAULT_LOCALE);
81 strcpy(snapshot_path, DEFAULT_SNAPSHOT_PATH);
83 force_uniprocessor = 0;
84 renderfarm_port = DEAMON_PORT;
85 renderfarm_consolidate = 0;
88 renderfarm_mountpoint[0] = 0;
90 renderfarm_job_count = 20;
91 renderfarm_watchdog_timeout = 60;
92 project_smp = processors = calculate_processors(0);
93 real_processors = calculate_processors(1);
94 ffmpeg_marker_indexes = 1;
95 memset(&use_hw_dev, 0, sizeof(use_hw_dev));
102 grab_input_focus = 1;
103 textbox_focus_policy = CLICK_ACTIVATE | CLICK_DEACTIVATE;
105 forward_render_displacement = 0;
106 dvd_yuv420p_interlace = 0;
107 highlight_inverse = 0xffffff;
108 yuv_color_space = BC_COLORS_BT601_NTSC;
109 yuv_color_range = BC_COLORS_JPEG;
110 autocolor_assets = 0;
114 // Default brender asset
115 brender_asset = new Asset;
116 brender_asset->audio_data = 0;
117 brender_asset->video_data = 1;
118 sprintf(brender_asset->path, "/tmp/brender");
119 brender_asset->format = FILE_JPEG_LIST;
120 brender_asset->jpeg_quality = 80;
123 brender_fragment = 1;
127 scan_commercials = 0;
130 android_port = 23432;
131 strcpy(android_pin, "cinelerra");
136 memset(channel_positions, 0, sizeof(channel_positions));
138 while( channels < MAXCHANNELS ) {
139 int *positions = channel_positions[channels++];
140 for( int i=0; i<channels; ++i )
141 positions[i] = default_audio_channel_position(i, channels);
145 Preferences::~Preferences()
147 brender_asset->Garbage::remove_user();
148 shbtn_prefs.remove_all_objects();
149 file_probes.remove_all_objects();
150 renderfarm_nodes.remove_all_objects();
151 delete preferences_lock;
154 void Preferences::copy_rates_from(Preferences *preferences)
156 preferences_lock->lock("Preferences::copy_rates_from");
157 // Need to match node titles in case the order changed and in case
158 // one of the nodes in the source is the master node.
159 local_rate = preferences->local_rate;
161 for( int j=0; j<preferences->renderfarm_nodes.total; ++j ) {
162 double new_rate = preferences->renderfarm_rate.values[j];
163 // Put in the master node
164 if( preferences->renderfarm_nodes.values[j][0] == '/' ) {
165 if( !EQUIV(new_rate, 0.0) )
166 local_rate = new_rate;
169 // Search for local node and copy it to that node
170 if( !EQUIV(new_rate, 0.0) ) {
171 for( int i=0; i<renderfarm_nodes.total; ++i ) {
172 if( !strcmp(preferences->renderfarm_nodes.values[j], renderfarm_nodes.values[i]) &&
173 preferences->renderfarm_ports.values[j] == renderfarm_ports.values[i] ) {
174 renderfarm_rate.values[i] = new_rate;
181 //printf("Preferences::copy_rates_from 1 %f %f\n", local_rate, preferences->local_rate);
182 preferences_lock->unlock();
185 void Preferences::copy_from(Preferences *that)
187 // ================================= Performance ================================
188 strcpy(index_directory, that->index_directory);
189 index_size = that->index_size;
190 index_count = that->index_count;
191 use_thumbnails = that->use_thumbnails;
192 keyframe_reticle = that->keyframe_reticle;
193 perpetual_session = that->perpetual_session;
194 awindow_picon_h = that->awindow_picon_h;
195 layout_scale = that->layout_scale;
196 vicon_size = that->vicon_size;
197 vicon_color_mode = that->vicon_color_mode;
198 strcpy(theme, that->theme);
199 strcpy(locale, that->locale);
200 strcpy(plugin_icons, that->plugin_icons);
201 strcpy(snapshot_path, that->snapshot_path);
203 use_tipwindow = that->use_tipwindow;
204 scan_commercials = that->scan_commercials;
205 android_remote = that->android_remote;
206 android_port = that->android_port;
207 strcpy(android_pin, that->android_pin);
209 slow_speed = that->slow_speed;
210 fast_speed = that->fast_speed;
212 this->shbtn_prefs.remove_all_objects();
213 for( int i=0; i<that->shbtn_prefs.size(); ++i )
214 this->shbtn_prefs.append(new ShBtnPref(*that->shbtn_prefs[i]));
215 this->file_probes.remove_all_objects();
216 for( int i=0; i<that->file_probes.size(); ++i )
217 this->file_probes.append(new ProbePref(*that->file_probes[i]));
218 cache_size = that->cache_size;
219 cache_transitions = that->cache_transitions;
220 project_smp = that->project_smp;
221 force_uniprocessor = that->force_uniprocessor;
222 strcpy(lv2_path, that->lv2_path);
223 autostart_lv2ui = that->autostart_lv2ui;
224 strcpy(nested_proxy_path, that->nested_proxy_path);
225 trap_sigsegv = that->trap_sigsegv;
226 trap_sigintr = that->trap_sigintr;
227 processors = that->processors;
228 real_processors = that->real_processors;
229 ffmpeg_marker_indexes = that->ffmpeg_marker_indexes;
230 strcpy(use_hw_dev, &that->use_hw_dev[0]);
231 warn_indexes = that->warn_indexes;
232 unsafe_gui = that->unsafe_gui;
233 ongoing_backups = that->ongoing_backups;
234 warn_fileref = that->warn_fileref;
235 bd_warn_root = that->bd_warn_root;
236 popupmenu_btnup = that->popupmenu_btnup;
237 grab_input_focus = that->grab_input_focus;
238 textbox_focus_policy = that->textbox_focus_policy;
239 auto_rotate = that->auto_rotate;
240 forward_render_displacement = that->forward_render_displacement;
241 dvd_yuv420p_interlace = that->dvd_yuv420p_interlace;
242 highlight_inverse = that->highlight_inverse;
243 yuv_color_space = that->yuv_color_space;
244 yuv_color_range = that->yuv_color_range;
245 autocolor_assets = that->autocolor_assets;
246 ctrl_toggle = that->ctrl_toggle;
247 rectify_audio = that->rectify_audio;
248 renderfarm_nodes.remove_all_objects();
249 renderfarm_ports.remove_all();
250 renderfarm_enabled.remove_all();
251 renderfarm_rate.remove_all();
252 local_rate = that->local_rate;
253 for( int i=0; i<that->renderfarm_nodes.size(); ++i ) {
254 add_node(that->renderfarm_nodes.get(i),
255 that->renderfarm_ports.get(i),
256 that->renderfarm_enabled.get(i),
257 that->renderfarm_rate.get(i));
259 use_renderfarm = that->use_renderfarm;
260 renderfarm_port = that->renderfarm_port;
261 render_preroll = that->render_preroll;
262 brender_preroll = that->brender_preroll;
263 renderfarm_job_count = that->renderfarm_job_count;
264 renderfarm_watchdog_timeout = that->renderfarm_watchdog_timeout;
265 renderfarm_vfs = that->renderfarm_vfs;
266 strcpy(renderfarm_mountpoint, that->renderfarm_mountpoint);
267 renderfarm_consolidate = that->renderfarm_consolidate;
268 use_brender = that->use_brender;
269 brender_fragment = that->brender_fragment;
270 brender_asset->copy_from(that->brender_asset, 0);
275 if( strlen(index_directory) ) {
276 fs.complete_path(index_directory);
277 fs.add_end_slash(index_directory);
280 // if( strlen(global_plugin_dir) )
282 // fs.complete_path(global_plugin_dir);
283 // fs.add_end_slash(global_plugin_dir);
287 // Redo with the proper value of force_uniprocessor
288 processors = calculate_processors(0);
292 void Preferences::boundaries()
294 renderfarm_job_count = MAX(renderfarm_job_count, 1);
295 CLAMP(cache_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
298 Preferences& Preferences::operator=(Preferences &that)
300 printf("Preferences::operator=\n");
305 void Preferences::print_channels(char *string, int *channel_positions, int channels)
307 char *cp = string, *ep = cp+BCTEXTLEN-1;
308 for( int i=0; i<channels; ++i ) {
309 if( i ) cp += snprintf(cp, ep-cp, ", ");
310 cp += snprintf(cp, ep-cp, "%d", channel_positions[i]);
315 void Preferences::scan_channels(char *string, int *channel_positions, int channels)
318 int current_channel = 0;
320 while( isspace(*cp) ) ++cp;
322 channel_positions[current_channel++] = strtol(cp, &cp, 0);
323 if( current_channel >= channels ) break;
324 while( isspace(*cp) ) ++cp;
325 if( *cp == ',' ) ++cp;
327 while( current_channel < channels ) {
328 int pos = default_audio_channel_position(current_channel, channels);
329 channel_positions[current_channel++] = pos;
334 // TODO validation, otherwise corrupted/edited Cinelerra_rc crash app!
335 int Preferences::load_defaults(BC_Hash *defaults)
337 char string[BCTEXTLEN];
339 use_tipwindow = defaults->get("USE_TIPWINDOW", use_tipwindow);
340 scan_commercials = defaults->get("SCAN_COMMERCIALS", scan_commercials);
341 android_remote = defaults->get("ANDROID_REMOTE", android_remote);
342 android_port = defaults->get("ANDROID_PORT", android_port);
343 fast_speed = defaults->get("FAST_SPEED", fast_speed);
344 slow_speed = defaults->get("SLOW_SPEED", slow_speed);
345 defaults->get("ANDROID_PIN", android_pin);
346 defaults->get("INDEX_DIRECTORY", index_directory);
347 index_size = defaults->get("INDEX_SIZE", index_size);
348 index_count = defaults->get("INDEX_COUNT", index_count);
349 use_thumbnails = defaults->get("USE_THUMBNAILS", use_thumbnails);
350 keyframe_reticle = defaults->get("KEYFRAME_RETICLE", keyframe_reticle);
351 perpetual_session = defaults->get("PERPETUAL_SESSION", perpetual_session);
352 strcpy(lv2_path, DEFAULT_LV2_PATH);
353 defaults->get("LV2_PATH", lv2_path);
354 autostart_lv2ui = defaults->get("AUTOSTART_LV2UI", autostart_lv2ui);
355 strcpy(nested_proxy_path, DEFAULT_NESTED_PROXY_PATH);
356 defaults->get("NESTED_PROXY_PATH", nested_proxy_path);
357 trap_sigsegv = defaults->get("TRAP_SIGSEGV", trap_sigsegv);
358 trap_sigintr = defaults->get("TRAP_SIGINTR", trap_sigintr);
360 awindow_picon_h = defaults->get("AWINDOW_PICON_H", awindow_picon_h);
361 layout_scale = defaults->get("LAYOUT_SCALE",layout_scale);
362 vicon_size = defaults->get("VICON_SIZE",vicon_size);
363 vicon_color_mode = defaults->get("VICON_COLOR_MODE",vicon_color_mode);
364 if (vicon_color_mode > ( MAX_VICON_COLOR_MODE -1 ) || vicon_color_mode <0) vicon_color_mode = 0;
365 strcpy(theme, _(DEFAULT_THEME));
366 strcpy(locale, DEFAULT_LOCALE);
367 strcpy(plugin_icons, DEFAULT_PICON);
368 defaults->get("THEME", theme);
369 defaults->get("LOCALE", locale);
370 defaults->get("PLUGIN_ICONS", plugin_icons);
371 strcpy(snapshot_path, DEFAULT_SNAPSHOT_PATH);
372 defaults->get("SNAPSHOT_PATH", snapshot_path);
374 for( int i=0; i<MAXCHANNELS; ++i ) {
375 char string2[BCTEXTLEN];
376 sprintf(string, "CHANNEL_POSITIONS%d", i);
377 print_channels(string2, &channel_positions[i][0], i+1);
378 defaults->get(string, string2);
379 scan_channels(string2, &channel_positions[i][0], i+1);
381 brender_asset->load_defaults(defaults, "BRENDER_", 1, 1, 1, 0, 0);
383 project_smp = defaults->get("PROJECT_SMP", project_smp);
384 force_uniprocessor = defaults->get("FORCE_UNIPROCESSOR", force_uniprocessor);
385 ffmpeg_marker_indexes = defaults->get("FFMPEG_MARKER_INDEXES", ffmpeg_marker_indexes);
386 memset(&use_hw_dev, 0, sizeof(use_hw_dev));
387 defaults->get("USE_HW_DEV", use_hw_dev);
388 warn_indexes = defaults->get("WARN_INDEXES", warn_indexes);
389 unsafe_gui = defaults->get("UNSAFE_GUI", unsafe_gui);
390 ongoing_backups = defaults->get("ONGOING_BACKUPS", ongoing_backups);
391 warn_fileref = defaults->get("WARN_FILEREF", warn_fileref);
392 bd_warn_root = defaults->get("BD_WARN_ROOT", bd_warn_root);
393 popupmenu_btnup = defaults->get("POPUPMENU_BTNUP", popupmenu_btnup);
394 grab_input_focus = defaults->get("GRAB_FOCUS", grab_input_focus);
395 textbox_focus_policy = defaults->get("TEXTBOX_FOCUS_POLICY", textbox_focus_policy);
396 auto_rotate = defaults->get("AUTO_ROTATE", auto_rotate);
397 forward_render_displacement = defaults->get("FORWARD_RENDER_DISPLACEMENT", forward_render_displacement);
398 dvd_yuv420p_interlace = defaults->get("DVD_YUV420P_INTERLACE", dvd_yuv420p_interlace);
399 highlight_inverse = defaults->get("HIGHLIGHT_INVERSE", highlight_inverse);
400 yuv_color_space = defaults->get("YUV_COLOR_SPACE", yuv_color_space);
401 if (yuv_color_space > (MAX_COLOR_SPACE - 1) || yuv_color_space < 0) yuv_color_space = 0;
402 yuv_color_range = defaults->get("YUV_COLOR_RANGE", yuv_color_range);
403 if (yuv_color_range > (MAX_COLOR_RANGE - 1) || yuv_color_range < 0) yuv_color_range = 0;
404 autocolor_assets = defaults->get("AUTOCOLOR_ASSETS", autocolor_assets);
405 ctrl_toggle = defaults->get("CTRL_TOGGLE", ctrl_toggle);
406 rectify_audio = defaults->get("RECTIFY_AUDIO", rectify_audio);
407 use_brender = defaults->get("USE_BRENDER", use_brender);
408 brender_fragment = defaults->get("BRENDER_FRAGMENT", brender_fragment);
409 cache_size = defaults->get("CACHE_SIZE", cache_size);
410 cache_transitions = defaults->get("CACHE_TRANSITIONS", cache_transitions);
411 local_rate = defaults->get("LOCAL_RATE", local_rate);
412 use_renderfarm = defaults->get("USE_RENDERFARM", use_renderfarm);
413 renderfarm_port = defaults->get("RENDERFARM_PORT", renderfarm_port);
414 render_preroll = defaults->get("RENDERFARM_PREROLL", render_preroll);
415 brender_preroll = defaults->get("BRENDER_PREROLL", brender_preroll);
416 renderfarm_job_count = defaults->get("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
417 renderfarm_watchdog_timeout = defaults->get("RENDERFARM_WATCHDOG_TIMEOUT", renderfarm_watchdog_timeout);
418 renderfarm_consolidate = defaults->get("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
419 // renderfarm_vfs = defaults->get("RENDERFARM_VFS", renderfarm_vfs);
420 defaults->get("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
421 int renderfarm_total = defaults->get("RENDERFARM_TOTAL", 0);
423 for( int i = 0; i < renderfarm_total; i++ ) {
424 sprintf(string, "RENDERFARM_NODE%d", i);
425 char result[BCTEXTLEN];
427 int result_enabled = 0;
428 float result_rate = 0.0;
431 defaults->get(string, result);
433 sprintf(string, "RENDERFARM_PORT%d", i);
434 result_port = defaults->get(string, renderfarm_port);
436 sprintf(string, "RENDERFARM_ENABLED%d", i);
437 result_enabled = defaults->get(string, result_enabled);
439 sprintf(string, "RENDERFARM_RATE%d", i);
440 result_rate = defaults->get(string, result_rate);
442 if( result[0] != 0 ) {
443 add_node(result, result_port, result_enabled, result_rate);
447 shbtn_prefs.remove_all_objects();
448 int shbtns_total = defaults->get("SHBTNS_TOTAL", -1);
449 if( shbtns_total < 0 ) {
450 shbtn_prefs.append(new ShBtnPref(_("Current Manual"), "$CIN_BROWSER https://cinelerra-gg.org/download/CinelerraGG_Manual.pdf"));
451 shbtn_prefs.append(new ShBtnPref(_("HTML Current Manual"), "$CIN_BROWSER https://cinelerra-gg.org/download/CinelerraGG_Manual"));
452 shbtn_prefs.append(new ShBtnPref(_("Setting Shell Commands"), "$CIN_BROWSER file://$CIN_DAT/doc/ShellCmds.html"));
453 shbtn_prefs.append(new ShBtnPref(_("Shortcuts"), "$CIN_BROWSER file://$CIN_DAT/doc/shortcuts.html"));
454 shbtn_prefs.append(new ShBtnPref(_("RenderMux"), "$CIN_DAT/doc/RenderMux.sh"));
455 shbtn_prefs.append(new ShBtnPref(_("Delete brender files in tmp"), "$CIN_DAT/doc/brender_tmp_delete.sh"));
458 for( int i=0; i<shbtns_total; ++i ) {
459 char name[BCTEXTLEN], commands[BCTEXTLEN];
460 sprintf(string, "SHBTN%d_NAME", i);
461 defaults->get(string, name);
462 sprintf(string, "SHBTN%d_COMMANDS", i);
463 defaults->get(string, commands);
464 sprintf(string, "SHBTN%d_WARN", i);
465 int warn = defaults->get(string, 0);
466 sprintf(string, "SHBTN%d_RUN_SCRIPT", i);
467 int run_script = defaults->get(string, 0);
468 shbtn_prefs.append(new ShBtnPref(name, commands, warn, run_script));
471 file_probes.remove_all_objects();
472 int file_probe_total = defaults->get("FILE_PROBE_TOTAL", 0);
473 for( int i=0; i<file_probe_total; ++i ) {
474 char name[BCTEXTLEN];
475 sprintf(string, "FILE_PROBE%d_NAME", i);
476 defaults->get(string, name);
477 sprintf(string, "FILE_PROBE%d_ARMED", i);
478 int armed = defaults->get(string, 1);
479 file_probes.append(new ProbePref(name, armed));
481 // append any missing probes
482 for( int i=0; i<File::nb_probes; ++i ) {
483 const char *nm = File::default_probes[i];
484 int k = file_probes.size();
485 while( --k>=0 && strcmp(nm, file_probes[k]->name) );
486 if( k >= 0 ) continue;
488 if( !strcmp(nm, "FFMPEG_Late") ||
489 !strcmp(nm, "CR2") ) armed = 0;
490 file_probes.append(new ProbePref(nm, armed));
493 // Redo with the proper value of force_uniprocessor
494 processors = calculate_processors(0);
499 int Preferences::save_defaults(BC_Hash *defaults)
501 char string[BCTEXTLEN];
504 defaults->update("USE_TIPWINDOW", use_tipwindow);
505 defaults->update("SCAN_COMMERCIALS", scan_commercials);
506 defaults->update("ANDROID_REMOTE", android_remote);
507 defaults->update("ANDROID_PIN", android_pin);
508 defaults->update("ANDROID_PORT", android_port);
509 defaults->update("SLOW_SPEED", slow_speed);
510 defaults->update("FAST_SPEED", fast_speed);
511 defaults->update("CACHE_SIZE", cache_size);
512 defaults->update("CACHE_TRANSITIONS", cache_transitions);
513 defaults->update("INDEX_DIRECTORY", index_directory);
514 defaults->update("INDEX_SIZE", index_size);
515 defaults->update("INDEX_COUNT", index_count);
516 defaults->update("USE_THUMBNAILS", use_thumbnails);
517 defaults->update("KEYFRAME_RETICLE", keyframe_reticle);
518 defaults->update("PERPETUAL_SESSION", perpetual_session);
519 defaults->update("LV2_PATH", lv2_path);
520 defaults->update("AUTOSTART_LV2UI", autostart_lv2ui);
521 defaults->update("NESTED_PROXY_PATH", nested_proxy_path);
522 defaults->update("TRAP_SIGSEGV", trap_sigsegv);
523 defaults->update("TRAP_SIGINTR", trap_sigintr);
524 defaults->update("AWINDOW_PICON_H", awindow_picon_h);
525 defaults->update("LAYOUT_SCALE",layout_scale);
526 defaults->update("VICON_SIZE",vicon_size);
527 defaults->update("VICON_COLOR_MODE",vicon_color_mode);
528 defaults->update("THEME", theme);
529 defaults->update("LOCALE", locale);
530 defaults->update("PLUGIN_ICONS", plugin_icons);
531 defaults->update("SNAPSHOT_PATH", snapshot_path);
533 for( int i = 0; i < MAXCHANNELS; i++ ) {
534 char string2[BCTEXTLEN];
535 sprintf(string, "CHANNEL_POSITIONS%d", i);
536 print_channels(string2, &channel_positions[i][0], i + 1);
537 defaults->update(string, string2);
540 defaults->update("PROJECT_SMP", project_smp);
541 defaults->update("FORCE_UNIPROCESSOR", force_uniprocessor);
542 defaults->update("FFMPEG_MARKER_INDEXES", ffmpeg_marker_indexes);
543 defaults->update("USE_HW_DEV", use_hw_dev);
544 defaults->update("WARN_INDEXES", warn_indexes);
545 defaults->update("UNSAFE_GUI", unsafe_gui);
546 defaults->update("ONGOING_BACKUPS", ongoing_backups);
547 defaults->update("WARN_FILEREF", warn_fileref);
548 defaults->update("BD_WARN_ROOT", bd_warn_root);
549 defaults->update("POPUPMENU_BTNUP", popupmenu_btnup);
550 defaults->update("GRAB_FOCUS", grab_input_focus);
551 defaults->update("TEXTBOX_FOCUS_POLICY", textbox_focus_policy);
552 defaults->update("AUTO_ROTATE", auto_rotate);
553 defaults->update("FORWARD_RENDER_DISPLACEMENT", forward_render_displacement);
554 defaults->update("DVD_YUV420P_INTERLACE", dvd_yuv420p_interlace);
555 defaults->update("HIGHLIGHT_INVERSE", highlight_inverse);
556 defaults->update("YUV_COLOR_SPACE", yuv_color_space);
557 defaults->update("YUV_COLOR_RANGE", yuv_color_range);
558 defaults->update("AUTOCOLOR_ASSETS", autocolor_assets);
559 defaults->update("CTRL_TOGGLE", ctrl_toggle);
560 defaults->update("RECTIFY_AUDIO", rectify_audio);
561 brender_asset->save_defaults(defaults, "BRENDER_", 1, 1, 1, 0, 0);
562 defaults->update("USE_BRENDER", use_brender);
563 defaults->update("BRENDER_FRAGMENT", brender_fragment);
564 defaults->update("USE_RENDERFARM", use_renderfarm);
565 defaults->update("LOCAL_RATE", local_rate);
566 defaults->update("RENDERFARM_PORT", renderfarm_port);
567 defaults->update("RENDERFARM_PREROLL", render_preroll);
568 defaults->update("BRENDER_PREROLL", brender_preroll);
569 // defaults->update("RENDERFARM_VFS", renderfarm_vfs);
570 defaults->update("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
571 defaults->update("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
572 defaults->update("RENDERFARM_WATCHDOG_TIMEOUT", renderfarm_watchdog_timeout);
573 defaults->update("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
574 defaults->update("RENDERFARM_TOTAL", (int64_t)renderfarm_nodes.total);
575 for( int i = 0; i < renderfarm_nodes.total; i++ ) {
576 sprintf(string, "RENDERFARM_NODE%d", i);
577 defaults->update(string, renderfarm_nodes.values[i]);
578 sprintf(string, "RENDERFARM_PORT%d", i);
579 defaults->update(string, renderfarm_ports.values[i]);
580 sprintf(string, "RENDERFARM_ENABLED%d", i);
581 defaults->update(string, renderfarm_enabled.values[i]);
582 sprintf(string, "RENDERFARM_RATE%d", i);
583 defaults->update(string, renderfarm_rate.values[i]);
585 defaults->update("SHBTNS_TOTAL", shbtn_prefs.size());
586 for( int i=0; i<shbtn_prefs.size(); ++i ) {
587 ShBtnPref *pref = shbtn_prefs[i];
588 sprintf(string, "SHBTN%d_NAME", i);
589 defaults->update(string, pref->name);
590 sprintf(string, "SHBTN%d_COMMANDS", i);
591 defaults->update(string, pref->commands);
592 sprintf(string, "SHBTN%d_WARN", i);
593 defaults->update(string, pref->warn);
594 sprintf(string, "SHBTN%d_RUN_SCRIPT", i);
595 defaults->update(string, pref->run_script);
597 defaults->update("FILE_PROBE_TOTAL", file_probes.size());
598 for( int i=0; i<file_probes.size(); ++i ) {
599 ProbePref *pref = file_probes[i];
600 sprintf(string, "FILE_PROBE%d_NAME", i);
601 defaults->update(string, pref->name);
602 sprintf(string, "FILE_PROBE%d_ARMED", i);
603 defaults->update(string, pref->armed);
609 void Preferences::add_node(const char *text, int port, int enabled, float rate)
611 if( text[0] == 0 ) return;
613 preferences_lock->lock("Preferences::add_node");
614 char *new_item = new char[strlen(text) + 1];
615 strcpy(new_item, text);
616 renderfarm_nodes.append(new_item);
617 renderfarm_nodes.set_array_delete();
618 renderfarm_ports.append(port);
619 renderfarm_enabled.append(enabled);
620 renderfarm_rate.append(rate);
621 preferences_lock->unlock();
624 void Preferences::delete_node(int number)
626 preferences_lock->lock("Preferences::delete_node");
627 if( number < renderfarm_nodes.total && number >= 0 ) {
628 delete [] renderfarm_nodes.values[number];
629 renderfarm_nodes.remove_number(number);
630 renderfarm_ports.remove_number(number);
631 renderfarm_enabled.remove_number(number);
632 renderfarm_rate.remove_number(number);
634 preferences_lock->unlock();
637 void Preferences::delete_nodes()
639 preferences_lock->lock("Preferences::delete_nodes");
640 for( int i = 0; i < renderfarm_nodes.total; i++ )
641 delete [] renderfarm_nodes.values[i];
642 renderfarm_nodes.remove_all();
643 renderfarm_ports.remove_all();
644 renderfarm_enabled.remove_all();
645 renderfarm_rate.remove_all();
646 preferences_lock->unlock();
649 void Preferences::reset_rates()
651 for( int i = 0; i < renderfarm_nodes.total; i++ ) {
652 renderfarm_rate.values[i] = 0.0;
657 float Preferences::get_rate(int node)
664 for( int i = 0; i < renderfarm_nodes.size(); i++ ) {
665 if( renderfarm_enabled.get(i) ) total++;
666 if( total == node + 1 ) {
667 return renderfarm_rate.get(i);
675 void Preferences::set_rate(float rate, int node)
677 //printf("Preferences::set_rate %f %d\n", rate, node);
683 for( int i = 0; i < renderfarm_nodes.size(); i++ ) {
684 if( renderfarm_enabled.get(i) ) total++;
685 if( total == node + 1 ) {
686 renderfarm_rate.set(i, rate);
693 float Preferences::get_avg_rate(int use_master_node)
695 preferences_lock->lock("Preferences::get_avg_rate");
697 if( renderfarm_rate.total ) {
699 if( use_master_node ) {
700 if( EQUIV(local_rate, 0.0) ) {
701 preferences_lock->unlock();
710 for( int i = 0; i < renderfarm_rate.total; i++ ) {
711 if( renderfarm_enabled.values[i] ) {
713 total += renderfarm_rate.values[i];
714 if( EQUIV(renderfarm_rate.values[i], 0.0) ) {
715 preferences_lock->unlock();
726 preferences_lock->unlock();
731 void Preferences::sort_nodes()
738 for( int i = 0; i < renderfarm_nodes.total - 1; i++ ) {
739 if( strcmp(renderfarm_nodes.values[i], renderfarm_nodes.values[i + 1]) > 0 ) {
740 char *temp = renderfarm_nodes.values[i];
741 int temp_port = renderfarm_ports.values[i];
743 renderfarm_nodes.values[i] = renderfarm_nodes.values[i + 1];
744 renderfarm_nodes.values[i + 1] = temp;
746 renderfarm_ports.values[i] = renderfarm_ports.values[i + 1];
747 renderfarm_ports.values[i + 1] = temp_port;
749 renderfarm_enabled.values[i] = renderfarm_enabled.values[i + 1];
750 renderfarm_enabled.values[i + 1] = temp_port;
752 renderfarm_rate.values[i] = renderfarm_rate.values[i + 1];
753 renderfarm_rate.values[i + 1] = temp_port;
760 void Preferences::edit_node(int number,
761 const char *new_text,
765 char *new_item = new char[strlen(new_text) + 1];
766 strcpy(new_item, new_text);
768 delete [] renderfarm_nodes.values[number];
769 renderfarm_nodes.values[number] = new_item;
770 renderfarm_ports.values[number] = new_port;
771 renderfarm_enabled.values[number] = new_enabled;
774 int Preferences::get_enabled_nodes()
777 for( int i = 0; i < renderfarm_enabled.total; i++ )
778 if( renderfarm_enabled.values[i] ) result++;
782 const char* Preferences::get_node_hostname(int number)
785 for( int i = 0; i < renderfarm_nodes.total; i++ ) {
786 if( renderfarm_enabled.values[i] ) {
787 if( total == number )
788 return renderfarm_nodes.values[i];
796 int Preferences::get_node_port(int number)
799 for( int i = 0; i < renderfarm_ports.total; i++ ) {
800 if( renderfarm_enabled.values[i] ) {
801 if( total == number )
802 return renderfarm_ports.values[i];
810 int Preferences::get_asset_file_path(Asset *asset, char *path)
812 strcpy(path, asset->path);
813 int result = !access(path, R_OK) ? 0 : -1;
814 if( !result && ( asset->format == FILE_MPEG || asset->format == FILE_AC3 ||
815 asset->format == FILE_VMPEG || asset->format == FILE_AMPEG ) ) {
816 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
817 IndexFile::get_index_filename(source_filename,
818 index_directory, index_filename, asset->path, ".toc");
819 strcpy(path, index_filename);
820 if( access(path, R_OK) )
823 // result = 0, asset->path/toc exist, -1 no asset, 1 no toc
828 int Preferences::calculate_processors(int interactive)
830 if( force_uniprocessor && !interactive ) return 1;
831 return BC_WindowBase::get_resources()->machine_cpus;
834 int Preferences::get_file_probe_armed(const char *nm)
836 int k = file_probes.size();
837 while( --k>=0 && strcmp(nm, file_probes[k]->name) );
838 if( k < 0 ) return -1;
839 return file_probes[k]->armed;
842 void Preferences::set_file_probe_armed(const char *nm, int v)
844 int k = file_probes.size();
845 while( --k>=0 && strcmp(nm, file_probes[k]->name) );
847 file_probes[k]->armed = v;