From ca87e623b5651d5c94274bdede86768a5562dd56 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 26 May 2016 18:43:49 +0200 Subject: 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. --- player/command.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'player/command.c') 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 -- cgit v1.2.3