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 return Render::get_strategy(farmed, labeled);
188 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
191 this->mwindow = mwindow;
205 BatchRenderThread::~BatchRenderThread()
208 delete boot_defaults;
214 void BatchRenderThread::reset(const char *path)
217 strcpy(batch_path, path);
222 delete default_job; default_job = 0;
223 jobs.remove_all_objects();
226 void BatchRenderThread::start(int do_farmed, int do_labeled)
228 this->do_farmed = do_farmed;
229 this->do_labeled = do_labeled;
230 BC_DialogThread::start();
233 void BatchRenderThread::handle_close_event(int result)
236 save_jobs(batch_path);
237 save_defaults(mwindow->defaults);
241 BC_Window* BatchRenderThread::new_gui()
245 default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
246 load_jobs(batch_path, mwindow->preferences);
247 load_defaults(mwindow->defaults);
248 this->gui = new BatchRenderGUI(mwindow, this,
249 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
250 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
251 this->gui->create_objects();
256 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
261 jobs.remove_all_objects();
262 if( !path ) path = batch_path;
263 if( !path[0] ) create_path(path);
264 file.read_from_file(path);
267 if( !(result = file.read_tag()) ) {
268 if( file.tag.title_is("JOBS") ) {
269 warn = file.tag.get_property("WARN", 1);
271 else if( file.tag.title_is("JOB") ) {
272 BatchRenderJob *job = new BatchRenderJob(preferences, 0,0);
276 else if( file.tag.title_is("DVD_JOB") ) {
277 DVD_BatchRenderJob *job = new DVD_BatchRenderJob(preferences, 0,0,0,0);
281 else if( file.tag.title_is("BD_JOB") ) {
282 BD_BatchRenderJob *job = new BD_BatchRenderJob(preferences, 0,0);
290 void BatchRenderThread::save_jobs(char *path)
293 file.tag.set_title("JOBS");
294 file.tag.set_property("WARN", warn);
296 file.append_newline();
298 for( int i = 0; i < jobs.total; i++ ) {
299 file.tag.set_title(jobs[i]->tag);
300 jobs[i]->save(&file);
302 file.tag.set_title("/JOBS");
304 file.append_newline();
306 if( !path ) path = batch_path;
307 if( !path[0] ) create_path(path);
308 file.write_to_file(path);
311 void BatchRenderThread::load_defaults(BC_Hash *defaults)
314 default_job->asset->load_defaults(defaults,
315 "BATCHRENDER_", 1, 1, 1, 1, 1);
318 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
319 char string[BCTEXTLEN];
320 sprintf(string, "BATCHRENDER_COLUMN%d", i);
321 list_width[i] = defaults->get(string, xS(column_widths[i]));
325 void BatchRenderThread::save_defaults(BC_Hash *defaults)
328 default_job->asset->save_defaults(defaults,
329 "BATCHRENDER_", 1, 1, 1, 1, 1);
331 for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
332 char string[BCTEXTLEN];
333 sprintf(string, "BATCHRENDER_COLUMN%d", i);
334 defaults->update(string, list_width[i]);
336 // defaults->update("BATCHRENDER_JOB", current_job);
338 mwindow->save_defaults();
343 char* BatchRenderThread::create_path(char *string)
346 sprintf(string, "%s/", File::get_config_path());
347 fs.complete_path(string);
348 strcat(string, BATCH_PATH);
352 void BatchRenderThread::new_job()
354 BatchRenderJob *result = get_current_job()->copy();
356 current_job = jobs.total - 1;
361 void BatchRenderThread::delete_job()
363 if( current_job < jobs.total && current_job >= 0 ) {
364 jobs.remove_object_number(current_job);
365 if( current_job > 0 ) current_job--;
371 void BatchRenderThread::use_current_edl()
373 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
375 // mwindow->edl->path,
376 // mwindow->edl->path);
378 strcpy(get_current_edl(), mwindow->edl->path);
380 gui->edl_path_text->update(get_current_edl());
383 void BatchRenderThread::update_selected_edl()
386 char *path = get_current_edl();
387 EDL *edl = mwindow->edl;
388 edl->save_xml(&xml_file, path);
389 xml_file.terminate_string();
390 if( xml_file.write_to_file(path) ) {
392 sprintf(msg, _("Unable to save: %s"), path);
393 MainError::show_error(msg);
397 BatchRenderJob* BatchRenderThread::get_current_job()
399 return current_job >= 0 && current_job < jobs.total ?
400 jobs.values[current_job] : default_job;
404 Asset* BatchRenderThread::get_current_asset()
406 return get_current_job()->asset;
409 char* BatchRenderThread::get_current_edl()
411 return get_current_job()->edl_path;
414 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
416 int count = err_jobs.size();
417 if( !count ) return 0;
418 fprintf(stderr, msg, count);
419 char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
420 sp += snprintf(sp,ep-sp, msg,count);
421 for( int i=0; i<count; ++i ) {
422 int no = err_jobs[i].no;
423 const char *path = err_jobs[i].path;
424 fprintf(stderr, "%d: %s\n", no, path);
425 sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
427 sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
428 mwindow->show_warning(warn, string);
429 if( mwindow->wait_warning() ) {
430 gui->button_enable();
435 // Test EDL files for existence
436 int BatchRenderThread::test_edl_files()
439 const char *path = 0;
440 BatchRenderWarnJobs not_equiv;
441 BatchRenderWarnJobs empty_jobs;
442 BatchRenderWarnJobs no_labels;
443 BatchRenderWarnJobs no_rendering;
445 for( int i=0; !ret && i<jobs.size(); ++i ) {
446 if( !jobs.values[i]->enabled ) continue;
447 path = jobs[i]->edl_path;
448 int is_script = *path == '@' ? 1 : 0;
449 if( is_script ) ++path;
450 FILE *fp = fopen(path, "r");
452 if( mwindow && !is_script ) {
453 char *bfr = 0; size_t sz = 0;
455 if( !fstat(fileno(fp), &st) ) {
457 bfr = new char[sz+1];
458 if( fread(bfr, 1, sz+1, fp) != sz )
464 EDL *edl = new EDL; edl->create_objects();
465 XMLBuffer data(bfr, sz, 0);
467 file.set_shared_input(&data);
468 edl->load_xml(&file, LOAD_ALL); }
469 double pos = edl->equivalent_output(mwindow->edl);
471 not_equiv.add(i+1, path);
472 double length = edl->tracks->total_playable_length();
473 double start = edl->local_session->get_selectionstart(1);
474 if( start >= length )
475 empty_jobs.add(i+1, path);
476 if( jobs[i]->labeled && !edl->labels->first)
477 no_labels.add(i+1,path);
478 Asset *asset = jobs[i]->asset;
479 if( !asset->audio_data && !asset->video_data )
480 no_rendering.add(i+1,path);
492 char string[BCTEXTLEN];
493 sprintf(string, _("EDL %s not found.\n"), path);
495 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
496 mwindow->gui->get_abs_cursor_x(1),
497 mwindow->gui->get_abs_cursor_y(1));
498 error_box.create_objects(string);
499 error_box.run_window();
500 gui->button_enable();
503 fprintf(stderr, "%s", string);
509 if( !ret && warn && mwindow ) {
510 ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
511 if( !warn ) gui->warning->update(0);
513 if( !ret && mwindow )
514 ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
515 if( !ret && mwindow )
516 ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
517 if( !ret && mwindow )
518 ret = test_errmsg(no_labels, _("%d job EDLs Create new file at labels checked, but no labels\n"), 0);
524 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
525 Preferences *preferences)
527 for( int i = 0; i < jobs.total; i++ ) {
528 BatchRenderJob *job = jobs.values[i];
529 if( job->enabled && *job->edl_path != '@' ) {
530 PackageDispatcher *packages = new PackageDispatcher;
533 TransportCommand *command = new TransportCommand;
534 FileXML *file = new FileXML;
535 file->read_from_file(job->edl_path);
537 // Use command to calculate range.
538 command->command = NORMAL_FWD;
539 command->get_edl()->load_xml(file,
541 command->change_type = CHANGE_ALL;
542 command->set_playback_range();
543 command->playback_range_adjust_inout();
545 // Create test packages
546 int result = packages->create_packages(mwindow, command->get_edl(),
547 preferences, job->get_strategy(), job->asset,
548 command->start_position, command->end_position, 0);
550 packages->get_package_paths(paths);
552 // Append output paths allocated to total
554 // Delete package harness
563 void BatchRenderThread::start_rendering(char *config_path,
566 BC_Hash *boot_defaults;
567 Preferences *preferences;
569 BC_Signals *signals = new BC_Signals;
570 // XXX the above stuff is leaked,
572 // Initialize stuff which MWindow does.
573 signals->initialize("/tmp/cinelerra_batch%d.dmp");
575 MWindow::init_defaults(boot_defaults, config_path);
576 load_defaults(boot_defaults);
577 preferences = new Preferences;
578 preferences->load_defaults(boot_defaults);
579 BC_Signals::set_trap_hook(trap_hook, this);
580 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
581 BC_Signals::set_catch_intr(0);
582 if( preferences->trap_sigsegv ) {
583 BC_Trace::enable_locks();
586 BC_Trace::disable_locks();
589 MWindow::init_plugins(0, preferences);
590 char font_path[BCTEXTLEN];
591 strcpy(font_path, preferences->plugin_dir);
592 strcat(font_path, "/" FONT_SEARCHPATH);
593 BC_Resources::init_fontconfig(font_path);
594 BC_WindowBase::get_resources()->vframe_shm = 1;
597 strcpy(this->batch_path, batch_path);
598 load_jobs(batch_path, preferences);
599 save_jobs(batch_path);
600 save_defaults(boot_defaults);
603 // Test EDL files for existence
604 if( test_edl_files() ) return;
608 // Predict all destination paths
609 ArrayList<char*> paths;
610 paths.set_array_delete();
611 calculate_dest_paths(&paths, preferences);
614 int result = ConfirmSave::test_files(0, &paths);
615 paths.remove_all_objects();
616 // Abort on any existing file because it's so hard to set this up.
620 render = new Render(0);
622 render->start_batches(&jobs, boot_defaults, preferences);
626 void BatchRenderThread::start_rendering()
628 if( is_rendering ) return;
631 save_jobs(batch_path);
632 save_defaults(mwindow->defaults);
633 gui->button_disable();
635 // Test EDL files for existence
636 if( test_edl_files() ) return;
638 // Predict all destination paths
639 ArrayList<char*> paths;
640 calculate_dest_paths(&paths,
641 mwindow->preferences);
643 // Test destination files for overwrite
644 int result = ConfirmSave::test_files(mwindow, &paths);
645 paths.remove_all_objects();
650 gui->button_enable();
654 mwindow->render->start_batches(&jobs);
657 void BatchRenderThread::stop_rendering()
659 if( !is_rendering ) return;
660 mwindow->render->stop_operation();
664 void BatchRenderThread::update_active(int number)
666 gui->lock_window("BatchRenderThread::update_active");
668 current_job = number;
669 rendering_job = number;
676 gui->unlock_window();
679 void BatchRenderThread::update_done(int number,
683 gui->lock_window("BatchRenderThread::update_done");
685 gui->button_enable();
688 jobs.values[number]->enabled = 0;
689 jobs.values[number]->elapsed = elapsed_time;
690 if( create_list ) gui->create_list(1);
692 gui->unlock_window();
695 void BatchRenderThread::move_batch(int src, int dst)
697 BatchRenderJob *src_job = jobs.values[src];
698 if( dst < 0 ) dst = jobs.total - 1;
701 for( int i = src; i < jobs.total - 1; i++ )
702 jobs.values[i] = jobs.values[i + 1];
703 // if( dst > src ) dst--;
704 for( int i = jobs.total - 1; i > dst; i-- )
705 jobs.values[i] = jobs.values[i - 1];
706 jobs.values[dst] = src_job;
711 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
713 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
714 fprintf(fp, "\nEDL:\n");
715 mwindow->dump_edl(fp);
716 fprintf(fp, "\nUNDO:\n");
717 mwindow->dump_undo(fp);
718 fprintf(fp, "\nEXE:\n");
719 mwindow->dump_exe(fp);
726 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
727 BatchRenderThread *thread, int x, int y, int w, int h)
728 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
729 x, y, w, h, xS(730), yS(400), 1, 0, 1)
731 this->mwindow = mwindow;
732 this->thread = thread;
736 BatchRenderGUI::~BatchRenderGUI()
738 lock_window("BatchRenderGUI::~BatchRenderGUI");
739 loadlist_batch->stop();
740 savelist_batch->stop();
746 void BatchRenderGUI::create_objects()
748 int xs10 = xS(10), xs30 = xS(30), xs40 = xS(40);
749 int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15);
750 lock_window("BatchRenderGUI::create_objects");
751 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
754 int x = mwindow->theme->batchrender_x1;
756 int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
757 int y1 = ys5, y2 = ys5;
760 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
761 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
763 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
764 format_tools->set_w(x2 - xs40);
765 BatchRenderJob *current_job = thread->get_current_job();
766 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
767 thread->do_labeled ? ¤t_job->labeled : 0, 0);
768 if( thread->do_labeled < 0 )
769 format_tools->labeled_files->disable();
770 if( thread->do_farmed ) {
771 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
772 ¤t_job->farmed);
773 add_subwindow(use_renderfarm);
774 y1 += use_renderfarm->get_h() + ys10;
775 if( thread->do_farmed < 0 )
776 use_renderfarm->disable();
780 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
781 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
784 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
785 x, y, get_w()-x - xs40, thread->get_current_edl()));
786 x = x2 + edl_path_text->get_w();
787 add_subwindow(edl_path_browse = new BrowseButton(
788 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
789 _("Input EDL"), _("Select an EDL to load:"), 0));
790 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
793 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
794 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
795 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
796 y += use_current_edl->get_h() + mwindow->theme->widget_border;
797 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
798 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
799 x += new_batch->get_w() + mwindow->theme->widget_border;
800 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
801 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
802 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
803 x += savelist_batch->get_w() + mwindow->theme->widget_border;
804 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
805 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
806 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
807 y2 = y + warning->get_h() + mwindow->theme->widget_border;
808 if( y2 > y1 ) y1 = y2;
809 x = mwindow->theme->batchrender_x1, y = y1;
811 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
812 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
813 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
814 y += list_title->get_h() + mwindow->theme->widget_border;
816 y1 -= ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
817 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
818 get_w() - x - xs10, y1 - y));
819 y += batch_list->get_h() + mwindow->theme->widget_border;
821 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
822 x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
823 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
824 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - xs10;
825 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
831 void BatchRenderGUI::button_disable()
833 new_batch->disable();
834 delete_batch->disable();
835 use_current_edl->disable();
836 update_selected_edl->disable();
839 void BatchRenderGUI::button_enable()
842 delete_batch->enable();
843 if( mwindow->edl && mwindow->edl->path[0] )
844 use_current_edl->enable();
845 update_selected_edl->enable();
848 int BatchRenderGUI::resize_event(int w, int h)
850 int xs10 = xS(10), xs40 = xS(40);
851 int ys5 = yS(5), ys15 = yS(15);
852 mwindow->session->batchrender_w = w;
853 mwindow->session->batchrender_h = h;
854 mwindow->theme->get_batchrender_sizes(this, w, h);
856 int x = mwindow->theme->batchrender_x1;
858 int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
859 int y1 = ys5, y2 = ys5;
862 output_path_title->reposition_window(x1, y1);
863 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
864 format_tools->reposition_window(x1, y1);
865 if( thread->do_farmed )
866 use_renderfarm->reposition_window(x1, y1);
869 edl_path_title->reposition_window(x, y);
870 y += edl_path_title->get_h() + mwindow->theme->widget_border;
871 edl_path_text->reposition_window(x, y, w - x - xs40);
872 x += edl_path_text->get_w();
873 edl_path_browse->reposition_window(x, y);
874 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
877 update_selected_edl->reposition_window(x, y);
878 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
879 use_current_edl->reposition_window(x, y);
880 y += use_current_edl->get_h() + mwindow->theme->widget_border;
881 new_batch->reposition_window(x, y);
882 x += new_batch->get_w() + mwindow->theme->widget_border;
883 delete_batch->reposition_window(x, y);
885 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
886 savelist_batch->reposition_window(x, y);
887 x += savelist_batch->get_w() + mwindow->theme->widget_border;
888 loadlist_batch->reposition_window(x, y);
889 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
890 warning->reposition_window(x2, y);
892 y1 = ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
893 y2 = get_h() - y1 - batch_list->get_h();
894 y2 -= list_title->get_h() + mwindow->theme->widget_border;
896 x = mwindow->theme->batchrender_x1; y = y2;
897 list_title->reposition_window(x, y);
898 y += list_title->get_h() + mwindow->theme->widget_border;
899 batch_list->reposition_window(x, y, w - x - xs10, h - y - y1);
900 y += batch_list->get_h() + mwindow->theme->widget_border;
902 start_button->reposition_window(x, y);
903 x = w / 2 - stop_button->get_w() / 2;
904 stop_button->reposition_window(x, y);
905 x = w - cancel_button->get_w() - xs10;
906 cancel_button->reposition_window(x, y);
910 int BatchRenderGUI::translation_event()
912 mwindow->session->batchrender_x = get_x();
913 mwindow->session->batchrender_y = get_y();
917 int BatchRenderGUI::close_event()
919 // Stop batch rendering
921 thread->stop_rendering();
922 lock_window("BatchRenderGUI::close_event");
927 void BatchRenderGUI::create_list(int update_widget)
929 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
930 list_items[i].remove_all_objects();
933 const char **column_titles = BatchRenderThread::column_titles;
935 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
936 list_width[list_columns++] = thread->list_width[ENABLED_COL];
937 if( thread->do_labeled > 0 ) {
938 list_titles[list_columns] = _(column_titles[LABELED_COL]);
939 list_width[list_columns++] = thread->list_width[LABELED_COL];
941 if( thread->do_farmed > 0 ) {
942 list_titles[list_columns] = _(column_titles[FARMED_COL]);
943 list_width[list_columns++] = thread->list_width[FARMED_COL];
945 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
946 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
947 list_titles[list_columns] = _(column_titles[EDL_COL]);
948 list_width[list_columns++] = thread->list_width[EDL_COL];
949 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
950 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
952 for( int i = 0; i < thread->jobs.total; i++ ) {
953 BatchRenderJob *job = thread->jobs.values[i];
954 char string[BCTEXTLEN];
955 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
956 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
957 new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
958 BC_ListBoxItem *farmed = thread->do_farmed > 0 ?
959 new BC_ListBoxItem(job->farmed ? "X" : " ") : 0;
960 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
961 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
962 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
963 Units::totext(string, job->elapsed, TIME_HMS2));
965 list_items[col++].append(enabled);
966 if( labeled ) list_items[col++].append(labeled);
967 if( farmed ) list_items[col++].append(farmed);
968 list_items[col++].append(out_path);
969 list_items[col++].append(edl_path);
970 list_items[col].append(elapsed);
971 if( i == thread->current_job ) {
972 enabled->set_selected(1);
973 if( labeled ) labeled->set_selected(1);
974 if( farmed ) farmed->set_selected(1);
975 out_path->set_selected(1);
976 edl_path->set_selected(1);
977 elapsed->set_selected(1);
979 if( i == thread->rendering_job ) {
980 enabled->set_color(RED);
981 if( labeled ) labeled->set_color(RED);
982 if( farmed ) farmed->set_color(RED);
983 out_path->set_color(RED);
984 edl_path->set_color(RED);
985 elapsed->set_color(RED);
989 if( update_widget ) {
990 batch_list->update(list_items, list_titles, list_width, list_columns,
991 batch_list->get_xposition(), batch_list->get_yposition(),
992 batch_list->get_highlighted_item(), 1, 1);
996 void BatchRenderGUI::change_job()
998 BatchRenderJob *job = thread->get_current_job();
999 format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
1000 if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
1001 edl_path_text->update(job->edl_path);
1005 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1006 : FormatTools(mwindow, gui, asset)
1009 this->mwindow = mwindow;
1012 BatchFormat::~BatchFormat()
1017 int BatchFormat::handle_event()
1019 gui->create_list(1);
1023 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1024 int x, int y, int w, char *text)
1025 : BC_TextBox(x, y, w, 1, text)
1027 this->thread = thread;
1031 int BatchRenderEDLPath::handle_event()
1033 calculate_suggestions();
1034 strcpy(thread->get_current_edl(), get_text());
1035 thread->gui->create_list(1);
1039 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1042 : BC_GenericButton(x, y, _("New"))
1044 this->thread = thread;
1047 int BatchRenderNew::handle_event()
1053 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1054 : BC_GenericButton(x, y, _("Delete"))
1056 this->thread = thread;
1059 int BatchRenderDelete::handle_event()
1061 thread->delete_job();
1067 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1068 : BC_GenericButton(x, y, _("Save Jobs"))
1070 this->thread = thread;
1071 set_tooltip(_("Save a Batch Render List"));
1073 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1076 BatchRenderSaveList::~BatchRenderSaveList()
1079 delete startup_lock;
1082 void BatchRenderSaveList::stop()
1084 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1085 if( gui ) gui->set_done(1);
1086 startup_lock->unlock();
1090 int BatchRenderSaveList::handle_event()
1092 if( Thread::running() ) {
1095 gui->raise_window();
1096 gui->unlock_window();
1100 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1102 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1103 startup_lock->unlock();
1107 void BatchRenderSaveList::run()
1109 char default_path[BCTEXTLEN];
1110 sprintf(default_path, "~");
1111 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1112 BC_FileBox filewindow(xS(100), yS(100), default_path,
1113 _("Save Batch Render List"),
1114 _("Enter a Batch Render filename to save as:"),
1118 startup_lock->unlock();
1119 filewindow.create_objects();
1121 int result2 = filewindow.run_window();
1123 strcpy(thread->batch_path, filewindow.get_submitted_path());
1124 thread->gui->lock_window("BatchRenderSaveList::run");
1125 thread->gui->batch_path->update(thread->batch_path);
1126 thread->gui->unlock_window();
1127 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1128 thread->save_jobs(thread->batch_path);
1131 startup_lock->lock("BatchRenderLoadList::run");
1133 startup_lock->unlock();
1136 int BatchRenderSaveList::keypress_event() {
1137 if( get_keypress() == 's' ||
1138 get_keypress() == 'S' ) return handle_event();
1143 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1146 : BC_GenericButton(x, y, _("Load Jobs")),
1149 this->thread = thread;
1150 set_tooltip(_("Load a previously saved Batch Render List"));
1152 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1155 BatchRenderLoadList::~BatchRenderLoadList()
1158 delete startup_lock;
1161 void BatchRenderLoadList::stop()
1163 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1164 if( gui ) gui->set_done(1);
1165 startup_lock->unlock();
1169 int BatchRenderLoadList::handle_event()
1171 if( Thread::running() ) {
1174 gui->raise_window();
1175 gui->unlock_window();
1179 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1181 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1182 startup_lock->unlock();
1186 void BatchRenderLoadList::run()
1188 char default_path[BCTEXTLEN];
1189 sprintf(default_path, "~");
1190 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1191 BC_FileBox filewindow(xS(100), yS(100), default_path, _("Load Batch Render List"),
1192 _("Enter a Batch Render filename to load from:"),
1196 startup_lock->unlock();
1197 filewindow.create_objects();
1199 int result2 = filewindow.run_window();
1201 thread->gui->lock_window("BatchRenderLoadList::run");
1202 strcpy(thread->batch_path, filewindow.get_submitted_path());
1203 thread->gui->batch_path->update(thread->batch_path);
1204 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1205 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1206 thread->gui->create_list(1);
1207 thread->current_job = 0;
1208 thread->gui->change_job();
1209 thread->gui->unlock_window();
1212 startup_lock->lock("BatchRenderLoadList::run");
1214 startup_lock->unlock();
1217 int BatchRenderLoadList::keypress_event() {
1218 if( get_keypress() == 'o' ||
1219 get_keypress() == 'O' ) return handle_event();
1223 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1226 : BC_GenericButton(x, y, _("Use Current EDL"))
1228 this->thread = thread;
1231 int BatchRenderCurrentEDL::handle_event()
1233 thread->use_current_edl();
1237 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1240 : BC_GenericButton(x, y, _("Save to EDL Path"))
1242 this->thread = thread;
1245 int BatchRenderUpdateEDL::handle_event()
1247 thread->update_selected_edl();
1252 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1253 int x, int y, int w, int h)
1254 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1255 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1256 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1258 this->thread = thread;
1260 set_process_drag(0);
1263 int BatchRenderList::handle_event()
1268 int BatchRenderList::selection_changed()
1270 thread->current_job = get_selection_number(0, 0);
1271 thread->gui->change_job();
1272 int cursor_x = get_cursor_x();
1273 BatchRenderJob *job = thread->get_current_job();
1274 int col_x = 0, changed = 1;
1275 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1276 job->enabled = !job->enabled;
1277 else if( thread->do_labeled > 0 &&
1278 cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1279 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1280 else if( thread->do_farmed > 0 &&
1281 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1282 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1286 thread->gui->create_list(1);
1287 thread->gui->change_job();
1292 int BatchRenderList::column_resize_event()
1295 thread->list_width[ENABLED_COL] = get_column_width(col++);
1296 if( thread->do_labeled > 0 )
1297 thread->list_width[LABELED_COL] = get_column_width(col++);
1298 if( thread->do_farmed > 0 )
1299 thread->list_width[FARMED_COL] = get_column_width(col++);
1300 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1301 thread->list_width[EDL_COL] = get_column_width(col++);
1302 thread->list_width[ELAPSED_COL] = get_column_width(col);
1306 int BatchRenderList::drag_start_event()
1308 if( BC_ListBox::drag_start_event() ) {
1316 int BatchRenderList::drag_motion_event()
1318 if( BC_ListBox::drag_motion_event() ) {
1324 int BatchRenderList::drag_stop_event()
1326 if( dragging_item ) {
1327 int src = get_selection_number(0, 0);
1328 int dst = get_highlighted_item();
1330 thread->move_batch(src, dst);
1332 BC_ListBox::drag_stop_event();
1340 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1341 : BC_GenericButton(x, y, _("Start"))
1343 this->thread = thread;
1346 int BatchRenderStart::handle_event()
1348 thread->start_rendering();
1352 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1353 : BC_GenericButton(x, y, _("Stop"))
1355 this->thread = thread;
1358 int BatchRenderStop::handle_event()
1361 thread->stop_rendering();
1362 lock_window("BatchRenderStop::handle_event");
1367 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1368 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1370 this->thread = thread;
1373 int BatchRenderWarning::handle_event()
1375 thread->warn = get_value();
1379 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1380 : BC_GenericButton(x, y, _("Close"))
1382 this->thread = thread;
1385 int BatchRenderCancel::handle_event()
1388 thread->stop_rendering();
1389 lock_window("BatchRenderCancel::handle_event");
1390 thread->gui->set_done(1);
1394 int BatchRenderCancel::keypress_event()
1396 if( get_keypress() == ESC ) {
1398 thread->stop_rendering();
1399 lock_window("BatchRenderCancel::keypress_event");
1400 thread->gui->set_done(1);
1406 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1407 : BC_CheckBox(x, y, *output, _("Use render farm"))
1409 this->thread = thread;
1410 this->output = output;
1413 int BatchRenderUseFarm::handle_event()
1415 *output = get_value();
1416 thread->gui->create_list(1);
1420 void BatchRenderUseFarm::update(int *output)
1422 this->output = output;
1423 BC_CheckBox::update(*output);