summaryrefslogtreecommitdiffstats
path: root/common/playlist.c
diff options
context:
space:
mode:
authorDavid Vaughan <david@davidv.xyz>2024-02-04 10:58:09 -0800
committerDudemanguy <random342@airmail.cc>2024-02-26 02:03:21 +0000
commitda753196af6593b2d6e94f691c9d1287b3ea093b (patch)
tree9960a897291bd8cf3f812031db9e45295fe14c72 /common/playlist.c
parenta8a314b829498c55aed393d4bc7f4f7bf9e92362 (diff)
downloadmpv-da753196af6593b2d6e94f691c9d1287b3ea093b.tar.bz2
mpv-da753196af6593b2d6e94f691c9d1287b3ea093b.tar.xz
player: change insert_next to insert_at
Change the `playlist_insert_next` function to `playlist_insert_at` (ie, insert at the location of an entry, rather than after it, and rename to be clearer that it doesn't have anything to do with the currently-playing entry). Also, replace calls to `playlist_add` with calls to `playlist_insert_at`, since the former has become redundant.
Diffstat (limited to 'common/playlist.c')
-rw-r--r--common/playlist.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/common/playlist.c b/common/playlist.c
index eda583224c..5ff34496c8 100644
--- a/common/playlist.c
+++ b/common/playlist.c
@@ -60,24 +60,15 @@ static void playlist_update_indexes(struct playlist *pl, int start, int end)
pl->entries[n]->pl_index = n;
}
-void playlist_add(struct playlist *pl, struct playlist_entry *add)
-{
- assert(add->filename);
- MP_TARRAY_APPEND(pl, pl->entries, pl->num_entries, add);
- add->pl = pl;
- add->pl_index = pl->num_entries - 1;
- add->id = ++pl->id_alloc;
- talloc_steal(pl, add);
-}
-
-// Inserts the entry so that it comes directly after "at" (or move to end, if at==NULL).
-void playlist_insert_next(struct playlist *pl, struct playlist_entry *add,
- struct playlist_entry *at)
+// Inserts the entry so that it takes "at"'s place, shifting "at" and all
+// further entires to the right (or append to end, if at==NULL).
+void playlist_insert_at(struct playlist *pl, struct playlist_entry *add,
+ struct playlist_entry *at)
{
assert(add->filename);
assert(!at || at->pl == pl);
- int index = at ? at->pl_index + 1 : pl->num_entries;
+ int index = at ? at->pl_index : pl->num_entries;
MP_TARRAY_INSERT_AT(pl, pl->entries, pl->num_entries, index, add);
add->pl = pl;
@@ -156,9 +147,9 @@ void playlist_move(struct playlist *pl, struct playlist_entry *entry,
MPMAX(index + 1, old_index + 1));
}
-void playlist_add_file(struct playlist *pl, const char *filename)
+void playlist_append_file(struct playlist *pl, const char *filename)
{
- playlist_add(pl, playlist_entry_new(filename));
+ playlist_insert_at(pl, playlist_entry_new(filename), NULL);
}
void playlist_populate_playlist_path(struct playlist *pl, const char *path)