Updated CueImportDialog and CueSheetModel as well as the CueSheet helper classes...
[LameXP.git] / src / Model_AudioFile.cpp
blob00247b6b8ad3b2ede0ab950007cb22780f934561
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
9 //
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"
24 #include "Global.h"
26 #include <QTime>
27 #include <QObject>
28 #include <QMutexLocker>
29 #include <QFile>
31 #include <limits.h>
33 const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1;
35 #define PRINT_S(VAR) do \
36 { \
37 if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", (VAR).toUtf8().constData()); \
38 } \
39 while(0)
41 #define PRINT_U(VAR) do \
42 { \
43 if((VAR) < 1) qDebug(#VAR " = N/A"); else qDebug(#VAR " = %u", (VAR)); \
44 } \
45 while(0)
47 ///////////////////////////////////////////////////////////////////////////////
48 // Audio File - Meta Info
49 ///////////////////////////////////////////////////////////////////////////////
51 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
53 reset();
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;
79 return (*this);
82 void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model, const bool replace)
84 qDebug("\n-------[AudioFileModel_MetaInfo::update]-------");
85 qDebug("Updating (%p):", this);
86 print();
87 qDebug("\nUpdating with (%p):", &model);
88 model.print();
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;
99 qDebug("\nResult:");
100 print();
101 qDebug("-----------------------------------------------\n\n");
104 AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
106 /*nothing to do*/
109 void AudioFileModel_MetaInfo::reset(void)
111 m_titel.clear();
112 m_artist.clear();
113 m_album.clear();
114 m_genre.clear();
115 m_comment.clear();
116 m_cover.clear();
117 m_year = 0;
118 m_position = 0;
121 void AudioFileModel_MetaInfo::print(void) const
123 PRINT_S(m_titel);
124 PRINT_S(m_artist);
125 PRINT_S(m_album);
126 PRINT_S(m_genre);
127 PRINT_S(m_comment);
128 PRINT_S(m_cover.filePath());
129 PRINT_U(m_year);
130 PRINT_U(m_position);
133 ///////////////////////////////////////////////////////////////////////////////
134 // Audio File - Technical Info
135 ///////////////////////////////////////////////////////////////////////////////
137 AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
139 reset();
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;
173 return (*this);
176 AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
178 /*nothing to do*/
181 void AudioFileModel_TechInfo::reset(void)
183 m_containerType.clear();
184 m_containerProfile.clear();
185 m_audioType.clear();
186 m_audioProfile.clear();
187 m_audioVersion.clear();
188 m_audioEncodeLib.clear();
189 m_audioSamplerate = 0;
190 m_audioChannels = 0;
191 m_audioBitdepth = 0;
192 m_audioBitrate = 0;
193 m_audioBitrateMode = 0;
194 m_duration = 0;
197 ////////////////////////////////////////////////////////////
198 // Audio File Model
199 ////////////////////////////////////////////////////////////
201 AudioFileModel::AudioFileModel(const QString &path)
203 m_filePath(path)
205 m_metaInfo.reset();
206 m_techInfo.reset();
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;
222 return (*this);
225 AudioFileModel::~AudioFileModel(void)
227 /*nothing to do*/
231 void AudioFileModel::reset(void)
233 m_filePath.clear();
234 m_metaInfo.reset();
235 m_techInfo.reset();
238 /*------------------------------------*/
239 /* Helper functions
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");
249 else
251 return QString();
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()));
261 return info;
263 else
265 return QString();
269 const QString AudioFileModel::audioBaseInfo(void) const
271 if(m_techInfo.audioSamplerate() || m_techInfo.audioChannels() || m_techInfo.audioBitdepth())
273 QString info;
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)));
291 else
293 info.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_techInfo.audioBitdepth())));
296 return info;
298 else
300 return QString();
304 const QString AudioFileModel::audioCompressInfo(void) const
306 if(!m_techInfo.audioType().isEmpty())
308 QString info;
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")));
328 break;
329 case BitrateModeVariable:
330 info.append(WCHAR2QSTR(L", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Variable")));
331 break;
332 default:
333 info.append(QString(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate())));
334 break;
337 if(!m_techInfo.audioEncodeLib().isEmpty())
339 info.append(QString(", %1: %2").arg(tr("Encoder"), m_techInfo.audioEncodeLib()));
341 return info;
343 else
345 return QString();