label edit deadlock, build openexr cfg option, code cleanup
[goodguy/history.git] / cinelerra-5.1 / cinelerra / asset.C
index 5350004cd4dbfe5285602b5db1d479b349e88561..af87bdbb91750ed1f2dd9cac55d714c3ca9a21b1 100644 (file)
 
 #include "asset.h"
 #include "assets.h"
+#include "awindowgui.h"
 #include "bchash.h"
 #include "bcsignals.h"
 #include "clip.h"
+#include "cstrdup.h"
 #include "edl.h"
 #include "file.h"
 #include "filesystem.h"
@@ -86,13 +88,13 @@ int Asset::init_values()
        ff_video_options[0] = 0;
        ff_audio_bitrate = 0;
        ff_video_bitrate = 0;
-       ff_video_quality = 0;
+       ff_video_quality = -1;
 
        jpeg_quality = 80;
        aspect_ratio = -1;
-       interlace_autofixoption = BC_ILACE_AUTOFIXOPTION_AUTO;
-       interlace_mode = BC_ILACE_MODE_UNDETECTED;
-       interlace_fixmethod = BC_ILACE_FIXMETHOD_NONE;
+       interlace_autofixoption = ILACE_AUTOFIXOPTION_AUTO;
+       interlace_mode = ILACE_MODE_UNDETECTED;
+       interlace_fixmethod = ILACE_FIXMETHOD_NONE;
 
        ampeg_bitrate = 256;
        ampeg_derivative = 3;
@@ -126,6 +128,7 @@ int Asset::init_values()
        ac3_bitrate = 128;
 
        png_use_alpha = 0;
+
        exr_use_alpha = 0;
        exr_compression = 0;
 
@@ -134,7 +137,6 @@ int Asset::init_values()
 
        use_header = 1;
        id = EDL::next_id();
-       reset_timecode();
 
        return 0;
 }
@@ -154,6 +156,7 @@ void Asset::reset_video()
        actual_width = width = 0;
        actual_height = height = 0;
        video_length = 0;
+       single_frame = 0;
        vmpeg_cmodel = BC_YUV420P;
        frame_rate = 0;
        program = -1;
@@ -172,17 +175,6 @@ void Asset::boundaries()
 //printf("Asset::boundaries %d %d %f\n", __LINE__, sample_rate, frame_rate);
 }
 
-int Asset::reset_timecode()
-{
-       strcpy(reel_name, "cin0000");
-       reel_number = 0;
-       tcstart = 0;
-       tcend = 0;
-       tcformat = 0;
-
-       return 0;
-}
-
 void Asset::copy_from(Asset *asset, int do_index)
 {
        copy_location(asset);
@@ -191,8 +183,8 @@ void Asset::copy_from(Asset *asset, int do_index)
 
 void Asset::copy_location(Asset *asset)
 {
-       strcpy(this->path, asset->path);
-       strcpy(this->folder, asset->folder);
+       strcpy(path, asset->path);
+       awindow_folder = asset->awindow_folder;
 }
 
 void Asset::copy_format(Asset *asset, int do_index)
@@ -235,7 +227,7 @@ void Asset::copy_format(Asset *asset, int do_index)
 
        this->audio_length = asset->audio_length;
        this->video_length = asset->video_length;
-
+       this->single_frame = asset->single_frame;
 
        ampeg_bitrate = asset->ampeg_bitrate;
        ampeg_derivative = asset->ampeg_derivative;
@@ -279,12 +271,6 @@ void Asset::copy_format(Asset *asset, int do_index)
 
        tiff_cmodel = asset->tiff_cmodel;
        tiff_compression = asset->tiff_compression;
-
-       strcpy(reel_name, asset->reel_name);
-       reel_number = asset->reel_number;
-       tcstart = asset->tcstart;
-       tcend = asset->tcend;
-       tcformat = asset->tcformat;
 }
 
 int64_t Asset::get_index_offset(int channel)
