PlaylistPrint.cxx 2.73 KB
Newer Older
1
/*
2
 * Copyright 2003-2018 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * 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.
14 15 16 17
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19
 */

20
#include "PlaylistPrint.hxx"
Max Kellermann's avatar
Max Kellermann committed
21
#include "PlaylistFile.hxx"
22
#include "PlaylistError.hxx"
23
#include "queue/Playlist.hxx"
Max Kellermann's avatar
Max Kellermann committed
24
#include "queue/QueuePrint.hxx"
Max Kellermann's avatar
Max Kellermann committed
25
#include "SongPrint.hxx"
26 27
#include "Partition.hxx"
#include "Instance.hxx"
28
#include "db/Interface.hxx"
29
#include "client/Response.hxx"
30

31 32 33
#define SONG_FILE "file: "
#define SONG_TIME "Time: "

34
void
35
playlist_print_uris(Response &r, const playlist &playlist)
36
{
37
	const Queue &queue = playlist.queue;
38

39
	queue_print_uris(r, queue, 0, queue.GetLength());
40 41
}

42
void
43
playlist_print_info(Response &r, const playlist &playlist,
44 45
		    unsigned start, unsigned end)
{
46
	const Queue &queue = playlist.queue;
47

48
	if (end > queue.GetLength())
49
		/* correct the "end" offset */
50
		end = queue.GetLength();
51 52 53

	if (start > end)
		/* an invalid "start" offset is fatal */
54
		throw PlaylistError::BadRange();
55

56
	queue_print_info(r, queue, start, end);
57 58
}

59
void
60
playlist_print_id(Response &r, const playlist &playlist,
61 62 63 64
		  unsigned id)
{
	int position;

65
	position = playlist.queue.IdToPosition(id);
66 67
	if (position < 0)
		/* no such song */
68
		throw PlaylistError::NoSuchSong();
69

70
	playlist_print_info(r, playlist, position, position + 1);
71 72 73
}

bool
74
playlist_print_current(Response &r, const playlist &playlist)
75
{
76
	int current_position = playlist.GetCurrentPosition();
77 78 79
	if (current_position < 0)
		return false;

80
	queue_print_info(r, playlist.queue,
81 82 83 84 85
			 current_position, current_position + 1);
	return true;
}

void
86
playlist_print_find(Response &r, const playlist &playlist,
87
		    const SongFilter &filter)
88
{
89
	queue_find(r, playlist.queue, filter);
90 91 92
}

void
93
playlist_print_changes_info(Response &r, const playlist &playlist,
94 95
			    uint32_t version,
			    unsigned start, unsigned end)
96
{
97
	queue_print_changes_info(r, playlist.queue, version,
98
				 start, end);
99 100 101
}

void
102
playlist_print_changes_position(Response &r,
103
				const playlist &playlist,
104 105
				uint32_t version,
				unsigned start, unsigned end)
106
{
107 108
	queue_print_changes_position(r, playlist.queue, version,
				     start, end);
109
}