collect_proxy nested_clip/edl fixes
authorGood Guy <good1.2guy@gmail.com>
Sun, 28 Jun 2020 01:00:12 +0000 (19:00 -0600)
committerGood Guy <good1.2guy@gmail.com>
Sun, 28 Jun 2020 01:00:12 +0000 (19:00 -0600)
cinelerra-5.1/cinelerra/asset.C
cinelerra-5.1/cinelerra/asset.h
cinelerra-5.1/cinelerra/awindowgui.C
cinelerra-5.1/cinelerra/awindowgui.h
cinelerra-5.1/cinelerra/edl.C
cinelerra-5.1/cinelerra/edl.h
cinelerra-5.1/cinelerra/mwindow.C
cinelerra-5.1/cinelerra/proxy.C
cinelerra-5.1/cinelerra/proxy.h

index fe169cbcd0d2623332b85f0135350ff39d72d388..751660ad9cc06aec8a70d82f890b2f258d2c59b2 100644 (file)
@@ -165,6 +165,7 @@ void Asset::reset_video()
        actual_width = width = 0;
        actual_height = height = 0;
        proxy_scale = 0; // not a proxy
+       proxy_edl = 0; // not proxy from edl
        video_length = 0;
        single_frame = 0;
        vmpeg_cmodel = BC_YUV420P;
@@ -226,6 +227,7 @@ void Asset::copy_format(Asset *asset, int do_index)
        actual_width = asset->actual_width;
        actual_height = asset->actual_height;
        proxy_scale = asset->proxy_scale;
+       proxy_edl = asset->proxy_edl;
        strcpy(vcodec, asset->vcodec);
        strcpy(acodec, asset->acodec);
 
@@ -470,6 +472,7 @@ int Asset::read_video(FileXML *file)
        height = file->tag.get_property("HEIGHT", height);
        width = file->tag.get_property("WIDTH", width);
        proxy_scale = file->tag.get_property("PROXY_SCALE", 0);
+       proxy_edl = file->tag.get_property("PROXY_EDL", 0);
        layers = file->tag.get_property("LAYERS", layers);
        program = file->tag.get_property("PROGRAM", program);
 // This is loaded from the index file after the EDL but this
@@ -638,6 +641,7 @@ int Asset::write_video(FileXML *file)
        file->tag.set_property("HEIGHT", height);
        file->tag.set_property("WIDTH", width);
        file->tag.set_property("PROXY_SCALE", proxy_scale);
+       file->tag.set_property("PROXY_EDL", proxy_edl);
        file->tag.set_property("LAYERS", layers);
        file->tag.set_property("PROGRAM", program);
        file->tag.set_property("FRAMERATE", frame_rate);
