668 changes: 416 additions & 252 deletions mythplugins/mythmusic/mythmusic/metadata.cpp

Large diffs are not rendered by default.

111 changes: 75 additions & 36 deletions mythplugins/mythmusic/mythmusic/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ using namespace std;


class AllMusic;
class CoverArt;
class AlbumArtImages;
class PlaylistContainer;
class MetaIO;

enum ImageType
{
Expand All @@ -31,28 +32,54 @@ enum ImageType
IT_LAST
};

typedef struct AlbumArtImage
class AlbumArtImage
{
int id;
QString filename;
ImageType imageType;
QString typeName;
QString description;
bool embedded;
} AlbumArtImage;
public:
AlbumArtImage(void) :
id(0), filename(""), imageType(IT_UNKNOWN),
description(""), embedded(false) {}
AlbumArtImage(AlbumArtImage *image) :
id(image->id), filename(image->filename), imageType(image->imageType),
description(image->description), embedded(image->embedded) {}
int id;
QString filename;
ImageType imageType;
QString description;
bool embedded;
};
typedef QList<AlbumArtImage*> AlbumArtList;

typedef QList<AlbumArtImage*> AlbumArtList;

typedef QHash<QString,QString> MetadataMap;


enum RepoType
{
RT_Database = 0,
RT_CD = 1,
RT_Radio = 2
};

#define METADATA_BITS_FOR_REPO 8
#define METADATA_REPO_SHIFT 24
#define METADATA_REPO_MASK 0xff000000
#define METADATA_ID_MASK 0x00ffffff

#define ID_TO_ID(x) x & METADATA_ID_MASK;
#define ID_TO_REPO(x) x >> METADATA_REPO_SHIFT

class Metadata
{
public:

typedef uint32_t IdType;

Metadata(QString lfilename = "", QString lartist = "", QString lcompilation_artist = "",
QString lalbum = "", QString ltitle = "", QString lgenre = "",
int lyear = 0, int ltracknum = 0, int llength = 0, int lid = 0,
int lrating = 0, int lplaycount = 0, QDateTime llastplay = QDateTime(),
bool lcompilation = false, QString lformat = "")
QDateTime ldateadded = QDateTime(), bool lcompilation = false, QString lformat = "")
: m_artist(lartist),
m_compilation_artist(lcompilation_artist),
m_album(lalbum),
Expand All @@ -71,9 +98,10 @@ class Metadata
m_albumid(-1),
m_genreid(-1),
m_lastplay(llastplay),
m_dateadded(ldateadded),
m_playcount(lplaycount),
m_compilation(lcompilation),
m_albumart(),
m_albumArt(NULL),
m_id(lid),
m_filename(lfilename),
m_changed(false),
Expand All @@ -82,13 +110,15 @@ class Metadata
checkEmptyFields();
}

~Metadata();

Metadata(const Metadata &other)
{
*this = other;
m_changed = false;
}

Metadata& operator=(Metadata *rhs);
Metadata& operator=(const Metadata &other);

QString Artist() const { return m_artist; }
void setArtist(const QString &lartist)
Expand Down Expand Up @@ -142,8 +172,11 @@ class Metadata
int Playcount() const { return m_playcount; }
void setPlaycount(int lplaycount) { m_playcount = lplaycount; }

unsigned int ID() const { return m_id; }
void setID(int lid) { m_id = lid; }
IdType ID() const { return m_id; }
void setID(IdType lid) { m_id = lid; }
void setRepo(RepoType repo) { m_id = (m_id & METADATA_ID_MASK) | (repo << METADATA_REPO_SHIFT); }

bool isCDTrack(void) { return ID_TO_REPO(m_id) == RT_CD; }

QString Filename() const { return m_filename; }
void setFilename(const QString &lfilename) { m_filename = lfilename; }
Expand Down Expand Up @@ -175,7 +208,7 @@ class Metadata
}
bool determineIfCompilation(bool cd = false);

void setEmbeddedAlbumArt(const QList<struct AlbumArtImage> &art);
void setEmbeddedAlbumArt(AlbumArtList &albumart);

bool isInDatabase(void);
void dumpToDatabase(void);
Expand All @@ -193,18 +226,17 @@ class Metadata
static QString GetStartdir() { return m_startdir; }

