switch move/swap tracks, add mv trk shortcut, update msg
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / batchrender.C
index 40ed1b0b68bb33581fc33815af8bd48a82f1fdb2..6dcdbc62f69fd7bf8fcd0015f011de87b2e93786 100644 (file)
@@ -39,6 +39,7 @@
 #include "keys.h"
 #include "labels.h"
 #include "language.h"
+#include "localsession.h"
 #include "mainerror.h"
 #include "mainundo.h"
 #include "mainsession.h"
@@ -120,6 +121,8 @@ BatchRenderJob *BatchRenderJob::copy()
 void BatchRenderJob::load(FileXML *file)
 {
        int result = 0;
+       char job_title[BCSTRLEN];
+       strcpy(job_title, file->tag.title);
 
        enabled = file->tag.get_property("ENABLED", enabled);
        farmed = file->tag.get_property("FARMED", farmed);
@@ -137,7 +140,7 @@ void BatchRenderJob::load(FileXML *file)
 // coding maintenance.  The defaults must now be stuffed into the XML for
 // unique storage.
                        BC_Hash defaults;
-                       defaults.load_string(file->read_text());
+                       defaults.load_string(file->read_text(job_title));
                        asset->load_defaults(&defaults,
                                "", 0, 1, 0, 0, 0);
                }
@@ -178,7 +181,9 @@ char *BatchRenderJob::create_script(EDL *edl, ArrayList<Indexable *> *idxbls)
 
 int BatchRenderJob::get_strategy()
 {
-       return Render::get_strategy(farmed, labeled);
+       int range = File::is_image_render(asset->format) ?
+               RANGE_1FRAME : RANGE_SELECTION;
+       return Render::get_strategy(farmed, labeled, range);
 }
 
 
@@ -315,7 +320,7 @@ void BatchRenderThread::load_defaults(BC_Hash *defaults)
        for( int i = 0; i < BATCHRENDER_COLUMNS; i++ ) {
                char string[BCTEXTLEN];
                sprintf(string, "BATCHRENDER_COLUMN%d", i);
-               list_width[i] = defaults->get(string, column_widths[i]);
+               list_width[i] = defaults->get(string, xS(column_widths[i]));
        }
 }
 
@@ -408,21 +413,45 @@ char* BatchRenderThread::get_current_edl()
        return get_current_job()->edl_path;
 }
 
+int BatchRenderThread::test_errmsg(BatchRenderWarnJobs &err_jobs, const char *msg, int *warn)
+{
+       int count = err_jobs.size();
+       if( !count ) return 0;
+       fprintf(stderr, msg, count);
+       char string[BCTEXTLEN], *sp = string, *ep = sp+sizeof(string)-1;
+       sp += snprintf(sp,ep-sp, msg,count);
+       for( int i=0; i<count; ++i ) {
+               int no = err_jobs[i].no;
+               const char *path = err_jobs[i].path;
+               fprintf(stderr, "%d: %s\n", no, path);
+               sp += snprintf(sp,ep-sp, "%d: %s\n", no, path);
+       }
+       sp += snprintf(sp,ep-sp, _("press cancel to abandon batch render"));
+       mwindow->show_warning(warn, string);
+       if( mwindow->wait_warning() ) {
+               gui->button_enable();
+       }
+       return 1;
+}
 
 // Test EDL files for existence
 int BatchRenderThread::test_edl_files()
 {
-       int not_equiv = 0, ret = 0;
+       int ret = 0;
        const char *path = 0;
+       BatchRenderWarnJobs not_equiv;
+       BatchRenderWarnJobs empty_jobs;
+       BatchRenderWarnJobs no_labels;
+       BatchRenderWarnJobs no_rendering;
 
        for( int i=0; !ret && i<jobs.size(); ++i ) {
                if( !jobs.values[i]->enabled ) continue;
-               path = jobs.values[i]->edl_path;
+               path = jobs[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 ) {
+                       if( mwindow && !is_script ) {
                                char *bfr = 0;  size_t sz = 0;
                                struct stat st;
                                if( !fstat(fileno(fp), &st) ) {
@@ -440,7 +469,17 @@ int BatchRenderThread::test_edl_files()
                                        file.set_shared_input(&data);
                                        edl->load_xml(&file, LOAD_ALL); }
                                        double pos = edl->equivalent_output(mwindow->edl);
-                                       if( pos >= 0 ) ++not_equiv;
+                                       if( pos >= 0 )
+                                               not_equiv.add(i+1, path);
+                                       double length = edl->tracks->total_playable_length();
+                                       double start = edl->local_session->get_selectionstart(1);
+                                       if( start >= length )
+                                               empty_jobs.add(i+1, path);
+                                       if( jobs[i]->labeled && !edl->labels->first)
+                                               no_labels.add(i+1,path);
+                                       Asset *asset = jobs[i]->asset;
+                                       if( !asset->audio_data && !asset->video_data )
+                                               no_rendering.add(i+1,path);
                                        edl->remove_user();
                                }
                                delete [] bfr;
@@ -466,21 +505,21 @@ int BatchRenderThread::test_edl_files()
                        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);
+               ret = 1;
        }
 
+       if( !ret && warn && mwindow ) {
+               ret = test_errmsg(not_equiv, _("%d job EDLs do not match session edl\n"), &warn);
+               if( !warn ) gui->warning->update(0);
+       }
+       if( !ret && mwindow )
+               ret = test_errmsg(empty_jobs, _("%d job EDLs begin position beyond end of media\n"), 0);
+       if( !ret && mwindow )
+               ret = test_errmsg(no_rendering, _("%d job EDLs no audio or video in render asset format\n"), 0);
+       if( !ret && mwindow )
+               ret = test_errmsg(no_labels, _("%d job EDLs Create new file at labels checked, but no labels\n"), 0);
+       if( ret )
+               is_rendering = 0;
        return ret;
 }
 
