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.
This commit is contained in:
David Vaughan
2024-02-04 10:58:09 -08:00
committed by Dudemanguy
parent a8a314b829
commit da753196af
7 changed files with 23 additions and 35 deletions

View File

@@ -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)

View File

@@ -81,10 +81,8 @@ void playlist_entry_add_params(struct playlist_entry *e,
struct playlist_entry *playlist_entry_new(const char *filename);
void playlist_add(struct playlist *pl, struct playlist_entry *add);
void playlist_insert_next(struct playlist *pl, struct playlist_entry *entry,
struct playlist_entry *at);
void playlist_insert_at(struct playlist *pl, struct playlist_entry *entry,
struct playlist_entry *at);
void playlist_remove(struct playlist *pl, struct playlist_entry *entry);
void playlist_clear(struct playlist *pl);
@@ -93,7 +91,7 @@ void playlist_clear_except_current(struct playlist *pl);
void playlist_move(struct playlist *pl, struct playlist_entry *entry,
struct playlist_entry *at);
void playlist_add_file(struct playlist *pl, const char *filename);
void playlist_append_file(struct playlist *pl, const char *filename);
void playlist_populate_playlist_path(struct playlist *pl, const char *path);
void playlist_shuffle(struct playlist *pl);
void playlist_unshuffle(struct playlist *pl);