summaryrefslogtreecommitdiff
path: root/src/song.h
blob: c135fb17104a81dde7c504ba90ef79628cd564e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
 *   Copyright (C) 2008-2014 by Andrzej Rybczak                            *
 *   electricityispower@gmail.com                                          *
 *                                                                         *
 *   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.                          *
 *                                                                         *
 *   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 St, Fifth Floor, Boston, MA 02110-1301, USA.              *
 ***************************************************************************/

#ifndef NCMPCPP_SONG_H
#define NCMPCPP_SONG_H

#include <cstring>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#include <mpd/client.h>

namespace MPD {//

struct Song
{
	struct Hash {
		size_t operator()(const Song &s) const { return s.m_hash; }
	};

	typedef std::string (Song::*GetFunction)(unsigned) const;
	
	Song() : m_hash(0) { }
	virtual ~Song() { }
	
	Song(mpd_song *s);

	Song(const Song &rhs) : m_song(rhs.m_song), m_hash(rhs.m_hash) { }
	Song(Song &&rhs) : m_song(std::move(rhs.m_song)), m_hash(rhs.m_hash) { }
	Song &operator=(Song rhs) {
		m_song = std::move(rhs.m_song);
		m_hash = rhs.m_hash;
		return *this;
	}
	
	std::string get(mpd_tag_type type, unsigned idx = 0) const;
	
	virtual std::string getURI(unsigned idx = 0) const;
	virtual std::string getName(unsigned idx = 0) const;
	virtual std::string getDirectory(unsigned idx = 0) const;
	virtual std::string getArtist(unsigned idx = 0) const;
	virtual std::string getTitle(unsigned idx = 0) const;
	virtual std::string getAlbum(unsigned idx = 0) const;
	virtual std::string getAlbumArtist(unsigned idx = 0) const;
	virtual std::string getTrack(unsigned idx = 0) const;
	virtual std::string getTrackNumber(unsigned idx = 0) const;
	virtual std::string getDate(unsigned idx = 0) const;
	virtual std::string getGenre(unsigned idx = 0) const;
	virtual std::string getComposer(unsigned idx = 0) const;
	virtual std::string getPerformer(unsigned idx = 0) const;
	virtual std::string getDisc(unsigned idx = 0) const;
	virtual std::string getComment(unsigned idx = 0) const;
	virtual std::string getLength(unsigned idx = 0) const;
	virtual std::string getPriority(unsigned idx = 0) const;
	
	virtual std::string getTags(GetFunction f) const;
	
	virtual unsigned getDuration() const;
	virtual unsigned getPosition() const;
	virtual unsigned getID() const;
	virtual unsigned getPrio() const;
	virtual time_t getMTime() const;
	
	virtual bool isFromDatabase() const;
	virtual bool isStream() const;
	
	virtual bool empty() const;
	
	bool operator==(const Song &rhs) const {
		if (m_hash != rhs.m_hash)
			return false;
		return strcmp(c_uri(), rhs.c_uri()) == 0;
	}
	bool operator!=(const Song &rhs) const {
		if (m_hash != rhs.m_hash)
			return true;
		return strcmp(c_uri(), rhs.c_uri()) != 0;
	}
	
	const char *c_uri() const { return m_song ? mpd_song_get_uri(m_song.get()) : ""; }

	static std::string ShowTime(unsigned length);

	static std::string TagsSeparator;

private:
	std::shared_ptr<mpd_song> m_song;
	size_t m_hash;
};

}

#endif // NCMPCPP_SONG_H