Fixed "mailto:" links in about dialog box.
[LameXP.git] / src / Model_AudioFile.cpp
blobdf7b8cb5566ffb14f21c3d822ee6918f8aa042c7
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Model_AudioFile.h"
25 #include "Global.h"
27 #include <QTime>
28 #include <QObject>
29 #include <QMutexLocker>
30 #include <QFile>
32 #include <limits.h>
34 const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1;
36 #define PRINT_S(VAR) do \
37 { \
38 if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", QUTF8((VAR))); \
39 } \
40 while(0)
42 #define PRINT_U(VAR) do \
43 { \
44 if((VAR) < 1) qDebug(#VAR " = N/A"); else qDebug(#VAR " = %u", (VAR)); \
45 } \
46 while(0)
48 //if((!(OTHER.NAME.isEmpty())) && ((FORCE) || (this.NAME.isEmpty()))) /*this.NAME = OTHER.NAME;*/ \
50 #define UPDATE_STR(OTHER, FORCE, NAME) do \
51 { \
52 if(!(((OTHER).NAME).isEmpty())) \
53 { \
54 if((FORCE) || ((this->NAME).isEmpty())) (this->NAME) = ((OTHER).NAME); \
55 } \
56 } \
57 while(0)
59 #define UPDATE_INT(OTHER, FORCE, NAME) do \
60 { \
61 if(((OTHER).NAME) > 0) \
62 { \
63 if((FORCE) || ((this->NAME) == 0)) (this->NAME) = ((OTHER).NAME); \
64 } \
65 } \
66 while(0)
68 #define ASSIGN_VAL(OTHER, NAME) do \
69 { \
70 (this->NAME) = ((OTHER).NAME); \
71 } \
72 while(0)
74 ///////////////////////////////////////////////////////////////////////////////
75 // Audio File - Meta Info
76 ///////////////////////////////////////////////////////////////////////////////
78 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
80 reset();
83 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo &model)
85 ASSIGN_VAL(model, m_titel);
86 ASSIGN_VAL(model, m_artist);
87 ASSIGN_VAL(model, m_album);
88 ASSIGN_VAL(model, m_genre);
89 ASSIGN_VAL(model, m_comment);
90 ASSIGN_VAL(model, m_cover);
91 ASSIGN_VAL(model, m_year);
92 ASSIGN_VAL(model, m_position);
95 AudioFileModel_MetaInfo &AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo &model)
97 ASSIGN_VAL(model, m_titel);
98 ASSIGN_VAL(model, m_artist);
99 ASSIGN_VAL(model, m_album);
100 ASSIGN_VAL(model, m_genre);
101 ASSIGN_VAL(model, m_comment);
102 ASSIGN_VAL(model, m_cover);
103 ASSIGN_VAL(model, m_year);
104 ASSIGN_VAL(model, m_position);
106 return (*this);
109 #define IS_EMPTY(X) ((X).isEmpty() ? "YES" : "NO")
111 void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model, const bool replace)
113 UPDATE_STR(model, replace, m_titel);
114 UPDATE_STR(model, replace, m_artist);
115 UPDATE_STR(model, replace, m_album);
116 UPDATE_STR(model, replace, m_genre);
117 UPDATE_STR(model, replace, m_comment);
118 UPDATE_STR(model, replace, m_cover);
119 UPDATE_INT(model, replace, m_year);
120 UPDATE_INT(model, replace, m_position);
123 AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
125 /*nothing to do*/
128 void AudioFileModel_MetaInfo::reset(void)
130 m_titel.clear();
131 m_artist.clear();
132 m_album.clear();
133 m_genre.clear();
134 m_comment.clear();
135 m_cover.clear();
136 m_year = 0;
137 m_position = 0;
140 void AudioFileModel_MetaInfo::print(void) const
142 PRINT_S(m_titel);
143 PRINT_S(m_artist);
144 PRINT_S(m_album);
145 PRINT_S(m_genre);
146 PRINT_S(m_comment);
147 PRINT_S(m_cover.filePath());
148 PRINT_U(m_year);
149 PRINT_U(m_position);
152 ///////////////////////////////////////////////////////////////////////////////
153 // Audio File - Technical Info
154 ///////////////////////////////////////////////////////////////////////////////
156 AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
158 reset();
161 AudioFileModel_TechInfo::AudioFileModel_TechInfo(const AudioFileModel_TechInfo &model)
163 ASSIGN_VAL(model, m_containerType);
164 ASSIGN_VAL(model, m_containerProfile);
165 ASSIGN_VAL(model, m_audioType);
166 ASSIGN_VAL(model, m_audioProfile);
167 ASSIGN_VAL(model, m_audioVersion);
168 ASSIGN_VAL(model, m_audioEncodeLib);
169 ASSIGN_VAL(model, m_audioSamplerate);
170 ASSIGN_VAL(model, m_audioChannels);
171 ASSIGN_VAL(model, m_audioBitdepth);
172 ASSIGN_VAL(model, m_audioBitrate);
173 ASSIGN_VAL(model, m_audioBitrateMode);
174 ASSIGN_VAL(model, m_duration);
177 AudioFileModel_TechInfo &AudioFileModel_TechInfo::operator=(const AudioFileModel_TechInfo &model)
179 ASSIGN_VAL(model, m_containerType);
180 ASSIGN_VAL(model, m_containerProfile);
181 ASSIGN_VAL(model, m_audioType);
182 ASSIGN_VAL(model, m_audioProfile);
183 ASSIGN_VAL(model, m_audioVersion);
184 ASSIGN_VAL(model, m_audioEncodeLib);
185 ASSIGN_VAL(model, m_audioSamplerate);
186 ASSIGN_VAL(model, m_audioChannels);
187 ASSIGN_VAL(model, m_audioBitdepth);
188 ASSIGN_VAL(model, m_audioBitrate);
189 ASSIGN_VAL(model, m_audioBitrateMode);
190 ASSIGN_VAL(model, m_duration);
192 return (*this);
195 AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
197 /*nothing to do*/
200 void AudioFileModel_TechInfo::reset(void)
202 m_containerType.clear();
203 m_containerProfile.clear();
204 m_audioType.clear();
205 m_audioProfile.clear();
206 m_audioVersion.clear();
207 m_audioEncodeLib.clear();
208 m_audioSamplerate = 0;
209 m_audioChannels = 0;
210 m_audioBitdepth = 0;
211 m_audioBitrate = 0;
212 m_audioBitrateMode = 0;
213 m_duration = 0;
216 ////////////////////////////////////////////////////////////
217 // Audio File Model
218 ////////////////////////////////////////////////////////////
220 AudioFileModel::AudioFileModel(const QString &path)
222 m_filePath(path)
224 m_metaInfo.reset();
225 m_techInfo.reset();
228 AudioFileModel::AudioFileModel(const AudioFileModel &model)
230 ASSIGN_VAL(model, m_filePath);
231 ASSIGN_VAL(model, m_metaInfo);
232 ASSIGN_VAL(model, m_techInfo);
235 AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
237 ASSIGN_VAL(model, m_filePath);
238 ASSIGN_VAL(model, m_metaInfo);
239 ASSIGN_VAL(model, m_techInfo);
241 return (*this);
244 AudioFileModel::~AudioFileModel(void)
246 /*nothing to do*/
250 void AudioFileModel::reset(void)
252 m_filePath.clear();
253 m_metaInfo.reset();
254 m_techInfo.reset();
257 /*------------------------------------*/
258 /* Helper functions
259 /*------------------------------------*/
261 const QString AudioFileModel::durationInfo(void) const
263 if(m_techInfo.duration())
265 QTime time = QTime().addSecs(m_techInfo.duration());
266 return time.toString("hh:mm:ss");
268 else
270 return QString();
274 const QString AudioFileModel::containerInfo(void) const
276 if(!m_techInfo.containerType().isEmpty())
278 QString info = m_techInfo.containerType();
279 if(!m_techInfo.containerProfile().isEmpty()) info.append(QString(" (%1: %2)").arg(tr("Profile"), m_techInfo.containerProfile()));
280 return info;
282 else
284 return QString();
288 const QString AudioFileModel::audioBaseInfo(void) const
290 if(m_techInfo.audioSamplerate() || m_techInfo.audioChannels() || m_techInfo.audioBitdepth())
292 QString info;
293 if(m_techInfo.audioChannels())
295 if(!info.isEmpty()) info.append(", ");
296 info.append(QString("%1: %2").arg(tr("Channels"), QString::number(m_techInfo.audioChannels())));
298 if(m_techInfo.audioSamplerate())
300 if(!info.isEmpty()) info.append(", ");
301 info.append(QString("%1: %2 Hz").arg(tr("Samplerate"), QString::number(m_techInfo.audioSamplerate())));
303 if(m_techInfo.audioBitdepth())
305 if(!info.isEmpty()) info.append(", ");
306 if(m_techInfo.audioBitdepth() == BITDEPTH_IEEE_FLOAT32)
308 info.append(QString("%1: %2 Bit (IEEE Float)").arg(tr("Bitdepth"), QString::number(32)));
310 else
312 info.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_techInfo.audioBitdepth())));
315 return info;
317 else
319 return QString();
323 const QString AudioFileModel::audioCompressInfo(void) const
325 if(!m_techInfo.audioType().isEmpty())
327 QString info;
328 if(!m_techInfo.audioProfile().isEmpty() || !m_techInfo.audioVersion().isEmpty())
330 info.append(QString("%1: ").arg(tr("Type")));
332 info.append(m_techInfo.audioType());
333 if(!m_techInfo.audioProfile().isEmpty())
335 info.append(QString(", %1: %2").arg(tr("Profile"), m_techInfo.audioProfile()));
337 if(!m_techInfo.audioVersion().isEmpty())
339 info.append(QString(", %1: %2").arg(tr("Version"), m_techInfo.audioVersion()));
341 if(m_techInfo.audioBitrate() > 0)
343 switch(m_techInfo.audioBitrateMode())
345 case BitrateModeConstant:
346 info.append(QString(", %1: %2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Constant")));
347 break;
348 case BitrateModeVariable:
349 info.append(WCHAR2QSTR(L", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Variable")));
350 break;
351 default:
352 info.append(QString(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate())));
353 break;
356 if(!m_techInfo.audioEncodeLib().isEmpty())
358 info.append(QString(", %1: %2").arg(tr("Encoder"), m_techInfo.audioEncodeLib()));
360 return info;
362 else
364 return QString();