From: Max Kellermann Date: Tue, 29 Sep 2009 20:11:23 +0000 (+0200) Subject: playlist: pass struct mpdclient_playlist to functions X-Git-Tag: release-0.16~299 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0947e9071699b56bd06b0a798f87080d1f944d72;p=ncmpc.git playlist: pass struct mpdclient_playlist to functions Passing a mpdclient object doesn't make sense in this library. --- diff --git a/src/mpdclient.c b/src/mpdclient.c index 933a148..ac7fce9 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -254,7 +254,8 @@ mpdclient_update(struct mpdclient *c) /* update the current song */ if (!c->song || mpd_status_get_song_id(c->status)) { - c->song = playlist_get_song(c, mpd_status_get_song_pos(c->status)); + c->song = playlist_get_song(&c->playlist, + mpd_status_get_song_pos(c->status)); } return retval; @@ -268,7 +269,7 @@ mpdclient_update(struct mpdclient *c) gint mpdclient_cmd_play(struct mpdclient *c, gint idx) { - struct mpd_song *song = playlist_get_song(c, idx); + struct mpd_song *song = playlist_get_song(&c->playlist, idx); if (MPD_ERROR(c)) return -1; diff --git a/src/playlist.c b/src/playlist.c index 713d3c6..562fde6 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -18,7 +18,6 @@ */ #include "playlist.h" -#include "mpdclient.h" #include @@ -62,21 +61,19 @@ mpdclient_playlist_free(struct mpdclient_playlist *playlist) } struct mpd_song * -playlist_get_song(struct mpdclient *c, gint idx) +playlist_get_song(struct mpdclient_playlist *playlist, gint idx) { - if (idx < 0 || (guint)idx >= c->playlist.list->len) + if (idx < 0 || (guint)idx >= playlist_length(playlist)) return NULL; - return playlist_get(&c->playlist, idx); + return playlist_get(playlist, idx); } struct mpd_song * -playlist_lookup_song(struct mpdclient *c, unsigned id) +playlist_lookup_song(struct mpdclient_playlist *playlist, unsigned id) { - guint i; - - for (i = 0; i < c->playlist.list->len; ++i) { - struct mpd_song *song = playlist_get(&c->playlist, i); + for (guint i = 0; i < playlist_length(playlist); ++i) { + struct mpd_song *song = playlist_get(playlist, i); if (mpd_song_get_id(song) == id) return song; } @@ -85,12 +82,11 @@ playlist_lookup_song(struct mpdclient *c, unsigned id) } gint -playlist_get_index(const struct mpdclient *c, const struct mpd_song *song) +playlist_get_index(const struct mpdclient_playlist *playlist, + const struct mpd_song *song) { - guint i; - - for (i = 0; i < c->playlist.list->len; ++i) { - if (playlist_get(&c->playlist, i) == song) + for (guint i = 0; i < playlist_length(playlist); ++i) { + if (playlist_get(playlist, i) == song) return (gint)i; } @@ -98,12 +94,11 @@ playlist_get_index(const struct mpdclient *c, const struct mpd_song *song) } gint -playlist_get_index_from_id(const struct mpdclient *c, unsigned id) +playlist_get_index_from_id(const struct mpdclient_playlist *playlist, + unsigned id) { - guint i; - - for (i = 0; i < c->playlist.list->len; ++i) { - const struct mpd_song *song = playlist_get(&c->playlist, i); + for (guint i = 0; i < playlist_length(playlist); ++i) { + const struct mpd_song *song = playlist_get(playlist, i); if (mpd_song_get_id(song) == id) return (gint)i; } @@ -112,12 +107,11 @@ playlist_get_index_from_id(const struct mpdclient *c, unsigned id) } gint -playlist_get_index_from_file(const struct mpdclient *c, const gchar *filename) +playlist_get_index_from_file(const struct mpdclient_playlist *playlist, + const gchar *filename) { - guint i; - - for (i = 0; i < c->playlist.list->len; ++i) { - const struct mpd_song *song = playlist_get(&c->playlist, i); + for (guint i = 0; i < playlist_length(playlist); ++i) { + const struct mpd_song *song = playlist_get(playlist, i); if (strcmp(mpd_song_get_uri(song), filename) == 0) return (gint)i; diff --git a/src/playlist.h b/src/playlist.h index b948936..580b1c9 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -25,8 +25,6 @@ #include #include -struct mpdclient; - struct mpdclient_playlist { /* playlist id */ unsigned id; @@ -121,24 +119,29 @@ playlist_swap(struct mpdclient_playlist *playlist, guint idx1, guint idx2) g_ptr_array_index(playlist->list, idx2) = song1; } -struct mpd_song *playlist_lookup_song(struct mpdclient *c, unsigned id); +struct mpd_song * +playlist_lookup_song(struct mpdclient_playlist *playlist, unsigned id); -struct mpd_song *playlist_get_song(struct mpdclient *c, gint index); +struct mpd_song * +playlist_get_song(struct mpdclient_playlist *playlist, gint index); gint -playlist_get_index(const struct mpdclient *c, const struct mpd_song *song); +playlist_get_index(const struct mpdclient_playlist *playlist, + const struct mpd_song *song); gint -playlist_get_index_from_id(const struct mpdclient *c, unsigned id); +playlist_get_index_from_id(const struct mpdclient_playlist *playlist, + unsigned id); gint -playlist_get_index_from_file(const struct mpdclient *c, const gchar *filename); +playlist_get_index_from_file(const struct mpdclient_playlist *playlist, + const gchar *filename); static inline gint -playlist_get_index_from_same_song(const struct mpdclient *c, +playlist_get_index_from_same_song(const struct mpdclient_playlist *playlist, const struct mpd_song *song) { - return playlist_get_index_from_file(c, mpd_song_get_uri(song)); + return playlist_get_index_from_file(playlist, mpd_song_get_uri(song)); } #endif diff --git a/src/screen_browser.c b/src/screen_browser.c index efa2a38..3b80bdb 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -84,7 +84,8 @@ sync_highlights(struct mpdclient *c, struct filelist *fl) const struct mpd_song *song = mpd_entity_get_song(entity); - if (playlist_get_index_from_same_song(c, song) >= 0) + if (playlist_get_index_from_same_song(&c->playlist, + song) >= 0) entry->flags |= HIGHLIGHT; else entry->flags &= ~HIGHLIGHT; @@ -207,7 +208,7 @@ enqueue_and_play(struct mpdclient *c, struct filelist_entry *entry) } #endif - idx = playlist_get_index_from_same_song(c, song); + idx = playlist_get_index_from_same_song(&c->playlist, song); mpdclient_cmd_play(c, idx); return true; } @@ -327,7 +328,8 @@ browser_select_entry(struct mpdclient *c, struct filelist_entry *entry, entry->flags &= ~HIGHLIGHT; - while ((idx = playlist_get_index_from_same_song(c, song)) >= 0) + while ((idx = playlist_get_index_from_same_song(&c->playlist, + song)) >= 0) mpdclient_cmd_delete(c, idx); #endif } diff --git a/src/screen_play.c b/src/screen_play.c index ed17499..6872b13 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -176,7 +176,7 @@ center_playing_item(struct mpdclient *c, bool center_cursor) return; /* try to center the song that are playing */ - idx = playlist_get_index(c, c->song); + idx = playlist_get_index(&c->playlist, c->song); if (idx < 0) return; @@ -666,7 +666,8 @@ play_cmd(struct mpdclient *c, command_t cmd) playlist_repaint(); return false; case CMD_SELECT_PLAYING: - list_window_set_selected(lw, playlist_get_index(c, c->song)); + list_window_set_selected(lw, playlist_get_index(&c->playlist, + c->song)); return true; case CMD_SHUFFLE: {