OSDN Git Service

Updated Monkey's Audio binary to v4.11 (2013-01-20), including STDERR flush fix.
[lamexp/LameXP.git] / src / Thread_FileAnalyzer_Task.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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 #include <QSemaphore>
30
31 class AudioFileModel;
32 class QFile;
33 class QDir;
34 class QFileInfo;
35 class LockedFile;
36
37 ////////////////////////////////////////////////////////////
38 // Splash Thread
39 ////////////////////////////////////////////////////////////
40
41 class AnalyzeTask: public QObject, public QRunnable
42 {
43         Q_OBJECT
44
45 public:
46         AnalyzeTask(const QString &inputFile, const QString &templateFile, volatile bool *abortFlag);
47         ~AnalyzeTask(void);
48         
49         static void reset(void);
50         static int getAdditionalFiles(QStringList &fileList);
51         static unsigned int filesAccepted(void);
52         static unsigned int filesRejected(void);
53         static unsigned int filesDenied(void);
54         static unsigned int filesDummyCDDA(void);
55         static unsigned int filesCueSheet(void);
56
57         //Wait until there is a free slot in the queue
58         static bool waitForFreeSlot(volatile bool *abortFlag);
59
60 signals:
61         void fileSelected(const QString &fileName);
62         void fileAnalyzed(const AudioFileModel &file);
63         void progressValChanged(unsigned int);
64         void progressMaxChanged(unsigned int);
65
66 protected:
67         void run(void);
68         void run_ex(void);
69
70 private:
71         enum cover_t
72         {
73                 coverNone,
74                 coverJpeg,
75                 coverPng,
76                 coverGif
77         };
78         enum fileType_t
79         {
80                 fileTypeNormal = 0,
81                 fileTypeCDDA = 1,
82                 fileTypeDenied = 2,
83                 fileTypeSkip = 3
84         };
85
86         const AudioFileModel analyzeFile(const QString &filePath, int *type);
87         void updateInfo(AudioFileModel &audioFile, bool *skipNext, unsigned int *id_val, cover_t *coverType, QByteArray *coverData, const QString &key, const QString &value);
88         unsigned int parseYear(const QString &str);
89         unsigned int parseDuration(const QString &str);
90         bool checkFile_CDDA(QFile &file);
91         void retrieveCover(AudioFileModel &audioFile, cover_t coverType, const QByteArray &coverData);
92         bool analyzeAvisynthFile(const QString &filePath, AudioFileModel &info);
93         void waitForPreviousThreads(void);
94
95         const unsigned __int64 m_threadIdx;
96
97         const QString m_mediaInfoBin;
98         const QString m_avs2wavBin;
99         const QString m_templateFile;
100         const QString m_inputFile;
101         
102         volatile bool *m_abortFlag;
103
104         static QMutex s_waitMutex;
105         static QWaitCondition s_waitCond;
106         static QSet<unsigned int> s_threadIdx_running;
107         static unsigned int s_threadIdx_next;
108         
109         static QSemaphore s_semaphore;
110
111         static QReadWriteLock s_lock;
112         static unsigned int s_filesAccepted;
113         static unsigned int s_filesRejected;
114         static unsigned int s_filesDenied;
115         static unsigned int s_filesDummyCDDA;
116         static unsigned int s_filesCueSheet;
117         static QSet<QString> s_recentlyAdded;
118         static QStringList s_additionalFiles;
119         
120         static unsigned __int64 makeThreadIdx(void);
121 };