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"
41 #include "mainerror.h"
43 #include "mainsession.h"
46 #include "mwindowgui.h"
47 #include "packagedispatcher.h"
48 #include "packagerenderer.h"
50 #include "pluginset.h"
51 #include "preferences.h"
55 #include "transportque.h"
58 // Farmed is not present if not preferences->use_renderfarm
59 int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
60 const char *BatchRenderThread::column_titles[] = {
61 N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
64 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
65 : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
68 this->mwindow = mwindow;
71 int BatchRenderMenuItem::handle_event()
73 mwindow->batch_render->start();
78 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
80 this->preferences = preferences;
81 this->labeled = labeled;
82 this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
89 BatchRenderJob::~BatchRenderJob()
91 asset->Garbage::remove_user();
94 void BatchRenderJob::copy_from(BatchRenderJob *src)
96 enabled = src->enabled;
98 labeled = src->labeled;
99 asset->copy_from(src->asset, 0);
100 strcpy(edl_path, src->edl_path);
104 void BatchRenderJob::load(FileXML *file)
108 enabled = file->tag.get_property("ENABLED", enabled);
109 farmed = file->tag.get_property("FARMED", farmed);
110 labeled = file->tag.get_property("STRATEGY", labeled);
112 file->tag.get_property("EDL_PATH", edl_path);
113 elapsed = file->tag.get_property("ELAPSED", elapsed);
115 result = file->read_tag();
117 if( file->tag.title_is("ASSET") ) {
118 file->tag.get_property("SRC", asset->path);
119 asset->read(file, 0);
120 // The compression parameters are stored in the defaults to reduce
121 // coding maintenance. The defaults must now be stuffed into the XML for
124 defaults.load_string(file->read_text());
125 asset->load_defaults(&defaults,
131 void BatchRenderJob::save(FileXML *file)
133 file->tag.set_property("ENABLED", enabled);
134 file->tag.set_property("FARMED", farmed);
135 file->tag.set_property("LABELED", labeled);
136 file->tag.set_property("EDL_PATH", edl_path);
137 file->tag.set_property("ELAPSED", elapsed);
139 file->append_newline();
140 asset->write(file, 0, "");
142 // The compression parameters are stored in the defaults to reduce
143 // coding maintenance. The defaults must now be stuffed into the XML for
146 asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
148 defaults.save_string(string);
149 file->append_text(string);
151 file->tag.set_title("/JOB");
153 file->append_newline();
156 int BatchRenderJob::get_strategy()
158 // if set, overrides farmed, labeled
159 int use_renderfarm = farmed && preferences->use_renderfarm ? 1 : 0;
160 return Render::get_strategy(use_renderfarm, labeled);
164 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
167 this->mwindow = mwindow;
179 BatchRenderThread::BatchRenderThread()
194 BatchRenderThread::~BatchRenderThread()
197 delete boot_defaults;
202 void BatchRenderThread::reset(const char *path)
205 strcpy(batch_path, path);
210 delete default_job; default_job = 0;
211 jobs.remove_all_objects();
214 void BatchRenderThread::handle_close_event(int result)
217 save_jobs(batch_path);
218 save_defaults(mwindow->defaults);
222 BC_Window* BatchRenderThread::new_gui()
226 default_job = new BatchRenderJob(mwindow->preferences);
227 load_jobs(batch_path, mwindow->preferences);
228 load_defaults(mwindow->defaults);
229 this->gui = new BatchRenderGUI(mwindow, this,
230 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
231 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
232 this->gui->create_objects();
237 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
242 jobs.remove_all_objects();
243 if( !path ) path = batch_path;
244 if( !path[0] ) create_path(path);
245 file.read_from_file(path);
248 if( !(result = file.read_tag()) ) {
249 if( file.tag.title_is("JOBS") ) {
250 warn = file.tag.get_property("WARN", 1);
252 else if( file.tag.title_is("JOB") ) {
253 BatchRenderJob *job = new BatchRenderJob(preferences);
261 void BatchRenderThread::save_jobs(char *path)
264 file.tag.set_title("JOBS");
265 file.tag.set_property("WARN", warn);
267 file.append_newline();
269 for( int i = 0; i < jobs.total; i++ ) {
270 file.tag.set_title("JOB");
271 jobs.values[i]->save(&file);
273 file.tag.set_title("/JOBS");
275 file.append_newline();
277 if( !path ) path = batch_path;
278 if( !path[0] ) create_path(path);
279 file.write_to_file(path);
282 void BatchRenderThread::load_defaults(BC_Hash *defaults)
285 default_job->asset->load_defaults(defaults,
286 "BATCHRENDER_", 1, 1, 1, 1, 1);
289 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
290 char string[BCTEXTLEN];
291 sprintf(string, "BATCHRENDER_COLUMN%d", i);
292 list_width[i] = defaults->get(string, column_widths[i]);
296 void BatchRenderThread::save_defaults(BC_Hash *defaults)
299 default_job->asset->save_defaults(defaults,
300 "BATCHRENDER_", 1, 1, 1, 1, 1);
302 for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
303 char string[BCTEXTLEN];
304 sprintf(string, "BATCHRENDER_COLUMN%d", i);
305 defaults->update(string, list_width[i]);
307 // defaults->update("BATCHRENDER_JOB", current_job);
309 mwindow->save_defaults();
314 char* BatchRenderThread::create_path(char *string)
317 sprintf(string, "%s/", File::get_config_path());
318 fs.complete_path(string);
319 strcat(string, BATCH_PATH);
323 void BatchRenderThread::new_job()
325 BatchRenderJob *result = new BatchRenderJob(mwindow->preferences);
326 result->copy_from(get_current_job());
328 current_job = jobs.total - 1;
333 void BatchRenderThread::delete_job()
335 if( current_job < jobs.total && current_job >= 0 ) {
336 jobs.remove_object_number(current_job);
337 if( current_job > 0 ) current_job--;
343 void BatchRenderThread::use_current_edl()
345 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
347 // mwindow->edl->path,
348 // mwindow->edl->path);
350 strcpy(get_current_edl(), mwindow->edl->path);
352 gui->edl_path_text->update(get_current_edl());
355 void BatchRenderThread::update_selected_edl()
358 char *path = get_current_edl();
359 EDL *edl = mwindow->edl;
360 edl->save_xml(&xml_file, path);
361 xml_file.terminate_string();
362 if( xml_file.write_to_file(path) ) {
364 sprintf(msg, _("Unable to save: %s"), path);
365 MainError::show_error(msg);
369 BatchRenderJob* BatchRenderThread::get_current_job()
371 return current_job >= 0 && current_job < jobs.total ?
372 jobs.values[current_job] : default_job;
376 Asset* BatchRenderThread::get_current_asset()
378 return get_current_job()->asset;
381 char* BatchRenderThread::get_current_edl()
383 return get_current_job()->edl_path;
387 // Test EDL files for existence
388 int BatchRenderThread::test_edl_files()
390 int not_equiv = 0, ret = 0;
391 const char *path = 0;
393 for( int i=0; !ret && i<jobs.size(); ++i ) {
394 if( !jobs.values[i]->enabled ) continue;
395 path = jobs.values[i]->edl_path;
396 int is_script = *path == '@' ? 1 : 0;
397 if( is_script ) ++path;
398 FILE *fp = fopen(path, "r");
400 if( warn && mwindow && !is_script ) {
401 char *bfr = 0; size_t sz = 0;
403 if( !fstat(fileno(fp), &st) ) {
405 bfr = new char[sz+1];
406 if( fread(bfr, 1, sz+1, fp) != sz )
412 EDL *edl = new EDL; edl->create_objects();
413 XMLBuffer data(bfr, sz, 0);
415 file.set_shared_input(&data);
416 edl->load_xml(&file, LOAD_ALL); }
417 double pos = edl->equivalent_output(mwindow->edl);
418 if( pos >= 0 ) ++not_equiv;
430 char string[BCTEXTLEN];
431 sprintf(string, _("EDL %s not found.\n"), path);
433 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
434 mwindow->gui->get_abs_cursor_x(1),
435 mwindow->gui->get_abs_cursor_y(1));
436 error_box.create_objects(string);
437 error_box.run_window();
438 gui->button_enable();
441 fprintf(stderr, "%s", string);
445 else if( warn && mwindow && not_equiv > 0 ) {
446 fprintf(stderr, _("%d job EDLs do not match session edl\n"), not_equiv);
447 char string[BCTEXTLEN], *sp = string;
448 sp += sprintf(sp, _("%d job EDLs do not match session edl\n"),not_equiv);
449 sp += sprintf(sp, _("press cancel to abandon batch render"));
450 mwindow->show_warning(&warn, string);
451 if( mwindow->wait_warning() ) {
452 gui->button_enable();
456 gui->warning->update(warn);
462 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
463 Preferences *preferences)
465 for( int i = 0; i < jobs.total; i++ ) {
466 BatchRenderJob *job = jobs.values[i];
467 if( job->enabled && *job->edl_path != '@' ) {
468 PackageDispatcher *packages = new PackageDispatcher;
471 TransportCommand *command = new TransportCommand;
472 FileXML *file = new FileXML;
473 file->read_from_file(job->edl_path);
475 // Use command to calculate range.
476 command->command = NORMAL_FWD;
477 command->get_edl()->load_xml(file,
479 command->change_type = CHANGE_ALL;
480 command->set_playback_range();
481 command->playback_range_adjust_inout();
483 // Create test packages
484 packages->create_packages(mwindow,
489 command->start_position,
490 command->end_position,
493 // Append output paths allocated to total
494 packages->get_package_paths(paths);
496 // Delete package harness
505 void BatchRenderThread::start_rendering(char *config_path,
508 BC_Hash *boot_defaults;
509 Preferences *preferences;
511 BC_Signals *signals = new BC_Signals;
512 // XXX the above stuff is leaked,
514 // Initialize stuff which MWindow does.
515 signals->initialize("/tmp/cinelerra_batch%d.dmp");
517 MWindow::init_defaults(boot_defaults, config_path);
518 load_defaults(boot_defaults);
519 preferences = new Preferences;
520 preferences->load_defaults(boot_defaults);
521 BC_Signals::set_trap_hook(trap_hook, this);
522 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
523 BC_Signals::set_catch_intr(0);
524 if( preferences->trap_sigsegv ) {
525 BC_Trace::enable_locks();
528 BC_Trace::disable_locks();
531 MWindow::init_plugins(0, preferences);
532 char font_path[BCTEXTLEN];
533 strcpy(font_path, preferences->plugin_dir);
534 strcat(font_path, "/" FONT_SEARCHPATH);
535 BC_Resources::init_fontconfig(font_path);
536 BC_WindowBase::get_resources()->vframe_shm = 1;
539 strcpy(this->batch_path, batch_path);
540 load_jobs(batch_path, preferences);
541 save_jobs(batch_path);
542 save_defaults(boot_defaults);
545 // Test EDL files for existence
546 if( test_edl_files() ) return;
550 // Predict all destination paths
551 ArrayList<char*> paths;
552 paths.set_array_delete();
553 calculate_dest_paths(&paths, preferences);
556 int result = ConfirmSave::test_files(0, &paths);
557 paths.remove_all_objects();
558 // Abort on any existing file because it's so hard to set this up.
562 render = new Render(0);
564 render->start_batches(&jobs, boot_defaults, preferences);
568 void BatchRenderThread::start_rendering()
570 if( is_rendering ) return;
573 save_jobs(batch_path);
574 save_defaults(mwindow->defaults);
575 gui->button_disable();
577 // Test EDL files for existence
578 if( test_edl_files() ) return;
580 // Predict all destination paths
581 ArrayList<char*> paths;
582 calculate_dest_paths(&paths,
583 mwindow->preferences);
585 // Test destination files for overwrite
586 int result = ConfirmSave::test_files(mwindow, &paths);
587 paths.remove_all_objects();
592 gui->button_enable();
596 mwindow->render->start_batches(&jobs);
599 void BatchRenderThread::stop_rendering()
601 if( !is_rendering ) return;
602 mwindow->render->stop_operation();
606 void BatchRenderThread::update_active(int number)
608 gui->lock_window("BatchRenderThread::update_active");
610 current_job = number;
611 rendering_job = number;
618 gui->unlock_window();
621 void BatchRenderThread::update_done(int number,
625 gui->lock_window("BatchRenderThread::update_done");
627 gui->button_enable();
630 jobs.values[number]->enabled = 0;
631 jobs.values[number]->elapsed = elapsed_time;
632 if( create_list ) gui->create_list(1);
634 gui->unlock_window();
637 void BatchRenderThread::move_batch(int src, int dst)
639 BatchRenderJob *src_job = jobs.values[src];
640 if( dst < 0 ) dst = jobs.total - 1;
643 for( int i = src; i < jobs.total - 1; i++ )
644 jobs.values[i] = jobs.values[i + 1];
645 // if( dst > src ) dst--;
646 for( int i = jobs.total - 1; i > dst; i-- )
647 jobs.values[i] = jobs.values[i - 1];
648 jobs.values[dst] = src_job;
653 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
655 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
656 fprintf(fp, "\nEDL:\n");
657 mwindow->dump_edl(fp);
658 fprintf(fp, "\nUNDO:\n");
659 mwindow->dump_undo(fp);
660 fprintf(fp, "\nEXE:\n");
661 mwindow->dump_exe(fp);
668 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
669 BatchRenderThread *thread, int x, int y, int w, int h)
670 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
671 x, y, w, h, 730, 400, 1, 0, 1)
673 this->mwindow = mwindow;
674 this->thread = thread;
678 BatchRenderGUI::~BatchRenderGUI()
680 lock_window("BatchRenderGUI::~BatchRenderGUI");
681 loadlist_batch->stop();
682 savelist_batch->stop();
688 void BatchRenderGUI::create_objects()
690 lock_window("BatchRenderGUI::create_objects");
691 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
694 int x = mwindow->theme->batchrender_x1;
696 int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
700 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
701 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
703 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
704 format_tools->set_w(get_w() / 2);
705 BatchRenderJob *current_job = thread->get_current_job();
706 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
707 ¤t_job->labeled, 0);
708 if( mwindow->preferences->use_renderfarm ) {
709 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
710 ¤t_job->farmed);
711 add_subwindow(use_renderfarm);
712 y1 += use_renderfarm->get_h() + 10;
715 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
716 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
719 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
720 x, y, get_w()-x - 40, thread->get_current_edl()));
721 x = x2 + edl_path_text->get_w();
722 add_subwindow(edl_path_browse = new BrowseButton(
723 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
724 _("Input EDL"), _("Select an EDL to load:"), 0));
725 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
728 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
729 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
730 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
731 y += use_current_edl->get_h() + mwindow->theme->widget_border;
732 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
733 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
734 x += new_batch->get_w() + mwindow->theme->widget_border;
735 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
736 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
737 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
738 x += savelist_batch->get_w() + mwindow->theme->widget_border;
739 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
740 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
741 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
742 y2 = y + warning->get_h() + mwindow->theme->widget_border;
743 if( y2 > y1 ) y1 = y2;
744 x = mwindow->theme->batchrender_x1, y = y1;
746 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
747 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
748 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
749 y += list_title->get_h() + mwindow->theme->widget_border;
751 y1 -= 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
752 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
753 get_w() - x - 10, y1 - y));
754 y += batch_list->get_h() + mwindow->theme->widget_border;
756 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
757 x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
758 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
759 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - 10;
760 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
766 void BatchRenderGUI::button_disable()
768 new_batch->disable();
769 delete_batch->disable();
770 use_current_edl->disable();
771 update_selected_edl->disable();
774 void BatchRenderGUI::button_enable()
777 delete_batch->enable();
778 if( mwindow->edl && mwindow->edl->path[0] )
779 use_current_edl->enable();
780 update_selected_edl->enable();
783 int BatchRenderGUI::resize_event(int w, int h)
785 mwindow->session->batchrender_w = w;
786 mwindow->session->batchrender_h = h;
787 mwindow->theme->get_batchrender_sizes(this, w, h);
789 int x = mwindow->theme->batchrender_x1;
791 int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
795 output_path_title->reposition_window(x1, y1);
796 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
797 format_tools->reposition_window(x1, y1);
799 use_renderfarm->reposition_window(x1, y1);
802 edl_path_title->reposition_window(x, y);
803 y += edl_path_title->get_h() + mwindow->theme->widget_border;
804 edl_path_text->reposition_window(x, y, w - x - 40);
805 x += edl_path_text->get_w();
806 edl_path_browse->reposition_window(x, y);
807 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
810 update_selected_edl->reposition_window(x, y);
811 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
812 use_current_edl->reposition_window(x, y);
813 y += use_current_edl->get_h() + mwindow->theme->widget_border;
814 new_batch->reposition_window(x, y);
815 x += new_batch->get_w() + mwindow->theme->widget_border;
816 delete_batch->reposition_window(x, y);
818 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
819 savelist_batch->reposition_window(x, y);
820 x += savelist_batch->get_w() + mwindow->theme->widget_border;
821 loadlist_batch->reposition_window(x, y);
822 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
823 warning->reposition_window(x2, y);
825 y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
826 y2 = get_h() - y1 - batch_list->get_h();
827 y2 -= list_title->get_h() + mwindow->theme->widget_border;
829 x = mwindow->theme->batchrender_x1; y = y2;
830 list_title->reposition_window(x, y);
831 y += list_title->get_h() + mwindow->theme->widget_border;
832 batch_list->reposition_window(x, y, w - x - 10, h - y - y1);
833 y += batch_list->get_h() + mwindow->theme->widget_border;
835 start_button->reposition_window(x, y);
836 x = w / 2 - stop_button->get_w() / 2;
837 stop_button->reposition_window(x, y);
838 x = w - cancel_button->get_w() - 10;
839 cancel_button->reposition_window(x, y);
843 int BatchRenderGUI::translation_event()
845 mwindow->session->batchrender_x = get_x();
846 mwindow->session->batchrender_y = get_y();
850 int BatchRenderGUI::close_event()
852 // Stop batch rendering
854 thread->stop_rendering();
855 lock_window("BatchRenderGUI::close_event");
860 void BatchRenderGUI::create_list(int update_widget)
862 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
863 list_items[i].remove_all_objects();
866 const char **column_titles = BatchRenderThread::column_titles;
868 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
869 list_width[list_columns++] = thread->list_width[ENABLED_COL];
870 list_titles[list_columns] = _(column_titles[LABELED_COL]);
871 list_width[list_columns++] = thread->list_width[LABELED_COL];
872 if( mwindow->preferences->use_renderfarm ) {
873 list_titles[list_columns] = _(column_titles[FARMED_COL]);
874 list_width[list_columns++] = thread->list_width[FARMED_COL];
876 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
877 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
878 list_titles[list_columns] = _(column_titles[EDL_COL]);
879 list_width[list_columns++] = thread->list_width[EDL_COL];
880 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
881 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
883 for( int i = 0; i < thread->jobs.total; i++ ) {
884 BatchRenderJob *job = thread->jobs.values[i];
885 char string[BCTEXTLEN];
886 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
887 BC_ListBoxItem *labeled = new BC_ListBoxItem(job->labeled ? "X" : " ");
888 BC_ListBoxItem *farmed = !mwindow->preferences->use_renderfarm ? 0 :
889 new BC_ListBoxItem(job->farmed ? "X" : " ");
890 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
891 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
892 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
893 Units::totext(string, job->elapsed, TIME_HMS2));
895 list_items[col++].append(enabled);
896 list_items[col++].append(labeled);
897 if( farmed ) list_items[col++].append(farmed);
898 list_items[col++].append(out_path);
899 list_items[col++].append(edl_path);
900 list_items[col].append(elapsed);
901 if( i == thread->current_job ) {
902 enabled->set_selected(1);
903 labeled->set_selected(1);
904 if( farmed ) farmed->set_selected(1);
905 out_path->set_selected(1);
906 edl_path->set_selected(1);
907 elapsed->set_selected(1);
909 if( i == thread->rendering_job ) {
910 enabled->set_color(RED);
911 labeled->set_color(RED);
912 if( farmed ) farmed->set_color(RED);
913 out_path->set_color(RED);
914 edl_path->set_color(RED);
915 elapsed->set_color(RED);
919 if( update_widget ) {
920 batch_list->update(list_items, list_titles, list_width, list_columns,
921 batch_list->get_xposition(), batch_list->get_yposition(),
922 batch_list->get_highlighted_item(), 1, 1);
926 void BatchRenderGUI::change_job()
928 BatchRenderJob *job = thread->get_current_job();
929 format_tools->update(job->asset, &job->labeled);
930 if( use_renderfarm ) use_renderfarm->update(&job->farmed);
931 edl_path_text->update(job->edl_path);
935 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
936 : FormatTools(mwindow, gui, asset)
939 this->mwindow = mwindow;
942 BatchFormat::~BatchFormat()
947 int BatchFormat::handle_event()
953 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
954 int x, int y, int w, char *text)
955 : BC_TextBox(x, y, w, 1, text)
957 this->thread = thread;
961 int BatchRenderEDLPath::handle_event()
963 calculate_suggestions();
964 strcpy(thread->get_current_edl(), get_text());
965 thread->gui->create_list(1);
969 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
972 : BC_GenericButton(x, y, _("New"))
974 this->thread = thread;
977 int BatchRenderNew::handle_event()
983 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
984 : BC_GenericButton(x, y, _("Delete"))
986 this->thread = thread;
989 int BatchRenderDelete::handle_event()
991 thread->delete_job();
997 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
998 : BC_GenericButton(x, y, _("Save Jobs"))
1000 this->thread = thread;
1001 set_tooltip(_("Save a Batch Render List"));
1003 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1006 BatchRenderSaveList::~BatchRenderSaveList()
1009 delete startup_lock;
1012 void BatchRenderSaveList::stop()
1014 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1015 if( gui ) gui->set_done(1);
1016 startup_lock->unlock();
1020 int BatchRenderSaveList::handle_event()
1022 if( Thread::running() ) {
1025 gui->raise_window();
1026 gui->unlock_window();
1030 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1032 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1033 startup_lock->unlock();
1037 void BatchRenderSaveList::run()
1039 char default_path[BCTEXTLEN];
1040 sprintf(default_path, "~");
1041 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1042 BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
1043 _("Enter a Batch Render filename to save as:"),
1047 startup_lock->unlock();
1048 filewindow.create_objects();
1050 int result2 = filewindow.run_window();
1052 strcpy(thread->batch_path, filewindow.get_submitted_path());
1053 thread->gui->lock_window("BatchRenderSaveList::run");
1054 thread->gui->batch_path->update(thread->batch_path);
1055 thread->gui->unlock_window();
1056 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1057 thread->save_jobs(thread->batch_path);
1060 startup_lock->lock("BatchRenderLoadList::run");
1062 startup_lock->unlock();
1065 int BatchRenderSaveList::keypress_event() {
1066 if( get_keypress() == 's' ||
1067 get_keypress() == 'S' ) return handle_event();
1072 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1075 : BC_GenericButton(x, y, _("Load Jobs")),
1078 this->thread = thread;
1079 set_tooltip(_("Load a previously saved Batch Render List"));
1081 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1084 BatchRenderLoadList::~BatchRenderLoadList()
1087 delete startup_lock;
1090 void BatchRenderLoadList::stop()
1092 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1093 if( gui ) gui->set_done(1);
1094 startup_lock->unlock();
1098 int BatchRenderLoadList::handle_event()
1100 if( Thread::running() ) {
1103 gui->raise_window();
1104 gui->unlock_window();
1108 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1110 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1111 startup_lock->unlock();
1115 void BatchRenderLoadList::run()
1117 char default_path[BCTEXTLEN];
1118 sprintf(default_path, "~");
1119 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1120 BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
1121 _("Enter a Batch Render filename to load from:"),
1125 startup_lock->unlock();
1126 filewindow.create_objects();
1128 int result2 = filewindow.run_window();
1130 strcpy(thread->batch_path, filewindow.get_submitted_path());
1131 thread->gui->batch_path->update(thread->batch_path);
1132 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1133 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1134 thread->gui->create_list(1);
1135 thread->current_job = 0;
1136 thread->gui->change_job();
1139 startup_lock->lock("BatchRenderLoadList::run");
1141 startup_lock->unlock();
1144 int BatchRenderLoadList::keypress_event() {
1145 if( get_keypress() == 'o' ||
1146 get_keypress() == 'O' ) return handle_event();
1150 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1153 : BC_GenericButton(x, y, _("Use Current EDL"))
1155 this->thread = thread;
1158 int BatchRenderCurrentEDL::handle_event()
1160 thread->use_current_edl();
1164 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1167 : BC_GenericButton(x, y, _("Save to EDL Path"))
1169 this->thread = thread;
1172 int BatchRenderUpdateEDL::handle_event()
1174 thread->update_selected_edl();
1179 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1180 int x, int y, int w, int h)
1181 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1182 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1183 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1185 this->thread = thread;
1187 set_process_drag(0);
1190 int BatchRenderList::handle_event()
1195 int BatchRenderList::selection_changed()
1197 thread->current_job = get_selection_number(0, 0);
1198 thread->gui->change_job();
1199 int cursor_x = get_cursor_x();
1200 BatchRenderJob *job = thread->get_current_job();
1201 int col_x = 0, changed = 1;
1202 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1203 job->enabled = !job->enabled;
1204 else if( cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1205 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1206 else if( thread->gui->use_renderfarm &&
1207 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1208 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1212 thread->gui->create_list(1);
1213 thread->gui->change_job();
1218 int BatchRenderList::column_resize_event()
1221 thread->list_width[ENABLED_COL] = get_column_width(col++);
1222 thread->list_width[LABELED_COL] = get_column_width(col++);
1223 if( thread->gui->use_renderfarm )
1224 thread->list_width[FARMED_COL] = get_column_width(col++);
1225 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1226 thread->list_width[EDL_COL] = get_column_width(col++);
1227 thread->list_width[ELAPSED_COL] = get_column_width(col);
1231 int BatchRenderList::drag_start_event()
1233 if( BC_ListBox::drag_start_event() ) {
1241 int BatchRenderList::drag_motion_event()
1243 if( BC_ListBox::drag_motion_event() ) {
1249 int BatchRenderList::drag_stop_event()
1251 if( dragging_item ) {
1252 int src = get_selection_number(0, 0);
1253 int dst = get_highlighted_item();
1255 thread->move_batch(src, dst);
1257 BC_ListBox::drag_stop_event();
1265 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1266 : BC_GenericButton(x, y, _("Start"))
1268 this->thread = thread;
1271 int BatchRenderStart::handle_event()
1273 thread->start_rendering();
1277 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1278 : BC_GenericButton(x, y, _("Stop"))
1280 this->thread = thread;
1283 int BatchRenderStop::handle_event()
1286 thread->stop_rendering();
1287 lock_window("BatchRenderStop::handle_event");
1292 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1293 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1295 this->thread = thread;
1298 int BatchRenderWarning::handle_event()
1300 thread->warn = get_value();
1304 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1305 : BC_GenericButton(x, y, _("Close"))
1307 this->thread = thread;
1310 int BatchRenderCancel::handle_event()
1313 thread->stop_rendering();
1314 lock_window("BatchRenderCancel::handle_event");
1315 thread->gui->set_done(1);
1319 int BatchRenderCancel::keypress_event()
1321 if( get_keypress() == ESC ) {
1323 thread->stop_rendering();
1324 lock_window("BatchRenderCancel::keypress_event");
1325 thread->gui->set_done(1);
1331 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1332 : BC_CheckBox(x, y, *output, _("Use render farm"))
1334 this->thread = thread;
1335 this->output = output;
1338 int BatchRenderUseFarm::handle_event()
1340 *output = get_value();
1341 thread->gui->create_list(1);
1345 void BatchRenderUseFarm::update(int *output)
1347 this->output = output;
1348 BC_CheckBox::update(*output);