///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2015 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, but always including the *additional*
-// restrictions defined in the "License.txt" file.
+// (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
:
m_tasksCounterNext(0),
m_tasksCounterDone(0),
- m_inputFiles(inputFiles),
- m_templateFile(NULL),
- m_pool(NULL)
+ m_inputFiles(inputFiles)
{
- m_bSuccess = false;
- m_bAborted = false;
-
m_filesAccepted = 0;
m_filesRejected = 0;
m_filesDenied = 0;
m_filesCueSheet = 0;
moveToThread(this); /*makes sure queued slots are executed in the proper thread context*/
-
- m_timer = new QElapsedTimer;
+ m_timer.reset(new QElapsedTimer());
}
FileAnalyzer::~FileAnalyzer(void)
{
- if(m_pool)
+ if(!m_pool.isNull())
{
if(!m_pool->waitForDone(2500))
{
qWarning("There are still running tasks in the thread pool!");
}
}
-
- MUTILS_DELETE(m_templateFile);
- MUTILS_DELETE(m_pool);
- MUTILS_DELETE(m_timer);
}
////////////////////////////////////////////////////////////
-// Static data
-////////////////////////////////////////////////////////////
-
-const char *FileAnalyzer::g_tags_gen[] =
-{
- "ID",
- "Format",
- "Format_Profile",
- "Format_Version",
- "Duration",
- "Title", "Track",
- "Track/Position",
- "Artist", "Performer",
- "Album",
- "Genre",
- "Released_Date", "Recorded_Date",
- "Comment",
- "Cover",
- "Cover_Type",
- "Cover_Mime",
- "Cover_Data",
- NULL
-};
-
-const char *FileAnalyzer::g_tags_aud[] =
-{
- "ID",
- "Source",
- "Format",
- "Format_Profile",
- "Format_Version",
- "Channel(s)",
- "SamplingRate",
- "BitDepth",
- "BitRate",
- "BitRate_Mode",
- "Encoded_Library",
- NULL
-};
-
-////////////////////////////////////////////////////////////
// Thread Main
////////////////////////////////////////////////////////////
void FileAnalyzer::run()
{
- m_bSuccess = false;
+ m_bSuccess.fetchAndStoreOrdered(0);
m_tasksCounterNext = 0;
m_tasksCounterDone = 0;
m_timer->invalidate();
- //Create MediaInfo template file
- if(!m_templateFile)
- {
- if(!createTemplate())
- {
- qWarning("Failed to create template file!");
- return;
- }
- }
-
//Sort files
MUtils::natural_string_sort(m_inputFiles, true);
emit progressMaxChanged(nFiles);
emit progressValChanged(0);
- //Create thread pool
- if(!m_pool) m_pool = new QThreadPool();
+ //Create the thread pool
+ if (m_pool.isNull())
+ {
+ m_pool.reset(new QThreadPool());
+ }
+
+ //Update thread count
const int idealThreadCount = QThread::idealThreadCount();
if(idealThreadCount > 0)
{
m_pool->waitForDone();
//Was opertaion aborted?
- if(m_bAborted)
+ if(MUTILS_BOOLIFY(m_bAborted))
{
qWarning("Operation cancelled by user!");
return;
}
qDebug("All files added.\n");
- m_bSuccess = true;
-
+ m_bSuccess.fetchAndStoreOrdered(1);
QThread::msleep(333);
}
bool FileAnalyzer::analyzeNextFile(void)
{
- if(!(m_inputFiles.isEmpty() || m_bAborted))
+ if(!(m_inputFiles.isEmpty() || MUTILS_BOOLIFY(m_bAborted)))
{
const unsigned int taskId = m_tasksCounterNext++;
const QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst());
m_timer->restart();
}
- AnalyzeTask *task = new AnalyzeTask(taskId, currentFile, m_templateFile->filePath(), &m_bAborted);
+ AnalyzeTask *task = new AnalyzeTask(taskId, currentFile, m_bAborted);
connect(task, SIGNAL(fileAnalyzed(const unsigned int, const int, AudioFileModel)), this, SLOT(taskFileAnalyzed(unsigned int, const int, AudioFileModel)), Qt::QueuedConnection);
connect(task, SIGNAL(taskCompleted(const unsigned int)), this, SLOT(taskThreadFinish(const unsigned int)), Qt::QueuedConnection);
m_runningTaskIds.insert(taskId); m_pool->start(task);
}
}
-bool FileAnalyzer::createTemplate(void)
-{
- if(m_templateFile)
- {
- qWarning("Template file already exists!");
- return true;
- }
-
- QString templatePath = QString("%1/%2.txt").arg(MUtils::temp_folder(), MUtils::rand_str());
-
- QFile templateFile(templatePath);
- if(!templateFile.open(QIODevice::WriteOnly))
- {
- return false;
- }
-
- templateFile.write("General;");
- for(size_t i = 0; g_tags_gen[i]; i++)
- {
- templateFile.write(QString("Gen_%1=%%1%\\n").arg(g_tags_gen[i]).toLatin1().constData());
- }
- templateFile.write("\\n\r\n");
-
- templateFile.write("Audio;");
- for(size_t i = 0; g_tags_aud[i]; i++)
- {
- templateFile.write(QString("Aud_%1=%%1%\\n").arg(g_tags_aud[i]).toLatin1().constData());
- }
- templateFile.write("\\n\r\n");
-
- bool success = (templateFile.error() == QFile::NoError);
- templateFile.close();
-
- if(!success)
- {
- QFile::remove(templatePath);
- return false;
- }
-
- try
- {
- m_templateFile = new LockedFile(templatePath, true);
- }
- catch(const std::exception &error)
- {
- qWarning("Failed to lock template file:\n%s\n", error.what());
- return false;
- }
- catch(...)
- {
- qWarning("Failed to lock template file!");
- return false;
- }
-
- return true;
-}
-
////////////////////////////////////////////////////////////
// Slot Functions
////////////////////////////////////////////////////////////