Merge pull request #2988 from Montellese/xsp_extensions
[vuplus_xbmc] / xbmc / music / tags / MusicInfoTag.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 class CSong;
23 class CAlbum;
24 class CArtist;
25
26 #include <vector>
27 #include <string>
28 #include <stdint.h>
29
30 #include "utils/Archive.h"
31 #include "utils/ISerializable.h"
32 #include "utils/ISortable.h"
33 #include "XBDateTime.h"
34
35 #define REPLAY_GAIN_HAS_TRACK_INFO 1
36 #define REPLAY_GAIN_HAS_ALBUM_INFO 2
37 #define REPLAY_GAIN_HAS_TRACK_PEAK 4
38 #define REPLAY_GAIN_HAS_ALBUM_PEAK 8
39
40 enum ReplayGain
41 {
42   REPLAY_GAIN_NONE  = 0,
43   REPLAY_GAIN_ALBUM,
44   REPLAY_GAIN_TRACK
45 };
46
47 namespace MUSIC_INFO
48 {
49   class EmbeddedArtInfo
50   {
51   public:
52     EmbeddedArtInfo() {};
53     EmbeddedArtInfo(size_t size, const std::string &mime);
54     void set(size_t size, const std::string &mime);
55     void clear();
56     bool empty() const;
57     bool matches(const EmbeddedArtInfo &right) const;
58     size_t      size;
59     std::string mime;
60   };
61
62   class EmbeddedArt : public EmbeddedArtInfo
63   {
64   public:
65     EmbeddedArt() {};
66     EmbeddedArt(const uint8_t *data, size_t size, const std::string &mime);
67     void set(const uint8_t *data, size_t size, const std::string &mime);
68     std::vector<uint8_t> data;
69   };
70
71 class CMusicInfoTag : public IArchivable, public ISerializable, public ISortable
72 {
73 public:
74   CMusicInfoTag(void);
75   CMusicInfoTag(const CMusicInfoTag& tag);
76   virtual ~CMusicInfoTag();
77   const CMusicInfoTag& operator =(const CMusicInfoTag& tag);
78   bool operator !=(const CMusicInfoTag& tag) const;
79   bool Loaded() const;
80   const CStdString& GetTitle() const;
81   const CStdString& GetURL() const;
82   const std::vector<std::string>& GetArtist() const;
83   const CStdString& GetAlbum() const;
84   int GetAlbumId() const;
85   const std::vector<std::string>& GetAlbumArtist() const;
86   const std::vector<std::string>& GetGenre() const;
87   int GetTrackNumber() const;
88   int GetDiscNumber() const;
89   int GetTrackAndDiskNumber() const;
90   int GetDuration() const;  // may be set even if Loaded() returns false
91   int GetYear() const;
92   int GetDatabaseId() const;
93   const std::string &GetType() const;
94
95   void GetReleaseDate(SYSTEMTIME& dateTime) const;
96   CStdString GetYearString() const;
97   const CStdString& GetMusicBrainzTrackID() const;
98   const std::vector<std::string>& GetMusicBrainzArtistID() const;
99   const CStdString& GetMusicBrainzAlbumID() const;
100   const std::vector<std::string>& GetMusicBrainzAlbumArtistID() const;
101   const CStdString& GetMusicBrainzTRMID() const;
102   const CStdString& GetComment() const;
103   const CStdString& GetLyrics() const;
104   const CDateTime& GetLastPlayed() const;
105   bool  GetCompilation() const;
106   char  GetRating() const;
107   int  GetListeners() const;
108   int  GetPlayCount() const;
109   const EmbeddedArtInfo &GetCoverArtInfo() const;
110   int   GetReplayGainTrackGain() const;
111   int   GetReplayGainAlbumGain() const;
112   float GetReplayGainTrackPeak() const;
113   float GetReplayGainAlbumPeak() const;
114   int   HasReplayGainInfo() const;
115
116   void SetURL(const CStdString& strURL);
117   void SetTitle(const CStdString& strTitle);
118   void SetArtist(const CStdString& strArtist);
119   void SetArtist(const std::vector<std::string>& artists);
120   void SetAlbum(const CStdString& strAlbum);
121   void SetAlbumId(const int iAlbumId);
122   void SetAlbumArtist(const CStdString& strAlbumArtist);
123   void SetAlbumArtist(const std::vector<std::string>& albumArtists);
124   void SetGenre(const CStdString& strGenre);
125   void SetGenre(const std::vector<std::string>& genres);
126   void SetYear(int year);
127   void SetDatabaseId(long id, const std::string &type);
128   void SetReleaseDate(SYSTEMTIME& dateTime);
129   void SetTrackNumber(int iTrack);
130   void SetPartOfSet(int m_iPartOfSet);
131   void SetTrackAndDiskNumber(int iTrackAndDisc);
132   void SetDuration(int iSec);
133   void SetLoaded(bool bOnOff = true);
134   void SetArtist(const CArtist& artist);
135   void SetAlbum(const CAlbum& album);
136   void SetSong(const CSong& song);
137   void SetMusicBrainzTrackID(const CStdString& strTrackID);
138   void SetMusicBrainzArtistID(const std::vector<std::string>& musicBrainzArtistId);
139   void SetMusicBrainzAlbumID(const CStdString& strAlbumID);
140   void SetMusicBrainzAlbumArtistID(const std::vector<std::string>& musicBrainzAlbumArtistId);
141   void SetMusicBrainzTRMID(const CStdString& strTRMID);
142   void SetComment(const CStdString& comment);
143   void SetLyrics(const CStdString& lyrics);
144   void SetRating(char rating);
145   void SetListeners(int listeners);
146   void SetPlayCount(int playcount);
147   void SetLastPlayed(const CStdString& strLastPlayed);
148   void SetLastPlayed(const CDateTime& strLastPlayed);
149   void SetCompilation(bool compilation);
150   void SetCoverArtInfo(size_t size, const std::string &mimeType);
151   void SetReplayGainTrackGain(int trackGain);
152   void SetReplayGainAlbumGain(int albumGain);
153   void SetReplayGainTrackPeak(float trackPeak);
154   void SetReplayGainAlbumPeak(float albumPeak);
155
156   /*! \brief Append a unique artist to the artist list
157    Checks if we have this artist already added, and if not adds it to the songs artist list.
158    \param value artist to add.
159    */
160   void AppendArtist(const CStdString &artist);
161
162   /*! \brief Append a unique album artist to the artist list
163    Checks if we have this album artist already added, and if not adds it to the songs album artist list.
164    \param albumArtist album artist to add.
165    */
166   void AppendAlbumArtist(const CStdString &albumArtist);
167
168   /*! \brief Append a unique genre to the genre list
169    Checks if we have this genre already added, and if not adds it to the songs genre list.
170    \param genre genre to add.
171    */
172   void AppendGenre(const CStdString &genre);
173
174   virtual void Archive(CArchive& ar);
175   virtual void Serialize(CVariant& ar) const;
176   virtual void ToSortable(SortItem& sortable);
177
178   void Clear();
179 protected:
180   /*! \brief Trim whitespace off the given string
181    \param value string to trim
182    \return trimmed value, with spaces removed from left and right, as well as carriage returns from the right.
183    */
184   CStdString Trim(const CStdString &value) const;
185
186   CStdString m_strURL;
187   CStdString m_strTitle;
188   std::vector<std::string> m_artist;
189   CStdString m_strAlbum;
190   std::vector<std::string> m_albumArtist;
191   std::vector<std::string> m_genre;
192   CStdString m_strMusicBrainzTrackID;
193   std::vector<std::string> m_musicBrainzArtistID;
194   CStdString m_strMusicBrainzAlbumID;
195   std::vector<std::string> m_musicBrainzAlbumArtistID;
196   CStdString m_strMusicBrainzTRMID;
197   CStdString m_strComment;
198   CStdString m_strLyrics;
199   CDateTime m_lastPlayed;
200   bool m_bCompilation;
201   int m_iDuration;
202   int m_iTrack;     // consists of the disk number in the high 16 bits, the track number in the low 16bits
203   int m_iDbId;
204   std::string m_type; ///< item type "song", "album", "artist"
205   bool m_bLoaded;
206   char m_rating;
207   int m_listeners;
208   int m_iTimesPlayed;
209   int m_iAlbumId;
210   SYSTEMTIME m_dwReleaseDate;
211
212   // ReplayGain
213   int m_iTrackGain; // measured in milliBels
214   int m_iAlbumGain;
215   float m_fTrackPeak; // 1.0 == full digital scale
216   float m_fAlbumPeak;
217   int m_iHasGainInfo;   // valid info
218   EmbeddedArtInfo m_coverArt; ///< art information
219 };
220 }