@@ -741,6 +745,7 @@ void Asset::load_defaults(BC_Hash *defaults,
                actual_height = GET_DEFAULT("ACTUAL_HEIGHT", actual_height);
                actual_width = GET_DEFAULT("ACTUAL_WIDTH", actual_width);
                proxy_scale = GET_DEFAULT("PROXY_SCALE", proxy_scale);
+               proxy_edl = GET_DEFAULT("PROXY_SCALE", proxy_edl);
                program = GET_DEFAULT("PROGRAM", program);
                layers = GET_DEFAULT("LAYERS", layers);
                if(EQUIV(frame_rate, 0)) frame_rate = GET_DEFAULT("FRAMERATE", frame_rate);
@@ -944,6 +949,7 @@ void Asset::save_defaults(BC_Hash *defaults,
                UPDATE_DEFAULT("ACTUAL_HEIGHT", actual_height);
                UPDATE_DEFAULT("ACTUAL_WIDTH", actual_width);
                UPDATE_DEFAULT("PROXY_SCALE", proxy_scale);
+               UPDATE_DEFAULT("PROXY_EDL", proxy_edl);
                UPDATE_DEFAULT("PROGRAM", program);
                UPDATE_DEFAULT("LAYERS", layers);
                UPDATE_DEFAULT("FRAMERATE", frame_rate);
@@ -989,9 +995,9 @@ int Asset::dump(FILE *fp)
                " height %d vcodec %s aspect_ratio %f ilace_mode %s\n",
                video_data, layers, program, frame_rate, width, height,
                vcodec, aspect_ratio,string);
-       fprintf(fp,"   actual_width %d actual_height %d proxy_scale %d"
+       fprintf(fp,"   actual_width %d actual_height %d proxy_scale %d proxy_edl %d"
                " video_length %jd repeat %d\n",
-               actual_width, actual_height, proxy_scale, video_length,
+               actual_width, actual_height, proxy_scale, proxy_edl, video_length,
                single_frame);
        fprintf(fp,"   video_length %jd repeat %d\n", video_length, single_frame);
        fprintf(fp,"   mov_sphere=%d jpeg_sphere=%d\n", mov_sphere, jpeg_sphere);
index 92b15794ced82f6f31a2144c87ad78c114564cf4..ce922c22c1e61aaed9c35a73f0a348d975b74527 100644 (file)
@@ -147,8 +147,8 @@ public:
 
        int actual_width, actual_height;
        int width, height;
-// scale factor or 0 if not proxy
-       int proxy_scale;
+// scale factor or 0 if not proxy, proxy_edl if proxyed from nested_edl
+       int proxy_scale, proxy_edl;
 // String or FourCC describing compression
        char vcodec[BCTEXTLEN];
 
index 33e3cbc8bd33a7aa93513a6c368797deb23e52da..a0a2d5cfde8499e2f5024820fc1c0ef9bfdaf203 100644 (file)
@@ -2210,14 +2210,16 @@ void AWindowGUI::sort_folders()
        update_assets();
 }
 
-EDL *AWindowGUI::collect_proxy(Indexable *indexable)
+EDL *AWindowGUI::collect_proxy(Asset *proxy_asset)
 {
-       Asset *proxy_asset = (Asset *)indexable;
        char path[BCTEXTLEN];
        int proxy_scale = mwindow->edl->session->proxy_scale;
        ProxyRender::from_proxy_path(path, proxy_asset, proxy_scale);
-       Asset *unproxy_asset = mwindow->edl->assets->get_asset(path);
-       if( !unproxy_asset || !unproxy_asset->layers ) return 0;
+       Indexable *unproxy_idxbl =
+               proxy_asset->proxy_edl ?
+                       (Indexable *) mwindow->edl->get_nested_edl(path) :
+                       (Indexable *) mwindow->edl->assets->get_asset(path);
+       if( !unproxy_idxbl || !unproxy_idxbl->get_video_layers() ) return 0;
 // make a clip from proxy video tracks and unproxy audio tracks
        EDL *proxy_edl = new EDL(mwindow->edl);
        proxy_edl->create_objects();
@@ -2226,7 +2228,7 @@ EDL *AWindowGUI::collect_proxy(Indexable *indexable)
        strcpy(proxy_edl->local_session->clip_title, path);
        strcpy(proxy_edl->local_session->clip_notes, _("Proxy clip"));
        proxy_edl->session->video_tracks = proxy_asset->layers;
-       proxy_edl->session->audio_tracks = unproxy_asset->channels;
+       proxy_edl->session->audio_tracks = unproxy_idxbl->get_audio_channels();
        proxy_edl->create_default_tracks();
        double length = proxy_asset->frame_rate > 0 ?
                ( proxy_asset->video_length >= 0 ?
@@ -2240,11 +2242,15 @@ EDL *AWindowGUI::collect_proxy(Indexable *indexable)
                if( current->data_type != TRACK_VIDEO ) continue;
                current->insert_asset(proxy_asset, 0, length, 0, vtrack++);
        }
-       length = (double)unproxy_asset->audio_length / unproxy_asset->sample_rate;
+       int64_t samples = unproxy_idxbl->get_audio_samples();
+       int sample_rate = unproxy_idxbl->get_sample_rate();
+       length = sample_rate > 0 ? (double)samples / sample_rate : 0;
        current = proxy_edl->tracks->first;
        for( int atrack=0; current; current=NEXT ) {
                if( current->data_type != TRACK_AUDIO ) continue;
-               current->insert_asset(unproxy_asset, 0, length, 0, atrack++);
+               Asset *asset = unproxy_idxbl->is_asset ? (Asset *)unproxy_idxbl : 0;
+               EDL *nested_edl = unproxy_idxbl->is_asset ? 0 : (EDL *)unproxy_idxbl;
+               current->insert_asset(asset, nested_edl, length, 0, atrack++);
        }
        proxy_edl->folder_no = AW_PROXY_FOLDER;
        return proxy_edl;
@@ -2260,7 +2266,7 @@ void AWindowGUI::collect_assets(int proxy)
                Indexable *indexable = result->indexable;
                if( proxy && indexable && indexable->is_asset &&
                    indexable->folder_no == AW_PROXY_FOLDER ) {
-                       EDL *drag_edl = collect_proxy(indexable);
+                       EDL *drag_edl = collect_proxy((Asset*)indexable);
                        if( drag_edl ) mwindow->session->drag_clips->append(drag_edl);
                        continue;
                }
@@ -2822,8 +2828,8 @@ int AWindowAssets::handle_event()
                break;
        }
        if( !vwindow || !vwindow->is_running() ) return 1;
-       if( proxy && picon_idxbl ) {
-               picon_edl = gui->collect_proxy(picon_idxbl);
+       if( proxy && picon_idxbl && picon_idxbl->is_asset ) {
+               picon_edl = gui->collect_proxy((Asset*)picon_idxbl);
                picon_idxbl = 0;
        }
 
index 6004247d4f158ec25264b05ff304e8cb6fe22f7a..8584049de27b3e37d829809fffef8c9c599f6aa4 100644 (file)
@@ -271,7 +271,7 @@ public:
        int drag_stop();
 // Collect items into the drag vectors of MainSession
        void collect_assets(int proxy=0);
-       EDL *collect_proxy(Indexable *indexable);
+       EDL *collect_proxy(Asset *asset);
        void create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
                int do_audio,
                int do_video,
index 5df16099ea7de304e2ca7f7f582e03b288c7db4f..cb080aca25103b8349062e069f7200cff3891614 100644 (file)
@@ -601,7 +601,7 @@ void EDL::copy_indexables(EDL *edl)
        }
 }
 
