Permalink
Browse files

[embedded art] adds EmbeddedArt members to CSong and CMusicInfoTag, a…

…nd adds art attribute to CAlbum
  • Loading branch information...
Jonathan Marshall
Jonathan Marshall committed May 26, 2012
1 parent 24a5ea0 commit d21a2987325a94c3675aa0d8f9b3cfa4e957d28d
Showing with 111 additions and 5 deletions.
  1. +2 −0 xbmc/music/Album.h
  2. +15 −0 xbmc/music/Song.cpp
  3. +13 −5 xbmc/music/Song.h
  4. +52 −0 xbmc/music/tags/MusicInfoTag.cpp
  5. +29 −0 xbmc/music/tags/MusicInfoTag.h
View
@@ -49,6 +49,7 @@ class CAlbum
moods.clear();
styles.clear();
themes.clear();
+ art.clear();
strReview.Empty();
strLabel.Empty();
strType.Empty();
@@ -77,6 +78,7 @@ class CAlbum
std::vector<std::string> moods;
std::vector<std::string> styles;
std::vector<std::string> themes;
+ std::map<std::string, std::string> art;
CStdString strReview;
CStdString strLabel;
CStdString strType;
View
@@ -47,6 +47,7 @@ CSong::CSong(CMusicInfoTag& tag)
iTrack = tag.GetTrackAndDiskNumber();
iDuration = tag.GetDuration();
bCompilation = tag.GetCompilation();
+ embeddedArt = tag.GetCoverArtInfo();
strThumb = "";
iStartOffset = 0;
iEndOffset = 0;
@@ -118,6 +119,20 @@ void CSong::Clear()
iArtistId = -1;
iAlbumId = -1;
bCompilation = false;
+ embeddedArt.clear();
+}
+
+bool CSong::HasArt() const
+{
+ if (!strThumb.empty()) return true;
+ if (!embeddedArt.empty()) return true;
+ return false;
+}
+
+bool CSong::ArtMatches(const CSong &right) const
+{
+ return (right.strThumb == strThumb &&
+ embeddedArt.matches(right.embeddedArt));
}
CSongMap::CSongMap()
View
@@ -27,15 +27,11 @@
#include "utils/StdString.h"
#include "utils/ISerializable.h"
#include "XBDateTime.h"
+#include "music/tags/MusicInfoTag.h" // for EmbeddedArt
#include <map>
#include <vector>
-namespace MUSIC_INFO
-{
- class CMusicInfoTag;
-}
-
/*!
\ingroup music
\brief Class to store and read album information from CMusicDatabase
@@ -71,6 +67,17 @@ class CSong: public ISerializable
if (iTrack < song.iTrack) return true;
return false;
}
+
+ /*! \brief whether this song has art associated with it
+ Tests both the strThumb and embeddedArt members.
+ */
+ bool HasArt() const;
+
+ /*! \brief whether the art from this song matches the art from another
+ Tests both the strThumb and embeddedArt members.
+ */
+ bool ArtMatches(const CSong &right) const;
+
long idSong;
CStdString strFileName;
CStdString strTitle;
@@ -79,6 +86,7 @@ class CSong: public ISerializable
std::vector<std::string> albumArtist;
std::vector<std::string> genre;
CStdString strThumb;
+ MUSIC_INFO::EmbeddedArtInfo embeddedArt;
CStdString strMusicBrainzTrackID;
CStdString strMusicBrainzArtistID;
CStdString strMusicBrainzAlbumID;
@@ -27,6 +27,46 @@
using namespace MUSIC_INFO;
+EmbeddedArtInfo::EmbeddedArtInfo(size_t siz, const std::string &mim)
+{
+ set(siz, mim);
+}
+
+void EmbeddedArtInfo::set(size_t siz, const std::string &mim)
+{
+ size = siz;
+ mime = mim;
+}
+
+void EmbeddedArtInfo::clear()
+{
+ mime.clear();
+ size = 0;
+}
+
+bool EmbeddedArtInfo::empty() const
+{
+ return size == 0;
+}
+
+bool EmbeddedArtInfo::matches(const EmbeddedArtInfo &right) const
+{
+ return (size == right.size &&
+ mime == right.mime);
+}
+
+EmbeddedArt::EmbeddedArt(const uint8_t *dat, size_t siz, const std::string &mim)
+{
+ set(dat, siz, mim);
+}
+
+void EmbeddedArt::set(const uint8_t *dat, size_t siz, const std::string &mim)
+{
+ EmbeddedArtInfo::set(siz, mim);
+ data.resize(siz);
+ memcpy(&data[0], dat, siz);
+}
+
CMusicInfoTag::CMusicInfoTag(void)
{
Clear();
@@ -70,6 +110,7 @@ const CMusicInfoTag& CMusicInfoTag::operator =(const CMusicInfoTag& tag)
m_iArtistId = tag.m_iArtistId;
m_iAlbumId = tag.m_iAlbumId;
memcpy(&m_dwReleaseDate, &tag.m_dwReleaseDate, sizeof(m_dwReleaseDate) );
+ m_coverArt = tag.m_coverArt;
return *this;
}
@@ -209,6 +250,11 @@ bool CMusicInfoTag::GetCompilation() const
return m_bCompilation;
}
+const EmbeddedArtInfo &CMusicInfoTag::GetCoverArtInfo() const
+{
+ return m_coverArt;
+}
+
void CMusicInfoTag::SetURL(const CStdString& strURL)
{
m_strURL = strURL;
@@ -401,6 +447,11 @@ void CMusicInfoTag::SetMusicBrainzTRMID(const CStdString& strTRMID)
m_strMusicBrainzTRMID=strTRMID;
}
+void CMusicInfoTag::SetCoverArtInfo(size_t size, const std::string &mimeType)
+{
+ m_coverArt.set(size, mimeType);
+}
+
void CMusicInfoTag::SetAlbum(const CAlbum& album)
{
SetArtist(album.artist);
@@ -574,6 +625,7 @@ void CMusicInfoTag::Clear()
memset(&m_dwReleaseDate, 0, sizeof(m_dwReleaseDate) );
m_iArtistId = -1;
m_iAlbumId = -1;
+ m_coverArt.clear();
}
void CMusicInfoTag::AppendArtist(const CStdString &artist)
@@ -24,13 +24,38 @@
class CSong;
class CAlbum;
+#include <vector>
+#include <string>
+#include <stdint.h>
+
#include "utils/Archive.h"
#include "utils/ISerializable.h"
#include "utils/ISortable.h"
#include "XBDateTime.h"
namespace MUSIC_INFO
{
+ class EmbeddedArtInfo
+ {
+ public:
+ EmbeddedArtInfo() {};
+ EmbeddedArtInfo(size_t size, const std::string &mime);
+ void set(size_t size, const std::string &mime);
+ void clear();
+ bool empty() const;
+ bool matches(const EmbeddedArtInfo &right) const;
+ size_t size;
+ std::string mime;
+ };
+
+ class EmbeddedArt : public EmbeddedArtInfo
+ {
+ public:
+ EmbeddedArt() {};
+ EmbeddedArt(const uint8_t *data, size_t size, const std::string &mime);
+ void set(const uint8_t *data, size_t size, const std::string &mime);
+ std::vector<uint8_t> data;
+ };
class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
{
@@ -70,6 +95,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
char GetRating() const;
int GetListeners() const;
int GetPlayCount() const;
+ const EmbeddedArtInfo &GetCoverArtInfo() const;
void SetURL(const CStdString& strURL);
void SetTitle(const CStdString& strTitle);
@@ -105,6 +131,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
void SetLastPlayed(const CStdString& strLastPlayed);
void SetLastPlayed(const CDateTime& strLastPlayed);
void SetCompilation(bool compilation);
+ void SetCoverArtInfo(size_t size, const std::string &mimeType);
/*! \brief Append a unique artist to the artist list
Checks if we have this artist already added, and if not adds it to the songs artist list.
@@ -162,5 +189,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
int m_iArtistId;
int m_iAlbumId;
SYSTEMTIME m_dwReleaseDate;
+
+ EmbeddedArtInfo m_coverArt; ///< art information
};
}

0 comments on commit d21a298

Please sign in to comment.