upgraded x265,ffmpeg,tdb,it.po fixed tab armed toggle
[goodguy/history.git] / cinelerra-5.1 / cinelerra / preferences.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "asset.h"
23 #include "audioconfig.h"
24 #include "audiodevice.inc"
25 #include "bcmeter.inc"
26 #include "bcsignals.h"
27 #include "cache.inc"
28 #include "clip.h"
29 #include "bchash.h"
30 #include "file.h"
31 #include "filesystem.h"
32 #include "guicast.h"
33 #include "indexfile.h"
34 #include "mutex.h"
35 #include "preferences.h"
36 #include "shbtnprefs.h"
37 #include "theme.h"
38 #include "videoconfig.h"
39 #include "videodevice.inc"
40
41 #include <string.h>
42 #include <unistd.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45
46
47 //#define CLAMP(x, y, z) (x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x)))
48
49 Preferences::Preferences()
50 {
51 // Set defaults
52         FileSystem fs;
53
54         preferences_lock = new Mutex("Preferences::preferences_lock");
55
56
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 = 0x1000000;
63         index_size = 0x400000;
64         index_count = 500;
65         use_thumbnails = 1;
66         keyframe_reticle = HAIRLINE_DRAGGING;
67         trap_sigsegv = 1;
68         trap_sigintr = 1;
69         theme[0] = 0;
70         use_renderfarm = 0;
71         force_uniprocessor = 0;
72         renderfarm_port = DEAMON_PORT;
73         render_preroll = 0.5;
74         brender_preroll = 0;
75         renderfarm_mountpoint[0] = 0;
76         renderfarm_vfs = 0;
77         renderfarm_job_count = 20;
78         processors = calculate_processors(0);
79         real_processors = calculate_processors(1);
80         ffmpeg_early_probe = 0;
81         ffmpeg_marker_indexes = 1;
82         warn_indexes = 1;
83         dvd_yuv420p_interlace = 0;
84
85 // Default brender asset
86         brender_asset = new Asset;
87         brender_asset->audio_data = 0;
88         brender_asset->video_data = 1;
89         sprintf(brender_asset->path, "/tmp/brender");
90         brender_asset->format = FILE_JPEG_LIST;
91         brender_asset->jpeg_quality = 80;
92
93         use_brender = 0;
94         brender_fragment = 1;
95         local_rate = 0.0;
96
97         use_tipwindow = 1;
98         scan_commercials = 0;
99
100         android_remote = 0;
101         android_port = 23432;
102         strcpy(android_pin, "cinelerra");
103
104         for(int i = 0; i < MAXCHANNELS; i++)
105         {
106                 for(int j = 0; j < i + 1; j++)
107                 {
108                         int position = 180 - (360 * j / (i + 1));
109                         while(position < 0) position += 360;
110                         channel_positions[i * MAXCHANNELS + j] = position;
111                 }
112         }
113 }
114
115 Preferences::~Preferences()
116 {
117         brender_asset->Garbage::remove_user();
118         shbtn_prefs.remove_all_objects();
119         renderfarm_nodes.remove_all_objects();
120         delete preferences_lock;
121 }
122
123 void Preferences::copy_rates_from(Preferences *preferences)
124 {
125         preferences_lock->lock("Preferences::copy_rates_from");
126 // Need to match node titles in case the order changed and in case
127 // one of the nodes in the source is the master node.
128         local_rate = preferences->local_rate;
129
130         for(int j = 0;
131                 j < preferences->renderfarm_nodes.total;
132                 j++)
133         {
134                 double new_rate = preferences->renderfarm_rate.values[j];
135 // Put in the master node
136                 if(preferences->renderfarm_nodes.values[j][0] == '/')
137                 {
138                         if(!EQUIV(new_rate, 0.0))
139                                 local_rate = new_rate;
140                 }
141                 else
142 // Search for local node and copy it to that node
143                 if(!EQUIV(new_rate, 0.0))
144                 {
145                         for(int i = 0; i < renderfarm_nodes.total; i++)
146                         {
147                                 if(!strcmp(preferences->renderfarm_nodes.values[j], renderfarm_nodes.values[i]) &&
148                                         preferences->renderfarm_ports.values[j] == renderfarm_ports.values[i])
149                                 {
150                                         renderfarm_rate.values[i] = new_rate;
151                                         break;
152                                 }
153                         }
154                 }
155         }
156
157 //printf("Preferences::copy_rates_from 1 %f %f\n", local_rate, preferences->local_rate);
158         preferences_lock->unlock();
159 }
160
161 void Preferences::copy_from(Preferences *that)
162 {
163 // ================================= Performance ================================
164         strcpy(index_directory, that->index_directory);
165         index_size = that->index_size;
166         index_count = that->index_count;
167         use_thumbnails = that->use_thumbnails;
168         keyframe_reticle = that->keyframe_reticle;
169         strcpy(theme, that->theme);
170
171         use_tipwindow = that->use_tipwindow;
172         scan_commercials = that->scan_commercials;
173         android_remote = that->android_remote;
174         android_port = that->android_port;
175         strcpy(android_pin, that->android_pin);
176         this->shbtn_prefs.remove_all_objects();
177         for( int i=0; i<that->shbtn_prefs.size(); ++i )
178                 this->shbtn_prefs.append(new ShBtnPref(*that->shbtn_prefs[i]));
179         cache_size = that->cache_size;
180         force_uniprocessor = that->force_uniprocessor;
181         trap_sigsegv = that->trap_sigsegv;
182         trap_sigintr = that->trap_sigintr;
183         processors = that->processors;
184         real_processors = that->real_processors;
185         ffmpeg_early_probe = that->ffmpeg_early_probe;
186         ffmpeg_marker_indexes = that->ffmpeg_marker_indexes;
187         warn_indexes = that->warn_indexes;
188         dvd_yuv420p_interlace = that->dvd_yuv420p_interlace;
189         renderfarm_nodes.remove_all_objects();
190         renderfarm_ports.remove_all();
191         renderfarm_enabled.remove_all();
192         renderfarm_rate.remove_all();
193         local_rate = that->local_rate;
194         for(int i = 0; i < that->renderfarm_nodes.size(); i++)
195         {
196                 add_node(that->renderfarm_nodes.get(i),
197                         that->renderfarm_ports.get(i),
198                         that->renderfarm_enabled.get(i),
199                         that->renderfarm_rate.get(i));
200         }
201         use_renderfarm = that->use_renderfarm;
202         renderfarm_port = that->renderfarm_port;
203         render_preroll = that->render_preroll;
204         brender_preroll = that->brender_preroll;
205         renderfarm_job_count = that->renderfarm_job_count;
206         renderfarm_vfs = that->renderfarm_vfs;
207         strcpy(renderfarm_mountpoint, that->renderfarm_mountpoint);
208         renderfarm_consolidate = that->renderfarm_consolidate;
209         use_brender = that->use_brender;
210         brender_fragment = that->brender_fragment;
211         brender_asset->copy_from(that->brender_asset, 0);
212
213 // Check boundaries
214
215         FileSystem fs;
216         if(strlen(index_directory))
217         {
218                 fs.complete_path(index_directory);
219                 fs.add_end_slash(index_directory);
220         }
221
222 //      if(strlen(global_plugin_dir))
223 //      {
224 //              fs.complete_path(global_plugin_dir);
225 //              fs.add_end_slash(global_plugin_dir);
226 //      }
227 //
228
229 // Redo with the proper value of force_uniprocessor
230         processors = calculate_processors(0);
231         boundaries();
232 }
233
234 void Preferences::boundaries()
235 {
236         renderfarm_job_count = MAX(renderfarm_job_count, 1);
237         CLAMP(cache_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
238 }
239
240 Preferences& Preferences::operator=(Preferences &that)
241 {
242 printf("Preferences::operator=\n");
243         copy_from(&that);
244         return *this;
245 }
246
247 void Preferences::print_channels(char *string,
248         int *channel_positions,
249         int channels)
250 {
251         char string3[BCTEXTLEN];
252         string[0] = 0;
253         for(int j = 0; j < channels; j++)
254         {
255                 sprintf(string3, "%d", channel_positions[j]);
256                 strcat(string, string3);
257                 if(j < channels - 1)
258                         strcat(string, ",");
259         }
260 }
261
262 void Preferences::scan_channels(char *string,
263         int *channel_positions,
264         int channels)
265 {
266         char string2[BCTEXTLEN];
267         int len = strlen(string);
268         int current_channel = 0;
269         for(int i = 0; i < len; i++)
270         {
271                 strcpy(string2, &string[i]);
272                 for(int j = 0; j < BCTEXTLEN; j++)
273                 {
274                         if(string2[j] == ',' || string2[j] == 0)
275                         {
276                                 i += j;
277                                 string2[j] = 0;
278                                 break;
279                         }
280                 }
281                 channel_positions[current_channel++] = atoi(string2);
282                 if(current_channel >= channels) break;
283         }
284 }
285
286 int Preferences::load_defaults(BC_Hash *defaults)
287 {
288         char string[BCTEXTLEN];
289
290         use_tipwindow = defaults->get("USE_TIPWINDOW", use_tipwindow);
291         scan_commercials = defaults->get("SCAN_COMMERCIALS", scan_commercials);
292         android_remote = defaults->get("ANDROID_REMOTE", android_remote);
293         android_port = defaults->get("ANDROID_PORT", android_port);
294         defaults->get("ANDROID_PIN", android_pin);
295         defaults->get("INDEX_DIRECTORY", index_directory);
296         index_size = defaults->get("INDEX_SIZE", index_size);
297         index_count = defaults->get("INDEX_COUNT", index_count);
298         use_thumbnails = defaults->get("USE_THUMBNAILS", use_thumbnails);
299         keyframe_reticle = defaults->get("KEYFRAME_RETICLE", keyframe_reticle);
300         trap_sigsegv = defaults->get("TRAP_SIGSEGV", trap_sigsegv);
301         trap_sigintr = defaults->get("TRAP_SIGINTR", trap_sigintr);
302
303         strcpy(theme, DEFAULT_THEME);
304         defaults->get("THEME", theme);
305
306         for(int i = 0; i < MAXCHANNELS; i++)
307         {
308                 char string2[BCTEXTLEN];
309                 sprintf(string, "CHANNEL_POSITIONS%d", i);
310                 print_channels(string2,
311                         &channel_positions[i * MAXCHANNELS],
312                         i + 1);
313
314                 defaults->get(string, string2);
315
316                 scan_channels(string2,
317                         &channel_positions[i * MAXCHANNELS],
318                         i + 1);
319         }
320
321         brender_asset->load_defaults(defaults,
322                 "BRENDER_",
323                 1,
324                 1,
325                 1,
326                 0,
327                 0);
328
329
330
331         force_uniprocessor = defaults->get("FORCE_UNIPROCESSOR", force_uniprocessor);
332         ffmpeg_early_probe = defaults->get("FFMPEG_EARLY_PROBE", ffmpeg_early_probe);
333         ffmpeg_marker_indexes = defaults->get("FFMPEG_MARKER_INDEXES", ffmpeg_marker_indexes);
334         warn_indexes = defaults->get("WARN_INDEXES", warn_indexes);
335         dvd_yuv420p_interlace = defaults->get("DVD_YUV420P_INTERLACE", dvd_yuv420p_interlace);
336         use_brender = defaults->get("USE_BRENDER", use_brender);
337         brender_fragment = defaults->get("BRENDER_FRAGMENT", brender_fragment);
338         cache_size = defaults->get("CACHE_SIZE", cache_size);
339         local_rate = defaults->get("LOCAL_RATE", local_rate);
340         use_renderfarm = defaults->get("USE_RENDERFARM", use_renderfarm);
341         renderfarm_port = defaults->get("RENDERFARM_PORT", renderfarm_port);
342         render_preroll = defaults->get("RENDERFARM_PREROLL", render_preroll);
343         brender_preroll = defaults->get("BRENDER_PREROLL", brender_preroll);
344         renderfarm_job_count = defaults->get("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
345         renderfarm_consolidate = defaults->get("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
346 //      renderfarm_vfs = defaults->get("RENDERFARM_VFS", renderfarm_vfs);
347         defaults->get("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
348         int renderfarm_total = defaults->get("RENDERFARM_TOTAL", 0);
349
350         for(int i = 0; i < renderfarm_total; i++)
351         {
352                 sprintf(string, "RENDERFARM_NODE%d", i);
353                 char result[BCTEXTLEN];
354                 int result_port = 0;
355                 int result_enabled = 0;
356                 float result_rate = 0.0;
357
358                 result[0] = 0;
359                 defaults->get(string, result);
360
361                 sprintf(string, "RENDERFARM_PORT%d", i);
362                 result_port = defaults->get(string, renderfarm_port);
363
364                 sprintf(string, "RENDERFARM_ENABLED%d", i);
365                 result_enabled = defaults->get(string, result_enabled);
366
367                 sprintf(string, "RENDERFARM_RATE%d", i);
368                 result_rate = defaults->get(string, result_rate);
369
370                 if(result[0] != 0)
371                 {
372                         add_node(result, result_port, result_enabled, result_rate);
373                 }
374         }
375
376         shbtn_prefs.remove_all_objects();
377         int shbtns_total = defaults->get("SHBTNS_TOTAL", -1);
378         if( shbtns_total < 0 ) {
379                 shbtn_prefs.append(new ShBtnPref("Features5", "firefox file://$CIN_DAT/doc/Features5.pdf", 0));
380                 shbtn_prefs.append(new ShBtnPref("Online Help", "firefox https://cinelerra-cv.org/docs.php", 0));
381                 shbtn_prefs.append(new ShBtnPref("Orignal Manual", "firefox file://$CIN_DAT/doc/cinelerra.html", 0));
382                 shbtns_total = 0;
383         }
384         for( int i=0; i<shbtns_total; ++i ) {
385                 char name[BCTEXTLEN], commands[BCTEXTLEN];
386                 sprintf(string, "SHBTN%d_NAME", i);
387                 defaults->get(string, name);
388                 sprintf(string, "SHBTN%d_COMMANDS", i);
389                 defaults->get(string, commands);
390                 sprintf(string, "SHBTN%d_WARN", i);
391                 int warn = defaults->get(string, 0);
392                 shbtn_prefs.append(new ShBtnPref(name, commands, warn));
393         }
394
395 // Redo with the proper value of force_uniprocessor
396         processors = calculate_processors(0);
397         boundaries();
398         return 0;
399 }
400
401 int Preferences::save_defaults(BC_Hash *defaults)
402 {
403         char string[BCTEXTLEN];
404
405
406         defaults->update("USE_TIPWINDOW", use_tipwindow);
407         defaults->update("SCAN_COMMERCIALS", scan_commercials);
408         defaults->update("ANDROID_REMOTE", android_remote);
409         defaults->update("ANDROID_PIN", android_pin);
410         defaults->update("ANDROID_PORT", android_port);
411
412         defaults->update("CACHE_SIZE", cache_size);
413         defaults->update("INDEX_DIRECTORY", index_directory);
414         defaults->update("INDEX_SIZE", index_size);
415         defaults->update("INDEX_COUNT", index_count);
416         defaults->update("USE_THUMBNAILS", use_thumbnails);
417         defaults->update("KEYFRAME_RETICLE", keyframe_reticle);
418         defaults->update("TRAP_SIGSEGV", trap_sigsegv);
419         defaults->update("TRAP_SIGINTR", trap_sigintr);
420 //      defaults->update("GLOBAL_PLUGIN_DIR", global_plugin_dir);
421         defaults->update("THEME", theme);
422
423
424         for(int i = 0; i < MAXCHANNELS; i++)
425         {
426                 char string2[BCTEXTLEN];
427                 sprintf(string, "CHANNEL_POSITIONS%d", i);
428                 print_channels(string2, &channel_positions[i * MAXCHANNELS], i + 1);
429                 defaults->update(string, string2);
430         }
431
432         defaults->update("FORCE_UNIPROCESSOR", force_uniprocessor);
433         defaults->update("FFMPEG_EARLY_PROBE", ffmpeg_early_probe);
434         defaults->update("FFMPEG_MARKER_INDEXES", ffmpeg_marker_indexes);
435         defaults->update("WARN_INDEXES", warn_indexes);
436         defaults->update("DVD_YUV420P_INTERLACE", dvd_yuv420p_interlace);
437         brender_asset->save_defaults(defaults,
438                 "BRENDER_",
439                 1,
440                 1,
441                 1,
442                 0,
443                 0);
444         defaults->update("USE_BRENDER", use_brender);
445         defaults->update("BRENDER_FRAGMENT", brender_fragment);
446         defaults->update("USE_RENDERFARM", use_renderfarm);
447         defaults->update("LOCAL_RATE", local_rate);
448         defaults->update("RENDERFARM_PORT", renderfarm_port);
449         defaults->update("RENDERFARM_PREROLL", render_preroll);
450         defaults->update("BRENDER_PREROLL", brender_preroll);
451 //      defaults->update("RENDERFARM_VFS", renderfarm_vfs);
452         defaults->update("RENDERFARM_MOUNTPOINT", renderfarm_mountpoint);
453         defaults->update("RENDERFARM_JOBS_COUNT", renderfarm_job_count);
454         defaults->update("RENDERFARM_CONSOLIDATE", renderfarm_consolidate);
455         defaults->update("RENDERFARM_TOTAL", (int64_t)renderfarm_nodes.total);
456         for(int i = 0; i < renderfarm_nodes.total; i++)
457         {
458                 sprintf(string, "RENDERFARM_NODE%d", i);
459                 defaults->update(string, renderfarm_nodes.values[i]);
460                 sprintf(string, "RENDERFARM_PORT%d", i);
461                 defaults->update(string, renderfarm_ports.values[i]);
462                 sprintf(string, "RENDERFARM_ENABLED%d", i);
463                 defaults->update(string, renderfarm_enabled.values[i]);
464                 sprintf(string, "RENDERFARM_RATE%d", i);
465                 defaults->update(string, renderfarm_rate.values[i]);
466         }
467         defaults->update("SHBTNS_TOTAL", shbtn_prefs.size());
468         for( int i=0; i<shbtn_prefs.size(); ++i ) {
469                 ShBtnPref *pref = shbtn_prefs[i];
470                 sprintf(string, "SHBTN%d_NAME", i);
471                 defaults->update(string, pref->name);
472                 sprintf(string, "SHBTN%d_COMMANDS", i);
473                 defaults->update(string, pref->commands);
474                 sprintf(string, "SHBTN%d_WARN", i);
475                 defaults->update(string, pref->warn);
476         }
477         return 0;
478 }
479
480
481 void Preferences::add_node(const char *text, int port, int enabled, float rate)
482 {
483         if(text[0] == 0) return;
484
485         preferences_lock->lock("Preferences::add_node");
486         char *new_item = new char[strlen(text) + 1];
487         strcpy(new_item, text);
488         renderfarm_nodes.append(new_item);
489         renderfarm_nodes.set_array_delete();
490         renderfarm_ports.append(port);
491         renderfarm_enabled.append(enabled);
492         renderfarm_rate.append(rate);
493         preferences_lock->unlock();
494 }
495
496 void Preferences::delete_node(int number)
497 {
498         preferences_lock->lock("Preferences::delete_node");
499         if(number < renderfarm_nodes.total && number >= 0)
500         {
501                 delete [] renderfarm_nodes.values[number];
502                 renderfarm_nodes.remove_number(number);
503                 renderfarm_ports.remove_number(number);
504                 renderfarm_enabled.remove_number(number);
505                 renderfarm_rate.remove_number(number);
506         }
507         preferences_lock->unlock();
508 }
509
510 void Preferences::delete_nodes()
511 {
512         preferences_lock->lock("Preferences::delete_nodes");
513         for(int i = 0; i < renderfarm_nodes.total; i++)
514                 delete [] renderfarm_nodes.values[i];
515         renderfarm_nodes.remove_all();
516         renderfarm_ports.remove_all();
517         renderfarm_enabled.remove_all();
518         renderfarm_rate.remove_all();
519         preferences_lock->unlock();
520 }
521
522 void Preferences::reset_rates()
523 {
524         for(int i = 0; i < renderfarm_nodes.total; i++)
525         {
526                 renderfarm_rate.values[i] = 0.0;
527         }
528         local_rate = 0.0;
529 }
530
531 float Preferences::get_rate(int node)
532 {
533         if(node < 0)
534         {
535                 return local_rate;
536         }
537         else
538         {
539                 int total = 0;
540                 for(int i = 0; i < renderfarm_nodes.size(); i++)
541                 {
542                         if(renderfarm_enabled.get(i)) total++;
543                         if(total == node + 1)
544                         {
545                                 return renderfarm_rate.get(i);
546                         }
547                 }
548         }
549
550         return 0;
551 }
552
553 void Preferences::set_rate(float rate, int node)
554 {
555 //printf("Preferences::set_rate %f %d\n", rate, node);
556         if(node < 0)
557         {
558                 local_rate = rate;
559         }
560         else
561         {
562                 int total = 0;
563                 for(int i = 0; i < renderfarm_nodes.size(); i++)
564                 {
565                         if(renderfarm_enabled.get(i)) total++;
566                         if(total == node + 1)
567                         {
568                                 renderfarm_rate.set(i, rate);
569                                 return;
570                         }
571                 }
572         }
573 }
574
575 float Preferences::get_avg_rate(int use_master_node)
576 {
577         preferences_lock->lock("Preferences::get_avg_rate");
578         float total = 0.0;
579         if(renderfarm_rate.total)
580         {
581                 int enabled = 0;
582                 if(use_master_node)
583                 {
584                         if(EQUIV(local_rate, 0.0))
585                         {
586                                 preferences_lock->unlock();
587                                 return 0.0;
588                         }
589                         else
590                         {
591                                 enabled++;
592                                 total += local_rate;
593                         }
594                 }
595
596                 for(int i = 0; i < renderfarm_rate.total; i++)
597                 {
598                         if(renderfarm_enabled.values[i])
599                         {
600                                 enabled++;
601                                 total += renderfarm_rate.values[i];
602                                 if(EQUIV(renderfarm_rate.values[i], 0.0))
603                                 {
604                                         preferences_lock->unlock();
605                                         return 0.0;
606                                 }
607                         }
608                 }
609
610                 if(enabled)
611                         total /= enabled;
612                 else
613                         total = 0.0;
614         }
615         preferences_lock->unlock();
616
617         return total;
618 }
619
620 void Preferences::sort_nodes()
621 {
622         int done = 0;
623
624         while(!done)
625         {
626                 done = 1;
627                 for(int i = 0; i < renderfarm_nodes.total - 1; i++)
628                 {
629                         if(strcmp(renderfarm_nodes.values[i], renderfarm_nodes.values[i + 1]) > 0)
630                         {
631                                 char *temp = renderfarm_nodes.values[i];
632                                 int temp_port = renderfarm_ports.values[i];
633
634                                 renderfarm_nodes.values[i] = renderfarm_nodes.values[i + 1];
635                                 renderfarm_nodes.values[i + 1] = temp;
636
637                                 renderfarm_ports.values[i] = renderfarm_ports.values[i + 1];
638                                 renderfarm_ports.values[i + 1] = temp_port;
639
640                                 renderfarm_enabled.values[i] = renderfarm_enabled.values[i + 1];
641                                 renderfarm_enabled.values[i + 1] = temp_port;
642
643                                 renderfarm_rate.values[i] = renderfarm_rate.values[i + 1];
644                                 renderfarm_rate.values[i + 1] = temp_port;
645                                 done = 0;
646                         }
647                 }
648         }
649 }
650
651 void Preferences::edit_node(int number,
652         const char *new_text,
653         int new_port,
654         int new_enabled)
655 {
656         char *new_item = new char[strlen(new_text) + 1];
657         strcpy(new_item, new_text);
658
659         delete [] renderfarm_nodes.values[number];
660         renderfarm_nodes.values[number] = new_item;
661         renderfarm_ports.values[number] = new_port;
662         renderfarm_enabled.values[number] = new_enabled;
663 }
664
665 int Preferences::get_enabled_nodes()
666 {
667         int result = 0;
668         for(int i = 0; i < renderfarm_enabled.total; i++)
669                 if(renderfarm_enabled.values[i]) result++;
670         return result;
671 }
672
673 const char* Preferences::get_node_hostname(int number)
674 {
675         int total = 0;
676         for(int i = 0; i < renderfarm_nodes.total; i++)
677         {
678                 if(renderfarm_enabled.values[i])
679                 {
680                         if(total == number)
681                                 return renderfarm_nodes.values[i];
682                         else
683                                 total++;
684                 }
685         }
686         return "";
687 }
688
689 int Preferences::get_node_port(int number)
690 {
691         int total = 0;
692         for(int i = 0; i < renderfarm_ports.total; i++)
693         {
694                 if(renderfarm_enabled.values[i])
695                 {
696                         if(total == number)
697                                 return renderfarm_ports.values[i];
698                         else
699                                 total++;
700                 }
701         }
702         return -1;
703 }
704
705 int Preferences::get_asset_file_path(Asset *asset, char *path)
706 {
707         strcpy(path, asset->path);
708         int result = !access(path, R_OK) ? 0 : -1;
709         if( !result && ( asset->format == FILE_MPEG ||
710                 asset->format == FILE_VMPEG || asset->format == FILE_AMPEG ) ) {
711                 char source_filename[BCTEXTLEN], index_filename[BCTEXTLEN];
712                 IndexFile::get_index_filename(source_filename,
713                         index_directory, index_filename, asset->path, ".toc");
714                 strcpy(path, index_filename);
715                 if( access(path, R_OK) )
716                         result = 1;
717         }
718 // result = 0, asset->path/toc exist, -1 no asset, 1 no toc
719         return result;
720 }
721
722
723 int Preferences::calculate_processors(int interactive)
724 {
725         if(force_uniprocessor && !interactive) return 1;
726         return BC_WindowBase::get_resources()->machine_cpus;
727 }
728