diff options
author | wm4 <wm4@nowhere> | 2020-08-05 22:37:47 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-08-05 22:37:47 +0200 |
commit | 13d354e46d27fd0c433880839abcf9096dbcbc2f (patch) | |
tree | 8b410c67db9a1ee0573892386d442019b54122da /options/m_config_frontend.c | |
parent | f457f3839a88447bdef2ecb3ea8b8e37864f9b93 (diff) | |
download | mpv-13d354e46d27fd0c433880839abcf9096dbcbc2f.tar.bz2 mpv-13d354e46d27fd0c433880839abcf9096dbcbc2f.tar.xz |
auto_profiles: add this script
This is taken from a somewhat older proof-of-concept script. The basic
idea, and most of the implementation, is still the same. The way the
profiles are actually defined changed.
I still feel bad about this being a Lua script, and running user
expressions as Lua code in a vaguely defined environment, but I guess as
far as balance of effort/maintenance/results goes, this is fine.
It's a bit bloated (the Lua scripting state is at least 150KB or so in
total), so in order to enable this by default, I decided it should
unload itself by default if no auto-profiles are used. (And currently,
it does not actually rescan the profile list if a new config file is
loaded some time later, so the script would do nothing anyway if no auto
profiles were defined.)
This still requires defining inverse profiles for "unapplying" a
profile. Also this is still somewhat racy. Both will probably be
alleviated to some degree in the future.
Diffstat (limited to 'options/m_config_frontend.c')
-rw-r--r-- | options/m_config_frontend.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/options/m_config_frontend.c b/options/m_config_frontend.c index 467c13eb8f..94cc9c015a 100644 --- a/options/m_config_frontend.c +++ b/options/m_config_frontend.c @@ -50,8 +50,10 @@ struct m_profile { struct m_profile *next; char *name; char *desc; + char *cond; int num_opts; // Option/value pair array. + // name,value = opts[n*2+0],opts[n*2+1] char **opts; }; @@ -85,6 +87,10 @@ static int show_profile(struct m_config *config, bstr param) MP_INFO(config, "Profile %s: %s\n", p->name, p->desc ? p->desc : ""); config->profile_depth++; + if (p->cond) { + MP_INFO(config, "%*sprofile-cond=%s\n", config->profile_depth, "", + p->cond); + } for (int i = 0; i < p->num_opts; i++) { MP_INFO(config, "%*s%s=%s\n", config->profile_depth, "", p->opts[2 * i], p->opts[2 * i + 1]); @@ -884,6 +890,14 @@ void m_profile_set_desc(struct m_profile *p, bstr desc) p->desc = bstrto0(p, desc); } +void m_profile_set_cond(struct m_profile *p, bstr cond) +{ + TA_FREEP(&p->cond); + cond = bstr_strip(cond); + if (cond.len) + p->cond = bstrto0(p, cond); +} + int m_config_set_profile_option(struct m_config *config, struct m_profile *p, bstr name, bstr val) { @@ -944,6 +958,8 @@ struct mpv_node m_config_get_profiles(struct m_config *config) node_map_add_string(entry, "name", profile->name); if (profile->desc) node_map_add_string(entry, "profile-desc", profile->desc); + if (profile->cond) + node_map_add_string(entry, "profile-cond", profile->cond); struct mpv_node *opts = node_map_add(entry, "options", MPV_FORMAT_NODE_ARRAY); |