repair default keyframe load, tweak init default histogram threshold
[goodguy/history.git] / cinelerra-5.1 / cinelerra / edit.C
index 0792fa443c5a3c179b1306c6f696c2f7e736b9eb..c680d8c634c4854ba86eb64af4eae0449ac17d01 100644 (file)
@@ -32,7 +32,7 @@
 #include "localsession.h"
 #include "plugin.h"
 #include "mainsession.h"
-#include "nestededls.h"
+#include "strack.h"
 #include "trackcanvas.h"
 #include "tracks.h"
 #include "transition.h"
@@ -83,6 +83,8 @@ void Edit::reset()
        user_title[0] = 0;
        nested_edl = 0;
        is_plugin = 0;
+       hard_left = 0;
+       hard_right = 0;
 }
 
 Indexable* Edit::get_source()
@@ -136,6 +138,8 @@ int Edit::copy(int64_t start,
                        file->tag.set_property("STARTSOURCE", startsource_in_selection);
                        file->tag.set_property("CHANNEL", (int64_t)channel);
                        file->tag.set_property("LENGTH", length_in_selection);
+                       file->tag.set_property("HARD_LEFT", hard_left);
+                       file->tag.set_property("HARD_RIGHT", hard_right);
                        if(user_title[0]) file->tag.set_property("USER_TITLE", user_title);
 //printf("Edit::copy 5\n");
 
@@ -150,6 +154,9 @@ int Edit::copy(int64_t start,
                                file->tag.set_title("NESTED_EDL");
                                file->tag.set_property("SRC", nested_edl->path);
                                file->append_tag();
+                               file->tag.set_title("/NESTED_EDL");
+                               file->append_tag();
+                               file->append_newline();
                        }
 
                        if(asset)
@@ -182,7 +189,7 @@ int Edit::copy(int64_t start,
                                file->append_tag();
                        }
 
-                       if(transition)
+                       if(transition && startsource_in_selection == startsource)
                        {
                                transition->save_xml(file);
                        }
@@ -226,17 +233,21 @@ void Edit::detach_transition()
 
 int Edit::silence()
 {
-       return asset || nested_edl ? 0 : 1;
+       return (track->data_type != TRACK_SUBTITLE ?
+               asset || nested_edl :
+               *((SEdit *)this)->get_text()) ? 0 : 1;
 }
 
 
 void Edit::copy_from(Edit *edit)
 {
-       this->nested_edl = edl->nested_edls->get_copy(edit->nested_edl);
+       this->nested_edl = edl->nested_edls.get_nested(edit->nested_edl);
        this->asset = edl->assets->update(edit->asset);
        this->startsource = edit->startsource;
        this->startproject = edit->startproject;
        this->length = edit->length;
+       this->hard_left = edit->hard_left;
+       this->hard_right = edit->hard_right;
        strcpy (this->user_title, edit->user_title);
 
        if(edit->transition)
@@ -279,7 +290,7 @@ void Edit::equivalent_output(Edit *edit, int64_t *result)
                        !transition->identical(edit->transition)) ||
 // Asset changed
                (asset && edit->asset &&
-                       !asset->equivalent(*edit->asset, 1, 1)) ||
+                       !asset->equivalent(*edit->asset, 1, 1, edl)) ||
 // Nested EDL changed
                (nested_edl && edit->nested_edl &&
                        strcmp(nested_edl->path, edit->nested_edl->path))
@@ -312,6 +323,8 @@ int Edit::identical(Edit &edit)
                this->startsource == edit.startsource &&
                this->startproject == edit.startproject &&
                this->length == edit.length &&
+               this->hard_left == edit.hard_left &&
+               this->hard_right == edit.hard_right &&
                this->transition == edit.transition &&
                this->channel == edit.channel);
        return result;
@@ -369,8 +382,8 @@ int Edit::dump(FILE *fp)
                fprintf(fp,"      TRANSITION %p\n", transition);
                transition->dump(fp);
        }
-       fprintf(fp,"      startsource %jd startproject %jd length %jd\n",
-               startsource, startproject, length); fflush(fp);
+       fprintf(fp,"      startsource %jd startproject %jd hard lt/rt %d/%d length %jd\n",
+               startsource, startproject, hard_left, hard_right, length); fflush(fp);
        return 0;
 }
 
@@ -378,6 +391,8 @@ int Edit::load_properties(FileXML *file, int64_t &startproject)
 {
        startsource = file->tag.get_property("STARTSOURCE", (int64_t)0);
        length = file->tag.get_property("LENGTH", (int64_t)0);
+       hard_left = file->tag.get_property("HARD_LEFT", (int64_t)0);
+       hard_right = file->tag.get_property("HARD_RIGHT", (int64_t)0);
        user_title[0] = 0;
        file->tag.get_property("USER_TITLE", user_title);
        this->startproject = startproject;
@@ -538,7 +553,6 @@ int Edit::shift_start_out(int edit_mode,
                                startproject -= cut_length;
                                startsource -= cut_length;
                                length += cut_length;
-printf("Edit::shift_start_out 2\n");
                        }
                        else
                        {   // Clear entire previous edit
@@ -687,11 +701,11 @@ int Edit::shift_end_out(int edit_mode,
 
 // Effects are shifted in length extension
                if(edit_plugins)
-                       edits->shift_effects_recursive(oldposition /* startproject */, 
+                       edits->shift_effects_recursive(oldposition /* startproject */,
                                cut_length,
                                edit_autos);
                if(edit_autos)
-                       edits->shift_keyframes_recursive(oldposition /* startproject */, 
+                       edits->shift_keyframes_recursive(oldposition /* startproject */,
                                cut_length);
 
                for(Edit* current_edit = next; current_edit; current_edit = current_edit->next)
@@ -710,13 +724,17 @@ int Edit::shift_end_out(int edit_mode,
                                next->startproject += cut_length;
                                next->startsource += cut_length;
                                next->length -= cut_length;
-//printf("Edit::shift_end_out 2 %d\n", cut_length);
+//printf("Edit::shift_end_out %d cut_length=%d\n", __LINE__, cut_length);
                        }
                        else
                        {
+//printf("Edit::shift_end_out %d cut_length=%d next->length=%d\n", __LINE__, cut_length, next->length);
                                cut_length = next->length;
+                               next->startproject += next->length;
+                               next->startsource += next->length;
                                next->length = 0;
                                length += cut_length;
+//track->dump();
                        }
                }
                else
@@ -795,7 +813,7 @@ int Edit::select_handle(float view_start, float zoom_units, int cursor_x, int cu
        pixel2 = right;
        pixel1 = pixel2 - 10;
 
-// test right edit     
+// test right edit
        if(cursor_x >= pixel1 && cursor_x <= pixel2)
        {
                selection = right_unit;
@@ -804,3 +822,23 @@ int Edit::select_handle(float view_start, float zoom_units, int cursor_x, int cu
        return 0;
 }
 
+void Edit::get_title(char *title)
+{
+       if( user_title[0] ) {
+               strcpy(title, user_title);
+               return;
+       }
+       Indexable *idxbl = asset ? (Indexable*)asset : (Indexable*)nested_edl;
+       if( !idxbl ) {
+               title[0] = 0;
+               return;
+       }
+       FileSystem fs;
+       fs.extract_name(title, idxbl->path);
+       if( asset || track->data_type == TRACK_AUDIO ) {
+               char number[BCSTRLEN];
+               sprintf(number, " #%d", channel + 1);
+               strcat(title, number);
+       }
+}
+