1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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.
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.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Thread_Process.h"
27 #include "Model_AudioFile.h"
28 #include "Model_Progress.h"
29 #include "Encoder_Abstract.h"
30 #include "Decoder_Abstract.h"
31 #include "Filter_Abstract.h"
32 #include "Filter_Downmix.h"
33 #include "Filter_Resample.h"
34 #include "Tool_WaveProperties.h"
35 #include "Registry_Decoder.h"
36 #include "Model_Settings.h"
39 #include <MUtils/Global.h>
40 #include <MUtils/OSSupport.h>
41 #include <MUtils/Version.h>
48 #include <QMutexLocker>
50 #include <QThreadPool>
57 #define DIFF(X,Y) ((X > Y) ? (X-Y) : (Y-X))
58 #define IS_WAVE(X) ((X.containerType().compare("Wave", Qt::CaseInsensitive) == 0) && (X.audioType().compare("PCM", Qt::CaseInsensitive) == 0))
59 #define STRDEF(STR,DEF) ((!STR.isEmpty()) ? STR : DEF)
61 ////////////////////////////////////////////////////////////
63 ////////////////////////////////////////////////////////////
65 ProcessThread::ProcessThread(const AudioFileModel
&audioFile
, const QString
&outputDirectory
, const QString
&tempDirectory
, AbstractEncoder
*encoder
, const bool prependRelativeSourcePath
)
67 m_audioFile(audioFile
),
68 m_outputDirectory(outputDirectory
),
69 m_tempDirectory(tempDirectory
),
71 m_jobId(QUuid::createUuid()),
72 m_prependRelativeSourcePath(prependRelativeSourcePath
),
73 m_renamePattern("<BaseName>"),
74 m_overwriteMode(OverwriteMode_KeepBoth
),
75 m_keepDateTime(false),
77 m_propDetect(new WaveProperties())
79 connect(m_encoder
, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection
);
80 connect(m_encoder
, SIGNAL(messageLogged(QString
)), this, SLOT(handleMessage(QString
)), Qt::DirectConnection
);
82 connect(m_propDetect
, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection
);
83 connect(m_propDetect
, SIGNAL(messageLogged(QString
)), this, SLOT(handleMessage(QString
)), Qt::DirectConnection
);
85 m_currentStep
= UnknownStep
;
88 ProcessThread::~ProcessThread(void)
90 while(!m_tempFiles
.isEmpty())
92 MUtils::remove_file(m_tempFiles
.takeFirst());
95 while(!m_filters
.isEmpty())
97 delete m_filters
.takeFirst();
100 MUTILS_DELETE(m_encoder
);
101 MUTILS_DELETE(m_propDetect
);
103 emit
processFinished();
106 ////////////////////////////////////////////////////////////
108 ////////////////////////////////////////////////////////////
110 bool ProcessThread::init(void)
112 if(m_initialized
.testAndSetOrdered((-1), 0))
114 //Initialize job status
115 qDebug("Process thread %s has started.", m_jobId
.toString().toLatin1().constData());
116 emit
processStateInitialized(m_jobId
, QFileInfo(m_audioFile
.filePath()).fileName(), tr("Starting..."), ProgressModel::JobRunning
);
119 handleMessage(QString().sprintf("LameXP v%u.%02u (Build #%u), compiled on %s at %s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), MUTILS_UTF8(MUtils::Version::app_build_date().toString(Qt::ISODate
)), MUTILS_UTF8(MUtils::Version::app_build_time().toString(Qt::ISODate
))));
120 handleMessage("\n-------------------------------\n");
125 qWarning("[ProcessThread::init] Job %s already initialialized, skipping!", m_jobId
.toString().toLatin1().constData());
129 bool ProcessThread::start(QThreadPool
*const pool
)
131 //Make sure object was initialized correctly
132 if (m_initialized
< 0)
134 MUTILS_THROW("Object not initialized yet!");
137 if (m_initialized
.testAndSetOrdered(0, 1))
139 m_outFileName
.clear();
140 m_aborted
.fetchAndStoreOrdered(0);
141 bool bSuccess
= false;
143 //Generate output file name
144 switch(generateOutFileName(m_outFileName
))
147 //File name generated successfully :-)
152 //File name already exists -> skipping!
153 emit
processStateChanged(m_jobId
, tr("Skipped."), ProgressModel::JobSkipped
);
154 emit
processStateFinished(m_jobId
, m_outFileName
, -1);
157 //File name could not be generated
158 emit
processStateChanged(m_jobId
, tr("Not found!"), ProgressModel::JobFailed
);
159 emit
processStateFinished(m_jobId
, m_outFileName
, 0);
166 qWarning("[ProcessThread::start] Job %s already started, skipping!", m_jobId
.toString().toLatin1().constData());
170 ////////////////////////////////////////////////////////////
171 // Thread Entry Point
172 ////////////////////////////////////////////////////////////
174 void ProcessThread::run()
180 catch(const std::exception
&error
)
182 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nException error:\n%s\n", error
.what());
183 MUtils::OS::fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
187 MUTILS_PRINT_ERROR("\nGURU MEDITATION !!!\n\nUnknown exception error!\n");
188 MUtils::OS::fatal_exit(L
"Unhandeled C++ exception error, application will exit!");
192 void ProcessThread::processFile()
195 bool bSuccess
= true;
197 //Make sure object was initialized correctly
198 if(m_initialized
< 1)
200 MUTILS_THROW("Object not initialized yet!");
203 QString sourceFile
= m_audioFile
.filePath();
205 //-----------------------------------------------------
206 // Decode source file
207 //-----------------------------------------------------
209 const AudioFileModel_TechInfo
&formatInfo
= m_audioFile
.techInfo();
210 if(!m_filters
.isEmpty() || !m_encoder
->isFormatSupported(formatInfo
.containerType(), formatInfo
.containerProfile(), formatInfo
.audioType(), formatInfo
.audioProfile(), formatInfo
.audioVersion()))
212 m_currentStep
= DecodingStep
;
213 AbstractDecoder
*decoder
= DecoderRegistry::lookup(formatInfo
.containerType(), formatInfo
.containerProfile(), formatInfo
.audioType(), formatInfo
.audioProfile(), formatInfo
.audioVersion());
217 QString tempFile
= generateTempFileName();
219 connect(decoder
, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection
);
220 connect(decoder
, SIGNAL(messageLogged(QString
)), this, SLOT(handleMessage(QString
)), Qt::DirectConnection
);
222 bSuccess
= decoder
->decode(sourceFile
, tempFile
, m_aborted
);
223 MUTILS_DELETE(decoder
);
227 sourceFile
= tempFile
;
228 m_audioFile
.techInfo().setContainerType(QString::fromLatin1("Wave"));
229 m_audioFile
.techInfo().setAudioType(QString::fromLatin1("PCM"));
231 if(QFileInfo(sourceFile
).size() >= 4294967296i64
)
233 handleMessage(tr("WARNING: Decoded file size exceeds 4 GB, problems might occur!\n"));
236 handleMessage("\n-------------------------------\n");
241 if(QFileInfo(m_outFileName
).exists() && (QFileInfo(m_outFileName
).size() < 512)) QFile::remove(m_outFileName
);
242 handleMessage(QString("%1\n%2\n\n%3\t%4\n%5\t%6").arg(tr("The format of this file is NOT supported:"), m_audioFile
.filePath(), tr("Container Format:"), m_audioFile
.containerInfo(), tr("Audio Format:"), m_audioFile
.audioCompressInfo()));
243 emit
processStateChanged(m_jobId
, tr("Unsupported!"), ProgressModel::JobFailed
);
244 emit
processStateFinished(m_jobId
, m_outFileName
, 0);
249 //-----------------------------------------------------
250 // Update audio properties after decode
251 //-----------------------------------------------------
253 if(bSuccess
&& (!m_aborted
) && IS_WAVE(m_audioFile
.techInfo()))
255 if(m_encoder
->supportedSamplerates() || m_encoder
->supportedBitdepths() || m_encoder
->supportedChannelCount() || m_encoder
->needsTimingInfo() || !m_filters
.isEmpty())
257 m_currentStep
= AnalyzeStep
;
258 bSuccess
= m_propDetect
->detect(sourceFile
, &m_audioFile
.techInfo(), m_aborted
);
262 handleMessage("\n-------------------------------\n");
264 //Do we need to take care if Stereo downmix?
265 const unsigned int *const supportedChannelCount
= m_encoder
->supportedChannelCount();
266 if(supportedChannelCount
&& supportedChannelCount
[0])
268 insertDownmixFilter(supportedChannelCount
);
271 //Do we need to take care of downsampling the input?
272 const unsigned int *const supportedSamplerates
= m_encoder
->supportedSamplerates();
273 const unsigned int *const supportedBitdepths
= m_encoder
->supportedBitdepths();
274 if((supportedSamplerates
&& supportedSamplerates
[0]) || (supportedBitdepths
&& supportedBitdepths
[0]))
276 insertDownsampleFilter(supportedSamplerates
, supportedBitdepths
);
282 //-----------------------------------------------------
283 // Apply all audio filters
284 //-----------------------------------------------------
286 while(bSuccess
&& (!m_filters
.isEmpty()) && (!m_aborted
))
288 QString tempFile
= generateTempFileName();
289 AbstractFilter
*poFilter
= m_filters
.takeFirst();
290 m_currentStep
= FilteringStep
;
292 connect(poFilter
, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection
);
293 connect(poFilter
, SIGNAL(messageLogged(QString
)), this, SLOT(handleMessage(QString
)), Qt::DirectConnection
);
295 const AbstractFilter::FilterResult filterResult
= poFilter
->apply(sourceFile
, tempFile
, &m_audioFile
.techInfo(), m_aborted
);
296 switch (filterResult
)
298 case AbstractFilter::FILTER_SUCCESS
:
299 sourceFile
= tempFile
;
301 case AbstractFilter::FILTER_FAILURE
:
306 handleMessage("\n-------------------------------\n");
310 //-----------------------------------------------------
312 //-----------------------------------------------------
314 if(bSuccess
&& (!m_aborted
))
316 m_currentStep
= EncodingStep
;
317 bSuccess
= m_encoder
->encode(sourceFile
, m_audioFile
.metaInfo(), m_audioFile
.techInfo().duration(), m_audioFile
.techInfo().audioChannels(), m_outFileName
, m_aborted
);
321 if((!bSuccess
) || MUTILS_BOOLIFY(m_aborted
))
323 QFileInfo
fileInfo(m_outFileName
);
324 if(fileInfo
.exists() && (fileInfo
.size() < 1024))
326 QFile::remove(m_outFileName
);
330 //Make sure output file exists
331 if(bSuccess
&& (!m_aborted
))
333 const QFileInfo
fileInfo(m_outFileName
);
334 bSuccess
= fileInfo
.exists() && fileInfo
.isFile() && (fileInfo
.size() >= 1024);
337 //-----------------------------------------------------
339 //-----------------------------------------------------
341 if (bSuccess
&& (!m_aborted
) && m_keepDateTime
)
343 updateFileTime(m_audioFile
.filePath(), m_outFileName
);
346 MUtils::OS::sleep_ms(12);
349 emit
processStateChanged(m_jobId
, (MUTILS_BOOLIFY(m_aborted
) ? tr("Aborted!") : (bSuccess
? tr("Done.") : tr("Failed!"))), ((bSuccess
&& (!m_aborted
)) ? ProgressModel::JobComplete
: ProgressModel::JobFailed
));
350 emit
processStateFinished(m_jobId
, m_outFileName
, (bSuccess
? 1 : 0));
352 qDebug("Process thread is done.");
355 ////////////////////////////////////////////////////////////
357 ////////////////////////////////////////////////////////////
359 void ProcessThread::handleUpdate(int progress
)
361 //qDebug("Progress: %d\n", progress);
363 switch(m_currentStep
)
366 emit
processStateChanged(m_jobId
, QString("%1 (%2%)").arg(tr("Encoding"), QString::number(progress
)), ProgressModel::JobRunning
);
369 emit
processStateChanged(m_jobId
, QString("%1 (%2%)").arg(tr("Analyzing"), QString::number(progress
)), ProgressModel::JobRunning
);
372 emit
processStateChanged(m_jobId
, QString("%1 (%2%)").arg(tr("Filtering"), QString::number(progress
)), ProgressModel::JobRunning
);
375 emit
processStateChanged(m_jobId
, QString("%1 (%2%)").arg(tr("Decoding"), QString::number(progress
)), ProgressModel::JobRunning
);
380 void ProcessThread::handleMessage(const QString
&line
)
382 emit
processMessageLogged(m_jobId
, line
);
385 ////////////////////////////////////////////////////////////
387 ////////////////////////////////////////////////////////////
389 int ProcessThread::generateOutFileName(QString
&outFileName
)
393 /* -------- Check source file -------- */
395 //Make sure the source file exists
396 const QFileInfo
sourceFile(m_audioFile
.filePath());
397 if(!(sourceFile
.exists() && sourceFile
.isFile()))
399 handleMessage(QString("%1\n%2").arg(tr("The source audio file could not be found:"), sourceFile
.absoluteFilePath()));
403 //Make sure the source file readable
404 QFile
readTest(sourceFile
.canonicalFilePath());
405 if(!readTest
.open(QIODevice::ReadOnly
))
407 handleMessage(QString("%1\n%2").arg(tr("The source audio file could not be opened for reading:"), QDir::toNativeSeparators(readTest
.fileName())));
415 /* -------- Determine target directory -------- */
417 QDir
targetDir(MUtils::clean_file_path(m_outputDirectory
.isEmpty() ? sourceFile
.canonicalPath() : m_outputDirectory
, false));
419 //Prepend relative source file path?
420 if(m_prependRelativeSourcePath
&& !m_outputDirectory
.isEmpty())
422 QDir sourceDir
= sourceFile
.dir();
423 if (!sourceDir
.isRoot())
426 while ((!sourceDir
.isRoot()) && (++depth
<= 0xFF))
428 if (!sourceDir
.cdUp()) break;
430 const QString postfix
= QFileInfo(sourceDir
.relativeFilePath(sourceFile
.canonicalFilePath())).path();
431 targetDir
.setPath(MUtils::clean_file_path(QString("%1/%2").arg(targetDir
.absolutePath(), postfix
), false));
435 //Make sure output directory does exist
436 if(!targetDir
.exists())
438 targetDir
.mkpath(".");
439 if(!targetDir
.exists())
441 handleMessage(QString("%1\n%2").arg(tr("The target output directory doesn't exist and could NOT be created:"), QDir::toNativeSeparators(targetDir
.absolutePath())));
446 //Make sure that the output dir is writable
447 QFile
writeTest(MUtils::make_temp_file(targetDir
, "~rw"));
448 if(!writeTest
.open(QIODevice::ReadWrite
))
450 handleMessage(QString("%1\n%2").arg(tr("The target output directory is NOT writable:"), QDir::toNativeSeparators(targetDir
.absolutePath())));
455 writeTest
.remove(); /*clean-up*/
458 /* -------- Generate initial file name and check -------- */
461 const QString fileExt
= m_renameFileExt
.isEmpty() ? QString::fromUtf8(m_encoder
->toEncoderInfo()->extension()) : m_renameFileExt
;
464 const QString fileName
= MUtils::clean_file_name(QString("%1.%2").arg(applyRegularExpression(applyRenamePattern(sourceFile
.completeBaseName(), m_audioFile
.metaInfo())), fileExt
), true);
466 //Generate full output path
467 outFileName
= targetDir
.absoluteFilePath(fileName
);
469 //Skip file, if target file exists (optional!)
470 if((m_overwriteMode
== OverwriteMode_SkipExisting
) && QFileInfo(outFileName
).exists())
472 handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to skip this file:"), QDir::toNativeSeparators(outFileName
)));
473 handleMessage(tr("If you don't want existing files to be skipped, please change the overwrite mode!"));
477 //Delete file, if target file exists (optional!)
478 const QFileInfo
origFileName(outFileName
);
479 if((m_overwriteMode
== OverwriteMode_Overwrite
) && origFileName
.exists() && origFileName
.isFile())
481 handleMessage(QString("%1\n%2\n").arg(tr("Target output file already exists, going to delete existing file:"), QDir::toNativeSeparators(outFileName
)));
482 bool removed
= false;
483 if(sourceFile
.canonicalFilePath().compare(origFileName
.absoluteFilePath(), Qt::CaseInsensitive
) != 0)
485 removed
= MUtils::remove_file(outFileName
);
489 handleMessage(QString("%1\n").arg(tr("Failed to delete existing target file, will save to another file name!")));
493 /* -------- Generate final non-existing file name -------- */
495 //Generate final name
496 outFileName
= MUtils::make_unique_file(origFileName
.absoluteDir(), origFileName
.completeBaseName(), origFileName
.suffix(), true, true);
497 if(!outFileName
.isEmpty())
503 handleMessage(QString("%1\n").arg(tr("Failed to generate non-existing target file name!")));
507 QString
ProcessThread::applyRenamePattern(const QString
&baseName
, const AudioFileModel_MetaInfo
&metaInfo
)
509 QString fileName
= m_renamePattern
;
511 fileName
.replace("<BaseName>", STRDEF(baseName
, tr("Unknown File Name")), Qt::CaseInsensitive
);
512 fileName
.replace("<TrackNo>", QString().sprintf("%02d", metaInfo
.position()), Qt::CaseInsensitive
);
513 fileName
.replace("<Title>", STRDEF(metaInfo
.title(), tr("Unknown Title")) , Qt::CaseInsensitive
);
514 fileName
.replace("<Artist>", STRDEF(metaInfo
.artist(), tr("Unknown Artist")), Qt::CaseInsensitive
);
515 fileName
.replace("<Album>", STRDEF(metaInfo
.album(), tr("Unknown Album")), Qt::CaseInsensitive
);
516 fileName
.replace("<Year>", QString().sprintf("%04d", metaInfo
.year()), Qt::CaseInsensitive
);
517 fileName
.replace("<Comment>", STRDEF(metaInfo
.comment(), tr("Unknown Comment")), Qt::CaseInsensitive
);
519 return fileName
.trimmed().isEmpty() ? baseName
: fileName
;
522 QString
ProcessThread::applyRegularExpression(const QString
&baseName
)
524 if(m_renameRegExp_Search
.isEmpty() || m_renameRegExp_Replace
.isEmpty())
529 QRegExp
regExp(m_renameRegExp_Search
);
530 if(!regExp
.isValid())
532 qWarning("Invalid regular expression detected -> cannot rename!");
536 const QString fileName
= QString(baseName
).replace(regExp
, m_renameRegExp_Replace
);
537 return fileName
.trimmed().isEmpty() ? baseName
: fileName
;
540 QString
ProcessThread::generateTempFileName(void)
542 const QString tempFileName
= MUtils::make_temp_file(m_tempDirectory
, "wav", true);
543 if(tempFileName
.isEmpty())
545 return QString("%1/~whoops%2.wav").arg(m_tempDirectory
, QString::number(MUtils::next_rand_u32()));
548 m_tempFiles
<< tempFileName
;
552 bool ProcessThread::insertDownsampleFilter(const unsigned int *const supportedSamplerates
, const unsigned int *const supportedBitdepths
)
554 int targetSampleRate
= 0, targetBitDepth
= 0;
556 /* Adjust sample rate */
557 if(supportedSamplerates
&& m_audioFile
.techInfo().audioSamplerate())
559 const unsigned int inputRate
= m_audioFile
.techInfo().audioSamplerate();
560 unsigned int currentDiff
= UINT_MAX
, minimumDiff
= UINT_MAX
, bestRate
= UINT_MAX
;
562 //Find the most suitable supported sampling rate
563 for(int i
= 0; supportedSamplerates
[i
]; i
++)
565 currentDiff
= DIFF(inputRate
, supportedSamplerates
[i
]);
566 if((currentDiff
< minimumDiff
) || ((currentDiff
== minimumDiff
) && (bestRate
< supportedSamplerates
[i
])))
568 bestRate
= supportedSamplerates
[i
];
569 minimumDiff
= currentDiff
;
570 if(!(minimumDiff
> 0)) break;
574 if(bestRate
!= inputRate
)
576 targetSampleRate
= (bestRate
!= UINT_MAX
) ? bestRate
: supportedSamplerates
[0];
580 /* Adjust bit depth (word size) */
581 if(supportedBitdepths
&& m_audioFile
.techInfo().audioBitdepth())
583 const unsigned int inputBPS
= m_audioFile
.techInfo().audioBitdepth();
584 bool bAdjustBitdepth
= true;
586 //Is the input bit depth supported exactly? (including IEEE Float)
587 for(int i
= 0; supportedBitdepths
[i
]; i
++)
589 if(supportedBitdepths
[i
] == inputBPS
) bAdjustBitdepth
= false;
594 unsigned int currentDiff
= UINT_MAX
, minimumDiff
= UINT_MAX
, bestBPS
= UINT_MAX
;
595 const unsigned int originalBPS
= (inputBPS
== AudioFileModel::BITDEPTH_IEEE_FLOAT32
) ? 32 : inputBPS
;
597 //Find the most suitable supported bit depth
598 for(int i
= 0; supportedBitdepths
[i
]; i
++)
600 if(supportedBitdepths
[i
] == AudioFileModel::BITDEPTH_IEEE_FLOAT32
) continue;
602 currentDiff
= DIFF(originalBPS
, supportedBitdepths
[i
]);
603 if((currentDiff
< minimumDiff
) || ((currentDiff
== minimumDiff
) && (bestBPS
< supportedBitdepths
[i
])))
605 bestBPS
= supportedBitdepths
[i
];
606 minimumDiff
= currentDiff
;
607 if(!(minimumDiff
> 0)) break;
611 if(bestBPS
!= originalBPS
)
613 targetBitDepth
= (bestBPS
!= UINT_MAX
) ? bestBPS
: supportedBitdepths
[0];
618 //Check if downsampling filter is already in the chain
619 if (targetSampleRate
|| targetBitDepth
)
621 for (int i
= 0; i
< m_filters
.count(); i
++)
623 if (dynamic_cast<ResampleFilter
*>(m_filters
.at(i
)))
625 qWarning("Encoder requires downsampling, but user has already set resamling filter!");
626 handleMessage("WARNING: Encoder may need resampling, but already using resample filter. Encoding *may* fail!\n");
627 targetSampleRate
= targetBitDepth
= 0;
632 /* Insert the filter */
633 if(targetSampleRate
|| targetBitDepth
)
635 m_filters
.append(new ResampleFilter(targetSampleRate
, targetBitDepth
));
639 return false; /*did not insert the resample filter */
642 bool ProcessThread::insertDownmixFilter(const unsigned int *const supportedChannels
)
644 //Determine number of channels in source
645 const unsigned int channels
= m_audioFile
.techInfo().audioChannels();
646 bool requiresDownmix
= (channels
> 0);
648 //Check whether encoder requires downmixing
651 for (int i
= 0; supportedChannels
[i
]; i
++)
653 if (supportedChannels
[i
] == channels
)
655 requiresDownmix
= false;
661 //Check if downmixing filter is already in the chain
664 for (int i
= 0; i
< m_filters
.count(); i
++)
666 if (dynamic_cast<DownmixFilter
*>(m_filters
.at(i
)))
668 qWarning("Encoder requires Stereo downmix, but user has already forced downmix!");
669 handleMessage("WARNING: Encoder may need downmixning, but already using downmixning filter. Encoding *may* fail!\n");
670 requiresDownmix
= false;
676 //Now add the downmixing filter, if needed
679 m_filters
.append(new DownmixFilter());
683 return false; /*did not insert the downmix filter*/
686 bool ProcessThread::updateFileTime(const QString
&originalFile
, const QString
&modifiedFile
)
688 bool success
= false;
690 QFileInfo
originalFileInfo(originalFile
);
691 const QDateTime timeCreated
= originalFileInfo
.created(), timeLastMod
= originalFileInfo
.lastModified();
692 if (timeCreated
.isValid() && timeLastMod
.isValid())
694 if (!MUtils::OS::set_file_time(modifiedFile
, timeCreated
, timeLastMod
))
696 qWarning("Failed to update creation/modified time of output file: \"%s\"", MUTILS_UTF8(modifiedFile
));
701 qWarning("Failed to read creation/modified time of source file: \"%s\"", MUTILS_UTF8(originalFile
));
707 ////////////////////////////////////////////////////////////
709 ////////////////////////////////////////////////////////////
711 void ProcessThread::addFilter(AbstractFilter
*filter
)
713 m_filters
.append(filter
);
716 void ProcessThread::setRenamePattern(const QString
&pattern
)
718 const QString newPattern
= pattern
.simplified();
719 if(!newPattern
.isEmpty()) m_renamePattern
= newPattern
;
722 void ProcessThread::setRenameRegExp(const QString
&search
, const QString
&replace
)
724 const QString newSearch
= search
.trimmed(), newReplace
= replace
.simplified();
725 if((!newSearch
.isEmpty()) && (!newReplace
.isEmpty()))
727 m_renameRegExp_Search
= newSearch
;
728 m_renameRegExp_Replace
= newReplace
;
732 void ProcessThread::setRenameFileExt(const QString
&fileExtension
)
734 m_renameFileExt
= MUtils::clean_file_name(fileExtension
, false).simplified();
735 while(m_renameFileExt
.startsWith('.'))
737 m_renameFileExt
= m_renameFileExt
.mid(1).trimmed();
741 void ProcessThread::setOverwriteMode(const bool &bSkipExistingFile
, const bool &bReplacesExisting
)
743 if(bSkipExistingFile
&& bReplacesExisting
)
745 qWarning("Inconsistent overwrite flags -> reverting to default!");
746 m_overwriteMode
= OverwriteMode_KeepBoth
;
750 m_overwriteMode
= OverwriteMode_KeepBoth
;
751 if(bSkipExistingFile
) m_overwriteMode
= OverwriteMode_SkipExisting
;
752 if(bReplacesExisting
) m_overwriteMode
= OverwriteMode_Overwrite
;
756 void ProcessThread::setKeepDateTime(const bool &keepDateTime
)
758 m_keepDateTime
= keepDateTime
;
761 ////////////////////////////////////////////////////////////
763 ////////////////////////////////////////////////////////////