dynamic keyframes, textbox rework, andrea ffmpeg.opts, perpetual chkpt undo, lv2...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / batchrender.C
index 9d52cd59531cd5c437c66a9d68a7eaf29b23c873..e75c71093253ea7c219b7954d1c66b1fd53ded77 100644 (file)
 #include "transportque.h"
 #include "vframe.h"
 
-
-static const char *list_titles[] =
-{
-       _("Enabled"),
-       _("Output"),
-       _("EDL"),
-       _("Elapsed")
-};
-
-static int list_widths[] =
-{
-       50,
-       100,
-       200,
-       100
+// Farmed is not present if not preferences->use_renderfarm
+int BatchRenderThread::column_widths[] = { 42, 42, 42, 222, 222, 150 };
+const char *BatchRenderThread::column_titles[] = {
+       N_("Enabled"), N_("Labeled"), N_("Farmed"), N_("Output"), N_("EDL"), N_("Elapsed")
 };
 
 BatchRenderMenuItem::BatchRenderMenuItem(MWindow *mwindow)
@@ -86,18 +75,13 @@ int BatchRenderMenuItem::handle_event()
 }
 
 
-
-
-
-
-
-
-BatchRenderJob::BatchRenderJob(Preferences *preferences)
+BatchRenderJob::BatchRenderJob(Preferences *preferences, int labeled, int farmed)
 {
        this->preferences = preferences;
+       this->labeled = labeled;
+       this->farmed = farmed >= 0 ? farmed : preferences->use_renderfarm;
        asset = new Asset;
        edl_path[0] = 0;
-       strategy = 0;
        enabled = 1;
        elapsed = 0;
 }
@@ -109,10 +93,11 @@ BatchRenderJob::~BatchRenderJob()
 
 void BatchRenderJob::copy_from(BatchRenderJob *src)
 {
+       enabled = src->enabled;
+       farmed = src->farmed;
+       labeled = src->labeled;
        asset->copy_from(src->asset, 0);
        strcpy(edl_path, src->edl_path);
-       strategy = src->strategy;
-       enabled = src->enabled;
        elapsed = 0;
 }
 
@@ -120,18 +105,16 @@ void BatchRenderJob::load(FileXML *file)
 {
        int result = 0;
 
+       enabled = file->tag.get_property("ENABLED", enabled);
+       farmed = file->tag.get_property("FARMED", farmed);
+       labeled = file->tag.get_property("STRATEGY", labeled);
        edl_path[0] = 0;
        file->tag.get_property("EDL_PATH", edl_path);
-       strategy = file->tag.get_property("STRATEGY", strategy);
-       enabled = file->tag.get_property("ENABLED", enabled);
        elapsed = file->tag.get_property("ELAPSED", elapsed);
-       fix_strategy();
 
        result = file->read_tag();
-       if(!result)
-       {
-               if(file->tag.title_is("ASSET"))
-               {
+       if( !result ) {
+               if( file->tag.title_is("ASSET") ) {
                        file->tag.get_property("SRC", asset->path);
                        asset->read(file, 0);
 // The compression parameters are stored in the defaults to reduce
@@ -140,39 +123,27 @@ void BatchRenderJob::load(FileXML *file)
                        BC_Hash defaults;
                        defaults.load_string(file->read_text());
                        asset->load_defaults(&defaults,
-                               "",
-                               0,
-                               1,
-                               0,
-                               0,
-                               0);
+                               "", 0, 1, 0, 0, 0);
                }
        }
 }
 
 void BatchRenderJob::save(FileXML *file)
 {
-       file->tag.set_property("EDL_PATH", edl_path);
-       file->tag.set_property("STRATEGY", strategy);
        file->tag.set_property("ENABLED", enabled);
+       file->tag.set_property("FARMED", farmed);
+       file->tag.set_property("LABELED", labeled);
+       file->tag.set_property("EDL_PATH", edl_path);
        file->tag.set_property("ELAPSED", elapsed);
        file->append_tag();
        file->append_newline();
-       asset->write(file,
-               0,
-               "");
+       asset->write(file, 0, "");
 
 // The compression parameters are stored in the defaults to reduce
 // coding maintenance.  The defaults must now be stuffed into the XML for
 // unique storage.
        BC_Hash defaults;
-       asset->save_defaults(&defaults,
-               "",
-               0,
-               1,
-               0,
-               0,
-               0);
+       asset->save_defaults(&defaults, "", 0, 1, 0, 0, 0);
        char *string;
        defaults.save_string(string);
        file->append_text(string);
@@ -182,20 +153,14 @@ void BatchRenderJob::save(FileXML *file)
        file->append_newline();
 }
 
-void BatchRenderJob::fix_strategy()
+int BatchRenderJob::get_strategy()
 {
-       strategy = Render::fix_strategy(strategy, preferences->use_renderfarm);
+// if set, overrides farmed, labeled
+       int use_renderfarm = farmed && preferences->use_renderfarm ? 1 : 0;
+       return Render::get_strategy(use_renderfarm, labeled);
 }
 
 
-
-
-
-
-
-
-
-
 BatchRenderThread::BatchRenderThread(MWindow *mwindow)
  : BC_DialogThread()
 {
@@ -206,8 +171,9 @@ BatchRenderThread::BatchRenderThread(MWindow *mwindow)
        default_job = 0;
        boot_defaults = 0;
        preferences = 0;
+       warn = 1;
        render = 0;
-       file_entries = 0;
+       batch_path[0] = 0;
 }
 
 BatchRenderThread::BatchRenderThread()
@@ -220,8 +186,9 @@ BatchRenderThread::BatchRenderThread()
        default_job = 0;
        boot_defaults = 0;
        preferences = 0;
+       warn = 1;
        render = 0;
-       file_entries = 0;
+       batch_path[0] = 0;
 }
 
 BatchRenderThread::~BatchRenderThread()
