summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorJames Ross-Gowan <rossymiles@gmail.com>2017-04-25 18:03:06 +1000
committerJames Ross-Gowan <rossymiles@gmail.com>2017-05-12 22:58:58 +1000
commit89fd3e1d9d25731c6cae8af1b9c5b0bae726c436 (patch)
tree84bd2fbe5b7af1c7245f4387464fd947474b149c /player
parent937128697fbbef6b21e2d23a4785f1334f62b9e3 (diff)
downloadmpv-89fd3e1d9d25731c6cae8af1b9c5b0bae726c436.tar.bz2
mpv-89fd3e1d9d25731c6cae8af1b9c5b0bae726c436.tar.xz
command: use scale_units to add/cycle integer properties
This adds check_property_scalable, which returns true if the property is backed by a floating-point number. When the add or cycle commands operate on these properties, they can benefit from the fractional scale value in cmd->scale. When the property is not backed by a floating-point number, cmd->scale_units is used instead, so for axis events, the property is only incrmented when the user scrolls one full unit. This solution isn't perfect, because in some cases integer-backed properties could benefit from accurate scrolling. For example, if an axis is bound to "cycle audio 5", the cycle command could be made to change the audio track by one when the user scrolls 1/5th of a unit, though this behaviour would require more changes to the options system.
Diffstat (limited to 'player')
-rw-r--r--player/command.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/player/command.c b/player/command.c
index ad871e34b3..a65a187dd7 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4783,6 +4783,20 @@ static bool check_property_autorepeat(char *property, struct MPContext *mpctx)
return true;
}
+// Whether changes to this property (add/cycle cmds) benefit from cmd->scale
+static bool check_property_scalable(char *property, struct MPContext *mpctx)
+{
+ struct m_option prop = {0};
+ if (mp_property_do(property, M_PROPERTY_GET_TYPE, &prop, mpctx) <= 0)
+ return true;
+
+ // These properties are backed by a floating-point number
+ return prop.type == &m_option_type_float ||
+ prop.type == &m_option_type_double ||
+ prop.type == &m_option_type_time ||
+ prop.type == &m_option_type_aspect;
+}
+
static struct mpv_node *add_map_entry(struct mpv_node *dst, const char *key)
{
struct mpv_node_list *list = dst->u.list;
@@ -4925,27 +4939,35 @@ int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *re
case MP_CMD_CYCLE:
{
char *property = cmd->args[0].v.s;
- struct m_property_switch_arg s = {
- .inc = cmd->args[1].v.d * cmd->scale,
- .wrap = cmd->id == MP_CMD_CYCLE,
- };
if (cmd->repeated && !check_property_autorepeat(property, mpctx)) {
MP_VERBOSE(mpctx, "Dropping command '%.*s' from auto-repeated key.\n",
BSTR_P(cmd->original));
break;
}
- int r = mp_property_do(property, M_PROPERTY_SWITCH, &s, mpctx);
- if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) {
- show_property_osd(mpctx, property, on_osd);
- } else if (r == M_PROPERTY_UNKNOWN) {
- set_osd_msg(mpctx, osdl, osd_duration,
- "Unknown property: '%s'", property);
- return -1;
- } else if (r <= 0) {
- set_osd_msg(mpctx, osdl, osd_duration,
- "Failed to increment property '%s' by %g",
- property, s.inc);
- return -1;
+ double scale = 1;
+ int scale_units = cmd->scale_units;
+ if (check_property_scalable(property, mpctx)) {
+ scale = cmd->scale;
+ scale_units = 1;
+ }
+ for (int i = 0; i < scale_units; i++) {
+ struct m_property_switch_arg s = {
+ .inc = cmd->args[1].v.d * scale,
+ .wrap = cmd->id == MP_CMD_CYCLE,
+ };
+ int r = mp_property_do(property, M_PROPERTY_SWITCH, &s, mpctx);
+ if (r == M_PROPERTY_OK || r == M_PROPERTY_UNAVAILABLE) {
+ show_property_osd(mpctx, property, on_osd);
+ } else if (r == M_PROPERTY_UNKNOWN) {
+ set_osd_msg(mpctx, osdl, osd_duration,
+ "Unknown property: '%s'", property);
+ return -1;
+ } else if (r <= 0) {
+ set_osd_msg(mpctx, osdl, osd_duration,
+ "Failed to increment property '%s' by %g",
+ property, s.inc);
+ return -1;
+ }
}
break;
}