1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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. *
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. *
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
30 #include <mpd/client.h>
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) { }
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
)
86 return strcmp(c_uri(), rhs
.c_uri()) == 0;
88 bool operator!=(const Song
&rhs
) const {
89 if (m_hash
!= rhs
.m_hash
)
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;
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
;
109 typedef std::vector
<Song
> SongList
;
113 #endif // NCMPCPP_SONG_H