@@ -230,30 +197,24 @@ BatchRenderThread::~BatchRenderThread()
        delete boot_defaults;
        delete preferences;
        delete render;
-       if( file_entries ) {
-               file_entries->remove_all_objects();
-               delete file_entries;
-       }
 }
 
-void BatchRenderThread::reset()
+void BatchRenderThread::reset(const char *path)
 {
+       if( path ) {
+               strcpy(batch_path, path);
+               warn = 1;
+       }
        current_job = 0;
        rendering_job = -1;
        delete default_job;  default_job = 0;
        jobs.remove_all_objects();
-       if(file_entries) {
-               file_entries->remove_all_objects();
-               delete file_entries;  file_entries = 0;
-       }
 }
 
 void BatchRenderThread::handle_close_event(int result)
 {
 // Save settings
-       char path[BCTEXTLEN];
-       path[0] = 0;
-       save_jobs(path);
+       save_jobs(batch_path);
        save_defaults(mwindow->defaults);
        reset();
 }
@@ -263,33 +224,11 @@ BC_Window* BatchRenderThread::new_gui()
        current_start = 0.0;
        current_end = 0.0;
        default_job = new BatchRenderJob(mwindow->preferences);
-
-
-       if(!file_entries)
-       {
-               file_entries = new ArrayList<BC_ListBoxItem*>;
-               FileSystem fs;
-               char string[BCTEXTLEN];
-       // Load current directory
-               fs.update(getcwd(string, BCTEXTLEN));
-               for(int i = 0; i < fs.total_files(); i++)
-               {
-                       file_entries->append(
-                               new BC_ListBoxItem(
-                                       fs.get_entry(i)->get_name()));
-               }
-       }
-
-       char path[BCTEXTLEN];
-       path[0] = 0;
-       load_jobs(path, mwindow->preferences);
+       load_jobs(batch_path, mwindow->preferences);
        load_defaults(mwindow->defaults);
-       this->gui = new BatchRenderGUI(mwindow,
-               this,
-               mwindow->session->batchrender_x,
-               mwindow->session->batchrender_y,
-               mwindow->session->batchrender_w,
-               mwindow->session->batchrender_h);
+       this->gui = new BatchRenderGUI(mwindow, this,
+               mwindow->session->batchrender_x, mwindow->session->batchrender_y,
+               mwindow->session->batchrender_w, mwindow->session->batchrender_h);
        this->gui->create_objects();
        return this->gui;
 }
@@ -301,19 +240,18 @@ void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
        int result = 0;
 
        jobs.remove_all_objects();
