summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c026efc)
raw | patch | inline | side by side (parent: c026efc)
author | Kalle Wallin <kaw@linux.se> | |
Thu, 17 Jun 2004 21:38:50 +0000 (21:38 +0000) | ||
committer | Kalle Wallin <kaw@linux.se> | |
Thu, 17 Jun 2004 21:38:50 +0000 (21:38 +0000) |
src/mpdclient.c | patch | blob | history |
diff --git a/src/mpdclient.c b/src/mpdclient.c
index c47dc3d19af9da34f5c3acf39a1edf5bb0a5dd05..bb6c90fa9e4fc5de84fef192c19bbe5a78f48030 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
#define ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_DELETE
#define ENABLE_FANCY_PLAYLIST_MANAGMENT_CMD_MOVE
#define ENABLE_SONG_ID
-#undef ENABLE_PLCHANGES /* something is broken */
+#define ENABLE_PLCHANGES
#define MPD_ERROR(c) (c==NULL || c->connection==NULL || c->connection->error)
}
#ifdef ENABLE_PLCHANGES
-static gint
-compare_songs(gconstpointer a, gconstpointer b)
+
+gint
+mpdclient_compare_songs(gconstpointer a, gconstpointer b)
{
mpd_Song *song1 = (mpd_Song *) a;
mpd_Song *song2 = (mpd_Song *) b;
return song1->pos - song2->pos;
}
+
+
/* update playlist (plchanges) */
gint
while( (entity=mpd_getNextInfoEntity(c->connection)) != NULL )
{
+
if(entity->type==MPD_INFO_ENTITY_TYPE_SONG)
{
- mpd_Song *song;
+ mpd_Song *song = entity->info.song;
GList *item;
- if( (song=mpd_songDup(entity->info.song)) == NULL )
- {
- D("song==NULL => calling mpdclient_playlist_update()\n");
- return mpdclient_playlist_update(c);
- }
-
item = playlist_lookup(c, song->id);
+#ifdef DEBUG
+ if( item )
+ D("Changing index:%d, pos:%d, id:%d => %s\n",
+ g_list_position(c->playlist.list, item),
+ song->pos, song->id, get_song_name(song));
+ else
+ D("Unable to find pos:%d, id:%d => %s\n",
+ song->pos, song->id, get_song_name(song));
+#endif
+
if( item && item->data)
{
GList *old;
gint index = g_list_position(c->playlist.list, item);
/* remove previous song at song->pos */
- if( song->pos != index &&
- (old=g_list_nth(c->playlist.list, song->pos)) )
+ while( song->pos != (index=g_list_position(c->playlist.list, item))
+ &&
+ (old=g_list_nth(c->playlist.list, song->pos)) )
{
- D("Removing item with index %d [%p]\n", index, old);
+ D("Removing item with index %d id:%d (%d)\n",
+ song->pos, old ? ((mpd_Song *) old->data)->id : -1, index);
+ if( item->data == c->song )
+ c->song = NULL;
mpd_freeSong((mpd_Song *) old->data);
old->data = NULL;
c->playlist.list = g_list_delete_link(c->playlist.list, old);
+ c->playlist.length = g_list_length(c->playlist.list);
}
/* Update playlist entry */
mpd_freeSong((mpd_Song *) item->data);
- item->data = song;
+ item->data = mpd_songDup(song);
if( c->song && c->song->id == song->id )
- c->song = song;
+ c->song = item->data;
- D("Changing index:%d, pos:%d, id:%d => %s\n",
- index, song->pos, song->id, get_song_name(song));
}
else
{
D("Adding pos:%d, id;%d - %s\n",
song->pos, song->id, get_song_name(song));
c->playlist.list = g_list_append(c->playlist.list,
- (gpointer) song);
+ (gpointer) mpd_songDup(song));
c->playlist.length++;
}
}
}
GList *
-playlist_lookup(mpdclient_t *c, gint id)
+playlist_lookup(mpdclient_t *c, int id)
{
- GList *list = c->playlist.list;
+ GList *list = g_list_first(c->playlist.list);
while( list )
{
mpd_Song *song = (mpd_Song *) list->data;
- if( (gint) song->id == id )
+ if( song->id == id )
return list;
list=list->next;
}