#include "Model_Progress.h"
#include "Model_Settings.h"
#include "Thread_Process.h"
+#include "Thread_CPUObserver.h"
+#include "Thread_RAMObserver.h"
#include "Thread_DiskObserver.h"
#include "Dialog_LogView.h"
#include "Encoder_MP3.h"
#include "Encoder_Vorbis.h"
#include "Encoder_AAC.h"
+#include "Encoder_AAC_FHG.h"
#include "Encoder_AC3.h"
#include "Encoder_FLAC.h"
#include "Encoder_Wave.h"
+#include "Filter_Downmix.h"
#include "Filter_Normalize.h"
#include "Filter_Resample.h"
#include "Filter_ToneAdjust.h"
////////////////////////////////////////////////////////////
//Maximum number of parallel instances
-#define MAX_INSTANCES 16
-
-//Maximum number of CPU cores for auto-detection
-#define MAX_CPU_COUNT 4
+#define MAX_INSTANCES 16U
////////////////////////////////////////////////////////////
}
#define SET_FONT_BOLD(WIDGET,BOLD) { QFont _font = WIDGET->font(); _font.setBold(BOLD); WIDGET->setFont(_font); }
+#define UPDATE_MIN_WIDTH(WIDGET) { if(WIDGET->width() > WIDGET->minimumWidth()) WIDGET->setMinimumWidth(WIDGET->width()); }
////////////////////////////////////////////////////////////
// Constructor
m_systemTray(new QSystemTrayIcon(QIcon(":/icons/cd_go.png"), this)),
m_settings(settings),
m_metaInfo(metaInfo),
- m_shutdownFlag(false),
- m_diskObserver(NULL)
+ m_shutdownFlag(shutdownFlag_None),
+ m_diskObserver(NULL),
+ m_cpuObserver(NULL),
+ m_ramObserver(NULL)
{
//Init the dialog, from the .ui file
setupUi(this);
//Init progress indicator
m_progressIndicator = new QMovie(":/images/Working.gif");
+ m_progressIndicator->setCacheMode(QMovie::CacheAll);
+ m_progressIndicator->setSpeed(50);
label_headerWorking->setMovie(m_progressIndicator);
progressBar->setValue(0);
view_log->verticalHeader()->hide();
view_log->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
view_log->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
+ view_log->viewport()->installEventFilter(this);
connect(m_progressModel, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(progressModelChanged()));
connect(m_progressModel, SIGNAL(modelReset()), this, SLOT(progressModelChanged()));
connect(view_log, SIGNAL(activated(QModelIndex)), this, SLOT(logViewDoubleClicked(QModelIndex)));
+ connect(view_log->horizontalHeader(), SIGNAL(sectionResized(int,int,int)), this, SLOT(logViewSectionSizeChanged(int,int,int)));
//Create context menu
m_contextMenu = new QMenu();
if(m_diskObserver)
{
m_diskObserver->stop();
- m_diskObserver->wait(15000);
+ if(!m_diskObserver->wait(15000))
+ {
+ m_diskObserver->terminate();
+ m_diskObserver->wait();
+ }
+ }
+ if(m_cpuObserver)
+ {
+ m_cpuObserver->stop();
+ if(!m_cpuObserver->wait(15000))
+ {
+ m_cpuObserver->terminate();
+ m_cpuObserver->wait();
+ }
+ }
+ if(m_ramObserver)
+ {
+ m_ramObserver->stop();
+ if(!m_ramObserver->wait(15000))
+ {
+ m_ramObserver->terminate();
+ m_ramObserver->wait();
+ }
}
LAMEXP_DELETE(m_progressIndicator);
LAMEXP_DELETE(m_contextMenu);
LAMEXP_DELETE(m_systemTray);
LAMEXP_DELETE(m_diskObserver);
+ LAMEXP_DELETE(m_cpuObserver);
+ LAMEXP_DELETE(m_ramObserver);
WinSevenTaskbar::setOverlayIcon(this, NULL);
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNoState);
void ProcessingDialog::showEvent(QShowEvent *event)
{
+ static const char *NA = " N/A";
+
setCloseButtonEnabled(false);
button_closeDialog->setEnabled(false);
button_AbortProcess->setEnabled(false);
SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
}
+ label_cpu->setText(NA);
+ label_disk->setText(NA);
+ label_ram->setText(NA);
+
QTimer::singleShot(1000, this, SLOT(initEncoding()));
}
return false;
}
+bool ProcessingDialog::winEvent(MSG *message, long *result)
+{
+ return WinSevenTaskbar::handleWinEvent(message, result);
+}
+
////////////////////////////////////////////////////////////
// SLOTS
////////////////////////////////////////////////////////////
checkBox_shutdownComputer->setEnabled(true);
checkBox_shutdownComputer->setChecked(false);
- WinSevenTaskbar::initTaskbar();
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
WinSevenTaskbar::setTaskbarProgress(this, 0, m_pendingJobs.count());
WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/control_play_blue.png"));
{
m_diskObserver = new DiskObserverThread(m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2());
connect(m_diskObserver, SIGNAL(messageLogged(QString,bool)), m_progressModel, SLOT(addSystemMessage(QString,bool)), Qt::QueuedConnection);
+ connect(m_diskObserver, SIGNAL(freeSpaceChanged(quint64)), this, SLOT(diskUsageHasChanged(quint64)), Qt::QueuedConnection);
m_diskObserver->start();
}
+ if(!m_cpuObserver)
+ {
+ m_cpuObserver = new CPUObserverThread();
+ connect(m_cpuObserver, SIGNAL(currentUsageChanged(double)), this, SLOT(cpuUsageHasChanged(double)), Qt::QueuedConnection);
+ m_cpuObserver->start();
+ }
+ if(!m_ramObserver)
+ {
+ m_ramObserver = new RAMObserverThread();
+ connect(m_ramObserver, SIGNAL(currentUsageChanged(double)), this, SLOT(ramUsageHasChanged(double)), Qt::QueuedConnection);
+ m_ramObserver->start();
+ }
- int maximumInstances = max(min(m_settings->maximumInstances(), MAX_INSTANCES), 0);
+ unsigned int maximumInstances = qBound(0U, m_settings->maximumInstances(), MAX_INSTANCES);
if(maximumInstances < 1)
{
lamexp_cpu_t cpuFeatures = lamexp_detect_cpu_features();
- maximumInstances = max(min(cpuFeatures.count, MAX_CPU_COUNT), 1);
+ maximumInstances = (cpuFeatures.count > 4) ? ((cpuFeatures.count / 2) + 2) : cpuFeatures.count;
}
- int parallelThreadCount = max(min(maximumInstances, m_pendingJobs.count()), 1);
+ unsigned int parallelThreadCount = qBound(1U, maximumInstances, static_cast<unsigned int>(m_pendingJobs.count()));
if(parallelThreadCount > 1)
{
m_progressModel->addSystemMessage(tr("Multi-threading enabled: Running %1 instances in parallel!").arg(QString::number(parallelThreadCount)));
}
- for(int i = 0; i < parallelThreadCount; i++)
+ for(unsigned int i = 0; i < parallelThreadCount; i++)
{
startNextJob();
}
button_AbortProcess->setEnabled(false);
checkBox_shutdownComputer->setEnabled(false);
+ m_progressModel->restoreHiddenItems();
view_log->scrollToBottom();
m_progressIndicator->stop();
progressBar->setValue(progressBar->maximum());
{
if(shutdownComputer())
{
- m_shutdownFlag = true;
+ m_shutdownFlag = m_settings->hibernateComputer() ? shutdownFlag_Hibernate : shutdownFlag_TurnPowerOff;
accept();
}
}
}
}
+void ProcessingDialog::logViewSectionSizeChanged(int logicalIndex, int oldSize, int newSize)
+{
+ if(logicalIndex == 1)
+ {
+ if(QHeaderView *hdr = view_log->horizontalHeader())
+ {
+ hdr->setMinimumSectionSize(qMax(hdr->minimumSectionSize(), hdr->sectionSize(1)));
+ }
+ }
+}
+
void ProcessingDialog::contextMenuTriggered(const QPoint &pos)
{
QAbstractScrollArea *scrollArea = dynamic_cast<QAbstractScrollArea*>(QObject::sender());
void ProcessingDialog::contextMenuDetailsActionTriggered(void)
{
- QModelIndex index = view_log->indexAt(view_log->mapFromGlobal(m_contextMenu->pos()));
+ QModelIndex index = view_log->indexAt(view_log->viewport()->mapFromGlobal(m_contextMenu->pos()));
logViewDoubleClicked(index.isValid() ? index : view_log->currentIndex());
}
void ProcessingDialog::contextMenuShowFileActionTriggered(void)
{
- QModelIndex index = view_log->indexAt(view_log->mapFromGlobal(m_contextMenu->pos()));
+ QModelIndex index = view_log->indexAt(view_log->viewport()->mapFromGlobal(m_contextMenu->pos()));
const QUuid &jobId = m_progressModel->getJobId(index.isValid() ? index : view_log->currentIndex());
QString filePath = m_playList.value(jobId, QString());
AbstractEncoder *encoder = NULL;
bool nativeResampling = false;
+ //Create encoder instance
switch(m_settings->compressionEncoder())
{
case SettingsModel::MP3Encoder:
break;
case SettingsModel::AACEncoder:
{
- AACEncoder *aacEncoder = new AACEncoder();
- aacEncoder->setBitrate(m_settings->compressionBitrate());
- aacEncoder->setRCMode(m_settings->compressionRCMode());
- aacEncoder->setEnable2Pass(m_settings->neroAACEnable2Pass());
- aacEncoder->setProfile(m_settings->neroAACProfile());
- aacEncoder->setCustomParams(m_settings->customParametersNeroAAC());
- encoder = aacEncoder;
+ if(lamexp_check_tool("fhgaacenc.exe") && lamexp_check_tool("enc_fhgaac.dll"))
+ {
+ FHGAACEncoder *aacEncoder = new FHGAACEncoder();
+ aacEncoder->setBitrate(m_settings->compressionBitrate());
+ aacEncoder->setRCMode(m_settings->compressionRCMode());
+ aacEncoder->setProfile(m_settings->aacEncProfile());
+ aacEncoder->setCustomParams(m_settings->customParametersAacEnc());
+ encoder = aacEncoder;
+ }
+ else
+ {
+ AACEncoder *aacEncoder = new AACEncoder();
+ aacEncoder->setBitrate(m_settings->compressionBitrate());
+ aacEncoder->setRCMode(m_settings->compressionRCMode());
+ aacEncoder->setEnable2Pass(m_settings->neroAACEnable2Pass());
+ aacEncoder->setProfile(m_settings->aacEncProfile());
+ aacEncoder->setCustomParams(m_settings->customParametersAacEnc());
+ encoder = aacEncoder;
+ }
}
break;
case SettingsModel::AC3Encoder:
throw "Unsupported encoder!";
}
+ //Create processing thread
ProcessThread *thread = new ProcessThread
(
currentFile,
(m_settings->outputToSourceDir() ? QFileInfo(currentFile.filePath()).absolutePath() : m_settings->outputDir()),
(m_settings->customTempPathEnabled() ? m_settings->customTempPath() : lamexp_temp_folder2()),
encoder,
- m_settings->prependRelativeSourcePath()
+ m_settings->prependRelativeSourcePath() && (!m_settings->outputToSourceDir())
);
+ //Add audio filters
+ if(m_settings->forceStereoDownmix())
+ {
+ thread->addFilter(new DownmixFilter());
+ }
if((m_settings->samplingRate() > 0) && !nativeResampling)
{
if(SettingsModel::samplingRates[m_settings->samplingRate()] != currentFile.formatAudioSamplerate() || currentFile.formatAudioSamplerate() == 0)
}
if(m_settings->normalizationFilterEnabled())
{
- thread->addFilter(new NormalizeFilter(m_settings->normalizationFilterMaxVolume()));
+ thread->addFilter(new NormalizeFilter(m_settings->normalizationFilterMaxVolume(), m_settings->normalizationFilterEqualizationMode()));
+ }
+ if(m_settings->renameOutputFilesEnabled() && (!m_settings->renameOutputFilesPattern().simplified().isEmpty()))
+ {
+ thread->setRenamePattern(m_settings->renameOutputFilesPattern());
}
m_threadList.append(thread);
m_allJobs.append(thread->getId());
+ //Connect thread signals
connect(thread, SIGNAL(finished()), this, SLOT(doneEncoding()), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateInitialized(QUuid,QString,QString,int)), m_progressModel, SLOT(addJob(QUuid,QString,QString,int)), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateChanged(QUuid,QString,int)), m_progressModel, SLOT(updateJob(QUuid,QString,int)), Qt::QueuedConnection);
connect(thread, SIGNAL(processStateFinished(QUuid,QString,bool)), this, SLOT(processFinished(QUuid,QString,bool)), Qt::QueuedConnection);
connect(thread, SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel, SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection);
+ //Give it a go!
m_runningThreads++;
thread->start();
}
return;
}
+ //Init local variables
+ QStringList list;
+ QRegExp regExp1("\\[\\d\\d\\][^/\\\\]+$", Qt::CaseInsensitive);
+ QRegExp regExp2("\\(\\d\\d\\)[^/\\\\]+$", Qt::CaseInsensitive);
+ QRegExp regExp3("\\d\\d[^/\\\\]+$", Qt::CaseInsensitive);
+ bool usePrefix[3] = {true, true, true};
+ bool useUtf8 = false;
+ int counter = 1;
+
+ //Generate playlist name
QString playListName = (m_metaInfo->fileAlbum().isEmpty() ? "Playlist" : m_metaInfo->fileAlbum());
+ if(!m_metaInfo->fileArtist().isEmpty())
+ {
+ playListName = QString("%1 - %2").arg(m_metaInfo->fileArtist(), playListName);
+ }
+
+ //Clean playlist name
+ playListName = lamexp_clean_filename(playListName);
- const static char *invalidChars = "\\/:*?\"<>|";
- for(int i = 0; invalidChars[i]; i++)
+ //Create list of audio files
+ for(int i = 0; i < m_allJobs.count(); i++)
{
- playListName.replace(invalidChars[i], ' ');
- playListName = playListName.simplified();
+ if(!m_succeededJobs.contains(m_allJobs.at(i))) continue;
+ list << QDir::toNativeSeparators(QDir(m_settings->outputDir()).relativeFilePath(m_playList.value(m_allJobs.at(i), "N/A")));
}
-
- QString playListFile = QString("%1/%2.m3u").arg(m_settings->outputDir(), playListName);
- int counter = 1;
+ //Use prefix?
+ for(int i = 0; i < list.count(); i++)
+ {
+ if(regExp1.indexIn(list.at(i)) < 0) usePrefix[0] = false;
+ if(regExp2.indexIn(list.at(i)) < 0) usePrefix[1] = false;
+ if(regExp3.indexIn(list.at(i)) < 0) usePrefix[2] = false;
+ }
+ if(usePrefix[0] || usePrefix[1] || usePrefix[2])
+ {
+ playListName.prepend(usePrefix[0] ? "[00] " : (usePrefix[1] ? "(00) " : "00 "));
+ }
+
+ //Do we need an UTF-8 playlist?
+ for(int i = 0; i < list.count(); i++)
+ {
+ if(wcscmp(QWCHAR(QString::fromLatin1(list.at(i).toLatin1().constData())), QWCHAR(list.at(i))))
+ {
+ useUtf8 = true;
+ break;
+ }
+ }
+
+ //Generate playlist output file
+ QString playListFile = QString("%1/%2.%3").arg(m_settings->outputDir(), playListName, (useUtf8 ? "m3u8" : "m3u"));
while(QFileInfo(playListFile).exists())
{
- playListFile = QString("%1/%2 (%3).m3u").arg(m_settings->outputDir(), playListName, QString::number(++counter));
+ playListFile = QString("%1/%2 (%3).%4").arg(m_settings->outputDir(), playListName, QString::number(++counter), (useUtf8 ? "m3u8" : "m3u"));
}
+ //Now write playlist to output file
QFile playList(playListFile);
if(playList.open(QIODevice::WriteOnly))
{
+ if(useUtf8)
+ {
+ playList.write("\xef\xbb\xbf");
+ }
playList.write("#EXTM3U\r\n");
- for(int i = 0; i < m_allJobs.count(); i++)
+ while(!list.isEmpty())
{
-
- if(!m_succeededJobs.contains(m_allJobs.at(i))) continue;
- playList.write(QDir::toNativeSeparators(QDir(m_settings->outputDir()).relativeFilePath(m_playList.value(m_allJobs.at(i), "N/A"))).toUtf8().constData());
+ playList.write(useUtf8 ? list.takeFirst().toUtf8().constData() : list.takeFirst().toLatin1().constData());
playList.write("\r\n");
}
playList.close();
}
}
+void ProcessingDialog::cpuUsageHasChanged(const double val)
+{
+
+ this->label_cpu->setText(QString().sprintf(" %d%%", qRound(val * 100.0)));
+ UPDATE_MIN_WIDTH(label_cpu);
+}
+
+void ProcessingDialog::ramUsageHasChanged(const double val)
+{
+
+ this->label_ram->setText(QString().sprintf(" %d%%", qRound(val * 100.0)));
+ UPDATE_MIN_WIDTH(label_ram);
+}
+
+void ProcessingDialog::diskUsageHasChanged(const quint64 val)
+{
+ int postfix = 0;
+ const char *postfixStr[6] = {"B", "KB", "MB", "GB", "TB", "PB"};
+ double space = static_cast<double>(val);
+
+ while((space >= 1000.0) && (postfix < 5))
+ {
+ space = space / 1024.0;
+ postfix++;
+ }
+
+ this->label_disk->setText(QString().sprintf(" %3.1f %s", space, postfixStr[postfix]));
+ UPDATE_MIN_WIDTH(label_disk);
+}
+
bool ProcessingDialog::shutdownComputer(void)
{
- const int iTimeout = 30;
+ const int iTimeout = m_settings->hibernateComputer() ? 10 : 30;
const Qt::WindowFlags flags = Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint | Qt::WindowSystemMenuHint;
const QString text = QString("%1%2%1").arg(QString().fill(' ', 18), tr("Warning: Computer will shutdown in %1 seconds..."));
progressDialog.close();
return true;
-}
+}
\ No newline at end of file