nested clips, big rework and cleanup, sams new icons, leaks and tweaks
[goodguy/history.git] / cinelerra-5.1 / cinelerra / autos.C
index 36abbd7dc756041d1d1cb1a356f24bb312508a70..49a8ea1cdc6674f8afd5c6b07cb635298349dad7 100644 (file)
@@ -204,7 +204,7 @@ Auto* Autos::get_prev_auto(int64_t position,
                        while(current && current->position > position) current = PREVIOUS;
                }
 
-               if(!current)
+               if(!current && first && first->position <= position)
                {
                        for(current = last;
                                current && current->position > position;
@@ -222,7 +222,7 @@ Auto* Autos::get_prev_auto(int64_t position,
                        while(current && current->position < position) current = NEXT;
                }
 
-               if(!current)
+               if(!current && last && last->position >= position)
                {
                        for(current = first;
                                current && current->position < position;
@@ -282,29 +282,20 @@ Auto* Autos::get_auto_at_position(double position)
 
 Auto* Autos::get_auto_for_editing(double position)
 {
-       if(position < 0)
-       {
+       if(position < 0) {
                position = edl->local_session->get_selectionstart(1);
        }
 
        Auto *result = 0;
-       position = edl->align_to_frame(position, 0);
-
-
-
-
-//printf("Autos::get_auto_for_editing %p %p\n", first, default_auto);
-
-       if(edl->session->auto_keyframes)
-       {
+       get_prev_auto(track->to_units(position, 0), PLAY_FORWARD, result);
+       if( edl->session->auto_keyframes && (!result || result->is_default ||
+              !EQUIV(track->from_units(result->position), position)) ) {
+//printf("Autos::get_auto_for_editing %p %p %p\n", default_auto, first, result);
+               position = edl->align_to_frame(position, 0);
                result = insert_auto(track->to_units(position, 0));
        }
-       else
-               result = get_prev_auto(track->to_units(position, 0),
-                       PLAY_FORWARD,
-                       result);
+//printf("Autos::get_auto_for_editing %p %p\n", first, default_auto);
 
-//printf("Autos::get_auto_for_editing %p %p %p\n", default_auto, first, result);
        return result;
 }
 
@@ -319,7 +310,7 @@ Auto* Autos::get_next_auto(int64_t position, int direction, Auto* &current, int
                        while(current && current->position < position) current = NEXT;
                }
 
-               if(!current)
+               if(!current && last && last->position > position)
                {
                        for(current = first;
                                current && current->position <= position;
@@ -338,7 +329,7 @@ Auto* Autos::get_next_auto(int64_t position, int direction, Auto* &current, int
                        while(current && current->position > position) current = PREVIOUS;
                }
 
-               if(!current)
+               if(!current && first && first->position <= position)
                {
                        for(current = last;
                                current && current->position > position;
@@ -712,22 +703,14 @@ Auto* Autos::autoof(int64_t position)
 Auto* Autos::nearest_before(int64_t position)
 {
        Auto *current;
-
-       for(current = last; current && current->position >= position; current = PREVIOUS)
-       { ; }
-
-
+       for(current = last; current && current->position >= position; current = PREVIOUS);
        return current;     // return 0 on failure
 }
 
 Auto* Autos::nearest_after(int64_t position)
 {
        Auto *current;
-
-       for(current = first; current && current->position <= position; current = NEXT)
-       { ; }
-
-
+       for(current = first; current && current->position <= position; current = NEXT);
        return current;     // return 0 on failure
 }