summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-05-26 18:43:49 +0200
committerwm4 <wm4@nowhere>2016-05-26 18:44:01 +0200
commitca87e623b5651d5c94274bdede86768a5562dd56 (patch)
tree3ea1081cf126a341f17155329684a5e679894969
parent306c554376f6b06fcd675c8b8609da4e005997ed (diff)
downloadmpv-ca87e623b5651d5c94274bdede86768a5562dd56.tar.bz2
mpv-ca87e623b5651d5c94274bdede86768a5562dd56.tar.xz
command: add playlist-pos-1 property
This has often been requested for use on OSD. I don't really like having such "special" properties, but whatever. Hopefully this will be the only case. Untested because I'm too damn lazy. Fixes #2828.
-rw-r--r--DOCS/man/input.rst3
-rw-r--r--player/command.c26
2 files changed, 23 insertions, 6 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst
index 095a91bb35..f8eb87b065 100644
--- a/DOCS/man/input.rst
+++ b/DOCS/man/input.rst
@@ -1674,6 +1674,9 @@ Property list
Current position on playlist. The first entry is on position 0. Writing
to the property will restart playback at the written entry.
+``playlist-pos-1`` (RW)
+ Same as ``playlist-pos``, but 1-based.
+
``playlist-count``
Number of total playlist entries.
diff --git a/player/command.c b/player/command.c
index 7d143ea1f4..db1e3e7703 100644
--- a/player/command.c
+++ b/player/command.c
@@ -3136,8 +3136,8 @@ static int mp_property_dvb_channel_name(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED;
}
-static int mp_property_playlist_pos(void *ctx, struct m_property *prop,
- int action, void *arg)
+static int mp_property_playlist_pos_x(void *ctx, struct m_property *prop,
+ int action, void *arg, int base)
{
MPContext *mpctx = ctx;
struct playlist *pl = mpctx->playlist;
@@ -3149,11 +3149,12 @@ static int mp_property_playlist_pos(void *ctx, struct m_property *prop,
int pos = playlist_entry_to_index(pl, pl->current);
if (pos < 0)
return M_PROPERTY_UNAVAILABLE;
- *(int *)arg = pos;
+ *(int *)arg = pos + base;
return M_PROPERTY_OK;
}
case M_PROPERTY_SET: {
- struct playlist_entry *e = playlist_entry_from_index(pl, *(int *)arg);
+ int pos = *(int *)arg - base;
+ struct playlist_entry *e = playlist_entry_from_index(pl, pos);
if (!e)
return M_PROPERTY_ERROR;
mp_set_playlist_entry(mpctx, e);
@@ -3163,8 +3164,8 @@ static int mp_property_playlist_pos(void *ctx, struct m_property *prop,
struct m_option opt = {
.type = CONF_TYPE_INT,
.flags = CONF_RANGE,
- .min = 0,
- .max = playlist_entry_count(pl) - 1,
+ .min = base,
+ .max = playlist_entry_count(pl) - 1 + base,
};
*(struct m_option *)arg = opt;
return M_PROPERTY_OK;
@@ -3173,6 +3174,18 @@ static int mp_property_playlist_pos(void *ctx, struct m_property *prop,
return M_PROPERTY_NOT_IMPLEMENTED;
}
+static int mp_property_playlist_pos(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ return mp_property_playlist_pos_x(ctx, prop, action, arg, 0);
+}
+
+static int mp_property_playlist_pos_1(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ return mp_property_playlist_pos_x(ctx, prop, action, arg, 1);
+}
+
static int get_playlist_entry(int item, int action, void *arg, void *ctx)
{
struct MPContext *mpctx = ctx;
@@ -3695,6 +3708,7 @@ static const struct m_property mp_properties[] = {
{"playlist", mp_property_playlist},
{"playlist-pos", mp_property_playlist_pos},
+ {"playlist-pos-1", mp_property_playlist_pos_1},
M_PROPERTY_ALIAS("playlist-count", "playlist/count"),
// Audio