rework set default transtion, nested proxy edl fixes, doubleclick proxy media fix...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / proxy.C
index faafc8005f36ab2d533e093fa3ed602c3ebb6bb1..9f25a7e1131ca32b0db95594adefa037b539ebbb 100644 (file)
@@ -33,6 +33,7 @@
 #include "formattools.h"
 #include "language.h"
 #include "mainerror.h"
+#include "mainindexes.h"
 #include "mainprogress.h"
 #include "mainundo.h"
 #include "mutex.h"
@@ -55,6 +56,11 @@ ProxyMenuItem::ProxyMenuItem(MWindow *mwindow)
 {
        this->mwindow = mwindow;
        set_alt();
+       dialog = 0;
+}
+ProxyMenuItem::~ProxyMenuItem()
+{
+       delete dialog;
 }
 
 void ProxyMenuItem::create_objects()
@@ -78,7 +84,9 @@ ProxyDialog::ProxyDialog(MWindow *mwindow)
        asset = new Asset;
        bzero(size_text, sizeof(char*) * MAX_SIZES);
        bzero(size_factors, sizeof(int) * MAX_SIZES);
-       total_sizes = 0;
+       size_text[0] = cstrdup(_("Original size"));
+       size_factors[0] = 1;
+       total_sizes = 1;
 }
 
 ProxyDialog::~ProxyDialog()
@@ -94,7 +102,7 @@ BC_Window* ProxyDialog::new_gui()
        asset->load_defaults(mwindow->defaults, "PROXY_", 1, 1, 0, 0, 0);
        mwindow->gui->lock_window("ProxyDialog::new_gui");
        int cx, cy;
-       mwindow->gui->get_abs_cursor_xy(cx, cy);
+       mwindow->gui->get_abs_cursor(cx, cy);
        gui = new ProxyWindow(mwindow, this, cx - WIDTH/2, cy - HEIGHT/2);
        gui->create_objects();
        mwindow->gui->unlock_window();
@@ -191,6 +199,26 @@ void ProxyDialog::to_proxy()
                        orig_idxbls.append(orig_asset);
                        orig_asset->add_user();
                }
+               for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
+                       EDL *orig_nested = edl->nested_edls[i];
+                       char new_path[BCTEXTLEN];
+                       if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
+                               continue;
+                       proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
+// test if proxy asset was already added to proxy_assets
+                       int got_it = 0;
+                       for( int i = 0; !got_it && i<proxy_assets.size(); ++i )
+                               got_it = !strcmp(proxy_assets[i]->path, new_path);
+                       if( got_it ) continue;
+                       Asset *proxy_nested = edl->assets->get_asset(new_path);
+                       if( !proxy_nested ) continue;
+// add pointer to existing EDL asset if it exists
+// EDL won't delete it unless it's the same pointer.
+                       proxy_assets.append(proxy_nested);
+                       proxy_nested->add_user();
+                       orig_idxbls.append(orig_nested);
+                       orig_nested->add_user();
+               }
 
 // convert from the proxy assets to the original assets
                int proxy_auto_scale = edl->session->proxy_auto_scale;
@@ -202,6 +230,8 @@ void ProxyDialog::to_proxy()
                        proxy->width = proxy->actual_width;
                        proxy->height = proxy->actual_height;
                        proxy->remove_user();
+                       mwindow->edl->assets->remove_pointer(proxy);
+                       proxy->remove_user();
                }
                proxy_assets.remove_all();
                for( int i = 0; i < orig_idxbls.size(); i++ )
@@ -228,6 +258,19 @@ void ProxyDialog::to_proxy()
                                proxy_render.add_needed(orig, proxy);
                        }
                }
+               for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
+                       EDL *orig_nested = edl->nested_edls[i];
+                       Asset *proxy = proxy_render.add_original(orig_nested, new_scale);
+                       if( !proxy ) continue;
+                       int exists = fs.get_size(proxy->path) > 0 ? 1 : 0;
+                       int got_it = exists && // if proxy exists, and is newer than orig_nested
+                           fs.get_date(proxy->path) > fs.get_date(orig_nested->path) ? 1 : 0;
+                       if( !got_it ) {
+                               if( exists ) // prompt user to overwrite
+                                       confirm_paths.append(cstrdup(proxy->path));
+                               proxy_render.add_needed(orig_nested, proxy);
+                       }
+               }
        }
 
        int result = 0;
@@ -249,7 +292,7 @@ void ProxyDialog::to_proxy()
        mwindow->restart_brender();
 
        mwindow->gui->lock_window("ProxyDialog::to_proxy");
-       mwindow->update_project(LOAD_ALL);
+       mwindow->update_project(LOADMODE_REPLACE);
        mwindow->gui->unlock_window();
 }
 
@@ -281,19 +324,20 @@ void ProxyRender::to_proxy_path(char *new_path, Indexable *indexable, int scale)
 //printf("ProxyRender::to_proxy_path %d %s %s\n", __LINE__, new_path), asset->path);
 }
 
-void ProxyRender::from_proxy_path(char *new_path, Asset *asset, int scale)
+int ProxyRender::from_proxy_path(char *new_path, Indexable *indexable, int scale)
 {
        char prxy[BCTEXTLEN];
        int n = sprintf(prxy, ".proxy%d", scale);
-       strcpy(new_path, asset->path);
-       char *ptr = strstr(asset->path, prxy);
-       if( !ptr || (ptr[n] != '-' && ptr[n] != '.') ) return;
+       strcpy(new_path, indexable->path);
+       char *ptr = strstr(new_path, prxy);
+       if( !ptr || (ptr[n] != '-' && ptr[n] != '.') ) return 1;
 // remove proxy, path.proxy#-sfx.ext => path.sfx
        char *ext = strrchr(ptr, '.');
        if( !ext ) ext = ptr + strlen(ptr);
        char *cp = ptr + n;
        for( *cp='.'; cp<ext; ++cp ) *ptr++ = *cp;
        *ptr = 0;
+       return 0;
 }
 
 ProxyRender::ProxyRender(MWindow *mwindow, Asset *format_asset)
@@ -449,9 +493,6 @@ void ProxyWindow::create_objects()
        add_subwindow(text = new BC_Title(x, y, _("Scale factor:")));
        x += text->get_w() + margin;
 
-       dialog->size_text[0] = cstrdup(_("Original size"));
-       dialog->size_factors[0] = 1;
-       dialog->total_sizes = 1;
        int popupmenu_w = BC_PopupMenu::calculate_w(get_text_width(MEDIUMFONT, dialog->size_text[0]));
        add_subwindow(scale_factor = new ProxyMenu(mwindow, this, x, y, popupmenu_w, ""));
        scale_factor->update_sizes();
@@ -753,6 +794,11 @@ void ProxyClient::process_package(LoadPackage *ptr)
                }
                proxy_render->update_progress();
        }
+       if( !proxy_render->failed && !proxy_render->is_canceled() ) {
+               Asset *asset = mwindow->edl->assets->update(proxy);
+               mwindow->mainindexes->add_next_asset(0, asset);
+               mwindow->mainindexes->start_build();
+       }
 }