/* * Initialize and launch process object */ bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args) { static AssignProcessToJobObjectFun AssignProcessToJobObjectPtr = NULL; QMutexLocker lock(m_mutex_startProcess); emit messageLogged(commandline2string(program, args) + "\n"); QProcessEnvironment env = process.processEnvironment(); if(env.isEmpty()) env = QProcessEnvironment::systemEnvironment(); env.insert("TEMP", QDir::toNativeSeparators(lamexp_temp_folder2())); env.insert("TMP", QDir::toNativeSeparators(lamexp_temp_folder2())); process.setProcessEnvironment(env); if(!AssignProcessToJobObjectPtr) { QLibrary Kernel32Lib("kernel32.dll"); AssignProcessToJobObjectPtr = (AssignProcessToJobObjectFun) Kernel32Lib.resolve("AssignProcessToJobObject"); } process.setProcessChannelMode(QProcess::MergedChannels); process.setReadChannel(QProcess::StandardOutput); process.start(program, args); if(process.waitForStarted()) { if(AssignProcessToJobObjectPtr) { AssignProcessToJobObjectPtr(m_handle_jobObject, process.pid()->hProcess); } if(!SetPriorityClass(process.pid()->hProcess, BELOW_NORMAL_PRIORITY_CLASS)) { SetPriorityClass(process.pid()->hProcess, IDLE_PRIORITY_CLASS); } lock.unlock(); if(m_firstLaunch) { emit statusUpdated(0); m_firstLaunch = false; } return true; } emit messageLogged("Process creation has failed :-("); QString errorMsg= process.errorString().trimmed(); if(!errorMsg.isEmpty()) emit messageLogged(errorMsg); process.kill(); process.waitForFinished(-1); return false; }
/* * Initialize and launch process object */ bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args, const QString &workingDir) { QMutexLocker lock(&s_startProcessMutex); if((!s_startProcessTimer.isNull()) && s_startProcessTimer->isValid()) { qint64 elapsed = s_startProcessTimer->elapsed(); while(elapsed < START_DELAY) { lock.unlock(); MUtils::OS::sleep_ms((size_t)(START_DELAY - elapsed)); lock.relock(); elapsed = s_startProcessTimer->elapsed(); } } emit messageLogged(commandline2string(program, args) + "\n"); MUtils::init_process(process, workingDir.isEmpty() ? QFileInfo(program).absolutePath() : workingDir); process.start(program, args); if(process.waitForStarted()) { if(!s_jobObjectInstance.isNull()) { if(!s_jobObjectInstance->addProcessToJob(&process)) { qWarning("Failed to assign process to job object!"); } } MUtils::OS::change_process_priority(&process, -1); if(m_firstLaunch) { emit statusUpdated(0); m_firstLaunch = false; } s_startProcessTimer->start(); return true; } emit messageLogged("Process creation has failed :-("); QString errorMsg= process.errorString().trimmed(); if(!errorMsg.isEmpty()) emit messageLogged(errorMsg); process.kill(); process.waitForFinished(-1); s_startProcessTimer->start(); return false; }
bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const QString &outputFile, volatile bool *abortFlag) { SHFILEOPSTRUCTW fileOperation; memset(&fileOperation, 0, sizeof(SHFILEOPSTRUCTW)); fileOperation.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_NOERRORUI | FOF_FILESONLY; emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); fileOperation.wFunc = FO_COPY; /* if(lamexp_temp_folder().compare(QFileInfo(sourceFile).canonicalPath(), Qt::CaseInsensitive) == 0) { //If the source is in the TEMP folder take shortcut and move the file emit messageLogged(QString("Moving file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); fileOperation.wFunc = FO_MOVE; } else { //...otherwise we actually copy the file in order to keep the source emit messageLogged(QString("Copy file \"%1\" to \"%2\"").arg(sourceFile, outputFile)); fileOperation.wFunc = FO_COPY; } */ size_t srcLen = wcslen(reinterpret_cast<const wchar_t*>(sourceFile.utf16())) + 3; wchar_t *srcBuffer = new wchar_t[srcLen]; memset(srcBuffer, 0, srcLen * sizeof(wchar_t)); wcsncpy_s(srcBuffer, srcLen, reinterpret_cast<const wchar_t*>(sourceFile.utf16()), _TRUNCATE); FIX_SEPARATORS (srcBuffer); fileOperation.pFrom = srcBuffer; size_t outLen = wcslen(reinterpret_cast<const wchar_t*>(outputFile.utf16())) + 3; wchar_t *outBuffer = new wchar_t[outLen]; memset(outBuffer, 0, outLen * sizeof(wchar_t)); wcsncpy_s(outBuffer, outLen, reinterpret_cast<const wchar_t*>(outputFile.utf16()), _TRUNCATE); FIX_SEPARATORS (outBuffer); fileOperation.pTo = outBuffer; emit statusUpdated(0); int result = SHFileOperation(&fileOperation); emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", result)); delete [] srcBuffer; delete [] outBuffer; return (result == 0 && fileOperation.fAnyOperationsAborted == false); }
void GDebug::Init() { _gl_logger = new QOpenGLDebugLogger(this); if(_gl_logger->initialize()) { qDebug() << "GL_DEBUG Debug Logger" << _gl_logger << "\n"; connect(_gl_logger, SIGNAL(messageLogged(QOpenGLDebugMessage)),this,SLOT(messageLogged(QOpenGLDebugMessage))); _gl_logger->startLogging(); } else { qDebug() << "GL_DEBUG Debug Logger (NONE)\n"; } }
void MapWidget::initializeGL() { initializeOpenGLFunctions(); QString versionString(QLatin1String(reinterpret_cast<const char*>(glGetString(GL_VERSION)))); QOpenGLContext *ctx = QOpenGLContext::currentContext(); Q_UNUSED(ctx); lg = new QOpenGLDebugLogger(context()); lg->initialize(); lg->startLogging(QOpenGLDebugLogger::SynchronousLogging); lg->enableMessages(); connect(lg, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, SLOT(glLog(QOpenGLDebugMessage))); qDebug() << "Driver Version String:" << versionString; qDebug() << "Current Context:" << ctx->format(); //glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &gpuTotalMemory); //qDebug() << "total" << gpuTotalMemory; m_renderer = new Renderer(); m_renderer->createStaticResources(); //m_painterOverlay = new PainterOverlay(); }
void MovingColoredTriangle::initialize() { // Récupération des fonctions d'OpenGL 4.3 m_funcs = m_context->versionFunctions<QOpenGLFunctions_4_3_Core>(); if ( ! m_funcs ) { qFatal("Requires OpenGL >= 4.3"); exit(1); } m_funcs->initializeOpenGLFunctions(); // Initialisation du système de logging connect(m_logger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, SLOT(onMessageLogged(QOpenGLDebugMessage)), Qt::DirectConnection); if(m_logger->initialize()) m_logger->enableMessages(); // Charge, compile et link le Vertex et Fragment Shader prepareShaders(); // Création du Vertex Array Object m_vao->create(); m_vao->bind(); }
void DiskObserverThread::observe(void) { unsigned __int64 minimumSpace = MIN_DISKSPACE; unsigned __int64 freeSpace, previousSpace = 0ui64; bool ok = false; forever { freeSpace = lamexp_free_diskspace(m_path, &ok); if(ok) { if(freeSpace < minimumSpace) { qWarning("Free diskspace on '%s' dropped below %s MB, only %s MB free!", m_path.toUtf8().constData(), QString::number(minimumSpace / 1048576ui64).toUtf8().constData(), QString::number(freeSpace / 1048576ui64).toUtf8().constData()); emit messageLogged(tr("Low diskspace on drive '%1' detected (only %2 MB are free), problems can occur!").arg(QDir::toNativeSeparators(m_path), QString::number(freeSpace / 1048576ui64)), ProgressModel::SysMsg_Warning); minimumSpace = qMin(freeSpace, (minimumSpace >> 1)); } if(freeSpace != previousSpace) { emit freeSpaceChanged(freeSpace); previousSpace = freeSpace; } } if(m_semaphore.tryAcquire(1, 2000)) break; }
/* * Initialize and launch process object */ bool AbstractTool::startProcess(QProcess &process, const QString &program, const QStringList &args) { QMutexLocker lock(&s_mutex_startProcess); if(lamexp_current_file_time() <= s_lastLaunchTime) { lamexp_sleep(START_DELAY); } emit messageLogged(commandline2string(program, args) + "\n"); lamexp_init_process(process, QFileInfo(program).absolutePath()); process.start(program, args); if(process.waitForStarted()) { if(s_jobObject) { if(!s_jobObject->addProcessToJob(&process)) { qWarning("Failed to assign process to job object!"); } } lamexp_change_process_priority(&process, -1); lock.unlock(); if(m_firstLaunch) { emit statusUpdated(0); m_firstLaunch = false; } s_lastLaunchTime = lamexp_current_file_time() + START_DELAY_NANO; return true; } emit messageLogged("Process creation has failed :-("); QString errorMsg= process.errorString().trimmed(); if(!errorMsg.isEmpty()) emit messageLogged(errorMsg); process.kill(); process.waitForFinished(-1); s_lastLaunchTime = lamexp_current_file_time() + START_DELAY_NANO; return false; }
LogWidget::LogWidget(QWidget *parent) : QWidget(parent), ui(new Ui::LogWidget) { ui->setupUi(this); connect(Logger::instance(), SIGNAL(messageLogged(Level,QString)), this, SLOT(printLoggedMessage(Level,QString))); connect(ui->clearButton, SIGNAL(clicked(bool)), this, SLOT(clear())); }
void ProcessThread::processFile() { m_aborted = false; bool bSuccess = true; qDebug("Process thread %s has started.", m_jobId.toString().toLatin1().constData()); emit processStateInitialized(m_jobId, QFileInfo(m_audioFile.filePath()).fileName(), tr("Starting..."), ProgressModel::JobRunning); handleMessage(QString().sprintf("LameXP v%u.%02u (Build #%u), compiled on %s at %s", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(), lamexp_version_time())); handleMessage("\n-------------------------------\n"); //Generate output file name QString outFileName = generateOutFileName(); if(outFileName.isEmpty()) { emit processStateChanged(m_jobId, tr("Not found!"), ProgressModel::JobFailed); emit processStateFinished(m_jobId, outFileName, false); return; } //Do we need to take care of downsampling the input? if(m_encoder->requiresDownsample()) { insertDownsampleFilter(); } //Do we need Stereo downmix? if(m_encoder->requiresDownmix()) { insertDownmixFilter(); } QString sourceFile = m_audioFile.filePath(); //Decode source file if(!m_filters.isEmpty() || !m_encoder->isFormatSupported(m_audioFile.formatContainerType(), m_audioFile.formatContainerProfile(), m_audioFile.formatAudioType(), m_audioFile.formatAudioProfile(), m_audioFile.formatAudioVersion())) { m_currentStep = DecodingStep; AbstractDecoder *decoder = DecoderRegistry::lookup(m_audioFile.formatContainerType(), m_audioFile.formatContainerProfile(), m_audioFile.formatAudioType(), m_audioFile.formatAudioProfile(), m_audioFile.formatAudioVersion()); if(decoder) { QString tempFile = generateTempFileName(); connect(decoder, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection); connect(decoder, SIGNAL(messageLogged(QString)), this, SLOT(handleMessage(QString)), Qt::DirectConnection); bSuccess = decoder->decode(sourceFile, tempFile, &m_aborted); LAMEXP_DELETE(decoder); if(bSuccess) { sourceFile = tempFile; handleMessage("\n-------------------------------\n"); } } else {
bool WaveEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const unsigned int channels, const QString &outputFile, QAtomicInt &abortFlag) { emit messageLogged(QString("Copy file \"%1\" to \"%2\"\n").arg(sourceFile, outputFile)); callback_t callbackData = { this, &abortFlag }; emit statusUpdated(0); const bool success = MUtils::OS::copy_file(sourceFile, outputFile, true, progressCallback, &callbackData); emit statusUpdated(100); if (success) { emit messageLogged(L1S("File copied successfully.")); } else { emit messageLogged(CHECK_FLAG(abortFlag) ? L1S("Operation cancelled by user!") : L1S("Error: Failed to copy file!")); } return success; }
void UpdaterDialog::initUpdate(void) { //Clean up files from previous attempt if(!m_binaries.isEmpty()) { cleanFiles(); } //Check binary files QString wgetBin, gpgvBin; if(!checkBinaries(wgetBin, gpgvBin)) { ui->buttonCancel->setEnabled(true); const QString message = QString("%1<br><br><nobr><a href=\"%2\">%3</a></nobr><br>").arg(tr("At least one file required by the web-update tool is missing or corrupted.<br>Please re-install this application and then try again!"), QString::fromLatin1(m_updateUrl), QString::fromLatin1(m_updateUrl).replace("-", "−")); if(QMessageBox::critical(this, tr("File Error"), message, tr("Download Latest Version"), tr("Discard")) == 0) { QDesktopServices::openUrl(QUrl(QString::fromLatin1(m_updateUrl))); } close(); return; } //Make sure user does have admin access if(!MUtils::OS::user_is_admin()) { qWarning("User is not in the \"admin\" group, cannot update!"); QString message; message += QString("<nobr>%1</nobr><br>").arg(tr("Sorry, but only users in the \"Administrators\" group can install updates.")); message += QString("<nobr>%1</nobr>").arg(tr("Please start application from an administrator account and try again!")); if(QMessageBox::critical(this, this->windowTitle(), message, tr("Discard"), tr("Ignore")) != 1) { ui->buttonCancel->setEnabled(true); close(); return; } } //Create and setup thread if(!m_thread) { m_thread.reset(new MUtils::UpdateChecker(m_binaries.value("wget.exe"), m_binaries.value("gpgv.exe"), m_binaries.value("gpgv.gpg"), "Simple x264 Launcher", x264_version_build(), false)); connect(m_thread.data(), SIGNAL(statusChanged(int)), this, SLOT(threadStatusChanged(int))); connect(m_thread.data(), SIGNAL(finished()), this, SLOT(threadFinished())); connect(m_thread.data(), SIGNAL(terminated()), this, SLOT(threadFinished())); connect(m_thread.data(), SIGNAL(messageLogged(QString)), this, SLOT(threadMessageLogged(QString))); }
ProcessThread::ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, const QString &tempDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath) : m_audioFile(audioFile), m_outputDirectory(outputDirectory), m_tempDirectory(tempDirectory), m_encoder(encoder), m_jobId(QUuid::createUuid()), m_prependRelativeSourcePath(prependRelativeSourcePath), m_renamePattern("<BaseName>"), m_aborted(false) { if(m_mutex_genFileName) { m_mutex_genFileName = new QMutex; } connect(m_encoder, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection); connect(m_encoder, SIGNAL(messageLogged(QString)), this, SLOT(handleMessage(QString)), Qt::DirectConnection); m_currentStep = UnknownStep; }
void UpdateDialog::showEvent(QShowEvent *event) { QDialog::showEvent(event); if(m_firstShow) { if(!m_thread) { m_thread = new UpdateCheckThread(m_binaryWGet, m_binaryGnuPG, m_binaryKeys, m_betaUpdates); connect(m_thread, SIGNAL(statusChanged(int)), this, SLOT(threadStatusChanged(int))); connect(m_thread, SIGNAL(progressChanged(int)), this, SLOT(threadProgressChanged(int))); connect(m_thread, SIGNAL(messageLogged(QString)), this, SLOT(threadMessageLogged(QString))); connect(m_thread, SIGNAL(finished()), this, SLOT(threadFinished())); connect(m_thread, SIGNAL(terminated()), this, SLOT(threadFinished())); } threadStatusChanged(m_thread->getUpdateStatus()); ui->labelVersionInstalled->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(lamexp_version_build()), lamexp_version_date().toString(Qt::ISODate))); ui->labelVersionLatest->setText(QString("(%1)").arg(tr("Unknown"))); ui->installButton->setEnabled(false); ui->closeButton->setEnabled(false); ui->retryButton->setEnabled(false); ui->logButton->setEnabled(false); ui->retryButton->hide(); ui->logButton->hide(); ui->infoLabel->hide(); ui->hintLabel->hide(); ui->hintIcon->hide(); ui->frameAnimation->hide(); ui->progressBar->setMaximum(m_thread->getMaximumProgress()); ui->progressBar->setValue(0); m_updaterProcess = NULL; QTimer::singleShot(0, this, SLOT(updateInit())); m_firstShow = false; }
bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel_TechInfo *formatInfo, volatile bool *abortFlag) { QProcess process; QStringList args; if((m_samplingRate == formatInfo->audioSamplerate()) && (m_bitDepth == formatInfo->audioBitdepth())) { messageLogged("Skipping resample filter!"); qDebug("Resampling filter target samplerate/bitdepth is equals to the format of the input file, skipping!"); return true; } process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath()); args << "-V3" << "-S"; args << "--guard" << "--temp" << "."; args << QDir::toNativeSeparators(sourceFile); if(m_bitDepth) { args << "-b" << QString::number(m_bitDepth); } args << QDir::toNativeSeparators(outputFile); if(m_samplingRate) { args << "rate"; args << ((m_bitDepth > 16) ? "-v" : "-h"); //if resampling at/to > 16 bit depth (i.e. most commonly 24-bit), use VHQ (-v), otherwise, use HQ (-h) args << ((m_samplingRate > 40000) ? "-L" : "-I"); //if resampling to < 40k, use intermediate phase (-I), otherwise use linear phase (-L) args << QString::number(m_samplingRate); } if((m_bitDepth || m_samplingRate) && (m_bitDepth <= 16)) { 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)) { return false; } bool bTimeout = false; bool bAborted = false; QRegExp regExp("In:(\\d+)(\\.\\d+)*%"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("SoX process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok) emit statusUpdated(progress); } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0) { return false; } if(m_samplingRate) formatInfo->setAudioSamplerate(m_samplingRate); if(m_bitDepth) formatInfo->setAudioBitdepth(m_bitDepth); return true; }
AbstractFilter::FilterResult ToneAdjustFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel_TechInfo *const formatInfo, volatile bool *abortFlag) { QProcess process; QStringList args; args << "-V3" << "-S"; args << "--guard" << "--temp" << "."; args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); if(m_bass != 0) { args << "bass" << QString().sprintf("%s%.2f", ((m_bass < 0) ? "-" : "+"), static_cast<double>(abs(m_bass)) / 100.0); } if(m_treble != 0) { args << "treble" << QString().sprintf("%s%.2f", ((m_treble < 0) ? "-" : "+"), static_cast<double>(abs(m_treble)) / 100.0); } if(!startProcess(process, m_binary, args, QFileInfo(outputFile).canonicalPath())) { return AbstractFilter::FILTER_FAILURE; } bool bTimeout = false; bool bAborted = false; QRegExp regExp("In:(\\d+)(\\.\\d+)*%"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("SoX process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok) emit statusUpdated(progress); } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0) { return AbstractFilter::FILTER_FAILURE; } return AbstractFilter::FILTER_SUCCESS; }
bool FLACDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; args << "-d" << "-F" << "-f"; args << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; QRegExp regExp("\\b(\\d+)% complete"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("FLAC process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine().replace('\b', char(0x20)); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok) emit statusUpdated(progress); } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0) { return false; } return true; }
bool ShortenDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; args << "-x"; args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; //The Shorten Decoder doesn't actually send any status updates :-[ emit statusUpdated(20 + (QUuid::createUuid().data1 % 80)); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("Shorten process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit || QFileInfo(outputFile).size() == 0) { return false; } return true; }
bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; const QString baseName = QFileInfo(outputFile).fileName(); switch(m_configRCMode) { case SettingsModel::VBRMode: args << "-q" << QString().sprintf("%.2f", double(qBound(0, m_configBitrate * 5, 100)) / 100.0); break; case SettingsModel::ABRMode: args << "-br" << QString::number(qBound(8, index2bitrate(m_configBitrate), 400) * 1000); break; case SettingsModel::CBRMode: args << "-cbr" << QString::number(qBound(8, index2bitrate(m_configBitrate), 400) * 1000); break; default: THROW("Bad rate-control mode!"); break; } if(m_configEnable2Pass && (m_configRCMode == SettingsModel::ABRMode)) { args << "-2pass"; } switch(m_configProfile) { case 1: args << "-lc"; //Forces use of LC AAC profile break; case 2: args << "-he"; //Forces use of HE AAC profile break; case 3: args << "-hev2"; //Forces use of HEv2 AAC profile break; } if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << "-if" << QDir::toNativeSeparators(sourceFile); args << "-of" << QDir::toNativeSeparators(outputFile); if(!startProcess(process, m_binary_enc, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("Processed\\s+(\\d+)\\s+seconds"); QRegExp regExp_pass1("First\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"); QRegExp regExp_pass2("Second\\s+pass:\\s+processed\\s+(\\d+)\\s+seconds"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("NeroAacEnc process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp_pass1.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp_pass1.cap(1).toInt(&ok); if(ok && (duration > 0)) { int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(duration)) * 50.0); if(newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } else if(regExp_pass2.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp_pass2.cap(1).toInt(&ok); if(ok && (duration > 0)) { int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(duration)) * 50.0) + 50; if(newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } else if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (duration > 0)) { int newProgress = qRound((static_cast<double>(progress) / static_cast<double>(duration)) * 100.0); if(newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } emit messageLogged("\n-------------------------------\n"); args.clear(); args << QDir::toNativeSeparators(outputFile); if(!metaInfo.title().isEmpty()) args << QString("-meta:title=%1").arg(cleanTag(metaInfo.title())); if(!metaInfo.artist().isEmpty()) args << QString("-meta:artist=%1").arg(cleanTag(metaInfo.artist())); if(!metaInfo.album().isEmpty()) args << QString("-meta:album=%1").arg(cleanTag(metaInfo.album())); if(!metaInfo.genre().isEmpty()) args << QString("-meta:genre=%1").arg(cleanTag(metaInfo.genre())); if(!metaInfo.comment().isEmpty()) args << QString("-meta:comment=%1").arg(cleanTag(metaInfo.comment())); if(metaInfo.year()) args << QString("-meta:year=%1").arg(QString::number(metaInfo.year())); if(metaInfo.position()) args << QString("-meta:track=%1").arg(QString::number(metaInfo.position())); if(!metaInfo.cover().isEmpty()) args << QString("-add-cover:%1:%2").arg("front", metaInfo.cover()); if(!startProcess(process, m_binary_tag, args)) { return false; } bTimeout = false; while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("NeroAacTag process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool NormalizeFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel_TechInfo *formatInfo, volatile bool *abortFlag) { QProcess process; QStringList args; QString eqMode = (m_equalizationMode == 0) ? "-n" : ((m_equalizationMode == 1) ? "-ne" : "-nb"); process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath()); args << "-V3" << "-S"; args << "--temp" << "."; args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); args << "gain"; args << eqMode << QString().sprintf("%.2f", static_cast<double>(m_peakVolume) / 100.0); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; QRegExp regExp("In:(\\d+)(\\.\\d+)*%"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("SoX process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok) emit statusUpdated(progress); } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0) { return false; } return true; }
bool QAACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath()); QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.insert("PATH", QDir::toNativeSeparators(QString("%1;%1/QTfiles;%2").arg(QDir(QCoreApplication::applicationDirPath()).canonicalPath(), lamexp_temp_folder2()))); process.setProcessEnvironment(env); if(m_configRCMode != SettingsModel::VBRMode) { switch(m_configProfile) { case 2: case 3: args << "--he"; //Forces use of HE AAC profile (there is no explicit HEv2 switch for QAAC) break; } } switch(m_configRCMode) { case SettingsModel::CBRMode: args << "--cbr" << QString::number(qBound(8, index2bitrate(m_configBitrate), 576)); break; case SettingsModel::ABRMode: args << "--abr" << QString::number(qBound(8, index2bitrate(m_configBitrate), 576)); break; case SettingsModel::VBRMode: args << "--tvbr" << QString::number(g_qaacVBRQualityLUT[qBound(0, m_configBitrate , 14)]); break; default: THROW("Bad rate-control mode!"); break; } if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); if(!metaInfo.title().isEmpty()) args << "--title" << cleanTag(metaInfo.title()); if(!metaInfo.artist().isEmpty()) args << "--artist" << cleanTag(metaInfo.artist()); if(!metaInfo.album().isEmpty()) args << "--album" << cleanTag(metaInfo.album()); if(!metaInfo.genre().isEmpty()) args << "--genre" << cleanTag(metaInfo.genre()); if(!metaInfo.comment().isEmpty()) args << "--comment" << cleanTag( metaInfo.comment()); if(metaInfo.year()) args << "--date" << QString::number(metaInfo.year()); if(metaInfo.position()) args << "--track" << QString::number(metaInfo.position()); if(!metaInfo.cover().isEmpty()) args << "--artwork" << metaInfo.cover(); args << "-d" << "."; args << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary_qaac, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\[(\\d+)\\.(\\d)%\\]"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("QAAC process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool MP3Decoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; args << "-v" << "--utf8" << "-w" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\b\\d+\\+\\d+\\s+(\\d+):(\\d+)\\.(\\d+)\\+(\\d+):(\\d+)\\.(\\d+)\\b"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("mpg123 process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { quint32 values[6]; if (MUtils::regexp_parse_uint32(regExp, values, 6)) { const double timeDone = (60.0 * double(values[0])) + double(values[1]) + (double(values[2]) / 100.0); const double timeLeft = (60.0 * double(values[3])) + double(values[4]) + (double(values[5]) / 100.0); if ((timeDone >= 0.005) || (timeLeft >= 0.005)) { const int newProgress = qRound((static_cast<double>(timeDone) / static_cast<double>(timeDone + timeLeft)) * 100.0); if (newProgress > prevProgress) { emit statusUpdated(newProgress); prevProgress = qMin(newProgress + 2, 99); } } } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool OpusEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; switch(m_configRCMode) { case SettingsModel::VBRMode: args << "--vbr"; break; case SettingsModel::ABRMode: args << "--cvbr"; break; case SettingsModel::CBRMode: args << "--hard-cbr"; break; default: MUTILS_THROW("Bad rate-control mode!"); break; } args << "--comp" << QString::number(m_configEncodeComplexity); switch(m_configFrameSize) { case 0: args << "--framesize" << "2.5"; break; case 1: args << "--framesize" << "5"; break; case 2: args << "--framesize" << "10"; break; case 3: args << "--framesize" << "20"; break; case 4: args << "--framesize" << "40"; break; case 5: args << "--framesize" << "60"; break; } args << QString("--bitrate") << QString::number(qBound(8, (m_configBitrate + 1) * 8, 256)); if(!metaInfo.title().isEmpty()) args << "--title" << cleanTag(metaInfo.title()); if(!metaInfo.artist().isEmpty()) args << "--artist" << cleanTag(metaInfo.artist()); if(!metaInfo.album().isEmpty()) args << "--album" << cleanTag(metaInfo.album()); if(!metaInfo.genre().isEmpty()) args << "--genre" << cleanTag(metaInfo.genre()); if(metaInfo.year()) args << "--date" << QString::number(metaInfo.year()); if(metaInfo.position()) args << "--comment" << QString("tracknumber=%1").arg(QString::number(metaInfo.position())); if(!metaInfo.comment().isEmpty()) args << "--comment" << QString("comment=%1").arg(cleanTag(metaInfo.comment())); if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\((\\d+)%\\)"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("Opus process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) { unsigned int channels = detectChannels(sourceFile, abortFlag); emit messageLogged(QString().sprintf("--> Number of channels is: %d\n", channels)); if((channels == 1) || (channels == 2)) { messageLogged("Skipping downmix!"); qDebug("Dowmmix not required for Mono or Stereo input, skipping!"); return false; } QProcess process; QStringList args; process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath()); args << "-V3" << "-S"; args << "--guard" << "--temp" << "."; args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); switch(channels) { case 3: //3.0 (L/R/C) args << "remix" << "1v0.66,3v0.34" << "2v0.66,3v0.34"; break; case 4: //3.1 (L/R/C/LFE) args << "remix" << "1v0.5,3v0.25,4v0.25" << "2v0.5,3v0.25,4v0.25"; break; case 5: //5.0 (L/R/C/BL/BR) args << "remix" << "1v0.5,3v0.25,4v0.25" << "2v0.5,3v0.25,5v0.25"; break; case 6: //5.1 (L/R/C/LFE/BL/BR) args << "remix" << "1v0.4,3v0.2,4v0.2,5v0.2" << "2v0.4,3v0.2,4v0.2,6v0.2"; break; case 7: //7.0 (L/R/C/BL/BR/SL/SR) args << "remix" << "1v0.4,3v0.2,4v0.2,6v0.2" << "2v0.4,3v0.2,5v0.2,7v0.2"; break; case 8: //7.1 (L/R/C/LFE/BL/BR/SL/SR) args << "remix" << "1v0.36,3v0.16,4v0.16,5v0.16,7v0.16" << "2v0.36,3v0.16,4v0.16,6v0.16,8v0.16"; break; case 9: //8.1 (L/R/C/LFE/BL/BR/SL/SR/BC) args << "remix" << "1v0.308,3v0.154,4v0.154,5v0.154,7v0.154,9v0.076" << "2v0.308,3v0.154,4v0.154,6v0.154,8v0.154,9v0.076"; break; default: //Unknown qWarning("Downmixer: Unknown channel configuration!"); args << "channels" << "2"; break; } if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; QRegExp regExp("In:(\\d+)(\\.\\d+)*%"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("SoX process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok) emit statusUpdated(progress); } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit || QFileInfo(outputFile).size() == 0) { return false; } return true; }
unsigned int DownmixFilter::detectChannels(const QString &sourceFile, volatile bool *abortFlag) { unsigned int channels = 0; QProcess process; QStringList args; args << "--i" << sourceFile; if(!startProcess(process, m_binary, args)) { return channels; } bool bTimeout = false; bool bAborted = false; QRegExp regExp("Channels\\s*:\\s*(\\d+)", Qt::CaseInsensitive); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("SoX process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; unsigned int temp = regExp.cap(1).toUInt(&ok); if(ok) channels = temp; } if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } return channels; }
void GLWindow::renderNow() { if (!isExposed()) return; bool needsInitialize = false; bool enableDebug = false; if (std::getenv("BIOFORMATS_OPENGL_DEBUG")) enableDebug = true; if (!glcontext) { QSurfaceFormat format = requestedFormat(); // OpenGL 2.0 profile with debugging. format.setVersion(2, 0); format.setProfile(QSurfaceFormat::NoProfile); if (enableDebug) { format.setOption(QSurfaceFormat::DebugContext); } format.setSamples(8); format.setDepthBufferSize(24); glcontext = new QOpenGLContext(this); glcontext->setFormat(format); glcontext->create(); makeCurrent(); if (enableDebug) { // The debug logger is broken on Windows for Qt 5.2 and earlier, so don't use. #if !defined(Q_OS_WIN) || QT_VERSION >= 0x050300 logger = new QOpenGLDebugLogger(this); connect(logger, SIGNAL(messageLogged(QOpenGLDebugMessage)), this, SLOT(logMessage(QOpenGLDebugMessage)), Qt::DirectConnection); if (logger->initialize()) { logger->startLogging(QOpenGLDebugLogger::SynchronousLogging); logger->enableMessages(); } #endif // !defined(Q_OS_WIN) || QT_VERSION >= 0x050300 } needsInitialize = true; } makeCurrent(); if (needsInitialize) { initializeOpenGLFunctions(); initialize(); } render(); glcontext->swapBuffers(this); if (animating) renderLater(); }
bool ALACDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; args << "--decode"; args << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; //The ALAC Decoder doesn't actually send any status updates :-[ //emit statusUpdated(20 + (QUuid::createUuid().data1 % 60)); QRegExp regExp("\\[(\\d+)\\.(\\d)%\\]"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("ALAC process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok[2] = {false, false}; int intVal[2] = {0, 0}; intVal[0] = regExp.cap(1).toInt(&ok[0]); intVal[1] = regExp.cap(2).toInt(&ok[1]); if(ok[0] && ok[1]) { int progress = qRound(static_cast<double>(intVal[0]) + (static_cast<double>(intVal[1]) / 10.0)); if(progress > prevProgress) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0) { return false; } return true; }
bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; const QString baseName = QFileInfo(outputFile).fileName(); switch(m_configRCMode) { case SettingsModel::VBRMode: args << "-q" << QString::number(qMax(-2, qMin(10, m_configBitrate))); break; case SettingsModel::ABRMode: args << "-b" << QString::number(qMax(32, qMin(500, (m_configBitrate * 8)))); break; default: throw "Bad rate-control mode!"; break; } if((m_configBitrateMaximum > 0) && (m_configBitrateMinimum > 0) && (m_configBitrateMinimum <= m_configBitrateMaximum)) { args << "--min-bitrate" << QString::number(qMin(qMax(m_configBitrateMinimum, 32), 500)); args << "--max-bitrate" << QString::number(qMin(qMax(m_configBitrateMaximum, 32), 500)); } if(m_configSamplingRate > 0) { args << "--resample" << QString::number(m_configSamplingRate) << "--converter" << QString::number(0); } if(!metaInfo.fileName().isEmpty()) args << "-t" << metaInfo.fileName(); if(!metaInfo.fileArtist().isEmpty()) args << "-a" << metaInfo.fileArtist(); if(!metaInfo.fileAlbum().isEmpty()) args << "-l" << metaInfo.fileAlbum(); if(!metaInfo.fileGenre().isEmpty()) args << "-G" << metaInfo.fileGenre(); if(!metaInfo.fileComment().isEmpty()) args << "-c" << QString("comment=%1").arg(metaInfo.fileComment()); if(metaInfo.fileYear()) args << "-d" << QString::number(metaInfo.fileYear()); if(metaInfo.filePosition()) args << "-N" << QString::number(metaInfo.filePosition()); //args << "--tv" << QString().sprintf("Encoder=LameXP v%d.%02d.%04d [%s]", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_release()); if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\[.*(\\d+)[.,](\\d+)%\\]"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("OggEnc process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit) { return false; } return true; }
bool FLACEncoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; args << QString("-%1").arg(QString::number(qBound(0, m_configBitrate, 8))); args << "--channel-map=none"; if(!metaInfo.fileName().isEmpty()) args << "-T" << QString("title=%1").arg(cleanTag(metaInfo.fileName())); if(!metaInfo.fileArtist().isEmpty()) args << "-T" << QString("artist=%1").arg(cleanTag(metaInfo.fileArtist())); if(!metaInfo.fileAlbum().isEmpty()) args << "-T" << QString("album=%1").arg(cleanTag(metaInfo.fileAlbum())); if(!metaInfo.fileGenre().isEmpty()) args << "-T" << QString("genre=%1").arg(cleanTag(metaInfo.fileGenre())); if(!metaInfo.fileComment().isEmpty()) args << "-T" << QString("comment=%1").arg(cleanTag(metaInfo.fileComment())); if(metaInfo.fileYear()) args << "-T" << QString("date=%1").arg(QString::number(metaInfo.fileYear())); if(metaInfo.filePosition()) args << "-T" << QString("track=%1").arg(QString::number(metaInfo.filePosition())); if(!metaInfo.fileCover().isEmpty()) args << QString("--picture=%1").arg(metaInfo.fileCover()); //args << "--tv" << QString().sprintf("Encoder=LameXP v%d.%02d.%04d [%s]", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_release()); if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << "-f" << "-o" << QDir::toNativeSeparators(outputFile); args << QDir::toNativeSeparators(sourceFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("\\b(\\d+)% complete"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("FLAC process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine().replace('\b', char(0x20)); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(1).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS) { return false; } return true; }
bool AC3Encoder::encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag) { QProcess process; QStringList args; switch(m_configRCMode) { case SettingsModel::VBRMode: args << "-q" << QString::number(qMax(0, qMin(1023, m_configBitrate * 64))); break; case SettingsModel::CBRMode: args << "-b" << QString::number(SettingsModel::ac3Bitrates[qMax(0, qMin(18, m_configBitrate))]); break; default: throw "Bad rate-control mode!"; break; } if(m_configAudioCodingMode >= 1) { args << "-acmod" << QString::number(m_configAudioCodingMode - 1); } if(m_configDynamicRangeCompression != 5) { args << "-dynrng" << QString::number(m_configDynamicRangeCompression); } if(m_configExponentSearchSize != 8) { args << "-exps" << QString::number(m_configExponentSearchSize); } if(m_configFastBitAllocation) { args << "-fba" << QString::number(1); } if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); if(!startProcess(process, m_binary, args)) { return false; } bool bTimeout = false; bool bAborted = false; int prevProgress = -1; QRegExp regExp("progress:(\\s+)(\\d+)%(\\s+)\\|"); while(process.state() != QProcess::NotRunning) { if(*abortFlag) { process.kill(); bAborted = true; emit messageLogged("\nABORTED BY USER !!!"); break; } process.waitForReadyRead(m_processTimeoutInterval); if(!process.bytesAvailable() && process.state() == QProcess::Running) { process.kill(); qWarning("Aften process timed out <-- killing!"); emit messageLogged("\nPROCESS TIMEOUT !!!"); bTimeout = true; break; } while(process.bytesAvailable() > 0) { QByteArray line = process.readLine(); QString text = QString::fromUtf8(line.constData()).simplified(); if(regExp.lastIndexIn(text) >= 0) { bool ok = false; int progress = regExp.cap(2).toInt(&ok); if(ok && (progress > prevProgress)) { emit statusUpdated(progress); prevProgress = qMin(progress + 2, 99); } } else if(!text.isEmpty()) { emit messageLogged(text); } } } process.waitForFinished(); if(process.state() != QProcess::NotRunning) { process.kill(); process.waitForFinished(-1); } emit statusUpdated(100); emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode())); if(bTimeout || bAborted || process.exitStatus() != QProcess::NormalExit) { return false; } return true; }