2010-11-06 23:04:47 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2011-01-01 17:04:25 +01:00
|
|
|
// Copyright (C) 2004-2011 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 <QTime>
|
2011-01-14 23:34:31 +01:00
|
|
|
#include <QObject>
|
2010-11-06 23:04:47 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor & Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
AudioFileModel::AudioFileModel(const QString &path, const QString &name)
|
|
|
|
{
|
2011-02-06 23:43:26 +01:00
|
|
|
resetAll();
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
m_filePath = path;
|
|
|
|
m_fileName = name;
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:34:14 +01:00
|
|
|
AudioFileModel::AudioFileModel(const AudioFileModel &model, bool copyMetaInfo)
|
2011-01-14 23:34:31 +01:00
|
|
|
{
|
2011-02-06 23:43:26 +01:00
|
|
|
resetAll();
|
2011-01-14 23:34:31 +01:00
|
|
|
|
2011-02-06 17:34:14 +01:00
|
|
|
setFilePath(model.m_filePath);
|
2011-01-14 23:34:31 +01:00
|
|
|
setFormatContainerType(model.m_formatContainerType);
|
|
|
|
setFormatContainerProfile(model.m_formatContainerProfile);
|
|
|
|
setFormatAudioType(model.m_formatAudioType);
|
|
|
|
setFormatAudioProfile(model.m_formatAudioProfile);
|
|
|
|
setFormatAudioVersion(model.m_formatAudioVersion);
|
|
|
|
setFormatAudioSamplerate(model.m_formatAudioSamplerate);
|
|
|
|
setFormatAudioChannels(model.m_formatAudioChannels);
|
|
|
|
setFormatAudioBitdepth(model.m_formatAudioBitdepth);
|
2011-02-06 17:34:14 +01:00
|
|
|
setFileDuration(model.m_fileDuration);
|
|
|
|
|
|
|
|
if(copyMetaInfo)
|
|
|
|
{
|
|
|
|
setFileName(model.m_fileName);
|
|
|
|
setFileArtist(model.m_fileArtist);
|
|
|
|
setFileAlbum(model.m_fileAlbum);
|
|
|
|
setFileGenre(model.m_fileGenre);
|
|
|
|
setFileComment(model.m_fileComment);
|
|
|
|
setFileYear(model.m_fileYear);
|
|
|
|
setFilePosition(model.m_filePosition);
|
|
|
|
}
|
2011-01-14 23:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
|
|
|
|
{
|
|
|
|
setFilePath(model.m_filePath);
|
|
|
|
setFileName(model.m_fileName);
|
|
|
|
setFileArtist(model.m_fileArtist);
|
|
|
|
setFileAlbum(model.m_fileAlbum);
|
|
|
|
setFileGenre(model.m_fileGenre);
|
|
|
|
setFileComment(model.m_fileComment);
|
|
|
|
setFileYear(model.m_fileYear);
|
|
|
|
setFilePosition(model.m_filePosition);
|
|
|
|
setFileDuration(model.m_fileDuration);
|
|
|
|
|
|
|
|
setFormatContainerType(model.m_formatContainerType);
|
|
|
|
setFormatContainerProfile(model.m_formatContainerProfile);
|
|
|
|
setFormatAudioType(model.m_formatAudioType);
|
|
|
|
setFormatAudioProfile(model.m_formatAudioProfile);
|
|
|
|
setFormatAudioVersion(model.m_formatAudioVersion);
|
|
|
|
setFormatAudioSamplerate(model.m_formatAudioSamplerate);
|
|
|
|
setFormatAudioChannels(model.m_formatAudioChannels);
|
|
|
|
setFormatAudioBitdepth(model.m_formatAudioBitdepth);
|
|
|
|
|
|
|
|
return (*this);
|
|
|
|
}
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
AudioFileModel::~AudioFileModel(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-06 23:43:26 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Private Functions
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void AudioFileModel::resetAll(void)
|
|
|
|
{
|
|
|
|
m_filePath.clear();
|
|
|
|
m_fileName.clear();
|
|
|
|
m_fileArtist.clear();
|
|
|
|
m_fileAlbum.clear();
|
|
|
|
m_fileGenre.clear();
|
|
|
|
m_fileComment.clear();
|
|
|
|
|
|
|
|
m_fileYear = 0;
|
|
|
|
m_filePosition = 0;
|
|
|
|
m_fileDuration = 0;
|
|
|
|
|
|
|
|
m_formatContainerType.clear();
|
|
|
|
m_formatContainerProfile.clear();
|
|
|
|
m_formatAudioType.clear();
|
|
|
|
m_formatAudioProfile.clear();
|
|
|
|
m_formatAudioVersion.clear();
|
|
|
|
|
|
|
|
m_formatAudioSamplerate = 0;
|
|
|
|
m_formatAudioChannels = 0;
|
|
|
|
m_formatAudioBitdepth = 0;
|
|
|
|
}
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Public Functions
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ---------------------------------
|
|
|
|
// Getter methods
|
|
|
|
// ---------------------------------
|
|
|
|
|
|
|
|
const QString &AudioFileModel::filePath(void) const
|
|
|
|
{
|
|
|
|
return m_filePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::fileName(void) const
|
|
|
|
{
|
|
|
|
return m_fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::fileArtist(void) const
|
|
|
|
{
|
|
|
|
return m_fileArtist;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::fileAlbum(void) const
|
|
|
|
{
|
|
|
|
return m_fileAlbum;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::fileGenre(void) const
|
|
|
|
{
|
|
|
|
return m_fileGenre;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::fileComment(void) const
|
|
|
|
{
|
|
|
|
return m_fileComment;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AudioFileModel::fileYear(void) const
|
|
|
|
{
|
|
|
|
return m_fileYear;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AudioFileModel::filePosition(void) const
|
|
|
|
{
|
|
|
|
return m_filePosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AudioFileModel::fileDuration(void) const
|
|
|
|
{
|
|
|
|
return m_fileDuration;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::formatContainerType(void) const
|
|
|
|
{
|
|
|
|
return m_formatContainerType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::formatContainerProfile(void) const
|
|
|
|
{
|
|
|
|
return m_formatContainerProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::formatAudioType(void) const
|
|
|
|
{
|
|
|
|
return m_formatAudioType;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::formatAudioProfile(void) const
|
|
|
|
{
|
|
|
|
return m_formatAudioProfile;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &AudioFileModel::formatAudioVersion(void) const
|
|
|
|
{
|
|
|
|
return m_formatAudioVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AudioFileModel::formatAudioSamplerate(void) const
|
|
|
|
{
|
|
|
|
return m_formatAudioSamplerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AudioFileModel::formatAudioChannels(void) const
|
|
|
|
{
|
|
|
|
return m_formatAudioChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int AudioFileModel::formatAudioBitdepth(void) const
|
|
|
|
{
|
|
|
|
return m_formatAudioBitdepth;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString AudioFileModel::fileDurationInfo(void) const
|
|
|
|
{
|
|
|
|
if(m_fileDuration)
|
|
|
|
{
|
|
|
|
QTime time = QTime().addSecs(m_fileDuration);
|
|
|
|
return time.toString("hh:mm:ss");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString AudioFileModel::formatContainerInfo(void) const
|
|
|
|
{
|
|
|
|
if(!m_formatContainerType.isEmpty())
|
|
|
|
{
|
|
|
|
QString info = m_formatContainerType;
|
2011-01-14 23:34:31 +01:00
|
|
|
if(!m_formatContainerProfile.isEmpty()) info.append(QString(" (%1: %2)").arg(tr("Profile"), m_formatContainerProfile));
|
2010-11-06 23:04:47 +01:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString AudioFileModel::formatAudioBaseInfo(void) const
|
|
|
|
{
|
|
|
|
if(m_formatAudioSamplerate || m_formatAudioChannels || m_formatAudioBitdepth)
|
|
|
|
{
|
|
|
|
QString info;
|
|
|
|
if(m_formatAudioChannels)
|
|
|
|
{
|
|
|
|
if(!info.isEmpty()) info.append(", ");
|
2011-01-14 23:34:31 +01:00
|
|
|
info.append(QString("%1: %2").arg(tr("Channels"), QString::number(m_formatAudioChannels)));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
if(m_formatAudioSamplerate)
|
|
|
|
{
|
|
|
|
if(!info.isEmpty()) info.append(", ");
|
2011-01-14 23:34:31 +01:00
|
|
|
info.append(QString("%1: %2 Hz").arg(tr("Samplerate"), QString::number(m_formatAudioSamplerate)));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
if(m_formatAudioBitdepth)
|
|
|
|
{
|
|
|
|
if(!info.isEmpty()) info.append(", ");
|
2011-01-14 23:34:31 +01:00
|
|
|
info.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_formatAudioBitdepth)));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString AudioFileModel::formatAudioCompressInfo(void) const
|
|
|
|
{
|
|
|
|
if(!m_formatAudioType.isEmpty())
|
|
|
|
{
|
|
|
|
QString info;
|
|
|
|
if(!m_formatAudioProfile.isEmpty() || !m_formatAudioVersion.isEmpty())
|
|
|
|
{
|
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_formatAudioType);
|
|
|
|
if(!m_formatAudioProfile.isEmpty())
|
|
|
|
{
|
2011-01-14 23:34:31 +01:00
|
|
|
info.append(QString(", %1: %2").arg(tr("Profile"), m_formatAudioProfile));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
if(!m_formatAudioVersion.isEmpty())
|
|
|
|
{
|
2011-01-14 23:34:31 +01:00
|
|
|
info.append(QString(", %1: %2").arg(tr("Version"), m_formatAudioVersion));
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------
|
|
|
|
// Setter methods
|
|
|
|
// ---------------------------------
|
|
|
|
|
|
|
|
void AudioFileModel::setFilePath(const QString &path)
|
|
|
|
{
|
|
|
|
m_filePath = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileName(const QString &name)
|
|
|
|
{
|
|
|
|
m_fileName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileArtist(const QString &artist)
|
|
|
|
{
|
|
|
|
m_fileArtist = artist;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileAlbum(const QString &album)
|
|
|
|
{
|
|
|
|
m_fileAlbum = album;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileGenre(const QString &genre)
|
|
|
|
{
|
|
|
|
m_fileGenre = genre;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileComment(const QString &comment)
|
|
|
|
{
|
|
|
|
m_fileComment = comment;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileYear(unsigned int year)
|
|
|
|
{
|
|
|
|
m_fileYear = year;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFilePosition(unsigned int position)
|
|
|
|
{
|
|
|
|
m_filePosition = position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFileDuration(unsigned int duration)
|
|
|
|
{
|
|
|
|
m_fileDuration = duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatContainerType(const QString &type)
|
|
|
|
{
|
|
|
|
m_formatContainerType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatContainerProfile(const QString &profile)
|
|
|
|
{
|
|
|
|
m_formatContainerProfile = profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatAudioType(const QString &type)
|
|
|
|
{
|
|
|
|
m_formatAudioType = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatAudioProfile(const QString &profile)
|
|
|
|
{
|
|
|
|
m_formatAudioProfile = profile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatAudioVersion(const QString &version)
|
|
|
|
{
|
|
|
|
m_formatAudioVersion = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatAudioSamplerate(unsigned int samplerate)
|
|
|
|
{
|
|
|
|
m_formatAudioSamplerate = samplerate;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatAudioChannels(unsigned int channels)
|
|
|
|
{
|
|
|
|
m_formatAudioChannels = channels;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AudioFileModel::setFormatAudioBitdepth(unsigned int bitdepth)
|
|
|
|
{
|
|
|
|
m_formatAudioBitdepth = bitdepth;
|
|
|
|
}
|
2011-02-06 23:43:26 +01:00
|
|
|
|
|
|
|
void AudioFileModel::updateMetaInfo(const AudioFileModel &model)
|
|
|
|
{
|
|
|
|
if(!model.fileArtist().isEmpty()) setFileArtist(model.fileArtist());
|
|
|
|
if(!model.fileAlbum().isEmpty()) setFileAlbum(model.fileAlbum());
|
|
|
|
if(!model.fileGenre().isEmpty()) setFileGenre(model.fileGenre());
|
|
|
|
if(!model.fileComment().isEmpty()) setFileComment(model.fileComment());
|
|
|
|
if(model.fileYear()) setFileYear(model.fileYear());
|
|
|
|
}
|