///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2020 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
+// 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; always including the non-optional
+// LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "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>
-#include <limits.h>
-#define U16Str(X) QString::fromUtf16(reinterpret_cast<const unsigned short*>(L##X))
+//CRT
+#include <limits.h>
const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1;
-////////////////////////////////////////////////////////////
-// Constructor & Destructor
-////////////////////////////////////////////////////////////
+#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)
-AudioFileModel::AudioFileModel(const QString &path, const QString &name)
-{
- resetAll();
+///////////////////////////////////////////////////////////////////////////////
+// Audio File - Meta Info
+///////////////////////////////////////////////////////////////////////////////
- m_filePath = path;
- m_fileName = name;
+AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
+{
+ reset();
}
-AudioFileModel::AudioFileModel(const AudioFileModel &model, bool copyMetaInfo)
+AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo &model)
{
- resetAll();
-
- setFilePath(model.m_filePath);
- setFormatContainerType(model.m_formatContainerType);
- setFormatContainerProfile(model.m_formatContainerProfile);
- setFormatAudioType(model.m_formatAudioType);
- setFormatAudioProfile(model.m_formatAudioProfile);
- setFormatAudioVersion(model.m_formatAudioVersion);
- setFormatAudioEncodeLib(model.m_formatAudioEncodeLib);
- setFormatAudioSamplerate(model.m_formatAudioSamplerate);
- setFormatAudioChannels(model.m_formatAudioChannels);
- setFormatAudioBitdepth(model.m_formatAudioBitdepth);
- setFormatAudioBitrate(model.m_formatAudioBitrate);
- setFormatAudioBitrateMode(model.m_formatAudioBitrateMode);
- 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);
- setFileCover(model.m_fileCover);
- setFileYear(model.m_fileYear);
- setFilePosition(model.m_filePosition);
- }
+ 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);
}
-AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
+AudioFileModel_MetaInfo &AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo &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);
- setFileCover(model.m_fileCover);
- 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);
- setFormatAudioEncodeLib(model.m_formatAudioEncodeLib);
- setFormatAudioSamplerate(model.m_formatAudioSamplerate);
- setFormatAudioChannels(model.m_formatAudioChannels);
- setFormatAudioBitdepth(model.m_formatAudioBitdepth);
- setFormatAudioBitrate(model.m_formatAudioBitrate);
- setFormatAudioBitrateMode(model.m_formatAudioBitrateMode);
+ 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);
return (*this);
}
-AudioFileModel::~AudioFileModel(void)
-{
-}
+#define IS_EMPTY(X) ((X).isEmpty() ? "YES" : "NO")
-////////////////////////////////////////////////////////////
-// Private Functions
-////////////////////////////////////////////////////////////
-
-void AudioFileModel::resetAll(void)
+void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model, const bool replace)
{
- m_filePath.clear();
- m_fileName.clear();
- m_fileArtist.clear();
- m_fileAlbum.clear();
- m_fileGenre.clear();
- m_fileComment.clear();
- m_fileCover.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_formatAudioEncodeLib.clear();
-
- m_formatAudioSamplerate = 0;
- m_formatAudioChannels = 0;
- m_formatAudioBitdepth = 0;
- m_formatAudioBitrate = 0;
- m_formatAudioBitrateMode = BitrateModeUndefined;
+ 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);
}
-////////////////////////////////////////////////////////////
-// Public Functions
-////////////////////////////////////////////////////////////
-
-// ---------------------------------
-// Getter methods
-// ---------------------------------
-
-const QString &AudioFileModel::filePath(void) const
+AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
{
- return m_filePath;
+ /*nothing to do*/
}
-const QString &AudioFileModel::fileName(void) const
+void AudioFileModel_MetaInfo::reset(void)
{
- return m_fileName;
+ m_titel.clear();
+ m_artist.clear();
+ m_album.clear();
+ m_genre.clear();
+ m_comment.clear();
+ m_cover.clear();
+ m_year = 0;
+ m_position = 0;
}
-const QString &AudioFileModel::fileArtist(void) const
+void AudioFileModel_MetaInfo::print(void) const
{
- return m_fileArtist;
+ 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);
}
-const QString &AudioFileModel::fileAlbum(void) const
+bool AudioFileModel_MetaInfo::empty(const bool &ignoreArtwork) const
{
- return m_fileAlbum;
-}
+ bool isEmpty = true;
-const QString &AudioFileModel::fileGenre(void) const
-{
- return m_fileGenre;
-}
+ if(!m_titel.isEmpty()) isEmpty = false;
+ if(!m_artist.isEmpty()) isEmpty = false;
+ if(!m_album.isEmpty()) isEmpty = false;
+ if(!m_genre.isEmpty()) isEmpty = false;
+ if(!m_comment.isEmpty()) isEmpty = false;
+ if(m_year) isEmpty = false;
+ if(m_position) isEmpty = false;
-const QString &AudioFileModel::fileComment(void) const
-{
- return m_fileComment;
-}
+ if(!ignoreArtwork)
+ {
+ if(!m_cover.isEmpty())
+ {
+ isEmpty = false;
+ }
+ }
-const QString &AudioFileModel::fileCover(void) const
-{
- return m_fileCover.filePath();
+ return isEmpty;
}
-unsigned int AudioFileModel::fileYear(void) const
-{
- return m_fileYear;
-}
+///////////////////////////////////////////////////////////////////////////////
+// Audio File - Technical Info
+///////////////////////////////////////////////////////////////////////////////
-unsigned int AudioFileModel::filePosition(void) const
+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);
-const QString &AudioFileModel::formatContainerProfile(void) const
-{
- return m_formatContainerProfile;
+ return (*this);
}
-const QString &AudioFileModel::formatAudioType(void) const
+AudioFileModel_TechInfo::~AudioFileModel_TechInfo(void)
{
- return m_formatAudioType;
+ /*nothing to do*/
}
-const QString &AudioFileModel::formatAudioProfile(void) const
+void AudioFileModel_TechInfo::reset(void)
{
- return m_formatAudioProfile;
+ 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::formatAudioVersion(void) const
-{
- return m_formatAudioVersion;
-}
+////////////////////////////////////////////////////////////
+// Audio File Model
+////////////////////////////////////////////////////////////
-unsigned int AudioFileModel::formatAudioSamplerate(void) const
+AudioFileModel::AudioFileModel(const QString &path)
+:
+ m_filePath(path)
{
- return m_formatAudioSamplerate;
+ m_metaInfo.reset();
+ m_techInfo.reset();
}
-unsigned int AudioFileModel::formatAudioChannels(void) const
+AudioFileModel::AudioFileModel(const AudioFileModel &model)
{
- return m_formatAudioChannels;
+ ASSIGN_VAL(model, m_filePath);
+ ASSIGN_VAL(model, m_metaInfo);
+ ASSIGN_VAL(model, m_techInfo);
}
-unsigned int AudioFileModel::formatAudioBitdepth(void) const
+AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
{
- return m_formatAudioBitdepth;
+ ASSIGN_VAL(model, m_filePath);
+ ASSIGN_VAL(model, m_metaInfo);
+ ASSIGN_VAL(model, m_techInfo);
+
+ return (*this);
}
-unsigned int AudioFileModel::formatAudioBitrate(void) const
+AudioFileModel::~AudioFileModel(void)
{
- return m_formatAudioBitrate;
+ /*nothing to do*/
}
-unsigned int AudioFileModel::formatAudioBitrateMode(void) const
+
+void AudioFileModel::reset(void)
{
- return m_formatAudioBitrateMode;
+ 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(QString(" (%1: %2)").arg(tr("Profile"), m_formatContainerProfile));
+ 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(QString("%1: %2").arg(tr("Channels"), 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(QString("%1: %2 Hz").arg(tr("Samplerate"), QString::number(m_formatAudioSamplerate)));
+ 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(", ");
- if(m_formatAudioBitdepth == BITDEPTH_IEEE_FLOAT32)
+ 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_formatAudioBitdepth)));
+ 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(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(QString(", %1: %2").arg(tr("Profile"), m_formatAudioProfile));
+ info.append(QString(", %1: %2").arg(tr("Profile"), m_techInfo.audioProfile()));
}
- if(!m_formatAudioVersion.isEmpty())
+ if(!m_techInfo.audioVersion().isEmpty())
{
- info.append(QString(", %1: %2").arg(tr("Version"), m_formatAudioVersion));
+ info.append(QString(", %1: %2").arg(tr("Version"), m_techInfo.audioVersion()));
}
- if(m_formatAudioBitrate > 0)
+ if(m_techInfo.audioBitrate() > 0)
{
- switch(m_formatAudioBitrateMode)
+ switch(m_techInfo.audioBitrateMode())
{
case BitrateModeConstant:
- info.append(U16Str(", %1: %2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_formatAudioBitrate), tr("Constant")));
+ info.append(QString(", %1: %2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Constant")));
break;
case BitrateModeVariable:
- info.append(U16Str(", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_formatAudioBitrate), tr("Variable")));
+ info.append(MUTILS_QSTR(L", %1: \u2248%2 kbps (%3)").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate()), tr("Variable")));
break;
default:
- info.append(U16Str(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_formatAudioBitrate)));
+ info.append(QString(", %1: %2 kbps").arg(tr("Bitrate"), QString::number(m_techInfo.audioBitrate())));
break;
}
}
- if(!m_formatAudioEncodeLib.isEmpty())
+ if(!m_techInfo.audioEncodeLib().isEmpty())
{
- info.append(QString(", %1: %2").arg(tr("Encoder"), m_formatAudioEncodeLib));
+ 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::setFileCover(const QString &coverFile, bool owner)
-{
- m_fileCover.setFilePath(coverFile, owner);
-}
-
-void AudioFileModel::setFileCover(const ArtworkModel &model)
-{
- m_fileCover = model;
-}
-
-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::setFormatAudioEncodeLib(const QString &encodeLib)
-{
- m_formatAudioEncodeLib = encodeLib;
-}
-
-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;
-}
-
-void AudioFileModel::setFormatAudioBitrate(unsigned int bitrate)
-{
- m_formatAudioBitrate = bitrate;
-}
-
-void AudioFileModel::setFormatAudioBitrateMode(unsigned int bitrateMode)
-{
- m_formatAudioBitrateMode = bitrateMode;
-}
-
-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());
-}