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
151
152
153
154
155
156
157
158
159
160
161
|
/***************************************************************************
* Copyright (C) 2009-2018 by Ilya Kotov *
* forkotov02@ya.ru *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <QFile>
#include <stdint.h>
#include <libmodplug/stdafx.h>
#include <libmodplug/it_defs.h>
#include <libmodplug/sndfile.h>
#include <libmodplug/modplug.h>
#include "archivereader.h"
#include "modplugmetadatamodel.h"
#define MAX_MESSAGE_LENGTH 4000
ModPlugMetaDataModel::ModPlugMetaDataModel(const QString &path) : MetaDataModel(true)
{
m_soundFile = nullptr;
m_path = path;
ArchiveReader reader(nullptr);
if(reader.isSupported(m_path))
{
m_buffer = reader.unpack(m_path);
}
else
{
QFile file(m_path);
if(!file.open(QIODevice::ReadOnly))
{
qWarning("DetailsDialog: error: %s", qPrintable(file.errorString ()));
return;
}
m_buffer = file.readAll();
file.close();
}
m_soundFile = new CSoundFile();
m_soundFile->Create((uchar*) m_buffer.data(), m_buffer.size());
}
ModPlugMetaDataModel::~ModPlugMetaDataModel()
{
if(m_soundFile)
{
m_soundFile->Destroy();
delete m_soundFile;
}
}
QList<MetaDataItem> ModPlugMetaDataModel::extraProperties() const
{
QList<MetaDataItem> ep;
if(!m_soundFile)
return ep;
ep << MetaDataItem(tr("Speed"), m_soundFile->GetMusicSpeed());
ep << MetaDataItem(tr("Tempo"), m_soundFile->GetMusicTempo());
ep << MetaDataItem(tr("Samples"), m_soundFile->GetNumSamples());
ep << MetaDataItem(tr("Instruments"), m_soundFile->GetNumInstruments());
ep << MetaDataItem(tr("Patterns"), m_soundFile->GetNumPatterns());
ep << MetaDataItem(tr("Channels"), m_soundFile->GetNumChannels());
return ep;
}
QList<MetaDataItem> ModPlugMetaDataModel::descriptions() const
{
QList<MetaDataItem> desc;
if(!m_soundFile)
return desc;
char lBuffer[33];
QString text;
for(uint i = 0; i < m_soundFile->GetNumSamples(); i++)
{
m_soundFile->GetSampleName(i, lBuffer);
text += QString::fromUtf8(lBuffer) + '\n';
}
text = text.trimmed();
if(!text.isEmpty())
desc << MetaDataItem(tr("Samples"), text);
text.clear();
for(uint i = 0; i < m_soundFile->GetNumInstruments(); i++)
{
m_soundFile->GetInstrumentName(i, lBuffer);
text += QString::fromUtf8(lBuffer) + '\n';
}
text = text.trimmed();
if(!text.isEmpty())
desc << MetaDataItem(tr("Instruments"), text);
text.clear();
char message[MAX_MESSAGE_LENGTH];
int length = m_soundFile->GetSongComments(message, MAX_MESSAGE_LENGTH, 80);
if (length != 0)
desc << MetaDataItem(tr("Comment"), QString::fromUtf8(message).trimmed ());
return desc;
}
QString ModPlugMetaDataModel::getTypeName(quint32 type)
{
switch (type) {
case MOD_TYPE_MOD:
return "ProTracker";
case MOD_TYPE_S3M:
return "Scream Tracker 3";
case MOD_TYPE_XM:
return "Fast Tracker 2";
case MOD_TYPE_IT:
return "Impulse Tracker";
case MOD_TYPE_MED:
return "OctaMed";
case MOD_TYPE_MTM:
return "MTM";
case MOD_TYPE_669:
return "669 Composer / UNIS 669";
case MOD_TYPE_ULT:
return "ULT";
case MOD_TYPE_STM:
return "Scream Tracker";
case MOD_TYPE_FAR:
return "Farandole";
case MOD_TYPE_AMF:
return "ASYLUM Music Format";
case MOD_TYPE_AMS:
return "AMS module";
case MOD_TYPE_DSM:
return "DSIK Internal Format";
case MOD_TYPE_MDL:
return "DigiTracker";
case MOD_TYPE_OKT:
return "Oktalyzer";
case MOD_TYPE_DMF:
return "Delusion Digital Music Fileformat (X-Tracker)";
case MOD_TYPE_PTM:
return "PolyTracker";
case MOD_TYPE_DBM:
return "DigiBooster Pro";
case MOD_TYPE_MT2:
return "MT2";
case MOD_TYPE_AMF0:
return "AMF0";
case MOD_TYPE_PSM:
return "PSM";
default:
;
}
return "Unknown";
}
|