From 53a78a8c926f8cca140602a7532f0af9ce94ec24 Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Fri, 7 Jun 2024 23:26:40 +0200 Subject: [PATCH] player: don't decrement --ab-loop-count=N and add remaining-ab-loops Follow up to the previous commit. Stop decreasing --ab-loop-count=N on each iteration so it is preserved across different loops. In particular it is preserved between different files without adding it to --reset-on-next-file. Add a property to expose the remaning A-B loop count instead. The current behavior of --ab-loop-count=N is even worse than --loop-file since it also doesn't reset when defining a new A-B loop in the same file. Defining it has no effect after --ab-loop-count has decreased to 0, and this can't be fixed by adding it to --reset-on-next-file. This commit also resets remaining-ab-loops every time --ab-loop-a and --ab-loop-b are set to fix this. --- DOCS/interface-changes/loop.txt | 4 +++- DOCS/man/input.rst | 6 ++++++ DOCS/man/options.rst | 9 ++++----- player/command.c | 16 ++++++++++++++++ player/core.h | 1 + player/loadfile.c | 2 ++ player/misc.c | 2 +- player/playloop.c | 8 +++----- 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/DOCS/interface-changes/loop.txt b/DOCS/interface-changes/loop.txt index 1ec487edad757..2073d65abf3ea 100644 --- a/DOCS/interface-changes/loop.txt +++ b/DOCS/interface-changes/loop.txt @@ -1,2 +1,4 @@ numerical values of `--loop-file` no longer decrease on each iteration -add `remaining-file-loops` property +add `remaining-file-loops` property as a replacement to get the remaining loop count +numerical values of `--ab-loop-count` no longer decrease on each iteration +add `remaining-ab-loops` property as a replacement to get the remaining loop count diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 76d87083cd75e..a66213a70fe27 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -2145,6 +2145,12 @@ Property list times it causes the player to seek to the beginning of the file, so it is 0 the last the time is played. +``remaining-ab-loops`` + How many more times the current A-B loop is going to be looped, if one is + active. This is initialized from the value of ``--ab-loop-count``. This + counts the number of times it causes the player to seek to ``--ab-loop-a``, + so it is 0 the last the time the loop is played. + ``chapter`` (RW) Current chapter number. The number of the first chapter is 0. diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 55c2f4553049a..073854ba5cb60 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -441,11 +441,10 @@ Playback Control ``--ab-loop-count=`` Run A-B loops only N times, then ignore the A-B loop points (default: inf). - Every finished loop iteration will decrement this option by 1 (unless it is - set to ``inf`` or 0). ``inf`` means that looping goes on forever. If this - option is set to 0, A-B looping is ignored, and even the ``ab-loop`` command - will not enable looping again (the command will show ``(disabled)`` on the - OSD message if both loop points are set, but ``ab-loop-count`` is 0). + ``inf`` means that looping goes on forever. If this option is set to 0, A-B + looping is ignored, and even the ``ab-loop`` command will not enable looping + again (the command will show ``(disabled)`` on the OSD message if both loop + points are set, but ``ab-loop-count`` is 0). ``--ordered-chapters=`` Enable support for Matroska ordered chapters. mpv will load and diff --git a/player/command.c b/player/command.c index b2bdc9cfa9260..42f7ac92bee68 100644 --- a/player/command.c +++ b/player/command.c @@ -893,6 +893,15 @@ static int mp_property_remaining_file_loops(void *ctx, struct m_property *prop, return m_property_int_ro(action, arg, mpctx->remaining_file_loops); } +static int mp_property_remaining_ab_loops(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + if (mpctx->remaining_ab_loops == -1) + return m_property_double_ro(action, arg, INFINITY); + return m_property_int_ro(action, arg, mpctx->remaining_ab_loops); +} + /// Current chapter (RW) static int mp_property_chapter(void *ctx, struct m_property *prop, int action, void *arg) @@ -4015,6 +4024,7 @@ static const struct m_property mp_properties_base[] = { {"playtime-remaining", mp_property_playtime_remaining}, {"playback-time", mp_property_playback_time}, {"remaining-file-loops", mp_property_remaining_file_loops}, + {"remaining-ab-loops", mp_property_remaining_ab_loops}, {"chapter", mp_property_chapter}, {"edition", mp_property_edition}, {"current-edition", mp_property_current_edition}, @@ -7511,6 +7521,12 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, mp_notify_property(mpctx, "remaining-file-loops"); } + if (opt_ptr == &opts->ab_loop[0] || opt_ptr == &opts->ab_loop[1] || + opt_ptr == &opts->ab_loop_count) { + mpctx->remaining_ab_loops = opts->ab_loop_count; + mp_notify_property(mpctx, "remaining-ab-loops"); + } + if (opt_ptr == &opts->ab_loop[0] || opt_ptr == &opts->ab_loop[1]) { update_ab_loop_clip(mpctx); // Update if visible diff --git a/player/core.h b/player/core.h index 4ae507b40bc75..a57c1886f17d1 100644 --- a/player/core.h +++ b/player/core.h @@ -421,6 +421,7 @@ typedef struct MPContext { bool playing_msg_shown; int remaining_file_loops; + int remaining_ab_loops; bool paused_for_cache; bool demux_underrun; diff --git a/player/loadfile.c b/player/loadfile.c index 715368471ff7b..c4b3da0c8cd7e 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1584,6 +1584,8 @@ static void play_current_file(struct MPContext *mpctx) mpctx->remaining_file_loops = mpctx->opts->loop_file; mp_notify_property(mpctx, "remaining-file-loops"); + mpctx->remaining_ab_loops = mpctx->opts->ab_loop_count; + mp_notify_property(mpctx, "remaining-ab-loops"); mpctx->max_frames = opts->play_frames; diff --git a/player/misc.c b/player/misc.c index f5cbc2f0cece0..3f5da68dc8026 100644 --- a/player/misc.c +++ b/player/misc.c @@ -129,7 +129,7 @@ bool get_ab_loop_times(struct MPContext *mpctx, double t[2]) t[0] = opts->ab_loop[0]; t[1] = opts->ab_loop[1]; - if (!opts->ab_loop_count) + if (!mpctx->remaining_ab_loops) return false; if (t[0] == MP_NOPTS_VALUE || t[1] == MP_NOPTS_VALUE || t[0] == t[1]) diff --git a/player/playloop.c b/player/playloop.c index df6356e96fc3a..0c6eff3628d6e 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -885,8 +885,6 @@ static void handle_sstep(struct MPContext *mpctx) static void handle_loop_file(struct MPContext *mpctx) { - struct MPOpts *opts = mpctx->opts; - if (mpctx->stop_play != AT_END_OF_FILE) return; @@ -895,9 +893,9 @@ static void handle_loop_file(struct MPContext *mpctx) double ab[2]; if (get_ab_loop_times(mpctx, ab) && mpctx->ab_loop_clip) { - if (opts->ab_loop_count > 0) { - opts->ab_loop_count--; - m_config_notify_change_opt_ptr(mpctx->mconfig, &opts->ab_loop_count); + if (mpctx->remaining_ab_loops > 0) { + mpctx->remaining_ab_loops--; + mp_notify_property(mpctx, "remaining-ab-loops"); } target = ab[0]; prec = MPSEEK_EXACT;