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 fseek(fp, 0, SEEK_END);
402 int64_t sz = ftell(fp);
403 fseek(fp, 0, SEEK_SET);
404 char *bfr = new char[sz+1];
405 int64_t len = fread(bfr, 1, sz+1, fp);
408 XMLBuffer data(bfr, len, 0);
409 file.set_shared_input(&data);
410 EDL *edl = new EDL; edl->create_objects();
411 edl->load_xml(&file, LOAD_ALL);
412 double pos = edl->equivalent_output(mwindow->edl);
413 if( pos >= 0 ) ++not_equiv;
427 char string[BCTEXTLEN];
428 sprintf(string, _("EDL %s not found.\n"), path);
430 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
431 mwindow->gui->get_abs_cursor_x(1),
432 mwindow->gui->get_abs_cursor_y(1));
433 error_box.create_objects(string);
434 error_box.run_window();
435 gui->button_enable();
438 fprintf(stderr, "%s", string);
442 else if( warn && mwindow && not_equiv > 0 ) {
443 fprintf(stderr, _("%d job EDLs do not match session edl\n"), not_equiv);
444 char string[BCTEXTLEN], *sp = string;
445 sp += sprintf(sp, _("%d job EDLs do not match session edl\n"),not_equiv);
446 sp += sprintf(sp, _("press cancel to abandon batch render"));
447 mwindow->show_warning(&warn, string);
448 if( mwindow->wait_warning() ) {
449 gui->button_enable();
453 gui->warning->update(warn);
459 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
460 Preferences *preferences)
462 for( int i = 0; i < jobs.total; i++ ) {
463 BatchRenderJob *job = jobs.values[i];
464 if( job->enabled && *job->edl_path != '@' ) {
465 PackageDispatcher *packages = new PackageDispatcher;
468 TransportCommand *command = new TransportCommand;
469 FileXML *file = new FileXML;
470 file->read_from_file(job->edl_path);
472 // Use command to calculate range.
473 command->command = NORMAL_FWD;
474 command->get_edl()->load_xml(file,
476 command->change_type = CHANGE_ALL;
477 command->set_playback_range();
478 command->playback_range_adjust_inout();
480 // Create test packages
481 packages->create_packages(mwindow,
486 command->start_position,
487 command->end_position,
490 // Append output paths allocated to total
491 packages->get_package_paths(paths);
493 // Delete package harness
502 void BatchRenderThread::start_rendering(char *config_path,
505 BC_Hash *boot_defaults;
506 Preferences *preferences;
508 BC_Signals *signals = new BC_Signals;
509 // XXX the above stuff is leaked,
511 // Initialize stuff which MWindow does.
512 signals->initialize("/tmp/cinelerra_batch%d.dmp");
513 MWindow::init_defaults(boot_defaults, config_path);
514 load_defaults(boot_defaults);
515 preferences = new Preferences;
516 preferences->load_defaults(boot_defaults);
517 BC_Signals::set_trap_hook(trap_hook, this);
518 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
519 BC_Signals::set_catch_intr(0);
520 if( preferences->trap_sigsegv ) {
521 BC_Trace::enable_locks();
524 BC_Trace::disable_locks();
527 MWindow::init_plugins(0, preferences);
528 char font_path[BCTEXTLEN];
529 strcpy(font_path, preferences->plugin_dir);
530 strcat(font_path, "/" FONT_SEARCHPATH);
531 BC_Resources::init_fontconfig(font_path);
532 BC_WindowBase::get_resources()->vframe_shm = 1;
535 strcpy(this->batch_path, batch_path);
536 load_jobs(batch_path, preferences);
537 save_jobs(batch_path);
538 save_defaults(boot_defaults);
541 // Test EDL files for existence
542 if( test_edl_files() ) return;
546 // Predict all destination paths
547 ArrayList<char*> paths;
548 paths.set_array_delete();
549 calculate_dest_paths(&paths, preferences);
552 int result = ConfirmSave::test_files(0, &paths);
553 paths.remove_all_objects();
554 // Abort on any existing file because it's so hard to set this up.
558 render = new Render(0);
560 render->start_batches(&jobs, boot_defaults, preferences);
564 void BatchRenderThread::start_rendering()
566 if( is_rendering ) return;
569 save_jobs(batch_path);
570 save_defaults(mwindow->defaults);
571 gui->button_disable();
573 // Test EDL files for existence
574 if( test_edl_files() ) return;
576 // Predict all destination paths
577 ArrayList<char*> paths;
578 calculate_dest_paths(&paths,
579 mwindow->preferences);
581 // Test destination files for overwrite
582 int result = ConfirmSave::test_files(mwindow, &paths);
583 paths.remove_all_objects();
588 gui->button_enable();
592 mwindow->render->start_batches(&jobs);
595 void BatchRenderThread::stop_rendering()
597 if( !is_rendering ) return;
598 mwindow->render->stop_operation();
602 void BatchRenderThread::update_active(int number)
604 gui->lock_window("BatchRenderThread::update_active");
606 current_job = number;
607 rendering_job = number;
614 gui->unlock_window();
617 void BatchRenderThread::update_done(int number,
621 gui->lock_window("BatchRenderThread::update_done");
623 gui->button_enable();
626 jobs.values[number]->enabled = 0;
627 jobs.values[number]->elapsed = elapsed_time;
628 if( create_list ) gui->create_list(1);
630 gui->unlock_window();
633 void BatchRenderThread::move_batch(int src, int dst)
635 BatchRenderJob *src_job = jobs.values[src];
636 if( dst < 0 ) dst = jobs.total - 1;
639 for( int i = src; i < jobs.total - 1; i++ )
640 jobs.values[i] = jobs.values[i + 1];
641 // if( dst > src ) dst--;
642 for( int i = jobs.total - 1; i > dst; i-- )
643 jobs.values[i] = jobs.values[i - 1];
644 jobs.values[dst] = src_job;
649 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
651 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
652 fprintf(fp, "\nEDL:\n");
653 mwindow->dump_edl(fp);
654 fprintf(fp, "\nUNDO:\n");
655 mwindow->dump_undo(fp);
656 fprintf(fp, "\nEXE:\n");
657 mwindow->dump_exe(fp);
664 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
665 BatchRenderThread *thread, int x, int y, int w, int h)
666 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
667 x, y, w, h, 730, 400, 1, 0, 1)
669 this->mwindow = mwindow;
670 this->thread = thread;
674 BatchRenderGUI::~BatchRenderGUI()
676 lock_window("BatchRenderGUI::~BatchRenderGUI");
677 loadlist_batch->stop();
678 savelist_batch->stop();
684 void BatchRenderGUI::create_objects()
686 lock_window("BatchRenderGUI::create_objects");
687 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
690 int x = mwindow->theme->batchrender_x1;
692 int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
696 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
697 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
699 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
700 format_tools->set_w(get_w() / 2);
701 BatchRenderJob *current_job = thread->get_current_job();
702 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
703 ¤t_job->labeled, 0);
704 if( mwindow->preferences->use_renderfarm ) {
705 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
706 ¤t_job->farmed);
707 add_subwindow(use_renderfarm);
708 y1 += use_renderfarm->get_h() + 10;
711 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
712 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
715 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
716 x, y, get_w()-x - 40, thread->get_current_edl()));
717 x = x2 + edl_path_text->get_w();
718 add_subwindow(edl_path_browse = new BrowseButton(
719 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
720 _("Input EDL"), _("Select an EDL to load:"), 0));
721 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
724 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
725 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
726 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
727 y += use_current_edl->get_h() + mwindow->theme->widget_border;
728 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
729 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
730 x += new_batch->get_w() + mwindow->theme->widget_border;
731 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
732 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
733 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
734 x += savelist_batch->get_w() + mwindow->theme->widget_border;
735 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
736 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
737 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
738 y2 = y + warning->get_h() + mwindow->theme->widget_border;
739 if( y2 > y1 ) y1 = y2;
740 x = mwindow->theme->batchrender_x1, y = y1;
742 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
743 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
744 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
745 y += list_title->get_h() + mwindow->theme->widget_border;
747 y1 -= 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
748 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
749 get_w() - x - 10, y1 - y));
750 y += batch_list->get_h() + mwindow->theme->widget_border;
752 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
753 x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
754 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
755 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - 10;
756 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
762 void BatchRenderGUI::button_disable()
764 new_batch->disable();
765 delete_batch->disable();
766 use_current_edl->disable();
767 update_selected_edl->disable();
770 void BatchRenderGUI::button_enable()
773 delete_batch->enable();
774 if( mwindow->edl && mwindow->edl->path[0] )
775 use_current_edl->enable();
776 update_selected_edl->enable();
779 int BatchRenderGUI::resize_event(int w, int h)
781 mwindow->session->batchrender_w = w;
782 mwindow->session->batchrender_h = h;
783 mwindow->theme->get_batchrender_sizes(this, w, h);
785 int x = mwindow->theme->batchrender_x1;
787 int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
791 output_path_title->reposition_window(x1, y1);
792 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
793 format_tools->reposition_window(x1, y1);
795 use_renderfarm->reposition_window(x1, y1);
798 edl_path_title->reposition_window(x, y);
799 y += edl_path_title->get_h() + mwindow->theme->widget_border;
800 edl_path_text->reposition_window(x, y, w - x - 40);
801 x += edl_path_text->get_w();
802 edl_path_browse->reposition_window(x, y);
803 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
806 update_selected_edl->reposition_window(x, y);
807 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
808 use_current_edl->reposition_window(x, y);
809 y += use_current_edl->get_h() + mwindow->theme->widget_border;
810 new_batch->reposition_window(x, y);
811 x += new_batch->get_w() + mwindow->theme->widget_border;
812 delete_batch->reposition_window(x, y);
814 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
815 savelist_batch->reposition_window(x, y);
816 x += savelist_batch->get_w() + mwindow->theme->widget_border;
817 loadlist_batch->reposition_window(x, y);
818 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
819 warning->reposition_window(x2, y);
821 y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
822 y2 = get_h() - y1 - batch_list->get_h();
823 y2 -= list_title->get_h() + mwindow->theme->widget_border;
825 x = mwindow->theme->batchrender_x1; y = y2;
826 list_title->reposition_window(x, y);
827 y += list_title->get_h() + mwindow->theme->widget_border;
828 batch_list->reposition_window(x, y, w - x - 10, h - y - y1);
829 y += batch_list->get_h() + mwindow->theme->widget_border;
831 start_button->reposition_window(x, y);
832 x = w / 2 - stop_button->get_w() / 2;
833 stop_button->reposition_window(x, y);
834 x = w - cancel_button->get_w() - 10;
835 cancel_button->reposition_window(x, y);
839 int BatchRenderGUI::translation_event()
841 mwindow->session->batchrender_x = get_x();
842 mwindow->session->batchrender_y = get_y();
846 int BatchRenderGUI::close_event()
848 // Stop batch rendering
850 thread->stop_rendering();
851 lock_window("BatchRenderGUI::close_event");
856 void BatchRenderGUI::create_list(int update_widget)
858 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
859 list_items[i].remove_all_objects();
862 const char **column_titles = BatchRenderThread::column_titles;
864 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
865 list_width[list_columns++] = thread->list_width[ENABLED_COL];
866 list_titles[list_columns] = _(column_titles[LABELED_COL]);
867 list_width[list_columns++] = thread->list_width[LABELED_COL];
868 if( mwindow->preferences->use_renderfarm ) {
869 list_titles[list_columns] = _(column_titles[FARMED_COL]);
870 list_width[list_columns++] = thread->list_width[FARMED_COL];
872 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
873 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
874 list_titles[list_columns] = _(column_titles[EDL_COL]);
875 list_width[list_columns++] = thread->list_width[EDL_COL];
876 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
877 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
879 for( int i = 0; i < thread->jobs.total; i++ ) {
880 BatchRenderJob *job = thread->jobs.values[i];
881 char string[BCTEXTLEN];
882 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
883 BC_ListBoxItem *labeled = new BC_ListBoxItem(job->labeled ? "X" : " ");
884 BC_ListBoxItem *farmed = !mwindow->preferences->use_renderfarm ? 0 :
885 new BC_ListBoxItem(job->farmed ? "X" : " ");
886 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
887 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
888 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
889 Units::totext(string, job->elapsed, TIME_HMS2));
891 list_items[col++].append(enabled);
892 list_items[col++].append(labeled);
893 if( farmed ) list_items[col++].append(farmed);
894 list_items[col++].append(out_path);
895 list_items[col++].append(edl_path);
896 list_items[col].append(elapsed);
897 if( i == thread->current_job ) {
898 enabled->set_selected(1);
899 labeled->set_selected(1);
900 if( farmed ) farmed->set_selected(1);
901 out_path->set_selected(1);
902 edl_path->set_selected(1);
903 elapsed->set_selected(1);
905 if( i == thread->rendering_job ) {
906 enabled->set_color(RED);
907 labeled->set_color(RED);
908 if( farmed ) farmed->set_color(RED);
909 out_path->set_color(RED);
910 edl_path->set_color(RED);
911 elapsed->set_color(RED);
915 if( update_widget ) {
916 batch_list->update(list_items, list_titles, list_width, list_columns,
917 batch_list->get_xposition(), batch_list->get_yposition(),
918 batch_list->get_highlighted_item(), 1, 1);
922 void BatchRenderGUI::change_job()
924 BatchRenderJob *job = thread->get_current_job();
925 format_tools->update(job->asset, &job->labeled);
926 if( use_renderfarm ) use_renderfarm->update(&job->farmed);
927 edl_path_text->update(job->edl_path);
931 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
932 : FormatTools(mwindow, gui, asset)
935 this->mwindow = mwindow;
938 BatchFormat::~BatchFormat()
943 int BatchFormat::handle_event()
949 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
950 int x, int y, int w, char *text)
951 : BC_TextBox(x, y, w, 1, text)
953 this->thread = thread;
957 int BatchRenderEDLPath::handle_event()
959 calculate_suggestions();
960 strcpy(thread->get_current_edl(), get_text());
961 thread->gui->create_list(1);
965 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
968 : BC_GenericButton(x, y, _("New"))
970 this->thread = thread;
973 int BatchRenderNew::handle_event()
979 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
980 : BC_GenericButton(x, y, _("Delete"))
982 this->thread = thread;
985 int BatchRenderDelete::handle_event()
987 thread->delete_job();
993 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
994 : BC_GenericButton(x, y, _("Save Jobs"))
996 this->thread = thread;
997 set_tooltip(_("Save a Batch Render List"));
999 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1002 BatchRenderSaveList::~BatchRenderSaveList()
1005 delete startup_lock;
1008 void BatchRenderSaveList::stop()
1010 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1011 if( gui ) gui->set_done(1);
1012 startup_lock->unlock();
1016 int BatchRenderSaveList::handle_event()
1018 if( Thread::running() ) {
1021 gui->raise_window();
1022 gui->unlock_window();
1026 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1028 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1029 startup_lock->unlock();
1033 void BatchRenderSaveList::run()
1035 char default_path[BCTEXTLEN];
1036 sprintf(default_path, "~");
1037 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1038 BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
1039 _("Enter a Batch Render filename to save as:"),
1043 startup_lock->unlock();
1044 filewindow.create_objects();
1046 int result2 = filewindow.run_window();
1048 strcpy(thread->batch_path, filewindow.get_submitted_path());
1049 thread->gui->batch_path->update(thread->batch_path);
1050 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1051 thread->save_jobs(thread->batch_path);
1054 startup_lock->lock("BatchRenderLoadList::run");
1056 startup_lock->unlock();
1059 int BatchRenderSaveList::keypress_event() {
1060 if( get_keypress() == 's' ||
1061 get_keypress() == 'S' ) return handle_event();
1066 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1069 : BC_GenericButton(x, y, _("Load Jobs")),
1072 this->thread = thread;
1073 set_tooltip(_("Load a previously saved Batch Render List"));
1075 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1078 BatchRenderLoadList::~BatchRenderLoadList()
1081 delete startup_lock;
1084 void BatchRenderLoadList::stop()
1086 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1087 if( gui ) gui->set_done(1);
1088 startup_lock->unlock();
1092 int BatchRenderLoadList::handle_event()
1094 if( Thread::running() ) {
1097 gui->raise_window();
1098 gui->unlock_window();
1102 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1104 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1105 startup_lock->unlock();
1109 void BatchRenderLoadList::run()
1111 char default_path[BCTEXTLEN];
1112 sprintf(default_path, "~");
1113 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1114 BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
1115 _("Enter a Batch Render filename to load from:"),
1119 startup_lock->unlock();
1120 filewindow.create_objects();
1122 int result2 = filewindow.run_window();
1124 strcpy(thread->batch_path, filewindow.get_submitted_path());
1125 thread->gui->batch_path->update(thread->batch_path);
1126 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1127 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1128 thread->gui->create_list(1);
1129 thread->current_job = 0;
1130 thread->gui->change_job();
1133 startup_lock->lock("BatchRenderLoadList::run");
1135 startup_lock->unlock();
1138 int BatchRenderLoadList::keypress_event() {
1139 if( get_keypress() == 'o' ||
1140 get_keypress() == 'O' ) return handle_event();
1144 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1147 : BC_GenericButton(x, y, _("Use Current EDL"))
1149 this->thread = thread;
1152 int BatchRenderCurrentEDL::handle_event()
1154 thread->use_current_edl();
1158 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1161 : BC_GenericButton(x, y, _("Save to EDL Path"))
1163 this->thread = thread;
1166 int BatchRenderUpdateEDL::handle_event()
1168 thread->update_selected_edl();
1173 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1174 int x, int y, int w, int h)
1175 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1176 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1177 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1179 this->thread = thread;
1181 set_process_drag(0);
1184 int BatchRenderList::handle_event()
1189 int BatchRenderList::selection_changed()
1191 thread->current_job = get_selection_number(0, 0);
1192 thread->gui->change_job();
1193 int cursor_x = get_cursor_x();
1194 BatchRenderJob *job = thread->get_current_job();
1195 int col_x = 0, changed = 1;
1196 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1197 job->enabled = !job->enabled;
1198 else if( cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1199 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1200 else if( thread->gui->use_renderfarm &&
1201 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1202 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1206 thread->gui->create_list(1);
1207 thread->gui->change_job();
1212 int BatchRenderList::column_resize_event()
1215 thread->list_width[ENABLED_COL] = get_column_width(col++);
1216 thread->list_width[LABELED_COL] = get_column_width(col++);
1217 if( thread->gui->use_renderfarm )
1218 thread->list_width[FARMED_COL] = get_column_width(col++);
1219 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1220 thread->list_width[EDL_COL] = get_column_width(col++);
1221 thread->list_width[ELAPSED_COL] = get_column_width(col);
1225 int BatchRenderList::drag_start_event()
1227 if( BC_ListBox::drag_start_event() ) {
1235 int BatchRenderList::drag_motion_event()
1237 if( BC_ListBox::drag_motion_event() ) {
1243 int BatchRenderList::drag_stop_event()
1245 if( dragging_item ) {
1246 int src = get_selection_number(0, 0);
1247 int dst = get_highlighted_item();
1249 thread->move_batch(src, dst);
1251 BC_ListBox::drag_stop_event();
1259 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1260 : BC_GenericButton(x, y, _("Start"))
1262 this->thread = thread;
1265 int BatchRenderStart::handle_event()
1267 thread->start_rendering();
1271 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1272 : BC_GenericButton(x, y, _("Stop"))
1274 this->thread = thread;
1277 int BatchRenderStop::handle_event()
1280 thread->stop_rendering();
1281 lock_window("BatchRenderStop::handle_event");
1286 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1287 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1289 this->thread = thread;
1292 int BatchRenderWarning::handle_event()
1294 thread->warn = get_value();
1298 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1299 : BC_GenericButton(x, y, _("Close"))
1301 this->thread = thread;
1304 int BatchRenderCancel::handle_event()
1307 thread->stop_rendering();
1308 lock_window("BatchRenderCancel::handle_event");
1309 thread->gui->set_done(1);
1313 int BatchRenderCancel::keypress_event()
1315 if( get_keypress() == ESC ) {
1317 thread->stop_rendering();
1318 lock_window("BatchRenderCancel::keypress_event");
1319 thread->gui->set_done(1);
1325 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1326 : BC_CheckBox(x, y, *output, _("Use render farm"))
1328 this->thread = thread;
1329 this->output = output;
1332 int BatchRenderUseFarm::handle_event()
1334 *output = get_value();
1335 thread->gui->create_list(1);
1339 void BatchRenderUseFarm::update(int *output)
1341 this->output = output;
1342 BC_CheckBox::update(*output);