diff options
author | wm4 <wm4@nowhere> | 2013-05-15 02:17:47 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-07 18:00:34 +0200 |
commit | c185b0ba4a09eab1bf969e40acc660454921f460 (patch) | |
tree | cd90cd1c42b897cfa48b084488d9e93b061535b2 /core/command.c | |
parent | b15143b7e0df6d9f6d0dc072e89d1c86d41f52d4 (diff) | |
download | mpv-c185b0ba4a09eab1bf969e40acc660454921f460.tar.bz2 mpv-c185b0ba4a09eab1bf969e40acc660454921f460.tar.xz |
command: replace some show_ commands with properties
show_chapters, show_tracks, and show_playlist are killed and replaced
with the properties chapter-list, track-list, and playlist. The code
and the output of these stays the same, this is just moving a lot of
code around and reducing the number of properties.
The "old" commands will still be supported for a while (to avoid making
everyone angry), so handle them with the legacy layer. Add something to
suppress printing the legacy warnings for these commands.
Diffstat (limited to 'core/command.c')
-rw-r--r-- | core/command.c | 215 |
1 files changed, 111 insertions, 104 deletions
diff --git a/core/command.c b/core/command.c index 2b902eef58..31097e1030 100644 --- a/core/command.c +++ b/core/command.c @@ -393,6 +393,38 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg, return M_PROPERTY_NOT_IMPLEMENTED; } +static int mp_property_list_chapters(m_option_t *prop, int action, void *arg, + MPContext *mpctx) +{ + if (action == M_PROPERTY_GET) { + int count = get_chapter_count(mpctx); + int cur = mpctx->num_sources ? get_current_chapter(mpctx) : -1; + char *res = NULL; + int n; + + if (count < 1) { + res = talloc_asprintf_append(res, "No chapters."); + } + + for (n = 0; n < count; n++) { + char *name = chapter_display_name(mpctx, n); + double t = chapter_start_time(mpctx, n); + char* time = mp_format_time(t, false); + res = talloc_asprintf_append(res, "%s", time); + talloc_free(time); + char *m1 = "> ", *m2 = " <"; + if (n != cur) + m1 = m2 = ""; + res = talloc_asprintf_append(res, " %s%s%s\n", m1, name, m2); + talloc_free(name); + } + + *(char **)arg = res; + return M_PROPERTY_OK; + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + static int mp_property_edition(m_option_t *prop, int action, void *arg, MPContext *mpctx) { @@ -832,6 +864,60 @@ static int property_switch_track(m_option_t *prop, int action, void *arg, return mp_property_generic_option(prop, action, arg, mpctx); } +static const char *track_type_name(enum stream_type t) +{ + switch (t) { + case STREAM_VIDEO: return "Video"; + case STREAM_AUDIO: return "Audio"; + case STREAM_SUB: return "Sub"; + } + return NULL; +} + +static int property_list_tracks(m_option_t *prop, int action, void *arg, + MPContext *mpctx, enum stream_type type) +{ + if (action == M_PROPERTY_GET) { + char *res = NULL; + + for (int type = 0; type < STREAM_TYPE_COUNT; type++) { + for (int n = 0; n < mpctx->num_tracks; n++) { + struct track *track = mpctx->tracks[n]; + if (track->type != type) + continue; + + bool selected = mpctx->current_track[track->type] == track; + res = talloc_asprintf_append(res, "%s: ", + track_type_name(track->type)); + if (selected) + res = talloc_asprintf_append(res, "> "); + res = talloc_asprintf_append(res, "(%d) ", track->user_tid); + if (track->title) + res = talloc_asprintf_append(res, "'%s' ", track->title); + if (track->lang) + res = talloc_asprintf_append(res, "(%s) ", track->lang); + if (track->is_external) + res = talloc_asprintf_append(res, "(external) "); + if (selected) + res = talloc_asprintf_append(res, "<"); + res = talloc_asprintf_append(res, "\n"); + } + + res = talloc_asprintf_append(res, "\n"); + } + + struct demuxer *demuxer = mpctx->master_demuxer; + if (demuxer && demuxer->num_editions > 1) + res = talloc_asprintf_append(res, "\nEdition: %d of %d\n", + demuxer->edition + 1, + demuxer->num_editions); + + *(char **)arg = res; + return M_PROPERTY_OK; + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + /// Selected audio id (RW) static int mp_property_audio(m_option_t *prop, int action, void *arg, MPContext *mpctx) @@ -1347,6 +1433,27 @@ static int mp_property_tv_color(m_option_t *prop, int action, void *arg, #endif +static int mp_property_playlist(m_option_t *prop, int action, void *arg, + MPContext *mpctx) +{ + if (action == M_PROPERTY_GET) { + char *res = talloc_strdup(NULL, ""); + + for (struct playlist_entry *e = mpctx->playlist->first; e; e = e->next) + { + if (mpctx->playlist->current == e) { + res = talloc_asprintf_append(res, "> %s <\n", e->filename); + } else { + res = talloc_asprintf_append(res, "%s\n", e->filename); + } + } + + *(char **)arg = res; + return M_PROPERTY_OK; + } + return M_PROPERTY_NOT_IMPLEMENTED; +} + static int mp_property_alias(m_option_t *prop, int action, void *arg, MPContext *mpctx) { @@ -1431,6 +1538,10 @@ static const m_option_t mp_properties[] = { { "clock", mp_property_clock, CONF_TYPE_STRING, 0, 0, 0, NULL }, + { "chapter-list", mp_property_list_chapters, CONF_TYPE_STRING }, + { "track-list", property_list_tracks, CONF_TYPE_STRING }, + { "playlist", mp_property_playlist, CONF_TYPE_STRING }, + // Audio { "volume", mp_property_volume, CONF_TYPE_FLOAT, M_OPT_RANGE, 0, 100, NULL }, @@ -1699,101 +1810,6 @@ static const char *property_error_string(int error_value) return "UNKNOWN"; } -static void show_chapters_on_osd(MPContext *mpctx) -{ - int count = get_chapter_count(mpctx); - int cur = mpctx->num_sources ? get_current_chapter(mpctx) : -1; - char *res = NULL; - int n; - - if (count < 1) { - res = talloc_asprintf_append(res, "No chapters."); - } - - for (n = 0; n < count; n++) { - char *name = chapter_display_name(mpctx, n); - double t = chapter_start_time(mpctx, n); - char* time = mp_format_time(t, false); - res = talloc_asprintf_append(res, "%s", time); - talloc_free(time); - char *m1 = "> ", *m2 = " <"; - if (n != cur) - m1 = m2 = ""; - res = talloc_asprintf_append(res, " %s%s%s\n", m1, name, m2); - talloc_free(name); - } - - set_osd_msg(mpctx, OSD_MSG_TEXT, 1, mpctx->opts.osd_duration, "%s", res); - talloc_free(res); -} - -static const char *track_type_name(enum stream_type t) -{ - switch (t) { - case STREAM_VIDEO: return "Video"; - case STREAM_AUDIO: return "Audio"; - case STREAM_SUB: return "Sub"; - } - return NULL; -} - -static void show_tracks_on_osd(MPContext *mpctx) -{ - struct MPOpts *opts = &mpctx->opts; - char *res = NULL; - - for (int type = 0; type < STREAM_TYPE_COUNT; type++) { - for (int n = 0; n < mpctx->num_tracks; n++) { - struct track *track = mpctx->tracks[n]; - if (track->type != type) - continue; - - bool selected = mpctx->current_track[track->type] == track; - res = talloc_asprintf_append(res, "%s: ", track_type_name(track->type)); - if (selected) - res = talloc_asprintf_append(res, "> "); - res = talloc_asprintf_append(res, "(%d) ", track->user_tid); - if (track->title) - res = talloc_asprintf_append(res, "'%s' ", track->title); - if (track->lang) - res = talloc_asprintf_append(res, "(%s) ", track->lang); - if (track->is_external) - res = talloc_asprintf_append(res, "(external) "); - if (selected) - res = talloc_asprintf_append(res, "<"); - res = talloc_asprintf_append(res, "\n"); - } - - res = talloc_asprintf_append(res, "\n"); - } - - struct demuxer *demuxer = mpctx->master_demuxer; - if (demuxer && demuxer->num_editions > 1) - res = talloc_asprintf_append(res, "\nEdition: %d of %d\n", - demuxer->edition + 1, - demuxer->num_editions); - - set_osd_msg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "%s", res); - talloc_free(res); -} - -static void show_playlist_on_osd(MPContext *mpctx) -{ - struct MPOpts *opts = &mpctx->opts; - char *res = NULL; - - for (struct playlist_entry *e = mpctx->playlist->first; e; e = e->next) { - if (mpctx->playlist->current == e) { - res = talloc_asprintf_append(res, "> %s <\n", e->filename); - } else { - res = talloc_asprintf_append(res, "%s\n", e->filename); - } - } - - set_osd_msg(mpctx, OSD_MSG_TEXT, 1, opts->osd_duration, "%s", res); - talloc_free(res); -} - static void change_video_filters(MPContext *mpctx, const char *cmd, const char *arg) { @@ -2380,15 +2396,6 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd) case MP_CMD_VF: change_video_filters(mpctx, cmd->args[0].v.s, cmd->args[1].v.s); break; - case MP_CMD_SHOW_CHAPTERS: - show_chapters_on_osd(mpctx); - break; - case MP_CMD_SHOW_TRACKS: - show_tracks_on_osd(mpctx); - break; - case MP_CMD_SHOW_PLAYLIST: - show_playlist_on_osd(mpctx); - break; default: mp_msg(MSGT_CPLAYER, MSGL_V, |