4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "batchrender.h"
24 #include "bcdisplayinfo.h"
25 #include "bcsignals.h"
26 #include "confirmsave.h"
32 #include "edlsession.h"
35 #include "filesystem.h"
37 #include "indexable.h"
42 #include "localsession.h"
43 #include "mainerror.h"
45 #include "mainsession.h"
48 #include "mwindowgui.h"
49 #include "packagedispatcher.h"
50 #include "packagerenderer.h"
52 #include "pluginset.h"
53 #include "preferences.h"
57 #include "transportque.h"
60 #include "dvdcreate.h"
63 int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
64 const char *BatchRenderThread::column_titles[] = {
65 N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
68 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
69 : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
72 this->mwindow = mwindow;
75 int BatchRenderMenuItem::handle_event()
77 mwindow->batch_render->start(1, 1);
81 BatchRenderJob::BatchRenderJob(const char *tag,
82 Preferences *preferences, int labeled, int farmed)
85 this->preferences = preferences;
86 this->labeled = labeled;
87 this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
94 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
95 : BatchRenderJob("JOB", preferences, labeled, farmed)
99 BatchRenderJob::~BatchRenderJob()
101 asset->Garbage::remove_user();
104 void BatchRenderJob::copy_from(BatchRenderJob *src)
106 enabled = src->enabled;
107 farmed = src->farmed;
108 labeled = src->labeled;
109 asset->copy_from(src->asset, 0);
110 strcpy(edl_path, src->edl_path);
114 BatchRenderJob *BatchRenderJob::copy()
116 BatchRenderJob *t = new BatchRenderJob(tag, preferences, labeled, farmed);
121 void BatchRenderJob::load(FileXML *file)
125 enabled = file->tag.get_property("ENABLED", enabled);
126 farmed = file->tag.get_property("FARMED", farmed);
127 labeled = file->tag.get_property("LABELED", labeled);
129 file->tag.get_property("EDL_PATH", edl_path);
130 elapsed = file->tag.get_property("ELAPSED", elapsed);
132 result = file->read_tag();
134 if( file->tag.title_is("ASSET") ) {
135 file->tag.get_property("SRC", asset->path);
136 asset->read(file, 0);
137 // The compression parameters are stored in the defaults to reduce
138 // coding maintenance. The defaults must now be stuffed into the XML for
141 defaults.load_string(file->read_text());
142 asset->load_defaults(&defaults,
148 void BatchRenderJob::save(FileXML *file)
150 char end_tag[BCSTRLEN]; end_tag[0] = '/';
151 strcpy(&end_tag[1], file->tag.get_title());
152 file->tag.set_property("ENABLED", enabled);
153 file->tag.set_property("FARMED", farmed);
154 file->tag.set_property("LABELED", labeled);
155 file->tag.set_property("EDL_PATH", edl_path);
156 file->tag.set_property("ELAPSED", elapsed);
158 file->append_newline();
159 asset->write(file, 0, "");
161 // The compression parameters are stored in the defaults to reduce
162 // coding maintenance. The defaults must now be stuffed into the XML for
165 asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
167 defaults.save_string(string);
168 file->append_text(string);
170 file->tag.set_title(end_tag);
172 file->append_newline();
175 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
180 int BatchRenderJob::get_strategy()
182 return Render::get_strategy(farmed, labeled);
186 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
189 this->mwindow = mwindow;
203 BatchRenderThread::~BatchRenderThread()
206 delete boot_defaults;
212 void BatchRenderThread::reset(const char *path)
215 strcpy(batch_path, path);
220 delete default_job; default_job = 0;
221 jobs.remove_all_objects();
224 void BatchRenderThread::start(int do_farmed, int do_labeled)
226 this->do_farmed = do_farmed;
227 this->do_labeled = do_labeled;
228 BC_DialogThread::start();
231 void BatchRenderThread::handle_close_event(int result)
234 save_jobs(batch_path);
235 save_defaults(mwindow->defaults);
239 BC_Window* BatchRenderThread::new_gui()
243 default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
244 load_jobs(batch_path, mwindow->preferences);
245 load_defaults(mwindow->defaults);
246 this->gui = new BatchRenderGUI(mwindow, this,
247 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
248 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
249 this->gui->create_objects();
254 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
259 jobs.remove_all_objects();
260 if( !path ) path = batch_path;
261 if( !path[0] ) create_path(path);
262 file.read_from_file(path);
265 if( !(result = file.read_tag()) ) {
266 if( file.tag.title_is("JOBS") ) {
267 warn = file.tag.get_property("WARN", 1);
269 else if( file.tag.title_is("JOB") ) {
270 BatchRenderJob *job = new BatchRenderJob(preferences, 0,0);
274 else if( file.tag.title_is("DVD_JOB") ) {
275 DVD_BatchRenderJob *job = new DVD_BatchRenderJob(preferences, 0,0,0,0);
279 else if( file.tag.title_is("BD_JOB") ) {
280 BD_BatchRenderJob *job = new BD_BatchRenderJob(preferences, 0,0);
288 void BatchRenderThread::save_jobs(char *path)
291 file.tag.set_title("JOBS");
292 file.tag.set_property("WARN", warn);
294 file.append_newline();
296 for( int i = 0; i < jobs.total; i++ ) {
297 file.tag.set_title(jobs[i]->tag);
298 jobs[i]->save(&file);
300 file.tag.set_title("/JOBS");
302 file.append_newline();
304 if( !path ) path = batch_path;
305 if( !path[0] ) create_path(path);
306 file.write_to_file(path);
309 void BatchRenderThread::load_defaults(BC_Hash *defaults)
312 default_job->asset->load_defaults(defaults,
313 "BATCHRENDER_", 1, 1, 1, 1, 1);
316 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
317 char string[BCTEXTLEN];
318 sprintf(string, "BATCHRENDER_COLUMN%d", i);
319 list_width[i] = defaults->get(string, column_widths[i]);
323 void BatchRenderThread::save_defaults(BC_Hash *defaults)
326 default_job->asset->save_defaults(defaults,
327 "BATCHRENDER_", 1, 1, 1, 1, 1);
329 for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
330 char string[BCTEXTLEN];
331 sprintf(string, "BATCHRENDER_COLUMN%d", i);
332 defaults->update(string, list_width[i]);
334 // defaults->update("BATCHRENDER_JOB", current_job);
336 mwindow->save_defaults();
341 char* BatchRenderThread::create_path(char *string)
344 sprintf(string, "%s/", File::get_config_path());
345 fs.complete_path(string);
346 strcat(string, BATCH_PATH);
350 void BatchRenderThread::new_job()
352 BatchRenderJob *result = get_current_job()->copy();
354 current_job = jobs.total - 1;
359 void BatchRenderThread::delete_job()
361 if( current_job < jobs.total && current_job >= 0 ) {
362 jobs.remove_object_number(current_job);
363 if( current_job > 0 ) current_job--;
369 void BatchRenderThread::use_current_edl()
371 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
373 // mwindow->edl->path,
374 // mwindow->edl->path);
376 strcpy(get_current_edl(), mwindow->edl->path);
378 gui->edl_path_text->update(get_current_edl());
381 void BatchRenderThread::update_selected_edl()
384 char *path = get_current_edl();
385 EDL *edl = mwindow->edl;
386 edl->save_xml(&xml_file, path);
387 xml_file.terminate_string();
388 if( xml_file.write_to_file(path) ) {
390 sprintf(msg, _("Unable to save: %s"), path);
391 MainError::show_error(msg);
395 BatchRenderJob* BatchRenderThread::get_current_job()
397 return current_job >= 0 && current_job < jobs.total ?
398 jobs.values[current_job] : default_job;
402 Asset* BatchRenderThread::get_current_asset()
404 return get_current_job()->asset;
407 char* BatchRenderThread::get_current_edl()
409 return get_current_job()->edl_path;
412 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
414 int count = err_jobs.size();
415 if( !count ) return 0;
416 fprintf(stderr, msg, count);
417 char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
418 sp += snprintf(sp,ep-sp, msg,count);
419 for( int i=0; i<count; ++i ) {
420 int no = err_jobs[i].no;
421 const char *path = err_jobs[i].path;
422 fprintf(stderr, "%d: %s\n", no, path);
423 sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
425 sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
426 mwindow->show_warning(warn, string);
427 if( mwindow->wait_warning() ) {
428 gui->button_enable();
433 // Test EDL files for existence
434 int BatchRenderThread::test_edl_files()
437 const char *path = 0;
438 BatchRenderWarnJobs not_equiv;
439 BatchRenderWarnJobs empty_jobs;
440 BatchRenderWarnJobs no_labels;
441 BatchRenderWarnJobs no_rendering;
443 for( int i=0; !ret && i<jobs.size(); ++i ) {
444 if( !jobs.values[i]->enabled ) continue;
445 path = jobs[i]->edl_path;
446 int is_script = *path == '@' ? 1 : 0;
447 if( is_script ) ++path;
448 FILE *fp = fopen(path, "r");
450 if( mwindow && !is_script ) {
451 char *bfr = 0; size_t sz = 0;
453 if( !fstat(fileno(fp), &st) ) {
455 bfr = new char[sz+1];
456 if( fread(bfr, 1, sz+1, fp) != sz )
462 EDL *edl = new EDL; edl->create_objects();
463 XMLBuffer data(bfr, sz, 0);
465 file.set_shared_input(&data);
466 edl->load_xml(&file, LOAD_ALL); }
467 double pos = edl->equivalent_output(mwindow->edl);
469 not_equiv.add(i+1, path);
470 double length = edl->tracks->total_playable_length();
471 double start = edl->local_session->get_selectionstart(1);
472 if( start >= length )
473 empty_jobs.add(i+1, path);
474 if( jobs[i]->labeled && !edl->labels->first)
475 no_labels.add(i+1,path);
476 Asset *asset = jobs[i]->asset;
477 if( !asset->audio_data && !asset->video_data )
478 no_rendering.add(i+1,path);
490 char string[BCTEXTLEN];
491 sprintf(string, _("EDL %s not found.\n"), path);
493 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
494 mwindow->gui->get_abs_cursor_x(1),
495 mwindow->gui->get_abs_cursor_y(1));
496 error_box.create_objects(string);
497 error_box.run_window();
498 gui->button_enable();
501 fprintf(stderr, "%s", string);
507 if( !ret && warn && mwindow ) {
508 ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
509 if( !warn ) gui->warning->update(0);
511 if( !ret && mwindow )
512 ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
513 if( !ret && mwindow )
514 ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
515 if( !ret && mwindow )
516 ret = test_errmsg(no_labels, _("%d job EDLs render file per label and no labels\n"), 0);
522 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
523 Preferences *preferences)
525 for( int i = 0; i < jobs.total; i++ ) {
526 BatchRenderJob *job = jobs.values[i];
527 if( job->enabled && *job->edl_path != '@' ) {
528 PackageDispatcher *packages = new PackageDispatcher;
531 TransportCommand *command = new TransportCommand;
532 FileXML *file = new FileXML;
533 file->read_from_file(job->edl_path);
535 // Use command to calculate range.
536 command->command = NORMAL_FWD;
537 command->get_edl()->load_xml(file,
539 command->change_type = CHANGE_ALL;
540 command->set_playback_range();
541 command->playback_range_adjust_inout();
543 // Create test packages
544 int result = packages->create_packages(mwindow, command->get_edl(),
545 preferences, job->get_strategy(), job->asset,
546 command->start_position, command->end_position, 0);
548 packages->get_package_paths(paths);
550 // Append output paths allocated to total
552 // Delete package harness
561 void BatchRenderThread::start_rendering(char *config_path,
564 BC_Hash *boot_defaults;
565 Preferences *preferences;
567 BC_Signals *signals = new BC_Signals;
568 // XXX the above stuff is leaked,
570 // Initialize stuff which MWindow does.
571 signals->initialize("/tmp/cinelerra_batch%d.dmp");
573 MWindow::init_defaults(boot_defaults, config_path);
574 load_defaults(boot_defaults);
575 preferences = new Preferences;
576 preferences->load_defaults(boot_defaults);
577 BC_Signals::set_trap_hook(trap_hook, this);
578 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
579 BC_Signals::set_catch_intr(0);
580 if( preferences->trap_sigsegv ) {
581 BC_Trace::enable_locks();
584 BC_Trace::disable_locks();
587 MWindow::init_plugins(0, preferences);
588 char font_path[BCTEXTLEN];
589 strcpy(font_path, preferences->plugin_dir);
590 strcat(font_path, "/" FONT_SEARCHPATH);
591 BC_Resources::init_fontconfig(font_path);
592 BC_WindowBase::get_resources()->vframe_shm = 1;
595 strcpy(this->batch_path, batch_path);
596 load_jobs(batch_path, preferences);
597 save_jobs(batch_path);
598 save_defaults(boot_defaults);
601 // Test EDL files for existence
602 if( test_edl_files() ) return;
606 // Predict all destination paths
607 ArrayList<char*> paths;
608 paths.set_array_delete();
609 calculate_dest_paths(&paths, preferences);
612 int result = ConfirmSave::test_files(0, &paths);
613 paths.remove_all_objects();
614 // Abort on any existing file because it's so hard to set this up.
618 render = new Render(0);
620 render->start_batches(&jobs, boot_defaults, preferences);
624 void BatchRenderThread::start_rendering()
626 if( is_rendering ) return;
629 save_jobs(batch_path);
630 save_defaults(mwindow->defaults);
631 gui->button_disable();
633 // Test EDL files for existence
634 if( test_edl_files() ) return;
636 // Predict all destination paths
637 ArrayList<char*> paths;
638 calculate_dest_paths(&paths,
639 mwindow->preferences);
641 // Test destination files for overwrite
642 int result = ConfirmSave::test_files(mwindow, &paths);
643 paths.remove_all_objects();
648 gui->button_enable();
652 mwindow->render->start_batches(&jobs);
655 void BatchRenderThread::stop_rendering()
657 if( !is_rendering ) return;
658 mwindow->render->stop_operation();
662 void BatchRenderThread::update_active(int number)
664 gui->lock_window("BatchRenderThread::update_active");
666 current_job = number;
667 rendering_job = number;
674 gui->unlock_window();
677 void BatchRenderThread::update_done(int number,
681 gui->lock_window("BatchRenderThread::update_done");
683 gui->button_enable();
686 jobs.values[number]->enabled = 0;
687 jobs.values[number]->elapsed = elapsed_time;
688 if( create_list ) gui->create_list(1);
690 gui->unlock_window();
693 void BatchRenderThread::move_batch(int src, int dst)
695 BatchRenderJob *src_job = jobs.values[src];
696 if( dst < 0 ) dst = jobs.total - 1;
699 for( int i = src; i < jobs.total - 1; i++ )
700 jobs.values[i] = jobs.values[i + 1];
701 // if( dst > src ) dst--;
702 for( int i = jobs.total - 1; i > dst; i-- )
703 jobs.values[i] = jobs.values[i - 1];
704 jobs.values[dst] = src_job;
709 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
711 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
712 fprintf(fp, "\nEDL:\n");
713 mwindow->dump_edl(fp);
714 fprintf(fp, "\nUNDO:\n");
715 mwindow->dump_undo(fp);
716 fprintf(fp, "\nEXE:\n");
717 mwindow->dump_exe(fp);
724 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
725 BatchRenderThread *thread, int x, int y, int w, int h)
726 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
727 x, y, w, h, 730, 400, 1, 0, 1)
729 this->mwindow = mwindow;
730 this->thread = thread;
734 BatchRenderGUI::~BatchRenderGUI()
736 lock_window("BatchRenderGUI::~BatchRenderGUI");
737 loadlist_batch->stop();
738 savelist_batch->stop();
744 void BatchRenderGUI::create_objects()
746 lock_window("BatchRenderGUI::create_objects");
747 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
750 int x = mwindow->theme->batchrender_x1;
752 int x1 = x, x2 = get_w()/2 + 30; // mwindow->theme->batchrender_x2;
756 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
757 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
759 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
760 format_tools->set_w(x2 - 40);
761 BatchRenderJob *current_job = thread->get_current_job();
762 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
763 thread->do_labeled ? ¤t_job->labeled : 0, 0);
764 if( thread->do_labeled < 0 )
765 format_tools->labeled_files->disable();
766 if( thread->do_farmed ) {
767 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
768 ¤t_job->farmed);
769 add_subwindow(use_renderfarm);
770 y1 += use_renderfarm->get_h() + 10;
771 if( thread->do_farmed < 0 )
772 use_renderfarm->disable();
776 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
777 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
780 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
781 x, y, get_w()-x - 40, thread->get_current_edl()));
782 x = x2 + edl_path_text->get_w();
783 add_subwindow(edl_path_browse = new BrowseButton(
784 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
785 _("Input EDL"), _("Select an EDL to load:"), 0));
786 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
789 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
790 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
791 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
792 y += use_current_edl->get_h() + mwindow->theme->widget_border;
793 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
794 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
795 x += new_batch->get_w() + mwindow->theme->widget_border;
796 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
797 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
798 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
799 x += savelist_batch->get_w() + mwindow->theme->widget_border;
800 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
801 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
802 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
803 y2 = y + warning->get_h() + mwindow->theme->widget_border;
804 if( y2 > y1 ) y1 = y2;
805 x = mwindow->theme->batchrender_x1, y = y1;
807 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
808 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
809 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
810 y += list_title->get_h() + mwindow->theme->widget_border;
812 y1 -= 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
813 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
814 get_w() - x - 10, y1 - y));
815 y += batch_list->get_h() + mwindow->theme->widget_border;
817 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
818 x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
819 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
820 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - 10;
821 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
827 void BatchRenderGUI::button_disable()
829 new_batch->disable();
830 delete_batch->disable();
831 use_current_edl->disable();
832 update_selected_edl->disable();
835 void BatchRenderGUI::button_enable()
838 delete_batch->enable();
839 if( mwindow->edl && mwindow->edl->path[0] )
840 use_current_edl->enable();
841 update_selected_edl->enable();
844 int BatchRenderGUI::resize_event(int w, int h)
846 mwindow->session->batchrender_w = w;
847 mwindow->session->batchrender_h = h;
848 mwindow->theme->get_batchrender_sizes(this, w, h);
850 int x = mwindow->theme->batchrender_x1;
852 int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
856 output_path_title->reposition_window(x1, y1);
857 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
858 format_tools->reposition_window(x1, y1);
859 if( thread->do_farmed )
860 use_renderfarm->reposition_window(x1, y1);
863 edl_path_title->reposition_window(x, y);
864 y += edl_path_title->get_h() + mwindow->theme->widget_border;
865 edl_path_text->reposition_window(x, y, w - x - 40);
866 x += edl_path_text->get_w();
867 edl_path_browse->reposition_window(x, y);
868 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
871 update_selected_edl->reposition_window(x, y);
872 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
873 use_current_edl->reposition_window(x, y);
874 y += use_current_edl->get_h() + mwindow->theme->widget_border;
875 new_batch->reposition_window(x, y);
876 x += new_batch->get_w() + mwindow->theme->widget_border;
877 delete_batch->reposition_window(x, y);
879 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
880 savelist_batch->reposition_window(x, y);
881 x += savelist_batch->get_w() + mwindow->theme->widget_border;
882 loadlist_batch->reposition_window(x, y);
883 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
884 warning->reposition_window(x2, y);
886 y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
887 y2 = get_h() - y1 - batch_list->get_h();
888 y2 -= list_title->get_h() + mwindow->theme->widget_border;
890 x = mwindow->theme->batchrender_x1; y = y2;
891 list_title->reposition_window(x, y);
892 y += list_title->get_h() + mwindow->theme->widget_border;
893 batch_list->reposition_window(x, y, w - x - 10, h - y - y1);
894 y += batch_list->get_h() + mwindow->theme->widget_border;
896 start_button->reposition_window(x, y);
897 x = w / 2 - stop_button->get_w() / 2;
898 stop_button->reposition_window(x, y);
899 x = w - cancel_button->get_w() - 10;
900 cancel_button->reposition_window(x, y);
904 int BatchRenderGUI::translation_event()
906 mwindow->session->batchrender_x = get_x();
907 mwindow->session->batchrender_y = get_y();
911 int BatchRenderGUI::close_event()
913 // Stop batch rendering
915 thread->stop_rendering();
916 lock_window("BatchRenderGUI::close_event");
921 void BatchRenderGUI::create_list(int update_widget)
923 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
924 list_items[i].remove_all_objects();
927 const char **column_titles = BatchRenderThread::column_titles;
929 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
930 list_width[list_columns++] = thread->list_width[ENABLED_COL];
931 if( thread->do_labeled > 0 ) {
932 list_titles[list_columns] = _(column_titles[LABELED_COL]);
933 list_width[list_columns++] = thread->list_width[LABELED_COL];
935 if( thread->do_farmed > 0 ) {
936 list_titles[list_columns] = _(column_titles[FARMED_COL]);
937 list_width[list_columns++] = thread->list_width[FARMED_COL];
939 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
940 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
941 list_titles[list_columns] = _(column_titles[EDL_COL]);
942 list_width[list_columns++] = thread->list_width[EDL_COL];
943 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
944 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
946 for( int i = 0; i < thread->jobs.total; i++ ) {
947 BatchRenderJob *job = thread->jobs.values[i];
948 char string[BCTEXTLEN];
949 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
950 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
951 new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
952 BC_ListBoxItem *farmed = thread->do_farmed > 0 ?
953 new BC_ListBoxItem(job->farmed ? "X" : " ") : 0;
954 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
955 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
956 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
957 Units::totext(string, job->elapsed, TIME_HMS2));
959 list_items[col++].append(enabled);
960 if( labeled ) list_items[col++].append(labeled);
961 if( farmed ) list_items[col++].append(farmed);
962 list_items[col++].append(out_path);
963 list_items[col++].append(edl_path);
964 list_items[col].append(elapsed);
965 if( i == thread->current_job ) {
966 enabled->set_selected(1);
967 if( labeled ) labeled->set_selected(1);
968 if( farmed ) farmed->set_selected(1);
969 out_path->set_selected(1);
970 edl_path->set_selected(1);
971 elapsed->set_selected(1);
973 if( i == thread->rendering_job ) {
974 enabled->set_color(RED);
975 if( labeled ) labeled->set_color(RED);
976 if( farmed ) farmed->set_color(RED);
977 out_path->set_color(RED);
978 edl_path->set_color(RED);
979 elapsed->set_color(RED);
983 if( update_widget ) {
984 batch_list->update(list_items, list_titles, list_width, list_columns,
985 batch_list->get_xposition(), batch_list->get_yposition(),
986 batch_list->get_highlighted_item(), 1, 1);
990 void BatchRenderGUI::change_job()
992 BatchRenderJob *job = thread->get_current_job();
993 format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
994 if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
995 edl_path_text->update(job->edl_path);
999 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1000 : FormatTools(mwindow, gui, asset)
1003 this->mwindow = mwindow;
1006 BatchFormat::~BatchFormat()
1011 int BatchFormat::handle_event()
1013 gui->create_list(1);
1017 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1018 int x, int y, int w, char *text)
1019 : BC_TextBox(x, y, w, 1, text)
1021 this->thread = thread;
1025 int BatchRenderEDLPath::handle_event()
1027 calculate_suggestions();
1028 strcpy(thread->get_current_edl(), get_text());
1029 thread->gui->create_list(1);
1033 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1036 : BC_GenericButton(x, y, _("New"))
1038 this->thread = thread;
1041 int BatchRenderNew::handle_event()
1047 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1048 : BC_GenericButton(x, y, _("Delete"))
1050 this->thread = thread;
1053 int BatchRenderDelete::handle_event()
1055 thread->delete_job();
1061 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1062 : BC_GenericButton(x, y, _("Save Jobs"))
1064 this->thread = thread;
1065 set_tooltip(_("Save a Batch Render List"));
1067 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1070 BatchRenderSaveList::~BatchRenderSaveList()
1073 delete startup_lock;
1076 void BatchRenderSaveList::stop()
1078 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1079 if( gui ) gui->set_done(1);
1080 startup_lock->unlock();
1084 int BatchRenderSaveList::handle_event()
1086 if( Thread::running() ) {
1089 gui->raise_window();
1090 gui->unlock_window();
1094 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1096 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1097 startup_lock->unlock();
1101 void BatchRenderSaveList::run()
1103 char default_path[BCTEXTLEN];
1104 sprintf(default_path, "~");
1105 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1106 BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
1107 _("Enter a Batch Render filename to save as:"),
1111 startup_lock->unlock();
1112 filewindow.create_objects();
1114 int result2 = filewindow.run_window();
1116 strcpy(thread->batch_path, filewindow.get_submitted_path());
1117 thread->gui->lock_window("BatchRenderSaveList::run");
1118 thread->gui->batch_path->update(thread->batch_path);
1119 thread->gui->unlock_window();
1120 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1121 thread->save_jobs(thread->batch_path);
1124 startup_lock->lock("BatchRenderLoadList::run");
1126 startup_lock->unlock();
1129 int BatchRenderSaveList::keypress_event() {
1130 if( get_keypress() == 's' ||
1131 get_keypress() == 'S' ) return handle_event();
1136 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1139 : BC_GenericButton(x, y, _("Load Jobs")),
1142 this->thread = thread;
1143 set_tooltip(_("Load a previously saved Batch Render List"));
1145 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1148 BatchRenderLoadList::~BatchRenderLoadList()
1151 delete startup_lock;
1154 void BatchRenderLoadList::stop()
1156 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1157 if( gui ) gui->set_done(1);
1158 startup_lock->unlock();
1162 int BatchRenderLoadList::handle_event()
1164 if( Thread::running() ) {
1167 gui->raise_window();
1168 gui->unlock_window();
1172 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1174 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1175 startup_lock->unlock();
1179 void BatchRenderLoadList::run()
1181 char default_path[BCTEXTLEN];
1182 sprintf(default_path, "~");
1183 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1184 BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
1185 _("Enter a Batch Render filename to load from:"),
1189 startup_lock->unlock();
1190 filewindow.create_objects();
1192 int result2 = filewindow.run_window();
1194 strcpy(thread->batch_path, filewindow.get_submitted_path());
1195 thread->gui->batch_path->update(thread->batch_path);
1196 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1197 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1198 thread->gui->create_list(1);
1199 thread->current_job = 0;
1200 thread->gui->change_job();
1203 startup_lock->lock("BatchRenderLoadList::run");
1205 startup_lock->unlock();
1208 int BatchRenderLoadList::keypress_event() {
1209 if( get_keypress() == 'o' ||
1210 get_keypress() == 'O' ) return handle_event();
1214 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1217 : BC_GenericButton(x, y, _("Use Current EDL"))
1219 this->thread = thread;
1222 int BatchRenderCurrentEDL::handle_event()
1224 thread->use_current_edl();
1228 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1231 : BC_GenericButton(x, y, _("Save to EDL Path"))
1233 this->thread = thread;
1236 int BatchRenderUpdateEDL::handle_event()
1238 thread->update_selected_edl();
1243 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1244 int x, int y, int w, int h)
1245 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1246 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1247 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1249 this->thread = thread;
1251 set_process_drag(0);
1254 int BatchRenderList::handle_event()
1259 int BatchRenderList::selection_changed()
1261 thread->current_job = get_selection_number(0, 0);
1262 thread->gui->change_job();
1263 int cursor_x = get_cursor_x();
1264 BatchRenderJob *job = thread->get_current_job();
1265 int col_x = 0, changed = 1;
1266 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1267 job->enabled = !job->enabled;
1268 else if( thread->do_labeled > 0 &&
1269 cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1270 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1271 else if( thread->do_farmed > 0 &&
1272 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1273 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1277 thread->gui->create_list(1);
1278 thread->gui->change_job();
1283 int BatchRenderList::column_resize_event()
1286 thread->list_width[ENABLED_COL] = get_column_width(col++);
1287 if( thread->do_labeled > 0 )
1288 thread->list_width[LABELED_COL] = get_column_width(col++);
1289 if( thread->do_farmed > 0 )
1290 thread->list_width[FARMED_COL] = get_column_width(col++);
1291 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1292 thread->list_width[EDL_COL] = get_column_width(col++);
1293 thread->list_width[ELAPSED_COL] = get_column_width(col);
1297 int BatchRenderList::drag_start_event()
1299 if( BC_ListBox::drag_start_event() ) {
1307 int BatchRenderList::drag_motion_event()
1309 if( BC_ListBox::drag_motion_event() ) {
1315 int BatchRenderList::drag_stop_event()
1317 if( dragging_item ) {
1318 int src = get_selection_number(0, 0);
1319 int dst = get_highlighted_item();
1321 thread->move_batch(src, dst);
1323 BC_ListBox::drag_stop_event();
1331 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1332 : BC_GenericButton(x, y, _("Start"))
1334 this->thread = thread;
1337 int BatchRenderStart::handle_event()
1339 thread->start_rendering();
1343 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1344 : BC_GenericButton(x, y, _("Stop"))
1346 this->thread = thread;
1349 int BatchRenderStop::handle_event()
1352 thread->stop_rendering();
1353 lock_window("BatchRenderStop::handle_event");
1358 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1359 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1361 this->thread = thread;
1364 int BatchRenderWarning::handle_event()
1366 thread->warn = get_value();
1370 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1371 : BC_GenericButton(x, y, _("Close"))
1373 this->thread = thread;
1376 int BatchRenderCancel::handle_event()
1379 thread->stop_rendering();
1380 lock_window("BatchRenderCancel::handle_event");
1381 thread->gui->set_done(1);
1385 int BatchRenderCancel::keypress_event()
1387 if( get_keypress() == ESC ) {
1389 thread->stop_rendering();
1390 lock_window("BatchRenderCancel::keypress_event");
1391 thread->gui->set_done(1);
1397 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1398 : BC_CheckBox(x, y, *output, _("Use render farm"))
1400 this->thread = thread;
1401 this->output = output;
1404 int BatchRenderUseFarm::handle_event()
1406 *output = get_value();
1407 thread->gui->create_list(1);
1411 void BatchRenderUseFarm::update(int *output)
1413 this->output = output;
1414 BC_CheckBox::update(*output);