no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / batchrender.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #include "asset.h"
24 #include "batchrender.h"
25 #include "bcdisplayinfo.h"
26 #include "bcsignals.h"
27 #include "confirmsave.h"
28 #include "cstrdup.h"
29 #include "bchash.h"
30 #include "edits.h"
31 #include "edit.h"
32 #include "edl.h"
33 #include "edlsession.h"
34 #include "errorbox.h"
35 #include "file.h"
36 #include "filesystem.h"
37 #include "filexml.h"
38 #include "indexable.h"
39 #include "keyframe.h"
40 #include "keys.h"
41 #include "labels.h"
42 #include "language.h"
43 #include "localsession.h"
44 #include "mainerror.h"
45 #include "mainundo.h"
46 #include "mainsession.h"
47 #include "mutex.h"
48 #include "mwindow.h"
49 #include "mwindowgui.h"
50 #include "packagedispatcher.h"
51 #include "packagerenderer.h"
52 #include "plugin.h"
53 #include "pluginset.h"
54 #include "preferences.h"
55 #include "render.h"
56 #include "theme.h"
57 #include "tracks.h"
58 #include "transportque.h"
59 #include "vframe.h"
60
61 #include "dvdcreate.h"
62 #include "bdcreate.h"
63
64 #include <stdlib.h>
65
66 int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
67 const char *BatchRenderThread::column_titles[] = {
68         N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
69 };
70
71 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
72  : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
73 {
74         set_shift(1);
75         this->mwindow = mwindow;
76 }
77
78 int BatchRenderMenuItem::handle_event()
79 {
80         mwindow->batch_render->start(1, 1);
81         return 1;
82 }
83
84 BatchRenderJob::BatchRenderJob(const char *tag,
85                 Preferences *preferences, int labeled, int farmed)
86 {
87         this->tag = tag;
88         this->preferences = preferences;
89         this->labeled = labeled;
90         this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
91         asset = new Asset;
92         edl_path[0] = 0;
93         enabled = 1;
94         elapsed = 0;
95 }
96
97 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
98  : BatchRenderJob("JOB", preferences, labeled, farmed)
99 {
100 }
101
102 BatchRenderJob::~BatchRenderJob()
103 {
104         asset->Garbage::remove_user();
105 }
106
107 void BatchRenderJob::copy_from(BatchRenderJob *src)
108 {
109         enabled = src->enabled;
110         farmed = src->farmed;
111         labeled = src->labeled;
112         asset->copy_from(src->asset, 0);
113         strcpy(edl_path, src->edl_path);
114         elapsed = 0;
115 }
116
117 BatchRenderJob *BatchRenderJob::copy()
118 {
119         BatchRenderJob *t = new BatchRenderJob(tag, preferences, labeled, farmed);
120         t->copy_from(this);
121         return t;
122 }
123
124 void BatchRenderJob::load(FileXML *file)
125 {
126         int result = 0;
127         char job_title[BCSTRLEN];
128         strcpy(job_title, file->tag.title);
129
130         enabled = file->tag.get_property("ENABLED", enabled);
131         farmed = file->tag.get_property("FARMED", farmed);
132         labeled = file->tag.get_property("LABELED", labeled);
133         edl_path[0] = 0;
134         file->tag.get_property("EDL_PATH", edl_path);
135         elapsed = file->tag.get_property("ELAPSED", elapsed);
136
137         result = file->read_tag();
138         if( !result ) {
139                 if( file->tag.title_is("ASSET") ) {
140                         file->tag.get_property("SRC", asset->path);
141                         asset->read(file, 0);
142 // The compression parameters are stored in the defaults to reduce
143 // coding maintenance.  The defaults must now be stuffed into the XML for
144 // unique storage.
145                         BC_Hash defaults;
146                         defaults.load_string(file->read_text(job_title));
147                         asset->load_defaults(&defaults,
148                                 "", 0, 1, 0, 0, 0);
149                 }
150         }
151 }
152
153 void BatchRenderJob::save(FileXML *file)
154 {
155         char end_tag[BCSTRLEN];  end_tag[0] = '/';
156         strcpy(&end_tag[1], file->tag.get_title());
157         file->tag.set_property("ENABLED", enabled);
158         file->tag.set_property("FARMED", farmed);
159         file->tag.set_property("LABELED", labeled);
160         file->tag.set_property("EDL_PATH", edl_path);
161         file->tag.set_property("ELAPSED", elapsed);
162         file->append_tag();
163         file->append_newline();
164         asset->write(file, 0, "");
165
166 // The compression parameters are stored in the defaults to reduce
167 // coding maintenance.  The defaults must now be stuffed into the XML for
168 // unique storage.
169         BC_Hash defaults;
170         asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
171         char *string;
172         defaults.save_string(string);
173         file->append_text(string);
174         free(string);
175         file->tag.set_title(end_tag);
176         file->append_tag();
177         file->append_newline();
178 }
179
180 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
181 {
182         return 0;
183 }
184
185 int BatchRenderJob::get_strategy()
186 {
187         int range = File::is_image_render(asset->format) ?
188                 RANGE_1FRAME : RANGE_SELECTION;
189         return Render::get_strategy(farmed, labeled, range);
190 }
191
192
193 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
194  : BC_DialogThread()
195 {
196         this->mwindow = mwindow;
197         current_job = 0;
198         rendering_job = -1;
199         is_rendering = 0;
200         default_job = 0;
201         boot_defaults = 0;
202         preferences = 0;
203         warn = 0;
204         render = 0;
205         batch_path[0] = 0;
206         do_farmed = 0;
207         do_labeled = 0;
208 }
209
210 BatchRenderThread::~BatchRenderThread()
211 {
212         close_window();
213         delete boot_defaults;
214         delete preferences;
215         delete default_job;
216         delete render;
217 }
218
219 void BatchRenderThread::reset(const char *path)
220 {
221         if( path ) {
222                 strcpy(batch_path, path);
223                 warn = 1;
224         }
225         current_job = 0;
226         rendering_job = -1;
227         delete default_job;  default_job = 0;
228         jobs.remove_all_objects();
229 }
230
231 void BatchRenderThread::start(int do_farmed, int do_labeled)
232 {
233         this->do_farmed = do_farmed;
234         this->do_labeled = do_labeled;
235         BC_DialogThread::start();
236 }
237
238 void BatchRenderThread::handle_close_event(int result)
239 {
240 // Save settings
241         save_jobs(batch_path);
242         save_defaults(mwindow->defaults);
243         reset();
244 }
245
246 BC_Window* BatchRenderThread::new_gui()
247 {
248         current_start = 0.0;
249         current_end = 0.0;
250         default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
251         load_jobs(batch_path, mwindow->preferences);
252         load_defaults(mwindow->defaults);
253         this->gui = new BatchRenderGUI(mwindow, this,
254                 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
255                 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
256         this->gui->create_objects();
257         return this->gui;
258 }
259
260
261 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
262 {
263         FileXML file;
264         int result = 0;
265
266         jobs.remove_all_objects();
267         if( !path ) path = batch_path;
268         if( !path[0] ) create_path(path);
269         file.read_from_file(path);
270
271         while( !result ) {
272                 if( !(result = file.read_tag()) ) {
273                         if( file.tag.title_is("JOBS") ) {
274                                 if (mwindow && mwindow->preferences->unsafe_gui)
275                                 warn = file.tag.get_property("WARN", 1);
276                                 if (mwindow && !mwindow->preferences->unsafe_gui)
277                                 warn = 0;
278                         }
279                         else if( file.tag.title_is("JOB") ) {
280                                 BatchRenderJob *job =  new BatchRenderJob(preferences, 0,0);
281                                 jobs.append(job);
282                                 job->load(&file);
283                         }
284                         else if( file.tag.title_is("DVD_JOB") ) {
285                                 DVD_BatchRenderJob *job =  new DVD_BatchRenderJob(preferences, 0,0,0,0);
286                                 jobs.append(job);
287                                 job->load(&file);
288                         }
289                         else if( file.tag.title_is("BD_JOB") ) {
290                                 BD_BatchRenderJob *job =  new BD_BatchRenderJob(preferences, 0,0);
291                                 jobs.append(job);
292                                 job->load(&file);
293                         }
294                 }
295         }
296 }
297
298 void BatchRenderThread::save_jobs(char *path)
299 {
300         FileXML file;
301         file.tag.set_title("JOBS");
302         if (mwindow && mwindow->preferences->unsafe_gui)
303         file.tag.set_property("WARN", warn);
304         file.append_tag();
305         file.append_newline();
306
307         for( int i = 0; i < jobs.total; i++ ) {
308                 file.tag.set_title(jobs[i]->tag);
309                 jobs[i]->save(&file);
310         }
311         file.tag.set_title("/JOBS");
312         file.append_tag();
313         file.append_newline();
314
315         if( !path ) path = batch_path;
316         if( !path[0] ) create_path(path);
317         file.write_to_file(path);
318 }
319
320 void BatchRenderThread::load_defaults(BC_Hash *defaults)
321 {
322         if( default_job ) {
323                 default_job->asset->load_defaults(defaults,
324                         "BATCHRENDER_", 1, 1, 1, 1, 1);
325         }
326
327         for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
328                 char string[BCTEXTLEN];
329                 sprintf(string, "BATCHRENDER_COLUMN%d", i);
330                 list_width[i] = defaults->get(string, xS(column_widths[i]));
331         }
332 }
333
334 void BatchRenderThread::save_defaults(BC_Hash *defaults)
335 {
336         if( default_job ) {
337                 default_job->asset->save_defaults(defaults,
338                         "BATCHRENDER_", 1, 1, 1, 1, 1);
339         }
340         for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
341                 char string[BCTEXTLEN];
342                 sprintf(string, "BATCHRENDER_COLUMN%d", i);
343                 defaults->update(string, list_width[i]);
344         }
345 //      defaults->update("BATCHRENDER_JOB", current_job);
346         if( mwindow )
347                 mwindow->save_defaults();
348         else
349                 defaults->save();
350 }
351
352 char* BatchRenderThread::create_path(char *string)
353 {
354         FileSystem fs;
355         sprintf(string, "%s/", File::get_config_path());
356         fs.complete_path(string);
357         strcat(string, BATCH_PATH);
358         return string;
359 }
360
361 void BatchRenderThread::new_job()
362 {
363         BatchRenderJob *result = get_current_job()->copy();
364         jobs.append(result);
365         current_job = jobs.total - 1;
366         gui->create_list(1);
367         gui->change_job();
368 }
369
370 void BatchRenderThread::delete_job()
371 {
372         if( current_job < jobs.total && current_job >= 0 ) {
373                 jobs.remove_object_number(current_job);
374                 if( current_job > 0 ) current_job--;
375                 gui->create_list(1);
376                 gui->change_job();
377         }
378 }
379
380 void BatchRenderThread::use_current_edl()
381 {
382 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
383 // __LINE__,
384 // mwindow->edl->path,
385 // mwindow->edl->path);
386
387         strcpy(get_current_edl(), mwindow->edl->path);
388         gui->create_list(1);
389         gui->edl_path_text->update(get_current_edl());
390 }
391
392 void BatchRenderThread::update_selected_edl()
393 {
394         FileXML xml_file;
395         char *path = get_current_edl();
396         EDL *edl = mwindow->edl;
397         // result = 1 if user cancelled operation
398         int result = ConfirmSave::test_file(mwindow, path);
399         if (!result) {
400         edl->save_xml(&xml_file, path);
401         xml_file.terminate_string();
402         if( xml_file.write_to_file(path) ) {
403                 char msg[BCTEXTLEN];
404                 sprintf(msg, _("Unable to save: %s"), path);
405                 MainError::show_error(msg);
406         }
407         }
408 }
409
410 BatchRenderJob* BatchRenderThread::get_current_job()
411 {
412         return current_job >= 0 && current_job < jobs.total ?
413                 jobs.values[current_job] : default_job;
414 }
415
416
417 Asset* BatchRenderThread::get_current_asset()
418 {
419         return get_current_job()->asset;
420 }
421
422 char* BatchRenderThread::get_current_edl()
423 {
424         return get_current_job()->edl_path;
425 }
426
427 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
428 {
429         int count = err_jobs.size();
430         if( !count ) return 0;
431         fprintf(stderr, msg, count);
432         char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
433         sp += snprintf(sp,ep-sp, msg,count);
434         for( int i=0; i<count; ++i ) {
435                 int no = err_jobs[i].no;
436                 const char *path = err_jobs[i].path;
437                 fprintf(stderr, "%d: %s\n", no, path);
438                 sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
439         }
440         sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
441         mwindow->show_warning(warn, string);
442         if( mwindow->wait_warning() ) {
443                 gui->button_enable();
444         }
445         return 1;
446 }
447
448 // Test EDL files for existence
449 int BatchRenderThread::test_edl_files()
450 {
451         int ret = 0;
452         const char *path = 0;
453         BatchRenderWarnJobs not_equiv;
454         BatchRenderWarnJobs empty_jobs;
455         BatchRenderWarnJobs no_labels;
456         BatchRenderWarnJobs no_rendering;
457
458         for( int i=0; !ret && i<jobs.size(); ++i ) {
459                 if( !jobs.values[i]->enabled ) continue;
460                 path = jobs[i]->edl_path;
461                 int is_script = *path == '@' ? 1 : 0;
462                 if( is_script ) ++path;
463                 FILE *fp = fopen(path, "r");
464                 if( fp ) {
465                         if( mwindow && !is_script ) {
466                                 char *bfr = 0;  size_t sz = 0;
467                                 struct stat st;
468                                 if( !fstat(fileno(fp), &st) ) {
469                                         sz = st.st_size;
470                                         bfr = new char[sz+1];
471                                         if( fread(bfr, 1, sz+1, fp) != sz )
472                                                 ret = 1;
473                                         else
474                                                 bfr[sz] = 0;
475                                 }
476                                 if( !ret ) {
477                                         EDL *edl = new EDL; edl->create_objects();
478                                         XMLBuffer data(bfr, sz, 0);
479                                         { FileXML file;
480                                         file.set_shared_input(&data);
481                                         edl->load_xml(&file, LOAD_ALL); }
482                                         double pos = edl->equivalent_output(mwindow->edl);
483                                         if( pos >= 0 )
484                                                 not_equiv.add(i+1, path);
485                                         double length = edl->tracks->total_playable_length();
486                                         double start = edl->local_session->get_selectionstart(1);
487                                         if( start >= length )
488                                                 empty_jobs.add(i+1, path);
489                                         if( jobs[i]->labeled && !edl->labels->first)
490                                                 no_labels.add(i+1,path);
491                                         Asset *asset = jobs[i]->asset;
492                                         if( !asset->audio_data && !asset->video_data )
493                                                 no_rendering.add(i+1,path);
494                                         edl->remove_user();
495                                 }
496                                 delete [] bfr;
497                         }
498                         fclose(fp);
499                 }
500                 else
501                         ret = 1;
502         }
503
504         if( ret ) {
505                 char string[BCTEXTLEN];
506                 sprintf(string, _("EDL %s not found.\n"), path);
507                 if( mwindow ) {
508                         ErrorBox error_box(_(PROGRAM_NAME ": Error"),
509                                 mwindow->gui->get_abs_cursor_x(1),
510                                 mwindow->gui->get_abs_cursor_y(1));
511                         error_box.create_objects(string);
512                         error_box.run_window();
513                         gui->button_enable();
514                 }
515                 else {
516                         fprintf(stderr, "%s", string);
517                 }
518                 is_rendering = 0;
519                 ret = 1;
520         }
521
522         if( !ret && warn && mwindow ) {
523                 ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
524                 if( !warn ) gui->warning->update(0);
525         }
526         if( !ret && mwindow )
527                 ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
528         if( !ret && mwindow )
529                 ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
530         if( !ret && mwindow )
531                 ret = test_errmsg(no_labels, _("%d job EDLs Create new file at labels checked, but no labels\n"), 0);
532         if( ret )
533                 is_rendering = 0;
534         return ret;
535 }
536
537 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
538         Preferences *preferences)
539 {
540         for( int i = 0; i < jobs.total; i++ ) {
541                 BatchRenderJob *job = jobs.values[i];
542                 if( job->enabled && *job->edl_path != '@' ) {
543                         PackageDispatcher *packages = new PackageDispatcher;
544
545 // Load EDL
546                         TransportCommand *command = new TransportCommand(preferences);
547                         FileXML *file = new FileXML;
548                         file->read_from_file(job->edl_path);
549
550 // Use command to calculate range.
551                         command->command = NORMAL_FWD;
552                         command->get_edl()->load_xml(file,
553                                 LOAD_ALL);
554                         command->change_type = CHANGE_ALL;
555                         command->set_playback_range();
556                         command->playback_range_adjust_inout();
557
558 // Create test packages
559                         int result = packages->create_packages(mwindow, command->get_edl(),
560                                 preferences, job->get_strategy(), job->asset,
561                                 command->start_position, command->end_position, 0);
562                         if( !result )
563                                 packages->get_package_paths(paths);
564
565 // Append output paths allocated to total
566
567 // Delete package harness
568                         delete packages;
569                         delete command;
570                         delete file;
571                 }
572         }
573 }
574
575
576 void BatchRenderThread::start_rendering(char *config_path,
577         char *batch_path)
578 {
579         BC_Hash *boot_defaults;
580         Preferences *preferences;
581         Render *render;
582         BC_Signals *signals = new BC_Signals;
583         // XXX the above stuff is leaked,
584 //PRINT_TRACE
585 // Initialize stuff which MWindow does.
586         signals->initialize("/tmp/cinelerra_batch%d.dmp");
587         boot_defaults = 0;
588         MWindow::init_defaults(boot_defaults, config_path);
589         load_defaults(boot_defaults);
590         preferences = new Preferences;
591         preferences->load_defaults(boot_defaults);
592         BC_Signals::set_trap_hook(trap_hook, this);
593         BC_Signals::set_catch_segv(preferences->trap_sigsegv);
594         BC_Signals::set_catch_intr(0);
595         if( preferences->trap_sigsegv ) {
596                 BC_Trace::enable_locks();
597         }
598         else {
599                 BC_Trace::disable_locks();
600         }
601 // In batch mode there is no mwindow, so init_plugins is called with
602 // mwindow* = NULL.
603         MWindow::init_plugins(0, preferences);
604         MWindow::init_ladspa_plugins(0, preferences);  
605         char font_path[BCTEXTLEN];
606         strcpy(font_path, preferences->plugin_dir);
607         strcat(font_path, "/" FONT_SEARCHPATH);
608         BC_Resources::init_fontconfig(font_path);
609         BC_WindowBase::get_resources()->vframe_shm = 1;
610
611 //PRINT_TRACE
612         strcpy(this->batch_path, batch_path);
613         load_jobs(batch_path, preferences);
614         save_jobs(batch_path);
615         save_defaults(boot_defaults);
616
617 //PRINT_TRACE
618 // Test EDL files for existence
619         if( test_edl_files() ) return;
620
621 //PRINT_TRACE
622
623 // Predict all destination paths
624         ArrayList<char*> paths;
625         paths.set_array_delete();
626         calculate_dest_paths(&paths, preferences);
627
628 //PRINT_TRACE
629         int result = ConfirmSave::test_files(0, &paths);
630         paths.remove_all_objects();
631 // Abort on any existing file because it's so hard to set this up.
632         if( result ) return;
633
634 //PRINT_TRACE
635         render = new Render(0);
636 //PRINT_TRACE
637         render->start_batches(&jobs, boot_defaults, preferences);
638 //PRINT_TRACE
639 }
640
641 void BatchRenderThread::start_rendering()
642 {
643         if( is_rendering ) return;
644         is_rendering = 1;
645
646         save_jobs(batch_path);
647         save_defaults(mwindow->defaults);
648         gui->button_disable();
649
650 // Test EDL files for existence
651         if( test_edl_files() ) return;
652
653 // Predict all destination paths
654         ArrayList<char*> paths;
655         calculate_dest_paths(&paths,
656                 mwindow->preferences);
657
658 // Test destination files for overwrite
659         int result = ConfirmSave::test_files(mwindow, &paths);
660         paths.remove_all_objects();
661
662 // User cancelled
663         if( result ) {
664                 is_rendering = 0;
665                 gui->button_enable();
666                 return;
667         }
668
669         mwindow->render->start_batches(&jobs);
670 }
671
672 void BatchRenderThread::stop_rendering()
673 {
674         if( !is_rendering ) return;
675         mwindow->render->stop_operation();
676         is_rendering = 0;
677 }
678
679 void BatchRenderThread::update_active(int number)
680 {
681         gui->lock_window("BatchRenderThread::update_active");
682         if( number >= 0 ) {
683                 current_job = number;
684                 rendering_job = number;
685         }
686         else {
687                 rendering_job = -1;
688                 is_rendering = 0;
689         }
690         gui->create_list(1);
691         gui->unlock_window();
692 }
693
694 void BatchRenderThread::update_done(int number,
695         int create_list,
696         double elapsed_time)
697 {
698         gui->lock_window("BatchRenderThread::update_done");
699         if( number < 0 ) {
700                 gui->button_enable();
701         }
702         else {
703                 jobs.values[number]->enabled = 0;
704                 jobs.values[number]->elapsed = elapsed_time;
705                 if( create_list ) gui->create_list(1);
706         }
707         gui->unlock_window();
708 }
709
710 void BatchRenderThread::move_batch(int src, int dst)
711 {
712         BatchRenderJob *src_job = jobs.values[src];
713         if( dst < 0 ) dst = jobs.total - 1;
714
715         if( dst != src ) {
716                 for( int i = src; i < jobs.total - 1; i++ )
717                         jobs.values[i] = jobs.values[i + 1];
718 //              if( dst > src ) dst--;
719                 for( int i = jobs.total - 1; i > dst; i-- )
720                         jobs.values[i] = jobs.values[i - 1];
721                 jobs.values[dst] = src_job;
722                 gui->create_list(1);
723         }
724 }
725
726 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
727 {
728         MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
729         fprintf(fp, "\nEDL:\n");
730         mwindow->dump_edl(fp);
731         fprintf(fp, "\nUNDO:\n");
732         mwindow->dump_undo(fp);
733         fprintf(fp, "\nEXE:\n");
734         mwindow->dump_exe(fp);
735 }
736
737
738
739
740
741 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
742         BatchRenderThread *thread, int x, int y, int w, int h)
743  : BC_Window(_(PROGRAM_NAME ": Batch Render"),
744         x, y, w, h, xS(730), yS(400), 1, 0, 1)
745 {
746         this->mwindow = mwindow;
747         this->thread = thread;
748         use_renderfarm = 0;
749 // *** CONTEXT_HELP ***
750         context_help_set_keyword("Batch Rendering");
751 }
752
753 BatchRenderGUI::~BatchRenderGUI()
754 {
755         lock_window("BatchRenderGUI::~BatchRenderGUI");
756         loadlist_batch->stop();
757         savelist_batch->stop();
758         delete format_tools;
759         unlock_window();
760 }
761
762
763 void BatchRenderGUI::create_objects()
764 {
765         int xs10 = xS(10), xs30 = xS(30), xs40 = xS(40);
766         int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15);
767         lock_window("BatchRenderGUI::create_objects");
768         mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
769         create_list(0);
770
771         int x = mwindow->theme->batchrender_x1;
772         int y = ys5;
773         int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
774         int y1 = ys5, y2 = ys5;
775
776 // output file
777         add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
778         y1 += output_path_title->get_h() + mwindow->theme->widget_border;
779
780         format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
781         format_tools->set_w(x2 - xs40);
782         BatchRenderJob *current_job = thread->get_current_job();
783         format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
784                         thread->do_labeled ? &current_job->labeled : 0, 0);
785         if( thread->do_labeled < 0 )
786                 format_tools->labeled_files->disable();
787         if( thread->do_farmed ) {
788                 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
789                         &current_job->farmed);
790                 add_subwindow(use_renderfarm);
791                 y1 += use_renderfarm->get_h() + ys10;
792                 if( thread->do_farmed < 0 )
793                         use_renderfarm->disable();
794         }
795
796 // input EDL
797         add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
798         y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
799
800         x = x2;  y = y2;
801         add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
802                 x, y, get_w()-x - xs40, thread->get_current_edl()));
803         x =  x2 + edl_path_text->get_w();
804         add_subwindow(edl_path_browse = new BrowseButton(
805                 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
806                 _("Input EDL"), _("Select an EDL to load:"), 0));
807         y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
808
809         x = x2;  y = y2;
810         if (mwindow->preferences->unsafe_gui) {
811         add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
812         y += update_selected_edl->get_h() + mwindow->theme->widget_border;
813         }
814         add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
815         y += use_current_edl->get_h() + mwindow->theme->widget_border;
816         if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
817         add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
818         x += new_batch->get_w() + mwindow->theme->widget_border;
819         add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
820         x = x2;  y += delete_batch->get_h() + mwindow->theme->widget_border;
821         add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
822         x += savelist_batch->get_w() + mwindow->theme->widget_border;
823         add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
824         y += loadlist_batch->get_h() + mwindow->theme->widget_border;
825         if (mwindow->preferences->unsafe_gui) {
826         add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
827         y2 = y + warning->get_h() + mwindow->theme->widget_border;
828         }
829         if( y2 > y1 ) y1 = y2;
830         x = mwindow->theme->batchrender_x1, y = y1;
831
832         add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
833         x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
834         add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
835         y += list_title->get_h() + mwindow->theme->widget_border;
836         y1 = get_h();
837         y1 -= ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
838         add_subwindow(batch_list = new BatchRenderList(thread, x, y,
839                 get_w() - x - xs10, y1 - y));
840         y += batch_list->get_h() + mwindow->theme->widget_border;
841
842         add_subwindow(start_button = new BatchRenderStart(thread, x, y));
843         x = get_w() / 3 - BC_GenericButton::calculate_w(this, _("Stop")) / 3;
844         add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
845         x = get_w() / 1.5 - BC_GenericButton::calculate_w(this, _("?")) / 1.5;
846         add_subwindow(help_button = new BatchRenderHelp(thread, x, y));
847         x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - xs10;
848         add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
849
850         show_window(1);
851         unlock_window();
852 }
853
854 void BatchRenderGUI::button_disable()
855 {
856         new_batch->disable();
857         delete_batch->disable();
858         use_current_edl->disable();
859         if (mwindow->preferences->unsafe_gui)
860         update_selected_edl->disable();
861 }
862
863 void BatchRenderGUI::button_enable()
864 {
865         new_batch->enable();
866         delete_batch->enable();
867         if( mwindow->edl && mwindow->edl->path[0] )
868                 use_current_edl->enable();
869         if (mwindow->preferences->unsafe_gui)
870         update_selected_edl->enable();
871 }
872
873 int BatchRenderGUI::resize_event(int w, int h)
874 {
875         int xs10 = xS(10), xs40 = xS(40);
876         int ys5 = yS(5), ys15 = yS(15);
877         mwindow->session->batchrender_w = w;
878         mwindow->session->batchrender_h = h;
879         mwindow->theme->get_batchrender_sizes(this, w, h);
880
881         int x = mwindow->theme->batchrender_x1;
882         int y = ys5;
883         int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
884         int y1 = ys5, y2 = ys5;
885
886 // output file
887         output_path_title->reposition_window(x1, y1);
888         y1 += output_path_title->get_h() + mwindow->theme->widget_border;
889         format_tools->reposition_window(x1, y1);
890         if( thread->do_farmed )
891                 use_renderfarm->reposition_window(x1, y1);
892 // input EDL
893         x = x2, y = y2;
894         edl_path_title->reposition_window(x, y);
895         y += edl_path_title->get_h() + mwindow->theme->widget_border;
896         edl_path_text->reposition_window(x, y, w - x - xs40);
897         x += edl_path_text->get_w();
898         edl_path_browse->reposition_window(x, y);
899         y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
900
901         x = x2;  y = y2;
902         if (mwindow->preferences->unsafe_gui) {
903         update_selected_edl->reposition_window(x, y);
904         y += update_selected_edl->get_h() + mwindow->theme->widget_border;
905         }
906         use_current_edl->reposition_window(x, y);
907         y += use_current_edl->get_h() + mwindow->theme->widget_border;
908         new_batch->reposition_window(x, y);
909         x += new_batch->get_w() + mwindow->theme->widget_border;
910         delete_batch->reposition_window(x, y);
911
912         x = x2;  y += delete_batch->get_h() + mwindow->theme->widget_border;
913         savelist_batch->reposition_window(x, y);
914         x += savelist_batch->get_w() + mwindow->theme->widget_border;
915         loadlist_batch->reposition_window(x, y);
916         y += loadlist_batch->get_h() + mwindow->theme->widget_border;
917         if (mwindow->preferences->unsafe_gui) {
918         warning->reposition_window(x2, y);
919         }
920         y1 = ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
921         y2 = get_h() - y1 - batch_list->get_h();
922         y2 -= list_title->get_h() + mwindow->theme->widget_border;
923
924         x = mwindow->theme->batchrender_x1;  y = y2;
925         list_title->reposition_window(x, y);
926         y += list_title->get_h() + mwindow->theme->widget_border;
927         batch_list->reposition_window(x, y, w - x - xs10, h - y - y1);
928         y += batch_list->get_h() + mwindow->theme->widget_border;
929
930         start_button->reposition_window(x, y);
931         x = w / 3 - stop_button->get_w() / 3;
932         stop_button->reposition_window(x, y);
933         x = w - cancel_button->get_w() - xs10;
934         cancel_button->reposition_window(x, y);
935         x = w / 1.5 - help_button->get_w() / 1.5;
936         help_button->reposition_window(x, y);
937         return 1;
938 }
939
940 int BatchRenderGUI::translation_event()
941 {
942         mwindow->session->batchrender_x = get_x();
943         mwindow->session->batchrender_y = get_y();
944         return 1;
945 }
946
947 int BatchRenderGUI::close_event()
948 {
949 // Stop batch rendering
950         unlock_window();
951         thread->stop_rendering();
952         lock_window("BatchRenderGUI::close_event");
953         set_done(1);
954         return 1;
955 }
956
957 void BatchRenderGUI::create_list(int update_widget)
958 {
959         for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
960                 list_items[i].remove_all_objects();
961         }
962
963         const char **column_titles = BatchRenderThread::column_titles;
964         list_columns = 0;
965         list_titles[list_columns] = _(column_titles[ENABLED_COL]);
966         list_width[list_columns++] = thread->list_width[ENABLED_COL];
967         if( thread->do_labeled > 0 ) {
968                 list_titles[list_columns] = _(column_titles[LABELED_COL]);
969                 list_width[list_columns++] = thread->list_width[LABELED_COL];
970         }
971         if( thread->do_farmed > 0 ) {
972                 list_titles[list_columns] = _(column_titles[FARMED_COL]);
973                 list_width[list_columns++] = thread->list_width[FARMED_COL];
974         }
975         list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
976         list_width[list_columns++] = thread->list_width[OUTPUT_COL];
977         list_titles[list_columns] = _(column_titles[EDL_COL]);
978         list_width[list_columns++] = thread->list_width[EDL_COL];
979         list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
980         list_width[list_columns++] = thread->list_width[ELAPSED_COL];
981
982         for( int i = 0; i < thread->jobs.total; i++ ) {
983                 BatchRenderJob *job = thread->jobs.values[i];
984                 char string[BCTEXTLEN];
985                 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
986                 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
987                         new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
988                 BC_ListBoxItem *farmed  = thread->do_farmed > 0 ?
989                         new BC_ListBoxItem(job->farmed  ? "X" : " ") : 0;
990                 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
991                 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
992                 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
993                         Units::totext(string, job->elapsed, TIME_HMS2));
994                 int col = 0;
995                 list_items[col++].append(enabled);
996                 if( labeled ) list_items[col++].append(labeled);
997                 if( farmed ) list_items[col++].append(farmed);
998                 list_items[col++].append(out_path);
999                 list_items[col++].append(edl_path);
1000                 list_items[col].append(elapsed);
1001                 if( i == thread->current_job ) {
1002                         enabled->set_selected(1);
1003                         if( labeled ) labeled->set_selected(1);
1004                         if( farmed ) farmed->set_selected(1);
1005                         out_path->set_selected(1);
1006                         edl_path->set_selected(1);
1007                         elapsed->set_selected(1);
1008                 }
1009                 if( i == thread->rendering_job ) {
1010                         enabled->set_color(RED);
1011                         if( labeled ) labeled->set_color(RED);
1012                         if( farmed ) farmed->set_color(RED);
1013                         out_path->set_color(RED);
1014                         edl_path->set_color(RED);
1015                         elapsed->set_color(RED);
1016                 }
1017         }
1018
1019         if( update_widget ) {
1020                 batch_list->update(list_items, list_titles, list_width, list_columns,
1021                         batch_list->get_xposition(), batch_list->get_yposition(),
1022                         batch_list->get_highlighted_item(), 1, 1);
1023         }
1024 }
1025
1026 void BatchRenderGUI::change_job()
1027 {
1028         BatchRenderJob *job = thread->get_current_job();
1029         format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
1030         if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
1031         edl_path_text->update(job->edl_path);
1032 }
1033
1034
1035 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1036  : FormatTools(mwindow, gui, asset)
1037 {
1038         this->gui = gui;
1039         this->mwindow = mwindow;
1040 }
1041
1042 BatchFormat::~BatchFormat()
1043 {
1044 }
1045
1046
1047 int BatchFormat::handle_event()
1048 {
1049         gui->create_list(1);
1050         return 1;
1051 }
1052
1053 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1054         int x, int y, int w, char *text)
1055  : BC_TextBox(x, y, w, 1, text)
1056 {
1057         this->thread = thread;
1058 }
1059
1060
1061 int BatchRenderEDLPath::handle_event()
1062 {
1063         calculate_suggestions();
1064         strcpy(thread->get_current_edl(), get_text());
1065         thread->gui->create_list(1);
1066         return 1;
1067 }
1068
1069 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1070         int x,
1071         int y)
1072  : BC_GenericButton(x, y, _("New"))
1073 {
1074         this->thread = thread;
1075         set_tooltip(_("Create a new batch"));
1076 }
1077
1078 int BatchRenderNew::handle_event()
1079 {
1080         thread->new_job();
1081         return 1;
1082 }
1083
1084 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1085  : BC_GenericButton(x, y, _("Delete"))
1086 {
1087         this->thread = thread;
1088         set_tooltip(_("Delete loaded (highlighted) batch"));
1089 }
1090
1091 int BatchRenderDelete::handle_event()
1092 {
1093         thread->delete_job();
1094         return 1;
1095 }
1096
1097
1098
1099 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1100  : BC_GenericButton(x, y, _("Save Jobs"))
1101 {
1102         this->thread = thread;
1103         set_tooltip(_("Save a Batch Render List"));
1104         gui = 0;
1105         startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1106 }
1107
1108 BatchRenderSaveList::~BatchRenderSaveList()
1109 {
1110         stop();
1111         delete startup_lock;
1112 }
1113
1114 void BatchRenderSaveList::stop()
1115 {
1116         startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1117         if( gui ) gui->set_done(1);
1118         startup_lock->unlock();
1119         Thread::join();
1120 }
1121
1122 int BatchRenderSaveList::handle_event()
1123 {
1124         if( Thread::running() ) {
1125                 if( gui ) {
1126                         gui->lock_window();
1127                         gui->raise_window();
1128                         gui->unlock_window();
1129                 }
1130                 return 1;
1131         }
1132         startup_lock->lock("BatchRenderSaveList::handle_event 1");
1133         Thread::start();
1134         startup_lock->lock("BatchRenderSaveList::handle_event 2");
1135         startup_lock->unlock();
1136         return 1;
1137 }
1138
1139 void BatchRenderSaveList::run()
1140 {
1141         char default_path[BCTEXTLEN];
1142         sprintf(default_path, "~");
1143         thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1144         BC_FileBox filewindow(xS(100), yS(100), default_path,
1145                         _("Save Batch Render List"),
1146                         _("Enter a Batch Render filename to save as:"),
1147                         0, 0, 0, 0);
1148         gui = &filewindow;
1149
1150         startup_lock->unlock();
1151         filewindow.create_objects();
1152
1153         int result2 = filewindow.run_window();
1154         if( !result2 ) {
1155                 strcpy(thread->batch_path, filewindow.get_submitted_path());
1156                 thread->gui->lock_window("BatchRenderSaveList::run");
1157                 thread->gui->batch_path->update(thread->batch_path);
1158                 thread->gui->unlock_window();
1159                 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1160                 thread->save_jobs(thread->batch_path);
1161         }
1162
1163         startup_lock->lock("BatchRenderLoadList::run");
1164         gui = 0;
1165         startup_lock->unlock();
1166 }
1167
1168 int BatchRenderSaveList::keypress_event() {
1169         if( get_keypress() == 's' ||
1170             get_keypress() == 'S' ) return handle_event();
1171         return context_help_check_and_show();
1172 }
1173
1174
1175 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1176         int x,
1177         int y)
1178   : BC_GenericButton(x, y, _("Load Jobs")),
1179     Thread()
1180 {
1181         this->thread = thread;
1182         set_tooltip(_("Load a previously saved Batch Render List"));
1183         gui = 0;
1184         startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1185 }
1186
1187 BatchRenderLoadList::~BatchRenderLoadList()
1188 {
1189         stop();
1190         delete startup_lock;
1191 }
1192
1193 void BatchRenderLoadList::stop()
1194 {
1195         startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1196         if( gui ) gui->set_done(1);
1197         startup_lock->unlock();
1198         Thread::join();
1199 }
1200
1201 int BatchRenderLoadList::handle_event()
1202 {
1203         if( Thread::running() ) {
1204                 if( gui ) {
1205                         gui->lock_window();
1206                         gui->raise_window();
1207                         gui->unlock_window();
1208                 }
1209                 return 1;
1210         }
1211         startup_lock->lock("BatchRenderLoadList::handle_event 1");
1212         Thread::start();
1213         startup_lock->lock("BatchRenderLoadList::handle_event 2");
1214         startup_lock->unlock();
1215         return 1;
1216 }
1217
1218 void BatchRenderLoadList::run()
1219 {
1220         char default_path[BCTEXTLEN];
1221         sprintf(default_path, "~");
1222         thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1223         BC_FileBox filewindow(xS(100), yS(100), default_path, _("Load Batch Render List"),
1224                         _("Enter a Batch Render filename to load from:"),
1225                         0, 0, 0, 0);
1226         gui = &filewindow;
1227
1228         startup_lock->unlock();
1229         filewindow.create_objects();
1230
1231         int result2 = filewindow.run_window();
1232         if( !result2 ) {
1233                 thread->gui->lock_window("BatchRenderLoadList::run");
1234                 strcpy(thread->batch_path, filewindow.get_submitted_path());
1235                 thread->gui->batch_path->update(thread->batch_path);
1236                 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1237                 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1238                 thread->gui->create_list(1);
1239                 thread->current_job = 0;
1240                 thread->gui->change_job();
1241                 thread->gui->unlock_window();
1242         }
1243
1244         startup_lock->lock("BatchRenderLoadList::run");
1245         gui = 0;
1246         startup_lock->unlock();
1247 }
1248
1249 int BatchRenderLoadList::keypress_event() {
1250         if( get_keypress() == 'o' ||
1251             get_keypress() == 'O' ) return handle_event();
1252         return context_help_check_and_show();
1253 }
1254
1255 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1256         int x,
1257         int y)
1258  : BC_GenericButton(x, y, _("Use Current EDL"))
1259 {
1260         this->thread = thread;
1261         set_tooltip(_("Replaces highlighted batch job with session currently on timeline. File on disk NOT changed!"));
1262 }
1263
1264 int BatchRenderCurrentEDL::handle_event()
1265 {
1266         thread->use_current_edl();
1267         return 1;
1268 }
1269
1270 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1271         int x,
1272         int y)
1273  : BC_GenericButton(x, y, _("Save to EDL Path"))
1274 {
1275         this->thread = thread;
1276         set_tooltip(_("WARNING - saves to loaded (highlighted) EDL, *overwrites* highlighted project!"));
1277 }
1278
1279 int BatchRenderUpdateEDL::handle_event()
1280 {
1281         thread->update_selected_edl();
1282         return 1;
1283 }
1284
1285
1286 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1287         int x, int y, int w, int h)
1288  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1289         thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1290         0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1291 {
1292         this->thread = thread;
1293         dragging_item = 0;
1294         set_process_drag(0);
1295 }
1296
1297 int BatchRenderList::handle_event()
1298 {
1299         return 1;
1300 }
1301
1302 int BatchRenderList::selection_changed()
1303 {
1304         thread->current_job = get_selection_number(0, 0);
1305         thread->gui->change_job();
1306         int cursor_x = get_cursor_x();
1307         BatchRenderJob *job = thread->get_current_job();
1308         int col_x = 0, changed = 1;
1309         if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1310                 job->enabled = !job->enabled;
1311         else if( thread->do_labeled > 0 &&
1312                  cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1313                 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1314         else if( thread->do_farmed > 0 &&
1315                  cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1316                 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1317         else
1318                 changed = 0;
1319         if( changed ) {
1320                 thread->gui->create_list(1);
1321                 thread->gui->change_job();
1322         }
1323         return 1;
1324 }
1325
1326 int BatchRenderList::column_resize_event()
1327 {
1328         int col = 0;
1329         thread->list_width[ENABLED_COL] = get_column_width(col++);
1330         if( thread->do_labeled > 0 )
1331                 thread->list_width[LABELED_COL] = get_column_width(col++);
1332         if( thread->do_farmed > 0 )
1333                 thread->list_width[FARMED_COL] = get_column_width(col++);
1334         thread->list_width[OUTPUT_COL] = get_column_width(col++);
1335         thread->list_width[EDL_COL] = get_column_width(col++);
1336         thread->list_width[ELAPSED_COL] = get_column_width(col);
1337         return 1;
1338 }
1339
1340 int BatchRenderList::drag_start_event()
1341 {
1342         if( BC_ListBox::drag_start_event() ) {
1343                 dragging_item = 1;
1344                 return 1;
1345         }
1346
1347         return 0;
1348 }
1349
1350 int BatchRenderList::drag_motion_event()
1351 {
1352         if( BC_ListBox::drag_motion_event() ) {
1353                 return 1;
1354         }
1355         return 0;
1356 }
1357
1358 int BatchRenderList::drag_stop_event()
1359 {
1360         if( dragging_item ) {
1361                 int src = get_selection_number(0, 0);
1362                 int dst = get_highlighted_item();
1363                 if( src != dst ) {
1364                         thread->move_batch(src, dst);
1365                 }
1366                 BC_ListBox::drag_stop_event();
1367                 dragging_item = 0;
1368         }
1369         return 0;
1370 }
1371
1372
1373
1374 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1375  : BC_GenericButton(x, y, _("Start"))
1376 {
1377         this->thread = thread;
1378         set_tooltip(_("Start batch rendering"));
1379 }
1380
1381 int BatchRenderStart::handle_event()
1382 {
1383         thread->start_rendering();
1384         return 1;
1385 }
1386
1387 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1388  : BC_GenericButton(x, y, _("Stop"))
1389 {
1390         this->thread = thread;
1391         set_tooltip(_("Stops currently active batch rendering"));
1392 }
1393
1394 int BatchRenderStop::handle_event()
1395 {
1396         unlock_window();
1397         thread->stop_rendering();
1398         lock_window("BatchRenderStop::handle_event");
1399         return 1;
1400 }
1401
1402
1403 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1404  : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1405 {
1406         this->thread = thread;
1407         set_tooltip(_("Prevents rendering if loaded session and batch job(s) differ"));
1408 }
1409
1410 int BatchRenderWarning::handle_event()
1411 {
1412         thread->warn = get_value();
1413         return 1;
1414 }
1415
1416 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1417  : BC_GenericButton(x, y, _("Close"))
1418 {
1419         this->thread = thread;
1420         set_tooltip(_("Closes this window"));
1421 }
1422
1423 int BatchRenderCancel::handle_event()
1424 {
1425         unlock_window();
1426         thread->stop_rendering();
1427         lock_window("BatchRenderCancel::handle_event");
1428         thread->gui->set_done(1);
1429         return 1;
1430 }
1431
1432 int BatchRenderCancel::keypress_event()
1433 {
1434         if( get_keypress() == ESC ) {
1435                 unlock_window();
1436                 thread->stop_rendering();
1437                 lock_window("BatchRenderCancel::keypress_event");
1438                 thread->gui->set_done(1);
1439                 return 1;
1440         }
1441         return context_help_check_and_show();
1442 }
1443
1444 //new help button
1445 BatchRenderHelp::BatchRenderHelp(BatchRenderThread *thread, int x, int y)
1446  : BC_GenericButton(x, y, _("?"))
1447 {
1448         this->thread = thread;
1449         set_tooltip(_("Open quick start guide in default browser"));
1450 }
1451
1452 int BatchRenderHelp::handle_event()
1453 {
1454         system("xdg-open file://$CIN_DAT/doc/help_br_index.html");
1455         return 0;
1456 }
1457
1458 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1459  : BC_CheckBox(x, y, *output, _("Use render farm"))
1460 {
1461         this->thread = thread;
1462         this->output = output;
1463 }
1464
1465 int BatchRenderUseFarm::handle_event()
1466 {
1467         *output = get_value();
1468         thread->gui->create_list(1);
1469         return 1;
1470 }
1471
1472 void BatchRenderUseFarm::update(int *output)
1473 {
1474         this->output = output;
1475         BC_CheckBox::update(*output);
1476 }
1477