Code

playlist: pass struct mpdclient_playlist to functions
authorMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 20:11:23 +0000 (22:11 +0200)
committerMax Kellermann <max@duempel.org>
Tue, 29 Sep 2009 20:11:23 +0000 (22:11 +0200)
Passing a mpdclient object doesn't make sense in this library.

src/mpdclient.c
src/playlist.c
src/playlist.h
src/screen_browser.c
src/screen_play.c

index 933a14874772a6890e7cf8b44dde5407c4ebe6c4..ac7fce93d045b16540a6b8f309b88f30cc18994c 100644 (file)
@@ -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;
index 713d3c69fc4b7902c17a45b32d1dc152778f8a00..562fde69e7b40932b8a1d98740578e9ff30e1886 100644 (file)
@@ -18,7 +18,6 @@
 */
 
 #include "playlist.h"
-#include "mpdclient.h"
 
 #include <string.h>
 
@@ -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;
index b94893681aff5af70b7586fabdd452577d05cc04..580b1c98069d8fca9809c6cc5da1a35daf0a4644 100644 (file)
@@ -25,8 +25,6 @@
 #include <assert.h>
 #include <glib.h>
 
-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
index efa2a387de144d43df5f94e1681a75cb51005ec5..3b80bdbccdb9343224bad7a6ab2e027cbe15bb4b 100644 (file)
@@ -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
        }
index ed17499164d0f5bca8a4636e5372129127ab4d8d..6872b139110b9e9741001351d7d0a1842e3868bb 100644 (file)
@@ -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:
        {