LameXP/src/Model_AudioFile.cpp

315 lines
8.3 KiB
C++
Raw Normal View History

///////////////////////////////////////////////////////////////////////////////
2010-11-06 23:04:47 +01:00
// LameXP - Audio Encoder Front-End
2013-02-08 23:50:51 +01:00
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
2010-11-06 23:04:47 +01:00
//
// 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.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#include "Model_AudioFile.h"
#include "Global.h"
2010-11-06 23:04:47 +01:00
#include <QTime>
2011-01-14 23:34:31 +01:00
#include <QObject>
2011-03-20 23:32:11 +01:00
#include <QMutexLocker>
#include <QFile>
#include <limits.h>
const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1;
///////////////////////////////////////////////////////////////////////////////
// Audio File - Meta Info
///////////////////////////////////////////////////////////////////////////////
2010-11-06 23:04:47 +01:00
AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
2010-11-06 23:04:47 +01:00
{
reset();
2010-11-06 23:04:47 +01:00
}
AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo &model)
2011-01-14 23:34:31 +01:00
{
m_titel = model.m_titel;
m_artist = model.m_artist;
m_album = model.m_album;
m_genre = model.m_genre;
m_comment = model.m_comment;
m_cover = model.m_cover;
m_year = model.m_year;
m_position = model.m_position;
2011-01-14 23:34:31 +01:00
}
AudioFileModel_MetaInfo &AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo &model)
2011-01-14 23:34:31 +01:00
{
m_titel = model.m_titel;
m_artist = model.m_artist;
m_album = model.m_album;
m_genre = model.m_genre;
m_comment = model.m_comment;
m_cover = model.m_cover;
m_year = model.m_year;
m_position = model.m_position;
2011-01-14 23:34:31 +01:00
return (*this);
}
void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model)
{
if(!model.m_titel.isEmpty()) m_titel = model.m_titel;
if(!model.m_artist.isEmpty()) m_artist = model.m_artist;
if(!model.m_album.isEmpty()) m_album = model.m_album;
if(!model.m_genre.isEmpty()) m_genre = model.m_genre;
if(!model.m_comment.isEmpty()) m_comment = model.m_comment;
if(!model.m_cover.isEmpty()) m_cover = model.m_cover;
if(model.m_year > 0) m_year = model.m_year;
if(model.m_position > 0) m_position = model.m_position;
}
AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
2010-11-06 23:04:47 +01:00
{
/*nothing to do*/
2010-11-06 23:04:47 +01:00
}
void AudioFileModel_MetaInfo::reset(void)
2010-11-06 23:04:47 +01:00
{
m_titel.clear();
m_artist.clear();
m_album.clear();
m_genre.clear();
m_comment.clear();
m_cover.clear();
m_year = 0;
m_position = 0;
2010-11-06 23:04:47 +01:00
}
///////////////////////////////////////////////////////////////////////////////
// Audio File - Technical Info
///////////////////////////////////////////////////////////////////////////////
2010-11-06 23:04:47 +01:00
AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
2010-11-06 23:04:47 +01:00
{
reset();
2010-11-06 23:04:47 +01:00
}
AudioFileModel_TechInfo::AudioFileModel_TechInfo(const AudioFileModel_TechInfo &model)
2011-03-20 23:32:11 +01:00
{
m_containerType = model.m_containerType;
m_containerProfile = model.m_containerProfile;
m_audioType = model.m_audioType;
m_audioProfile = model.m_audioProfile;
m_audioVersion = model.m_audioVersion;
m_audioEncodeLib = model.m_audioEncodeLib;
m_audioSamplerate = model.m_audioSamplerate;
m_audioChannels = model.m_audioChannels;
m_audioBitdepth = model.m_audioBitdepth;
m_audioBitrate = model.m_audioBitrate;
m_audioBitrateMode = model.m_audioBitrateMode;
m_duration = model.m_duration;
2011-03-20 23:32:11 +01:00
}
AudioFileModel_TechInfo &AudioFileModel_TechInfo::operator=(const AudioFileModel_TechInfo &model)
2010-11-06 23:04:47 +01:00
{
m_containerType = model.m_containerType;
m_containerProfile = model.m_containerProfile;
m_audioType = model.m_audioType;
m_audioProfile = model.m_audioProfile;
m_audioVersion = model.m_audioVersion;
m_audioEncodeLib = model.m_audioEncodeLib;
m_audioSamplerate = model.m_audioSamplerate;
m_audioChannels = model.m_audioChannels;
m_audioBitdepth = model.m_audioBitdepth;
m_audioBitrate = model.m_audioBitrate;
m_audioBitrateMode = model.m_audioBitrateMode;
m_duration = model.m_duration;
2010-11-06 23:04:47 +01:00
return (*this);
2010-11-06 23:04:47 +01:00
}
AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
2010-11-06 23:04:47 +01:00
{
/*nothing to do*/
2010-11-06 23:04:47 +01:00
}
void AudioFileModel_TechInfo::reset(void)
2010-11-06 23:04:47 +01:00
{
m_containerType.clear();
m_containerProfile.clear();
m_audioType.clear();
m_audioProfile.clear();
m_audioVersion.clear();
m_audioEncodeLib.clear();
m_audioSamplerate = 0;
m_audioChannels = 0;
m_audioBitdepth = 0;
m_audioBitrate = 0;
m_audioBitrateMode = 0;
m_duration = 0;
2010-11-06 23:04:47 +01:00
}
////////////////////////////////////////////////////////////
// Audio File Model
////////////////////////////////////////////////////////////
2010-11-06 23:04:47 +01:00
AudioFileModel::AudioFileModel(const QString &path)
:
m_filePath(path)
2010-11-06 23:04:47 +01:00
{
m_metaInfo.reset();
m_techInfo.reset();
2010-11-06 23:04:47 +01:00
}
AudioFileModel::AudioFileModel(const AudioFileModel &model)
2010-11-06 23:04:47 +01:00
{
m_filePath = model.m_filePath;
m_metaInfo = model.m_metaInfo;
m_techInfo = model.m_techInfo;
2010-11-06 23:04:47 +01:00
}
AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
2010-11-06 23:04:47 +01:00
{
m_filePath = model.m_filePath;
m_metaInfo = model.m_metaInfo;
m_techInfo = model.m_techInfo;
2010-11-06 23:04:47 +01:00
return (*this);
2010-11-06 23:04:47 +01:00
}
AudioFileModel::~AudioFileModel(void)
2010-11-06 23:04:47 +01:00
{
/*nothing to do*/
2010-11-06 23:04:47 +01:00
}
void AudioFileModel::reset(void)
{
m_filePath.clear();
m_metaInfo.reset();
m_techInfo.reset();
}
/*------------------------------------*/
/* Helper functions
/*------------------------------------*/
const QString AudioFileModel::durationInfo(void) const
2010-11-06 23:04:47 +01:00
{
if(m_techInfo.duration())
2010-11-06 23:04:47 +01:00
{
QTime time = QTime().addSecs(m_techInfo.duration());
2010-11-06 23:04:47 +01:00
return time.toString("hh:mm:ss");
}
else
{
return QString();
}
}
const QString AudioFileModel::containerInfo(void) const
2010-11-06 23:04:47 +01:00
{
if(!m_techInfo.containerType().isEmpty())
2010-11-06 23:04:47 +01:00
{
QString info = m_techInfo.containerType();
if(!m_techInfo.containerProfile().isEmpty()) info.append(QString(" (%1: %2)").arg(tr("Profile"), m_techInfo.containerProfile()));
2010-11-06 23:04:47 +01:00
return info;
}
else
{
return QString();
}
}
const QString AudioFileModel::audioBaseInfo(void) const
2010-11-06 23:04:47 +01:00
{
if(m_techInfo.audioSamplerate() || m_techInfo.audioChannels() || m_techInfo.audioBitdepth())
2010-11-06 23:04:47 +01:00
{
QString info;
if(m_techInfo.audioChannels())
2010-11-06 23:04:47 +01:00
{
if(!info.isEmpty()) info.append(", ");
info.append(QString("%1: %2").arg(tr("Channels"), QString::number(m_techInfo.audioChannels())));
2010-11-06 23:04:47 +01:00
}
if(m_techInfo.audioSamplerate())
2010-11-06 23:04:47 +01:00
{
if(!info.isEmpty()) info.append(", ");
info.append(QString("%1: %2 Hz").arg(tr("Samplerate"), QString::number(m_techInfo.audioSamplerate())));
2010-11-06 23:04:47 +01:00
}
if(m_techInfo.audioBitdepth())
2010-11-06 23:04:47 +01:00
{
if(!info.isEmpty()) info.append(", ");
if(m_techInfo.audioBitdepth() == BITDEPTH_IEEE_FLOAT32)
{
info.append(QString("%1: %2 Bit (IEEE Float)").arg(tr("Bitdepth"), QString::number(32)));
}
else
{
info.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_techInfo.audioBitdepth())));
}
2010-11-06 23:04:47 +01:00
}
return info;
}
else
{
return QString();
}
}
const QString AudioFileModel::audioCompressInfo(void) const
2010-11-06 23:04:47 +01:00
{
if(!m_techInfo.audioType().isEmpty())
2010-11-06 23:04:47 +01:00
{
QString info;
if(!m_techInfo.audioProfile().isEmpty() || !m_techInfo.audioVersion().isEmpty())
2010-11-06 23:04:47 +01:00
{
2011-01-14 23:34:31 +01:00
info.append(QString("%1: ").arg(tr("Type")));
2010-11-06 23:04:47 +01:00
}
info.append(m_techInfo.audioType());
if(!m_techInfo.audioProfile().isEmpty())
2010-11-06 23:04:47 +01:00
{
info.append(QString(", %1: %2").arg(tr("Profile"), m_techInfo.audioProfile()));
2010-11-06 23:04:47 +01:00
}
if(!m_techInfo.audioVersion().isEmpty())
2010-11-06 23:04:47 +01:00
{
info.append(QString(", %1: %2").arg(tr("Version"), m_techInfo.audioVersion()));
2010-11-06 23:04:47 +01:00
}
if(m_techInfo.audioBitrate() > 0)
{
switch(m_techInfo.audioBitrateMode())
{
case BitrateModeConstant:
info.append(QString(", %1: %2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Constant")));
break;
case BitrateModeVariable:
info.append(WCHAR2QSTR(L", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Variable")));
break;
default:
info.append(QString(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate())));
break;
}
}
if(!m_techInfo.audioEncodeLib().isEmpty())
{
info.append(QString(", %1: %2").arg(tr("Encoder"), m_techInfo.audioEncodeLib()));
}
2010-11-06 23:04:47 +01:00
return info;
}
else
{
return QString();
}
}