void CueSplitter::run() { m_bSuccess = false; m_bAborted = false; m_abortFlag = false; m_nTracksSuccess = 0; m_nTracksSkipped = 0; m_decompressedFiles.clear(); m_activeFile.clear(); if(!QDir(m_outputDir).exists()) { qWarning("Output directory \"%s\" does not exist!", QUTF8(m_outputDir)); return; } QStringList inputFileList = m_inputFilesInfo.keys(); int nInputFiles = inputFileList.count(); emit progressMaxChanged(nInputFiles); emit progressValChanged(0); //Decompress all input files for(int i = 0; i < nInputFiles; i++) { const AudioFileModel_TechInfo &inputFileInfo = m_inputFilesInfo[inputFileList.at(i)].techInfo(); if(inputFileInfo.containerType().compare("Wave", Qt::CaseInsensitive) || inputFileInfo.audioType().compare("PCM", Qt::CaseInsensitive)) { AbstractDecoder *decoder = DecoderRegistry::lookup(inputFileInfo.containerType(), inputFileInfo.containerProfile(), inputFileInfo.audioType(), inputFileInfo.audioProfile(), inputFileInfo.audioVersion()); if(decoder) { m_activeFile = shortName(QFileInfo(inputFileList.at(i)).fileName()); emit fileSelected(m_activeFile); emit progressValChanged(i+1); QString tempFile = QString("%1/~%2.wav").arg(m_outputDir, lamexp_rand_str()); connect(decoder, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection); if(decoder->decode(inputFileList.at(i), tempFile, &m_abortFlag)) { m_decompressedFiles.insert(inputFileList.at(i), tempFile); m_tempFiles.append(tempFile); } else { qWarning("Failed to decompress file: <%s>", inputFileList.at(i).toLatin1().constData()); lamexp_remove_file(tempFile); } m_activeFile.clear(); LAMEXP_DELETE(decoder); } else { qWarning("Unsupported input file: <%s>", inputFileList.at(i).toLatin1().constData()); } }
void FileAnalyzer::taskThreadFinish(const unsigned int taskId) { m_runningTaskIds.remove(taskId); emit progressValChanged(++m_completedCounter); if(!analyzeNextFile()) { if(m_runningTaskIds.empty()) { QTimer::singleShot(0, this, SLOT(quit())); //Stop event processing, if all threads have completed! } } }
void FileAnalyzer::run() { m_abortFlag = false; m_bAborted = false; m_bSuccess = false; int nFiles = m_inputFiles.count(); emit progressMaxChanged(nFiles); emit progressValChanged(0); lamexp_natural_string_sort(m_inputFiles, true); //.sort(); if(!m_templateFile) { if(!createTemplate()) { qWarning("Failed to create template file!"); return; } } AnalyzeTask::reset(); QThreadPool *pool = new QThreadPool(); QThread::msleep(333); pool->setMaxThreadCount(qBound(2, ((QThread::idealThreadCount() * 3) / 2), 12)); while(!(m_inputFiles.isEmpty() || m_bAborted)) { while(!(m_inputFiles.isEmpty() || m_bAborted)) { if(!AnalyzeTask::waitForFreeSlot(&m_abortFlag)) { qWarning("Timeout in AnalyzeTask::waitForFreeSlot() !!!"); } if(m_abortFlag) { MessageBeep(MB_ICONERROR); m_bAborted = true; break; } if(!m_bAborted) { const QString currentFile = QDir::fromNativeSeparators(m_inputFiles.takeFirst()); AnalyzeTask *task = new AnalyzeTask(currentFile, m_templateFile->filePath(), &m_abortFlag); connect(task, SIGNAL(fileSelected(QString)), this, SIGNAL(fileSelected(QString)), Qt::DirectConnection); connect(task, SIGNAL(progressValChanged(unsigned int)), this, SIGNAL(progressValChanged(unsigned int)), Qt::DirectConnection); connect(task, SIGNAL(progressMaxChanged(unsigned int)), this, SIGNAL(progressMaxChanged(unsigned int)), Qt::DirectConnection); connect(task, SIGNAL(fileAnalyzed(AudioFileModel)), this, SIGNAL(fileAnalyzed(AudioFileModel)), Qt::DirectConnection); pool->start(task); if(int count = AnalyzeTask::getAdditionalFiles(m_inputFiles)) { emit progressMaxChanged(nFiles += count); } } } //One of the Analyze tasks may have gathered additional files from a playlist! if(!m_bAborted) { pool->waitForDone(); if(int count = AnalyzeTask::getAdditionalFiles(m_inputFiles)) { emit progressMaxChanged(nFiles += count); } } } pool->waitForDone(); LAMEXP_DELETE(pool); if(m_bAborted) { qWarning("Operation cancelled by user!"); return; } qDebug("All files added.\n"); m_bSuccess = true; }
void FileAnalyzer::run() { m_bSuccess = false; m_tasksCounterNext = 0; m_tasksCounterDone = 0; m_completedCounter = 0; m_completedFiles.clear(); m_completedTaskIds.clear(); m_runningTaskIds.clear(); m_filesAccepted = 0; m_filesRejected = 0; m_filesDenied = 0; m_filesDummyCDDA = 0; m_filesCueSheet = 0; m_timer->invalidate(); //Create MediaInfo template file if(!m_templateFile) { if(!createTemplate()) { qWarning("Failed to create template file!"); return; } } //Sort files MUtils::natural_string_sort(m_inputFiles, true); //Handle playlist files first! handlePlaylistFiles(); const unsigned int nFiles = m_inputFiles.count(); if(nFiles < 1) { qWarning("File list is empty, nothing to do!"); return; } //Update progress emit progressMaxChanged(nFiles); emit progressValChanged(0); //Create thread pool if(!m_pool) m_pool = new QThreadPool(); const int idealThreadCount = QThread::idealThreadCount(); if(idealThreadCount > 0) { m_pool->setMaxThreadCount(qBound(2, ((idealThreadCount * 3) / 2), 12)); } //Start first N threads QTimer::singleShot(0, this, SLOT(initializeTasks())); //Start event processing this->exec(); //Wait for pending tasks to complete m_pool->waitForDone(); //Was opertaion aborted? if(m_bAborted) { qWarning("Operation cancelled by user!"); return; } //Update progress emit progressValChanged(nFiles); //Emit pending files (this should not be required though!) if(!m_completedFiles.isEmpty()) { qWarning("FileAnalyzer: Pending file information found after last thread terminated!"); QList<unsigned int> keys = m_completedFiles.keys(); qSort(keys); while(!keys.isEmpty()) { emit fileAnalyzed(m_completedFiles.take(keys.takeFirst())); } } qDebug("All files added.\n"); m_bSuccess = true; QThread::msleep(333); }