change version to 0.6.4_pre
[ncmpcpp.git] / src / song.h
blob7e2801323e67a9a935625ed47b5ba97ce6b3b2a9
1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_SONG_H
22 #define NCMPCPP_SONG_H
24 #include <cstring>
25 #include <functional>
26 #include <memory>
27 #include <string>
28 #include <vector>
30 #include <mpd/client.h>
32 namespace MPD {//
34 struct Song
36 struct Hash {
37 size_t operator()(const Song &s) const { return s.m_hash; }
40 typedef std::string (Song::*GetFunction)(unsigned) const;
42 Song() : m_hash(0) { }
43 virtual ~Song() { }
45 Song(mpd_song *s);
47 std::string get(mpd_tag_type type, unsigned idx = 0) const;
49 virtual std::string getURI(unsigned idx = 0) const;
50 virtual std::string getName(unsigned idx = 0) const;
51 virtual std::string getDirectory(unsigned idx = 0) const;
52 virtual std::string getArtist(unsigned idx = 0) const;
53 virtual std::string getTitle(unsigned idx = 0) const;
54 virtual std::string getAlbum(unsigned idx = 0) const;
55 virtual std::string getAlbumArtist(unsigned idx = 0) const;
56 virtual std::string getTrack(unsigned idx = 0) const;
57 virtual std::string getTrackNumber(unsigned idx = 0) const;
58 virtual std::string getDate(unsigned idx = 0) const;
59 virtual std::string getGenre(unsigned idx = 0) const;
60 virtual std::string getComposer(unsigned idx = 0) const;
61 virtual std::string getPerformer(unsigned idx = 0) const;
62 virtual std::string getDisc(unsigned idx = 0) const;
63 virtual std::string getComment(unsigned idx = 0) const;
64 virtual std::string getLength(unsigned idx = 0) const;
65 virtual std::string getPriority(unsigned idx = 0) const;
67 virtual std::string getTags(GetFunction f, const std::string &tags_separator) const;
69 virtual unsigned getDuration() const;
70 virtual unsigned getPosition() const;
71 virtual unsigned getID() const;
72 virtual unsigned getPrio() const;
73 virtual time_t getMTime() const;
75 virtual bool isFromDatabase() const;
76 virtual bool isStream() const;
78 virtual bool empty() const;
80 virtual std::string toString(const std::string &fmt, const std::string &tags_separator,
81 const std::string &escape_chars = "") const;
83 bool operator==(const Song &rhs) const {
84 if (m_hash != rhs.m_hash)
85 return false;
86 return strcmp(c_uri(), rhs.c_uri()) == 0;
88 bool operator!=(const Song &rhs) const {
89 if (m_hash != rhs.m_hash)
90 return true;
91 return strcmp(c_uri(), rhs.c_uri()) != 0;
94 const char *c_uri() const { return m_song ? mpd_song_get_uri(m_song.get()) : ""; }
96 static std::string ShowTime(unsigned length);
97 static void validateFormat(const std::string &fmt);
99 static const char FormatEscapeCharacter = 1;
101 private:
102 std::string ParseFormat(std::string::const_iterator &it, const std::string &tags_separator,
103 const std::string &escape_chars) const;
105 std::shared_ptr<mpd_song> m_song;
106 size_t m_hash;
109 typedef std::vector<Song> SongList;
113 #endif // NCMPCPP_SONG_H