aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am2
-rw-r--r--src/playlist.c41
-rw-r--r--src/queue_print.c79
-rw-r--r--src/queue_print.h52
4 files changed, 142 insertions, 32 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 704e2a6a..104d6426 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -93,6 +93,7 @@ mpd_headers = \
playlist.h \
playlist_save.h \
queue.h \
+ queue_print.h \
replay_gain.h \
sig_handlers.h \
song.h \
@@ -177,6 +178,7 @@ mpd_SOURCES = \
playlist.c \
playlist_save.c \
queue.c \
+ queue_print.c \
replay_gain.c \
sig_handlers.c \
song.c \
diff --git a/src/playlist.c b/src/playlist.c
index 0a3f3271..5945d088 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -18,6 +18,7 @@
#include "playlist.h"
#include "playlist_save.h"
+#include "queue_print.h"
#include "player_control.h"
#include "command.h"
#include "ls.h"
@@ -155,12 +156,8 @@ void clearPlaylist(void)
void showPlaylist(struct client *client)
{
- for (unsigned i = 0; i < queue_length(&playlist.queue); i++) {
- const struct song *song = queue_get(&playlist.queue, i);
- char *uri = song_get_uri(song);
- client_printf(client, "%i:%s\n", i, uri);
- g_free(uri);
- }
+ queue_print_uris(client, &playlist.queue,
+ 0, queue_length(&playlist.queue));
}
static void playlist_save(FILE *fp)
@@ -313,31 +310,15 @@ void readPlaylistState(FILE *fp)
}
}
-static void printPlaylistSongInfo(struct client *client, unsigned song)
-{
- song_print_info(client, queue_get(&playlist.queue, song));
- client_printf(client, "Pos: %u\nId: %u\n",
- song, queue_position_to_id(&playlist.queue, song));
-}
-
int playlistChanges(struct client *client, uint32_t version)
{
- for (unsigned i = 0; i < queue_length(&playlist.queue); i++) {
- if (queue_song_newer(&playlist.queue, i, version))
- printPlaylistSongInfo(client, i);
- }
-
+ queue_print_changes_info(client, &playlist.queue, version);
return 0;
}
int playlistChangesPosId(struct client *client, uint32_t version)
{
- for (unsigned i = 0; i < queue_length(&playlist.queue); i++) {
- if (queue_song_newer(&playlist.queue, i, version))
- client_printf(client, "cpos: %i\nId: %i\n",
- i, queue_position_to_id(&playlist.queue, i));
- }
-
+ queue_print_changes_position(client, &playlist.queue, version);
return 0;
}
@@ -350,9 +331,7 @@ playlistInfo(struct client *client, unsigned start, unsigned end)
if (start > end)
return PLAYLIST_RESULT_BAD_RANGE;
- for (unsigned i = start; i < end; i++)
- printPlaylistSongInfo(client, i);
-
+ queue_print_info(client, &playlist.queue, start, end);
return PLAYLIST_RESULT_SUCCESS;
}
@@ -374,9 +353,7 @@ enum playlist_result playlistId(struct client *client, int id)
end = begin + 1;
}
- for (unsigned i = begin; i < end; i++)
- printPlaylistSongInfo(client, i);
-
+ queue_print_info(client, &playlist.queue, begin, end);
return PLAYLIST_RESULT_SUCCESS;
}
@@ -1312,7 +1289,7 @@ searchForSongsInPlaylist(struct client *client,
const struct song *song = queue_get(&playlist.queue, i);
if (strstrSearchTags(song, numItems, items))
- printPlaylistSongInfo(client, i);
+ queue_print_song_info(client, &playlist.queue, i);
}
freeLocateTagItemArray(numItems, new_items);
@@ -1326,7 +1303,7 @@ findSongsInPlaylist(struct client *client,
const struct song *song = queue_get(&playlist.queue, i);
if (tagItemsFoundAndMatches(song, numItems, items))
- printPlaylistSongInfo(client, i);
+ queue_print_song_info(client, &playlist.queue, i);
}
}
diff --git a/src/queue_print.c b/src/queue_print.c
new file mode 100644
index 00000000..4ff43b18
--- /dev/null
+++ b/src/queue_print.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "queue_print.h"
+#include "queue.h"
+#include "song.h"
+#include "song_print.h"
+#include "client.h"
+
+void
+queue_print_song_info(struct client *client, const struct queue *queue,
+ unsigned position)
+{
+ song_print_info(client, queue_get(queue, position));
+ client_printf(client, "Pos: %u\nId: %u\n",
+ position, queue_position_to_id(queue, position));
+}
+
+void
+queue_print_info(struct client *client, const struct queue *queue,
+ unsigned start, unsigned end)
+{
+ assert(start <= end);
+ assert(end <= queue_length(queue));
+
+ for (unsigned i = start; i < end; ++i)
+ queue_print_song_info(client, queue, i);
+}
+
+void
+queue_print_uris(struct client *client, const struct queue *queue,
+ unsigned start, unsigned end)
+{
+ assert(start <= end);
+ assert(end <= queue_length(queue));
+
+ for (unsigned i = start; i < end; ++i) {
+ const struct song *song = queue_get(queue, i);
+ char *uri = song_get_uri(song);
+
+ client_printf(client, "%i:%s\n", i, uri);
+ g_free(uri);
+ }
+}
+
+void
+queue_print_changes_info(struct client *client, const struct queue *queue,
+ uint32_t version)
+{
+ for (unsigned i = 0; i < queue_length(queue); i++) {
+ if (queue_song_newer(queue, i, version))
+ queue_print_song_info(client, queue, i);
+ }
+}
+
+void
+queue_print_changes_position(struct client *client, const struct queue *queue,
+ uint32_t version)
+{
+ for (unsigned i = 0; i < queue_length(queue); i++)
+ if (queue_song_newer(queue, i, version))
+ client_printf(client, "cpos: %i\nId: %i\n",
+ i, queue_position_to_id(queue, i));
+}
diff --git a/src/queue_print.h b/src/queue_print.h
new file mode 100644
index 00000000..c67caff6
--- /dev/null
+++ b/src/queue_print.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * This library sends information about songs in the queue to the
+ * client.
+ */
+
+#ifndef QUEUE_PRINT_H
+#define QUEUE_PRINT_H
+
+#include <stdint.h>
+
+struct client;
+struct queue;
+
+void
+queue_print_song_info(struct client *client, const struct queue *queue,
+ unsigned position);
+
+void
+queue_print_info(struct client *client, const struct queue *queue,
+ unsigned start, unsigned end);
+
+void
+queue_print_uris(struct client *client, const struct queue *queue,
+ unsigned start, unsigned end);
+
+void
+queue_print_changes_info(struct client *client, const struct queue *queue,
+ uint32_t version);
+
+void
+queue_print_changes_position(struct client *client, const struct queue *queue,
+ uint32_t version);
+
+#endif