Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't decrement --loop-file=N and --ab-loop-count=N #14302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DOCS/interface-changes/loop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numerical values of `--loop-file` no longer decrease on each iteration
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
12 changes: 12 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,18 @@ Property list
``playback-time/full``
``playback-time`` with milliseconds.

``remaining-file-loops``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't loop-file-remaining be more in line with existing naming?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes no grammatical sense though. And the options are already inconsistent, --loop-file-count and --loop-playlist-count would more logical and consistent with --ab-loop-count.

How many more times the current file is going to be looped. This is
initialized from the value of ``--loop-file``. This counts the number of
times it causes the player to seek to the beginning of the file, so it is 0
the last the time is played. -1 corresponds to infinity.

``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. -1 corresponds to infinity.

``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
27 changes: 27 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,20 @@ static int mp_property_playback_time(void *ctx, struct m_property *prop,
return property_time(action, arg, get_playback_time(mpctx));
}

static int mp_property_remaining_file_loops(void *ctx, struct m_property *prop,
int action, void *arg)
{
MPContext *mpctx = ctx;
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;
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 @@ -4005,6 +4019,8 @@ static const struct m_property mp_properties_base[] = {
{"audio-pts", mp_property_audio_pts},
{"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 @@ -7496,6 +7512,17 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags,
mpctx->stop_play = PT_CURRENT_ENTRY;
}

if (opt_ptr == &opts->loop_file) {
mpctx->remaining_file_loops = opts->loop_file;
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
3 changes: 3 additions & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ typedef struct MPContext {
int max_frames;
bool playing_msg_shown;

int remaining_file_loops;
int remaining_ab_loops;

bool paused_for_cache;
bool demux_underrun;
double cache_stop_time;
Expand Down
5 changes: 5 additions & 0 deletions player/loadfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,11 @@ static void play_current_file(struct MPContext *mpctx)
load_per_file_options(mpctx->mconfig, mpctx->playing->params,
mpctx->playing->num_params);

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;

handle_force_window(mpctx, false);
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
16 changes: 7 additions & 9 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,16 +893,16 @@ 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;
} else if (opts->loop_file) {
if (opts->loop_file > 0) {
opts->loop_file--;
m_config_notify_change_opt_ptr(mpctx->mconfig, &opts->loop_file);
} else if (mpctx->remaining_file_loops) {
if (mpctx->remaining_file_loops > 0) {
mpctx->remaining_file_loops--;
mp_notify_property(mpctx, "remaining-file-loops");
}
target = get_start_time(mpctx, mpctx->play_dir);
}
Expand Down
Loading