-
Notifications
You must be signed in to change notification settings - Fork 1
/
song.h
150 lines (121 loc) · 3.29 KB
/
song.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#ifndef SONG_H
#define SONG_H
#include <QtWinExtras/QtWin>
#include <QString>
#include <QPixmap>
#include <QImage>
#include <QFile>
#include <QDir>
#include <QImageReader>
#include <QMimeDatabase>
#include <QMimeData>
#include <QDebug>
#include <QByteArray>
#include <QByteArrayData>
#include <iostream>
#include <fstream>
#include <vector>
#include <windows.h>
#include <gdiplus.h>
#include <gdiplus/gdiplusheaders.h>
#include <string>
#include <utility>
#include <map>
#include <id3v2tag.h>
#include <flacpicture.h>
#include <flacfile.h>
#include <mpegfile.h>
#include <mp4coverart.h>
#include <mp4file.h>
#include <flacmetadatablock.h>
#include <mpegfile.h>
#include <id3v2frame.h>
#include <id3v2header.h>
#include <attachedpictureframe.h>
// Bass header files
#include "bass.h"
#include "bassopus.h"
#include "bass_ape.h"
#include "bass_fx.h"
#include "bassflac.h"
#include "basswebm.h"
#include "bass_spx.h"
#include "bass_tta.h"
using namespace std;
using namespace TagLib;
class Song
{
private:
QString name = "";
QString suffix = "";
float sampleRate;
float bitrate;
float dur = -1;
public:
vector <pair<float, QString>> lyrics;
QString lrcFile = "";
QString path = "";
map <int, QString> marks;
Song();
Song(QString p) : path(p) {
suffix = path.mid(path.lastIndexOf('.') + 1);
suffix = suffix.toUpper();
if (suffix == "") suffix = "Unknown";
};
Song(const Song& o) = default;
Song(Song&& o) = default;
Song& operator=(const Song&) = default;
void setLrcFile (QString path) {
if (path == "") return;
lrcFile = path;
parseLyrics();
}
void parseLyrics();
void countDuration() {
HSTREAM stream;
createStream(stream, path, 0);
QWORD len = BASS_ChannelGetLength(stream, 0); // the length in bytes
this->dur = BASS_ChannelBytes2Seconds(stream, len);
BASS_StreamFree(stream);
}
void setName (QString n) {
this->name = n;
}
void setNameFromPath () {
int left = path.lastIndexOf('/');
name = path.mid(left + 1);
int right = name.lastIndexOf('.');
name = name.mid(0, right);
}
QString getFileSizeMB () {
QFile file (path);
double size = file.size();
size /= 1024; // Kbytes
size /= 1024; // MBytes
size = int(size * 100) / 100.0f;
QString sizeStr = QString::number(size) + " MB";
return sizeStr;
}
QString getName () {
return name;
}
bool operator==(const Song right) {
if (this->path == right.path) return true;
return false;
}
float qstring2seconds (QString timecode) {
if (timecode.contains(':') && timecode.count('.') == 1) {
return qstring2seconds(timecode.mid(0, timecode.indexOf('.'))) + timecode.mid(timecode.indexOf('.') + 1).toFloat() / 100.0f;
}
else if (timecode.contains(':')) {
float minutes = timecode.mid(0, timecode.indexOf(':')).toFloat();
float seconds = timecode.mid(timecode.indexOf(':') + 1).toFloat();
return minutes * 60 + seconds;
}
}
void createStream(HSTREAM & chan, QString file, DWORD flags);
double getDuration();
QString getFormat();
QImage getCover();
};
#endif // SONG_H