-EDL *EDL::new_nested_edl(EDL *edl, const char *path)
+EDL *EDL::new_nested_clip(EDL *edl, const char *path)
 {
        EDL *nested = new EDL;  // no parent for nested edl
        nested->create_objects();
@@ -614,19 +614,14 @@ EDL *EDL::new_nested_edl(EDL *edl, const char *path)
        return nested;
 }
 
-EDL *EDL::get_nested_edl()
+EDL *EDL::get_nested_edl(const char *path)
 {
-       Track *track = tracks->first;
-       Edit *edit = track ? track->edits->first : 0;
-       EDL *nested = edit && !edit->next && !edit->asset ? edit->nested_edl : 0;
-       while( nested && (track=track->next)!=0 ) {
-               Edit *edit = track->edits->first;
-               if( !edit || edit->next ||
-                   ( edit->nested_edl != nested &&
-                     strcmp(edit->nested_edl->path, nested->path) ) )
-                       nested = 0;
+       for( int i=0; i<nested_edls.size(); ++i ) {
+               EDL *nested_edl = nested_edls[i];
+               if( !strcmp(path, nested_edl->path) )
+                       return nested_edl;
        }
-       return nested;
+       return 0;
 }
 
 
@@ -642,8 +637,8 @@ void EDL::create_nested(EDL *nested)
 {
        int video_tracks = 0, audio_tracks = 0;
        for( Track *track=nested->tracks->first; track!=0; track=track->next ) {
-               if( track->data_type == TRACK_VIDEO && track->is_armed() ) ++video_tracks;
-               if( track->data_type == TRACK_AUDIO && track->is_armed() ) ++audio_tracks;
+               if( track->data_type == TRACK_VIDEO && track->play ) ++video_tracks;
+               if( track->data_type == TRACK_AUDIO && track->play ) ++audio_tracks;
        }
 // renderengine properties
        if( video_tracks > 0 )
index 80aadb2c4f708a07387ff688adc5e40af32a0a2d..5d08285bd5ddd2abf726c73c68618a55c009b6de 100644 (file)
@@ -197,8 +197,8 @@ public:
        int copy_assets(int copy_flags, double start, double end,
                FileXML *file, const char *output_path);
        void copy_indexables(EDL *edl);
-       EDL *new_nested_edl(EDL *edl, const char *path);
-       EDL *get_nested_edl();
+       EDL *new_nested_clip(EDL *edl, const char *path);
+       EDL *get_nested_edl(const char *path);
        EDL *create_nested_clip(EDL *nested);
        void create_nested(EDL *nested);
        void overwrite_clip(EDL *clip);
index f072467e39a6c3475a4aacb2ca72be2026c80d53..49709028846b0a50f886a8a9d4fbc5130f838df2 100644 (file)
@@ -2492,8 +2492,6 @@ int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
                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;
@@ -3431,7 +3429,7 @@ int MWindow::get_hash_color(Edit *edit)
        char path[BCTEXTLEN];
        if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
            edl->session->proxy_scale == 1 ||
-           ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
+           ProxyRender::from_proxy_path(path, (Asset*)idxbl, edl->session->proxy_scale) )
                strcpy(path, idxbl->path);
        char *cp = strrchr(path, '/');
        cp = !cp ? path : cp+1;
@@ -4004,7 +4002,7 @@ void MWindow::clip_to_media()
                char *bp = strrchr(clip->local_session->clip_title, '/');
                bp = bp ? bp+1 : clip->local_session->clip_title;
                cp += snprintf(cp, ep-cp, "%s", bp);
-               EDL *nested = edl->new_nested_edl(clip, path);
+               EDL *nested = edl->new_nested_clip(clip, path);
                edl->clips.remove(clip);
                clip->remove_user();
                mainindexes->add_indexable(nested);
index fbb34fcfc4061e767bb63c8fe0734be1bee07f8f..34f833fbbc6d18cb3693454cdb54f574afdd41e3 100644 (file)
@@ -229,11 +229,11 @@ 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);
 }
 