static QStringList fillFieldList(QString field);
static Metadata *getMetadataFromID(int id);

// this looks for any image available - preferring a front cover if available
QImage getAlbumArt(void);
// this looks only for the given image type
QImage getAlbumArt(ImageType type);

// this looks for any image available - preferring a front cover if available
QString getAlbumArtFile(void);
// this looks only for the given image type
QString getAlbumArtFile(ImageType type);

AlbumArtImages *getAlbumArtImages(void);
void reloadAlbumArtImages(void);

MetaIO *getTagger(void);

private:
void setCompilationFormatting(bool cd = false);
QString formatReplaceSymbols(const QString &format);
Expand All @@ -228,15 +260,17 @@ class Metadata
int m_albumid;
int m_genreid;
QDateTime m_lastplay;
QDateTime m_dateadded;
int m_playcount;
bool m_compilation;
QList<struct AlbumArtImage> m_albumart;

unsigned int m_id;
QString m_filename;
bool m_changed;
AlbumArtImages *m_albumArt;

bool m_show;
IdType m_id;
QString m_filename;
bool m_changed;

bool m_show;

static QString m_startdir;

Expand Down Expand Up @@ -366,6 +400,8 @@ class AllMusic
void resetListings(){m_last_listed = -1;}
void setAllVisible(bool visible);

MetadataPtrList *getAllMetadata(void) { return &m_all_music; }

private:

MetadataPtrList m_all_music;
Expand Down Expand Up @@ -428,30 +464,33 @@ extern MPUBLIC MusicData *gMusicData;

//----------------------------------------------------------------------------


class AlbumArtImages
{
public:
AlbumArtImages(Metadata *metadata);
~AlbumArtImages();

typedef vector<AlbumArtImage*> ImageList;

uint getImageCount() { return m_imageList.size(); }
AlbumArtImage *getImage(ImageType type);
QString getTypeName(ImageType type);
QStringList getImageFilenames(void) const;
ImageList *getImageList(void) { return &m_imageList; }
AlbumArtImage *getImageAt(uint index);
void addImage(const AlbumArtImage &newImage);
uint getImageCount() { return m_imageList.size(); }
AlbumArtImage *getImage(ImageType type);
QStringList getImageFilenames(void) const;
AlbumArtList *getImageList(void) { return &m_imageList; }
AlbumArtImage *getImageAt(uint index);

bool saveImageType(const int id, ImageType type);

void dumpToDatabase(void);

static ImageType guessImageType(const QString &filename);
static QString getTypeName(ImageType type);
static QString getTypeFilename(ImageType type);

private:
void findImages(void);

Metadata *m_parent;
ImageList m_imageList;
Metadata *m_parent;
AlbumArtList m_imageList;
};

Q_DECLARE_METATYPE(AlbumArtImage*);
Expand Down
11 changes: 9 additions & 2 deletions mythplugins/mythmusic/mythmusic/metaio.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class MetaIO
/*!
* \brief Writes rating and playcount back to a file
*
* \param rating Integer between 0 and 10 representing the rating given to
* this file by the user
* \param mdata A pointer to a Metadata object
* \returns Boolean to indicate success/failure.
*/
virtual bool writeVolatileMetadata(const Metadata* mdata)
Expand Down Expand Up @@ -57,6 +56,7 @@ class MetaIO
/*!
* \brief Reads the list of embedded images in the tag
*
* \param filename The filename to read images from.
* \returns the list of embedded images
*/
virtual AlbumArtList getAlbumArtList(const QString &filename)
Expand All @@ -79,6 +79,13 @@ class MetaIO
return false;
}

virtual QImage *getAlbumArt(QString filename, ImageType type)
{
(void)filename;
(void)type;
return false;
}

void readFromFilename(QString filename, QString &artist, QString &album,
QString &title, QString &genre, int &tracknum);

