sams last ladspa icons, libopus/vp9, mixer fixer, plugin resets, fmt frmsz, shm fixes
[goodguy/history.git] / cinelerra-5.1 / cinelerra / autos.C
index 7ab31dd54ff3696657cae871de179406306eb203..b895a9049085c03a99db492cc171c90ace8fa2c3 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;
@@ -287,14 +287,15 @@ Auto* Autos::get_auto_for_editing(double position)
        }
 
        Auto *result = 0;
-       position = edl->align_to_frame(position, 0);
+       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));
+       }
 //printf("Autos::get_auto_for_editing %p %p\n", first, default_auto);
 
-       result = edl->session->auto_keyframes ?
-               insert_auto(track->to_units(position, 0)) :
-               get_prev_auto(track->to_units(position, 0), PLAY_FORWARD, result);
-
-//printf("Autos::get_auto_for_editing %p %p %p\n", default_auto, first, result);
        return result;
 }
 
@@ -309,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;
@@ -328,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;