-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecoderoptimfrogfactory.cpp
118 lines (104 loc) · 3.46 KB
/
decoderoptimfrogfactory.cpp
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
#include "decoderoptimfrogfactory.h"
#include "decoder_optimfrog.h"
#include "optimfroghelper.h"
#include "optimfrogmetadatamodel.h"
#include <QMessageBox>
bool DecoderOptimFROGFactory::canDecode(QIODevice *input) const
{
OptimFROGHelper helper(input);
return helper.initialize();
}
DecoderProperties DecoderOptimFROGFactory::properties() const
{
DecoderProperties properties;
properties.name = tr("OptimFROG Plugin");
properties.shortName = "optimfrog";
properties.filters << "*.ofr" << "*.ofs";
properties.description = "OptimFROG Lossless Audio File";
properties.hasAbout = true;
return properties;
}
Decoder *DecoderOptimFROGFactory::create(const QString &path, QIODevice *input)
{
Q_UNUSED(path);
return new DecoderOptimFROG(input);
}
QList<TrackInfo*> DecoderOptimFROGFactory::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *)
{
TrackInfo *info = new TrackInfo(path);
if(parts == TrackInfo::Parts())
{
return QList<TrackInfo*>() << info;
}
QFile file(path);
if(!file.open(QIODevice::ReadOnly))
{
delete info;
return QList<TrackInfo*>();
}
OptimFROGHelper helper(&file);
if(!helper.initialize())
{
file.close();
delete info;
return QList<TrackInfo*>();
}
if(parts & TrackInfo::Properties)
{
info->setValue(Qmmp::BITRATE, helper.bitrate());
info->setValue(Qmmp::SAMPLERATE, helper.sampleRate());
info->setValue(Qmmp::CHANNELS, helper.channels());
info->setValue(Qmmp::BITS_PER_SAMPLE, helper.depth());
info->setValue(Qmmp::FORMAT_NAME, "OptimFROG");
info->setDuration(helper.totalTime());
}
if((parts & TrackInfo::MetaData) && helper.hasTags())
{
QString value;
value = helper.tag("title");
info->setValue(Qmmp::TITLE, value.replace('\n', "<br>"));
value = helper.tag("artist");
info->setValue(Qmmp::ARTIST, value.replace('\n', "<br>"));
value = helper.tag("album");
info->setValue(Qmmp::ALBUM, value.replace('\n', "<br>"));
value = helper.tag("comment");
info->setValue(Qmmp::COMMENT, value.replace('\n', "<br>"));
value = helper.tag("genre");
info->setValue(Qmmp::GENRE, value.replace('\n', "<br>"));
value = helper.tag("composer");
info->setValue(Qmmp::COMPOSER, value.replace('\n', "<br>"));
value = helper.tag("year");
info->setValue(Qmmp::YEAR, value.replace('\n', "<br>"));
value = helper.tag("track");
info->setValue(Qmmp::TRACK, value.replace('\n', "<br>"));
}
file.close();
return QList<TrackInfo*>() << info;
}
MetaDataModel *DecoderOptimFROGFactory::createMetaDataModel(const QString &path, bool readOnly)
{
Q_UNUSED(readOnly);
return new OptimFROGMetaDataModel(path);
}
#if (QMMP_VERSION_INT < 0x10700) || (0x20000 <= QMMP_VERSION_INT && QMMP_VERSION_INT < 0x20200)
void DecoderOptimFROGFactory::showSettings(QWidget *parent)
{
Q_UNUSED(parent);
}
#else
QDialog *DecoderOptimFROGFactory::createSettings(QWidget *parent)
{
Q_UNUSED(parent);
return nullptr;
}
#endif
void DecoderOptimFROGFactory::showAbout(QWidget *parent)
{
QMessageBox::about(parent, tr("About OptimFROGF Reader Plugin"),
tr("Qmmp OptimFROGF Reader Plugin") + "\n" +
tr("Written by: Greedysky <[email protected]>"));
}
QString DecoderOptimFROGFactory::translation() const
{
return QString();
}