1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-18 12:55:16 +00:00

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,
// 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,9 +81,7 @@ 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,
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);
@ -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);

View File

@ -91,7 +91,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check)
qsort(files, num_files, sizeof(files[0]), cmp_filename);
for (int n = 0; n < num_files; n++)
playlist_add_file(pl, files[n]);
playlist_append_file(pl, files[n]);
playlist_set_stream_flags(pl, demuxer->stream_origin);

View File

@ -202,7 +202,7 @@ static void pl_free_line(struct pl_parser *p, bstr line)
static void pl_add(struct pl_parser *p, bstr entry)
{
char *s = bstrto0(NULL, entry);
playlist_add_file(p->pl, s);
playlist_append_file(p->pl, s);
talloc_free(s);
}
@ -266,7 +266,7 @@ ok:
talloc_free(fn);
e->title = talloc_steal(e, title);
title = NULL;
playlist_add(p->pl, e);
playlist_insert_at(p->pl, e, NULL);
}
pl_free_line(p, line);
line = pl_get_line(p);
@ -296,7 +296,7 @@ static int parse_ref_init(struct pl_parser *p)
bstr burl = bstr0(p->s->url);
if (bstr_eatstart0(&burl, "http://") && check_mimetype(p->s, mmsh_types)) {
MP_INFO(p, "Redirecting to mmsh://\n");
playlist_add_file(p->pl, talloc_asprintf(p, "mmsh://%.*s", BSTR_P(burl)));
playlist_append_file(p->pl, talloc_asprintf(p, "mmsh://%.*s", BSTR_P(burl)));
return 0;
}
@ -456,7 +456,7 @@ static bool scan_dir(struct pl_parser *p, char *path,
scan_dir(p, file, dir_stack, num_dir_stack + 1);
}
else {
playlist_add_file(p->pl, dir_entries[n].path);
playlist_append_file(p->pl, dir_entries[n].path);
}
}

View File

@ -103,10 +103,10 @@ static void process_non_option(struct playlist *files, const char *arg)
// Glob filenames on Windows (cmd.exe doesn't do this automatically)
if (glob(arg, 0, NULL, &gg)) {
playlist_add_file(files, arg);
playlist_append_file(files, arg);
} else {
for (int i = 0; i < gg.gl_pathc; i++)
playlist_add_file(files, gg.gl_pathv[i]);
playlist_append_file(files, gg.gl_pathv[i]);
globfree(&gg);
}
@ -114,7 +114,7 @@ static void process_non_option(struct playlist *files, const char *arg)
#else
static void process_non_option(struct playlist *files, const char *arg)
{
playlist_add_file(files, arg);
playlist_append_file(files, arg);
}
#endif

View File

@ -5543,11 +5543,10 @@ static void cmd_loadfile(void *p)
playlist_entry_add_param(entry, bstr0(pairs[i]), bstr0(pairs[i + 1]));
}
if (insert_next) {
playlist_insert_next(mpctx->playlist, entry, mpctx->playlist->current);
} else {
playlist_add(mpctx->playlist, entry);
}
struct playlist_entry *at = insert_next ?
playlist_get_next(mpctx->playlist, +1) : NULL;
playlist_insert_at(mpctx->playlist, entry, at);
struct mpv_node *res = &cmd->result;
node_init(res, MPV_FORMAT_NODE_MAP, NULL);

View File

@ -322,7 +322,7 @@ void merge_playlist_files(struct playlist *pl)
edl = talloc_strdup_append_buffer(edl, e->filename);
}
playlist_clear(pl);
playlist_add_file(pl, edl);
playlist_append_file(pl, edl);
talloc_free(edl);
}