1
///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
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"
29 #include <QMutexLocker>
34 const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32
= UINT_MAX
-1;
36 #define PRINT_S(VAR) do \
38 if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", QUTF8((VAR))); \
42 #define PRINT_U(VAR) do \
44 if((VAR) < 1) qDebug(#VAR " = N/A"); else qDebug(#VAR " = %u", (VAR)); \
48 //if((!(OTHER.NAME.isEmpty())) && ((FORCE) || (this.NAME.isEmpty()))) /*this.NAME = OTHER.NAME;*/ \
50 #define UPDATE_STR(OTHER, FORCE, NAME) do \
52 if(!(((OTHER).NAME).isEmpty())) \
54 if((FORCE) || ((this->NAME).isEmpty())) (this->NAME) = ((OTHER).NAME); \
59 #define UPDATE_INT(OTHER, FORCE, NAME) do \
61 if(((OTHER).NAME) > 0) \
63 if((FORCE) || ((this->NAME) == 0)) (this->NAME) = ((OTHER).NAME); \
68 #define ASSIGN_VAL(OTHER, NAME) do \
70 (this->NAME) = ((OTHER).NAME); \
74 ///////////////////////////////////////////////////////////////////////////////
75 // Audio File - Meta Info
76 ///////////////////////////////////////////////////////////////////////////////
78 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
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
);
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)
128 void AudioFileModel_MetaInfo::reset(void)
140 void AudioFileModel_MetaInfo::print(void) const
147 PRINT_S(m_cover
.filePath());
152 ///////////////////////////////////////////////////////////////////////////////
153 // Audio File - Technical Info
154 ///////////////////////////////////////////////////////////////////////////////
156 AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
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
);
195 AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
200 void AudioFileModel_TechInfo::reset(void)
202 m_containerType
.clear();
203 m_containerProfile
.clear();
205 m_audioProfile
.clear();
206 m_audioVersion
.clear();
207 m_audioEncodeLib
.clear();
208 m_audioSamplerate
= 0;
212 m_audioBitrateMode
= 0;
216 ////////////////////////////////////////////////////////////
218 ////////////////////////////////////////////////////////////
220 AudioFileModel::AudioFileModel(const QString
&path
)
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
);
244 AudioFileModel::~AudioFileModel(void)
250 void AudioFileModel::reset(void)
257 /*------------------------------------*/
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");
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()));
288 const QString
AudioFileModel::audioBaseInfo(void) const
290 if(m_techInfo
.audioSamplerate() || m_techInfo
.audioChannels() || m_techInfo
.audioBitdepth())
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)));
312 info
.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_techInfo
.audioBitdepth())));
323 const QString
AudioFileModel::audioCompressInfo(void) const
325 if(!m_techInfo
.audioType().isEmpty())
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")));
348 case BitrateModeVariable
:
349 info
.append(WCHAR2QSTR(L
", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo
.audioBitrate()), tr("Variable")));
352 info
.append(QString(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_techInfo
.audioBitrate())));
356 if(!m_techInfo
.audioEncodeLib().isEmpty())
358 info
.append(QString(", %1: %2").arg(tr("Encoder"), m_techInfo
.audioEncodeLib()));