1
///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Model_AudioFile.h"
28 #include <QMutexLocker>
33 const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32
= UINT_MAX
-1;
35 #define PRINT_S(VAR) do \
37 if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", (VAR).toUtf8().constData()); \
41 #define PRINT_U(VAR) do \
43 if((VAR) < 1) qDebug(#VAR " = N/A"); else qDebug(#VAR " = %u", (VAR)); \
47 ///////////////////////////////////////////////////////////////////////////////
48 // Audio File - Meta Info
49 ///////////////////////////////////////////////////////////////////////////////
51 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
56 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo
&model
)
58 m_titel
= model
.m_titel
;
59 m_artist
= model
.m_artist
;
60 m_album
= model
.m_album
;
61 m_genre
= model
.m_genre
;
62 m_comment
= model
.m_comment
;
63 m_cover
= model
.m_cover
;
64 m_year
= model
.m_year
;
65 m_position
= model
.m_position
;
68 AudioFileModel_MetaInfo
&AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo
&model
)
70 m_titel
= model
.m_titel
;
71 m_artist
= model
.m_artist
;
72 m_album
= model
.m_album
;
73 m_genre
= model
.m_genre
;
74 m_comment
= model
.m_comment
;
75 m_cover
= model
.m_cover
;
76 m_year
= model
.m_year
;
77 m_position
= model
.m_position
;
82 void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo
&model
, const bool replace
)
84 qDebug("\n-------[AudioFileModel_MetaInfo::update]-------");
85 qDebug("Updating (%p):", this);
87 qDebug("\nUpdating with (%p):", &model
);
90 if((!model
.m_titel
.isEmpty()) && (replace
|| m_titel
.isEmpty())) m_titel
= model
.m_titel
;
91 if((!model
.m_artist
.isEmpty()) && (replace
|| m_artist
.isEmpty())) m_artist
= model
.m_artist
;
92 if((!model
.m_album
.isEmpty()) && (replace
|| m_album
.isEmpty())) m_album
= model
.m_album
;
93 if((!model
.m_genre
.isEmpty()) && (replace
|| m_genre
.isEmpty())) m_genre
= model
.m_genre
;
94 if((!model
.m_comment
.isEmpty()) && (replace
|| m_comment
.isEmpty())) m_comment
= model
.m_comment
;
95 if((!model
.m_cover
.isEmpty()) && (replace
|| m_cover
.isEmpty())) m_cover
= model
.m_cover
;
96 if((model
.m_year
> 0) && (replace
|| (m_year
== 0))) m_year
= model
.m_year
;
97 if((model
.m_position
> 0) && (replace
|| (m_position
== 0))) m_position
= model
.m_position
;
101 qDebug("-----------------------------------------------\n\n");
104 AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
109 void AudioFileModel_MetaInfo::reset(void)
121 void AudioFileModel_MetaInfo::print(void) const
128 PRINT_S(m_cover
.filePath());
133 ///////////////////////////////////////////////////////////////////////////////
134 // Audio File - Technical Info
135 ///////////////////////////////////////////////////////////////////////////////
137 AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
142 AudioFileModel_TechInfo::AudioFileModel_TechInfo(const AudioFileModel_TechInfo
&model
)
144 m_containerType
= model
.m_containerType
;
145 m_containerProfile
= model
.m_containerProfile
;
146 m_audioType
= model
.m_audioType
;
147 m_audioProfile
= model
.m_audioProfile
;
148 m_audioVersion
= model
.m_audioVersion
;
149 m_audioEncodeLib
= model
.m_audioEncodeLib
;
150 m_audioSamplerate
= model
.m_audioSamplerate
;
151 m_audioChannels
= model
.m_audioChannels
;
152 m_audioBitdepth
= model
.m_audioBitdepth
;
153 m_audioBitrate
= model
.m_audioBitrate
;
154 m_audioBitrateMode
= model
.m_audioBitrateMode
;
155 m_duration
= model
.m_duration
;
158 AudioFileModel_TechInfo
&AudioFileModel_TechInfo::operator=(const AudioFileModel_TechInfo
&model
)
160 m_containerType
= model
.m_containerType
;
161 m_containerProfile
= model
.m_containerProfile
;
162 m_audioType
= model
.m_audioType
;
163 m_audioProfile
= model
.m_audioProfile
;
164 m_audioVersion
= model
.m_audioVersion
;
165 m_audioEncodeLib
= model
.m_audioEncodeLib
;
166 m_audioSamplerate
= model
.m_audioSamplerate
;
167 m_audioChannels
= model
.m_audioChannels
;
168 m_audioBitdepth
= model
.m_audioBitdepth
;
169 m_audioBitrate
= model
.m_audioBitrate
;
170 m_audioBitrateMode
= model
.m_audioBitrateMode
;
171 m_duration
= model
.m_duration
;
176 AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
181 void AudioFileModel_TechInfo::reset(void)
183 m_containerType
.clear();
184 m_containerProfile
.clear();
186 m_audioProfile
.clear();
187 m_audioVersion
.clear();
188 m_audioEncodeLib
.clear();
189 m_audioSamplerate
= 0;
193 m_audioBitrateMode
= 0;
197 ////////////////////////////////////////////////////////////
199 ////////////////////////////////////////////////////////////
201 AudioFileModel::AudioFileModel(const QString
&path
)
209 AudioFileModel::AudioFileModel(const AudioFileModel
&model
)
211 m_filePath
= model
.m_filePath
;
212 m_metaInfo
= model
.m_metaInfo
;
213 m_techInfo
= model
.m_techInfo
;
216 AudioFileModel
&AudioFileModel::operator=(const AudioFileModel
&model
)
218 m_filePath
= model
.m_filePath
;
219 m_metaInfo
= model
.m_metaInfo
;
220 m_techInfo
= model
.m_techInfo
;
225 AudioFileModel::~AudioFileModel(void)
231 void AudioFileModel::reset(void)
238 /*------------------------------------*/
240 /*------------------------------------*/
242 const QString
AudioFileModel::durationInfo(void) const
244 if(m_techInfo
.duration())
246 QTime time
= QTime().addSecs(m_techInfo
.duration());
247 return time
.toString("hh:mm:ss");
255 const QString
AudioFileModel::containerInfo(void) const
257 if(!m_techInfo
.containerType().isEmpty())
259 QString info
= m_techInfo
.containerType();
260 if(!m_techInfo
.containerProfile().isEmpty()) info
.append(QString(" (%1: %2)").arg(tr("Profile"), m_techInfo
.containerProfile()));
269 const QString
AudioFileModel::audioBaseInfo(void) const
271 if(m_techInfo
.audioSamplerate() || m_techInfo
.audioChannels() || m_techInfo
.audioBitdepth())
274 if(m_techInfo
.audioChannels())
276 if(!info
.isEmpty()) info
.append(", ");
277 info
.append(QString("%1: %2").arg(tr("Channels"), QString::number(m_techInfo
.audioChannels())));
279 if(m_techInfo
.audioSamplerate())
281 if(!info
.isEmpty()) info
.append(", ");
282 info
.append(QString("%1: %2 Hz").arg(tr("Samplerate"), QString::number(m_techInfo
.audioSamplerate())));
284 if(m_techInfo
.audioBitdepth())
286 if(!info
.isEmpty()) info
.append(", ");
287 if(m_techInfo
.audioBitdepth() == BITDEPTH_IEEE_FLOAT32
)
289 info
.append(QString("%1: %2 Bit (IEEE Float)").arg(tr("Bitdepth"), QString::number(32)));
293 info
.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_techInfo
.audioBitdepth())));
304 const QString
AudioFileModel::audioCompressInfo(void) const
306 if(!m_techInfo
.audioType().isEmpty())
309 if(!m_techInfo
.audioProfile().isEmpty() || !m_techInfo
.audioVersion().isEmpty())
311 info
.append(QString("%1: ").arg(tr("Type")));
313 info
.append(m_techInfo
.audioType());
314 if(!m_techInfo
.audioProfile().isEmpty())
316 info
.append(QString(", %1: %2").arg(tr("Profile"), m_techInfo
.audioProfile()));
318 if(!m_techInfo
.audioVersion().isEmpty())
320 info
.append(QString(", %1: %2").arg(tr("Version"), m_techInfo
.audioVersion()));
322 if(m_techInfo
.audioBitrate() > 0)
324 switch(m_techInfo
.audioBitrateMode())
326 case BitrateModeConstant
:
327 info
.append(QString(", %1: %2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo
.audioBitrate()), tr("Constant")));
329 case BitrateModeVariable
:
330 info
.append(WCHAR2QSTR(L
", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo
.audioBitrate()), tr("Variable")));
333 info
.append(QString(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_techInfo
.audioBitrate())));
337 if(!m_techInfo
.audioEncodeLib().isEmpty())
339 info
.append(QString(", %1: %2").arg(tr("Encoder"), m_techInfo
.audioEncodeLib()));