Permalink
Browse files

[musicdb] add m_type to CMusicInfoTag

  • Loading branch information...
1 parent eb019ca commit de75cc274d54fb2fda258ab5a28ef23038c7fd83 Jonathan Marshall committed May 5, 2012
@@ -871,7 +871,7 @@ void CMusicDatabase::GetFileItemFromDataset(const dbiplus::sql_record* const rec
item->GetMusicInfoTag()->SetAlbumId(record->at(song_idAlbum).get_asInt());
item->GetMusicInfoTag()->SetTrackAndDiskNumber(record->at(song_iTrack).get_asInt());
item->GetMusicInfoTag()->SetDuration(record->at(song_iDuration).get_asInt());
- item->GetMusicInfoTag()->SetDatabaseId(record->at(song_idSong).get_asInt());
+ item->GetMusicInfoTag()->SetDatabaseId(record->at(song_idSong).get_asInt(), "song");
SYSTEMTIME stTime;
stTime.wYear = (WORD)record->at(song_iYear).get_asInt();
item->GetMusicInfoTag()->SetReleaseDate(stTime);
@@ -1138,6 +1138,7 @@ bool CMusicDatabase::SearchArtists(const CStdString& search, CFileItemList &arti
pItem->SetLabel(label);
label.Format("A %s", m_pDS->fv(1).get_asString()); // sort label is stored in the title tag
pItem->GetMusicInfoTag()->SetTitle(label);
+ pItem->GetMusicInfoTag()->SetDatabaseId(m_pDS->fv(0).get_asInt(), "artist");
pItem->SetCachedArtistThumb();
artists.Add(pItem);
m_pDS->next();
@@ -2683,7 +2684,7 @@ bool CMusicDatabase::GetGenresNav(const CStdString& strBaseDir, CFileItemList& i
{
CFileItemPtr pItem(new CFileItem(m_pDS->fv("strGenre").get_asString()));
pItem->GetMusicInfoTag()->SetGenre(m_pDS->fv("strGenre").get_asString());
- pItem->GetMusicInfoTag()->SetDatabaseId(m_pDS->fv("idGenre").get_asInt());
+ pItem->GetMusicInfoTag()->SetDatabaseId(m_pDS->fv("idGenre").get_asInt(), "genre");
CStdString strDir;
strDir.Format("%ld/", m_pDS->fv("idGenre").get_asInt());
pItem->SetPath(strBaseDir + strDir);
@@ -2860,7 +2861,7 @@ bool CMusicDatabase::GetArtistsByWhere(const CStdString& strBaseDir, const CStdS
CStdString strDir;
strDir.Format("%ld/", artist.idArtist);
pItem->SetPath(strBaseDir + strDir);
- pItem->GetMusicInfoTag()->SetDatabaseId(artist.idArtist);
+ pItem->GetMusicInfoTag()->SetDatabaseId(artist.idArtist, "artist");
if (CFile::Exists(pItem->GetCachedArtistThumb()))
pItem->SetThumbnailImage(pItem->GetCachedArtistThumb());
pItem->SetIconImage("DefaultArtist.png");
@@ -160,7 +160,7 @@ void CGUIDialogMusicInfo::SetAlbum(const CAlbum& album, const CStdString &path)
m_albumItem->GetMusicInfoTag()->SetLoaded(true);
m_albumItem->GetMusicInfoTag()->SetRating('0' + m_album.iRating);
m_albumItem->GetMusicInfoTag()->SetGenre(m_album.genre);
- m_albumItem->GetMusicInfoTag()->SetDatabaseId(m_album.idAlbum);
+ m_albumItem->GetMusicInfoTag()->SetDatabaseId(m_album.idAlbum, "album");
CMusicDatabase::SetPropertiesFromAlbum(*m_albumItem,m_album);
m_albumItem->SetMusicThumb();
// set the artist thumb
@@ -186,7 +186,7 @@ void CGUIDialogMusicInfo::SetArtist(const CArtist& artist, const CStdString &pat
m_albumItem->GetMusicInfoTag()->SetArtist(m_artist.strArtist);
m_albumItem->GetMusicInfoTag()->SetLoaded(true);
m_albumItem->GetMusicInfoTag()->SetGenre(m_artist.genre);
- m_albumItem->GetMusicInfoTag()->SetDatabaseId(m_artist.idArtist);
+ m_albumItem->GetMusicInfoTag()->SetDatabaseId(m_artist.idArtist, "artist");
CMusicDatabase::SetPropertiesFromArtist(*m_albumItem,m_artist);
CStdString strFanart = m_albumItem->GetCachedFanart();
if (CFile::Exists(strFanart))
@@ -66,6 +66,7 @@ const CMusicInfoTag& CMusicInfoTag::operator =(const CMusicInfoTag& tag)
m_listeners = tag.m_listeners;
m_iTimesPlayed = tag.m_iTimesPlayed;
m_iDbId = tag.m_iDbId;
+ m_type = tag.m_type;
m_iArtistId = tag.m_iArtistId;
m_iAlbumId = tag.m_iAlbumId;
memcpy(&m_dwReleaseDate, &tag.m_dwReleaseDate, sizeof(m_dwReleaseDate) );
@@ -156,6 +157,11 @@ long CMusicInfoTag::GetDatabaseId() const
return m_iDbId;
}
+const std::string &CMusicInfoTag::GetType() const
+{
+ return m_type;
+}
+
CStdString CMusicInfoTag::GetYearString() const
{
CStdString strReturn;
@@ -259,9 +265,10 @@ void CMusicInfoTag::SetYear(int year)
m_dwReleaseDate.wYear = year;
}
-void CMusicInfoTag::SetDatabaseId(long id)
+void CMusicInfoTag::SetDatabaseId(long id, const std::string &type)
{
m_iDbId = id;
+ m_type = type;
}
void CMusicInfoTag::SetReleaseDate(SYSTEMTIME& dateTime)
@@ -402,6 +409,7 @@ void CMusicInfoTag::SetAlbum(const CAlbum& album)
stTime.wYear = album.iYear;
SetReleaseDate(stTime);
m_iDbId = album.idAlbum;
+ m_type = "album";
m_bLoaded = true;
}
@@ -428,6 +436,7 @@ void CMusicInfoTag::SetSong(const CSong& song)
m_iTrack = song.iTrack;
m_iDuration = song.iDuration;
m_iDbId = song.idSong;
+ m_type = "song";
m_bLoaded = true;
m_iTimesPlayed = song.iTimesPlayed;
m_iArtistId = song.iArtistId;
@@ -555,6 +564,7 @@ void CMusicInfoTag::Clear()
m_strComment.Empty();
m_rating = '0';
m_iDbId = -1;
+ m_type.clear();
m_iTimesPlayed = 0;
memset(&m_dwReleaseDate, 0, sizeof(m_dwReleaseDate) );
m_iArtistId = -1;
@@ -53,6 +53,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
int GetDuration() const; // may be set even if Loaded() returns false
int GetYear() const;
long GetDatabaseId() const;
+ const std::string &GetType() const;
void GetReleaseDate(SYSTEMTIME& dateTime) const;
CStdString GetYearString() const;
@@ -81,7 +82,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
void SetGenre(const CStdString& strGenre);
void SetGenre(const std::vector<std::string>& genres);
void SetYear(int year);
- void SetDatabaseId(long id);
+ void SetDatabaseId(long id, const std::string &type);
void SetReleaseDate(SYSTEMTIME& dateTime);
void SetTrackNumber(int iTrack);
void SetPartOfSet(int m_iPartOfSet);
@@ -152,6 +153,7 @@ class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
int m_iDuration;
int m_iTrack; // consists of the disk number in the high 16 bits, the track number in the low 16bits
long m_iDbId;
+ std::string m_type; ///< item type "song", "album", "artist"
bool m_bLoaded;
char m_rating;
int m_listeners;

2 comments on commit de75cc2

@night199uk

yes :-)

Whats your thought on using an enum type instead of a string? makes select{ case : } simpler in core (GUIWindowMusicBase needs this). Can be translated in e.g. JSON-RPC where we want a string?

@jmarshallnz
Owner

Doesn't particularly worry me either way. JSON-RPC already sets a string based on other criteria, so that doesn't really matter as either way it would need support). The db doesn't require one (it could use an int instead, which would be slightly more efficient to hash perhaps?)

There's a slight advantage in that the type is often also related to the table name, which means slightly less code (eg see GetArtistArtByItem) though that could be done using a LUT instead easily enough.

@Montellese: your thoughts?

Please sign in to comment.