VBR for ffmpeg mpegts, user mount for udf images, widget fixes
[goodguy/history.git] / cinelerra-5.1 / cinelerra / batchrender.C
index a02a8cff87615b23942f0027ca8dca6a9135cc0c..799796ff94eab561b3ab324cb2b345144be96b79 100644 (file)
@@ -140,12 +140,7 @@ 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);
                }
        }
 }
@@ -208,7 +203,7 @@ BatchRenderThread::BatchRenderThread(MWindow *mwindow)
        preferences = 0;
        warn = 1;
        render = 0;
-       file_entries = 0;
+       batch_path[0] = 0;
 }
 
 BatchRenderThread::BatchRenderThread()
@@ -223,7 +218,7 @@ BatchRenderThread::BatchRenderThread()
        preferences = 0;
        warn = 1;
        render = 0;
-       file_entries = 0;
+       batch_path[0] = 0;
 }
 
 BatchRenderThread::~BatchRenderThread()
@@ -232,31 +227,24 @@ BatchRenderThread::~BatchRenderThread()
        delete boot_defaults;
        delete preferences;
        delete render;
-       if( file_entries ) {
-               file_entries->remove_all_objects();
-               delete file_entries;
-       }
 }
 
-void BatchRenderThread::reset(int warn)
+void BatchRenderThread::reset(const char *path)
 {
-       if( warn ) this->warn = 1;
+       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();
 }
@@ -266,26 +254,7 @@ 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,
@@ -304,10 +273,9 @@ 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));
+       if( !path ) path = batch_path;
+       if( !path[0] ) create_path(path);
+       file.read_from_file(path);
 
        while(!result)
        {
@@ -344,10 +312,9 @@ void BatchRenderThread::save_jobs(char *path)
        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)
@@ -595,11 +562,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);
@@ -608,6 +585,7 @@ 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);
@@ -641,11 +619,9 @@ void BatchRenderThread::start_rendering(char *config_path,
 void BatchRenderThread::start_rendering()
 {
        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();
 
@@ -731,7 +707,16 @@ void BatchRenderThread::move_batch(int src, int dst)
        }
 }
 
-
+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);
+}
 
 
 
@@ -740,7 +725,7 @@ void BatchRenderThread::move_batch(int src, int dst)
 BatchRenderGUI::BatchRenderGUI(MWindow *mwindow,
        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;
@@ -772,18 +757,18 @@ void BatchRenderGUI::create_objects()
        format_tools = new BatchFormat(mwindow, this, thread->get_current_asset());
        format_tools->set_w(get_w() / 2);
        format_tools->create_objects(x1, y1, 1, 1, 1, 1, 0, 1, 0, 0,
-                       &thread->get_current_job()->strategy, 0); 
+                       &thread->get_current_job()->strategy, 0);
 
 // 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;
 
@@ -807,6 +792,8 @@ void BatchRenderGUI::create_objects()
        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;
@@ -880,6 +867,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();
@@ -1035,9 +1023,7 @@ 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;
@@ -1081,7 +1067,7 @@ int BatchRenderDelete::handle_event()
 BatchRenderSaveList::BatchRenderSaveList(BatchRenderThread *thread,
        int x,
        int y)
- : BC_GenericButton(x, y, _("Save List"))
+ : BC_GenericButton(x, y, _("Save Jobs"))
 {
        this->thread = thread;
        set_tooltip(_("Save a Batch Render List"));
@@ -1126,27 +1112,21 @@ 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();
@@ -1167,7 +1147,7 @@ int BatchRenderSaveList::keypress_event() {
 BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
        int x,
        int y)
-  : BC_GenericButton(x, y, _("Load List")),
+  : BC_GenericButton(x, y, _("Load Jobs")),
     Thread()
 {
        this->thread = thread;
@@ -1179,8 +1159,7 @@ BatchRenderLoadList::BatchRenderLoadList(BatchRenderThread *thread,
 BatchRenderLoadList::~BatchRenderLoadList()
 {
        startup_lock->lock("BatchRenderLoadList::~BrowseButton");
-       if(gui)
-       {
+       if(gui) {
                gui->lock_window();
                gui->set_done(1);
                gui->unlock_window();
@@ -1192,10 +1171,8 @@ BatchRenderLoadList::~BatchRenderLoadList()
 
 int BatchRenderLoadList::handle_event()
 {
-       if(Thread::running())
-       {
-               if(gui)
-               {
+       if(Thread::running()) {
+               if(gui) {
                        gui->lock_window();
                        gui->raise_window();
                        gui->unlock_window();
@@ -1213,31 +1190,25 @@ 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);
        }
 
-       this->thread->gui->flush();
+       thread->gui->flush();
        startup_lock->lock("BatchRenderLoadList::run");
        gui = 0;
        startup_lock->unlock();