-///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
//
// 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.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
#include "Model_AudioFile.h"
+//Internal
+#include "Global.h"
+
+//MUtils
+#include <MUtils/Global.h>
+
+//Qt
#include <QTime>
+#include <QObject>
+#include <QMutexLocker>
+#include <QFile>
+
+//CRT
+#include <limits.h>
+
+const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1;
+
+#define PRINT_S(VAR) do \
+{ \
+ if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", MUTILS_UTF8((VAR))); \
+} \
+while(0)
+
+#define PRINT_U(VAR) do \
+{ \
+ if((VAR) < 1) qDebug(#VAR " = N/A"); else qDebug(#VAR " = %u", (VAR)); \
+} \
+while(0)
+
+//if((!(OTHER.NAME.isEmpty())) && ((FORCE) || (this.NAME.isEmpty()))) /*this.NAME = OTHER.NAME;*/ \
+
+#define UPDATE_STR(OTHER, FORCE, NAME) do \
+{ \
+ if(!(((OTHER).NAME).isEmpty())) \
+ { \
+ if((FORCE) || ((this->NAME).isEmpty())) (this->NAME) = ((OTHER).NAME); \
+ } \
+} \
+while(0)
+
+#define UPDATE_INT(OTHER, FORCE, NAME) do \
+{ \
+ if(((OTHER).NAME) > 0) \
+ { \
+ if((FORCE) || ((this->NAME) == 0)) (this->NAME) = ((OTHER).NAME); \
+ } \
+} \
+while(0)
+
+#define ASSIGN_VAL(OTHER, NAME) do \
+{ \
+ (this->NAME) = ((OTHER).NAME); \
+} \
+while(0)
-////////////////////////////////////////////////////////////
-// Constructor & Destructor
-////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+// Audio File - Meta Info
+///////////////////////////////////////////////////////////////////////////////
-AudioFileModel::AudioFileModel(const QString &path, const QString &name)
+AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
{
- m_filePath = path;
- m_fileName = name;
- m_fileYear = 0;
- m_filePosition = 0;
- m_fileDuration = 0;
- m_formatAudioSamplerate = 0;
- m_formatAudioChannels = 0;
- m_formatAudioBitdepth = 0;
+ reset();
}
-AudioFileModel::~AudioFileModel(void)
+AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo &model)
{
+ ASSIGN_VAL(model, m_titel);
+ ASSIGN_VAL(model, m_artist);
+ ASSIGN_VAL(model, m_album);
+ ASSIGN_VAL(model, m_genre);
+ ASSIGN_VAL(model, m_comment);
+ ASSIGN_VAL(model, m_cover);
+ ASSIGN_VAL(model, m_year);
+ ASSIGN_VAL(model, m_position);
}
-////////////////////////////////////////////////////////////
-// Public Functions
-////////////////////////////////////////////////////////////
-
-// ---------------------------------
-// Getter methods
-// ---------------------------------
-
-const QString &AudioFileModel::filePath(void) const
+AudioFileModel_MetaInfo &AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo &model)
{
- return m_filePath;
-}
+ ASSIGN_VAL(model, m_titel);
+ ASSIGN_VAL(model, m_artist);
+ ASSIGN_VAL(model, m_album);
+ ASSIGN_VAL(model, m_genre);
+ ASSIGN_VAL(model, m_comment);
+ ASSIGN_VAL(model, m_cover);
+ ASSIGN_VAL(model, m_year);
+ ASSIGN_VAL(model, m_position);
-const QString &AudioFileModel::fileName(void) const
-{
- return m_fileName;
+ return (*this);
}
-const QString &AudioFileModel::fileArtist(void) const
-{
- return m_fileArtist;
-}
+#define IS_EMPTY(X) ((X).isEmpty() ? "YES" : "NO")
-const QString &AudioFileModel::fileAlbum(void) const
+void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model, const bool replace)
{
- return m_fileAlbum;
+ UPDATE_STR(model, replace, m_titel);
+ UPDATE_STR(model, replace, m_artist);
+ UPDATE_STR(model, replace, m_album);
+ UPDATE_STR(model, replace, m_genre);
+ UPDATE_STR(model, replace, m_comment);
+ UPDATE_STR(model, replace, m_cover);
+ UPDATE_INT(model, replace, m_year);
+ UPDATE_INT(model, replace, m_position);
}
-const QString &AudioFileModel::fileGenre(void) const
+AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
{
- return m_fileGenre;
+ /*nothing to do*/
}
-const QString &AudioFileModel::fileComment(void) const
+void AudioFileModel_MetaInfo::reset(void)
{
- return m_fileComment;
+ m_titel.clear();
+ m_artist.clear();
+ m_album.clear();
+ m_genre.clear();
+ m_comment.clear();
+ m_cover.clear();
+ m_year = 0;
+ m_position = 0;
}
-unsigned int AudioFileModel::fileYear(void) const
+void AudioFileModel_MetaInfo::print(void) const
{
- return m_fileYear;
+ PRINT_S(m_titel);
+ PRINT_S(m_artist);
+ PRINT_S(m_album);
+ PRINT_S(m_genre);
+ PRINT_S(m_comment);
+ PRINT_S(m_cover.filePath());
+ PRINT_U(m_year);
+ PRINT_U(m_position);
}
-unsigned int AudioFileModel::filePosition(void) const
+///////////////////////////////////////////////////////////////////////////////
+// Audio File - Technical Info
+///////////////////////////////////////////////////////////////////////////////
+
+AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
{
- return m_filePosition;
+ reset();
}
-unsigned int AudioFileModel::fileDuration(void) const
+AudioFileModel_TechInfo::AudioFileModel_TechInfo(const AudioFileModel_TechInfo &model)
{
- return m_fileDuration;
+ ASSIGN_VAL(model, m_containerType);
+ ASSIGN_VAL(model, m_containerProfile);
+ ASSIGN_VAL(model, m_audioType);
+ ASSIGN_VAL(model, m_audioProfile);
+ ASSIGN_VAL(model, m_audioVersion);
+ ASSIGN_VAL(model, m_audioEncodeLib);
+ ASSIGN_VAL(model, m_audioSamplerate);
+ ASSIGN_VAL(model, m_audioChannels);
+ ASSIGN_VAL(model, m_audioBitdepth);
+ ASSIGN_VAL(model, m_audioBitrate);
+ ASSIGN_VAL(model, m_audioBitrateMode);
+ ASSIGN_VAL(model, m_duration);
}
-const QString &AudioFileModel::formatContainerType(void) const
+AudioFileModel_TechInfo &AudioFileModel_TechInfo::operator=(const AudioFileModel_TechInfo &model)
{
- return m_formatContainerType;
+ ASSIGN_VAL(model, m_containerType);
+ ASSIGN_VAL(model, m_containerProfile);
+ ASSIGN_VAL(model, m_audioType);
+ ASSIGN_VAL(model, m_audioProfile);
+ ASSIGN_VAL(model, m_audioVersion);
+ ASSIGN_VAL(model, m_audioEncodeLib);
+ ASSIGN_VAL(model, m_audioSamplerate);
+ ASSIGN_VAL(model, m_audioChannels);
+ ASSIGN_VAL(model, m_audioBitdepth);
+ ASSIGN_VAL(model, m_audioBitrate);
+ ASSIGN_VAL(model, m_audioBitrateMode);
+ ASSIGN_VAL(model, m_duration);
+
+ return (*this);
}
-const QString &AudioFileModel::formatContainerProfile(void) const
+AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
{
- return m_formatContainerProfile;
+ /*nothing to do*/
}
-const QString &AudioFileModel::formatAudioType(void) const
+void AudioFileModel_TechInfo::reset(void)
{
- return m_formatAudioType;
+ 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;
}
-const QString &AudioFileModel::formatAudioProfile(void) const
+////////////////////////////////////////////////////////////
+// Audio File Model
+////////////////////////////////////////////////////////////
+
+AudioFileModel::AudioFileModel(const QString &path)
+:
+ m_filePath(path)
{
- return m_formatAudioProfile;
+ m_metaInfo.reset();
+ m_techInfo.reset();
}
-const QString &AudioFileModel::formatAudioVersion(void) const
+AudioFileModel::AudioFileModel(const AudioFileModel &model)
{
- return m_formatAudioVersion;
+ ASSIGN_VAL(model, m_filePath);
+ ASSIGN_VAL(model, m_metaInfo);
+ ASSIGN_VAL(model, m_techInfo);
}
-unsigned int AudioFileModel::formatAudioSamplerate(void) const
+AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
{
- return m_formatAudioSamplerate;
+ ASSIGN_VAL(model, m_filePath);
+ ASSIGN_VAL(model, m_metaInfo);
+ ASSIGN_VAL(model, m_techInfo);
+
+ return (*this);
}
-unsigned int AudioFileModel::formatAudioChannels(void) const
+AudioFileModel::~AudioFileModel(void)
{
- return m_formatAudioChannels;
+ /*nothing to do*/
}
-unsigned int AudioFileModel::formatAudioBitdepth(void) const
+
+void AudioFileModel::reset(void)
{
- return m_formatAudioBitdepth;
+ m_filePath.clear();
+ m_metaInfo.reset();
+ m_techInfo.reset();
}
-const QString AudioFileModel::fileDurationInfo(void) const
+/*------------------------------------*/
+/* Helper functions
+/*------------------------------------*/
+
+const QString AudioFileModel::durationInfo(void) const
{
- if(m_fileDuration)
+ if(m_techInfo.duration())
{
- QTime time = QTime().addSecs(m_fileDuration);
+ QTime time = QTime().addSecs(m_techInfo.duration());
return time.toString("hh:mm:ss");
}
else
}
}
-const QString AudioFileModel::formatContainerInfo(void) const
+const QString AudioFileModel::containerInfo(void) const
{
- if(!m_formatContainerType.isEmpty())
+ if(!m_techInfo.containerType().isEmpty())
{
- QString info = m_formatContainerType;
- if(!m_formatContainerProfile.isEmpty()) info.append(" (Profile: ").append(m_formatContainerProfile).append(")");
+ QString info = m_techInfo.containerType();
+ if(!m_techInfo.containerProfile().isEmpty()) info.append(QString(" (%1: %2)").arg(tr("Profile"), m_techInfo.containerProfile()));
return info;
}
else
}
}
-const QString AudioFileModel::formatAudioBaseInfo(void) const
+const QString AudioFileModel::audioBaseInfo(void) const
{
- if(m_formatAudioSamplerate || m_formatAudioChannels || m_formatAudioBitdepth)
+ if(m_techInfo.audioSamplerate() || m_techInfo.audioChannels() || m_techInfo.audioBitdepth())
{
QString info;
- if(m_formatAudioChannels)
+ if(m_techInfo.audioChannels())
{
if(!info.isEmpty()) info.append(", ");
- info.append("Channels: ").append(QString::number(m_formatAudioChannels));
+ info.append(QString("%1: %2").arg(tr("Channels"), QString::number(m_techInfo.audioChannels())));
}
- if(m_formatAudioSamplerate)
+ if(m_techInfo.audioSamplerate())
{
if(!info.isEmpty()) info.append(", ");
- info.append("Samplerate: ").append(QString::number(m_formatAudioSamplerate)).append(" Hz");
+ info.append(QString("%1: %2 Hz").arg(tr("Samplerate"), QString::number(m_techInfo.audioSamplerate())));
}
- if(m_formatAudioBitdepth)
+ if(m_techInfo.audioBitdepth())
{
if(!info.isEmpty()) info.append(", ");
- info.append("Bitdepth: ").append(QString::number(m_formatAudioBitdepth)).append(" Bit");
+ 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())));
+ }
}
return info;
}
}
}
-const QString AudioFileModel::formatAudioCompressInfo(void) const
+const QString AudioFileModel::audioCompressInfo(void) const
{
- if(!m_formatAudioType.isEmpty())
+ if(!m_techInfo.audioType().isEmpty())
{
QString info;
- if(!m_formatAudioProfile.isEmpty() || !m_formatAudioVersion.isEmpty())
+ if(!m_techInfo.audioProfile().isEmpty() || !m_techInfo.audioVersion().isEmpty())
{
- info.append("Type: ");
+ info.append(QString("%1: ").arg(tr("Type")));
}
- info.append(m_formatAudioType);
- if(!m_formatAudioProfile.isEmpty())
+ info.append(m_techInfo.audioType());
+ if(!m_techInfo.audioProfile().isEmpty())
{
- info.append(", Profile: ").append(m_formatAudioProfile);
+ info.append(QString(", %1: %2").arg(tr("Profile"), m_techInfo.audioProfile()));
}
- if(!m_formatAudioVersion.isEmpty())
+ if(!m_techInfo.audioVersion().isEmpty())
{
- info.append(", Version: ").append(m_formatAudioVersion);
+ info.append(QString(", %1: %2").arg(tr("Version"), m_techInfo.audioVersion()));
+ }
+ 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(MUTILS_QSTR(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()));
}
return info;
}
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;
-}