summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e240f08)
raw | patch | inline | side by side (parent: e240f08)
author | Max Kellermann <max@duempel.org> | |
Tue, 29 Sep 2009 20:22:54 +0000 (22:22 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 29 Sep 2009 20:22:54 +0000 (22:22 +0200) |
Use the "addid"/"playid" commands in enqueue_and_play(). This
requires MPD 0.12.
requires MPD 0.12.
NEWS | patch | blob | history | |
src/playlist.c | patch | blob | history | |
src/playlist.h | patch | blob | history | |
src/screen_browser.c | patch | blob | history |
index 3c4d0fc5c07b29ea2fe7b0b6a9101e40b98b34d1..571f7bf9436f8f1b1397f0c3c199e24aa4d40e2a 100644 (file)
--- a/NEWS
+++ b/NEWS
* require MPD 0.12
* allow multiple queued database updates
* reactivate incremental playlist changes
+* optimize "add+play song" with addid/playid
ncmpc 0.15 - 2009-09-24
diff --git a/src/playlist.c b/src/playlist.c
index 5fced75f0c7c1041eb7d7280fb5a1e8f34676c62..a6e4005672dc63bb12944bba4be977551eb87689 100644 (file)
--- a/src/playlist.c
+++ b/src/playlist.c
return -1;
}
+
+gint
+playlist_get_id_from_uri(const struct mpdclient_playlist *playlist,
+ const gchar *uri)
+{
+ 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), uri) == 0)
+ return mpd_song_get_id(song);
+ }
+
+ return -1;
+}
diff --git a/src/playlist.h b/src/playlist.h
index cee91002f840f288d92602888958896fa7b549de..67319d24b346f46422a1dfb38d09f13f4492c6bf 100644 (file)
--- a/src/playlist.h
+++ b/src/playlist.h
return playlist_get_index_from_file(playlist, mpd_song_get_uri(song));
}
+gint
+playlist_get_id_from_uri(const struct mpdclient_playlist *playlist,
+ const gchar *uri);
+
+static inline gint
+playlist_get_id_from_same_song(const struct mpdclient_playlist *playlist,
+ const struct mpd_song *song)
+{
+ return playlist_get_id_from_uri(playlist, mpd_song_get_uri(song));
+}
+
#endif
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 3b80bdbccdb9343224bad7a6ab2e027cbe15bb4b..a2204f9e92aa5da4afbe73eecd652614c68370c0 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
static bool
enqueue_and_play(struct mpdclient *c, struct filelist_entry *entry)
{
- int idx;
const struct mpd_song *song = mpd_entity_get_song(entry->entity);
+ int id;
#ifndef NCMPC_MINI
- if (!(entry->flags & HIGHLIGHT)) {
+ if (!(entry->flags & HIGHLIGHT))
+ id = -1;
+ else
#endif
- if (mpdclient_cmd_add(c, song) == 0) {
- char buf[BUFSIZE];
+ id = playlist_get_id_from_same_song(&c->playlist, song);
+
+ if (id < 0) {
+ char buf[BUFSIZE];
+
+ id = mpd_run_add_id(c->connection, mpd_song_get_uri(song));
+ if (id < 0) {
+ mpdclient_handle_error(c);
+ return false;
+ }
#ifndef NCMPC_MINI
- entry->flags |= HIGHLIGHT;
+ entry->flags |= HIGHLIGHT;
#endif
- strfsong(buf, BUFSIZE, options.list_format, song);
- screen_status_printf(_("Adding \'%s\' to playlist"), buf);
- mpdclient_update(c); /* get song id */
- } else
- return false;
+ strfsong(buf, BUFSIZE, options.list_format, song);
+ screen_status_printf(_("Adding \'%s\' to playlist"), buf);
#ifndef NCMPC_MINI
}
#endif
- idx = playlist_get_index_from_same_song(&c->playlist, song);
- mpdclient_cmd_play(c, idx);
+ if (!mpd_run_play_id(c->connection, id)) {
+ mpdclient_handle_error(c);
+ return false;
+ }
+
return true;
}