diff options
author | wm4 <wm4@nowhere> | 2013-06-28 22:16:29 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-06-29 22:58:12 +0200 |
commit | a6a1f4b8336c0d18c0588922da6b786b6408209f (patch) | |
tree | 1fd7bae3a83c98a090601c824ff35a933603c3ef /core/playlist.c | |
parent | fd7dd83e287c96f8be026cdec2c1ec74aaaa823b (diff) | |
download | mpv-a6a1f4b8336c0d18c0588922da6b786b6408209f.tar.bz2 mpv-a6a1f4b8336c0d18c0588922da6b786b6408209f.tar.xz |
command: add properties for playlist position
playlist-pos can set/get the current playlist index. playlist-count
returns the number of entries in the playlist.
Diffstat (limited to 'core/playlist.c')
-rw-r--r-- | core/playlist.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/core/playlist.c b/core/playlist.c index 7188392bc6..4132ebec10 100644 --- a/core/playlist.c +++ b/core/playlist.c @@ -196,3 +196,36 @@ void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl) playlist_insert(pl, add_after, e); } } + +// Return number of entries between list start and e. +// Return -1 if e is not on the list, or if e is NULL. +int playlist_entry_to_index(struct playlist *pl, struct playlist_entry *e) +{ + struct playlist_entry *cur = pl->first; + int pos = 0; + if (!e) + return -1; + while (cur && cur != e) { + cur = cur->next; + pos++; + } + return cur == e ? pos : -1; +} + +int playlist_entry_count(struct playlist *pl) +{ + return playlist_entry_to_index(pl, pl->last) + 1; +} + +// Return entry for which playlist_entry_to_index() would return index. +// Return NULL if not found. +struct playlist_entry *playlist_entry_from_index(struct playlist *pl, int index) +{ + struct playlist_entry *e = pl->first; + for (int n = 0; ; n++) { + if (!e || n == index) + return e; + e = e->next; + } +} + |