add sliders to cwdw proj/cam tools, edit id tweaks, deltrk shortcut tweak
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / edit.C
index 5321209acd68b7233a3b23d2ac1bb4da9edcadfe..72f179907fe8758143b7337b7491e06dd283f7f9 100644 (file)
@@ -52,6 +52,7 @@ Edit::Edit(EDL *edl, Track *track)
        this->track = track;
        if(track) this->edits = track->edits;
        id = EDL::next_id();
+       orig_id = id;
 }
 
 Edit::Edit(EDL *edl, Edits *edits)
@@ -61,6 +62,7 @@ Edit::Edit(EDL *edl, Edits *edits)
        this->edits = edits;
        if(edits) this->track = edits->track;
        id = EDL::next_id();
+       orig_id = id;
 }
 
 Edit::~Edit()
@@ -254,6 +256,7 @@ void Edit::set_selected(int v)
 
 void Edit::copy_from(Edit *edit)
 {
+       this->orig_id = edit->orig_id;
        this->nested_edl = edl->nested_edls.get_nested(edit->nested_edl);
        this->asset = edl->assets->update(edit->asset);
        this->startsource = edit->startsource;
@@ -276,6 +279,12 @@ void Edit::copy_from(Edit *edit)
        this->channel = edit->channel;
 }
 
+void Edit::clone_from(Edit *edit)
+{
+       copy_from(edit);
+       edit->orig_id = edit->id;
+}
+
 void Edit::equivalent_output(Edit *edit, int64_t *result)
 {
 // End of edit changed
@@ -317,13 +326,6 @@ void Edit::equivalent_output(Edit *edit, int64_t *result)
 }
 
 
-Edit& Edit::operator=(Edit& edit)
-{
-//printf("Edit::operator= called\n");
-       copy_from(&edit);
-       return *this;
-}
-
 void Edit::synchronize_params(Edit *edit)
 {
        copy_from(edit);
@@ -343,11 +345,6 @@ int Edit::identical(Edit &edit)
        return result;
 }
 
