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)
124 char job_title[BCSTRLEN];
125 strcpy(job_title, file->tag.title);
127 enabled = file->tag.get_property("ENABLED", enabled);
128 farmed = file->tag.get_property("FARMED", farmed);
129 labeled = file->tag.get_property("LABELED", labeled);
131 file->tag.get_property("EDL_PATH", edl_path);
132 elapsed = file->tag.get_property("ELAPSED", elapsed);
134 result = file->read_tag();
136 if( file->tag.title_is("ASSET") ) {
137 file->tag.get_property("SRC", asset->path);
138 asset->read(file, 0);
139 // The compression parameters are stored in the defaults to reduce
140 // coding maintenance. The defaults must now be stuffed into the XML for
143 defaults.load_string(file->read_text(job_title));
144 asset->load_defaults(&defaults,
150 void BatchRenderJob::save(FileXML *file)
152 char end_tag[BCSTRLEN]; end_tag[0] = '/';
153 strcpy(&end_tag[1], file->tag.get_title());
154 file->tag.set_property("ENABLED", enabled);
155 file->tag.set_property("FARMED", farmed);
156 file->tag.set_property("LABELED", labeled);
157 file->tag.set_property("EDL_PATH", edl_path);
158 file->tag.set_property("ELAPSED", elapsed);
160 file->append_newline();
161 asset->write(file, 0, "");
163 // The compression parameters are stored in the defaults to reduce
164 // coding maintenance. The defaults must now be stuffed into the XML for
167 asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
169 defaults.save_string(string);
170 file->append_text(string);
172 file->tag.set_title(end_tag);
174 file->append_newline();
177 char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
182 int BatchRenderJob::get_strategy()
184 int range = File::is_image_render(asset->format) ?
185 RANGE_1FRAME : RANGE_SELECTION;
186 return Render::get_strategy(farmed, labeled, range);
190 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
193 this->mwindow = mwindow;
207 BatchRenderThread::~BatchRenderThread()
210 delete boot_defaults;
216 void BatchRenderThread::reset(const char *path)
219 strcpy(batch_path, path);
224 delete default_job; default_job = 0;
225 jobs.remove_all_objects();
228 void BatchRenderThread::start(int do_farmed, int do_labeled)
230 this->do_farmed = do_farmed;
231 this->do_labeled = do_labeled;
232 BC_DialogThread::start();
235 void BatchRenderThread::handle_close_event(int result)
238 save_jobs(batch_path);
239 save_defaults(mwindow->defaults);
243 BC_Window* BatchRenderThread::new_gui()
247 default_job = new BatchRenderJob(mwindow->preferences, 0, -1);
248 load_jobs(batch_path, mwindow->preferences);
249 load_defaults(mwindow->defaults);
250 this->gui = new BatchRenderGUI(mwindow, this,
251 mwindow->session->batchrender_x, mwindow->session->batchrender_y,
252 mwindow->session->batchrender_w, mwindow->session->batchrender_h);
253 this->gui->create_objects();
258 void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
263 jobs.remove_all_objects();
264 if( !path ) path = batch_path;
265 if( !path[0] ) create_path(path);
266 file.read_from_file(path);
269 if( !(result = file.read_tag()) ) {
270 if( file.tag.title_is("JOBS") ) {
271 if (mwindow->preferences->unsafe_gui)
272 warn = file.tag.get_property("WARN", 1);
273 if (!mwindow->preferences->unsafe_gui)
276 else if( file.tag.title_is("JOB") ) {
277 BatchRenderJob *job = new BatchRenderJob(preferences, 0,0);
281 else if( file.tag.title_is("DVD_JOB") ) {
282 DVD_BatchRenderJob *job = new DVD_BatchRenderJob(preferences, 0,0,0,0);
286 else if( file.tag.title_is("BD_JOB") ) {
287 BD_BatchRenderJob *job = new BD_BatchRenderJob(preferences, 0,0);
295 void BatchRenderThread::save_jobs(char *path)
298 file.tag.set_title("JOBS");
299 if (mwindow->preferences->unsafe_gui)
300 file.tag.set_property("WARN", warn);
302 file.append_newline();
304 for( int i = 0; i < jobs.total; i++ ) {
305 file.tag.set_title(jobs[i]->tag);
306 jobs[i]->save(&file);
308 file.tag.set_title("/JOBS");
310 file.append_newline();
312 if( !path ) path = batch_path;
313 if( !path[0] ) create_path(path);
314 file.write_to_file(path);
317 void BatchRenderThread::load_defaults(BC_Hash *defaults)
320 default_job->asset->load_defaults(defaults,
321 "BATCHRENDER_", 1, 1, 1, 1, 1);
324 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
325 char string[BCTEXTLEN];
326 sprintf(string, "BATCHRENDER_COLUMN%d", i);
327 list_width[i] = defaults->get(string, xS(column_widths[i]));
331 void BatchRenderThread::save_defaults(BC_Hash *defaults)
334 default_job->asset->save_defaults(defaults,
335 "BATCHRENDER_", 1, 1, 1, 1, 1);
337 for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
338 char string[BCTEXTLEN];
339 sprintf(string, "BATCHRENDER_COLUMN%d", i);
340 defaults->update(string, list_width[i]);
342 // defaults->update("BATCHRENDER_JOB", current_job);
344 mwindow->save_defaults();
349 char* BatchRenderThread::create_path(char *string)
352 sprintf(string, "%s/", File::get_config_path());
353 fs.complete_path(string);
354 strcat(string, BATCH_PATH);
358 void BatchRenderThread::new_job()
360 BatchRenderJob *result = get_current_job()->copy();
362 current_job = jobs.total - 1;
367 void BatchRenderThread::delete_job()
369 if( current_job < jobs.total && current_job >= 0 ) {
370 jobs.remove_object_number(current_job);
371 if( current_job > 0 ) current_job--;
377 void BatchRenderThread::use_current_edl()
379 // printf("BatchRenderThread::use_current_edl %d %p %s\n",
381 // mwindow->edl->path,
382 // mwindow->edl->path);
384 strcpy(get_current_edl(), mwindow->edl->path);
386 gui->edl_path_text->update(get_current_edl());
389 void BatchRenderThread::update_selected_edl()
392 char *path = get_current_edl();
393 EDL *edl = mwindow->edl;
394 // result = 1 if user cancelled operation
395 int result = ConfirmSave::test_file(mwindow, path);
397 edl->save_xml(&xml_file, path);
398 xml_file.terminate_string();
399 if( xml_file.write_to_file(path) ) {
401 sprintf(msg, _("Unable to save: %s"), path);
402 MainError::show_error(msg);
407 BatchRenderJob* BatchRenderThread::get_current_job()
409 return current_job >= 0 && current_job < jobs.total ?
410 jobs.values[current_job] : default_job;
414 Asset* BatchRenderThread::get_current_asset()
416 return get_current_job()->asset;
419 char* BatchRenderThread::get_current_edl()
421 return get_current_job()->edl_path;
424 int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
426 int count = err_jobs.size();
427 if( !count ) return 0;
428 fprintf(stderr, msg, count);
429 char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
430 sp += snprintf(sp,ep-sp, msg,count);
431 for( int i=0; i<count; ++i ) {
432 int no = err_jobs[i].no;
433 const char *path = err_jobs[i].path;
434 fprintf(stderr, "%d: %s\n", no, path);
435 sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
437 sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
438 mwindow->show_warning(warn, string);
439 if( mwindow->wait_warning() ) {
440 gui->button_enable();
445 // Test EDL files for existence
446 int BatchRenderThread::test_edl_files()
449 const char *path = 0;
450 BatchRenderWarnJobs not_equiv;
451 BatchRenderWarnJobs empty_jobs;
452 BatchRenderWarnJobs no_labels;
453 BatchRenderWarnJobs no_rendering;
455 for( int i=0; !ret && i<jobs.size(); ++i ) {
456 if( !jobs.values[i]->enabled ) continue;
457 path = jobs[i]->edl_path;
458 int is_script = *path == '@' ? 1 : 0;
459 if( is_script ) ++path;
460 FILE *fp = fopen(path, "r");
462 if( mwindow && !is_script ) {
463 char *bfr = 0; size_t sz = 0;
465 if( !fstat(fileno(fp), &st) ) {
467 bfr = new char[sz+1];
468 if( fread(bfr, 1, sz+1, fp) != sz )
474 EDL *edl = new EDL; edl->create_objects();
475 XMLBuffer data(bfr, sz, 0);
477 file.set_shared_input(&data);
478 edl->load_xml(&file, LOAD_ALL); }
479 double pos = edl->equivalent_output(mwindow->edl);
481 not_equiv.add(i+1, path);
482 double length = edl->tracks->total_playable_length();
483 double start = edl->local_session->get_selectionstart(1);
484 if( start >= length )
485 empty_jobs.add(i+1, path);
486 if( jobs[i]->labeled && !edl->labels->first)
487 no_labels.add(i+1,path);
488 Asset *asset = jobs[i]->asset;
489 if( !asset->audio_data && !asset->video_data )
490 no_rendering.add(i+1,path);
502 char string[BCTEXTLEN];
503 sprintf(string, _("EDL %s not found.\n"), path);
505 ErrorBox error_box(_(PROGRAM_NAME ": Error"),
506 mwindow->gui->get_abs_cursor_x(1),
507 mwindow->gui->get_abs_cursor_y(1));
508 error_box.create_objects(string);
509 error_box.run_window();
510 gui->button_enable();
513 fprintf(stderr, "%s", string);
519 if( !ret && warn && mwindow ) {
520 ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
521 if( !warn ) gui->warning->update(0);
523 if( !ret && mwindow )
524 ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
525 if( !ret && mwindow )
526 ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
527 if( !ret && mwindow )
528 ret = test_errmsg(no_labels, _("%d job EDLs Create new file at labels checked, but no labels\n"), 0);
534 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
535 Preferences *preferences)
537 for( int i = 0; i < jobs.total; i++ ) {
538 BatchRenderJob *job = jobs.values[i];
539 if( job->enabled && *job->edl_path != '@' ) {
540 PackageDispatcher *packages = new PackageDispatcher;
543 TransportCommand *command = new TransportCommand;
544 FileXML *file = new FileXML;
545 file->read_from_file(job->edl_path);
547 // Use command to calculate range.
548 command->command = NORMAL_FWD;
549 command->get_edl()->load_xml(file,
551 command->change_type = CHANGE_ALL;
552 command->set_playback_range();
553 command->playback_range_adjust_inout();
555 // Create test packages
556 int result = packages->create_packages(mwindow, command->get_edl(),
557 preferences, job->get_strategy(), job->asset,
558 command->start_position, command->end_position, 0);
560 packages->get_package_paths(paths);
562 // Append output paths allocated to total
564 // Delete package harness
573 void BatchRenderThread::start_rendering(char *config_path,
576 BC_Hash *boot_defaults;
577 Preferences *preferences;
579 BC_Signals *signals = new BC_Signals;
580 // XXX the above stuff is leaked,
582 // Initialize stuff which MWindow does.
583 signals->initialize("/tmp/cinelerra_batch%d.dmp");
585 MWindow::init_defaults(boot_defaults, config_path);
586 load_defaults(boot_defaults);
587 preferences = new Preferences;
588 preferences->load_defaults(boot_defaults);
589 BC_Signals::set_trap_hook(trap_hook, this);
590 BC_Signals::set_catch_segv(preferences->trap_sigsegv);
591 BC_Signals::set_catch_intr(0);
592 if( preferences->trap_sigsegv ) {
593 BC_Trace::enable_locks();
596 BC_Trace::disable_locks();
599 MWindow::init_plugins(0, preferences);
600 char font_path[BCTEXTLEN];
601 strcpy(font_path, preferences->plugin_dir);
602 strcat(font_path, "/" FONT_SEARCHPATH);
603 BC_Resources::init_fontconfig(font_path);
604 BC_WindowBase::get_resources()->vframe_shm = 1;
607 strcpy(this->batch_path, batch_path);
608 load_jobs(batch_path, preferences);
609 save_jobs(batch_path);
610 save_defaults(boot_defaults);
613 // Test EDL files for existence
614 if( test_edl_files() ) return;
618 // Predict all destination paths
619 ArrayList<char*> paths;
620 paths.set_array_delete();
621 calculate_dest_paths(&paths, preferences);
624 int result = ConfirmSave::test_files(0, &paths);
625 paths.remove_all_objects();
626 // Abort on any existing file because it's so hard to set this up.
630 render = new Render(0);
632 render->start_batches(&jobs, boot_defaults, preferences);
636 void BatchRenderThread::start_rendering()
638 if( is_rendering ) return;
641 save_jobs(batch_path);
642 save_defaults(mwindow->defaults);
643 gui->button_disable();
645 // Test EDL files for existence
646 if( test_edl_files() ) return;
648 // Predict all destination paths
649 ArrayList<char*> paths;
650 calculate_dest_paths(&paths,
651 mwindow->preferences);
653 // Test destination files for overwrite
654 int result = ConfirmSave::test_files(mwindow, &paths);
655 paths.remove_all_objects();
660 gui->button_enable();
664 mwindow->render->start_batches(&jobs);
667 void BatchRenderThread::stop_rendering()
669 if( !is_rendering ) return;
670 mwindow->render->stop_operation();
674 void BatchRenderThread::update_active(int number)
676 gui->lock_window("BatchRenderThread::update_active");
678 current_job = number;
679 rendering_job = number;
686 gui->unlock_window();
689 void BatchRenderThread::update_done(int number,
693 gui->lock_window("BatchRenderThread::update_done");
695 gui->button_enable();
698 jobs.values[number]->enabled = 0;
699 jobs.values[number]->elapsed = elapsed_time;
700 if( create_list ) gui->create_list(1);
702 gui->unlock_window();
705 void BatchRenderThread::move_batch(int src, int dst)
707 BatchRenderJob *src_job = jobs.values[src];
708 if( dst < 0 ) dst = jobs.total - 1;
711 for( int i = src; i < jobs.total - 1; i++ )
712 jobs.values[i] = jobs.values[i + 1];
713 // if( dst > src ) dst--;
714 for( int i = jobs.total - 1; i > dst; i-- )
715 jobs.values[i] = jobs.values[i - 1];
716 jobs.values[dst] = src_job;
721 void BatchRenderThread::trap_hook(FILE *fp, void *vp)
723 MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
724 fprintf(fp, "\nEDL:\n");
725 mwindow->dump_edl(fp);
726 fprintf(fp, "\nUNDO:\n");
727 mwindow->dump_undo(fp);
728 fprintf(fp, "\nEXE:\n");
729 mwindow->dump_exe(fp);
736 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
737 BatchRenderThread *thread, int x, int y, int w, int h)
738 : BC_Window(_(PROGRAM_NAME ": Batch Render"),
739 x, y, w, h, xS(730), yS(400), 1, 0, 1)
741 this->mwindow = mwindow;
742 this->thread = thread;
746 BatchRenderGUI::~BatchRenderGUI()
748 lock_window("BatchRenderGUI::~BatchRenderGUI");
749 loadlist_batch->stop();
750 savelist_batch->stop();
756 void BatchRenderGUI::create_objects()
758 int xs10 = xS(10), xs30 = xS(30), xs40 = xS(40);
759 int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15);
760 lock_window("BatchRenderGUI::create_objects");
761 mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
764 int x = mwindow->theme->batchrender_x1;
766 int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
767 int y1 = ys5, y2 = ys5;
770 add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
771 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
773 format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
774 format_tools->set_w(x2 - xs40);
775 BatchRenderJob *current_job = thread->get_current_job();
776 format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
777 thread->do_labeled ? ¤t_job->labeled : 0, 0);
778 if( thread->do_labeled < 0 )
779 format_tools->labeled_files->disable();
780 if( thread->do_farmed ) {
781 use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
782 ¤t_job->farmed);
783 add_subwindow(use_renderfarm);
784 y1 += use_renderfarm->get_h() + ys10;
785 if( thread->do_farmed < 0 )
786 use_renderfarm->disable();
790 add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
791 y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
794 add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
795 x, y, get_w()-x - xs40, thread->get_current_edl()));
796 x = x2 + edl_path_text->get_w();
797 add_subwindow(edl_path_browse = new BrowseButton(
798 mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
799 _("Input EDL"), _("Select an EDL to load:"), 0));
800 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
803 if (mwindow->preferences->unsafe_gui) {
804 add_subwindow(update_selected_edl = new BatchRenderUpdateEDL(thread, x, y));
805 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
807 add_subwindow(use_current_edl = new BatchRenderCurrentEDL(thread, x, y));
808 y += use_current_edl->get_h() + mwindow->theme->widget_border;
809 if( !mwindow->edl || !mwindow->edl->path[0] ) use_current_edl->disable();
810 add_subwindow(new_batch = new BatchRenderNew(thread, x, y));
811 x += new_batch->get_w() + mwindow->theme->widget_border;
812 add_subwindow(delete_batch = new BatchRenderDelete(thread, x, y));
813 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
814 add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
815 x += savelist_batch->get_w() + mwindow->theme->widget_border;
816 add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
817 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
818 if (mwindow->preferences->unsafe_gui) {
819 add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
820 y2 = y + warning->get_h() + mwindow->theme->widget_border;
822 if( y2 > y1 ) y1 = y2;
823 x = mwindow->theme->batchrender_x1, y = y1;
825 add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
826 x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
827 add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
828 y += list_title->get_h() + mwindow->theme->widget_border;
830 y1 -= ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
831 add_subwindow(batch_list = new BatchRenderList(thread, x, y,
832 get_w() - x - xs10, y1 - y));
833 y += batch_list->get_h() + mwindow->theme->widget_border;
835 add_subwindow(start_button = new BatchRenderStart(thread, x, y));
836 x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
837 add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
838 x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - xs10;
839 add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
845 void BatchRenderGUI::button_disable()
847 new_batch->disable();
848 delete_batch->disable();
849 use_current_edl->disable();
850 if (mwindow->preferences->unsafe_gui)
851 update_selected_edl->disable();
854 void BatchRenderGUI::button_enable()
857 delete_batch->enable();
858 if( mwindow->edl && mwindow->edl->path[0] )
859 use_current_edl->enable();
860 if (mwindow->preferences->unsafe_gui)
861 update_selected_edl->enable();
864 int BatchRenderGUI::resize_event(int w, int h)
866 int xs10 = xS(10), xs40 = xS(40);
867 int ys5 = yS(5), ys15 = yS(15);
868 mwindow->session->batchrender_w = w;
869 mwindow->session->batchrender_h = h;
870 mwindow->theme->get_batchrender_sizes(this, w, h);
872 int x = mwindow->theme->batchrender_x1;
874 int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
875 int y1 = ys5, y2 = ys5;
878 output_path_title->reposition_window(x1, y1);
879 y1 += output_path_title->get_h() + mwindow->theme->widget_border;
880 format_tools->reposition_window(x1, y1);
881 if( thread->do_farmed )
882 use_renderfarm->reposition_window(x1, y1);
885 edl_path_title->reposition_window(x, y);
886 y += edl_path_title->get_h() + mwindow->theme->widget_border;
887 edl_path_text->reposition_window(x, y, w - x - xs40);
888 x += edl_path_text->get_w();
889 edl_path_browse->reposition_window(x, y);
890 y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
893 if (mwindow->preferences->unsafe_gui) {
894 update_selected_edl->reposition_window(x, y);
895 y += update_selected_edl->get_h() + mwindow->theme->widget_border;
897 use_current_edl->reposition_window(x, y);
898 y += use_current_edl->get_h() + mwindow->theme->widget_border;
899 new_batch->reposition_window(x, y);
900 x += new_batch->get_w() + mwindow->theme->widget_border;
901 delete_batch->reposition_window(x, y);
903 x = x2; y += delete_batch->get_h() + mwindow->theme->widget_border;
904 savelist_batch->reposition_window(x, y);
905 x += savelist_batch->get_w() + mwindow->theme->widget_border;
906 loadlist_batch->reposition_window(x, y);
907 y += loadlist_batch->get_h() + mwindow->theme->widget_border;
908 if (mwindow->preferences->unsafe_gui) {
909 warning->reposition_window(x2, y);
911 y1 = ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
912 y2 = get_h() - y1 - batch_list->get_h();
913 y2 -= list_title->get_h() + mwindow->theme->widget_border;
915 x = mwindow->theme->batchrender_x1; y = y2;
916 list_title->reposition_window(x, y);
917 y += list_title->get_h() + mwindow->theme->widget_border;
918 batch_list->reposition_window(x, y, w - x - xs10, h - y - y1);
919 y += batch_list->get_h() + mwindow->theme->widget_border;
921 start_button->reposition_window(x, y);
922 x = w / 2 - stop_button->get_w() / 2;
923 stop_button->reposition_window(x, y);
924 x = w - cancel_button->get_w() - xs10;
925 cancel_button->reposition_window(x, y);
929 int BatchRenderGUI::translation_event()
931 mwindow->session->batchrender_x = get_x();
932 mwindow->session->batchrender_y = get_y();
936 int BatchRenderGUI::close_event()
938 // Stop batch rendering
940 thread->stop_rendering();
941 lock_window("BatchRenderGUI::close_event");
946 void BatchRenderGUI::create_list(int update_widget)
948 for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
949 list_items[i].remove_all_objects();
952 const char **column_titles = BatchRenderThread::column_titles;
954 list_titles[list_columns] = _(column_titles[ENABLED_COL]);
955 list_width[list_columns++] = thread->list_width[ENABLED_COL];
956 if( thread->do_labeled > 0 ) {
957 list_titles[list_columns] = _(column_titles[LABELED_COL]);
958 list_width[list_columns++] = thread->list_width[LABELED_COL];
960 if( thread->do_farmed > 0 ) {
961 list_titles[list_columns] = _(column_titles[FARMED_COL]);
962 list_width[list_columns++] = thread->list_width[FARMED_COL];
964 list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
965 list_width[list_columns++] = thread->list_width[OUTPUT_COL];
966 list_titles[list_columns] = _(column_titles[EDL_COL]);
967 list_width[list_columns++] = thread->list_width[EDL_COL];
968 list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
969 list_width[list_columns++] = thread->list_width[ELAPSED_COL];
971 for( int i = 0; i < thread->jobs.total; i++ ) {
972 BatchRenderJob *job = thread->jobs.values[i];
973 char string[BCTEXTLEN];
974 BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
975 BC_ListBoxItem *labeled = thread->do_labeled > 0 ?
976 new BC_ListBoxItem(job->labeled ? "X" : " ") : 0;
977 BC_ListBoxItem *farmed = thread->do_farmed > 0 ?
978 new BC_ListBoxItem(job->farmed ? "X" : " ") : 0;
979 BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
980 BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
981 BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
982 Units::totext(string, job->elapsed, TIME_HMS2));
984 list_items[col++].append(enabled);
985 if( labeled ) list_items[col++].append(labeled);
986 if( farmed ) list_items[col++].append(farmed);
987 list_items[col++].append(out_path);
988 list_items[col++].append(edl_path);
989 list_items[col].append(elapsed);
990 if( i == thread->current_job ) {
991 enabled->set_selected(1);
992 if( labeled ) labeled->set_selected(1);
993 if( farmed ) farmed->set_selected(1);
994 out_path->set_selected(1);
995 edl_path->set_selected(1);
996 elapsed->set_selected(1);
998 if( i == thread->rendering_job ) {
999 enabled->set_color(RED);
1000 if( labeled ) labeled->set_color(RED);
1001 if( farmed ) farmed->set_color(RED);
1002 out_path->set_color(RED);
1003 edl_path->set_color(RED);
1004 elapsed->set_color(RED);
1008 if( update_widget ) {
1009 batch_list->update(list_items, list_titles, list_width, list_columns,
1010 batch_list->get_xposition(), batch_list->get_yposition(),
1011 batch_list->get_highlighted_item(), 1, 1);
1015 void BatchRenderGUI::change_job()
1017 BatchRenderJob *job = thread->get_current_job();
1018 format_tools->update(job->asset, thread->do_labeled ? &job->labeled : 0);
1019 if( thread->do_farmed ) use_renderfarm->update(&job->farmed);
1020 edl_path_text->update(job->edl_path);
1024 BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
1025 : FormatTools(mwindow, gui, asset)
1028 this->mwindow = mwindow;
1031 BatchFormat::~BatchFormat()
1036 int BatchFormat::handle_event()
1038 gui->create_list(1);
1042 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
1043 int x, int y, int w, char *text)
1044 : BC_TextBox(x, y, w, 1, text)
1046 this->thread = thread;
1050 int BatchRenderEDLPath::handle_event()
1052 calculate_suggestions();
1053 strcpy(thread->get_current_edl(), get_text());
1054 thread->gui->create_list(1);
1058 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
1061 : BC_GenericButton(x, y, _("New"))
1063 this->thread = thread;
1064 set_tooltip(_("Create a new batch"));
1067 int BatchRenderNew::handle_event()
1073 BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
1074 : BC_GenericButton(x, y, _("Delete"))
1076 this->thread = thread;
1077 set_tooltip(_("Delete loaded (highlighted) batch"));
1080 int BatchRenderDelete::handle_event()
1082 thread->delete_job();
1088 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
1089 : BC_GenericButton(x, y, _("Save Jobs"))
1091 this->thread = thread;
1092 set_tooltip(_("Save a Batch Render List"));
1094 startup_lock = new Mutex("BatchRenderSaveList::startup_lock");
1097 BatchRenderSaveList::~BatchRenderSaveList()
1100 delete startup_lock;
1103 void BatchRenderSaveList::stop()
1105 startup_lock->lock("BatchRenderSaveList::~BrowseButton");
1106 if( gui ) gui->set_done(1);
1107 startup_lock->unlock();
1111 int BatchRenderSaveList::handle_event()
1113 if( Thread::running() ) {
1116 gui->raise_window();
1117 gui->unlock_window();
1121 startup_lock->lock("BatchRenderSaveList::handle_event 1");
1123 startup_lock->lock("BatchRenderSaveList::handle_event 2");
1124 startup_lock->unlock();
1128 void BatchRenderSaveList::run()
1130 char default_path[BCTEXTLEN];
1131 sprintf(default_path, "~");
1132 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1133 BC_FileBox filewindow(xS(100), yS(100), default_path,
1134 _("Save Batch Render List"),
1135 _("Enter a Batch Render filename to save as:"),
1139 startup_lock->unlock();
1140 filewindow.create_objects();
1142 int result2 = filewindow.run_window();
1144 strcpy(thread->batch_path, filewindow.get_submitted_path());
1145 thread->gui->lock_window("BatchRenderSaveList::run");
1146 thread->gui->batch_path->update(thread->batch_path);
1147 thread->gui->unlock_window();
1148 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1149 thread->save_jobs(thread->batch_path);
1152 startup_lock->lock("BatchRenderLoadList::run");
1154 startup_lock->unlock();
1157 int BatchRenderSaveList::keypress_event() {
1158 if( get_keypress() == 's' ||
1159 get_keypress() == 'S' ) return handle_event();
1164 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
1167 : BC_GenericButton(x, y, _("Load Jobs")),
1170 this->thread = thread;
1171 set_tooltip(_("Load a previously saved Batch Render List"));
1173 startup_lock = new Mutex("BatchRenderLoadList::startup_lock");
1176 BatchRenderLoadList::~BatchRenderLoadList()
1179 delete startup_lock;
1182 void BatchRenderLoadList::stop()
1184 startup_lock->lock("BatchRenderLoadList::~BrowseButton");
1185 if( gui ) gui->set_done(1);
1186 startup_lock->unlock();
1190 int BatchRenderLoadList::handle_event()
1192 if( Thread::running() ) {
1195 gui->raise_window();
1196 gui->unlock_window();
1200 startup_lock->lock("BatchRenderLoadList::handle_event 1");
1202 startup_lock->lock("BatchRenderLoadList::handle_event 2");
1203 startup_lock->unlock();
1207 void BatchRenderLoadList::run()
1209 char default_path[BCTEXTLEN];
1210 sprintf(default_path, "~");
1211 thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
1212 BC_FileBox filewindow(xS(100), yS(100), default_path, _("Load Batch Render List"),
1213 _("Enter a Batch Render filename to load from:"),
1217 startup_lock->unlock();
1218 filewindow.create_objects();
1220 int result2 = filewindow.run_window();
1222 thread->gui->lock_window("BatchRenderLoadList::run");
1223 strcpy(thread->batch_path, filewindow.get_submitted_path());
1224 thread->gui->batch_path->update(thread->batch_path);
1225 thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
1226 thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
1227 thread->gui->create_list(1);
1228 thread->current_job = 0;
1229 thread->gui->change_job();
1230 thread->gui->unlock_window();
1233 startup_lock->lock("BatchRenderLoadList::run");
1235 startup_lock->unlock();
1238 int BatchRenderLoadList::keypress_event() {
1239 if( get_keypress() == 'o' ||
1240 get_keypress() == 'O' ) return handle_event();
1244 BatchRenderCurrentEDL::BatchRenderCurrentEDL(BatchRenderThread *thread,
1247 : BC_GenericButton(x, y, _("Use Current EDL"))
1249 this->thread = thread;
1250 set_tooltip(_("Replaces highlighted batch job with session currently on timeline. File on disk NOT changed!"));
1253 int BatchRenderCurrentEDL::handle_event()
1255 thread->use_current_edl();
1259 BatchRenderUpdateEDL::BatchRenderUpdateEDL(BatchRenderThread *thread,
1262 : BC_GenericButton(x, y, _("Save to EDL Path"))
1264 this->thread = thread;
1265 set_tooltip(_("WARNING - saves to loaded (highlighted) EDL, *overwrites* highlighted project!"));
1268 int BatchRenderUpdateEDL::handle_event()
1270 thread->update_selected_edl();
1275 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
1276 int x, int y, int w, int h)
1277 : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
1278 thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
1279 0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
1281 this->thread = thread;
1283 set_process_drag(0);
1286 int BatchRenderList::handle_event()
1291 int BatchRenderList::selection_changed()
1293 thread->current_job = get_selection_number(0, 0);
1294 thread->gui->change_job();
1295 int cursor_x = get_cursor_x();
1296 BatchRenderJob *job = thread->get_current_job();
1297 int col_x = 0, changed = 1;
1298 if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
1299 job->enabled = !job->enabled;
1300 else if( thread->do_labeled > 0 &&
1301 cursor_x < (col_x += thread->list_width[LABELED_COL]) )
1302 job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
1303 else if( thread->do_farmed > 0 &&
1304 cursor_x < (col_x += thread->list_width[FARMED_COL]) )
1305 job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
1309 thread->gui->create_list(1);
1310 thread->gui->change_job();
1315 int BatchRenderList::column_resize_event()
1318 thread->list_width[ENABLED_COL] = get_column_width(col++);
1319 if( thread->do_labeled > 0 )
1320 thread->list_width[LABELED_COL] = get_column_width(col++);
1321 if( thread->do_farmed > 0 )
1322 thread->list_width[FARMED_COL] = get_column_width(col++);
1323 thread->list_width[OUTPUT_COL] = get_column_width(col++);
1324 thread->list_width[EDL_COL] = get_column_width(col++);
1325 thread->list_width[ELAPSED_COL] = get_column_width(col);
1329 int BatchRenderList::drag_start_event()
1331 if( BC_ListBox::drag_start_event() ) {
1339 int BatchRenderList::drag_motion_event()
1341 if( BC_ListBox::drag_motion_event() ) {
1347 int BatchRenderList::drag_stop_event()
1349 if( dragging_item ) {
1350 int src = get_selection_number(0, 0);
1351 int dst = get_highlighted_item();
1353 thread->move_batch(src, dst);
1355 BC_ListBox::drag_stop_event();
1363 BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
1364 : BC_GenericButton(x, y, _("Start"))
1366 this->thread = thread;
1367 set_tooltip(_("Start batch rendering"));
1370 int BatchRenderStart::handle_event()
1372 thread->start_rendering();
1376 BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
1377 : BC_GenericButton(x, y, _("Stop"))
1379 this->thread = thread;
1380 set_tooltip(_("Stops currently active batch rendering"));
1383 int BatchRenderStop::handle_event()
1386 thread->stop_rendering();
1387 lock_window("BatchRenderStop::handle_event");
1392 BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
1393 : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
1395 this->thread = thread;
1396 set_tooltip(_("Prevents rendering if loaded session and batch job(s) differ"));
1399 int BatchRenderWarning::handle_event()
1401 thread->warn = get_value();
1405 BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
1406 : BC_GenericButton(x, y, _("Close"))
1408 this->thread = thread;
1409 set_tooltip(_("Closes this window"));
1412 int BatchRenderCancel::handle_event()
1415 thread->stop_rendering();
1416 lock_window("BatchRenderCancel::handle_event");
1417 thread->gui->set_done(1);
1421 int BatchRenderCancel::keypress_event()
1423 if( get_keypress() == ESC ) {
1425 thread->stop_rendering();
1426 lock_window("BatchRenderCancel::keypress_event");
1427 thread->gui->set_done(1);
1433 BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
1434 : BC_CheckBox(x, y, *output, _("Use render farm"))
1436 this->thread = thread;
1437 this->output = output;
1440 int BatchRenderUseFarm::handle_event()
1442 *output = get_value();
1443 thread->gui->create_list(1);
1447 void BatchRenderUseFarm::update(int *output)
1449 this->output = output;
1450 BC_CheckBox::update(*output);