OSDN Git Service

Manual: Completed the "Tutorial" section.
[lamexp/LameXP.git] / src / Thread_Process.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
10 //
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.
15 //
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.
19 //
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #pragma once
24
25 #include <QRunnable>
26 #include <QUuid>
27 #include <QStringList>
28
29 #include "Model_AudioFile.h"
30 #include "Encoder_Abstract.h"
31
32 class AbstractFilter;
33 class WaveProperties;
34 class QThreadPool;
35 class QCoreApplication;
36
37 class ProcessThread: public QObject, public QRunnable
38 {
39         Q_OBJECT
40
41 public:
42         ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, const QString &tempDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath);
43         ~ProcessThread(void);
44         
45         bool init(void);
46         bool start(QThreadPool *pool);
47         
48         QUuid getId(void) { return m_jobId; }
49         void setRenamePattern(const QString &pattern);
50         void setOverwriteMode(const bool &bSkipExistingFile, const bool &bReplacesExisting = false);
51         void addFilter(AbstractFilter *filter);
52
53 public slots:
54         void abort(void) { m_aborted = true; }
55
56 private slots:
57         void handleUpdate(int progress);
58         void handleMessage(const QString &line);
59
60 signals:
61         void processStateInitialized(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState);
62         void processStateChanged(const QUuid &jobId, const QString &newStatus, int newState);
63         void processStateFinished(const QUuid &jobId, const QString &outFileName, int success);
64         void processMessageLogged(const QUuid &jobId, const QString &line);
65         void processFinished(void);
66
67 protected:
68         virtual void run(void);
69
70 private:
71         enum ProcessStep
72         {
73                 DecodingStep = 0,
74                 AnalyzeStep = 1,
75                 FilteringStep = 2,
76                 EncodingStep = 3,
77                 UnknownStep = 4
78         };
79
80         enum OverwriteMode
81         {
82                 OverwriteMode_KeepBoth     = 0,
83                 OverwriteMode_SkipExisting = 1,
84                 OverwriteMode_Overwrite    = 2,
85         };
86         
87         void processFile();
88         int generateOutFileName(QString &outFileName);
89         QString applyRenamePattern(const QString &baseName, const AudioFileModel_MetaInfo &metaInfo);
90         QString generateTempFileName(void);
91         void insertDownmixFilter(void);
92         void insertDownsampleFilter(void);
93
94         volatile bool m_aborted;
95         volatile int m_initialized;
96
97         const QUuid m_jobId;
98         AudioFileModel m_audioFile;
99         AbstractEncoder *m_encoder;
100         const QString m_outputDirectory;
101         const QString m_tempDirectory;
102         ProcessStep m_currentStep;
103         QStringList m_tempFiles;
104         const bool m_prependRelativeSourcePath;
105         QList<AbstractFilter*> m_filters;
106         QString m_renamePattern;
107         int m_overwriteMode;
108         WaveProperties *m_propDetect;
109         QString m_outFileName;
110 };