Skip to content

Commit fe0d088

Browse files
committed
mutable song: rename a few functions
1 parent 43778b3 commit fe0d088

6 files changed

Lines changed: 22 additions & 23 deletions

File tree

‎src/actions.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ void EditLibraryTag::Run()
13791379
for (auto s = songs.begin(); s != songs.end(); ++s)
13801380
{
13811381
MPD::MutableSong es = *s;
1382-
es.setTag(set, new_tag);
1382+
es.setTags(set, new_tag);
13831383
ShowMessage("Updating tags in \"%s\"...", es.getName().c_str());
13841384
std::string path = Config.mpd_music_dir + es.getURI();
13851385
if (!TagEditor::WriteTags(es))

‎src/mutable_song.cpp‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void MutableSong::setDuration(unsigned int duration)
166166
m_duration = duration;
167167
}
168168

169-
void MutableSong::setTag(SetFunction set, const std::string &value, const std::string &delimiter)
169+
void MutableSong::setTags(SetFunction set, const std::string &value, const std::string &delimiter)
170170
{
171171
auto tags = split(value, delimiter);
172172
for (size_t i = 0; i < tags.size(); ++i)
@@ -184,17 +184,6 @@ void MutableSong::clearModifications()
184184
m_tags.clear();
185185
}
186186

187-
std::string MutableSong::getTag(mpd_tag_type tag_type, std::function<std::string()> orig_value, unsigned idx) const
188-
{
189-
auto it = m_tags.find(Tag(tag_type, idx));
190-
std::string result;
191-
if (it == m_tags.end())
192-
result = orig_value();
193-
else
194-
result = it->second;
195-
return result;
196-
}
197-
198187
void MutableSong::replaceTag(mpd_tag_type tag_type, std::string &&orig_value, const std::string &value, unsigned idx)
199188
{
200189
Tag tag(tag_type, idx);

‎src/mutable_song.h‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct MutableSong : public Song
6363
virtual unsigned getDuration() const;
6464
void setDuration(unsigned duration);
6565

66-
void setTag(SetFunction set, const std::string &value, const std::string &delimiter = "");
66+
void setTags(SetFunction set, const std::string &value, const std::string &delimiter = "");
6767

6868
bool isModified() const;
6969
void clearModifications();
@@ -88,8 +88,19 @@ struct MutableSong : public Song
8888
unsigned m_idx;
8989
};
9090

91-
std::string getTag(mpd_tag_type tag_type, std::function<std::string()> orig_value, unsigned idx) const;
92-
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value, const std::string &value, unsigned idx);
91+
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value,
92+
const std::string &value, unsigned idx);
93+
94+
template <typename F>
95+
std::string getTag(mpd_tag_type tag_type, F orig_value, unsigned idx) const {
96+
auto it = m_tags.find(Tag(tag_type, idx));
97+
std::string result;
98+
if (it == m_tags.end())
99+
result = orig_value();
100+
else
101+
result = it->second;
102+
return result;
103+
}
93104

94105
std::string m_uri;
95106
unsigned m_duration;

‎src/song.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ std::string Song::getTrack(unsigned idx) const
123123
std::string track = getTag(MPD_TAG_TRACK, idx);
124124
if ((track.length() == 1 && track[0] != '0')
125125
|| (track.length() > 3 && track[1] == '/'))
126-
return "0"+track;
127-
else
128-
return track;
126+
track = "0"+track;
127+
return track;
129128
}
130129

131130
std::string Song::getTrackNumber(unsigned idx) const

‎src/tag_editor.cpp‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ void TagEditor::EnterPressed()
525525
std::string new_tag = wFooter->getString(Tags->current().value().getTags(get));
526526
UnlockStatusbar();
527527
for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it)
528-
(*it)->setTag(set, new_tag);
528+
(*it)->setTags(set, new_tag);
529529
}
530530
else if (w == Tags)
531531
{
@@ -534,7 +534,7 @@ void TagEditor::EnterPressed()
534534
std::string new_tag = wFooter->getString(Tags->current().value().getTags(get));
535535
UnlockStatusbar();
536536
if (new_tag != Tags->current().value().getTags(get))
537-
Tags->current().value().setTag(set, new_tag);
537+
Tags->current().value().setTags(set, new_tag);
538538
Tags->scroll(NC::wDown);
539539
}
540540
}
@@ -1291,7 +1291,7 @@ std::string ParseFilename(MPD::MutableSong &s, std::string mask, bool preview)
12911291
{
12921292
MPD::MutableSong::SetFunction set = IntoSetFunction(it->first);
12931293
if (set)
1294-
s.setTag(set, it->second);
1294+
s.setTags(set, it->second);
12951295
}
12961296
else
12971297
result << "%" << it->first << ": " << it->second << "\n";

‎src/tiny_tag_editor.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void TinyTagEditor::EnterPressed()
109109
{
110110
size_t pos = option-8;
111111
Statusbar() << NC::fmtBold << SongInfo::Tags[pos].Name << ": " << NC::fmtBoldEnd;
112-
itsEdited.setTag(SongInfo::Tags[pos].Set, Global::wFooter->getString(itsEdited.getTags(SongInfo::Tags[pos].Get)));
112+
itsEdited.setTags(SongInfo::Tags[pos].Set, Global::wFooter->getString(itsEdited.getTags(SongInfo::Tags[pos].Get)));
113113
w->at(option).value().clear();
114114
w->at(option).value() << NC::fmtBold << SongInfo::Tags[pos].Name << ':' << NC::fmtBoldEnd << ' ';
115115
ShowTag(w->at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get));

0 commit comments

Comments
 (0)