PlaylistPrint.cxx 2.99 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 37
playlist_print_uris(Response &r, Partition &partition,
		    const playlist &playlist)
38
{
39
	const Queue &queue = playlist.queue;
40

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

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

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

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

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

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

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

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

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

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

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

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

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