-int Edit::operator==(Edit &edit)
-{
-       return identical(edit);
-}
-
 double Edit::frames_per_picon()
 {
        return Units::round(picon_w()) / frame_w();
@@ -383,8 +380,8 @@ int Edit::picon_h()
 int Edit::dump(FILE *fp)
 {
        fprintf(fp,"     EDIT %p\n", this); fflush(fp);
-       fprintf(fp,"      nested_edl=%p %s asset=%p %s\n",
-               nested_edl, nested_edl ? nested_edl->path : "",
+       fprintf(fp,"      id %d, orig_id %d, nested_edl=%p %s asset=%p %s\n",
+               id, orig_id, nested_edl, nested_edl ? nested_edl->path : "",
                asset, asset ? asset->path : "");
        fflush(fp);
        fprintf(fp,"      channel %d, color %08x, hard lt/rt %d/%d"
@@ -443,20 +440,28 @@ int Edit::shift_start(int edit_mode, int64_t newposition, int64_t oldposition,
        int edit_labels, int edit_autos, int edit_plugins, Edits *trim_edits)
 {
        int64_t cut_length = newposition - oldposition;
-       if( !cut_length ) return 0;
+       int rest_moved = edit_mode == MOVE_RIPPLE || edit_mode == MOVE_EDGE ? 1 : 0;
+       if( cut_length > length )
+               cut_length = length;
+       else if( cut_length < -length )
+               cut_length = -length;
+
        int64_t start = startproject, end = start + length;
        Edit *prev = this->previous, *next = this->next;
-       int edits_moved = 0, rest_moved = 0;
+       int edits_moved = 0;
 
        switch( edit_mode ) {
        case MOVE_RIPPLE:
-               edits_moved = rest_moved = 1;
+               edits_moved = 1;
                startsource += cut_length;
-               length -= cut_length;
+               cut_length = -cut_length;
+               length += cut_length;
                for( Edit *edit=next; edit; edit=edit->next )
-                       edit->startproject -= cut_length;
+                       edit->startproject += cut_length;
                break;
        case MOVE_ROLL:
+               if( prev && prev->length + cut_length < 0 )
+                       cut_length = -prev->length;
                if( prev ) prev->trim(cut_length);
                startproject += cut_length;
                startsource += cut_length;
@@ -468,6 +473,10 @@ int Edit::shift_start(int edit_mode, int64_t newposition, int64_t oldposition,
                break;
        case MOVE_SLIDE:
                edits_moved = 1;
+               if( prev && prev->length + cut_length < 0 )
+                       cut_length = -prev->length;
+               if( next && next->length - cut_length < 0 )
+                       cut_length = next->length;
                if( prev ) prev->trim(cut_length);
                startproject += cut_length;
                if( next ) {
@@ -477,7 +486,7 @@ int Edit::shift_start(int edit_mode, int64_t newposition, int64_t oldposition,
                }
                break;
        case MOVE_EDGE:
-               edits_moved = rest_moved = 1;
+               edits_moved = 1;
                startsource -= cut_length;
                length += cut_length;
                for( Edit *edit=next; edit; edit=edit->next )
@@ -485,7 +494,6 @@ int Edit::shift_start(int edit_mode, int64_t newposition, int64_t oldposition,
                break;
        }
        trim(0);
-
        return follow_edits(start, end, cut_length, edits_moved, rest_moved,
                edit_labels, edit_autos, edit_plugins, trim_edits);
 }
@@ -494,20 +502,26 @@ int Edit::shift_end(int edit_mode, int64_t newposition, int64_t oldposition,
        int edit_labels, int edit_autos, int edit_plugins, Edits *trim_edits)
 {
        int64_t cut_length = newposition - oldposition;
-       if( !cut_length ) return 0;
+       int rest_moved = edit_mode == MOVE_RIPPLE || edit_mode == MOVE_EDGE ? 1 : 0;
+       if( cut_length > length ) {
+                if( !rest_moved ) cut_length = length;
+       }
+       else if( cut_length < -length )
+               cut_length = -length;
        int64_t start = startproject, end = start + length;
        Edit *prev = this->previous, *next = this->next;
-       int edits_moved = 0, rest_moved = 0;
+       int edits_moved = 0;
 
        switch( edit_mode ) {
        case MOVE_RIPPLE:
        case MOVE_EDGE:
-               rest_moved = 1;
                length += cut_length;
                for( Edit *edit=next; edit; edit=edit->next )
                        edit->startproject += cut_length;
                break;
        case MOVE_ROLL:
+               if( next && next->length - cut_length < 0 )
+                       cut_length = next->length;
                length += cut_length;
                if( next ) {
                        next->startproject += cut_length;
@@ -521,6 +535,10 @@ int Edit::shift_end(int edit_mode, int64_t newposition, int64_t oldposition,
                break;
        case MOVE_SLIDE:
                edits_moved = 1;
+               if( prev && prev->length + cut_length < 0 )
+                       cut_length = -prev->length;
+               if( next && next->length - cut_length < 0 )
+                       cut_length = next->length;
                if( prev ) prev->trim(cut_length);
                startproject += cut_length;
                if( next ) {
@@ -531,7 +549,6 @@ int Edit::shift_end(int edit_mode, int64_t newposition, int64_t oldposition,
                break;
        }
        trim(0);
-
        return follow_edits(start, end, cut_length, edits_moved, rest_moved,
                edit_labels, edit_autos, edit_plugins, trim_edits);
 }
@@ -579,11 +596,11 @@ int Edit::follow_edits(int64_t start, int64_t end, int64_t cut_length,
                }
                if( edit_plugins ) {
                        if( cut_length > 0 ) {
-                               track->clear(end, end+cut_length, 0, 0, 1, 0, 0);
+                               track->clear(end, end+cut_length, 0, 0, -1, 0, 0);
                                track->shift_effects(start, cut_length, 1, 0);
                        }
                        else if( cut_length < 0 ) {
-                               track->clear(start+cut_length, start, 0, 0, 1, 0, 0);
+                               track->clear(start+cut_length, start, 0, 0, -1, 0, 0);
                                track->shift_effects(end+cut_length, -cut_length, 1, 0);
                        }
                }
@@ -633,7 +650,7 @@ int Edit::select_handle(float view_start, float zoom_units, int cursor_x, int cu
 
        int64_t pixel1, pixel2;
        pixel1 = left;
-       pixel2 = pixel1 + 10;
+       pixel2 = pixel1 + xS(10);
 
 // test left edit
 // cursor_x is faked in acanvas
@@ -645,7 +662,7 @@ int Edit::select_handle(float view_start, float zoom_units, int cursor_x, int cu
 
        //int64_t endproject = startproject + length;
        pixel2 = right;
-       pixel1 = pixel2 - 10;
+       pixel1 = pixel2 - xS(10);
 
 // test right edit
        if(cursor_x >= pixel1 && cursor_x <= pixel2)