Expand Down
15 changes: 8 additions & 7 deletions mythplugins/mythmusic/mythmusic/metaioid3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ Metadata *MetaIOID3::read(QString filename)
*
* \param filename The filename for which we want to find the length.
* \param type The type of image we want - front/back etc
* \returns A QByteArray that can contains the image data.
* \returns A pointer to a QImage owned by the caller or NULL if not found.
*/
QImage MetaIOID3::getAlbumArt(QString filename, ImageType type)
QImage* MetaIOID3::getAlbumArt(QString filename, ImageType type)
{
QImage picture;
QImage *picture = new QImage();

AttachedPictureFrame::Type apicType
= AttachedPictureFrame::FrontCover;
Expand Down Expand Up @@ -282,9 +282,8 @@ QImage MetaIOID3::getAlbumArt(QString filename, ImageType type)
static_cast<AttachedPictureFrame *>(*it);
if (frame && frame->type() == apicType)
{
QImage picture;
picture.loadFromData((const uchar *)frame->picture().data(),
frame->picture().size());
picture->loadFromData((const uchar *)frame->picture().data(),
frame->picture().size());
return picture;
}
}
Expand All @@ -293,7 +292,9 @@ QImage MetaIOID3::getAlbumArt(QString filename, ImageType type)
delete mpegfile;
}

return picture;
delete picture;

return NULL;
}


Expand Down
2 changes: 1 addition & 1 deletion mythplugins/mythmusic/mythmusic/metaioid3.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MetaIOID3 : public MetaIOTagLib

Metadata* read(QString filename);
AlbumArtList getAlbumArtList(const QString &filename);
static QImage getAlbumArt(QString filename, ImageType type);
QImage *getAlbumArt(QString filename, ImageType type);

bool supportsEmbeddedImages(void) { return true; }

Expand Down
24 changes: 9 additions & 15 deletions mythplugins/mythmusic/mythmusic/musiccommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1234,16 +1234,14 @@ void MusicCommon::updateTrackInfo(Metadata *mdata)
m_maxTime = mdata->Length() / 1000;
if (m_coverartImage)
{
//FIXME: change this to use the filename
QImage image = gPlayer->getCurrentMetadata()->getAlbumArt();
if (!image.isNull())
QString filename = mdata->getAlbumArtFile();
if (!filename.isEmpty())
{
MythImage *mimage = GetMythPainter()->GetFormatImage();
mimage->Assign(image);
m_coverartImage->SetImage(mimage);
m_coverartImage->SetFilename(filename);
m_coverartImage->Load();
}
else
m_coverartImage->Reset();
m_coverartImage->Reset();
}

if (m_ratingState)
Expand Down Expand Up @@ -1275,15 +1273,11 @@ void MusicCommon::updateAlbumArtImage(Metadata *mdata)
if (!m_coverartImage || !mdata)
return;

QSize img_size = m_coverartImage->GetArea().size();

QImage albumArt = mdata->getAlbumArt();

if (!albumArt.isNull())
QString filename = mdata->getAlbumArtFile();
if (!filename.isEmpty())
{
MythImage *mimage = GetMythPainter()->GetFormatImage();
mimage->Assign(albumArt);
m_coverartImage->SetImage(mimage);
m_coverartImage->SetFilename(filename);
m_coverartImage->Load();
}
else
m_coverartImage->Reset();
Expand Down
5 changes: 4 additions & 1 deletion mythplugins/mythmusic/mythmusic/playbackbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,10 @@ void PlaybackBoxMusic::showAlbumArtImage(Metadata *mdata)

QSize img_size = albumart_image->GetSize(true);

QImage albumArt = mdata->getAlbumArt();
QImage albumArt;
QString imageFilename = mdata->getAlbumArtFile();
if (!imageFilename.isEmpty())
albumArt.load(imageFilename);

if (!albumArt.isNull())
{
Expand Down
6 changes: 5 additions & 1 deletion mythplugins/mythmusic/mythmusic/visualize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ bool AlbumArt::draw(QPainter *p, const QColor &back)
// If the directory has changed (new album) or the size, reload
if (needsUpdate())
{
QImage art(gPlayer->getCurrentMetadata()->getAlbumArt(m_currImageType));
QImage art;
QString imageFilename = gPlayer->getCurrentMetadata()->getAlbumArtFile(m_currImageType);
if (!imageFilename.isEmpty())
art.load(imageFilename);

if (art.isNull())
{
m_cursize = m_size;
Expand Down