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