summaryrefslogtreecommitdiff
path: root/src/song.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/song.h')
-rw-r--r--src/song.h162
1 files changed, 54 insertions, 108 deletions
diff --git a/src/song.h b/src/song.h
index a63cf4a8..dce19d1a 100644
--- a/src/song.h
+++ b/src/song.h
@@ -21,120 +21,66 @@
#ifndef _SONG_H
#define _SONG_H
-#include <map>
+#include <functional>
+#include <memory>
#include <string>
#include <mpd/client.h>
-namespace MPD
+namespace MPD {//
+
+struct Song
{
- class Song
- {
- typedef std::map<std::pair<mpd_tag_type, unsigned>, std::string> TagMap;
+ typedef std::string (Song::*GetFunction)(unsigned) const;
+
+ Song() { }
+ Song(mpd_song *s);
+
+ std::string getURI(unsigned idx = 0) const;
+ std::string getName(unsigned idx = 0) const;
+ std::string getDirectory(unsigned idx = 0) const;
+ std::string getArtist(unsigned idx = 0) const;
+ std::string getTitle(unsigned idx = 0) const;
+ std::string getAlbum(unsigned idx = 0) const;
+ std::string getAlbumArtist(unsigned idx = 0) const;
+ std::string getTrack(unsigned idx = 0) const;
+ std::string getTrackNumber(unsigned idx = 0) const;
+ std::string getDate(unsigned idx = 0) const;
+ std::string getGenre(unsigned idx = 0) const;
+ std::string getComposer(unsigned idx = 0) const;
+ std::string getPerformer(unsigned idx = 0) const;
+ std::string getDisc(unsigned idx = 0) const;
+ std::string getComment(unsigned idx = 0) const;
+ std::string getLength(unsigned idx = 0) const;
+ std::string getPriority(unsigned idx = 0) const;
+
+ std::string getTags(GetFunction f, const std::string tag_separator = ", ") const;
+
+ unsigned getHash() const;
+ unsigned getDuration() const;
+ unsigned getPosition() const;
+ unsigned getID() const;
+ unsigned getPrio() const;
+ time_t getMTime() const;
+
+ bool isFromDatabase() const;
+ bool isStream() const;
+
+ bool empty() const;
+
+ std::string toString(const std::string &fmt, const std::string &tag_separator = ", ", const std::string &escape_chars = "") const;
+
+ static std::string ShowTime(unsigned length);
+ static bool isFormatOk(const std::string &type, const std::string &fmt);
+
+ static const char FormatEscapeCharacter = 1;
+
+ private:
+ std::string ParseFormat(std::string::const_iterator &it, const std::string &tag_separator, const std::string &escape_chars) const;
- public:
-
- typedef void (Song::*SetFunction)(const std::string &, unsigned);
- typedef std::string (Song::*GetFunction)(unsigned) const;
-
- Song(mpd_song * = 0, bool = 0);
- Song(const Song &);
- ~Song();
-
- std::string GetFile(unsigned = 0) const;
- std::string GetName(unsigned = 0) const;
- std::string GetDirectory(unsigned = 0) const;
- std::string GetArtist(unsigned = 0) const;
- std::string GetTitle(unsigned = 0) const;
- std::string GetAlbum(unsigned = 0) const;
- std::string GetAlbumArtist(unsigned = 0) const;
- std::string GetTrack(unsigned = 0) const;
- std::string GetTrackNumber(unsigned = 0) const;
- std::string GetDate(unsigned = 0) const;
- std::string GetGenre(unsigned = 0) const;
- std::string GetComposer(unsigned = 0) const;
- std::string GetPerformer(unsigned = 0) const;
- std::string GetDisc(unsigned = 0) const;
- std::string GetComment(unsigned = 0) const;
- std::string GetLength(unsigned = 0) const;
- std::string GetPriority(unsigned = 0) const;
-
- std::string GetTags(GetFunction) const;
-
- unsigned GetHash() const { return itsHash; }
- unsigned GetTotalLength() const { return mpd_song_get_duration(itsSong); }
- unsigned GetPosition() const { return mpd_song_get_pos(itsSong); }
- unsigned GetID() const { return mpd_song_get_id(itsSong); }
- unsigned GetPrio() const { return mpd_song_get_prio(itsSong); }
-
- time_t GetMTime() const { return mpd_song_get_last_modified(itsSong); }
-
- void SetArtist(const std::string &, unsigned = 0);
- void SetTitle(const std::string &, unsigned = 0);
- void SetAlbum(const std::string &, unsigned = 0);
- void SetAlbumArtist(const std::string &, unsigned = 0);
- void SetTrack(const std::string &, unsigned = 0);
- void SetTrack(unsigned, unsigned = 0);
- void SetDate(const std::string &, unsigned = 0);
- void SetGenre(const std::string &, unsigned = 0);
- void SetComposer(const std::string &, unsigned = 0);
- void SetPerformer(const std::string &, unsigned = 0);
- void SetDisc(const std::string &, unsigned = 0);
- void SetComment(const std::string &, unsigned = 0);
-
- void SetTags(SetFunction, const std::string &);
-
- void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
- std::string GetNewName() const { return itsNewName; }
-
- std::string toString(const std::string &, const char *escape_chars = 0) const;
- static const char FormatEscapeCharacter = 1;
-
- void NullMe() { itsSong = 0; }
- void CopyPtr(bool copy) { copyPtr = copy; }
-
- void Localize();
- void Clear();
- bool Empty() const;
- bool isFromDB() const;
- bool isStream() const;
- bool Localized() const { return isLocalised; }
-
- Song &operator=(const Song &);
-
- static std::string ShowTime(int);
- static bool isFormatOk(const std::string &type, const std::string &format);
-
- private:
- void SetHashAndSlash();
- std::string ParseFormat(std::string::const_iterator &it, const char *escape_chars) const;
-
- void SetTag(mpd_tag_type, unsigned, const std::string &);
- std::string GetTag(mpd_tag_type, unsigned) const;
-
- /// Used internally for handling filename, since we don't have
- /// write access to file string in mpd_song, manage our own if
- /// localization was done and there is localized filename that
- /// is different than the original one.
- ///
- const char *MyFilename() const;
-
- /// internal mpd_song structure
- mpd_song *itsSong;
-
- /// localized version of filename
- const char *itsFile;
-
- /// map that contains localized tags or these set by tag editor
- TagMap *itsTags;
-
- std::string itsNewName;
-
- size_t itsSlash;
- unsigned itsHash;
- bool copyPtr;
- bool isLocalised;
- };
+ std::shared_ptr<struct SongImpl> pimpl;
+};
+
}
#endif