Bump version.
[LameXP.git] / src / Thread_Process.h
blob27cc0405a88b597cf682670b3e2399f2e8e8a2eb
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2021 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU GENERAL PUBLIC LICENSE as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version; always including the non-optional
9 // LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "License.txt" file!
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #pragma once
25 #include <QRunnable>
26 #include <QUuid>
27 #include <QStringList>
29 #include "Model_AudioFile.h"
30 #include "Encoder_Abstract.h"
32 class AbstractFilter;
33 class WaveProperties;
34 class QThreadPool;
35 class QCoreApplication;
37 class ProcessThread: public QObject, public QRunnable
39 Q_OBJECT
41 public:
42 ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, const QString &tempDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath);
43 ~ProcessThread(void);
45 bool init(void);
46 bool start(QThreadPool *const pool);
48 QUuid getId(void) { return m_jobId; }
49 void setRenamePattern(const QString &pattern);
50 void setRenameRegExp(const QString &search, const QString &replace);
51 void setRenameFileExt(const QString &fileExtension);
52 void setOverwriteMode(const bool &bSkipExistingFile, const bool &bReplacesExisting = false);
53 void setKeepDateTime(const bool &keepDateTime);
54 void addFilter(AbstractFilter *filter);
56 public slots:
57 void abort(void) { m_aborted.ref(); }
59 private slots:
60 void handleUpdate(int progress);
61 void handleMessage(const QString &line);
63 signals:
64 void processStateInitialized(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState);
65 void processStateChanged(const QUuid &jobId, const QString &newStatus, int newState);
66 void processStateFinished(const QUuid &jobId, const QString &outFileName, int success);
67 void processMessageLogged(const QUuid &jobId, const QString &line);
68 void processFinished(void);
70 protected:
71 virtual void run(void);
73 private:
74 enum ProcessStep
76 DecodingStep = 0,
77 AnalyzeStep = 1,
78 FilteringStep = 2,
79 EncodingStep = 3,
80 UnknownStep = 4
83 enum OverwriteMode
85 OverwriteMode_KeepBoth = 0,
86 OverwriteMode_SkipExisting = 1,
87 OverwriteMode_Overwrite = 2,
90 void processFile();
91 int generateOutFileName(QString &outFileName);
92 QString applyRenamePattern(const QString &baseName, const AudioFileModel_MetaInfo &metaInfo);
93 QString applyRegularExpression(const QString &baseName);
94 QString generateTempFileName(void);
95 bool insertDownmixFilter(const unsigned int *const supportedChannels);
96 bool insertDownsampleFilter(const unsigned int *const supportedSamplerates, const unsigned int *const supportedBitdepths);
97 bool updateFileTime(const QString &originalFile, const QString &modifiedFile);
99 QAtomicInt m_aborted;
100 QAtomicInt m_initialized;
102 const QUuid m_jobId;
103 AudioFileModel m_audioFile;
104 AbstractEncoder *m_encoder;
105 const QString m_outputDirectory;
106 const QString m_tempDirectory;
107 ProcessStep m_currentStep;
108 QStringList m_tempFiles;
109 const bool m_prependRelativeSourcePath;
110 QList<AbstractFilter*> m_filters;
111 QString m_renamePattern;
112 QString m_renameRegExp_Search;
113 QString m_renameRegExp_Replace;
114 QString m_renameFileExt;
115 int m_overwriteMode;
116 bool m_keepDateTime;
117 WaveProperties *m_propDetect;
118 QString m_outFileName;