OSDN Git Service

Implemented a method to disables update signals from the FileList model. This will...
[lamexp/LameXP.git] / src / Thread_FileAnalyzer_Task.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include <QRunnable>
25 #include <QReadWriteLock>
26 #include <QWaitCondition>
27 #include <QStringList>
28 #include <QMutex>
29
30 class AudioFileModel;
31 class QFile;
32 class QDir;
33 class QFileInfo;
34 class LockedFile;
35
36 ////////////////////////////////////////////////////////////
37 // Splash Thread
38 ////////////////////////////////////////////////////////////
39
40 class AnalyzeTask: public QObject, public QRunnable
41 {
42         Q_OBJECT
43
44 public:
45         AnalyzeTask(const QString &inputFile, const QString &templateFile, volatile bool *abortFlag);
46         ~AnalyzeTask(void);
47         
48         static void reset(void);
49         static void getAdditionalFiles(QStringList &fileList);
50         static unsigned int filesAccepted(void);
51         static unsigned int filesRejected(void);
52         static unsigned int filesDenied(void);
53         static unsigned int filesDummyCDDA(void);
54         static unsigned int filesCueSheet(void);
55
56         //Wait till the next running thread terminates
57         static __forceinline bool waitForOneThread(unsigned long timeout)
58         {
59                 bool ret = false;
60                 s_waitMutex.lock();
61                 ret = s_waitCond.wait(&s_waitMutex, timeout);
62                 s_waitMutex.unlock();
63                 return ret;
64         }
65
66 signals:
67         void fileSelected(const QString &fileName);
68         void fileAnalyzed(const AudioFileModel &file);
69
70 protected:
71         void run(void);
72         void run_ex(void);
73
74 private:
75         enum cover_t
76         {
77                 coverNone,
78                 coverJpeg,
79                 coverPng,
80                 coverGif
81         };
82         enum fileType_t
83         {
84                 fileTypeNormal = 0,
85                 fileTypeCDDA = 1,
86                 fileTypeDenied = 2,
87                 fileTypeSkip = 3
88         };
89
90         const AudioFileModel analyzeFile(const QString &filePath, int *type);
91         void updateInfo(AudioFileModel &audioFile, bool *skipNext, unsigned int *id_val, cover_t *coverType, QByteArray *coverData, const QString &key, const QString &value);
92         unsigned int parseYear(const QString &str);
93         unsigned int parseDuration(const QString &str);
94         bool checkFile_CDDA(QFile &file);
95         void retrieveCover(AudioFileModel &audioFile, cover_t coverType, const QByteArray &coverData);
96         bool analyzeAvisynthFile(const QString &filePath, AudioFileModel &info);
97         void waitForPreviousThreads(void);
98
99         const unsigned __int64 m_threadIdx;
100
101         const QString m_mediaInfoBin;
102         const QString m_avs2wavBin;
103         const QString m_templateFile;
104         const QString m_inputFile;
105         
106         volatile bool *m_abortFlag;
107
108         static QReadWriteLock s_lock;
109         static QMutex s_waitMutex;
110         static QWaitCondition s_waitCond;
111         
112         static unsigned __int64 s_threadIdx_created;
113         static unsigned __int64 s_threadIdx_finished;
114
115         static QStringList s_recentlyAdded;
116         static QStringList s_additionalFiles;
117         
118         static unsigned int s_filesAccepted;
119         static unsigned int s_filesRejected;
120         static unsigned int s_filesDenied;
121         static unsigned int s_filesDummyCDDA;
122         static unsigned int s_filesCueSheet;
123         
124         static unsigned __int64 makeThreadIdx(void);
125 };