OSDN Git Service

Parallel initialization of optional AAC encoders + massive code refactoring in AAC...
[lamexp/LameXP.git] / src / Model_AudioFile.cpp
index 68f9430..23d9c5b 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 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\"", QUTF8((VAR))); \
+       if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", MUTILS_UTF8((VAR))); \
 } \
 while(0)
 
@@ -44,6 +51,32 @@ while(0)
 } \
 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)
+
 ///////////////////////////////////////////////////////////////////////////////
 // Audio File - Meta Info
 ///////////////////////////////////////////////////////////////////////////////
@@ -55,40 +88,42 @@ AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void)
 
 AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo &model)
 {
-       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;
+       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_MetaInfo &AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo &model)
 {
-       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;
+       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);
 }
 
+#define IS_EMPTY(X) ((X).isEmpty() ? "YES" : "NO")
+
 void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model, const bool replace)
 {
-       if((!model.m_titel.isEmpty())   && (replace || m_titel.isEmpty()))   m_titel    = model.m_titel;
-       if((!model.m_artist.isEmpty())  && (replace || m_artist.isEmpty()))  m_artist   = model.m_artist;
-       if((!model.m_album.isEmpty())   && (replace || m_album.isEmpty()))   m_album    = model.m_album;
-       if((!model.m_genre.isEmpty())   && (replace || m_genre.isEmpty()))   m_genre    = model.m_genre;
-       if((!model.m_comment.isEmpty()) && (replace || m_comment.isEmpty())) m_comment  = model.m_comment;
-       if((!model.m_cover.isEmpty())   && (replace || m_cover.isEmpty()))   m_cover    = model.m_cover;
-       if((model.m_year > 0)           && (replace || (m_year == 0)))       m_year     = model.m_year;
-       if((model.m_position > 0)       && (replace || (m_position == 0)))   m_position = model.m_position;
+       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);
 }
 
 AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void)
@@ -131,34 +166,34 @@ AudioFileModel_TechInfo::AudioFileModel_TechInfo(void)
 
 AudioFileModel_TechInfo::AudioFileModel_TechInfo(const AudioFileModel_TechInfo &model)
 {
-       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;
+       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);
 }
 
 AudioFileModel_TechInfo &AudioFileModel_TechInfo::operator=(const AudioFileModel_TechInfo &model)
 {
-       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;
+       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);
 }
@@ -198,16 +233,16 @@ AudioFileModel::AudioFileModel(const QString &path)
 
 AudioFileModel::AudioFileModel(const AudioFileModel &model)
 {
-       m_filePath = model.m_filePath;
-       m_metaInfo = model.m_metaInfo;
-       m_techInfo = model.m_techInfo;
+       ASSIGN_VAL(model, m_filePath);
+       ASSIGN_VAL(model, m_metaInfo);
+       ASSIGN_VAL(model, m_techInfo);
 }
 
 AudioFileModel &AudioFileModel::operator=(const AudioFileModel &model)
 {
-       m_filePath = model.m_filePath;
-       m_metaInfo = model.m_metaInfo;
-       m_techInfo = model.m_techInfo;
+       ASSIGN_VAL(model, m_filePath);
+       ASSIGN_VAL(model, m_metaInfo);
+       ASSIGN_VAL(model, m_techInfo);
 
        return (*this);
 }
@@ -317,7 +352,7 @@ const QString AudioFileModel::audioCompressInfo(void) const
                                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")));
+                               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())));