PlaylistPrint.cxx 2.75 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 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 "config.h"
21
#include "PlaylistPrint.hxx"
Max Kellermann's avatar
Max Kellermann committed
22
#include "PlaylistFile.hxx"
23
#include "PlaylistError.hxx"
24
#include "queue/Playlist.hxx"
Max Kellermann's avatar
Max Kellermann committed
25
#include "queue/QueuePrint.hxx"
Max Kellermann's avatar
Max Kellermann committed
26
#include "SongPrint.hxx"
27 28
#include "Partition.hxx"
#include "Instance.hxx"
29
#include "db/Interface.hxx"
30
#include "client/Response.hxx"
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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