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
114
115
|
/***************************************************************************
* Copyright (C) 2008-2013 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_EDITABLE_SONG_H
#define NCMPCPP_EDITABLE_SONG_H
#include <map>
#include "song.h"
namespace MPD {//
struct MutableSong : public Song
{
typedef void (MutableSong::*SetFunction)(const std::string &, unsigned);
MutableSong() : m_mtime(0), m_duration(0) { }
MutableSong(Song s) : Song(s), m_mtime(0), m_duration(0) { }
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 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;
void setArtist(const std::string &value, unsigned idx = 0);
void setTitle(const std::string &value, unsigned idx = 0);
void setAlbum(const std::string &value, unsigned idx = 0);
void setAlbumArtist(const std::string &value, unsigned idx = 0);
void setTrack(const std::string &value, unsigned idx = 0);
void setDate(const std::string &value, unsigned idx = 0);
void setGenre(const std::string &value, unsigned idx = 0);
void setComposer(const std::string &value, unsigned idx = 0);
void setPerformer(const std::string &value, unsigned idx = 0);
void setDisc(const std::string &value, unsigned idx = 0);
void setComment(const std::string &value, unsigned idx = 0);
const std::string &getNewURI() const;
void setNewURI(const std::string &value);
virtual unsigned getDuration() const;
virtual time_t getMTime() const;
void setDuration(unsigned duration);
void setMTime(time_t mtime);
void setTags(SetFunction set, const std::string &value, const std::string &delimiter);
bool isModified() const;
void clearModifications();
private:
struct Tag
{
Tag(mpd_tag_type type_, unsigned idx_) : m_type(type_), m_idx(idx_) { }
mpd_tag_type type() const { return m_type; }
unsigned idx() const { return m_idx; }
bool operator<(const Tag &t) const
{
if (m_type != t.m_type)
return m_type < t.m_type;
return m_idx < t.m_idx;
}
private:
mpd_tag_type m_type;
unsigned m_idx;
};
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value,
const std::string &value, unsigned idx);
template <typename F>
std::string getTag(mpd_tag_type tag_type, F orig_value, unsigned idx) const {
auto it = m_tags.find(Tag(tag_type, idx));
std::string result;
if (it == m_tags.end())
result = orig_value();
else
result = it->second;
return result;
}
std::string m_uri;
time_t m_mtime;
unsigned m_duration;
std::map<Tag, std::string> m_tags;
};
}
#endif // NCMPCPP_EDITABLE_SONG_H
|