OSDN Git Service

Parallel initialization of optional AAC encoders + massive code refactoring in AAC...
[lamexp/LameXP.git] / src / Thread_CueSplitter.cpp
index fb5e32e..a219b36 100644 (file)
@@ -1,11 +1,12 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // 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
-// (at your option) any later version.
+// (at your option) any later version, but always including the *additional*
+// restrictions defined in the "License.txt" file.
 //
 // This program is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,6 +22,7 @@
 
 #include "Thread_CueSplitter.h"
 
+//Internal
 #include "Global.h"
 #include "LockedFile.h"
 #include "Model_AudioFile.h"
 #include "Registry_Decoder.h"
 #include "Decoder_Abstract.h"
 
+//MUtils
+#include <MUtils/Global.h>
+#include <MUtils/OSSupport.h>
+
+//Qt
 #include <QDir>
 #include <QFileInfo>
 #include <QProcess>
@@ -35,6 +42,7 @@
 #include <QTime>
 #include <QDebug>
 
+//CRT
 #include <math.h>
 #include <float.h>
 #include <limits>
@@ -48,7 +56,7 @@ CueSplitter::CueSplitter(const QString &outputDir, const QString &baseName, CueS
        m_model(model),
        m_outputDir(outputDir),
        m_baseName(baseName),
-       m_soxBin(lamexp_lookup_tool("sox.exe"))
+       m_soxBin(lamexp_tools_lookup("sox.exe"))
 {
        if(m_soxBin.isEmpty())
        {
@@ -64,7 +72,7 @@ CueSplitter::CueSplitter(const QString &outputDir, const QString &baseName, CueS
        for(int i = 0; i < nInputFiles; i++)
        {
                m_inputFilesInfo.insert(inputFilesInfo[i].filePath(), inputFilesInfo[i]);
-               qDebug("File %02d: <%s>", i, QUTF8(inputFilesInfo[i].filePath()));
+               qDebug("File %02d: <%s>", i, MUTILS_UTF8(inputFilesInfo[i].filePath()));
        }
        
        qDebug("All input files added.");
@@ -75,7 +83,7 @@ CueSplitter::~CueSplitter(void)
 {
        while(!m_tempFiles.isEmpty())
        {
-               lamexp_remove_file(m_tempFiles.takeFirst());
+               MUtils::remove_file(m_tempFiles.takeFirst());
        }
 }
 
@@ -95,7 +103,7 @@ void CueSplitter::run()
        
        if(!QDir(m_outputDir).exists())
        {
-               qWarning("Output directory \"%s\" does not exist!", QUTF8(m_outputDir));
+               qWarning("Output directory \"%s\" does not exist!", MUTILS_UTF8(m_outputDir));
                return;
        }
        
@@ -119,7 +127,7 @@ void CueSplitter::run()
                                emit fileSelected(m_activeFile);
                                emit progressValChanged(i+1);
                                
-                               QString tempFile = QString("%1/~%2.wav").arg(m_outputDir, lamexp_rand_str());
+                               QString tempFile = QString("%1/~%2.wav").arg(m_outputDir, MUtils::rand_str());
                                connect(decoder, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection);
                                
                                if(decoder->decode(inputFileList.at(i), tempFile, &m_abortFlag))
@@ -130,11 +138,11 @@ void CueSplitter::run()
                                else
                                {
                                        qWarning("Failed to decompress file: <%s>", inputFileList.at(i).toLatin1().constData());
-                                       lamexp_remove_file(tempFile);
+                                       MUtils::remove_file(tempFile);
                                }
                                
                                m_activeFile.clear();
-                               LAMEXP_DELETE(decoder);
+                               MUTILS_DELETE(decoder);
                        }
                        else
                        {
@@ -200,10 +208,10 @@ void CueSplitter::run()
 
                        //Generate output file name
                        QString trackTitle = trackMetaInfo.title().isEmpty() ? QString().sprintf("Track %02d", trackNo) : trackMetaInfo.title();
-                       QString outputFile = QString("%1/[%2] %3 - %4.wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), lamexp_clean_filename(m_baseName), lamexp_clean_filename(trackTitle));
+                       QString outputFile = QString("%1/[%2] %3 - %4.wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), MUtils::clean_file_name(m_baseName), MUtils::clean_file_name(trackTitle));
                        for(int n = 2; QFileInfo(outputFile).exists(); n++)
                        {
-                               outputFile = QString("%1/[%2] %3 - %4 (%5).wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), lamexp_clean_filename(m_baseName), lamexp_clean_filename(trackTitle), QString::number(n));
+                               outputFile = QString("%1/[%2] %3 - %4 (%5).wav").arg(m_outputDir, QString().sprintf("%02d", trackNo), MUtils::clean_file_name(m_baseName), MUtils::clean_file_name(trackTitle), QString::number(n));
                        }
 
                        //Call split function
@@ -221,7 +229,7 @@ void CueSplitter::run()
        }
 
        emit progressValChanged(10 * nTracksTotal);
-       lamexp_sleep(333);
+       MUtils::OS::sleep_ms(333);
 
        qDebug("All files were split.\n");
        m_bSuccess = true;
@@ -243,12 +251,12 @@ void CueSplitter::handleUpdate(int progress)
 void CueSplitter::splitFile(const QString &output, const int trackNo, const QString &file, const double offset, const double length, const AudioFileModel_MetaInfo &metaInfo, const int baseProgress)
 {
        qDebug("[Track %02d]", trackNo);
-       qDebug("File: <%s>", QUTF8(file));
+       qDebug("File: <%s>", MUTILS_UTF8(file));
        qDebug("Offset: <%f> <%s>", offset, indexToString(offset).toLatin1().constData());
        qDebug("Length: <%f> <%s>", length, indexToString(length).toLatin1().constData());
-       qDebug("Artist: <%s>", QUTF8(metaInfo.artist()));
-       qDebug("Title: <%s>", QUTF8(metaInfo.title()));
-       qDebug("Album: <%s>", QUTF8(metaInfo.album()));
+       qDebug("Artist: <%s>", MUTILS_UTF8(metaInfo.artist()));
+       qDebug("Title: <%s>", MUTILS_UTF8(metaInfo.title()));
+       qDebug("Album: <%s>", MUTILS_UTF8(metaInfo.album()));
        
        int prevProgress = baseProgress;
 
@@ -261,7 +269,7 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
 
        QString baseName = shortName(QFileInfo(output).fileName());
        QString decompressedInput = m_decompressedFiles[file];
-       qDebug("Input: <%s>", QUTF8(decompressedInput));
+       qDebug("Input: <%s>", MUTILS_UTF8(decompressedInput));
        
        AudioFileModel outFileInfo(output);
        outFileInfo.setMetaInfo(metaInfo);
@@ -296,9 +304,8 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr
        QRegExp rxDuration("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d).(\\d\\d)", Qt::CaseInsensitive);
 
        QProcess process;
-       process.setProcessChannelMode(QProcess::MergedChannels);
-       process.setReadChannel(QProcess::StandardOutput);
-       process.setWorkingDirectory(m_outputDir);
+       MUtils::init_process(process, m_outputDir);
+
        process.start(m_soxBin, args);
                
        if(!process.waitForStarted())