@@ -506,12 +545,13 @@ void BatchRenderThread::calculate_dest_paths(ArrayList<char*> *paths,
                        command->playback_range_adjust_inout();
 
 // Create test packages
-                       packages->create_packages(mwindow, command->get_edl(),
+                       int result = packages->create_packages(mwindow, command->get_edl(),
                                preferences, job->get_strategy(), job->asset,
                                command->start_position, command->end_position, 0);
+                       if( !result )
+                               packages->get_package_paths(paths);
 
 // Append output paths allocated to total
-                       packages->get_package_paths(paths);
 
 // Delete package harness
                        delete packages;
@@ -688,7 +728,7 @@ void BatchRenderThread::trap_hook(FILE *fp, void *vp)
 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
        BatchRenderThread *thread, int x, int y, int w, int h)
  : BC_Window(_(PROGRAM_NAME ": Batch Render"),
-       x, y, w, h, 730, 400, 1, 0, 1)
+       x, y, w, h, xS(730), yS(400), 1, 0, 1)
 {
        this->mwindow = mwindow;
        this->thread = thread;
@@ -707,21 +747,23 @@ BatchRenderGUI::~BatchRenderGUI()
 
 void BatchRenderGUI::create_objects()
 {
+       int xs10 = xS(10), xs30 = xS(30), xs40 = xS(40);
+       int ys5 = yS(5), ys10 = yS(10), ys15 = yS(15);
        lock_window("BatchRenderGUI::create_objects");
        mwindow->theme->get_batchrender_sizes(this, get_w(), get_h());
        create_list(0);
 
        int x = mwindow->theme->batchrender_x1;
-       int y = 5;
-       int x1 = x, x2 = get_w()/2 + 30; // mwindow->theme->batchrender_x2;
-       int y1 = 5, y2 = 5;
+       int y = ys5;
+       int x1 = x, x2 = get_w()/2 + xs30; // mwindow->theme->batchrender_x2;
+       int y1 = ys5, y2 = ys5;
 
 // output file
        add_subwindow(output_path_title = new BC_Title(x1, y1, _("Output path:")));
        y1 += output_path_title->get_h() + mwindow->theme->widget_border;
 
        format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
-       format_tools->set_w(x2 - 40);
+       format_tools->set_w(x2 - xs40);
        BatchRenderJob *current_job = thread->get_current_job();
        format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
                        thread->do_labeled ? &current_job->labeled : 0, 0);
@@ -731,7 +773,7 @@ void BatchRenderGUI::create_objects()
                use_renderfarm = new BatchRenderUseFarm(thread, x1, y1,
                        &current_job->farmed);
                add_subwindow(use_renderfarm);
-               y1 += use_renderfarm->get_h() + 10;
+               y1 += use_renderfarm->get_h() + ys10;
                if( thread->do_farmed < 0 )
                        use_renderfarm->disable();
        }
@@ -742,7 +784,7 @@ void BatchRenderGUI::create_objects()
 
        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 - xs40, thread->get_current_edl()));
        x =  x2 + edl_path_text->get_w();
        add_subwindow(edl_path_browse = new BrowseButton(
                mwindow->theme, this, edl_path_text, x, y, thread->get_current_edl(),
@@ -773,15 +815,15 @@ void BatchRenderGUI::create_objects()
        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;
+       y1 -= ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
        add_subwindow(batch_list = new BatchRenderList(thread, x, y,
-               get_w() - x - 10, y1 - y));
+               get_w() - x - xs10, y1 - y));
        y += batch_list->get_h() + mwindow->theme->widget_border;
 
        add_subwindow(start_button = new BatchRenderStart(thread, x, y));
        x = get_w() / 2 - BC_GenericButton::calculate_w(this, _("Stop")) / 2;
        add_subwindow(stop_button = new BatchRenderStop(thread, x, y));