-       if(path[0])
-               file.read_from_file(path);
-       else
-               file.read_from_file(create_path(path));
-
-       while(!result)
-       {
-               if(!(result = file.read_tag()))
-               {
-                       if(file.tag.title_is("JOB"))
-                       {
-                               BatchRenderJob *job;
-                               jobs.append(job = new BatchRenderJob(preferences));
+       if( !path ) path = batch_path;
+       if( !path[0] ) create_path(path);
+       file.read_from_file(path);
+
+       while( !result ) {
+               if( !(result = file.read_tag()) ) {
+                       if( file.tag.title_is("JOBS") ) {
+                               warn = file.tag.get_property("WARN", 1);
+                       }
+                       else if( file.tag.title_is("JOB") ) {
+                               BatchRenderJob *job =  new BatchRenderJob(preferences);
+                               jobs.append(job);
                                job->load(&file);
                        }
                }
@@ -323,62 +261,51 @@ void BatchRenderThread::load_jobs(char *path, Preferences *preferences)
 void BatchRenderThread::save_jobs(char *path)
 {
        FileXML file;
+       file.tag.set_title("JOBS");
+       file.tag.set_property("WARN", warn);
+       file.append_tag();
+       file.append_newline();
 
-       for(int i = 0; i < jobs.total; i++)
-       {
+       for( int i = 0; i < jobs.total; i++ ) {
                file.tag.set_title("JOB");
                jobs.values[i]->save(&file);
        }
+       file.tag.set_title("/JOBS");
+       file.append_tag();
+       file.append_newline();
 
-       if(path[0])
-               file.write_to_file(path);
-       else
-               file.write_to_file(create_path(path));
+       if( !path ) path = batch_path;
+       if( !path[0] ) create_path(path);
+       file.write_to_file(path);
 }
 
 void BatchRenderThread::load_defaults(BC_Hash *defaults)
 {
-       if(default_job)
-       {
+       if( default_job ) {
                default_job->asset->load_defaults(defaults,
-                       "BATCHRENDER_",
-                       1,
-                       1,
-                       1,
-                       1,
-                       1);
-               default_job->fix_strategy();
+                       "BATCHRENDER_", 1, 1, 1, 1, 1);
        }
 
-       for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
-       {
+       for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
                char string[BCTEXTLEN];
                sprintf(string, "BATCHRENDER_COLUMN%d", i);
-               column_width[i] = defaults->get(string, list_widths[i]);
+               list_width[i] = defaults->get(string, column_widths[i]);
        }
 }
 
 void BatchRenderThread::save_defaults(BC_Hash *defaults)
 {
-       if(default_job)
-       {
+       if( default_job ) {
                default_job->asset->save_defaults(defaults,
-                       "BATCHRENDER_",
-                       1,
-                       1,
-                       1,
-                       1,
-                       1);
-               defaults->update("BATCHRENDER_STRATEGY", default_job->strategy);
+                       "BATCHRENDER_", 1, 1, 1, 1, 1);
        }
-       for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
-       {
+       for( int i=0; i<BATCHRENDER_COLUMNS; ++i ) {
                char string[BCTEXTLEN];
                sprintf(string, "BATCHRENDER_COLUMN%d", i);
-               defaults->update(string, column_width[i]);
+               defaults->update(string, list_width[i]);
        }
 //     defaults->update("BATCHRENDER_JOB", current_job);
-       if(mwindow)
+       if( mwindow )
                mwindow->save_defaults();
        else
                defaults->save();
@@ -405,10 +332,9 @@ void BatchRenderThread::new_job()
 
 void BatchRenderThread::delete_job()
 {
-       if(current_job < jobs.total && current_job >= 0)
-       {
+       if( current_job < jobs.total && current_job >= 0 ) {
                jobs.remove_object_number(current_job);
-               if(current_job > 0) current_job--;
+               if( current_job > 0 ) current_job--;
                gui->create_list(1);
                gui->change_job();
        }
@@ -431,7 +357,7 @@ void BatchRenderThread::update_selected_edl()
         FileXML xml_file;
        char *path = get_current_edl();
        EDL *edl = mwindow->edl;
-        edl->save_xml(&xml_file, path, 0, 0);
+        edl->save_xml(&xml_file, path);
         xml_file.terminate_string();
         if( xml_file.write_to_file(path) ) {
                char msg[BCTEXTLEN];
@@ -442,16 +368,8 @@ void BatchRenderThread::update_selected_edl()
 
 BatchRenderJob* BatchRenderThread::get_current_job()
 {
-       BatchRenderJob *result;
-       if(current_job >= jobs.total || current_job < 0)
-       {
-               result = default_job;
-       }
-       else
-       {
-               result = jobs.values[current_job];
-       }
-       return result;
+       return current_job >= 0 && current_job < jobs.total ?
+               jobs.values[current_job] : default_job;
 }
 
 
@@ -469,53 +387,81 @@ char* BatchRenderThread::get_current_edl()
 // Test EDL files for existence
 int BatchRenderThread::test_edl_files()
 {
-       for(int i = 0; i < jobs.total; i++)
-       {
-               if(jobs.values[i]->enabled)
-               {
-                       const char *path = jobs.values[i]->edl_path;
-                       if( *path == '@' ) ++path;
-                       FILE *fd = fopen(path, "r");
-                       if(!fd)
-                       {
-                               char string[BCTEXTLEN];
-                               sprintf(string, _("EDL %s not found.\n"), jobs.values[i]->edl_path);
-                               if(mwindow)
-                               {
-                                       ErrorBox error_box(_(PROGRAM_NAME ": Error"),
-                                               mwindow->gui->get_abs_cursor_x(1),
-                                               mwindow->gui->get_abs_cursor_y(1));
-                                       error_box.create_objects(string);
-                                       error_box.run_window();
-                                       gui->button_enable();
+       int not_equiv = 0, ret = 0;
+       const char *path = 0;
+
+       for( int i=0; !ret && i<jobs.size(); ++i ) {
+               if( !jobs.values[i]->enabled ) continue;
+               const char *path = jobs.values[i]->edl_path;
+               int is_script = *path == '@' ? 1 : 0;
+               if( is_script ) ++path;
+               FILE *fp = fopen(path, "r");
+               if( fp ) {
+                       if( warn && mwindow && !is_script ) {
+                               fseek(fp, 0, SEEK_END);
+                               int64_t sz = ftell(fp);
+                               fseek(fp, 0, SEEK_SET);
+                               char *bfr = new char[sz+1];
+                               int64_t len = fread(bfr, 1, sz+1, fp);
+                               if( len == sz ) {
+                                       FileXML file;
+                                       XMLBuffer data(bfr, len, 0);
+                                       file.set_shared_input(&data);
+                                       EDL *edl = new EDL; edl->create_objects();
+                                       edl->load_xml(&file, LOAD_ALL);
+                                       double pos = edl->equivalent_output(mwindow->edl);
+                                       if( pos >= 0 ) ++not_equiv;
+                                       edl->remove_user();
                                }
                                else
-                               {
-                                       fprintf(stderr,
-                                               "%s",
-                                               string);
-                               }
-
-                               is_rendering = 0;
-                               return 1;
-                       }
-                       else
-                       {
-                               fclose(fd);
+                                       ret = 1;
+                               delete [] bfr;
                        }
+                       fclose(fp);
                }
+               else
+                       ret = 1;
        }
-       return 0;
+
+       if( ret ) {
+               char string[BCTEXTLEN];
+               sprintf(string, _("EDL %s not found.\n"), path);
+               if( mwindow ) {
+                       ErrorBox error_box(_(PROGRAM_NAME ": Error"),
+                               mwindow->gui->get_abs_cursor_x(1),
+                               mwindow->gui->get_abs_cursor_y(1));
+                       error_box.create_objects(string);
+                       error_box.run_window();
+                       gui->button_enable();
+               }
+               else {
+                       fprintf(stderr, "%s", string);
+               }
+               is_rendering = 0;
+       }
+       else if( warn && mwindow && not_equiv > 0 ) {
+               fprintf(stderr, _("%d job EDLs do not match session edl\n"), not_equiv);
+               char string[BCTEXTLEN], *sp = string;
+               sp += sprintf(sp, _("%d job EDLs do not match session edl\n"),not_equiv);
+               sp += sprintf(sp, _("press cancel to abandon batch render"));
+               mwindow->show_warning(&warn, string);
+               if( mwindow->wait_warning() ) {
+                       gui->button_enable();
+                       is_rendering = 0;
+                       ret = 1;
+               }
+               gui->warning->update(warn);
+       }
+
+       return ret;
 }
 
 void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
        Preferences *preferences)
 {
-       for(int i = 0; i < jobs.total; i++)
-       {
+       for( int i = 0; i < jobs.total; i++ ) {
                BatchRenderJob *job = jobs.values[i];
-               if(job->enabled && *job->edl_path != '@')
-               {
+               if( job->enabled && *job->edl_path != '@' ) {
                        PackageDispatcher *packages = new PackageDispatcher;
 
 // Load EDL
@@ -535,7 +481,7 @@ void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
                        packages->create_packages(mwindow,
                                command->get_edl(),
                                preferences,
-                               job->strategy,
+                               job->get_strategy(),
                                job->asset,
                                command->start_position,
                                command->end_position,
@@ -563,11 +509,21 @@ void BatchRenderThread::start_rendering(char *config_path,
        // XXX the above stuff is leaked,
 //PRINT_TRACE
 // Initialize stuff which MWindow does.
-       signals->initialize();
+       signals->initialize("/tmp/cinelerra_batch%d.dmp");
        MWindow::init_defaults(boot_defaults, config_path);
        load_defaults(boot_defaults);
        preferences = new Preferences;
        preferences->load_defaults(boot_defaults);
+       BC_Signals::set_trap_hook(trap_hook, this);
+       BC_Signals::set_catch_segv(preferences->trap_sigsegv);
+       BC_Signals::set_catch_intr(0);
+       if( preferences->trap_sigsegv ) {
+               BC_Trace::enable_locks();
+       }
+       else {
+               BC_Trace::disable_locks();
+       }
+
        MWindow::init_plugins(0, preferences);
        char font_path[BCTEXTLEN];
        strcpy(font_path, preferences->plugin_dir);
@@ -576,13 +532,14 @@ void BatchRenderThread::start_rendering(char *config_path,
        BC_WindowBase::get_resources()->vframe_shm = 1;
 
 //PRINT_TRACE
+       strcpy(this->batch_path, batch_path);
        load_jobs(batch_path, preferences);
        save_jobs(batch_path);
        save_defaults(boot_defaults);
 
 //PRINT_TRACE
 // Test EDL files for existence
-       if(test_edl_files()) return;
+       if( test_edl_files() ) return;
 
 //PRINT_TRACE
 
@@ -595,30 +552,26 @@ void BatchRenderThread::start_rendering(char *config_path,
        int result = ConfirmSave::test_files(0, &paths);
        paths.remove_all_objects();
 // Abort on any existing file because it's so hard to set this up.
-       if(result) return;
+       if( result ) return;
 
 //PRINT_TRACE
        render = new Render(0);
 //PRINT_TRACE
-       render->start_batches(&jobs,
-               boot_defaults,
-               preferences);
+       render->start_batches(&jobs, boot_defaults, preferences);
 //PRINT_TRACE
 }
 
 void BatchRenderThread::start_rendering()
 {
-       if(is_rendering) return;
-
+       if( is_rendering ) return;
        is_rendering = 1;
-       char path[BCTEXTLEN];
-       path[0] = 0;
-       save_jobs(path);
+
+       save_jobs(batch_path);
        save_defaults(mwindow->defaults);
        gui->button_disable();
 
 // Test EDL files for existence
-       if(test_edl_files()) return;
+       if( test_edl_files() ) return;
 
 // Predict all destination paths
        ArrayList<char*> paths;
@@ -630,8 +583,7 @@ void BatchRenderThread::start_rendering()
        paths.remove_all_objects();
 
 // User cancelled
-       if(result)
-       {
+       if( result ) {
                is_rendering = 0;
                gui->button_enable();
                return;
@@ -642,7 +594,7 @@ void BatchRenderThread::start_rendering()
 
 void BatchRenderThread::stop_rendering()
 {
-       if(!is_rendering) return;
+       if( !is_rendering ) return;
        mwindow->render->stop_operation();
        is_rendering = 0;
 }
@@ -650,13 +602,11 @@ void BatchRenderThread::stop_rendering()
 void BatchRenderThread::update_active(int number)
 {
        gui->lock_window("BatchRenderThread::update_active");
-       if(number >= 0)
-       {
+       if( number >= 0 ) {
                current_job = number;
                rendering_job = number;
        }
-       else
-       {
+       else {
                rendering_job = -1;
                is_rendering = 0;
        }
@@ -669,15 +619,13 @@ void BatchRenderThread::update_done(int number,
        double elapsed_time)
 {
        gui->lock_window("BatchRenderThread::update_done");
-       if(number < 0)
-       {
+       if( number < 0 ) {
                gui->button_enable();
        }
-       else
-       {
+       else {
                jobs.values[number]->enabled = 0;
                jobs.values[number]->elapsed = elapsed_time;
-               if(create_list) gui->create_list(1);
+               if( create_list ) gui->create_list(1);
        }
        gui->unlock_window();
 }
@@ -685,50 +633,49 @@ void BatchRenderThread::update_done(int number,
 void BatchRenderThread::move_batch(int src, int dst)
 {
        BatchRenderJob *src_job = jobs.values[src];
-       if(dst < 0) dst = jobs.total - 1;
+       if( dst < 0 ) dst = jobs.total - 1;
 
-       if(dst != src)
-       {
-               for(int i = src; i < jobs.total - 1; i++)
+       if( dst != src ) {
+               for( int i = src; i < jobs.total - 1; i++ )
                        jobs.values[i] = jobs.values[i + 1];
-//             if(dst > src) dst--;
-               for(int i = jobs.total - 1; i > dst; i--)
+//             if( dst > src ) dst--;
+               for( int i = jobs.total - 1; i > dst; i-- )
                        jobs.values[i] = jobs.values[i - 1];
                jobs.values[dst] = src_job;
                gui->create_list(1);
        }
 }
 
-
+void BatchRenderThread::trap_hook(FILE *fp, void *vp)
+{
+       MWindow *mwindow = ((BatchRenderThread *)vp)->mwindow;
+       fprintf(fp, "\nEDL:\n");
+       mwindow->dump_edl(fp);
+       fprintf(fp, "\nUNDO:\n");
+       mwindow->dump_undo(fp);
+       fprintf(fp, "\nEXE:\n");
+       mwindow->dump_exe(fp);
+}
 
 
 
 
 
 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
-       BatchRenderThread *thread,
-       int x,
-       int y,
-       int w,
-       int h)
+       BatchRenderThread *thread, int x, int y, int w, int h)
  : BC_Window(_(PROGRAM_NAME ": Batch Render"),
-       x,
-       y,
-       w,
-       h,
-       50,
-       50,
-       1,
-       0,
-       1)
+       x, y, w, h, 730, 400, 1, 0, 1)
 {
        this->mwindow = mwindow;
        this->thread = thread;
+       use_renderfarm = 0;
 }
 
 BatchRenderGUI::~BatchRenderGUI()
 {
        lock_window("BatchRenderGUI::~BatchRenderGUI");
+       loadlist_batch->stop();
+       savelist_batch->stop();
        delete format_tools;
        unlock_window();
 }
@@ -751,19 +698,25 @@ void BatchRenderGUI::create_objects()
 
        format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
        format_tools->set_w(get_w() / 2);
+       BatchRenderJob *current_job = thread->get_current_job();
        format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
-                       &thread->get_current_job()->strategy, 0); 
-
+                       &current_job->labeled, 0);
+       if( mwindow->preferences->use_renderfarm ) {
+               use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
+                       &current_job->farmed);
+               add_subwindow(use_renderfarm);
+               y1 += use_renderfarm->get_h() + 10;
+       }
 // input EDL
        add_subwindow(edl_path_title = new BC_Title(x2, y2, _("EDL Path:")));
        y2 += edl_path_title->get_h() + mwindow->theme->widget_border;
-       
+
        x = x2;  y = y2;
        add_subwindow(edl_path_text = new BatchRenderEDLPath( thread,
-               x, y, get_w()-x - 40, thread->get_current_edl())); 
+               x, y, get_w()-x - 40, thread->get_current_edl()));
        x =  x2 + edl_path_text->get_w();
        add_subwindow(edl_path_browse = new BrowseButton(
-               mwindow, this, edl_path_text, x, y, thread->get_current_edl(),
+               mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
                _("Input EDL"), _("Select an EDL to load:"), 0));
        y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
 
@@ -780,11 +733,15 @@ void BatchRenderGUI::create_objects()
        add_subwindow(savelist_batch = new BatchRenderSaveList(thread, x, y));
        x += savelist_batch->get_w() + mwindow->theme->widget_border;
        add_subwindow(loadlist_batch = new BatchRenderLoadList(thread, x, y));
-       y2 = y + loadlist_batch->get_h() + mwindow->theme->widget_border;
+       y += loadlist_batch->get_h() + mwindow->theme->widget_border;
+       add_subwindow(warning = new BatchRenderWarning(thread, x2, y));
+       y2 = y + warning->get_h() + mwindow->theme->widget_border;
        if( y2 > y1 ) y1 = y2;
        x = mwindow->theme->batchrender_x1, y = y1;
 
        add_subwindow(list_title = new BC_Title(x, y, _("Batches to render:")));
+       x1 = x + list_title->get_w() + mwindow->theme->widget_border;;
+       add_subwindow(batch_path = new BC_Title(x1, y, thread->batch_path, MEDIUMFONT));
        y += list_title->get_h() + mwindow->theme->widget_border;
        y1 = get_h();
        y1 -= 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
@@ -834,7 +791,8 @@ int BatchRenderGUI::resize_event(int w, int h)
        output_path_title->reposition_window(x1, y1);
        y1 += output_path_title->get_h() + mwindow->theme->widget_border;
        format_tools->reposition_window(x1, y1);
-
+       if( use_renderfarm )
+               use_renderfarm->reposition_window(x1, y1);
 // input EDL
        x = x2, y = y2;
        edl_path_title->reposition_window(x, y);
@@ -858,6 +816,7 @@ int BatchRenderGUI::resize_event(int w, int h)
        x += savelist_batch->get_w() + mwindow->theme->widget_border;
        loadlist_batch->reposition_window(x, y);
        y += loadlist_batch->get_h() + mwindow->theme->widget_border;
+       warning->reposition_window(x2, y);
 
        y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
        y2 = get_h() - y1 - batch_list->get_h();
@@ -896,79 +855,80 @@ int BatchRenderGUI::close_event()
 
 void BatchRenderGUI::create_list(int update_widget)
 {
-       for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
-       {
-               list_columns[i].remove_all_objects();
+       for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
+               list_items[i].remove_all_objects();
        }
 
-       for(int i = 0; i < thread->jobs.total; i++)
-       {
+       const char **column_titles = BatchRenderThread::column_titles;
+       list_columns = 0;
+       list_titles[list_columns] = _(column_titles[ENABLED_COL]);
+       list_width[list_columns++] = thread->list_width[ENABLED_COL];
+       list_titles[list_columns] = _(column_titles[LABELED_COL]);
+       list_width[list_columns++] = thread->list_width[LABELED_COL];
+       if( mwindow->preferences->use_renderfarm ) {
+               list_titles[list_columns] = _(column_titles[FARMED_COL]);
+               list_width[list_columns++] = thread->list_width[FARMED_COL];
+       }
+       list_titles[list_columns] = _(column_titles[OUTPUT_COL]);
+       list_width[list_columns++] = thread->list_width[OUTPUT_COL];
+       list_titles[list_columns] = _(column_titles[EDL_COL]);
+       list_width[list_columns++] = thread->list_width[EDL_COL];
+       list_titles[list_columns] = _(column_titles[ELAPSED_COL]);
+       list_width[list_columns++] = thread->list_width[ELAPSED_COL];
+
+       for( int i = 0; i < thread->jobs.total; i++ ) {
                BatchRenderJob *job = thread->jobs.values[i];
                char string[BCTEXTLEN];
-               BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ?
-                       (char*)"X" :
-                       (char*)" ");
-               BC_ListBoxItem *item1 = new BC_ListBoxItem(job->asset->path);
-               BC_ListBoxItem *item2 = new BC_ListBoxItem(job->edl_path);
-               BC_ListBoxItem *item3;
-               if(job->elapsed)
-                       item3 = new BC_ListBoxItem(
-                               Units::totext(string,
-                                       job->elapsed,
-                                       TIME_HMS2));
-               else
-                       item3 = new BC_ListBoxItem(_("Unknown"));
-               list_columns[0].append(enabled);
-               list_columns[1].append(item1);
-               list_columns[2].append(item2);
-               list_columns[3].append(item3);
-               if(i == thread->current_job)
-               {
+               BC_ListBoxItem *enabled = new BC_ListBoxItem(job->enabled ? "X" : " ");
+               BC_ListBoxItem *labeled = new BC_ListBoxItem(job->labeled ? "X" : " ");
+               BC_ListBoxItem *farmed  = !mwindow->preferences->use_renderfarm ? 0 :
+                       new BC_ListBoxItem(job->farmed  ? "X" : " ");
+               BC_ListBoxItem *out_path = new BC_ListBoxItem(job->asset->path);
+               BC_ListBoxItem *edl_path = new BC_ListBoxItem(job->edl_path);
+               BC_ListBoxItem *elapsed = new BC_ListBoxItem(!job->elapsed ? _("Unknown") :
+                       Units::totext(string, job->elapsed, TIME_HMS2));
+               int col = 0;
+               list_items[col++].append(enabled);
+               list_items[col++].append(labeled);
+               if( farmed ) list_items[col++].append(farmed);
+               list_items[col++].append(out_path);
+               list_items[col++].append(edl_path);
+               list_items[col].append(elapsed);
+               if( i == thread->current_job ) {
                        enabled->set_selected(1);
-                       item1->set_selected(1);
-                       item2->set_selected(1);
-                       item3->set_selected(1);
+                       labeled->set_selected(1);
+                       if( farmed ) farmed->set_selected(1);
+                       out_path->set_selected(1);
+                       edl_path->set_selected(1);
+                       elapsed->set_selected(1);
                }
-               if(i == thread->rendering_job)
-               {
+               if( i == thread->rendering_job ) {
                        enabled->set_color(RED);
-                       item1->set_color(RED);
-                       item2->set_color(RED);
-                       item3->set_color(RED);
+                       labeled->set_color(RED);
+                       if( farmed ) farmed->set_color(RED);
+                       out_path->set_color(RED);
+                       edl_path->set_color(RED);
+                       elapsed->set_color(RED);
                }
        }
 
-       if(update_widget)
-       {
-               batch_list->update(list_columns,
-                                               list_titles,
-                                               thread->column_width,
-                                               BATCHRENDER_COLUMNS,
-                                               batch_list->get_xposition(),
-                                               batch_list->get_yposition(),
-                                               batch_list->get_highlighted_item(),  // Flat index of item cursor is over
-                                               1,     // set all autoplace flags to 1
-                                               1);
+       if( update_widget ) {
+               batch_list->update(list_items, list_titles, list_width, list_columns,
+                       batch_list->get_xposition(), batch_list->get_yposition(),
+                       batch_list->get_highlighted_item(), 1, 1);
        }
 }
 
 void BatchRenderGUI::change_job()
 {
        BatchRenderJob *job = thread->get_current_job();
-       format_tools->update(job->asset, &job->strategy);
+       format_tools->update(job->asset, &job->labeled);
+       if( use_renderfarm ) use_renderfarm->update(&job->farmed);
        edl_path_text->update(job->edl_path);
 }
 
 
-
-
-
-
-
-
-BatchFormat::BatchFormat(MWindow *mwindow,
-                       BatchRenderGUI *gui,
-                       Asset *asset)
+BatchFormat::BatchFormat(MWindow *mwindow, BatchRenderGUI *gui, Asset *asset)
  : FormatTools(mwindow, gui, asset)
 {
        this->gui = gui;
@@ -986,26 +946,9 @@ int BatchFormat::handle_event()
        return 1;
 }
 
-
-
-
-
-
-
-
-
-
-
 BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
-       int x,
-       int y,
-       int w,
-       char *text)
- : BC_TextBox(x,
-               y,
-               w,
-               1,
-               text)
+       int x, int y, int w, char *text)
+ : BC_TextBox(x, y, w, 1, text)
 {
        this->thread = thread;
 }
@@ -1013,19 +956,12 @@ BatchRenderEDLPath::BatchRenderEDLPath(BatchRenderThread *thread,
 
 int BatchRenderEDLPath::handle_event()
 {
-// Suggestions
-       calculate_suggestions(thread->file_entries);
-
+       calculate_suggestions();
        strcpy(thread->get_current_edl(), get_text());
        thread->gui->create_list(1);
        return 1;
 }
 
-
-
-
-
-
 BatchRenderNew::BatchRenderNew(BatchRenderThread *thread,
        int x,
        int y)
@@ -1040,9 +976,7 @@ int BatchRenderNew::handle_event()
        return 1;
 }
 
-BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread,
-       int x,
-       int y)
+BatchRenderDelete::BatchRenderDelete(BatchRenderThread *thread, int x, int y)
  : BC_GenericButton(x, y, _("Delete"))
 {
        this->thread = thread;
@@ -1056,10 +990,8 @@ int BatchRenderDelete::handle_event()
 
 
 
-BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread,
-       int x,
-       int y)
- : BC_GenericButton(x, y, _("Save List"))
+BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread, int x, int y)
+ : BC_GenericButton(x, y, _("Save Jobs"))
 {
        this->thread = thread;
        set_tooltip(_("Save a Batch Render List"));
@@ -1068,25 +1000,23 @@ BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread,
 }
 
 BatchRenderSaveList::~BatchRenderSaveList()
+{
+       stop();
+       delete startup_lock;
+}
+
+void BatchRenderSaveList::stop()
 {
        startup_lock->lock("BatchRenderSaveList::~BrowseButton");
-       if(gui)
-       {
-               gui->lock_window();
-               gui->set_done(1);
-               gui->unlock_window();
-       }
+       if( gui ) gui->set_done(1);
        startup_lock->unlock();
        Thread::join();
-       delete startup_lock;
 }
 
 int BatchRenderSaveList::handle_event()
 {
-       if(Thread::running())
-       {
-               if(gui)
-               {
+       if( Thread::running() ) {
+               if( gui ) {
                        gui->lock_window();
                        gui->raise_window();
                        gui->unlock_window();
@@ -1104,48 +1034,39 @@ void BatchRenderSaveList::run()
 {
        char default_path[BCTEXTLEN];
        sprintf(default_path, "~");
-       BC_FileBox filewindow(100,
-                             100,
-                             this->thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path),
-                             _("Save Batch Render List"),
-                             _("Enter a Batch Render filename to save as:"),
-                             0,
-                             0,
-                             0,
-                             0);
-
+       thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
+       BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
+                       _("Enter a Batch Render filename to save as:"),
+                       0, 0, 0, 0);
        gui = &filewindow;
 
        startup_lock->unlock();
        filewindow.create_objects();
 
        int result2 = filewindow.run_window();
-
-       if(!result2)
-       {
-               this->thread->save_jobs(filewindow.get_submitted_path());
-               this->thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", filewindow.get_submitted_path());
+       if( !result2 ) {
+               strcpy(thread->batch_path, filewindow.get_submitted_path());
+               thread->gui->batch_path->update(thread->batch_path);
+               thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
+               thread->save_jobs(thread->batch_path);
        }
 
-       this->thread->gui->flush();
        startup_lock->lock("BatchRenderLoadList::run");
        gui = 0;
        startup_lock->unlock();
 }
 
 int BatchRenderSaveList::keypress_event() {
-       if (get_keypress() == 's' ||
-           get_keypress() == 'S') return handle_event();
+       ifget_keypress() == 's' ||
+           get_keypress() == 'S' ) return handle_event();
        return 0;
 }
 
 
-
-
 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
        int x,
        int y)
-  : BC_GenericButton(x, y, _("Load List")),
+  : BC_GenericButton(x, y, _("Load Jobs")),
     Thread()
 {
        this->thread = thread;
@@ -1155,25 +1076,23 @@ BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
 }
 
 BatchRenderLoadList::~BatchRenderLoadList()
+{
+       stop();
+       delete startup_lock;
+}
+
+void BatchRenderLoadList::stop()
 {
        startup_lock->lock("BatchRenderLoadList::~BrowseButton");
-       if(gui)
-       {
-               gui->lock_window();
-               gui->set_done(1);
-               gui->unlock_window();
-       }
+       if( gui ) gui->set_done(1);
        startup_lock->unlock();
        Thread::join();
-       delete startup_lock;
 }
 
 int BatchRenderLoadList::handle_event()
 {
-       if(Thread::running())
-       {
-               if(gui)
-               {
+       if( Thread::running() ) {
+               if( gui ) {
                        gui->lock_window();
                        gui->raise_window();
                        gui->unlock_window();
@@ -1191,39 +1110,34 @@ void BatchRenderLoadList::run()
 {
        char default_path[BCTEXTLEN];
        sprintf(default_path, "~");
-       BC_FileBox filewindow(100,
-                             100,
-                             this->thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path),
-                             _("Load Batch Render List"),
-                             _("Enter a Batch Render filename to load from:"),
-                             0,
-                             0,
-                             0,
-                             0);
-
+       thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
+       BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
+                       _("Enter a Batch Render filename to load from:"),
+                       0, 0, 0, 0);
        gui = &filewindow;
 
        startup_lock->unlock();
        filewindow.create_objects();
 
        int result2 = filewindow.run_window();
-
-       if(!result2)
-       {
-               this->thread->load_jobs(filewindow.get_submitted_path(),this->thread->mwindow->preferences);
-               this->thread->gui->create_list(1);
-               this->thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", filewindow.get_submitted_path());
+       if( !result2 ) {
+               strcpy(thread->batch_path, filewindow.get_submitted_path());
+               thread->gui->batch_path->update(thread->batch_path);
+               thread->mwindow->defaults->update("DEFAULT_BATCHLOADPATH", thread->batch_path);
+               thread->load_jobs(thread->batch_path, thread->mwindow->preferences);
+               thread->gui->create_list(1);
+               thread->current_job = 0;
+               thread->gui->change_job();
        }
 
-       this->thread->gui->flush();
        startup_lock->lock("BatchRenderLoadList::run");
        gui = 0;
        startup_lock->unlock();
 }
 
 int BatchRenderLoadList::keypress_event() {
-       if (get_keypress() == 'o' ||
-           get_keypress() == 'O') return handle_event();
+       ifget_keypress() == 'o' ||
+           get_keypress() == 'O' ) return handle_event();
        return 0;
 }
 
@@ -1256,27 +1170,11 @@ int BatchRenderUpdateEDL::handle_event()
 }
 
 
-
-
 BatchRenderList::BatchRenderList(BatchRenderThread *thread,
-       int x,
-       int y,
-       int w,
-       int h)
- : BC_ListBox(x,
-       y,
-       w,
-       h,
-       LISTBOX_TEXT,
-       thread->gui->list_columns,
-       list_titles,
-       thread->column_width,
-       BATCHRENDER_COLUMNS,
-       0,
-       0,
-       LISTBOX_SINGLE,
-       ICON_LEFT,
-       1)
+       int x, int y, int w, int h)
+ : BC_ListBox(x, y, w, h, LISTBOX_TEXT, thread->gui->list_items,
+       thread->gui->list_titles, thread->gui->list_width, thread->gui->list_columns,
+       0, 0, LISTBOX_SINGLE, ICON_LEFT, 1)
 {
        this->thread = thread;
        dragging_item = 0;
@@ -1292,28 +1190,36 @@ int BatchRenderList::selection_changed()
 {
        thread->current_job = get_selection_number(0, 0);
        thread->gui->change_job();
-       if(get_cursor_x() < thread->column_width[0])
-       {
-               BatchRenderJob *job = thread->get_current_job();
+       int cursor_x = get_cursor_x();
+       BatchRenderJob *job = thread->get_current_job();
+       int col_x = 0, changed = 1;
+       if( cursor_x < (col_x += thread->list_width[ENABLED_COL]) )
                job->enabled = !job->enabled;
+       else if( cursor_x < (col_x += thread->list_width[LABELED_COL]) )
+               job->labeled = job->edl_path[0] != '@' ? !job->labeled : 0;
+       else if( thread->gui->use_renderfarm &&
+                cursor_x < (col_x += thread->list_width[FARMED_COL]) )
+               job->farmed = job->edl_path[0] != '@' ? !job->farmed : 0;
+       else
+               changed = 0;
+       if( changed ) {
                thread->gui->create_list(1);
+               thread->gui->change_job();
        }
        return 1;
 }
 
 int BatchRenderList::column_resize_event()
 {
-       for(int i = 0; i < BATCHRENDER_COLUMNS; i++)
-       {
-               thread->column_width[i] = get_column_width(i);
+       for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
+               thread->list_width[i] = get_column_width(i);
        }
        return 1;
 }
 
 int BatchRenderList::drag_start_event()
 {
-       if(BC_ListBox::drag_start_event())
-       {
+       if( BC_ListBox::drag_start_event() ) {
                dragging_item = 1;
                return 1;
        }
@@ -1323,8 +1229,7 @@ int BatchRenderList::drag_start_event()
 
 int BatchRenderList::drag_motion_event()
 {
-       if(BC_ListBox::drag_motion_event())
-       {
+       if( BC_ListBox::drag_motion_event() ) {
                return 1;
        }
        return 0;
@@ -1332,37 +1237,22 @@ int BatchRenderList::drag_motion_event()
 
 int BatchRenderList::drag_stop_event()
 {
-       if(dragging_item)
-       {
+       if( dragging_item ) {
                int src = get_selection_number(0, 0);
                int dst = get_highlighted_item();
-               if(src != dst)
-               {
+               if( src != dst ) {
                        thread->move_batch(src, dst);
                }
                BC_ListBox::drag_stop_event();
+               dragging_item = 0;
        }
        return 0;
 }
 
 
 
-
-
-
-
-
-
-
-
-
-
-BatchRenderStart::BatchRenderStart(BatchRenderThread *thread,
-       int x,
-       int y)
- : BC_GenericButton(x,
-       y,
-       _("Start"))
+BatchRenderStart::BatchRenderStart(BatchRenderThread *thread, int x, int y)
+ : BC_GenericButton(x, y, _("Start"))
 {
        this->thread = thread;
 }
@@ -1373,12 +1263,8 @@ int BatchRenderStart::handle_event()
        return 1;
 }
 
-BatchRenderStop::BatchRenderStop(BatchRenderThread *thread,
-       int x,
-       int y)
- : BC_GenericButton(x,
-       y,
-       _("Stop"))
+BatchRenderStop::BatchRenderStop(BatchRenderThread *thread, int x, int y)
+ : BC_GenericButton(x, y, _("Stop"))
 {
        this->thread = thread;
 }
@@ -1392,12 +1278,20 @@ int BatchRenderStop::handle_event()
 }
 
 
-BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread,
-       int x,
-       int y)
- : BC_GenericButton(x,
-       y,
-       _("Close"))
+BatchRenderWarning::BatchRenderWarning(BatchRenderThread *thread, int x, int y)
+ : BC_CheckBox(x, y, thread->warn, _("warn if jobs/session mismatched"))
+{
+       this->thread = thread;
+}
+
+int BatchRenderWarning::handle_event()
+{
+       thread->warn = get_value();
+       return 1;
+}
+
+BatchRenderCancel::BatchRenderCancel(BatchRenderThread *thread, int x, int y)
+ : BC_GenericButton(x, y, _("Close"))
 {
        this->thread = thread;
 }
@@ -1413,8 +1307,7 @@ int BatchRenderCancel::handle_event()
 
 int BatchRenderCancel::keypress_event()
 {
-       if(get_keypress() == ESC)
-       {
+       if( get_keypress() == ESC ) {
                unlock_window();
                thread->stop_rendering();
                lock_window("BatchRenderCancel::keypress_event");
@@ -1424,3 +1317,23 @@ int BatchRenderCancel::keypress_event()
        return 0;
 }
 
+BatchRenderUseFarm::BatchRenderUseFarm(BatchRenderThread *thread, int x, int y, int *output)
+ : BC_CheckBox(x, y, *output, _("Use render farm"))
+{
+       this->thread = thread;
+       this->output = output;
+}
+
+int BatchRenderUseFarm::handle_event()
+{
+       *output = get_value();
+       thread->gui->create_list(1);
+       return 1;
+}
+
+void BatchRenderUseFarm::update(int *output)
+{
+       this->output = output;
+       BC_CheckBox::update(*output);
+}
+