Skip to content

Commit

Permalink
player: don't decrement --ab-loop-count=N and add remaining-ab-loops
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
guidocella committed Jun 5, 2024
1 parent 8190894 commit 4d66742
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
2 changes: 2 additions & 0 deletions DOCS/interface-changes/loop.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
numerical values of `--loop-file` no longer decrease on each iteration
add `remaining-file-loops` property
numerical values of `--ab-loop-count` no longer decrease on each iteration
add `remaining-ab-loops` property
6 changes: 6 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 4 additions & 5 deletions DOCS/man/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,10 @@ Playback Control

``--ab-loop-count=<N|inf>``
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=<yes|no>``
Enable support for Matroska ordered chapters. mpv will load and
Expand Down
16 changes: 16 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion player/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
8 changes: 3 additions & 5 deletions player/playloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down

0 comments on commit 4d66742

Please sign in to comment.