1 /*
2  *  Copyright (C) 2005-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 /*!
12  \file Song.h
13 \brief
14 */
15 
16 #include "Artist.h"
17 #include "XBDateTime.h"
18 #include "music/tags/ReplayGain.h"
19 #include "utils/EmbeddedArt.h"
20 #include "utils/ISerializable.h"
21 
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 class CVariant;
27 
28 /*!
29  \ingroup music
30  \brief Class to store and read album information from CMusicDatabase
31  \sa CSong, CMusicDatabase
32  */
33 
34 class CGenre
35 {
36 public:
37   int idGenre;
38   std::string strGenre;
39 };
40 
41 class CFileItem;
42 
43 /*!
44  \ingroup music
45  \brief Class to store and read song information from CMusicDatabase
46  \sa CAlbum, CMusicDatabase
47  */
48 class CSong final : public ISerializable
49 {
50 public:
51   CSong() ;
52   explicit CSong(CFileItem& item);
53   void Clear() ;
54   void MergeScrapedSong(const CSong& source, bool override);
55   void Serialize(CVariant& value) const override;
56 
57   bool operator<(const CSong &song) const
58   {
59     if (strFileName < song.strFileName) return true;
60     if (strFileName > song.strFileName) return false;
61     if (iTrack < song.iTrack) return true;
62     return false;
63   }
64 
65   /*! \brief Get artist names from the vector of artistcredits objects
66   \return artist names as a vector of strings
67   */
68   const std::vector<std::string> GetArtist() const;
69 
70   /*! \brief Get artist sort name string
71   \return artist sort name as a single string
72   */
73   const std::string GetArtistSort() const;
74 
75   /*! \brief Get artist MusicBrainz IDs from the vector of artistcredits objects
76   \return artist MusicBrainz IDs as a vector of strings
77   */
78   const std::vector<std::string> GetMusicBrainzArtistID() const;
79 
80   /*! \brief Get artist names from the artist description string (if it exists)
81   or concatenated from the vector of artistcredits objects
82   \return artist names as a single string
83   */
84   const std::string GetArtistString() const;
85 
86   /*! \brief Get song artist IDs (for json rpc) from the vector of artistcredits objects
87   \return album artist IDs as a vector of integers
88   */
89   const std::vector<int> GetArtistIDArray() const;
90 
91   /*! \brief Get album artist names associated with song from tag data
92    Note for initial album processing only, normalised album artist data belongs to album
93    and is stored in album artist credits
94   \return album artist names as a vector of strings
95   */
GetAlbumArtist()96   const std::vector<std::string> GetAlbumArtist() const { return m_albumArtist; }
97 
98   /*! \brief Get album artist sort name string
99   \return album artist sort name as a single string
100   */
GetAlbumArtistSort()101   const std::string GetAlbumArtistSort() const { return m_strAlbumArtistSort; }
102 
103   /*! \brief Get disc subtitle string where one exists
104   \return disc subtitle as a single string
105   */
106   const std::string GetDiscSubtitle() const;
107 
108   /*! \brief Get composer sort name string
109   \return composer sort name as a single string
110   */
GetComposerSort()111   const std::string GetComposerSort() const { return m_strComposerSort; }
112 
113   /*! \brief Get the full list of artist names and the role each played for those
114     that contributed to the recording. Given in music file tags other than ARTIST
115     or ALBUMARTIST, e.g. COMPOSER or CONDUCTOR etc.
116   \return a vector of all contributing artist names and their roles
117   */
GetContributors()118   const VECMUSICROLES& GetContributors() const { return m_musicRoles; };
119   //void AddArtistRole(const int &role, const std::string &artist);
120   void AppendArtistRole(const CMusicRole& musicRole);
121 
122   /*! \brief Set album artist vector.
123    Album artist is held local to song until album created for inital processing only.
124    Normalised album artist data belongs to album and is stored in album artist credits
125   \param album artist names as a vector of strings
126   */
SetAlbumArtist(const std::vector<std::string> & albumartists)127   void SetAlbumArtist(const std::vector<std::string>& albumartists) { m_albumArtist = albumartists; }
128 
129   /*! \brief Whether this song has any artists in artist credits vector
130     Tests if artist credits has been populated yet, during processing there can be
131     artists in the artist description but not yet in the credits
132   */
HasArtistCredits()133   bool HasArtistCredits() const { return !artistCredits.empty(); }
134 
135   /*! \brief Whether this song has any artists in music roles (contributors) vector
136   Tests if contributors has been populated yet, there may be none.
137   */
HasContributors()138   bool HasContributors() const { return !m_musicRoles.empty(); }
139 
140   /*! \brief whether this song has art associated with it
141    Tests both the strThumb and embeddedArt members.
142    */
143   bool HasArt() const;
144 
145   /*! \brief whether the art from this song matches the art from another
146    Tests both the strThumb and embeddedArt members.
147    */
148   bool ArtMatches(const CSong &right) const;
149 
150   /*! \brief Set artist credits using the arrays of tag values.
151     If strArtistSort (as from ARTISTSORT tag) is already set then individual
152     artist sort names are also processed.
153     \param names       String vector of artist names (as from ARTIST tag)
154     \param hints       String vector of artist name hints (as from ARTISTS tag)
155     \param mbids       String vector of artist Musicbrainz IDs (as from MUSICBRAINZARTISTID tag)
156   */
157   void SetArtistCredits(const std::vector<std::string>& names, const std::vector<std::string>& hints,
158     const std::vector<std::string>& mbids);
159 
160   int idSong;
161   int idAlbum;
162   std::string strFileName;
163   std::string strTitle;
164   std::string strArtistSort;
165   std::string strArtistDesc;
166   VECARTISTCREDITS artistCredits;
167   std::string strAlbum;
168   std::vector<std::string> genre;
169   std::string strThumb;
170   EmbeddedArtInfo embeddedArt;
171   std::string strMusicBrainzTrackID;
172   std::string strComment;
173   std::string strMood;
174   std::string strCueSheet;
175   float rating;
176   int userrating;
177   int votes;
178   int iTrack;
179   int iDuration;
180   std::string strOrigReleaseDate;
181   std::string strReleaseDate;
182   std::string strDiscSubtitle;
183   int iTimesPlayed;
184   CDateTime lastPlayed;
185   CDateTime dateAdded; // File creation or modification time, or when tags (re-)scanned
186   CDateTime dateUpdated; // Time db record Last modified
187   CDateTime dateNew;  // Time db record created
188   int iStartOffset;
189   int iEndOffset;
190   bool bCompilation;
191   int iBPM;
192   int iSampleRate;
193   int iBitRate;
194   int iChannels;
195   std::string strRecordLabel; // Record label from tag for album processing by CMusicInfoScanner::FileItemsToAlbums
196   std::string strAlbumType; // (Musicbrainz release type) album type from tag for album processing by CMusicInfoScanner::FileItemsToAlbums
197 
198   ReplayGain replayGain;
199 private:
200   std::vector<std::string> m_albumArtist; // Album artist from tag for album processing, no desc or MBID
201   std::string m_strAlbumArtistSort; // Albumartist sort string from tag for album processing by CMusicInfoScanner::FileItemsToAlbums
202   std::string m_strComposerSort;
203   VECMUSICROLES m_musicRoles;
204 };
205 
206 /*!
207  \ingroup music
208  \brief A vector of CSong objects, used for CMusicDatabase
209  \sa CMusicDatabase
210  */
211 typedef std::vector<CSong> VECSONGS;
212 
213 /*!
214  \ingroup music
215  \brief A map of a vector of CSong objects key by filename, used for CMusicDatabase
216  */
217 typedef std::map<std::string, VECSONGS> MAPSONGS;
218 
219 /*!
220  \ingroup music
221  \brief A vector of std::string objects, used for CMusicDatabase
222  \sa CMusicDatabase
223  */
224 typedef std::vector<CGenre> VECGENRES;
225