-       x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - 10;
+       x = get_w() - BC_GenericButton::calculate_w(this, _("Close")) - xs10;
        add_subwindow(cancel_button = new BatchRenderCancel(thread, x, y));
 
        show_window(1);
@@ -807,14 +849,16 @@ void BatchRenderGUI::button_enable()
 
 int BatchRenderGUI::resize_event(int w, int h)
 {
+       int xs10 = xS(10), xs40 = xS(40);
+       int ys5 = yS(5), ys15 = yS(15);
        mwindow->session->batchrender_w = w;
        mwindow->session->batchrender_h = h;
        mwindow->theme->get_batchrender_sizes(this, w, h);
 
        int x = mwindow->theme->batchrender_x1;
-       int y = 5;
-       int x1 = x, x2 = get_w()/2 + 10; // mwindow->theme->batchrender_x2;
-       int y1 = 5, y2 = 5;
+       int y = ys5;
+       int x1 = x, x2 = get_w()/2 + xs10; // mwindow->theme->batchrender_x2;
+       int y1 = ys5, y2 = ys5;
 
 // output file
        output_path_title->reposition_window(x1, y1);
@@ -826,7 +870,7 @@ int BatchRenderGUI::resize_event(int w, int h)
        x = x2, y = y2;
        edl_path_title->reposition_window(x, y);
        y += edl_path_title->get_h() + mwindow->theme->widget_border;
-       edl_path_text->reposition_window(x, y, w - x - 40);
+       edl_path_text->reposition_window(x, y, w - x - xs40);
        x += edl_path_text->get_w();
        edl_path_browse->reposition_window(x, y);
        y2 = y + edl_path_browse->get_h() + mwindow->theme->widget_border;
@@ -847,20 +891,20 @@ int BatchRenderGUI::resize_event(int w, int h)
        y += loadlist_batch->get_h() + mwindow->theme->widget_border;
        warning->reposition_window(x2, y);
 
-       y1 = 15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
+       y1 = ys15 + BC_GenericButton::calculate_h() + mwindow->theme->widget_border;
        y2 = get_h() - y1 - batch_list->get_h();
        y2 -= list_title->get_h() + mwindow->theme->widget_border;
 
        x = mwindow->theme->batchrender_x1;  y = y2;
        list_title->reposition_window(x, y);
        y += list_title->get_h() + mwindow->theme->widget_border;
-       batch_list->reposition_window(x, y, w - x - 10, h - y - y1);
+       batch_list->reposition_window(x, y, w - x - xs10, h - y - y1);
        y += batch_list->get_h() + mwindow->theme->widget_border;
 
        start_button->reposition_window(x, y);
        x = w / 2 - stop_button->get_w() / 2;
        stop_button->reposition_window(x, y);
-       x = w - cancel_button->get_w() - 10;
+       x = w - cancel_button->get_w() - xs10;
        cancel_button->reposition_window(x, y);
        return 1;
 }
@@ -1067,7 +1111,8 @@ void BatchRenderSaveList::run()
        char default_path[BCTEXTLEN];
        sprintf(default_path, "~");
        thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
-       BC_FileBox filewindow(100, 100, default_path, _("Save Batch Render List"),
+       BC_FileBox filewindow(xS(100), yS(100), default_path,
+                       _("Save Batch Render List"),
                        _("Enter a Batch Render filename to save as:"),
                        0, 0, 0, 0);
        gui = &filewindow;
@@ -1145,7 +1190,7 @@ void BatchRenderLoadList::run()
        char default_path[BCTEXTLEN];
        sprintf(default_path, "~");
        thread->mwindow->defaults->get("DEFAULT_BATCHLOADPATH", default_path);
-       BC_FileBox filewindow(100, 100, default_path, _("Load Batch Render List"),
+       BC_FileBox filewindow(xS(100), yS(100), default_path, _("Load Batch Render List"),
                        _("Enter a Batch Render filename to load from:"),
                        0, 0, 0, 0);
        gui = &filewindow;
@@ -1155,6 +1200,7 @@ void BatchRenderLoadList::run()
 
        int result2 = filewindow.run_window();
        if( !result2 ) {
+               thread->gui->lock_window("BatchRenderLoadList::run");
                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);
@@ -1162,6 +1208,7 @@ void BatchRenderLoadList::run()
                thread->gui->create_list(1);
                thread->current_job = 0;
                thread->gui->change_job();
+               thread->gui->unlock_window();
        }
 
        startup_lock->lock("BatchRenderLoadList::run");