summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-09-21 14:22:23 +0200
committerwm4 <wm4@nowhere>2012-10-12 10:10:31 +0200
commitd3562198249d51087e8a23a6fafafd140eaaf935 (patch)
tree4008ecb961c4a7940e0202eacfa6c132418d1298
parent74adc534b9dd8dde67042e8f3f448da3baca2fef (diff)
downloadmpv-d3562198249d51087e8a23a6fafafd140eaaf935.tar.bz2
mpv-d3562198249d51087e8a23a6fafafd140eaaf935.tar.xz
commands: remove M_PROPERTY_SWITCH from edition property
Instead, communicate the new value range with M_PROPERTY_GET_TYPE. Add M_PROPERTY_GET_WRAP to allow properties to enable cycling instead of stopping at min/max.
-rw-r--r--command.c51
-rw-r--r--m_property.c1
-rw-r--r--m_property.h4
3 files changed, 32 insertions, 24 deletions
diff --git a/command.c b/command.c
index 74ef6d2f7d..7c2ab61c96 100644
--- a/command.c
+++ b/command.c
@@ -382,29 +382,33 @@ static int mp_property_edition(m_option_t *prop, int action, void *arg,
case M_PROPERTY_GET:
*(int *)arg = edition;
return M_PROPERTY_OK;
- case M_PROPERTY_SET:
+ case M_PROPERTY_SET: {
edition = *(int *)arg;
- break;
- case M_PROPERTY_SWITCH: {
- edition += *(double *)arg;
- if (edition < 0)
- edition = demuxer->num_editions - 1;
- if (edition >= demuxer->num_editions)
- edition = 0;
- break;
+ if (edition != demuxer->edition) {
+ opts->edition_id = edition;
+ mpctx->stop_play = PT_RESTART;
+ set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration,
+ "Playing edition %d of %d.", edition + 1,
+ demuxer->num_editions);
+ }
+ return M_PROPERTY_OK;
}
- default:
- return M_PROPERTY_NOT_IMPLEMENTED;
+ case M_PROPERTY_GET_TYPE: {
+ struct m_option opt = {
+ .name = prop->name,
+ .type = CONF_TYPE_INT,
+ .flags = CONF_RANGE,
+ .min = 0,
+ .max = demuxer->num_editions - 1,
+ };
+ *(struct m_option *)arg = opt;
+ return M_PROPERTY_OK;
}
-
- if (edition != demuxer->edition) {
- opts->edition_id = edition;
- mpctx->stop_play = PT_RESTART;
- set_osd_tmsg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration,
- "Playing edition %d of %d.", edition + 1,
- demuxer->num_editions);
+ case M_PROPERTY_GET_WRAP:
+ *(bool *)arg = true;
+ return M_PROPERTY_OK;
}
- return M_PROPERTY_OK;
+ return M_PROPERTY_NOT_IMPLEMENTED;
}
/// Number of titles in file
@@ -476,9 +480,9 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
resync_audio_stream(sh_audio);
}
return M_PROPERTY_OK;
- case M_PROPERTY_SWITCH:
- // NOTE: should cycle
- return M_PROPERTY_NOT_IMPLEMENTED;
+ case M_PROPERTY_GET_WRAP:
+ *(bool *)arg = true;
+ return M_PROPERTY_OK;
}
return M_PROPERTY_NOT_IMPLEMENTED;
}
@@ -1351,8 +1355,7 @@ static const m_option_t mp_properties[] = {
M_OPT_MIN, 0, 0, NULL },
{ "chapter", mp_property_chapter, CONF_TYPE_INT,
M_OPT_MIN, 0, 0, NULL },
- { "edition", mp_property_edition, CONF_TYPE_INT,
- M_OPT_MIN, -1, 0, NULL },
+ M_OPTION_PROPERTY_CUSTOM("edition", mp_property_edition),
{ "titles", mp_property_titles, CONF_TYPE_INT,
0, 0, 0, NULL },
{ "chapters", mp_property_chapters, CONF_TYPE_INT,
diff --git a/m_property.c b/m_property.c
index f2899912d6..4952c3a29c 100644
--- a/m_property.c
+++ b/m_property.c
@@ -115,6 +115,7 @@ int m_property_do(const m_option_t *prop_list, const char *name,
return r;
bool wrap = opt.type == &m_option_type_choice ||
opt.type == &m_option_type_flag;
+ do_action(prop_list, name, M_PROPERTY_GET_WRAP, &wrap, ctx);
opt.type->add(&opt, &val, *(double*)arg, wrap);
r = do_action(prop_list, name, M_PROPERTY_SET, &val, ctx);
m_option_free(&opt, &val);
diff --git a/m_property.h b/m_property.h
index 2893fc569d..33bd7f3f7c 100644
--- a/m_property.h
+++ b/m_property.h
@@ -64,6 +64,10 @@ enum mp_property_action {
// Pass down an action to a sub-property.
// arg: struct m_property_action*
M_PROPERTY_KEY_ACTION,
+
+ // Get wrap method.
+ // arg: bool* (true: wrap/cycle, false: clamp)
+ M_PROPERTY_GET_WRAP,
};
// Argument for M_PROPERTY_KEY_ACTION