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