diff --git a/include/library/movie.hpp b/include/library/movie.hpp index 4ff8c1bc..57fdff6a 100644 --- a/include/library/movie.hpp +++ b/include/library/movie.hpp @@ -268,11 +268,11 @@ public: /** * Recount frames. */ - void recount_frames() { frames_in_movie = movie_data.count_frames(); } + void recount_frames() { adjust_frame_count(movie_data.count_frames() - frames_in_movie); } /** * Adjust frame count. */ - void adjust_frame_count(int64_t adjust) { frames_in_movie += adjust; } + void adjust_frame_count(int64_t adjust); private: //Sequence number. uint64_t seqno; diff --git a/src/library/movie.cpp b/src/library/movie.cpp index 0982a027..2c8e158c 100644 --- a/src/library/movie.cpp +++ b/src/library/movie.cpp @@ -455,6 +455,19 @@ movie& movie::operator=(const movie& m) return *this; } +void movie::adjust_frame_count(int64_t adjust) +{ + uint64_t old_frames = frames_in_movie; + frames_in_movie += adjust; + //If current_frame_first_subframe is in part extended, recompute it. + if(current_frame > old_frames + 1) { + current_frame_first_subframe = 0; + if(current_frame > 0) + for(uint64_t i = 0; i < current_frame - 1; i++) + current_frame_first_subframe += count_changes(current_frame_first_subframe); + } +} + void movie::set_pflag_handler(poll_flag* handler) { pflag_handler = handler;