summaryrefslogtreecommitdiff
path: root/src/playlist
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-07-05 19:07:05 +0200
committerMax Kellermann <max@musicpd.org>2018-07-05 19:07:05 +0200
commit3d3a1232b1d2b58d2cc05b2dd5c37f2256832693 (patch)
tree250933da4d5dc29145ce18e5a05a7f8da30396fd /src/playlist
parent09d4176210d66cf9e2d258b563a7811892c560f4 (diff)
tag/Handler: convert to class with virtual methods
Diffstat (limited to 'src/playlist')
-rw-r--r--src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx b/src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx
index afbf6a55c..63ebe911e 100644
--- a/src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx
+++ b/src/playlist/plugins/EmbeddedCuePlaylistPlugin.cxx
@@ -71,22 +71,23 @@ public:
virtual std::unique_ptr<DetachedSong> NextSong() override;
};
-static void
-embcue_tag_pair(const char *name, const char *value, void *ctx)
-{
- EmbeddedCuePlaylist *playlist = (EmbeddedCuePlaylist *)ctx;
+class ExtractCuesheetTagHandler final : public NullTagHandler {
+public:
+ std::string cuesheet;
- if (playlist->cuesheet.empty() &&
- StringEqualsCaseASCII(name, "cuesheet"))
- playlist->cuesheet = value;
-}
+ ExtractCuesheetTagHandler() noexcept:NullTagHandler(WANT_PAIR) {}
-static constexpr TagHandler embcue_tag_handler = {
- nullptr,
- nullptr,
- embcue_tag_pair,
+ void OnPair(const char *key, const char *value) noexcept override;
};
+void
+ExtractCuesheetTagHandler::OnPair(const char *name, const char *value) noexcept
+{
+ if (cuesheet.empty() &&
+ StringEqualsCaseASCII(name, "cuesheet"))
+ cuesheet = value;
+}
+
static std::unique_ptr<SongEnumerator>
embcue_playlist_open_uri(const char *uri,
gcc_unused Mutex &mutex)
@@ -97,18 +98,21 @@ embcue_playlist_open_uri(const char *uri,
const auto path_fs = AllocatedPath::FromUTF8Throw(uri);
- auto playlist = std::make_unique<EmbeddedCuePlaylist>();
-
- tag_file_scan(path_fs, embcue_tag_handler, playlist.get());
- if (playlist->cuesheet.empty())
- ScanGenericTags(path_fs, embcue_tag_handler, playlist.get());
+ ExtractCuesheetTagHandler extract_cuesheet;
+ tag_file_scan(path_fs, extract_cuesheet);
+ if (extract_cuesheet.cuesheet.empty())
+ ScanGenericTags(path_fs, extract_cuesheet);
- if (playlist->cuesheet.empty())
+ if (extract_cuesheet.cuesheet.empty())
/* no "CUESHEET" tag found */
return nullptr;
+ auto playlist = std::make_unique<EmbeddedCuePlaylist>();
+
playlist->filename = PathTraitsUTF8::GetBase(uri);
+ playlist->cuesheet = std::move(extract_cuesheet.cuesheet);
+
playlist->next = &playlist->cuesheet[0];
playlist->parser = new CueParser();