2010-11-18 00:32:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2017-03-12 12:12:49 +01:00
|
|
|
// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-18 00:32:46 +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
|
2013-10-23 20:56:57 +02:00
|
|
|
// (at your option) any later version, but always including the *additional*
|
|
|
|
// restrictions defined in the "License.txt" file.
|
2010-11-18 00:32:46 +01:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-10-09 03:14:38 +02:00
|
|
|
#include <QRunnable>
|
2010-11-18 22:37:35 +01:00
|
|
|
#include <QUuid>
|
2010-12-01 23:14:47 +01:00
|
|
|
#include <QStringList>
|
2010-11-18 00:32:46 +01:00
|
|
|
|
2010-11-19 21:11:54 +01:00
|
|
|
#include "Model_AudioFile.h"
|
2010-11-20 02:14:22 +01:00
|
|
|
#include "Encoder_Abstract.h"
|
2010-11-19 21:11:54 +01:00
|
|
|
|
2011-01-25 23:12:56 +01:00
|
|
|
class AbstractFilter;
|
2011-12-22 00:06:34 +01:00
|
|
|
class WaveProperties;
|
2013-10-09 16:11:58 +02:00
|
|
|
class QThreadPool;
|
|
|
|
class QCoreApplication;
|
2010-11-20 22:14:10 +01:00
|
|
|
|
2013-10-09 03:14:38 +02:00
|
|
|
class ProcessThread: public QObject, public QRunnable
|
2010-11-18 00:32:46 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2011-02-25 22:03:39 +01:00
|
|
|
ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, const QString &tempDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath);
|
2010-11-18 00:32:46 +01:00
|
|
|
~ProcessThread(void);
|
2010-11-26 00:29:53 +01:00
|
|
|
|
2013-10-11 20:43:31 +02:00
|
|
|
bool init(void);
|
2015-05-10 19:52:07 +02:00
|
|
|
bool start(QThreadPool *const pool);
|
2010-11-26 00:29:53 +01:00
|
|
|
|
2013-10-09 03:14:38 +02:00
|
|
|
QUuid getId(void) { return m_jobId; }
|
2011-08-04 23:26:38 +02:00
|
|
|
void setRenamePattern(const QString &pattern);
|
2015-05-09 23:33:07 +02:00
|
|
|
void setRenameRegExp(const QString &search, const QString &replace);
|
2015-05-10 19:52:07 +02:00
|
|
|
void setRenameFileExt(const QString &fileExtension);
|
2014-05-30 16:52:34 +02:00
|
|
|
void setOverwriteMode(const bool &bSkipExistingFile, const bool &bReplacesExisting = false);
|
2015-11-07 21:39:33 +01:00
|
|
|
void setKeepDateTime(const bool &keepDateTime);
|
2011-01-25 23:12:56 +01:00
|
|
|
void addFilter(AbstractFilter *filter);
|
2010-11-18 00:32:46 +01:00
|
|
|
|
2013-10-09 03:14:38 +02:00
|
|
|
public slots:
|
2017-04-18 21:05:28 +02:00
|
|
|
void abort(void) { m_aborted.ref(); }
|
2013-10-09 03:14:38 +02:00
|
|
|
|
2010-11-20 02:14:22 +01:00
|
|
|
private slots:
|
|
|
|
void handleUpdate(int progress);
|
2010-11-22 21:45:00 +01:00
|
|
|
void handleMessage(const QString &line);
|
2010-11-20 02:14:22 +01:00
|
|
|
|
2010-11-18 00:32:46 +01:00
|
|
|
signals:
|
2010-11-18 22:37:35 +01:00
|
|
|
void processStateInitialized(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState);
|
|
|
|
void processStateChanged(const QUuid &jobId, const QString &newStatus, int newState);
|
2012-11-11 18:33:55 +01:00
|
|
|
void processStateFinished(const QUuid &jobId, const QString &outFileName, int success);
|
2010-11-22 21:45:00 +01:00
|
|
|
void processMessageLogged(const QUuid &jobId, const QString &line);
|
2013-10-09 03:14:38 +02:00
|
|
|
void processFinished(void);
|
2010-11-18 00:32:46 +01:00
|
|
|
|
2013-10-09 16:11:58 +02:00
|
|
|
protected:
|
|
|
|
virtual void run(void);
|
|
|
|
|
2010-11-18 00:32:46 +01:00
|
|
|
private:
|
2010-12-01 23:14:47 +01:00
|
|
|
enum ProcessStep
|
|
|
|
{
|
|
|
|
DecodingStep = 0,
|
2011-12-22 00:06:34 +01:00
|
|
|
AnalyzeStep = 1,
|
|
|
|
FilteringStep = 2,
|
|
|
|
EncodingStep = 3,
|
|
|
|
UnknownStep = 4
|
2010-12-01 23:14:47 +01:00
|
|
|
};
|
2014-05-30 16:52:34 +02:00
|
|
|
|
|
|
|
enum OverwriteMode
|
|
|
|
{
|
|
|
|
OverwriteMode_KeepBoth = 0,
|
|
|
|
OverwriteMode_SkipExisting = 1,
|
|
|
|
OverwriteMode_Overwrite = 2,
|
|
|
|
};
|
2010-12-01 23:14:47 +01:00
|
|
|
|
2010-11-26 00:29:53 +01:00
|
|
|
void processFile();
|
2012-11-08 21:19:45 +01:00
|
|
|
int generateOutFileName(QString &outFileName);
|
2013-10-12 22:55:41 +02:00
|
|
|
QString applyRenamePattern(const QString &baseName, const AudioFileModel_MetaInfo &metaInfo);
|
2017-03-12 21:14:56 +01:00
|
|
|
QString applyRegularExpression(const QString &baseName);
|
2010-12-01 23:14:47 +01:00
|
|
|
QString generateTempFileName(void);
|
2016-11-12 16:06:04 +01:00
|
|
|
bool insertDownmixFilter(const unsigned int *const supportedChannels);
|
|
|
|
bool insertDownsampleFilter(const unsigned int *const supportedSamplerates, const unsigned int *const supportedBitdepths);
|
2015-10-25 16:19:45 +01:00
|
|
|
bool updateFileTime(const QString &originalFile, const QString &modifiedFile);
|
2013-10-09 16:11:58 +02:00
|
|
|
|
2017-04-18 21:05:28 +02:00
|
|
|
QAtomicInt m_aborted;
|
|
|
|
QAtomicInt m_initialized;
|
2013-10-09 16:11:58 +02:00
|
|
|
|
2010-11-18 22:37:35 +01:00
|
|
|
const QUuid m_jobId;
|
2010-11-19 21:11:54 +01:00
|
|
|
AudioFileModel m_audioFile;
|
2010-11-20 02:14:22 +01:00
|
|
|
AbstractEncoder *m_encoder;
|
|
|
|
const QString m_outputDirectory;
|
2011-02-25 22:03:39 +01:00
|
|
|
const QString m_tempDirectory;
|
2010-12-01 23:14:47 +01:00
|
|
|
ProcessStep m_currentStep;
|
|
|
|
QStringList m_tempFiles;
|
2010-12-14 01:25:13 +01:00
|
|
|
const bool m_prependRelativeSourcePath;
|
2011-01-25 23:12:56 +01:00
|
|
|
QList<AbstractFilter*> m_filters;
|
2011-08-04 23:26:38 +02:00
|
|
|
QString m_renamePattern;
|
2015-05-09 23:33:07 +02:00
|
|
|
QString m_renameRegExp_Search;
|
|
|
|
QString m_renameRegExp_Replace;
|
2015-05-10 19:52:07 +02:00
|
|
|
QString m_renameFileExt;
|
2014-05-30 16:52:34 +02:00
|
|
|
int m_overwriteMode;
|
2015-11-07 21:39:33 +01:00
|
|
|
bool m_keepDateTime;
|
2011-12-22 00:06:34 +01:00
|
|
|
WaveProperties *m_propDetect;
|
2013-10-09 16:11:58 +02:00
|
|
|
QString m_outFileName;
|
2010-11-18 00:32:46 +01:00
|
|
|
};
|