PlaylistPrint.cxx 3.01 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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
#include "util/Error.hxx"
32

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

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

42
	queue_print_uris(r, partition, queue, 0, queue.GetLength());
43 44
}

45
void
46 47
playlist_print_info(Response &r, Partition &partition,
		    const playlist &playlist,
48 49
		    unsigned start, unsigned end)
{
50
	const Queue &queue = playlist.queue;
51

52
	if (end > queue.GetLength())
53
		/* correct the "end" offset */
54
		end = queue.GetLength();
55 56 57

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

60
	queue_print_info(r, partition, queue, start, end);
61 62
}

63
void
64
playlist_print_id(Response &r, Partition &partition, const playlist &playlist,
65 66 67 68
		  unsigned id)
{
	int position;

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

74 75
	playlist_print_info(r, partition,
			    playlist, position, position + 1);
76 77 78
}

bool
79 80
playlist_print_current(Response &r, Partition &partition,
		       const playlist &playlist)
81
{
82
	int current_position = playlist.GetCurrentPosition();
83 84 85
	if (current_position < 0)
		return false;

86
	queue_print_info(r, partition, playlist.queue,
87 88 89 90 91
			 current_position, current_position + 1);
	return true;
}

void
92 93
playlist_print_find(Response &r, Partition &partition,
		    const playlist &playlist,
94
		    const SongFilter &filter)
95
{
96
	queue_find(r, partition, playlist.queue, filter);
97 98 99
}

void
100
playlist_print_changes_info(Response &r, Partition &partition,
101
			    const playlist &playlist,
102 103
			    uint32_t version,
			    unsigned start, unsigned end)
104
{
105 106
	queue_print_changes_info(r, partition, playlist.queue, version,
				 start, end);
107 108 109
}

void
110
playlist_print_changes_position(Response &r,
111
				const playlist &playlist,
112 113
				uint32_t version,
				unsigned start, unsigned end)
114
{
115 116
	queue_print_changes_position(r, playlist.queue, version,
				     start, end);
117
}