version update
[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, 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
413 // Test EDL files for existence
414 int BatchRenderThread::test_edl_files()
415 {
416         int ret = 0;
417         const char *path = 0;
418         BatchRenderWarnJobs not_equiv;
419         BatchRenderWarnJobs empty_jobs;
420
421         for( int i=0; !ret && i<jobs.size(); ++i ) {
422                 if( !jobs.values[i]->enabled ) continue;
423                 path = jobs.values[i]->edl_path;
424                 int is_script = *path == '@' ? 1 : 0;
425                 if( is_script ) ++path;
426                 FILE *fp = fopen(path, "r");
427                 if( fp ) {
428                         if( mwindow && !is_script ) {
429                                 char *bfr = 0;  size_t sz = 0;
430                                 struct stat st;
431                                 if( !fstat(fileno(fp), &st) ) {
432                                         sz = st.st_size;
433                                         bfr = new char[sz+1];
434                                         if( fread(bfr, 1, sz+1, fp) != sz )
435                                                 ret = 1;
436                                         else
437                                                 bfr[sz] = 0;
438                                 }
439                                 if( !ret ) {
440                                         EDL *edl = new EDL; edl->create_objects();
441                                         XMLBuffer data(bfr, sz, 0);
442                                         { FileXML file;
443                                         file.set_shared_input(&data);
444                                         edl->load_xml(&file, LOAD_ALL); }
445                                         double pos = edl->equivalent_output(mwindow->edl);
446                                         if( pos >= 0 ) not_equiv.add(i+1, path);
447                                         double length = edl->tracks->total_playable_length();
448                                         double start = edl->local_session->get_selectionstart(1);
449                                         if( start >= length ) empty_jobs.add(i+1, path);
450                                         edl->remove_user();
451                                 }
452                                 delete [] bfr;
453                         }
454                         fclose(fp);
455                 }
456                 else
457                         ret = 1;
458         }
459
460         if( ret ) {
461                 char string[BCTEXTLEN];
462                 sprintf(string, _("EDL %s not found.\n"), path);
463                 if( mwindow ) {
464                         ErrorBox error_box(_(PROGRAM_NAME ": Error"),
465                                 mwindow->gui->get_abs_cursor_x(1),
466                                 mwindow->gui->get_abs_cursor_y(1));
467                         error_box.create_objects(string);
468                         error_box.run_window();
469                         gui->button_enable();
470                 }
471                 else {
472                         fprintf(stderr, "%s", string);
473                 }
474                 is_rendering = 0;
475         }
476
477         int mismatched = not_equiv.size();
478         if( is_rendering && warn && mwindow && mismatched > 0 ) {
479                 fprintf(stderr, _("%d job EDLs do not match session edl\n"), mismatched);
480                 char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
481                 sp += snprintf(sp,ep-sp, _("%d job EDLs do not match session edl\n"),mismatched);
482                 for( int i=0; i<mismatched; ++i ) {
483                         int no = not_equiv[i].no;  const char *path = not_equiv[i].path;
484                         fprintf(stderr, "%d: %s\n", no, path);
485                         sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
486                 }
487                 sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
488                 mwindow->show_warning(&warn, string);
489                 if( mwindow->wait_warning() ) {
490                         gui->button_enable();
491                         is_rendering = 0;
492                         ret = 1;
493                 }
494                 gui->warning->update(warn);
495         }
496
497         int empty = empty_jobs.size();
498         if( is_rendering && empty > 0 ) {
499                 fprintf(stderr, _("%d job EDLs begin position beyond end of media\n"), empty);
500                 char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
501                 sp += snprintf(sp,ep-sp, _("%d job EDLs begin position beyond end of media\n"), empty);
502                 for( int i=0; i<empty; ++i ) {
503                         int no = empty_jobs[i].no;  const char *path = empty_jobs[i].path;
504                         fprintf(stderr, "%d: %s\n", no, path);
505                         sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
506                 }
507                 sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
508                 mwindow->show_warning(0, string);
509                 if( mwindow->wait_warning() ) {
510                         gui->button_enable();
511                         is_rendering = 0;
512                         ret = 1;
513                 }
514         }
515
516         return ret;
517 }
518
519 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
520         Preferences *preferences)
521 {
522         for( int i = 0; i < jobs.total; i++ ) {
523                 BatchRenderJob *job = jobs.values[i];
524                 if( job->enabled && *job->edl_path != '@' ) {
525                         PackageDispatcher *packages = new PackageDispatcher;
526
527 // Load EDL
528                         TransportCommand *command = new TransportCommand;
529                         FileXML *file = new FileXML;
530                         file->read_from_file(job->edl_path);
531
532 // Use command to calculate range.
533                         command->command = NORMAL_FWD;
534                         command->get_edl()->load_xml(file,
535                                 LOAD_ALL);
536                         command->change_type = CHANGE_ALL;
537                         command->set_playback_range();
538                         command->playback_range_adjust_inout();
539
540 // Create test packages
541                         packages->create_packages(mwindow, command->get_edl(),
542                                 preferences, job->get_strategy(), job->asset,
543                                 command->start_position, command->end_position, 0);
544
545 // Append output paths allocated to total
546                         packages->get_package_paths(paths);
547
548 // Delete package harness
549                         delete packages;
550                         delete command;
551                         delete file;
552                 }
553         }
554 }
555
556
557 void BatchRenderThread::start_rendering(char *config_path,
558         char *batch_path)
559 {
560         BC_Hash *boot_defaults;
561         Preferences *preferences;
562         Render *render;
563         BC_Signals *signals = new BC_Signals;
564         // XXX the above stuff is leaked,
565 //PRINT_TRACE
566 // Initialize stuff which MWindow does.
567         signals->initialize("/tmp/cinelerra_batch%d.dmp");
568         boot_defaults = 0;
569         MWindow::init_defaults(boot_defaults, config_path);
570         load_defaults(boot_defaults);
571         preferences = new Preferences;
572         preferences->load_defaults(boot_defaults);
573         BC_Signals::set_trap_hook(trap_hook, this);
574         BC_Signals::set_catch_segv(preferences->trap_sigsegv);
575         BC_Signals::set_catch_intr(0);
576         if( preferences->trap_sigsegv ) {
577                 BC_Trace::enable_locks();
578         }
579         else {
580                 BC_Trace::disable_locks();
581         }
582
583         MWindow::init_plugins(0, preferences);
584         char font_path[BCTEXTLEN];
585         strcpy(font_path, preferences->plugin_dir);
586         strcat(font_path, "/" FONT_SEARCHPATH);
587         BC_Resources::init_fontconfig(font_path);
588         BC_WindowBase::get_resources()->vframe_shm = 1;
589
590 //PRINT_TRACE
591         strcpy(this->batch_path, batch_path);
592         load_jobs(batch_path, preferences);
593         save_jobs(batch_path);
594         save_defaults(boot_defaults);
595
596 //PRINT_TRACE
597 // Test EDL files for existence
598         if( test_edl_files() ) return;
599
600 //PRINT_TRACE
601
602 // Predict all destination paths
603         ArrayList<char*> paths;
604         paths.set_array_delete();
605         calculate_dest_paths(&paths, preferences);
606
607 //PRINT_TRACE
608         int result = ConfirmSave::test_files(0, &paths);
609         paths.remove_all_objects();
610 // Abort on any existing file because it's so hard to set this up.
611         if( result ) return;
612
613 //PRINT_TRACE
614         render = new Render(0);
615 //PRINT_TRACE
616         render->start_batches(&jobs, boot_defaults, preferences);
617 //PRINT_TRACE
618 }
619
620 void BatchRenderThread::start_rendering()
621 {
622         if( is_rendering ) return;
623         is_rendering = 1;
624
625         save_jobs(batch_path);
626         save_defaults(mwindow->defaults);
627         gui->button_disable();
628
629 // Test EDL files for existence
630         if( test_edl_files() ) return;
631
632 // Predict all destination paths
633         ArrayList<char*> paths;
634         calculate_dest_paths(&paths,
635                 mwindow->preferences);
636
637 // Test destination files for overwrite
638         int result = ConfirmSave::test_files(mwindow, &paths);
639         paths.remove_all_objects();
640
641 // User cancelled
642         if( result ) {
643                 is_rendering = 0;
644                 gui->button_enable();
645                 return;
646         }
647
648         mwindow->render->start_batches(&jobs);
649 }
650
651 void BatchRenderThread::stop_rendering()
652 {
653         if( !is_rendering ) return;
654         mwindow->render->stop_operation();
655         is_rendering = 0;
656 }
657
658 void BatchRenderThread::update_active(int number)
659 {
660         gui->lock_window("BatchRenderThread::update_active");
661         if( number >= 0 ) {
662                 current_job = number;
663                 rendering_job = number;
664         }
665         else {
666                 rendering_job = -1;
667                 is_rendering = 0;
668         }
669         gui->create_list(1);
670         gui->unlock_window();
671 }
672
673 void BatchRenderThread::update_done(int number,
674         int create_list,
675         double elapsed_time)
676 {
677         gui->lock_window("BatchRenderThread::update_done");
678         if( number < 0 ) {
679                 gui->button_enable();
680         }
681         else {
682                 jobs.values[number]->enabled = 0;
683                 jobs.values[number]->elapsed = elapsed_time;
684                 if( create_list ) gui->create_list(1);
685         }
686         gui->unlock_window();
687 }
688
689 void BatchRenderThread::move_batch(int src, int dst)
690 {
691         BatchRenderJob *src_job = jobs.values[src];
692         if( dst < 0 ) dst = jobs.total - 1;
693
694         if( dst != src ) {
695                 for( int i = src; i < jobs.total - 1; i++ )
696                         jobs.values[i] = jobs.values[i + 1];
697 //              if( dst > src ) dst--;
698                 for( int i = jobs.total - 1; i > dst; i-- )
699                         jobs.values[i] = jobs.values[i - 1];
700                 jobs.values[dst] = src_job;
701                 gui->create_list(1);
702         }
703 }
704
705 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
706 {
707         MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
708         fprintf(fp, "\nEDL:\n");
709         mwindow->dump_edl(fp);
710         fprintf(fp, "\nUNDO:\n");
711         mwindow->dump_undo(fp);
712         fprintf(fp, "\nEXE:\n");
713         mwindow->dump_exe(fp);
714 }
715
716
717
718
719
720 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
721         BatchRenderThread *thread, int x, int y, int w, int h)
722  : BC_Window(_(PROGRAM_NAME ": Batch Render"),
723         x, y, w, h, 730, 400, 1, 0, 1)
724 {
725         this->mwindow = mwindow;
726         this->thread = thread;
727         use_renderfarm = 0;
728 }
729
730 BatchRenderGUI::~BatchRenderGUI()
731 {
732         lock_window("BatchRenderGUI::~BatchRenderGUI");
733         loadlist_batch->stop();
734         savelist_batch->stop();
735         delete format_tools;
736         unlock_window();
737 }
738
739
740 void BatchRenderGUI::create_objects()
741 {
742         lock_window("BatchRenderGUI::create_objects");
743         mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
744         create_list(0);
745
746         int x = mwindow->theme->batchrender_x1;
747         int y = 5;
748         int x1 = x, x2 = get_w()/2 + 30; // mwindow->theme->batchrender_x2;
749         int y1 = 5, y2 = 5;
750
751 // output file
752         add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
753         y1 += output_path_title->get_h() + mwindow->theme->widget_border;
754
755         format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
756         format_tools->set_w(x2 - 40);
757         BatchRenderJob *current_job = thread->get_current_job();
758         format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
759                         thread->do_labeled ? &current_job->labeled : 0, 0);
760         if( thread->do_labeled < 0 )
761                 format_tools->labeled_files->disable();
762         if( thread->do_farmed ) {
763                 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
764                         &current_job->farmed);
765                 add_subwindow(use_renderfarm);
766                 y1 += use_renderfarm->get_h() + 10;
767                 if( thread->do_farmed < 0 )
768                         use_renderfarm->disable();
769         }
770
771 // input EDL
772         add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
773         y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
774
775         x = x2;  y = y2;
776         add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
777                 x, y, get_w()-x - 40, thread->get_current_edl()));
778         x =  x2 + edl_path_text->get_w();
779         add_subwindow(edl_path_browse = new BrowseButton(
780                 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
781                 _("Input EDL"), _("Select an EDL to load:"), 0));
782         y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
783
784         x = x2;  y = y2;
785         add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
786         y += update_selected_edl->get_h() + mwindow->theme->widget_border;
787         add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
788         y += use_current_edl->get_h() + mwindow->theme->widget_border;
789         if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
790         add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
791         x += new_batch->get_w() + mwindow->theme->widget_border;
792         add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
793         x = x2;  y += delete_batch->get_h() + mwindow->theme->widget_border;
794         add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
795         x += savelist_batch->get_w() + mwindow->theme->widget_border;
796         add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
797         y += loadlist_batch->get_h() + mwindow->theme->widget_border;
798         add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
799         y2 = y + warning->get_h() + mwindow->theme->widget_border;
800         if( y2 > y1 ) y1 = y2;
801         x = mwindow->theme->batchrender_x1, y = y1;
802
803         add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
804         x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
805         add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
806         y += list_title->get_h() + mwindow->theme->widget_border;
807         y1 = get_h();
808         y1 -= 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
809         add_subwindow(batch_list = new BatchRenderList(thread, x, y,
810                 get_w() - x - 10, y1 - y));
811         y += batch_list->get_h() + mwindow->theme->widget_border;
812
813         add_subwindow(start_button = new BatchRenderStart(thread, x, y));
814         x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
815         add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
816         x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - 10;
817         add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
818
819         show_window(1);
820         unlock_window();
821 }
822
823 void BatchRenderGUI::button_disable()
824 {
825         new_batch->disable();
826         delete_batch->disable();
827         use_current_edl->disable();
828         update_selected_edl->disable();
829 }
830
831 void BatchRenderGUI::button_enable()
832 {
833         new_batch->enable();
834         delete_batch->enable();
835         if( mwindow->edl && mwindow->edl->path[0] )
836                 use_current_edl->enable();
837         update_selected_edl->enable();
838 }
839
840 int BatchRenderGUI::resize_event(int w, int h)
841 {
842         mwindow->session->batchrender_w = w;
843         mwindow->session->batchrender_h = h;
844         mwindow->theme->get_batchrender_sizes(this, w, h);
845
846         int x = mwindow->theme->batchrender_x1;
847         int y = 5;
848         int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
849         int y1 = 5, y2 = 5;
850
851 // output file
852         output_path_title->reposition_window(x1, y1);
853         y1 += output_path_title->get_h() + mwindow->theme->widget_border;
854         format_tools->reposition_window(x1, y1);
855         if( thread->do_farmed )
856                 use_renderfarm->reposition_window(x1, y1);
857 // input EDL
858         x = x2, y = y2;
859         edl_path_title->reposition_window(x, y);
860         y += edl_path_title->get_h() + mwindow->theme->widget_border;
861         edl_path_text->reposition_window(x, y, w - x - 40);
862         x += edl_path_text->get_w();
863         edl_path_browse->reposition_window(x, y);
864         y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
865
866         x = x2;  y = y2;
867         update_selected_edl->reposition_window(x, y);
868         y += update_selected_edl->get_h() + mwindow->theme->widget_border;
869         use_current_edl->reposition_window(x, y);
870         y += use_current_edl->get_h() + mwindow->theme->widget_border;
871         new_batch->reposition_window(x, y);
872         x += new_batch->get_w() + mwindow->theme->widget_border;
873         delete_batch->reposition_window(x, y);
874
875         x = x2;  y += delete_batch->get_h() + mwindow->theme->widget_border;
876         savelist_batch->reposition_window(x, y);
877         x += savelist_batch->get_w() + mwindow->theme->widget_border;
878         loadlist_batch->reposition_window(x, y);
879         y += loadlist_batch->get_h() + mwindow->theme->widget_border;
880         warning->reposition_window(x2, y);
881
882         y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
883         y2 = get_h() - y1 - batch_list->get_h();
884         y2 -= list_title->get_h() + mwindow->theme->widget_border;
885
886         x = mwindow->theme->batchrender_x1;  y = y2;
887         list_title->reposition_window(x, y);
888         y += list_title->get_h() + mwindow->theme->widget_border;
889         batch_list->reposition_window(x, y, w - x - 10, h - y - y1);
890         y += batch_list->get_h() + mwindow->theme->widget_border;
891
892         start_button->reposition_window(x, y);
893         x = w / 2 - stop_button->get_w() / 2;
894         stop_button->reposition_window(x, y);
895         x = w - cancel_button->get_w() - 10;
896         cancel_button->reposition_window(x, y);
897         return 1;
898 }
899
900 int BatchRenderGUI::translation_event()
901 {
902         mwindow->session->batchrender_x = get_x();
903         mwindow->session->batchrender_y = get_y();
904         return 1;
905 }
906
907 int BatchRenderGUI::close_event()
908 {
909 // Stop batch rendering
910         unlock_window();
911         thread->stop_rendering();
912         lock_window("BatchRenderGUI::close_event");
913         set_done(1);
914         return 1;
915 }
916
917 void BatchRenderGUI::create_list(int update_widget)
918 {
919         for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
920                 list_items[i].remove_all_objects();
921         }
922
923         const char **column_titles = BatchRenderThread::column_titles;
924         list_columns = 0;
925         list_titles[list_columns] = _(column_titles[ENABLED_COL]);
926         list_width[list_columns++] = thread->list_width[ENABLED_COL];
927         if( thread->do_labeled > 0 ) {
928                 list_titles[list_columns] = _(column_titles[LABELED_COL]);
929                 list_width[list_columns++] = thread->list_width[LABELED_COL];
930         }
931         if( thread->do_farmed > 0 ) {
932                 list_titles[list_columns] = _(column_titles[FARMED_COL]);
933                 list_width[list_columns++] = thread->list_width[FARMED_COL];
934         }
935         list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
936         list_width[list_columns++] = thread->list_width[OUTPUT_COL];
937         list_titles[list_columns] = _(column_titles[EDL_COL]);
938         list_width[list_columns++] = thread->list_width[EDL_COL];
939         list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
940         list_width[list_columns++] = thread->list_width[ELAPSED_COL];
941
942         for( int i = 0; i < thread->jobs.total; i++ ) {
943                 BatchRenderJob *job = thread->jobs.values[i];
944                 char string[BCTEXTLEN];
945                 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
946                 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
947                         new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
948                 BC_ListBoxItem *farmed  = thread->do_farmed > 0 ?
949                         new BC_ListBoxItem(job->farmed  ? "X" : " ") : 0;
950                 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
951                 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
952                 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
953                         Units::totext(string, job->elapsed, TIME_HMS2));
954                 int col = 0;
955                 list_items[col++].append(enabled);
956                 if( labeled ) list_items[col++].append(labeled);
957                 if( farmed ) list_items[col++].append(farmed);
958                 list_items[col++].append(out_path);
959                 list_items[col++].append(edl_path);
960                 list_items[col].append(elapsed);
961                 if( i == thread->current_job ) {
962                         enabled->set_selected(1);
963                         if( labeled ) labeled->set_selected(1);
964                         if( farmed ) farmed->set_selected(1);
965                         out_path->set_selected(1);
966                         edl_path->set_selected(1);
967                         elapsed->set_selected(1);
968                 }
969                 if( i == thread->rendering_job ) {
970                         enabled->set_color(RED);
971                         if( labeled ) labeled->set_color(RED);
972                         if( farmed ) farmed->set_color(RED);
973                         out_path->set_color(RED);
974                         edl_path->set_color(RED);
975                         elapsed->set_color(RED);
976                 }
977         }
978
979         if( update_widget ) {
980                 batch_list->update(list_items, list_titles, list_width, list_columns,
981                         batch_list->get_xposition(), batch_list->get_yposition(),
982                         batch_list->get_highlighted_item(), 1, 1);
983         }
984 }
985
986 void BatchRenderGUI::change_job()
987 {
988         BatchRenderJob *job = thread->get_current_job();
989         format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
990         if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
991         edl_path_text->update(job->edl_path);
992 }
993
994
995 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
996  : FormatTools(mwindow, gui, asset)
997 {
998         this->gui = gui;
999         this->mwindow = mwindow;
1000 }
1001
1002 BatchFormat::~BatchFormat()
1003 {
1004 }
1005
1006
1007 int BatchFormat::handle_event()
1008 {
1009         gui->create_list(1);
1010         return 1;
1011 }
1012
1013 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1014         int x, int y, int w, char *text)
1015  : BC_TextBox(x, y, w, 1, text)
1016 {
1017         this->thread = thread;
1018 }
1019
1020
1021 int BatchRenderEDLPath::handle_event()
1022 {
1023         calculate_suggestions();
1024         strcpy(thread->get_current_edl(), get_text());
1025         thread->gui->create_list(1);
1026         return 1;
1027 }
1028
1029 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1030         int x,
1031         int y)
1032  : BC_GenericButton(x, y, _("New"))
1033 {
1034         this->thread = thread;
1035 }
1036
1037 int BatchRenderNew::handle_event()
1038 {
1039         thread->new_job();
1040         return 1;
1041 }
1042
1043 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1044  : BC_GenericButton(x, y, _("Delete"))
1045 {
1046         this->thread = thread;
1047 }
1048
1049 int BatchRenderDelete::handle_event()
1050 {
1051         thread->delete_job();
1052         return 1;
1053 }
1054
1055
1056
1057 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1058  : BC_GenericButton(x, y, _("Save Jobs"))
1059 {
1060         this->thread = thread;
1061         set_tooltip(_("Save a Batch Render List"));
1062         gui = 0;
1063         startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1064 }
1065
1066 BatchRenderSaveList::~BatchRenderSaveList()
1067 {
1068         stop();
1069         delete startup_lock;
1070 }
1071
1072 void BatchRenderSaveList::stop()
1073 {
1074         startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1075         if( gui ) gui->set_done(1);
1076         startup_lock->unlock();
1077         Thread::join();
1078 }
1079
1080 int BatchRenderSaveList::handle_event()
1081 {
1082         if( Thread::running() ) {
1083                 if( gui ) {
1084                         gui->lock_window();
1085                         gui->raise_window();
1086                         gui->unlock_window();
1087                 }
1088                 return 1;
1089         }
1090         startup_lock->lock("BatchRenderSaveList::handle_event 1");
1091         Thread::start();
1092         startup_lock->lock("BatchRenderSaveList::handle_event 2");
1093         startup_lock->unlock();
1094         return 1;
1095 }
1096
1097 void BatchRenderSaveList::run()
1098 {
1099         char default_path[BCTEXTLEN];
1100         sprintf(default_path, "~");
1101         thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1102         BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
1103                         _("Enter a Batch Render filename to save as:"),
1104                         0, 0, 0, 0);
1105         gui = &filewindow;
1106
1107         startup_lock->unlock();
1108         filewindow.create_objects();
1109
1110         int result2 = filewindow.run_window();
1111         if( !result2 ) {
1112                 strcpy(thread->batch_path, filewindow.get_submitted_path());
1113                 thread->gui->lock_window("BatchRenderSaveList::run");
1114                 thread->gui->batch_path->update(thread->batch_path);
1115                 thread->gui->unlock_window();
1116                 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1117                 thread->save_jobs(thread->batch_path);
1118         }
1119
1120         startup_lock->lock("BatchRenderLoadList::run");
1121         gui = 0;
1122         startup_lock->unlock();
1123 }
1124
1125 int BatchRenderSaveList::keypress_event() {
1126         if( get_keypress() == 's' ||
1127             get_keypress() == 'S' ) return handle_event();
1128         return 0;
1129 }
1130
1131
1132 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1133         int x,
1134         int y)
1135   : BC_GenericButton(x, y, _("Load Jobs")),
1136     Thread()
1137 {
1138         this->thread = thread;
1139         set_tooltip(_("Load a previously saved Batch Render List"));
1140         gui = 0;
1141         startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1142 }
1143
1144 BatchRenderLoadList::~BatchRenderLoadList()
1145 {
1146         stop();
1147         delete startup_lock;
1148 }
1149
1150 void BatchRenderLoadList::stop()
1151 {
1152         startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1153         if( gui ) gui->set_done(1);
1154         startup_lock->unlock();
1155         Thread::join();
1156 }
1157
1158 int BatchRenderLoadList::handle_event()
1159 {
1160         if( Thread::running() ) {
1161                 if( gui ) {
1162                         gui->lock_window();
1163                         gui->raise_window();
1164                         gui->unlock_window();
1165                 }
1166                 return 1;
1167         }
1168         startup_lock->lock("BatchRenderLoadList::handle_event 1");
1169         Thread::start();
1170         startup_lock->lock("BatchRenderLoadList::handle_event 2");
1171         startup_lock->unlock();
1172         return 1;
1173 }
1174
1175 void BatchRenderLoadList::run()
1176 {
1177         char default_path[BCTEXTLEN];
1178         sprintf(default_path, "~");
1179         thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1180         BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
1181                         _("Enter a Batch Render filename to load from:"),
1182                         0, 0, 0, 0);
1183         gui = &filewindow;
1184
1185         startup_lock->unlock();
1186         filewindow.create_objects();
1187
1188         int result2 = filewindow.run_window();
1189         if( !result2 ) {
1190                 strcpy(thread->batch_path, filewindow.get_submitted_path());
1191                 thread->gui->batch_path->update(thread->batch_path);
1192                 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1193                 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1194                 thread->gui->create_list(1);
1195                 thread->current_job = 0;
1196                 thread->gui->change_job();
1197         }
1198
1199         startup_lock->lock("BatchRenderLoadList::run");
1200         gui = 0;
1201         startup_lock->unlock();
1202 }
1203
1204 int BatchRenderLoadList::keypress_event() {
1205         if( get_keypress() == 'o' ||
1206             get_keypress() == 'O' ) return handle_event();
1207         return 0;
1208 }
1209
1210 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1211         int x,
1212         int y)
1213  : BC_GenericButton(x, y, _("Use Current EDL"))
1214 {
1215         this->thread = thread;
1216 }
1217
1218 int BatchRenderCurrentEDL::handle_event()
1219 {
1220         thread->use_current_edl();
1221         return 1;
1222 }
1223
1224 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1225         int x,
1226         int y)
1227  : BC_GenericButton(x, y, _("Save to EDL Path"))
1228 {
1229         this->thread = thread;
1230 }
1231
1232 int BatchRenderUpdateEDL::handle_event()
1233 {
1234         thread->update_selected_edl();
1235         return 1;
1236 }
1237
1238
1239 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1240         int x, int y, int w, int h)
1241  : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1242         thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1243         0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1244 {
1245         this->thread = thread;
1246         dragging_item = 0;
1247         set_process_drag(0);
1248 }
1249
1250 int BatchRenderList::handle_event()
1251 {
1252         return 1;
1253 }
1254
1255 int BatchRenderList::selection_changed()
1256 {
1257         thread->current_job = get_selection_number(0, 0);
1258         thread->gui->change_job();
1259         int cursor_x = get_cursor_x();
1260         BatchRenderJob *job = thread->get_current_job();
1261         int col_x = 0, changed = 1;
1262         if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1263                 job->enabled = !job->enabled;
1264         else if( thread->do_labeled > 0 &&
1265                  cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1266                 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1267         else if( thread->do_farmed > 0 &&
1268                  cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1269                 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1270         else
1271                 changed = 0;
1272         if( changed ) {
1273                 thread->gui->create_list(1);
1274                 thread->gui->change_job();
1275         }
1276         return 1;
1277 }
1278
1279 int BatchRenderList::column_resize_event()
1280 {
1281         int col = 0;
1282         thread->list_width[ENABLED_COL] = get_column_width(col++);
1283         if( thread->do_labeled > 0 )
1284                 thread->list_width[LABELED_COL] = get_column_width(col++);
1285         if( thread->do_farmed > 0 )
1286                 thread->list_width[FARMED_COL] = get_column_width(col++);
1287         thread->list_width[OUTPUT_COL] = get_column_width(col++);
1288         thread->list_width[EDL_COL] = get_column_width(col++);
1289         thread->list_width[ELAPSED_COL] = get_column_width(col);
1290         return 1;
1291 }
1292
1293 int BatchRenderList::drag_start_event()
1294 {
1295         if( BC_ListBox::drag_start_event() ) {
1296                 dragging_item = 1;
1297                 return 1;
1298         }
1299
1300         return 0;
1301 }
1302
1303 int BatchRenderList::drag_motion_event()
1304 {
1305         if( BC_ListBox::drag_motion_event() ) {
1306                 return 1;
1307         }
1308         return 0;
1309 }
1310
1311 int BatchRenderList::drag_stop_event()
1312 {
1313         if( dragging_item ) {
1314                 int src = get_selection_number(0, 0);
1315                 int dst = get_highlighted_item();
1316                 if( src != dst ) {
1317                         thread->move_batch(src, dst);
1318                 }
1319                 BC_ListBox::drag_stop_event();
1320                 dragging_item = 0;
1321         }
1322         return 0;
1323 }
1324
1325
1326
1327 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1328  : BC_GenericButton(x, y, _("Start"))
1329 {
1330         this->thread = thread;
1331 }
1332
1333 int BatchRenderStart::handle_event()
1334 {
1335         thread->start_rendering();
1336         return 1;
1337 }
1338
1339 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1340  : BC_GenericButton(x, y, _("Stop"))
1341 {
1342         this->thread = thread;
1343 }
1344
1345 int BatchRenderStop::handle_event()
1346 {
1347         unlock_window();
1348         thread->stop_rendering();
1349         lock_window("BatchRenderStop::handle_event");
1350         return 1;
1351 }
1352
1353
1354 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1355  : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1356 {
1357         this->thread = thread;
1358 }
1359
1360 int BatchRenderWarning::handle_event()
1361 {
1362         thread->warn = get_value();
1363         return 1;
1364 }
1365
1366 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1367  : BC_GenericButton(x, y, _("Close"))
1368 {
1369         this->thread = thread;
1370 }
1371
1372 int BatchRenderCancel::handle_event()
1373 {
1374         unlock_window();
1375         thread->stop_rendering();
1376         lock_window("BatchRenderCancel::handle_event");
1377         thread->gui->set_done(1);
1378         return 1;
1379 }
1380
1381 int BatchRenderCancel::keypress_event()
1382 {
1383         if( get_keypress() == ESC ) {
1384                 unlock_window();
1385                 thread->stop_rendering();
1386                 lock_window("BatchRenderCancel::keypress_event");
1387                 thread->gui->set_done(1);
1388                 return 1;
1389         }
1390         return 0;
1391 }
1392
1393 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1394  : BC_CheckBox(x, y, *output, _("Use render farm"))
1395 {
1396         this->thread = thread;
1397         this->output = output;
1398 }
1399
1400 int BatchRenderUseFarm::handle_event()
1401 {
1402         *output = get_value();
1403         thread->gui->create_list(1);
1404         return 1;
1405 }
1406
1407 void BatchRenderUseFarm::update(int *output)
1408 {
1409         this->output = output;
1410         BC_CheckBox::update(*output);
1411 }
1412