OSDN Git Service

Switch to using QAtomicInc for abort flags.
[lamexp/LameXP.git] / src / Filter_Resample.cpp
index e208d3a..f692fb4 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2017 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
@@ -61,7 +61,7 @@ ResampleFilter::~ResampleFilter(void)
 {
 }
 
-bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel_TechInfo *formatInfo, volatile bool *abortFlag)
+AbstractFilter::FilterResult ResampleFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel_TechInfo *const formatInfo, QAtomicInt &abortFlag)
 {
        QProcess process;
        QStringList args;
@@ -70,11 +70,9 @@ bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile,
        {
                messageLogged("Skipping resample filter!");
                qDebug("Resampling filter target samplerate/bitdepth is equals to the format of the input file, skipping!");
-               return true;
+               return AbstractFilter::FILTER_SKIPPED;
        }
 
-       process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath());
-
        args << "-V3" << "-S";
        args << "--guard" << "--temp" << ".";
        args << QDir::toNativeSeparators(sourceFile);
@@ -99,9 +97,9 @@ bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile,
                args << "dither" << "-s";                                       //if you're mastering to 16-bit, you also need to add 'dither' (and in most cases noise-shaping) after the rate
        }
 
-       if(!startProcess(process, m_binary, args))
+       if(!startProcess(process, m_binary, args, QFileInfo(outputFile).canonicalPath()))
        {
-               return false;
+               return AbstractFilter::FILTER_FAILURE;
        }
 
        bool bTimeout = false;
@@ -111,7 +109,7 @@ bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile,
 
        while(process.state() != QProcess::NotRunning)
        {
-               if(*abortFlag)
+               if(checkFlag(abortFlag))
                {
                        process.kill();
                        bAborted = true;
@@ -156,11 +154,13 @@ bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile,
 
        if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
        {
-               return false;
+               return AbstractFilter::FILTER_FAILURE;
        }
        
-       if(m_samplingRate) formatInfo->setAudioSamplerate(m_samplingRate);
-       if(m_bitDepth) formatInfo->setAudioBitdepth(m_bitDepth);
+       if(m_samplingRate)
+               formatInfo->setAudioSamplerate(m_samplingRate);
+       if(m_bitDepth)
+               formatInfo->setAudioBitdepth(m_bitDepth);
 
-       return true;
+       return AbstractFilter::FILTER_SUCCESS;
 }