|
a/HelperStructs/MetaData.h |
|
b/HelperStructs/MetaData.h |
|
... |
|
... |
13 |
* GNU General Public License for more details.
|
13 |
* GNU General Public License for more details.
|
14 |
|
14 |
|
15 |
* You should have received a copy of the GNU General Public License
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
17 |
*/
|
18 |
|
|
|
19 |
#ifndef METADATA_H_
|
18 |
#ifndef METADATA_H_
|
20 |
#define METADATA_H_
|
19 |
#define METADATA_H_
|
21 |
|
20 |
|
22 |
#include <vector>
|
21 |
#include <vector>
|
23 |
using namespace std;
|
|
|
24 |
|
22 |
|
25 |
#include <QString>
|
23 |
#include <QString>
|
26 |
#include <QStringList>
|
24 |
#include <QStringList>
|
27 |
#include <QDebug>
|
|
|
28 |
#include <QVariant>
|
25 |
#include <QVariant>
|
29 |
#include <QFile>
|
26 |
#include <QFile>
|
30 |
#include <QDataStream>
|
27 |
#include <QDataStream>
|
31 |
|
28 |
|
32 |
#include "HelperStructs/globals.h"
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
struct MetaData {
|
29 |
struct MetaData {
|
36 |
|
30 |
|
37 |
qint32 id;
|
31 |
qint32 id{-1};
|
38 |
qint32 album_id;
|
32 |
qint32 album_id{-1};
|
39 |
qint32 artist_id;
|
33 |
qint32 artist_id{-1};
|
40 |
QString title;
|
34 |
QString title;
|
41 |
QString artist;
|
35 |
QString artist;
|
42 |
QString album;
|
36 |
QString album;
|
43 |
QStringList genres;
|
37 |
QStringList genres;
|
44 |
qint32 rating;
|
38 |
qint32 rating{0};
|
45 |
qint64 length_ms;
|
39 |
qint64 length_ms{0};
|
46 |
qint32 year;
|
40 |
qint32 year{0};
|
47 |
QString filepath;
|
41 |
QString filepath;
|
48 |
qint32 track_num;
|
42 |
qint32 track_num{0};
|
49 |
qint32 bitrate;
|
43 |
qint32 bitrate{0};
|
50 |
qint64 filesize;
|
44 |
qint64 filesize{0};
|
51 |
QString comment;
|
45 |
QString comment;
|
52 |
int discnumber;
|
46 |
int discnumber{0};
|
53 |
int n_discs;
|
47 |
int n_discs{-1};
|
54 |
|
48 |
|
55 |
bool is_extern;
|
49 |
bool is_extern{false};
|
56 |
|
50 |
|
57 |
bool pl_selected;
|
51 |
bool pl_selected{false};
|
58 |
bool pl_playing;
|
52 |
bool pl_playing{false};
|
59 |
bool pl_dragged;
|
53 |
bool pl_dragged{false};
|
60 |
|
54 |
|
61 |
bool unused1;
|
55 |
bool unused1{false};
|
62 |
bool is_disabled;
|
56 |
bool is_disabled{false};
|
63 |
|
57 |
|
64 |
QString didl;
|
58 |
QString didl;
|
65 |
QString albumArtURI;
|
59 |
QString albumArtURI;
|
66 |
|
60 |
|
67 |
///// The following are not saved on disk as part of a saved playlist.///
|
61 |
///// The following are not saved on disk as part of a saved playlist.///
|
68 |
// While playing in avt + shuffle mode: remember what we already played
|
62 |
// While playing in avt + shuffle mode: remember what we already played
|
69 |
bool shuffle_played;
|
63 |
bool shuffle_played{false};
|
70 |
|
64 |
|
71 |
inline MetaData () {
|
|
|
72 |
id = -1;
|
|
|
73 |
artist_id = -1;
|
|
|
74 |
album_id = -1;
|
|
|
75 |
title = "";
|
|
|
76 |
artist = "";
|
|
|
77 |
album = "";
|
|
|
78 |
rating = 0;
|
|
|
79 |
length_ms = 0;
|
|
|
80 |
year = 0;
|
|
|
81 |
filepath = "";
|
|
|
82 |
track_num = 0;
|
|
|
83 |
bitrate = 0;
|
|
|
84 |
is_extern = false;
|
|
|
85 |
filesize = 0;
|
|
|
86 |
comment = "";
|
|
|
87 |
discnumber = 0;
|
|
|
88 |
n_discs = -1;
|
|
|
89 |
|
|
|
90 |
pl_selected = false;
|
|
|
91 |
pl_playing = false;
|
|
|
92 |
pl_dragged = false;
|
|
|
93 |
|
|
|
94 |
unused1 = false;
|
|
|
95 |
is_disabled = false;
|
|
|
96 |
|
|
|
97 |
didl = "";
|
|
|
98 |
|
|
|
99 |
shuffle_played = false;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
void print() const {
|
|
|
103 |
|
|
|
104 |
qDebug() << title
|
|
|
105 |
<< " by " << artist
|
|
|
106 |
<< " from " << album
|
|
|
107 |
<< " (" << length_ms << " m_sec) :: " << filepath;
|
|
|
108 |
}
|
|
|
109 |
|
65 |
|
110 |
QVariant toVariant() const {
|
66 |
QVariant toVariant() const {
|
111 |
|
|
|
112 |
QStringList list;
|
67 |
QStringList list;
|
113 |
|
68 |
|
114 |
QString tmpTitle = title;
|
69 |
QString tmpTitle = title;
|
115 |
QString tmpArtist = artist;
|
70 |
QString tmpArtist = artist;
|
116 |
QString tmpAlbum = album;
|
71 |
QString tmpAlbum = album;
|
117 |
|
|
|
118 |
if (title.trimmed().size() == 0) tmpTitle = QString("(Unknown title)");
|
72 |
if (title.trimmed().size() == 0) tmpTitle = QString("(Unknown title)");
|
119 |
if (artist.trimmed().size() == 0) tmpArtist = QString("");
|
73 |
if (artist.trimmed().size() == 0) tmpArtist = QString("");
|
120 |
if (album.trimmed().size() == 0) tmpAlbum = QString("");
|
74 |
if (album.trimmed().size() == 0) tmpAlbum = QString("");
|
121 |
|
75 |
|
122 |
list.push_back(tmpTitle);
|
76 |
list.push_back(tmpTitle);
|
|
... |
|
... |
146 |
list.push_back(albumArtURI);
|
100 |
list.push_back(albumArtURI);
|
147 |
|
101 |
|
148 |
return list;
|
102 |
return list;
|
149 |
}
|
103 |
}
|
150 |
|
104 |
|
151 |
static bool fromVariant(QVariant v, MetaData& md){
|
105 |
static bool fromVariant(QVariant v, MetaData& md) {
|
152 |
|
106 |
|
153 |
QStringList list = v.toStringList();
|
107 |
QStringList list = v.toStringList();
|
154 |
|
108 |
|
155 |
if(list.size() < 24) return false;
|
109 |
if(list.size() < 24) return false;
|
156 |
unsigned int idx = 0;
|
110 |
unsigned int idx = 0;
|
|
... |
|
... |
180 |
md.didl = list[idx++];
|
134 |
md.didl = list[idx++];
|
181 |
md.albumArtURI = list[idx++];
|
135 |
md.albumArtURI = list[idx++];
|
182 |
return true;
|
136 |
return true;
|
183 |
}
|
137 |
}
|
184 |
|
138 |
|
185 |
bool compare(const MetaData& other) {
|
139 |
bool compare(const MetaData& other) const {
|
186 |
bool same = title == other.title &&
|
140 |
bool same = title == other.title &&
|
187 |
artist == other.artist &&
|
141 |
artist == other.artist &&
|
188 |
album == other.album &&
|
142 |
album == other.album &&
|
189 |
rating == other.rating &&
|
143 |
rating == other.rating &&
|
190 |
length_ms == other.length_ms &&
|
144 |
length_ms == other.length_ms &&
|
|
... |
|
... |
202 |
genres == other.genres &&
|
156 |
genres == other.genres &&
|
203 |
is_extern == other.is_extern &&
|
157 |
is_extern == other.is_extern &&
|
204 |
pl_playing == other.pl_playing &&
|
158 |
pl_playing == other.pl_playing &&
|
205 |
pl_selected == other.pl_selected &&
|
159 |
pl_selected == other.pl_selected &&
|
206 |
pl_dragged == other.pl_dragged &&
|
160 |
pl_dragged == other.pl_dragged &&
|
207 |
unused1 == other.unused1 &&
|
|
|
208 |
is_disabled == other.is_disabled &&
|
161 |
is_disabled == other.is_disabled &&
|
209 |
didl == other.didl &&
|
162 |
didl == other.didl &&
|
210 |
albumArtURI == other.albumArtURI;
|
163 |
albumArtURI == other.albumArtURI;
|
211 |
return !same;
|
164 |
return !same;
|
212 |
}
|
165 |
}
|
213 |
|
166 |
|
214 |
bool serialize(QDataStream& strm) {
|
167 |
bool serialize(QDataStream& strm) const {
|
215 |
strm <<
|
168 |
strm <<
|
216 |
title <<
|
169 |
title <<
|
217 |
artist <<
|
170 |
artist <<
|
218 |
album <<
|
171 |
album <<
|
219 |
rating <<
|
172 |
rating <<
|
|
... |
|
... |
238 |
is_disabled <<
|
191 |
is_disabled <<
|
239 |
didl <<
|
192 |
didl <<
|
240 |
albumArtURI;
|
193 |
albumArtURI;
|
241 |
return true;
|
194 |
return true;
|
242 |
}
|
195 |
}
|
|
|
196 |
|
243 |
bool unSerialize(QDataStream& strm) {
|
197 |
bool unSerialize(QDataStream& strm) {
|
244 |
strm >>
|
198 |
strm >>
|
245 |
title >>
|
199 |
title >>
|
246 |
artist >>
|
200 |
artist >>
|
247 |
album >>
|
201 |
album >>
|
|
... |
|
... |
267 |
is_disabled >>
|
221 |
is_disabled >>
|
268 |
didl >>
|
222 |
didl >>
|
269 |
albumArtURI;
|
223 |
albumArtURI;
|
270 |
return strm.status() == QDataStream::Ok;
|
224 |
return strm.status() == QDataStream::Ok;
|
271 |
}
|
225 |
}
|
272 |
|
|
|
273 |
};
|
226 |
};
|
274 |
|
227 |
|
275 |
class MetaDataList : public vector<MetaData> {
|
228 |
class MetaDataList : public std::vector<MetaData> {
|
276 |
|
|
|
277 |
public:
|
229 |
public:
|
278 |
|
|
|
279 |
MetaDataList(){}
|
|
|
280 |
~MetaDataList() {
|
|
|
281 |
clear();
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
void setCurPlayTrack(int idx) {
|
230 |
void setCurPlayTrack(int idx) {
|
285 |
for (uint i = 0; i < size(); i++) {
|
231 |
for (unsigned int i = 0; i < size(); i++) {
|
286 |
if ((int) i == idx)
|
|
|
287 |
at(i).pl_playing = true;
|
|
|
288 |
else
|
|
|
289 |
at(i).pl_playing = false;
|
232 |
at(i).pl_playing = false;
|
290 |
}
|
233 |
}
|
|
|
234 |
if (idx >= 0 && idx < int(size()))
|
|
|
235 |
at(idx).pl_playing = true;
|
291 |
}
|
236 |
}
|
292 |
|
237 |
|
293 |
bool contains(const MetaData& md, bool cs=false, MetaData **found = 0) {
|
238 |
bool contains(const MetaData& md, bool cs=false, MetaData **found = 0) {
|
294 |
if(cs) {
|
|
|
295 |
QString filepath = md.filepath.trimmed();
|
239 |
QString filepath = cs ? md.filepath.trimmed() :
|
296 |
|
240 |
md.filepath.toLower().trimmed();
|
297 |
for(uint i = 0; i < size(); i++){
|
241 |
for(unsigned int i = 0; i < size(); i++) {
|
298 |
QString filepath2 = at(i).filepath.trimmed();
|
242 |
QString filepath2 = cs ? at(i).filepath.trimmed() :
|
|
|
243 |
at(i).filepath.toLower().trimmed();
|
299 |
if(!filepath.compare(filepath2)) {
|
244 |
if(!filepath.compare(filepath2)) {
|
300 |
if (found)
|
245 |
if (found)
|
301 |
*found = &(at(i));
|
246 |
*found = &(at(i));
|
302 |
return true;
|
247 |
return true;
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
} else {
|
|
|
306 |
QString filepath = md.filepath.toLower().trimmed();
|
|
|
307 |
|
|
|
308 |
for (uint i = 0; i < size(); i++){
|
|
|
309 |
QString filepath2 = at(i).filepath.toLower().trimmed();
|
|
|
310 |
if(!filepath.compare(filepath2)) {
|
|
|
311 |
if (found)
|
|
|
312 |
*found = &(at(i));
|
|
|
313 |
return true;
|
|
|
314 |
}
|
|
|
315 |
}
|
248 |
}
|
316 |
}
|
249 |
}
|
317 |
return false;
|
250 |
return false;
|
318 |
}
|
251 |
}
|
319 |
|
252 |
|