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