PlaylistPrint.cxx 2.6 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 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"
25

26 27 28
#define SONG_FILE "file: "
#define SONG_TIME "Time: "

29
void
30
playlist_print_uris(Response &r, const playlist &playlist)
31
{
32
	const Queue &queue = playlist.queue;
33

34
	queue_print_uris(r, queue, 0, queue.GetLength());
35 36
}

37
void
38
playlist_print_info(Response &r, const playlist &playlist,
39 40
		    unsigned start, unsigned end)
{
41
	const Queue &queue = playlist.queue;
42

43
	if (end > queue.GetLength())
44
		/* correct the "end" offset */
45
		end = queue.GetLength();
46 47 48

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

51
	queue_print_info(r, queue, start, end);
52 53
}

54
void
55
playlist_print_id(Response &r, const playlist &playlist,
56 57 58 59
		  unsigned id)
{
	int position;

60
	position = playlist.queue.IdToPosition(id);
61 62
	if (position < 0)
		/* no such song */
63
		throw PlaylistError::NoSuchSong();
64

65
	playlist_print_info(r, playlist, position, position + 1);
66 67 68
}

bool
69
playlist_print_current(Response &r, const playlist &playlist)
70
{
71
	int current_position = playlist.GetCurrentPosition();
72 73 74
	if (current_position < 0)
		return false;

75
	queue_print_info(r, playlist.queue,
76 77 78 79 80
			 current_position, current_position + 1);
	return true;
}

void
81
playlist_print_find(Response &r, const playlist &playlist,
82
		    const SongFilter &filter)
83
{
84
	queue_find(r, playlist.queue, filter);
85 86 87
}

void
88
playlist_print_changes_info(Response &r, const playlist &playlist,
89 90
			    uint32_t version,
			    unsigned start, unsigned end)
91
{
92
	queue_print_changes_info(r, playlist.queue, version,
93
				 start, end);
94 95 96
}

void
97
playlist_print_changes_position(Response &r,
98
				const playlist &playlist,
99 100
				uint32_t version,
				unsigned start, unsigned end)
101
{
102 103
	queue_print_changes_position(r, playlist.queue, version,
				     start, end);
104
}