add edit length update when open_edl changes media length, replace stack_warn with...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / fileref.C
index ab8ecd7f05acd7357c27658947df85bf9876a467..8d9b1ae9f22154bbf976d6eee1128853409bb723 100644 (file)
@@ -75,7 +75,26 @@ int FileREF::open_file(int rd, int wr)
                if( ref ) ref->remove_user();
                ref = new EDL;
                ref->create_objects();
-               ref->load_xml(&file_xml, LOAD_ALL);
+               if( ref->load_xml(&file_xml, LOAD_ALL) ) {
+                       ref->remove_user();
+                       ref = 0;
+                       eprintf(_("Error loading Reference file:\n%s"), asset->path);
+                       return 1;
+               }
+               if( !asset->layers ) asset->layers = ref->get_video_layers();
+               asset->video_data = asset->layers > 0 ? 1 : 0;
+               asset->video_length = asset->video_data ? ref->get_video_frames() : 0;
+               asset->actual_width = asset->video_data ? ref->get_w() : 0;
+               asset->actual_height = asset->video_data ? ref->get_h() : 0;
+               if( !asset->width ) asset->width = asset->actual_width;
+               if( !asset->height ) asset->height = asset->actual_height;
+               if( !asset->frame_rate ) asset->frame_rate = ref->get_frame_rate();
+               strcpy(asset->vcodec, "REF");
+               asset->channels = ref->get_audio_channels();
+               asset->audio_data = asset->channels > 0 ? 1 : 0;
+               asset->sample_rate = ref->get_sample_rate();
+               asset->audio_length = asset->audio_data ? ref->get_audio_samples() : 0;
+               strcpy(asset->acodec, "REF");
                command = new TransportCommand();
                command->reset();
                command->get_edl()->copy_all(ref);
@@ -101,8 +120,8 @@ int FileREF::close_file()
        ref = 0;
        delete render_engine;  render_engine = 0;
        delete command;  command = 0;
-       delete acache;   acache = 0;
-       delete vcache;   vcache = 0;
+       if( acache ) { acache->remove_user();  acache = 0; }
+       if( vcache ) { vcache->remove_user();  vcache = 0; }
        delete temp;     temp = 0;
        for( int i=0; i<MAX_CHANNELS; ++i ) {
                delete samples[i];  samples[i] = 0;