diff options
author | wm4 <wm4@nowhere> | 2013-10-31 23:23:38 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-10-31 23:30:14 +0100 |
commit | 71ded03123a704ddcbf018dcb0ec633475ccb04a (patch) | |
tree | bddcea247a2e2396fbf414168b25aac2a57316d7 /mpvcore/player/command.c | |
parent | 94542abf2e2ccb123cf3b0c9eef76a2290dd19b1 (diff) | |
download | mpv-71ded03123a704ddcbf018dcb0ec633475ccb04a.tar.bz2 mpv-71ded03123a704ddcbf018dcb0ec633475ccb04a.tar.xz |
command: add generic "multiply" command
Essentially works like "add".
Diffstat (limited to 'mpvcore/player/command.c')
-rw-r--r-- | mpvcore/player/command.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/mpvcore/player/command.c b/mpvcore/player/command.c index f393318fb6..172a799c03 100644 --- a/mpvcore/player/command.c +++ b/mpvcore/player/command.c @@ -2379,6 +2379,29 @@ static void overlay_uninit(struct MPContext *mpctx){} #endif +static int mp_property_multiply(char *property, double f, struct MPContext *mpctx) +{ + union m_option_value val = {0}; + struct m_option opt = {0}; + int r; + + r = mp_property_do(property, M_PROPERTY_GET_TYPE, &opt, mpctx); + if (r != M_PROPERTY_OK) + return r; + assert(opt.type); + + if (!opt.type->multiply) + return M_PROPERTY_NOT_IMPLEMENTED; + + r = mp_property_do(property, M_PROPERTY_GET, &val, mpctx); + if (r != M_PROPERTY_OK) + return r; + opt.type->multiply(&opt, &val, f); + r = mp_property_do(property, M_PROPERTY_SET, &val, mpctx); + m_option_free(&opt, &val); + return r; +} + // Whether this property should react to key events generated by auto-repeat. static bool check_property_autorepeat(char *property, struct MPContext *mpctx) { @@ -2484,6 +2507,23 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) break; } + case MP_CMD_MULTIPLY: { + char *property = cmd->args[0].v.s; + double f = cmd->args[1].v.d; + int r = mp_property_multiply(property, f, mpctx); + + if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) { + show_property_osd(mpctx, property, cmd->on_osd); + } else if (r == M_PROPERTY_UNKNOWN) { + set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration, + "Unknown property: '%s'", property); + } else if (r <= 0) { + set_osd_msg(mpctx, OSD_MSG_TEXT, osdl, osd_duration, + "Failed to multiply property '%s' by %g", property, f); + } + break; + } + case MP_CMD_GET_PROPERTY: { char *tmp; int r = mp_property_do(cmd->args[0].v.s, M_PROPERTY_GET_STRING, |