-int ProxyRender::from_proxy_path(char *new_path, Indexable *indexable, int scale)
+int ProxyRender::from_proxy_path(char *new_path, Asset *asset, int scale)
 {
        char prxy[BCTEXTLEN];
        int n = sprintf(prxy, ".proxy%d", scale);
-       strcpy(new_path, indexable->path);
+       strcpy(new_path, asset->path);
        char *ptr = strstr(new_path, prxy);
        if( !ptr || (ptr[n] != '-' && ptr[n] != '.') ) return 1;
 // remove proxy, path.proxy#-sfx.ext => path.sfx
@@ -242,6 +242,12 @@ int ProxyRender::from_proxy_path(char *new_path, Indexable *indexable, int scale
        char *cp = ptr + n;
        for( *cp='.'; cp<ext; ++cp ) *ptr++ = *cp;
        *ptr = 0;
+       if( asset->proxy_edl ) {
+               if( (cp = strrchr(new_path, '/')) != 0 ) {
+                       for( ptr=new_path; *++cp; ) *ptr++ = *cp;
+                       *ptr = 0;
+               }
+       }
        return 0;
 }
 
@@ -307,6 +313,7 @@ Asset *ProxyRender::add_original(Indexable *idxbl, int new_scale)
                        proxy->video_length = video_frames;
                }
                proxy->folder_no = AW_PROXY_FOLDER;
+               proxy->proxy_edl = !idxbl->is_asset ? 1 : 0;
                proxy->audio_data = 0;
                proxy->video_data = 1;
                proxy->layers = 1;
index 7f88686dda1b7579a550cbf4a5fe70555525f821..b134b910be78a42a17bac33b1f3450d3c05082aa 100644 (file)
@@ -67,7 +67,7 @@ public:
        ProxyRender(MWindow *mwindow, Asset *format_asset, int asset_scale);
        ~ProxyRender();
        void to_proxy_path(char *new_path, Indexable *indexable, int scale);
-       static int from_proxy_path(char *new_path, Indexable *indexable, int scale);
+       static int from_proxy_path(char *new_path, Asset *asset, int scale);
 
        ArrayList<Indexable *> orig_idxbls;   // originals which match the proxy assets
        ArrayList<Indexable *> orig_proxies;  // proxy assets