4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "batchrender.h"
24 #include "bcdisplayinfo.h"
25 #include "bcsignals.h"
26 #include "confirmsave.h"
32 #include "edlsession.h"
35 #include "filesystem.h"
37 #include "indexable.h"
42 #include "localsession.h"
43 #include "mainerror.h"
45 #include "mainsession.h"
48 #include "mwindowgui.h"
49 #include "packagedispatcher.h"
50 #include "packagerenderer.h"
52 #include "pluginset.h"
53 #include "preferences.h"
57 #include "transportque.h"
60 #include "dvdcreate.h"
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")
68 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
69 : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
72 this->mwindow = mwindow;
75 int BatchRenderMenuItem::handle_event()
77 mwindow->batch_render->start(1, 1);
81 BatchRenderJob::BatchRenderJob(const char *tag,
82 Preferences *preferences, int labeled, int farmed)
85 this->preferences = preferences;
86 this->labeled = labeled;
87 this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
94 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
95 : BatchRenderJob("JOB", preferences, labeled, farmed)
99 BatchRenderJob::~BatchRenderJob()
101 asset->Garbage::remove_user();
104 void BatchRenderJob::copy_from(BatchRenderJob *src)
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);
114 BatchRenderJob *BatchRenderJob::copy()
116 BatchRenderJob *t = new BatchRenderJob(tag, preferences, labeled, farmed);
121 void BatchRenderJob::load(FileXML *file)
124 char job_title[BCSTRLEN];
125 strcpy(job_title, file->tag.title);
127 enabled = file->tag.get_property("ENABLED", enabled);
128 farmed = file->tag.get_property("FARMED", farmed);
129 labeled = file->tag.get_property("LABELED", labeled);
131 file->tag.get_property("EDL_PATH", edl_path);
132 elapsed = file->tag.get_property("ELAPSED", elapsed);
134 result = file->read_tag();
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
143 defaults.load_string(file->read_text(job_title));
144 asset->load_defaults(&defaults,
150 void BatchRenderJob::save(FileXML *file)
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);
160 file->append_newline();
161 asset->write(file, 0, "");
163 // The compression parameters are stored in the defaults to reduce
164 // coding maintenance. The defaults must now be stuffed into the XML for
167 asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
169 defaults.save_string(string);
170 file->append_text(string);
172 file->tag.set_title(end_tag);
174 file->append_newline();
177 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
182 int BatchRenderJob::get_strategy()
184 int range = File::is_image_render(asset->format) ?
185 RANGE_1FRAME : RANGE_SELECTION;
186 return Render::get_strategy(farmed, labeled, range);
190 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
193 this->mwindow = mwindow;
207 BatchRenderThread::~BatchRenderThread()
210 delete boot_defaults;
216 void BatchRenderThread::reset(const char *path)
219 strcpy(batch_path, path);
224 delete default_job; default_job = 0;
225 jobs.remove_all_objects();
228 void BatchRenderThread::start(int do_farmed, int do_labeled)
230 this->do_farmed = do_farmed;
231 this->do_labeled = do_labeled;
232 BC_DialogThread::start();
235 void BatchRenderThread::handle_close_event(int result)
238 save_jobs(batch_path);
239 save_defaults(mwindow->defaults);
243 BC_Window* BatchRenderThread::new_gui()
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();
258 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
263 jobs.remove_all_objects();
264 if( !path ) path = batch_path;
265 if( !path[0] ) create_path(path);
266 file.read_from_file(path);
269 if( !(result = file.read_tag()) ) {
270 if( file.tag.title_is("JOBS") ) {
271 warn = file.tag.get_property("WARN", 1);
273 else if( file.tag.title_is("JOB") ) {
274 BatchRenderJob *job = new BatchRenderJob(preferences, 0,0);
278 else if( file.tag.title_is("DVD_JOB") ) {
279 DVD_BatchRenderJob *job = new DVD_BatchRenderJob(preferences, 0,0,0,0);
283 else if( file.tag.title_is("BD_JOB") ) {
284 BD_BatchRenderJob *job = new BD_BatchRenderJob(preferences, 0,0);
292 void BatchRenderThread::save_jobs(char *path)
295 file.tag.set_title("JOBS");
296 file.tag.set_property("WARN", warn);
298 file.append_newline();
300 for( int i = 0; i < jobs.total; i++ ) {
301 file.tag.set_title(jobs[i]->tag);
302 jobs[i]->save(&file);
304 file.tag.set_title("/JOBS");
306 file.append_newline();
308 if( !path ) path = batch_path;
309 if( !path[0] ) create_path(path);
310 file.write_to_file(path);
313 void BatchRenderThread::load_defaults(BC_Hash *defaults)
316 default_job->asset->load_defaults(defaults,
317 "BATCHRENDER_", 1, 1, 1, 1, 1);
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]));
327 void BatchRenderThread::save_defaults(BC_Hash *defaults)
330 default_job->asset->save_defaults(defaults,
331 "BATCHRENDER_", 1, 1, 1, 1, 1);
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]);
338 // defaults->update("BATCHRENDER_JOB", current_job);
340 mwindow->save_defaults();
345 char* BatchRenderThread::create_path(char *string)
348 sprintf(string, "%s/", File::get_config_path());
349 fs.complete_path(string);
350 strcat(string, BATCH_PATH);
354 void BatchRenderThread::new_job()
356 BatchRenderJob *result = get_current_job()->copy();
358 current_job = jobs.total - 1;
363 void BatchRenderThread::delete_job()
365 if( current_job < jobs.total && current_job >= 0 ) {
366 jobs.remove_object_number(current_job);
367 if( current_job > 0 ) current_job--;
373 void BatchRenderThread::use_current_edl()
375 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
377 // mwindow->edl->path,
378 // mwindow->edl->path);
380 strcpy(get_current_edl(), mwindow->edl->path);
382 gui->edl_path_text->update(get_current_edl());
385 void BatchRenderThread::update_selected_edl()
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) ) {
394 sprintf(msg, _("Unable to save: %s"), path);
395 MainError::show_error(msg);
399 BatchRenderJob* BatchRenderThread::get_current_job()
401 return current_job >= 0 && current_job < jobs.total ?
402 jobs.values[current_job] : default_job;
406 Asset* BatchRenderThread::get_current_asset()
408 return get_current_job()->asset;
411 char* BatchRenderThread::get_current_edl()
413 return get_current_job()->edl_path;
416 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
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);
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();
437 // Test EDL files for existence
438 int BatchRenderThread::test_edl_files()
441 const char *path = 0;
442 BatchRenderWarnJobs not_equiv;
443 BatchRenderWarnJobs empty_jobs;
444 BatchRenderWarnJobs no_labels;
445 BatchRenderWarnJobs no_rendering;
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");
454 if( mwindow && !is_script ) {
455 char *bfr = 0; size_t sz = 0;
457 if( !fstat(fileno(fp), &st) ) {
459 bfr = new char[sz+1];
460 if( fread(bfr, 1, sz+1, fp) != sz )
466 EDL *edl = new EDL; edl->create_objects();
467 XMLBuffer data(bfr, sz, 0);
469 file.set_shared_input(&data);
470 edl->load_xml(&file, LOAD_ALL); }
471 double pos = edl->equivalent_output(mwindow->edl);
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);
494 char string[BCTEXTLEN];
495 sprintf(string, _("EDL %s not found.\n"), path);
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();
505 fprintf(stderr, "%s", string);
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);
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);
526 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
527 Preferences *preferences)
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;
535 TransportCommand *command = new TransportCommand;
536 FileXML *file = new FileXML;
537 file->read_from_file(job->edl_path);
539 // Use command to calculate range.
540 command->command = NORMAL_FWD;
541 command->get_edl()->load_xml(file,
543 command->change_type = CHANGE_ALL;
544 command->set_playback_range();
545 command->playback_range_adjust_inout();
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);
552 packages->get_package_paths(paths);
554 // Append output paths allocated to total
556 // Delete package harness
565 void BatchRenderThread::start_rendering(char *config_path,
568 BC_Hash *boot_defaults;
569 Preferences *preferences;
571 BC_Signals *signals = new BC_Signals;
572 // XXX the above stuff is leaked,
574 // Initialize stuff which MWindow does.
575 signals->initialize("/tmp/cinelerra_batch%d.dmp");
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();
588 BC_Trace::disable_locks();
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;
599 strcpy(this->batch_path, batch_path);
600 load_jobs(batch_path, preferences);
601 save_jobs(batch_path);
602 save_defaults(boot_defaults);
605 // Test EDL files for existence
606 if( test_edl_files() ) return;
610 // Predict all destination paths
611 ArrayList<char*> paths;
612 paths.set_array_delete();
613 calculate_dest_paths(&paths, preferences);
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.
622 render = new Render(0);
624 render->start_batches(&jobs, boot_defaults, preferences);
628 void BatchRenderThread::start_rendering()
630 if( is_rendering ) return;
633 save_jobs(batch_path);
634 save_defaults(mwindow->defaults);
635 gui->button_disable();
637 // Test EDL files for existence
638 if( test_edl_files() ) return;
640 // Predict all destination paths
641 ArrayList<char*> paths;
642 calculate_dest_paths(&paths,
643 mwindow->preferences);
645 // Test destination files for overwrite
646 int result = ConfirmSave::test_files(mwindow, &paths);
647 paths.remove_all_objects();
652 gui->button_enable();
656 mwindow->render->start_batches(&jobs);
659 void BatchRenderThread::stop_rendering()
661 if( !is_rendering ) return;
662 mwindow->render->stop_operation();
666 void BatchRenderThread::update_active(int number)
668 gui->lock_window("BatchRenderThread::update_active");
670 current_job = number;
671 rendering_job = number;
678 gui->unlock_window();
681 void BatchRenderThread::update_done(int number,
685 gui->lock_window("BatchRenderThread::update_done");
687 gui->button_enable();
690 jobs.values[number]->enabled = 0;
691 jobs.values[number]->elapsed = elapsed_time;
692 if( create_list ) gui->create_list(1);
694 gui->unlock_window();
697 void BatchRenderThread::move_batch(int src, int dst)
699 BatchRenderJob *src_job = jobs.values[src];
700 if( dst < 0 ) dst = jobs.total - 1;
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;
713 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
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);
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)
733 this->mwindow = mwindow;
734 this->thread = thread;
738 BatchRenderGUI::~BatchRenderGUI()
740 lock_window("BatchRenderGUI::~BatchRenderGUI");
741 loadlist_batch->stop();
742 savelist_batch->stop();
748 void BatchRenderGUI::create_objects()
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());
756 int x = mwindow->theme->batchrender_x1;
758 int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
759 int y1 = ys5, y2 = ys5;
762 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
763 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
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 ? ¤t_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 ¤t_job->farmed);
775 add_subwindow(use_renderfarm);
776 y1 += use_renderfarm->get_h() + ys10;
777 if( thread->do_farmed < 0 )
778 use_renderfarm->disable();
782 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
783 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
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;
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;
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;
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;
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));
833 void BatchRenderGUI::button_disable()
835 new_batch->disable();
836 delete_batch->disable();
837 use_current_edl->disable();
838 update_selected_edl->disable();
841 void BatchRenderGUI::button_enable()
844 delete_batch->enable();
845 if( mwindow->edl && mwindow->edl->path[0] )
846 use_current_edl->enable();
847 update_selected_edl->enable();
850 int BatchRenderGUI::resize_event(int w, int h)
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);
858 int x = mwindow->theme->batchrender_x1;
860 int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
861 int y1 = ys5, y2 = ys5;
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);
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;
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);
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);
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;
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;
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);
912 int BatchRenderGUI::translation_event()
914 mwindow->session->batchrender_x = get_x();
915 mwindow->session->batchrender_y = get_y();
919 int BatchRenderGUI::close_event()
921 // Stop batch rendering
923 thread->stop_rendering();
924 lock_window("BatchRenderGUI::close_event");
929 void BatchRenderGUI::create_list(int update_widget)
931 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
932 list_items[i].remove_all_objects();
935 const char **column_titles = BatchRenderThread::column_titles;
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];
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];
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];
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));
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);
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);
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);
998 void BatchRenderGUI::change_job()
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);
1007 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1008 : FormatTools(mwindow, gui, asset)
1011 this->mwindow = mwindow;
1014 BatchFormat::~BatchFormat()
1019 int BatchFormat::handle_event()
1021 gui->create_list(1);
1025 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1026 int x, int y, int w, char *text)
1027 : BC_TextBox(x, y, w, 1, text)
1029 this->thread = thread;
1033 int BatchRenderEDLPath::handle_event()
1035 calculate_suggestions();
1036 strcpy(thread->get_current_edl(), get_text());
1037 thread->gui->create_list(1);
1041 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1044 : BC_GenericButton(x, y, _("New"))
1046 this->thread = thread;
1049 int BatchRenderNew::handle_event()
1055 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1056 : BC_GenericButton(x, y, _("Delete"))
1058 this->thread = thread;
1061 int BatchRenderDelete::handle_event()
1063 thread->delete_job();
1069 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1070 : BC_GenericButton(x, y, _("Save Jobs"))
1072 this->thread = thread;
1073 set_tooltip(_("Save a Batch Render List"));
1075 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1078 BatchRenderSaveList::~BatchRenderSaveList()
1081 delete startup_lock;
1084 void BatchRenderSaveList::stop()
1086 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1087 if( gui ) gui->set_done(1);
1088 startup_lock->unlock();
1092 int BatchRenderSaveList::handle_event()
1094 if( Thread::running() ) {
1097 gui->raise_window();
1098 gui->unlock_window();
1102 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1104 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1105 startup_lock->unlock();
1109 void BatchRenderSaveList::run()
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:"),
1120 startup_lock->unlock();
1121 filewindow.create_objects();
1123 int result2 = filewindow.run_window();
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);
1133 startup_lock->lock("BatchRenderLoadList::run");
1135 startup_lock->unlock();
1138 int BatchRenderSaveList::keypress_event() {
1139 if( get_keypress() == 's' ||
1140 get_keypress() == 'S' ) return handle_event();
1145 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1148 : BC_GenericButton(x, y, _("Load Jobs")),
1151 this->thread = thread;
1152 set_tooltip(_("Load a previously saved Batch Render List"));
1154 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1157 BatchRenderLoadList::~BatchRenderLoadList()
1160 delete startup_lock;
1163 void BatchRenderLoadList::stop()
1165 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1166 if( gui ) gui->set_done(1);
1167 startup_lock->unlock();
1171 int BatchRenderLoadList::handle_event()
1173 if( Thread::running() ) {
1176 gui->raise_window();
1177 gui->unlock_window();
1181 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1183 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1184 startup_lock->unlock();
1188 void BatchRenderLoadList::run()
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:"),
1198 startup_lock->unlock();
1199 filewindow.create_objects();
1201 int result2 = filewindow.run_window();
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();
1214 startup_lock->lock("BatchRenderLoadList::run");
1216 startup_lock->unlock();
1219 int BatchRenderLoadList::keypress_event() {
1220 if( get_keypress() == 'o' ||
1221 get_keypress() == 'O' ) return handle_event();
1225 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1228 : BC_GenericButton(x, y, _("Use Current EDL"))
1230 this->thread = thread;
1233 int BatchRenderCurrentEDL::handle_event()
1235 thread->use_current_edl();
1239 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1242 : BC_GenericButton(x, y, _("Save to EDL Path"))
1244 this->thread = thread;
1247 int BatchRenderUpdateEDL::handle_event()
1249 thread->update_selected_edl();
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)
1260 this->thread = thread;
1262 set_process_drag(0);
1265 int BatchRenderList::handle_event()
1270 int BatchRenderList::selection_changed()
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;
1288 thread->gui->create_list(1);
1289 thread->gui->change_job();
1294 int BatchRenderList::column_resize_event()
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);
1308 int BatchRenderList::drag_start_event()
1310 if( BC_ListBox::drag_start_event() ) {
1318 int BatchRenderList::drag_motion_event()
1320 if( BC_ListBox::drag_motion_event() ) {
1326 int BatchRenderList::drag_stop_event()
1328 if( dragging_item ) {
1329 int src = get_selection_number(0, 0);
1330 int dst = get_highlighted_item();
1332 thread->move_batch(src, dst);
1334 BC_ListBox::drag_stop_event();
1342 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1343 : BC_GenericButton(x, y, _("Start"))
1345 this->thread = thread;
1348 int BatchRenderStart::handle_event()
1350 thread->start_rendering();
1354 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1355 : BC_GenericButton(x, y, _("Stop"))
1357 this->thread = thread;
1360 int BatchRenderStop::handle_event()
1363 thread->stop_rendering();
1364 lock_window("BatchRenderStop::handle_event");
1369 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1370 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1372 this->thread = thread;
1375 int BatchRenderWarning::handle_event()
1377 thread->warn = get_value();
1381 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1382 : BC_GenericButton(x, y, _("Close"))
1384 this->thread = thread;
1387 int BatchRenderCancel::handle_event()
1390 thread->stop_rendering();
1391 lock_window("BatchRenderCancel::handle_event");
1392 thread->gui->set_done(1);
1396 int BatchRenderCancel::keypress_event()
1398 if( get_keypress() == ESC ) {
1400 thread->stop_rendering();
1401 lock_window("BatchRenderCancel::keypress_event");
1402 thread->gui->set_done(1);
1408 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1409 : BC_CheckBox(x, y, *output, _("Use render farm"))
1411 this->thread = thread;
1412 this->output = output;
1415 int BatchRenderUseFarm::handle_event()
1417 *output = get_value();
1418 thread->gui->create_list(1);
1422 void BatchRenderUseFarm::update(int *output)
1424 this->output = output;
1425 BC_CheckBox::update(*output);