2 #include "audioconfig.h"
3 #include "audiodevice.inc"
8 #include "filesystem.h"
10 #include "preferences.h"
12 #include "videoconfig.h"
13 #include "videodevice.inc"
16 //#define CLAMP(x, y, z) (x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x)))
29 Preferences::Preferences()
34 preferences_lock = new Mutex;
35 sprintf(index_directory, BCASTDIR);
36 if(strlen(index_directory))
37 fs.complete_path(index_directory);
44 renderfarm_port = DEAMON_PORT;
47 renderfarm_mountpoint[0] = 0;
49 renderfarm_job_count = 1;
50 brender_asset = new Asset;
51 brender_asset->audio_data = 0;
52 brender_asset->video_data = 1;
58 Preferences::~Preferences()
61 delete preferences_lock;
64 void Preferences::copy_rates_from(Preferences *preferences)
66 preferences_lock->lock();
67 // Need to match node titles in case the order changed and in case
68 // one of the nodes in the source is the master node.
69 local_rate = preferences->local_rate;
72 j < preferences->renderfarm_nodes.total;
75 double new_rate = preferences->renderfarm_rate.values[j];
76 // Put in the master node
77 if(preferences->renderfarm_nodes.values[j][0] == '/')
79 if(!EQUIV(new_rate, 0.0))
80 local_rate = new_rate;
83 // Search for local node and copy it to that node
84 if(!EQUIV(new_rate, 0.0))
86 for(int i = 0; i < renderfarm_nodes.total; i++)
88 if(!strcmp(preferences->renderfarm_nodes.values[j], renderfarm_nodes.values[i]) &&
89 preferences->renderfarm_ports.values[j] == renderfarm_ports.values[i])
91 renderfarm_rate.values[i] = new_rate;
98 //printf("Preferences::copy_rates_from 1 %f %f\n", local_rate, preferences->local_rate);
99 preferences_lock->unlock();
102 Preferences& Preferences::operator=(Preferences &that)
104 // ================================= Performance ================================
105 strcpy(index_directory, that.index_directory);
106 index_size = that.index_size;
107 index_count = that.index_count;
108 use_thumbnails = that.use_thumbnails;
109 strcpy(global_plugin_dir, that.global_plugin_dir);
110 strcpy(local_plugin_dir, that.local_plugin_dir);
111 strcpy(theme, that.theme);
113 cache_size = that.cache_size;
114 renderfarm_nodes.remove_all_objects();
115 renderfarm_ports.remove_all();
116 renderfarm_enabled.remove_all();
117 renderfarm_rate.remove_all();
118 local_rate = that.local_rate;
119 for(int i = 0; i < that.renderfarm_nodes.total; i++)
121 add_node(that.renderfarm_nodes.values[i],
122 that.renderfarm_ports.values[i],
123 that.renderfarm_enabled.values[i],
124 that.renderfarm_rate.values[i]);
126 use_renderfarm = that.use_renderfarm;
127 renderfarm_port = that.renderfarm_port;
128 render_preroll = that.render_preroll;
129 brender_preroll = that.brender_preroll;
130 renderfarm_job_count = that.renderfarm_job_count;
131 renderfarm_vfs = that.renderfarm_vfs;
132 strcpy(renderfarm_mountpoint, that.renderfarm_mountpoint);
133 renderfarm_consolidate = that.renderfarm_consolidate;
134 use_brender = that.use_brender;
135 brender_fragment = that.brender_fragment;
136 *brender_asset = *that.brender_asset;
141 if(strlen(index_directory))
143 fs.complete_path(index_directory);
144 fs.add_end_slash(index_directory);
147 if(strlen(global_plugin_dir))
149 fs.complete_path(global_plugin_dir);
150 fs.add_end_slash(global_plugin_dir);
153 if(strlen(local_plugin_dir))
155 fs.complete_path(local_plugin_dir);
156 fs.add_end_slash(local_plugin_dir);
159 renderfarm_job_count = MAX(renderfarm_job_count, 1);
160 CLAMP(cache_size, 1, 100);
165 int Preferences::load_defaults(Defaults *defaults)
167 char string[BCTEXTLEN];
169 defaults->get("INDEX_DIRECTORY", index_directory);
170 index_size = defaults->get("INDEX_SIZE", index_size);
171 index_count = defaults->get("INDEX_COUNT", index_count);
172 use_thumbnails = defaults->get("USE_THUMBNAILS", use_thumbnails);
174 sprintf(global_plugin_dir, PLUGINDIR);
175 sprintf(local_plugin_dir, "");
176 strcpy(theme, DEFAULT_THEME);
177 defaults->get("GLOBAL_PLUGIN_DIR", global_plugin_dir);
178 defaults->get("LOCAL_PLUGIN_DIR", local_plugin_dir);
179 defaults->get("THEME", theme);
181 sprintf(brender_asset->path, "/tmp/brender");
182 brender_asset->format = FILE_JPEG_LIST;
183 brender_asset->jpeg_quality = 80;
184 brender_asset->load_defaults(defaults, "BRENDER_", 1);
185 use_brender = defaults->get("USE_BRENDER", use_brender);
186 brender_fragment = defaults->get("BRENDER_FRAGMENT", brender_fragment);
187 cache_size = defaults->get("CACHE_SIZE", cache_size);
188 local_rate = defaults->get("LOCAL_RATE", local_rate);
189 use_renderfarm = defaults->get("USE_RENDERFARM", use_renderfarm);
190 renderfarm_port = defaults->get("RENDERFARM_PORT", renderfarm_port);
191 render_preroll = defaults->get("RENDERFARM_PREROLL", render_preroll);
192 brender_preroll = defaults->get("BRENDER_PREROLL", brender_preroll);
193 renderfarm_job_count = defaults->get("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
194 renderfarm_consolidate = defaults->get("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
195 renderfarm_vfs = defaults->get("RENDERFARM_VFS", renderfarm_vfs);
196 defaults->get("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
197 int renderfarm_total = defaults->get("RENDERFARM_TOTAL", 0);
199 for(int i = 0; i < renderfarm_total; i++)
201 sprintf(string, "RENDERFARM_NODE%d", i);
202 char result[BCTEXTLEN];
204 int result_enabled = 0;
205 float result_rate = 0.0;
208 defaults->get(string, result);
210 sprintf(string, "RENDERFARM_PORT%d", i);
211 result_port = defaults->get(string, renderfarm_port);
213 sprintf(string, "RENDERFARM_ENABLED%d", i);
214 result_enabled = defaults->get(string, result_enabled);
216 sprintf(string, "RENDERFARM_RATE%d", i);
217 result_rate = defaults->get(string, result_rate);
221 add_node(result, result_port, result_enabled, result_rate);
228 int Preferences::save_defaults(Defaults *defaults)
230 char string[BCTEXTLEN];
231 defaults->update("CACHE_SIZE", cache_size);
232 defaults->update("INDEX_DIRECTORY", index_directory);
233 defaults->update("INDEX_SIZE", index_size);
234 defaults->update("INDEX_COUNT", index_count);
235 defaults->update("USE_THUMBNAILS", use_thumbnails);
236 defaults->update("GLOBAL_PLUGIN_DIR", global_plugin_dir);
237 defaults->update("LOCAL_PLUGIN_DIR", local_plugin_dir);
238 defaults->update("THEME", theme);
242 brender_asset->save_defaults(defaults, "BRENDER_");
243 defaults->update("USE_BRENDER", use_brender);
244 defaults->update("BRENDER_FRAGMENT", brender_fragment);
245 defaults->update("USE_RENDERFARM", use_renderfarm);
246 defaults->update("LOCAL_RATE", local_rate);
247 defaults->update("RENDERFARM_PORT", renderfarm_port);
248 defaults->update("RENDERFARM_PREROLL", render_preroll);
249 defaults->update("BRENDER_PREROLL", brender_preroll);
250 defaults->update("RENDERFARM_VFS", renderfarm_vfs);
251 defaults->update("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
252 defaults->update("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
253 defaults->update("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
254 defaults->update("RENDERFARM_TOTAL", (int64_t)renderfarm_nodes.total);
255 for(int i = 0; i < renderfarm_nodes.total; i++)
257 sprintf(string, "RENDERFARM_NODE%d", i);
258 defaults->update(string, renderfarm_nodes.values[i]);
259 sprintf(string, "RENDERFARM_PORT%d", i);
260 defaults->update(string, renderfarm_ports.values[i]);
261 sprintf(string, "RENDERFARM_ENABLED%d", i);
262 defaults->update(string, renderfarm_enabled.values[i]);
263 sprintf(string, "RENDERFARM_RATE%d", i);
264 defaults->update(string, renderfarm_rate.values[i]);
270 void Preferences::add_node(char *text, int port, int enabled, float rate)
272 if(text[0] == 0) return;
274 preferences_lock->lock();
275 char *new_item = new char[strlen(text) + 1];
276 strcpy(new_item, text);
277 renderfarm_nodes.append(new_item);
278 renderfarm_ports.append(port);
279 renderfarm_enabled.append(enabled);
280 renderfarm_rate.append(rate);
281 preferences_lock->unlock();
284 void Preferences::delete_node(int number)
286 preferences_lock->lock();
287 if(number < renderfarm_nodes.total)
289 delete [] renderfarm_nodes.values[number];
290 renderfarm_nodes.remove_number(number);
291 renderfarm_ports.remove_number(number);
292 renderfarm_enabled.remove_number(number);
293 renderfarm_rate.remove_number(number);
295 preferences_lock->unlock();
298 void Preferences::delete_nodes()
300 preferences_lock->lock();
301 for(int i = 0; i < renderfarm_nodes.total; i++)
302 delete [] renderfarm_nodes.values[i];
303 renderfarm_nodes.remove_all();
304 renderfarm_ports.remove_all();
305 renderfarm_enabled.remove_all();
306 renderfarm_rate.remove_all();
307 preferences_lock->unlock();
310 void Preferences::reset_rates()
312 for(int i = 0; i < renderfarm_nodes.total; i++)
314 renderfarm_rate.values[i] = 0.0;
319 void Preferences::set_rate(float rate, int node)
321 //printf("Preferences::set_rate %f %d\n", rate, node);
329 for(int i = 0; i < renderfarm_nodes.total; i++)
331 if(renderfarm_enabled.values[i]) total++;
332 if(total == node + 1)
334 renderfarm_rate.values[i] = rate;
341 float Preferences::get_avg_rate(int use_master_node)
343 preferences_lock->lock();
345 if(renderfarm_rate.total)
350 if(EQUIV(local_rate, 0.0))
352 preferences_lock->unlock();
362 for(int i = 0; i < renderfarm_rate.total; i++)
364 if(renderfarm_enabled.values[i])
367 total += renderfarm_rate.values[i];
368 if(EQUIV(renderfarm_rate.values[i], 0.0))
370 preferences_lock->unlock();
381 preferences_lock->unlock();
386 void Preferences::sort_nodes()
393 for(int i = 0; i < renderfarm_nodes.total - 1; i++)
395 if(strcmp(renderfarm_nodes.values[i], renderfarm_nodes.values[i + 1]) > 0)
397 char *temp = renderfarm_nodes.values[i];
398 int temp_port = renderfarm_ports.values[i];
400 renderfarm_nodes.values[i] = renderfarm_nodes.values[i + 1];
401 renderfarm_nodes.values[i + 1] = temp;
403 renderfarm_ports.values[i] = renderfarm_ports.values[i + 1];
404 renderfarm_ports.values[i + 1] = temp_port;
406 renderfarm_enabled.values[i] = renderfarm_enabled.values[i + 1];
407 renderfarm_enabled.values[i + 1] = temp_port;
409 renderfarm_rate.values[i] = renderfarm_rate.values[i + 1];
410 renderfarm_rate.values[i + 1] = temp_port;
417 void Preferences::edit_node(int number,
422 char *new_item = new char[strlen(new_text) + 1];
423 strcpy(new_item, new_text);
425 delete [] renderfarm_nodes.values[number];
426 renderfarm_nodes.values[number] = new_item;
427 renderfarm_ports.values[number] = new_port;
428 renderfarm_enabled.values[number] = new_enabled;
431 int Preferences::get_enabled_nodes()
434 for(int i = 0; i < renderfarm_enabled.total; i++)
435 if(renderfarm_enabled.values[i]) result++;
439 char* Preferences::get_node_hostname(int number)
442 for(int i = 0; i < renderfarm_nodes.total; i++)
444 if(renderfarm_enabled.values[i])
447 return renderfarm_nodes.values[i];
455 int Preferences::get_node_port(int number)
458 for(int i = 0; i < renderfarm_ports.total; i++)
460 if(renderfarm_enabled.values[i])
463 return renderfarm_ports.values[i];