4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "batchrender.h"
25 #include "bcdisplayinfo.h"
26 #include "bcsignals.h"
27 #include "confirmsave.h"
33 #include "edlsession.h"
36 #include "filesystem.h"
38 #include "indexable.h"
43 #include "localsession.h"
44 #include "mainerror.h"
46 #include "mainsession.h"
49 #include "mwindowgui.h"
50 #include "packagedispatcher.h"
51 #include "packagerenderer.h"
53 #include "pluginset.h"
54 #include "preferences.h"
58 #include "transportque.h"
61 #include "dvdcreate.h"
66 int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
67 const char *BatchRenderThread::column_titles[] = {
68 N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
71 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
72 : BC_MenuItem(_("Batch Render..."), _("Shift-B"), 'B')
75 this->mwindow = mwindow;
78 int BatchRenderMenuItem::handle_event()
80 mwindow->batch_render->start(1, 1);
84 BatchRenderJob::BatchRenderJob(const char *tag,
85 Preferences *preferences, int labeled, int farmed)
88 this->preferences = preferences;
89 this->labeled = labeled;
90 this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
97 BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
98 : BatchRenderJob("JOB", preferences, labeled, farmed)
102 BatchRenderJob::~BatchRenderJob()
104 asset->Garbage::remove_user();
107 void BatchRenderJob::copy_from(BatchRenderJob *src)
109 enabled = src->enabled;
110 farmed = src->farmed;
111 labeled = src->labeled;
112 asset->copy_from(src->asset, 0);
113 strcpy(edl_path, src->edl_path);
117 BatchRenderJob *BatchRenderJob::copy()
119 BatchRenderJob *t = new BatchRenderJob(tag, preferences, labeled, farmed);
124 void BatchRenderJob::load(FileXML *file)
127 char job_title[BCSTRLEN];
128 strcpy(job_title, file->tag.title);
130 enabled = file->tag.get_property("ENABLED", enabled);
131 farmed = file->tag.get_property("FARMED", farmed);
132 labeled = file->tag.get_property("LABELED", labeled);
134 file->tag.get_property("EDL_PATH", edl_path);
135 elapsed = file->tag.get_property("ELAPSED", elapsed);
137 result = file->read_tag();
139 if( file->tag.title_is("ASSET") ) {
140 file->tag.get_property("SRC", asset->path);
141 asset->read(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 defaults.load_string(file->read_text(job_title));
147 asset->load_defaults(&defaults,
153 void BatchRenderJob::save(FileXML *file)
155 char end_tag[BCSTRLEN]; end_tag[0] = '/';
156 strcpy(&end_tag[1], file->tag.get_title());
157 file->tag.set_property("ENABLED", enabled);
158 file->tag.set_property("FARMED", farmed);
159 file->tag.set_property("LABELED", labeled);
160 file->tag.set_property("EDL_PATH", edl_path);
161 file->tag.set_property("ELAPSED", elapsed);
163 file->append_newline();
164 asset->write(file, 0, "");
166 // The compression parameters are stored in the defaults to reduce
167 // coding maintenance. The defaults must now be stuffed into the XML for
170 asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
172 defaults.save_string(string);
173 file->append_text(string);
175 file->tag.set_title(end_tag);
177 file->append_newline();
180 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
185 int BatchRenderJob::get_strategy()
187 int range = File::is_image_render(asset->format) ?
188 RANGE_1FRAME : RANGE_SELECTION;
189 return Render::get_strategy(farmed, labeled, range);
193 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
196 this->mwindow = mwindow;
210 BatchRenderThread::~BatchRenderThread()
213 delete boot_defaults;
219 void BatchRenderThread::reset(const char *path)
222 strcpy(batch_path, path);
227 delete default_job; default_job = 0;
228 jobs.remove_all_objects();
231 void BatchRenderThread::start(int do_farmed, int do_labeled)
233 this->do_farmed = do_farmed;
234 this->do_labeled = do_labeled;
235 BC_DialogThread::start();
238 void BatchRenderThread::handle_close_event(int result)
241 save_jobs(batch_path);
242 save_defaults(mwindow->defaults);
246 BC_Window* BatchRenderThread::new_gui()
250 default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
251 load_jobs(batch_path, mwindow->preferences);
252 load_defaults(mwindow->defaults);
253 this->gui = new BatchRenderGUI(mwindow, this,
254 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
255 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
256 this->gui->create_objects();
261 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
266 jobs.remove_all_objects();
267 if( !path ) path = batch_path;
268 if( !path[0] ) create_path(path);
269 file.read_from_file(path);
272 if( !(result = file.read_tag()) ) {
273 if( file.tag.title_is("JOBS") ) {
274 if (mwindow && mwindow->preferences->unsafe_gui)
275 warn = file.tag.get_property("WARN", 1);
276 if (mwindow && !mwindow->preferences->unsafe_gui)
279 else if( file.tag.title_is("JOB") ) {
280 BatchRenderJob *job = new BatchRenderJob(preferences, 0,0);
284 else if( file.tag.title_is("DVD_JOB") ) {
285 DVD_BatchRenderJob *job = new DVD_BatchRenderJob(preferences, 0,0,0,0);
289 else if( file.tag.title_is("BD_JOB") ) {
290 BD_BatchRenderJob *job = new BD_BatchRenderJob(preferences, 0,0);
298 void BatchRenderThread::save_jobs(char *path)
301 file.tag.set_title("JOBS");
302 if (mwindow && mwindow->preferences->unsafe_gui)
303 file.tag.set_property("WARN", warn);
305 file.append_newline();
307 for( int i = 0; i < jobs.total; i++ ) {
308 file.tag.set_title(jobs[i]->tag);
309 jobs[i]->save(&file);
311 file.tag.set_title("/JOBS");
313 file.append_newline();
315 if( !path ) path = batch_path;
316 if( !path[0] ) create_path(path);
317 file.write_to_file(path);
320 void BatchRenderThread::load_defaults(BC_Hash *defaults)
323 default_job->asset->load_defaults(defaults,
324 "BATCHRENDER_", 1, 1, 1, 1, 1);
327 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
328 char string[BCTEXTLEN];
329 sprintf(string, "BATCHRENDER_COLUMN%d", i);
330 list_width[i] = defaults->get(string, xS(column_widths[i]));
334 void BatchRenderThread::save_defaults(BC_Hash *defaults)
337 default_job->asset->save_defaults(defaults,
338 "BATCHRENDER_", 1, 1, 1, 1, 1);
340 for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
341 char string[BCTEXTLEN];
342 sprintf(string, "BATCHRENDER_COLUMN%d", i);
343 defaults->update(string, list_width[i]);
345 // defaults->update("BATCHRENDER_JOB", current_job);
347 mwindow->save_defaults();
352 char* BatchRenderThread::create_path(char *string)
355 sprintf(string, "%s/", File::get_config_path());
356 fs.complete_path(string);
357 strcat(string, BATCH_PATH);
361 void BatchRenderThread::new_job()
363 BatchRenderJob *result = get_current_job()->copy();
365 current_job = jobs.total - 1;
370 void BatchRenderThread::delete_job()
372 if( current_job < jobs.total && current_job >= 0 ) {
373 jobs.remove_object_number(current_job);
374 if( current_job > 0 ) current_job--;
380 void BatchRenderThread::use_current_edl()
382 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
384 // mwindow->edl->path,
385 // mwindow->edl->path);
387 strcpy(get_current_edl(), mwindow->edl->path);
389 gui->edl_path_text->update(get_current_edl());
392 void BatchRenderThread::update_selected_edl()
395 char *path = get_current_edl();
396 EDL *edl = mwindow->edl;
397 // result = 1 if user cancelled operation
398 int result = ConfirmSave::test_file(mwindow, path);
400 edl->save_xml(&xml_file, path);
401 xml_file.terminate_string();
402 if( xml_file.write_to_file(path) ) {
404 sprintf(msg, _("Unable to save: %s"), path);
405 MainError::show_error(msg);
410 BatchRenderJob* BatchRenderThread::get_current_job()
412 return current_job >= 0 && current_job < jobs.total ?
413 jobs.values[current_job] : default_job;
417 Asset* BatchRenderThread::get_current_asset()
419 return get_current_job()->asset;
422 char* BatchRenderThread::get_current_edl()
424 return get_current_job()->edl_path;
427 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
429 int count = err_jobs.size();
430 if( !count ) return 0;
431 fprintf(stderr, msg, count);
432 char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
433 sp += snprintf(sp,ep-sp, msg,count);
434 for( int i=0; i<count; ++i ) {
435 int no = err_jobs[i].no;
436 const char *path = err_jobs[i].path;
437 fprintf(stderr, "%d: %s\n", no, path);
438 sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
440 sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
441 mwindow->show_warning(warn, string);
442 if( mwindow->wait_warning() ) {
443 gui->button_enable();
448 // Test EDL files for existence
449 int BatchRenderThread::test_edl_files()
452 const char *path = 0;
453 BatchRenderWarnJobs not_equiv;
454 BatchRenderWarnJobs empty_jobs;
455 BatchRenderWarnJobs no_labels;
456 BatchRenderWarnJobs no_rendering;
458 for( int i=0; !ret && i<jobs.size(); ++i ) {
459 if( !jobs.values[i]->enabled ) continue;
460 path = jobs[i]->edl_path;
461 int is_script = *path == '@' ? 1 : 0;
462 if( is_script ) ++path;
463 FILE *fp = fopen(path, "r");
465 if( mwindow && !is_script ) {
466 char *bfr = 0; size_t sz = 0;
468 if( !fstat(fileno(fp), &st) ) {
470 bfr = new char[sz+1];
471 if( fread(bfr, 1, sz+1, fp) != sz )
477 EDL *edl = new EDL; edl->create_objects();
478 XMLBuffer data(bfr, sz, 0);
480 file.set_shared_input(&data);
481 edl->load_xml(&file, LOAD_ALL); }
482 double pos = edl->equivalent_output(mwindow->edl);
484 not_equiv.add(i+1, path);
485 double length = edl->tracks->total_playable_length();
486 double start = edl->local_session->get_selectionstart(1);
487 if( start >= length )
488 empty_jobs.add(i+1, path);
489 if( jobs[i]->labeled && !edl->labels->first)
490 no_labels.add(i+1,path);
491 Asset *asset = jobs[i]->asset;
492 if( !asset->audio_data && !asset->video_data )
493 no_rendering.add(i+1,path);
505 char string[BCTEXTLEN];
506 sprintf(string, _("EDL %s not found.\n"), path);
508 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
509 mwindow->gui->get_abs_cursor_x(1),
510 mwindow->gui->get_abs_cursor_y(1));
511 error_box.create_objects(string);
512 error_box.run_window();
513 gui->button_enable();
516 fprintf(stderr, "%s", string);
522 if( !ret && warn && mwindow ) {
523 ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
524 if( !warn ) gui->warning->update(0);
526 if( !ret && mwindow )
527 ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
528 if( !ret && mwindow )
529 ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
530 if( !ret && mwindow )
531 ret = test_errmsg(no_labels, _("%d job EDLs Create new file at labels checked, but no labels\n"), 0);
537 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
538 Preferences *preferences)
540 for( int i = 0; i < jobs.total; i++ ) {
541 BatchRenderJob *job = jobs.values[i];
542 if( job->enabled && *job->edl_path != '@' ) {
543 PackageDispatcher *packages = new PackageDispatcher;
546 TransportCommand *command = new TransportCommand(preferences);
547 FileXML *file = new FileXML;
548 file->read_from_file(job->edl_path);
550 // Use command to calculate range.
551 command->command = NORMAL_FWD;
552 command->get_edl()->load_xml(file,
554 command->change_type = CHANGE_ALL;
555 command->set_playback_range();
556 command->playback_range_adjust_inout();
558 // Create test packages
559 int result = packages->create_packages(mwindow, command->get_edl(),
560 preferences, job->get_strategy(), job->asset,
561 command->start_position, command->end_position, 0);
563 packages->get_package_paths(paths);
565 // Append output paths allocated to total
567 // Delete package harness
576 void BatchRenderThread::start_rendering(char *config_path,
579 BC_Hash *boot_defaults;
580 Preferences *preferences;
582 BC_Signals *signals = new BC_Signals;
583 // XXX the above stuff is leaked,
585 // Initialize stuff which MWindow does.
586 signals->initialize("/tmp/cinelerra_batch%d.dmp");
588 MWindow::init_defaults(boot_defaults, config_path);
589 load_defaults(boot_defaults);
590 preferences = new Preferences;
591 preferences->load_defaults(boot_defaults);
592 BC_Signals::set_trap_hook(trap_hook, this);
593 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
594 BC_Signals::set_catch_intr(0);
595 if( preferences->trap_sigsegv ) {
596 BC_Trace::enable_locks();
599 BC_Trace::disable_locks();
601 // In batch mode there is no mwindow, so init_plugins is called with
603 MWindow::init_plugins(0, preferences);
604 MWindow::init_ladspa_plugins(0, preferences);
605 char font_path[BCTEXTLEN];
606 strcpy(font_path, preferences->plugin_dir);
607 strcat(font_path, "/" FONT_SEARCHPATH);
608 BC_Resources::init_fontconfig(font_path);
609 BC_WindowBase::get_resources()->vframe_shm = 1;
612 strcpy(this->batch_path, batch_path);
613 load_jobs(batch_path, preferences);
614 save_jobs(batch_path);
615 save_defaults(boot_defaults);
618 // Test EDL files for existence
619 if( test_edl_files() ) return;
623 // Predict all destination paths
624 ArrayList<char*> paths;
625 paths.set_array_delete();
626 calculate_dest_paths(&paths, preferences);
629 int result = ConfirmSave::test_files(0, &paths);
630 paths.remove_all_objects();
631 // Abort on any existing file because it's so hard to set this up.
635 render = new Render(0);
637 render->start_batches(&jobs, boot_defaults, preferences);
641 void BatchRenderThread::start_rendering()
643 if( is_rendering ) return;
646 save_jobs(batch_path);
647 save_defaults(mwindow->defaults);
648 gui->button_disable();
650 // Test EDL files for existence
651 if( test_edl_files() ) return;
653 // Predict all destination paths
654 ArrayList<char*> paths;
655 calculate_dest_paths(&paths,
656 mwindow->preferences);
658 // Test destination files for overwrite
659 int result = ConfirmSave::test_files(mwindow, &paths);
660 paths.remove_all_objects();
665 gui->button_enable();
669 mwindow->render->start_batches(&jobs);
672 void BatchRenderThread::stop_rendering()
674 if( !is_rendering ) return;
675 mwindow->render->stop_operation();
679 void BatchRenderThread::update_active(int number)
681 gui->lock_window("BatchRenderThread::update_active");
683 current_job = number;
684 rendering_job = number;
691 gui->unlock_window();
694 void BatchRenderThread::update_done(int number,
698 gui->lock_window("BatchRenderThread::update_done");
700 gui->button_enable();
703 jobs.values[number]->enabled = 0;
704 jobs.values[number]->elapsed = elapsed_time;
705 if( create_list ) gui->create_list(1);
707 gui->unlock_window();
710 void BatchRenderThread::move_batch(int src, int dst)
712 BatchRenderJob *src_job = jobs.values[src];
713 if( dst < 0 ) dst = jobs.total - 1;
716 for( int i = src; i < jobs.total - 1; i++ )
717 jobs.values[i] = jobs.values[i + 1];
718 // if( dst > src ) dst--;
719 for( int i = jobs.total - 1; i > dst; i-- )
720 jobs.values[i] = jobs.values[i - 1];
721 jobs.values[dst] = src_job;
726 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
728 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
729 fprintf(fp, "\nEDL:\n");
730 mwindow->dump_edl(fp);
731 fprintf(fp, "\nUNDO:\n");
732 mwindow->dump_undo(fp);
733 fprintf(fp, "\nEXE:\n");
734 mwindow->dump_exe(fp);
741 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
742 BatchRenderThread *thread, int x, int y, int w, int h)
743 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
744 x, y, w, h, xS(730), yS(400), 1, 0, 1)
746 this->mwindow = mwindow;
747 this->thread = thread;
749 // *** CONTEXT_HELP ***
750 context_help_set_keyword("Batch Rendering");
753 BatchRenderGUI::~BatchRenderGUI()
755 lock_window("BatchRenderGUI::~BatchRenderGUI");
756 loadlist_batch->stop();
757 savelist_batch->stop();
763 void BatchRenderGUI::create_objects()
765 int xs10 = xS(10), xs30 = xS(30), xs40 = xS(40);
766 int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15);
767 lock_window("BatchRenderGUI::create_objects");
768 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
771 int x = mwindow->theme->batchrender_x1;
773 int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
774 int y1 = ys5, y2 = ys5;
777 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
778 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
780 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
781 format_tools->set_w(x2 - xs40);
782 BatchRenderJob *current_job = thread->get_current_job();
783 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
784 thread->do_labeled ? ¤t_job->labeled : 0, 0);
785 if( thread->do_labeled < 0 )
786 format_tools->labeled_files->disable();
787 if( thread->do_farmed ) {
788 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
789 ¤t_job->farmed);
790 add_subwindow(use_renderfarm);
791 y1 += use_renderfarm->get_h() + ys10;
792 if( thread->do_farmed < 0 )
793 use_renderfarm->disable();
797 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
798 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
801 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
802 x, y, get_w()-x - xs40, thread->get_current_edl()));
803 x = x2 + edl_path_text->get_w();
804 add_subwindow(edl_path_browse = new BrowseButton(
805 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
806 _("Input EDL"), _("Select an EDL to load:"), 0));
807 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
810 if (mwindow->preferences->unsafe_gui) {
811 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
812 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
814 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
815 y += use_current_edl->get_h() + mwindow->theme->widget_border;
816 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
817 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
818 x += new_batch->get_w() + mwindow->theme->widget_border;
819 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
820 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
821 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
822 x += savelist_batch->get_w() + mwindow->theme->widget_border;
823 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
824 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
825 if (mwindow->preferences->unsafe_gui) {
826 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
827 y2 = y + warning->get_h() + mwindow->theme->widget_border;
829 if( y2 > y1 ) y1 = y2;
830 x = mwindow->theme->batchrender_x1, y = y1;
832 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
833 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
834 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
835 y += list_title->get_h() + mwindow->theme->widget_border;
837 y1 -= ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
838 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
839 get_w() - x - xs10, y1 - y));
840 y += batch_list->get_h() + mwindow->theme->widget_border;
842 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
843 x = get_w() / 3 - BC_GenericButton::calculate_w(this, _("Stop")) / 3;
844 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
845 x = get_w() / 1.5 - BC_GenericButton::calculate_w(this, _("?")) / 1.5;
846 add_subwindow(help_button = new BatchRenderHelp(thread, x, y));
847 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - xs10;
848 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
854 void BatchRenderGUI::button_disable()
856 new_batch->disable();
857 delete_batch->disable();
858 use_current_edl->disable();
859 if (mwindow->preferences->unsafe_gui)
860 update_selected_edl->disable();
863 void BatchRenderGUI::button_enable()
866 delete_batch->enable();
867 if( mwindow->edl && mwindow->edl->path[0] )
868 use_current_edl->enable();
869 if (mwindow->preferences->unsafe_gui)
870 update_selected_edl->enable();
873 int BatchRenderGUI::resize_event(int w, int h)
875 int xs10 = xS(10), xs40 = xS(40);
876 int ys5 = yS(5), ys15 = yS(15);
877 mwindow->session->batchrender_w = w;
878 mwindow->session->batchrender_h = h;
879 mwindow->theme->get_batchrender_sizes(this, w, h);
881 int x = mwindow->theme->batchrender_x1;
883 int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
884 int y1 = ys5, y2 = ys5;
887 output_path_title->reposition_window(x1, y1);
888 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
889 format_tools->reposition_window(x1, y1);
890 if( thread->do_farmed )
891 use_renderfarm->reposition_window(x1, y1);
894 edl_path_title->reposition_window(x, y);
895 y += edl_path_title->get_h() + mwindow->theme->widget_border;
896 edl_path_text->reposition_window(x, y, w - x - xs40);
897 x += edl_path_text->get_w();
898 edl_path_browse->reposition_window(x, y);
899 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
902 if (mwindow->preferences->unsafe_gui) {
903 update_selected_edl->reposition_window(x, y);
904 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
906 use_current_edl->reposition_window(x, y);
907 y += use_current_edl->get_h() + mwindow->theme->widget_border;
908 new_batch->reposition_window(x, y);
909 x += new_batch->get_w() + mwindow->theme->widget_border;
910 delete_batch->reposition_window(x, y);
912 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
913 savelist_batch->reposition_window(x, y);
914 x += savelist_batch->get_w() + mwindow->theme->widget_border;
915 loadlist_batch->reposition_window(x, y);
916 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
917 if (mwindow->preferences->unsafe_gui) {
918 warning->reposition_window(x2, y);
920 y1 = ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
921 y2 = get_h() - y1 - batch_list->get_h();
922 y2 -= list_title->get_h() + mwindow->theme->widget_border;
924 x = mwindow->theme->batchrender_x1; y = y2;
925 list_title->reposition_window(x, y);
926 y += list_title->get_h() + mwindow->theme->widget_border;
927 batch_list->reposition_window(x, y, w - x - xs10, h - y - y1);
928 y += batch_list->get_h() + mwindow->theme->widget_border;
930 start_button->reposition_window(x, y);
931 x = w / 3 - stop_button->get_w() / 3;
932 stop_button->reposition_window(x, y);
933 x = w - cancel_button->get_w() - xs10;
934 cancel_button->reposition_window(x, y);
935 x = w / 1.5 - help_button->get_w() / 1.5;
936 help_button->reposition_window(x, y);
940 int BatchRenderGUI::translation_event()
942 mwindow->session->batchrender_x = get_x();
943 mwindow->session->batchrender_y = get_y();
947 int BatchRenderGUI::close_event()
949 // Stop batch rendering
951 thread->stop_rendering();
952 lock_window("BatchRenderGUI::close_event");
957 void BatchRenderGUI::create_list(int update_widget)
959 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
960 list_items[i].remove_all_objects();
963 const char **column_titles = BatchRenderThread::column_titles;
965 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
966 list_width[list_columns++] = thread->list_width[ENABLED_COL];
967 if( thread->do_labeled > 0 ) {
968 list_titles[list_columns] = _(column_titles[LABELED_COL]);
969 list_width[list_columns++] = thread->list_width[LABELED_COL];
971 if( thread->do_farmed > 0 ) {
972 list_titles[list_columns] = _(column_titles[FARMED_COL]);
973 list_width[list_columns++] = thread->list_width[FARMED_COL];
975 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
976 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
977 list_titles[list_columns] = _(column_titles[EDL_COL]);
978 list_width[list_columns++] = thread->list_width[EDL_COL];
979 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
980 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
982 for( int i = 0; i < thread->jobs.total; i++ ) {
983 BatchRenderJob *job = thread->jobs.values[i];
984 char string[BCTEXTLEN];
985 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
986 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
987 new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
988 BC_ListBoxItem *farmed = thread->do_farmed > 0 ?
989 new BC_ListBoxItem(job->farmed ? "X" : " ") : 0;
990 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
991 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
992 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
993 Units::totext(string, job->elapsed, TIME_HMS2));
995 list_items[col++].append(enabled);
996 if( labeled ) list_items[col++].append(labeled);
997 if( farmed ) list_items[col++].append(farmed);
998 list_items[col++].append(out_path);
999 list_items[col++].append(edl_path);
1000 list_items[col].append(elapsed);
1001 if( i == thread->current_job ) {
1002 enabled->set_selected(1);
1003 if( labeled ) labeled->set_selected(1);
1004 if( farmed ) farmed->set_selected(1);
1005 out_path->set_selected(1);
1006 edl_path->set_selected(1);
1007 elapsed->set_selected(1);
1009 if( i == thread->rendering_job ) {
1010 enabled->set_color(RED);
1011 if( labeled ) labeled->set_color(RED);
1012 if( farmed ) farmed->set_color(RED);
1013 out_path->set_color(RED);
1014 edl_path->set_color(RED);
1015 elapsed->set_color(RED);
1019 if( update_widget ) {
1020 batch_list->update(list_items, list_titles, list_width, list_columns,
1021 batch_list->get_xposition(), batch_list->get_yposition(),
1022 batch_list->get_highlighted_item(), 1, 1);
1026 void BatchRenderGUI::change_job()
1028 BatchRenderJob *job = thread->get_current_job();
1029 format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
1030 if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
1031 edl_path_text->update(job->edl_path);
1035 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1036 : FormatTools(mwindow, gui, asset)
1039 this->mwindow = mwindow;
1042 BatchFormat::~BatchFormat()
1047 int BatchFormat::handle_event()
1049 gui->create_list(1);
1053 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1054 int x, int y, int w, char *text)
1055 : BC_TextBox(x, y, w, 1, text)
1057 this->thread = thread;
1061 int BatchRenderEDLPath::handle_event()
1063 calculate_suggestions();
1064 strcpy(thread->get_current_edl(), get_text());
1065 thread->gui->create_list(1);
1069 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1072 : BC_GenericButton(x, y, _("New"))
1074 this->thread = thread;
1075 set_tooltip(_("Create a new batch"));
1078 int BatchRenderNew::handle_event()
1084 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1085 : BC_GenericButton(x, y, _("Delete"))
1087 this->thread = thread;
1088 set_tooltip(_("Delete loaded (highlighted) batch"));
1091 int BatchRenderDelete::handle_event()
1093 thread->delete_job();
1099 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1100 : BC_GenericButton(x, y, _("Save Jobs"))
1102 this->thread = thread;
1103 set_tooltip(_("Save a Batch Render List"));
1105 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1108 BatchRenderSaveList::~BatchRenderSaveList()
1111 delete startup_lock;
1114 void BatchRenderSaveList::stop()
1116 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1117 if( gui ) gui->set_done(1);
1118 startup_lock->unlock();
1122 int BatchRenderSaveList::handle_event()
1124 if( Thread::running() ) {
1127 gui->raise_window();
1128 gui->unlock_window();
1132 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1134 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1135 startup_lock->unlock();
1139 void BatchRenderSaveList::run()
1141 char default_path[BCTEXTLEN];
1142 sprintf(default_path, "~");
1143 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1144 BC_FileBox filewindow(xS(100), yS(100), default_path,
1145 _("Save Batch Render List"),
1146 _("Enter a Batch Render filename to save as:"),
1150 startup_lock->unlock();
1151 filewindow.create_objects();
1153 int result2 = filewindow.run_window();
1155 strcpy(thread->batch_path, filewindow.get_submitted_path());
1156 thread->gui->lock_window("BatchRenderSaveList::run");
1157 thread->gui->batch_path->update(thread->batch_path);
1158 thread->gui->unlock_window();
1159 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1160 thread->save_jobs(thread->batch_path);
1163 startup_lock->lock("BatchRenderLoadList::run");
1165 startup_lock->unlock();
1168 int BatchRenderSaveList::keypress_event() {
1169 if( get_keypress() == 's' ||
1170 get_keypress() == 'S' ) return handle_event();
1171 return context_help_check_and_show();
1175 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1178 : BC_GenericButton(x, y, _("Load Jobs")),
1181 this->thread = thread;
1182 set_tooltip(_("Load a previously saved Batch Render List"));
1184 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1187 BatchRenderLoadList::~BatchRenderLoadList()
1190 delete startup_lock;
1193 void BatchRenderLoadList::stop()
1195 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1196 if( gui ) gui->set_done(1);
1197 startup_lock->unlock();
1201 int BatchRenderLoadList::handle_event()
1203 if( Thread::running() ) {
1206 gui->raise_window();
1207 gui->unlock_window();
1211 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1213 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1214 startup_lock->unlock();
1218 void BatchRenderLoadList::run()
1220 char default_path[BCTEXTLEN];
1221 sprintf(default_path, "~");
1222 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1223 BC_FileBox filewindow(xS(100), yS(100), default_path, _("Load Batch Render List"),
1224 _("Enter a Batch Render filename to load from:"),
1228 startup_lock->unlock();
1229 filewindow.create_objects();
1231 int result2 = filewindow.run_window();
1233 thread->gui->lock_window("BatchRenderLoadList::run");
1234 strcpy(thread->batch_path, filewindow.get_submitted_path());
1235 thread->gui->batch_path->update(thread->batch_path);
1236 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1237 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1238 thread->gui->create_list(1);
1239 thread->current_job = 0;
1240 thread->gui->change_job();
1241 thread->gui->unlock_window();
1244 startup_lock->lock("BatchRenderLoadList::run");
1246 startup_lock->unlock();
1249 int BatchRenderLoadList::keypress_event() {
1250 if( get_keypress() == 'o' ||
1251 get_keypress() == 'O' ) return handle_event();
1252 return context_help_check_and_show();
1255 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1258 : BC_GenericButton(x, y, _("Use Current EDL"))
1260 this->thread = thread;
1261 set_tooltip(_("Replaces highlighted batch job with session currently on timeline. File on disk NOT changed!"));
1264 int BatchRenderCurrentEDL::handle_event()
1266 thread->use_current_edl();
1270 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1273 : BC_GenericButton(x, y, _("Save to EDL Path"))
1275 this->thread = thread;
1276 set_tooltip(_("WARNING - saves to loaded (highlighted) EDL, *overwrites* highlighted project!"));
1279 int BatchRenderUpdateEDL::handle_event()
1281 thread->update_selected_edl();
1286 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1287 int x, int y, int w, int h)
1288 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1289 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1290 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1292 this->thread = thread;
1294 set_process_drag(0);
1297 int BatchRenderList::handle_event()
1302 int BatchRenderList::selection_changed()
1304 thread->current_job = get_selection_number(0, 0);
1305 thread->gui->change_job();
1306 int cursor_x = get_cursor_x();
1307 BatchRenderJob *job = thread->get_current_job();
1308 int col_x = 0, changed = 1;
1309 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1310 job->enabled = !job->enabled;
1311 else if( thread->do_labeled > 0 &&
1312 cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1313 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1314 else if( thread->do_farmed > 0 &&
1315 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1316 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1320 thread->gui->create_list(1);
1321 thread->gui->change_job();
1326 int BatchRenderList::column_resize_event()
1329 thread->list_width[ENABLED_COL] = get_column_width(col++);
1330 if( thread->do_labeled > 0 )
1331 thread->list_width[LABELED_COL] = get_column_width(col++);
1332 if( thread->do_farmed > 0 )
1333 thread->list_width[FARMED_COL] = get_column_width(col++);
1334 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1335 thread->list_width[EDL_COL] = get_column_width(col++);
1336 thread->list_width[ELAPSED_COL] = get_column_width(col);
1340 int BatchRenderList::drag_start_event()
1342 if( BC_ListBox::drag_start_event() ) {
1350 int BatchRenderList::drag_motion_event()
1352 if( BC_ListBox::drag_motion_event() ) {
1358 int BatchRenderList::drag_stop_event()
1360 if( dragging_item ) {
1361 int src = get_selection_number(0, 0);
1362 int dst = get_highlighted_item();
1364 thread->move_batch(src, dst);
1366 BC_ListBox::drag_stop_event();
1374 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1375 : BC_GenericButton(x, y, _("Start"))
1377 this->thread = thread;
1378 set_tooltip(_("Start batch rendering"));
1381 int BatchRenderStart::handle_event()
1383 thread->start_rendering();
1387 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1388 : BC_GenericButton(x, y, _("Stop"))
1390 this->thread = thread;
1391 set_tooltip(_("Stops currently active batch rendering"));
1394 int BatchRenderStop::handle_event()
1397 thread->stop_rendering();
1398 lock_window("BatchRenderStop::handle_event");
1403 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1404 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1406 this->thread = thread;
1407 set_tooltip(_("Prevents rendering if loaded session and batch job(s) differ"));
1410 int BatchRenderWarning::handle_event()
1412 thread->warn = get_value();
1416 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1417 : BC_GenericButton(x, y, _("Close"))
1419 this->thread = thread;
1420 set_tooltip(_("Closes this window"));
1423 int BatchRenderCancel::handle_event()
1426 thread->stop_rendering();
1427 lock_window("BatchRenderCancel::handle_event");
1428 thread->gui->set_done(1);
1432 int BatchRenderCancel::keypress_event()
1434 if( get_keypress() == ESC ) {
1436 thread->stop_rendering();
1437 lock_window("BatchRenderCancel::keypress_event");
1438 thread->gui->set_done(1);
1441 return context_help_check_and_show();
1445 BatchRenderHelp::BatchRenderHelp(BatchRenderThread *thread, int x, int y)
1446 : BC_GenericButton(x, y, _("?"))
1448 this->thread = thread;
1449 set_tooltip(_("Open quick start guide in default browser"));
1452 int BatchRenderHelp::handle_event()
1454 system("xdg-open file://$CIN_DAT/doc/help_br_index.html");
1458 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1459 : BC_CheckBox(x, y, *output, _("Use render farm"))
1461 this->thread = thread;
1462 this->output = output;
1465 int BatchRenderUseFarm::handle_event()
1467 *output = get_value();
1468 thread->gui->create_list(1);
1472 void BatchRenderUseFarm::update(int *output)
1474 this->output = output;
1475 BC_CheckBox::update(*output);