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 "mainerror.h"
44 #include "mainsession.h"
47 #include "mwindowgui.h"
48 #include "packagedispatcher.h"
49 #include "packagerenderer.h"
51 #include "pluginset.h"
52 #include "preferences.h"
56 #include "transportque.h"
59 #include "dvdcreate.h"
62 int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
63 const char *BatchRenderThread::column_titles[] = {
64 N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
67 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
68 : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
71 this->mwindow = mwindow;
74 int BatchRenderMenuItem::handle_event()
76 mwindow->batch_render->start(1, 1);
80 BatchRenderJob::BatchRenderJob(const char *tag,
81 Preferences *preferences, int labeled, int farmed)
84 this->preferences = preferences;
85 this->labeled = labeled;
86 this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
93 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
94 : BatchRenderJob("JOB", preferences, labeled, farmed)
98 BatchRenderJob::~BatchRenderJob()
100 asset->Garbage::remove_user();
103 void BatchRenderJob::copy_from(BatchRenderJob *src)
105 enabled = src->enabled;
106 farmed = src->farmed;
107 labeled = src->labeled;
108 asset->copy_from(src->asset, 0);
109 strcpy(edl_path, src->edl_path);
113 BatchRenderJob *BatchRenderJob::copy()
115 BatchRenderJob *t = new BatchRenderJob(tag, preferences, labeled, farmed);
120 void BatchRenderJob::load(FileXML *file)
124 enabled = file->tag.get_property("ENABLED", enabled);
125 farmed = file->tag.get_property("FARMED", farmed);
126 labeled = file->tag.get_property("LABELED", labeled);
128 file->tag.get_property("EDL_PATH", edl_path);
129 elapsed = file->tag.get_property("ELAPSED", elapsed);
131 result = file->read_tag();
133 if( file->tag.title_is("ASSET") ) {
134 file->tag.get_property("SRC", asset->path);
135 asset->read(file, 0);
136 // The compression parameters are stored in the defaults to reduce
137 // coding maintenance. The defaults must now be stuffed into the XML for
140 defaults.load_string(file->read_text());
141 asset->load_defaults(&defaults,
147 void BatchRenderJob::save(FileXML *file)
149 char end_tag[BCSTRLEN]; end_tag[0] = '/';
150 strcpy(&end_tag[1], file->tag.get_title());
151 file->tag.set_property("ENABLED", enabled);
152 file->tag.set_property("FARMED", farmed);
153 file->tag.set_property("LABELED", labeled);
154 file->tag.set_property("EDL_PATH", edl_path);
155 file->tag.set_property("ELAPSED", elapsed);
157 file->append_newline();
158 asset->write(file, 0, "");
160 // The compression parameters are stored in the defaults to reduce
161 // coding maintenance. The defaults must now be stuffed into the XML for
164 asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
166 defaults.save_string(string);
167 file->append_text(string);
169 file->tag.set_title(end_tag);
171 file->append_newline();
174 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
179 int BatchRenderJob::get_strategy()
181 return Render::get_strategy(farmed, labeled);
185 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
188 this->mwindow = mwindow;
202 BatchRenderThread::~BatchRenderThread()
205 delete boot_defaults;
211 void BatchRenderThread::reset(const char *path)
214 strcpy(batch_path, path);
219 delete default_job; default_job = 0;
220 jobs.remove_all_objects();
223 void BatchRenderThread::start(int do_farmed, int do_labeled)
225 this->do_farmed = do_farmed;
226 this->do_labeled = do_labeled;
227 BC_DialogThread::start();
230 void BatchRenderThread::handle_close_event(int result)
233 save_jobs(batch_path);
234 save_defaults(mwindow->defaults);
238 BC_Window* BatchRenderThread::new_gui()
242 default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
243 load_jobs(batch_path, mwindow->preferences);
244 load_defaults(mwindow->defaults);
245 this->gui = new BatchRenderGUI(mwindow, this,
246 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
247 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
248 this->gui->create_objects();
253 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
258 jobs.remove_all_objects();
259 if( !path ) path = batch_path;
260 if( !path[0] ) create_path(path);
261 file.read_from_file(path);
264 if( !(result = file.read_tag()) ) {
265 if( file.tag.title_is("JOBS") ) {
266 warn = file.tag.get_property("WARN", 1);
268 else if( file.tag.title_is("JOB") ) {
269 BatchRenderJob *job = new BatchRenderJob(preferences, 0,0);
273 else if( file.tag.title_is("DVD_JOB") ) {
274 DVD_BatchRenderJob *job = new DVD_BatchRenderJob(preferences, 0,0,0,0);
278 else if( file.tag.title_is("BD_JOB") ) {
279 BD_BatchRenderJob *job = new BD_BatchRenderJob(preferences, 0,0);
287 void BatchRenderThread::save_jobs(char *path)
290 file.tag.set_title("JOBS");
291 file.tag.set_property("WARN", warn);
293 file.append_newline();
295 for( int i = 0; i < jobs.total; i++ ) {
296 file.tag.set_title(jobs[i]->tag);
297 jobs[i]->save(&file);
299 file.tag.set_title("/JOBS");
301 file.append_newline();
303 if( !path ) path = batch_path;
304 if( !path[0] ) create_path(path);
305 file.write_to_file(path);
308 void BatchRenderThread::load_defaults(BC_Hash *defaults)
311 default_job->asset->load_defaults(defaults,
312 "BATCHRENDER_", 1, 1, 1, 1, 1);
315 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
316 char string[BCTEXTLEN];
317 sprintf(string, "BATCHRENDER_COLUMN%d", i);
318 list_width[i] = defaults->get(string, column_widths[i]);
322 void BatchRenderThread::save_defaults(BC_Hash *defaults)
325 default_job->asset->save_defaults(defaults,
326 "BATCHRENDER_", 1, 1, 1, 1, 1);
328 for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
329 char string[BCTEXTLEN];
330 sprintf(string, "BATCHRENDER_COLUMN%d", i);
331 defaults->update(string, list_width[i]);
333 // defaults->update("BATCHRENDER_JOB", current_job);
335 mwindow->save_defaults();
340 char* BatchRenderThread::create_path(char *string)
343 sprintf(string, "%s/", File::get_config_path());
344 fs.complete_path(string);
345 strcat(string, BATCH_PATH);
349 void BatchRenderThread::new_job()
351 BatchRenderJob *result = get_current_job()->copy();
353 current_job = jobs.total - 1;
358 void BatchRenderThread::delete_job()
360 if( current_job < jobs.total && current_job >= 0 ) {
361 jobs.remove_object_number(current_job);
362 if( current_job > 0 ) current_job--;
368 void BatchRenderThread::use_current_edl()
370 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
372 // mwindow->edl->path,
373 // mwindow->edl->path);
375 strcpy(get_current_edl(), mwindow->edl->path);
377 gui->edl_path_text->update(get_current_edl());
380 void BatchRenderThread::update_selected_edl()
383 char *path = get_current_edl();
384 EDL *edl = mwindow->edl;
385 edl->save_xml(&xml_file, path);
386 xml_file.terminate_string();
387 if( xml_file.write_to_file(path) ) {
389 sprintf(msg, _("Unable to save: %s"), path);
390 MainError::show_error(msg);
394 BatchRenderJob* BatchRenderThread::get_current_job()
396 return current_job >= 0 && current_job < jobs.total ?
397 jobs.values[current_job] : default_job;
401 Asset* BatchRenderThread::get_current_asset()
403 return get_current_job()->asset;
406 char* BatchRenderThread::get_current_edl()
408 return get_current_job()->edl_path;
412 // Test EDL files for existence
413 int BatchRenderThread::test_edl_files()
415 int not_equiv = 0, ret = 0;
416 const char *path = 0;
418 for( int i=0; !ret && i<jobs.size(); ++i ) {
419 if( !jobs.values[i]->enabled ) continue;
420 path = jobs.values[i]->edl_path;
421 int is_script = *path == '@' ? 1 : 0;
422 if( is_script ) ++path;
423 FILE *fp = fopen(path, "r");
425 if( warn && mwindow && !is_script ) {
426 char *bfr = 0; size_t sz = 0;
428 if( !fstat(fileno(fp), &st) ) {
430 bfr = new char[sz+1];
431 if( fread(bfr, 1, sz+1, fp) != sz )
437 EDL *edl = new EDL; edl->create_objects();
438 XMLBuffer data(bfr, sz, 0);
440 file.set_shared_input(&data);
441 edl->load_xml(&file, LOAD_ALL); }
442 double pos = edl->equivalent_output(mwindow->edl);
443 if( pos >= 0 ) ++not_equiv;
455 char string[BCTEXTLEN];
456 sprintf(string, _("EDL %s not found.\n"), path);
458 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
459 mwindow->gui->get_abs_cursor_x(1),
460 mwindow->gui->get_abs_cursor_y(1));
461 error_box.create_objects(string);
462 error_box.run_window();
463 gui->button_enable();
466 fprintf(stderr, "%s", string);
470 else if( warn && mwindow && not_equiv > 0 ) {
471 fprintf(stderr, _("%d job EDLs do not match session edl\n"), not_equiv);
472 char string[BCTEXTLEN], *sp = string;
473 sp += sprintf(sp, _("%d job EDLs do not match session edl\n"),not_equiv);
474 sp += sprintf(sp, _("press cancel to abandon batch render"));
475 mwindow->show_warning(&warn, string);
476 if( mwindow->wait_warning() ) {
477 gui->button_enable();
481 gui->warning->update(warn);
487 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
488 Preferences *preferences)
490 for( int i = 0; i < jobs.total; i++ ) {
491 BatchRenderJob *job = jobs.values[i];
492 if( job->enabled && *job->edl_path != '@' ) {
493 PackageDispatcher *packages = new PackageDispatcher;
496 TransportCommand *command = new TransportCommand;
497 FileXML *file = new FileXML;
498 file->read_from_file(job->edl_path);
500 // Use command to calculate range.
501 command->command = NORMAL_FWD;
502 command->get_edl()->load_xml(file,
504 command->change_type = CHANGE_ALL;
505 command->set_playback_range();
506 command->playback_range_adjust_inout();
508 // Create test packages
509 packages->create_packages(mwindow, command->get_edl(),
510 preferences, job->get_strategy(), job->asset,
511 command->start_position, command->end_position, 0);
513 // Append output paths allocated to total
514 packages->get_package_paths(paths);
516 // Delete package harness
525 void BatchRenderThread::start_rendering(char *config_path,
528 BC_Hash *boot_defaults;
529 Preferences *preferences;
531 BC_Signals *signals = new BC_Signals;
532 // XXX the above stuff is leaked,
534 // Initialize stuff which MWindow does.
535 signals->initialize("/tmp/cinelerra_batch%d.dmp");
537 MWindow::init_defaults(boot_defaults, config_path);
538 load_defaults(boot_defaults);
539 preferences = new Preferences;
540 preferences->load_defaults(boot_defaults);
541 BC_Signals::set_trap_hook(trap_hook, this);
542 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
543 BC_Signals::set_catch_intr(0);
544 if( preferences->trap_sigsegv ) {
545 BC_Trace::enable_locks();
548 BC_Trace::disable_locks();
551 MWindow::init_plugins(0, preferences);
552 char font_path[BCTEXTLEN];
553 strcpy(font_path, preferences->plugin_dir);
554 strcat(font_path, "/" FONT_SEARCHPATH);
555 BC_Resources::init_fontconfig(font_path);
556 BC_WindowBase::get_resources()->vframe_shm = 1;
559 strcpy(this->batch_path, batch_path);
560 load_jobs(batch_path, preferences);
561 save_jobs(batch_path);
562 save_defaults(boot_defaults);
565 // Test EDL files for existence
566 if( test_edl_files() ) return;
570 // Predict all destination paths
571 ArrayList<char*> paths;
572 paths.set_array_delete();
573 calculate_dest_paths(&paths, preferences);
576 int result = ConfirmSave::test_files(0, &paths);
577 paths.remove_all_objects();
578 // Abort on any existing file because it's so hard to set this up.
582 render = new Render(0);
584 render->start_batches(&jobs, boot_defaults, preferences);
588 void BatchRenderThread::start_rendering()
590 if( is_rendering ) return;
593 save_jobs(batch_path);
594 save_defaults(mwindow->defaults);
595 gui->button_disable();
597 // Test EDL files for existence
598 if( test_edl_files() ) return;
600 // Predict all destination paths
601 ArrayList<char*> paths;
602 calculate_dest_paths(&paths,
603 mwindow->preferences);
605 // Test destination files for overwrite
606 int result = ConfirmSave::test_files(mwindow, &paths);
607 paths.remove_all_objects();
612 gui->button_enable();
616 mwindow->render->start_batches(&jobs);
619 void BatchRenderThread::stop_rendering()
621 if( !is_rendering ) return;
622 mwindow->render->stop_operation();
626 void BatchRenderThread::update_active(int number)
628 gui->lock_window("BatchRenderThread::update_active");
630 current_job = number;
631 rendering_job = number;
638 gui->unlock_window();
641 void BatchRenderThread::update_done(int number,
645 gui->lock_window("BatchRenderThread::update_done");
647 gui->button_enable();
650 jobs.values[number]->enabled = 0;
651 jobs.values[number]->elapsed = elapsed_time;
652 if( create_list ) gui->create_list(1);
654 gui->unlock_window();
657 void BatchRenderThread::move_batch(int src, int dst)
659 BatchRenderJob *src_job = jobs.values[src];
660 if( dst < 0 ) dst = jobs.total - 1;
663 for( int i = src; i < jobs.total - 1; i++ )
664 jobs.values[i] = jobs.values[i + 1];
665 // if( dst > src ) dst--;
666 for( int i = jobs.total - 1; i > dst; i-- )
667 jobs.values[i] = jobs.values[i - 1];
668 jobs.values[dst] = src_job;
673 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
675 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
676 fprintf(fp, "\nEDL:\n");
677 mwindow->dump_edl(fp);
678 fprintf(fp, "\nUNDO:\n");
679 mwindow->dump_undo(fp);
680 fprintf(fp, "\nEXE:\n");
681 mwindow->dump_exe(fp);
688 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
689 BatchRenderThread *thread, int x, int y, int w, int h)
690 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
691 x, y, w, h, 730, 400, 1, 0, 1)
693 this->mwindow = mwindow;
694 this->thread = thread;
698 BatchRenderGUI::~BatchRenderGUI()
700 lock_window("BatchRenderGUI::~BatchRenderGUI");
701 loadlist_batch->stop();
702 savelist_batch->stop();
708 void BatchRenderGUI::create_objects()
710 lock_window("BatchRenderGUI::create_objects");
711 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
714 int x = mwindow->theme->batchrender_x1;
716 int x1 = x, x2 = get_w()/2 + 30; // mwindow->theme->batchrender_x2;
720 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
721 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
723 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
724 format_tools->set_w(x2 - 40);
725 BatchRenderJob *current_job = thread->get_current_job();
726 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
727 thread->do_labeled ? ¤t_job->labeled : 0, 0);
728 if( thread->do_labeled < 0 )
729 format_tools->labeled_files->disable();
730 if( thread->do_farmed ) {
731 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
732 ¤t_job->farmed);
733 add_subwindow(use_renderfarm);
734 y1 += use_renderfarm->get_h() + 10;
735 if( thread->do_farmed < 0 )
736 use_renderfarm->disable();
740 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
741 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
744 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
745 x, y, get_w()-x - 40, thread->get_current_edl()));
746 x = x2 + edl_path_text->get_w();
747 add_subwindow(edl_path_browse = new BrowseButton(
748 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
749 _("Input EDL"), _("Select an EDL to load:"), 0));
750 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
753 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
754 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
755 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
756 y += use_current_edl->get_h() + mwindow->theme->widget_border;
757 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
758 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
759 x += new_batch->get_w() + mwindow->theme->widget_border;
760 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
761 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
762 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
763 x += savelist_batch->get_w() + mwindow->theme->widget_border;
764 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
765 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
766 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
767 y2 = y + warning->get_h() + mwindow->theme->widget_border;
768 if( y2 > y1 ) y1 = y2;
769 x = mwindow->theme->batchrender_x1, y = y1;
771 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
772 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
773 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
774 y += list_title->get_h() + mwindow->theme->widget_border;
776 y1 -= 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
777 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
778 get_w() - x - 10, y1 - y));
779 y += batch_list->get_h() + mwindow->theme->widget_border;
781 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
782 x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
783 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
784 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - 10;
785 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
791 void BatchRenderGUI::button_disable()
793 new_batch->disable();
794 delete_batch->disable();
795 use_current_edl->disable();
796 update_selected_edl->disable();
799 void BatchRenderGUI::button_enable()
802 delete_batch->enable();
803 if( mwindow->edl && mwindow->edl->path[0] )
804 use_current_edl->enable();
805 update_selected_edl->enable();
808 int BatchRenderGUI::resize_event(int w, int h)
810 mwindow->session->batchrender_w = w;
811 mwindow->session->batchrender_h = h;
812 mwindow->theme->get_batchrender_sizes(this, w, h);
814 int x = mwindow->theme->batchrender_x1;
816 int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
820 output_path_title->reposition_window(x1, y1);
821 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
822 format_tools->reposition_window(x1, y1);
823 if( thread->do_farmed )
824 use_renderfarm->reposition_window(x1, y1);
827 edl_path_title->reposition_window(x, y);
828 y += edl_path_title->get_h() + mwindow->theme->widget_border;
829 edl_path_text->reposition_window(x, y, w - x - 40);
830 x += edl_path_text->get_w();
831 edl_path_browse->reposition_window(x, y);
832 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
835 update_selected_edl->reposition_window(x, y);
836 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
837 use_current_edl->reposition_window(x, y);
838 y += use_current_edl->get_h() + mwindow->theme->widget_border;
839 new_batch->reposition_window(x, y);
840 x += new_batch->get_w() + mwindow->theme->widget_border;
841 delete_batch->reposition_window(x, y);
843 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
844 savelist_batch->reposition_window(x, y);
845 x += savelist_batch->get_w() + mwindow->theme->widget_border;
846 loadlist_batch->reposition_window(x, y);
847 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
848 warning->reposition_window(x2, y);
850 y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
851 y2 = get_h() - y1 - batch_list->get_h();
852 y2 -= list_title->get_h() + mwindow->theme->widget_border;
854 x = mwindow->theme->batchrender_x1; y = y2;
855 list_title->reposition_window(x, y);
856 y += list_title->get_h() + mwindow->theme->widget_border;
857 batch_list->reposition_window(x, y, w - x - 10, h - y - y1);
858 y += batch_list->get_h() + mwindow->theme->widget_border;
860 start_button->reposition_window(x, y);
861 x = w / 2 - stop_button->get_w() / 2;
862 stop_button->reposition_window(x, y);
863 x = w - cancel_button->get_w() - 10;
864 cancel_button->reposition_window(x, y);
868 int BatchRenderGUI::translation_event()
870 mwindow->session->batchrender_x = get_x();
871 mwindow->session->batchrender_y = get_y();
875 int BatchRenderGUI::close_event()
877 // Stop batch rendering
879 thread->stop_rendering();
880 lock_window("BatchRenderGUI::close_event");
885 void BatchRenderGUI::create_list(int update_widget)
887 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
888 list_items[i].remove_all_objects();
891 const char **column_titles = BatchRenderThread::column_titles;
893 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
894 list_width[list_columns++] = thread->list_width[ENABLED_COL];
895 if( thread->do_labeled > 0 ) {
896 list_titles[list_columns] = _(column_titles[LABELED_COL]);
897 list_width[list_columns++] = thread->list_width[LABELED_COL];
899 if( thread->do_farmed > 0 ) {
900 list_titles[list_columns] = _(column_titles[FARMED_COL]);
901 list_width[list_columns++] = thread->list_width[FARMED_COL];
903 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
904 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
905 list_titles[list_columns] = _(column_titles[EDL_COL]);
906 list_width[list_columns++] = thread->list_width[EDL_COL];
907 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
908 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
910 for( int i = 0; i < thread->jobs.total; i++ ) {
911 BatchRenderJob *job = thread->jobs.values[i];
912 char string[BCTEXTLEN];
913 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
914 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
915 new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
916 BC_ListBoxItem *farmed = thread->do_farmed > 0 ?
917 new BC_ListBoxItem(job->farmed ? "X" : " ") : 0;
918 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
919 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
920 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
921 Units::totext(string, job->elapsed, TIME_HMS2));
923 list_items[col++].append(enabled);
924 if( labeled ) list_items[col++].append(labeled);
925 if( farmed ) list_items[col++].append(farmed);
926 list_items[col++].append(out_path);
927 list_items[col++].append(edl_path);
928 list_items[col].append(elapsed);
929 if( i == thread->current_job ) {
930 enabled->set_selected(1);
931 if( labeled ) labeled->set_selected(1);
932 if( farmed ) farmed->set_selected(1);
933 out_path->set_selected(1);
934 edl_path->set_selected(1);
935 elapsed->set_selected(1);
937 if( i == thread->rendering_job ) {
938 enabled->set_color(RED);
939 if( labeled ) labeled->set_color(RED);
940 if( farmed ) farmed->set_color(RED);
941 out_path->set_color(RED);
942 edl_path->set_color(RED);
943 elapsed->set_color(RED);
947 if( update_widget ) {
948 batch_list->update(list_items, list_titles, list_width, list_columns,
949 batch_list->get_xposition(), batch_list->get_yposition(),
950 batch_list->get_highlighted_item(), 1, 1);
954 void BatchRenderGUI::change_job()
956 BatchRenderJob *job = thread->get_current_job();
957 format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
958 if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
959 edl_path_text->update(job->edl_path);
963 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
964 : FormatTools(mwindow, gui, asset)
967 this->mwindow = mwindow;
970 BatchFormat::~BatchFormat()
975 int BatchFormat::handle_event()
981 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
982 int x, int y, int w, char *text)
983 : BC_TextBox(x, y, w, 1, text)
985 this->thread = thread;
989 int BatchRenderEDLPath::handle_event()
991 calculate_suggestions();
992 strcpy(thread->get_current_edl(), get_text());
993 thread->gui->create_list(1);
997 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1000 : BC_GenericButton(x, y, _("New"))
1002 this->thread = thread;
1005 int BatchRenderNew::handle_event()
1011 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1012 : BC_GenericButton(x, y, _("Delete"))
1014 this->thread = thread;
1017 int BatchRenderDelete::handle_event()
1019 thread->delete_job();
1025 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1026 : BC_GenericButton(x, y, _("Save Jobs"))
1028 this->thread = thread;
1029 set_tooltip(_("Save a Batch Render List"));
1031 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1034 BatchRenderSaveList::~BatchRenderSaveList()
1037 delete startup_lock;
1040 void BatchRenderSaveList::stop()
1042 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1043 if( gui ) gui->set_done(1);
1044 startup_lock->unlock();
1048 int BatchRenderSaveList::handle_event()
1050 if( Thread::running() ) {
1053 gui->raise_window();
1054 gui->unlock_window();
1058 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1060 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1061 startup_lock->unlock();
1065 void BatchRenderSaveList::run()
1067 char default_path[BCTEXTLEN];
1068 sprintf(default_path, "~");
1069 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1070 BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
1071 _("Enter a Batch Render filename to save as:"),
1075 startup_lock->unlock();
1076 filewindow.create_objects();
1078 int result2 = filewindow.run_window();
1080 strcpy(thread->batch_path, filewindow.get_submitted_path());
1081 thread->gui->lock_window("BatchRenderSaveList::run");
1082 thread->gui->batch_path->update(thread->batch_path);
1083 thread->gui->unlock_window();
1084 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1085 thread->save_jobs(thread->batch_path);
1088 startup_lock->lock("BatchRenderLoadList::run");
1090 startup_lock->unlock();
1093 int BatchRenderSaveList::keypress_event() {
1094 if( get_keypress() == 's' ||
1095 get_keypress() == 'S' ) return handle_event();
1100 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1103 : BC_GenericButton(x, y, _("Load Jobs")),
1106 this->thread = thread;
1107 set_tooltip(_("Load a previously saved Batch Render List"));
1109 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1112 BatchRenderLoadList::~BatchRenderLoadList()
1115 delete startup_lock;
1118 void BatchRenderLoadList::stop()
1120 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1121 if( gui ) gui->set_done(1);
1122 startup_lock->unlock();
1126 int BatchRenderLoadList::handle_event()
1128 if( Thread::running() ) {
1131 gui->raise_window();
1132 gui->unlock_window();
1136 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1138 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1139 startup_lock->unlock();
1143 void BatchRenderLoadList::run()
1145 char default_path[BCTEXTLEN];
1146 sprintf(default_path, "~");
1147 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1148 BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
1149 _("Enter a Batch Render filename to load from:"),
1153 startup_lock->unlock();
1154 filewindow.create_objects();
1156 int result2 = filewindow.run_window();
1158 strcpy(thread->batch_path, filewindow.get_submitted_path());
1159 thread->gui->batch_path->update(thread->batch_path);
1160 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1161 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1162 thread->gui->create_list(1);
1163 thread->current_job = 0;
1164 thread->gui->change_job();
1167 startup_lock->lock("BatchRenderLoadList::run");
1169 startup_lock->unlock();
1172 int BatchRenderLoadList::keypress_event() {
1173 if( get_keypress() == 'o' ||
1174 get_keypress() == 'O' ) return handle_event();
1178 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1181 : BC_GenericButton(x, y, _("Use Current EDL"))
1183 this->thread = thread;
1186 int BatchRenderCurrentEDL::handle_event()
1188 thread->use_current_edl();
1192 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1195 : BC_GenericButton(x, y, _("Save to EDL Path"))
1197 this->thread = thread;
1200 int BatchRenderUpdateEDL::handle_event()
1202 thread->update_selected_edl();
1207 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1208 int x, int y, int w, int h)
1209 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1210 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1211 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1213 this->thread = thread;
1215 set_process_drag(0);
1218 int BatchRenderList::handle_event()
1223 int BatchRenderList::selection_changed()
1225 thread->current_job = get_selection_number(0, 0);
1226 thread->gui->change_job();
1227 int cursor_x = get_cursor_x();
1228 BatchRenderJob *job = thread->get_current_job();
1229 int col_x = 0, changed = 1;
1230 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1231 job->enabled = !job->enabled;
1232 else if( thread->do_labeled > 0 &&
1233 cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1234 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1235 else if( thread->do_farmed > 0 &&
1236 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1237 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1241 thread->gui->create_list(1);
1242 thread->gui->change_job();
1247 int BatchRenderList::column_resize_event()
1250 thread->list_width[ENABLED_COL] = get_column_width(col++);
1251 if( thread->do_labeled > 0 )
1252 thread->list_width[LABELED_COL] = get_column_width(col++);
1253 if( thread->do_farmed > 0 )
1254 thread->list_width[FARMED_COL] = get_column_width(col++);
1255 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1256 thread->list_width[EDL_COL] = get_column_width(col++);
1257 thread->list_width[ELAPSED_COL] = get_column_width(col);
1261 int BatchRenderList::drag_start_event()
1263 if( BC_ListBox::drag_start_event() ) {
1271 int BatchRenderList::drag_motion_event()
1273 if( BC_ListBox::drag_motion_event() ) {
1279 int BatchRenderList::drag_stop_event()
1281 if( dragging_item ) {
1282 int src = get_selection_number(0, 0);
1283 int dst = get_highlighted_item();
1285 thread->move_batch(src, dst);
1287 BC_ListBox::drag_stop_event();
1295 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1296 : BC_GenericButton(x, y, _("Start"))
1298 this->thread = thread;
1301 int BatchRenderStart::handle_event()
1303 thread->start_rendering();
1307 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1308 : BC_GenericButton(x, y, _("Stop"))
1310 this->thread = thread;
1313 int BatchRenderStop::handle_event()
1316 thread->stop_rendering();
1317 lock_window("BatchRenderStop::handle_event");
1322 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1323 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1325 this->thread = thread;
1328 int BatchRenderWarning::handle_event()
1330 thread->warn = get_value();
1334 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1335 : BC_GenericButton(x, y, _("Close"))
1337 this->thread = thread;
1340 int BatchRenderCancel::handle_event()
1343 thread->stop_rendering();
1344 lock_window("BatchRenderCancel::handle_event");
1345 thread->gui->set_done(1);
1349 int BatchRenderCancel::keypress_event()
1351 if( get_keypress() == ESC ) {
1353 thread->stop_rendering();
1354 lock_window("BatchRenderCancel::keypress_event");
1355 thread->gui->set_done(1);
1361 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1362 : BC_CheckBox(x, y, *output, _("Use render farm"))
1364 this->thread = thread;
1365 this->output = output;
1368 int BatchRenderUseFarm::handle_event()
1370 *output = get_value();
1371 thread->gui->create_list(1);
1375 void BatchRenderUseFarm::update(int *output)
1377 this->output = output;
1378 BC_CheckBox::update(*output);