@@ -317,24 +303,35 @@ char* Asset::get_compression_text(int audio, int video)
        return 0;
 }
 
-Asset& Asset::operator=(Asset &asset)
-{
-printf("Asset::operator=\n");
-       copy_location(&asset);
-       copy_format(&asset, 1);
-       return *this;
-}
-
-
-int Asset::equivalent(Asset &asset,
-       int test_audio,
-       int test_video)
+int Asset::equivalent(Asset &asset, int test_audio, int test_video, EDL *edl)
 {
-       int result = (!strcmp(asset.path, path) &&
-               format == asset.format);
+       int result = format == asset.format ? 1 : 0;
+       if( result && strcmp(asset.path, path) ) {
+               char *out_path = edl ? FileSystem::basepath(edl->path) : 0;
+               char *sp = out_path ? strrchr(out_path,'/') : 0;
+               if( sp ) *++sp = 0;
+               char *apath = FileSystem::basepath(asset.path);
+               char *tpath = FileSystem::basepath(this->path);
+               if( out_path ) {
+                       if( *apath != '/' ) {
+                               char *cp = cstrcat(2, out_path, apath);
+                               delete [] apath;  apath = FileSystem::basepath(cp);
+                               delete [] cp;
+                       }
+                       if( *tpath != '/' ) {
+                               char *cp = cstrcat(2, out_path, tpath);
+                               delete [] tpath;  tpath = FileSystem::basepath(cp);
+                               delete [] cp;
+                       }
+               }
+               if( strcmp(apath, tpath) ) result = 0;
+               delete [] apath;
+               delete [] tpath;
+               delete [] out_path;
+       }
 
-       if(result && format == FILE_FFMPEG)
-               result = !strcmp(fformat, asset.fformat);
+       if(result && format == FILE_FFMPEG && strcmp(fformat, asset.fformat) )
+               result = 0;
 
        if(test_audio && result)
        {
@@ -363,12 +360,7 @@ int Asset::equivalent(Asset &asset,
                        interlace_fixmethod     == asset.interlace_fixmethod &&
                        width == asset.width &&
                        height == asset.height &&
-                       !strcmp(vcodec, asset.vcodec) &&
-                       strcmp(reel_name, asset.reel_name) == 0 &&
-                       reel_number == asset.reel_number &&
-                       tcstart == asset.tcstart &&
-                       tcend == asset.tcend &&
-                       tcformat == asset.tcformat);
+                       !strcmp(vcodec, asset.vcodec));
                if(result && format == FILE_FFMPEG)
                        result = !strcmp(ff_video_options, asset.ff_video_options) &&
                                ff_video_bitrate == asset.ff_video_bitrate &&
@@ -378,19 +370,6 @@ int Asset::equivalent(Asset &asset,
        return result;
 }
 
-int Asset::operator==(Asset &asset)
-{
-
-       return equivalent(asset,
-               1,
-               1);
-}
-
-int Asset::operator!=(Asset &asset)
-{
-       return !(*this == asset);
-}
-
 int Asset::test_path(const char *path)
 {
        if(!strcasecmp(this->path, path))
@@ -463,7 +442,9 @@ int Asset::read(FileXML *file,
                        else
                        if(file->tag.title_is("FOLDER"))
                        {
-                               strcpy(folder, file->read_text());
+                               const char *string = file->tag.get_property("NUMBER");
+                               awindow_folder = string ? atoi(string) :
+                                       AWindowGUI::folder_number(file->read_text());
                        }
                        else
                        if(file->tag.title_is("VIDEO"))
@@ -504,13 +485,6 @@ int Asset::read_audio(FileXML *file)
        audio_length = file->tag.get_property("AUDIO_LENGTH", (int64_t)0);
        acodec[0] = 0;
        file->tag.get_property("ACODEC", acodec);
-
-       if(!video_data)
-       {
-               tcstart = 0;
-               tcend = audio_length;
-               tcformat = 0;
-       }
        return 0;
 }
 
@@ -532,20 +506,15 @@ int Asset::read_video(FileXML *file)
        file->tag.get_property("VCODEC", vcodec);
 
        video_length = file->tag.get_property("VIDEO_LENGTH", (int64_t)0);
+       single_frame = file->tag.get_property("SINGLE_FRAME", (int64_t)0);
 
        interlace_autofixoption = file->tag.get_property("INTERLACE_AUTOFIX",0);
 
-       ilacemode_to_xmltext(string, BC_ILACE_MODE_NOTINTERLACED);
-       interlace_mode = ilacemode_from_xmltext(file->tag.get_property("INTERLACE_MODE",string), BC_ILACE_MODE_NOTINTERLACED);
-
-       ilacefixmethod_to_xmltext(string, BC_ILACE_FIXMETHOD_NONE);
-       interlace_fixmethod = ilacefixmethod_from_xmltext(file->tag.get_property("INTERLACE_FIXMETHOD",string), BC_ILACE_FIXMETHOD_NONE);
+       ilacemode_to_xmltext(string, ILACE_MODE_NOTINTERLACED);
+       interlace_mode = ilacemode_from_xmltext(file->tag.get_property("INTERLACE_MODE",string), ILACE_MODE_NOTINTERLACED);
 
-       file->tag.get_property("REEL_NAME", reel_name);
-       reel_number = file->tag.get_property("REEL_NUMBER", reel_number);
-       tcstart = file->tag.get_property("TCSTART", tcstart);
-       tcend = file->tag.get_property("TCEND", tcend);
-       tcformat = file->tag.get_property("TCFORMAT", tcformat);
+       ilacefixmethod_to_xmltext(string, ILACE_FIXMETHOD_NONE);
+       interlace_fixmethod = ilacefixmethod_from_xmltext(file->tag.get_property("INTERLACE_FIXMETHOD",string), ILACE_FIXMETHOD_NONE);
 
        return 0;
 }
@@ -591,8 +560,8 @@ int Asset::write(FileXML *file,
        file->append_newline();
 
        file->tag.set_title("FOLDER");
+       file->tag.set_property("NUMBER", awindow_folder);
        file->append_tag();
-       file->append_text(folder);
        file->tag.set_title("/FOLDER");
        file->append_tag();
        file->append_newline();
@@ -692,6 +661,7 @@ int Asset::write_video(FileXML *file)
                file->tag.set_property("VCODEC", vcodec);
 
        file->tag.set_property("VIDEO_LENGTH", video_length);
+       file->tag.set_property("SINGLE_FRAME", single_frame);
 
        file->tag.set_property("INTERLACE_AUTOFIX", interlace_autofixoption);
 
@@ -701,13 +671,6 @@ int Asset::write_video(FileXML *file)
        ilacefixmethod_to_xmltext(string, interlace_fixmethod);
        file->tag.set_property("INTERLACE_FIXMETHOD", string);
 
-
-       file->tag.set_property("REEL_NAME", reel_name);
-       file->tag.set_property("REEL_NUMBER", reel_number);
-       file->tag.set_property("TCSTART", tcstart);
-       file->tag.set_property("TCEND", tcend);
-       file->tag.set_property("TCFORMAT", tcformat);
-
        file->append_tag();
        if(video_data)
                file->tag.set_title("/VIDEO");
@@ -799,6 +762,7 @@ void Asset::load_defaults(BC_Hash *defaults,
                layers = GET_DEFAULT("LAYERS", layers);
                if(EQUIV(frame_rate, 0)) frame_rate = GET_DEFAULT("FRAMERATE", frame_rate);
                video_length = GET_DEFAULT("VIDEO_LENGTH", (int64_t)0);
+               single_frame = GET_DEFAULT("SINGLE_FRAME", (int64_t)0);
        }
 
        ampeg_bitrate = GET_DEFAULT("AMPEG_BITRATE", ampeg_bitrate);
@@ -827,9 +791,9 @@ void Asset::load_defaults(BC_Hash *defaults,
        jpeg_quality = GET_DEFAULT("JPEG_QUALITY", jpeg_quality);
        aspect_ratio = GET_DEFAULT("ASPECT_RATIO", aspect_ratio);
 
-       interlace_autofixoption = BC_ILACE_AUTOFIXOPTION_AUTO;
-       interlace_mode          = BC_ILACE_MODE_UNDETECTED;
-       interlace_fixmethod     = BC_ILACE_FIXMETHOD_UPONE;
+       interlace_autofixoption = ILACE_AUTOFIXOPTION_AUTO;
+       interlace_mode          = ILACE_MODE_UNDETECTED;
+       interlace_fixmethod     = ILACE_FIXMETHOD_UPONE;
 
 // MPEG format information
        vmpeg_iframe_distance = GET_DEFAULT("VMPEG_IFRAME_DISTANCE", vmpeg_iframe_distance);
@@ -861,12 +825,6 @@ void Asset::load_defaults(BC_Hash *defaults,
        tiff_cmodel = GET_DEFAULT("TIFF_CMODEL", tiff_cmodel);
        tiff_compression = GET_DEFAULT("TIFF_COMPRESSION", tiff_compression);
 
-       GET_DEFAULT("REEL_NAME", reel_name);
-       reel_number = GET_DEFAULT("REEL_NUMBER", reel_number);
-       tcstart = GET_DEFAULT("TCSTART", tcstart);
-       tcend = GET_DEFAULT("TCEND", tcend);
-       tcformat = GET_DEFAULT("TCFORMAT", tcformat);
-
        boundaries();
 }
 
@@ -983,14 +941,9 @@ void Asset::save_defaults(BC_Hash *defaults,
                UPDATE_DEFAULT("LAYERS", layers);
                UPDATE_DEFAULT("FRAMERATE", frame_rate);
                UPDATE_DEFAULT("VIDEO_LENGTH", video_length);
+               UPDATE_DEFAULT("SINGLE_FRAME", single_frame);
 
        }
-
-       UPDATE_DEFAULT("REEL_NAME", reel_name);
-       UPDATE_DEFAULT("REEL_NUMBER", reel_number);
-       UPDATE_DEFAULT("TCSTART", tcstart);
-       UPDATE_DEFAULT("TCEND", tcend);
-       UPDATE_DEFAULT("TCFORMAT", tcformat);
 }
 
 
@@ -1024,11 +977,7 @@ int Asset::dump(FILE *fp)
                " height %d vcodec %4.4s aspect_ratio %f ilace_mode %s\n",
                video_data, layers, program, frame_rate, width, height,
                vcodec, aspect_ratio,string);
-       fprintf(fp,"   reel_name %s reel_number %i tcstart %jd tcend %jd tcf %d\n",
-               reel_name, reel_number, tcstart, tcend, tcformat);
-       fprintf(fp,"   video_length %jd \n", video_length);
-
-
+       fprintf(fp,"   video_length %jd repeat %d\n", video_length, single_frame);
        return 0;
 }
 
@@ -1107,23 +1056,3 @@ double Asset::total_length_framealigned(double fps)
        return 0;
 }
 
-int Asset::set_timecode(char *tc, int format, int end)
-{
-       int hr, min, sec;
-
-       hr = ((int) tc[0] - 48) * 10 + (int) tc[1] - 48;
-       min = ((int) tc[3] - 48) * 10 + (int) tc[4] - 48;
-       sec = ((int) tc[6] - 48) * 10 + (int) tc[7] - 48;
-
-       // This needs to be modified to handle drop-frame
-
-       if(end)
-               tcend = (int64_t) (((hr * 3600) + (min * 60) + sec) * frame_rate);
-       else
-               tcstart = (int64_t) (((hr * 3600) + (min * 60) + sec) * frame_rate);
-
-       tcformat = format;
-       return 0;
-}
-
-