From 8fd45dc4dd93f6f460ced0669757119a70fb0bee Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 11 Oct 2013 20:43:31 +0200 Subject: [PATCH] Split ProcessThread::start() method into ProcessThread::init() and ProcessThread::start(). --- etc/Translation/Blank.ts | 138 +++++++++++++++++------------------ etc/Translation/LameXP_EN.ts | 24 +++--- etc/Translation/LameXP_PL.ts | 138 +++++++++++++++++------------------ etc/Translation/LameXP_SV.ts | 138 +++++++++++++++++------------------ src/Config.h | 2 +- src/Dialog_Processing.cpp | 18 ++++- src/Thread_Process.cpp | 28 +++++-- src/Thread_Process.h | 5 +- 8 files changed, 258 insertions(+), 233 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index f9251035..578612fb 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -2876,143 +2876,143 @@ ProcessThread - + Starting... - + Skipped. - + Not found! - + WARNING: Decoded file size exceeds 4 GB, problems might occur! - + The format of this file is NOT supported: - + Container Format: - + Audio Format: - + Unsupported! - + Aborted! - + Done. - + Failed! - + Encoding - + Analyzing - + Filtering - + Decoding - + The source audio file could not be found: - + The source audio file could not be opened for reading: - + The target output directory doesn't exist and could NOT be created: - + The target output directory is NOT writable: - + Unknown File Name - + Unknown Title - + Unknown Artist - + Unknown Album - + Unknown Comment - + Target output file already exists, going to skip this file: - + If you don't want existing files to be skipped, please change the overwrite mode! - + Target output file already exists, going to delete existing file: - + Failed to delete existing target file, will save to another file name! @@ -3063,209 +3063,209 @@ - + Show details for selected job - + Browse Output File Location - + Filter Log Items - + Show Running Only - + Show Succeeded Only - + Show Failed Only - + Show Skipped Only - + Show All Items - + Encoding Files - + Your files are being encoded, please be patient... - + Encoding files, please wait... - + Multi-threading enabled: Running %1 instances in parallel! - + Aborted! Waiting for running jobs to terminate... - + Encoding: %n file(s) of %1 completed so far, please wait... - + Creating the playlist file, please wait... - + Process was aborted by the user after %n file(s)! - + Process was aborted prematurely by the user! - + LameXP - Aborted - + Process was aborted by the user. - + Process finished after %1. - + Error: %1 of %n file(s) failed (%2). Double-click failed items for detailed information! - + %n file(s) skipped - + Error: %1 of %n file(s) failed. Double-click failed items for detailed information! - + LameXP - Error - + At least one file has failed! - + All files completed successfully. Skipped %n file(s). - - + + All files completed successfully. - + LameXP - Done - + None of the items matches the current filtering rules - + Playlist creation failed - + The playlist file could not be created: - + Warning: Computer will shutdown in %1 seconds... - - + + Cancel Shutdown - + %n hour(s) - - + + %n minute(s) - - + + %n second(s) - + %n millisecond(s) diff --git a/etc/Translation/LameXP_EN.ts b/etc/Translation/LameXP_EN.ts index 1818b3c5..51c988d5 100644 --- a/etc/Translation/LameXP_EN.ts +++ b/etc/Translation/LameXP_EN.ts @@ -74,7 +74,7 @@ ProcessingDialog - + Encoding: %n file(s) of %1 completed so far, please wait... Encoding: %n file of %1 completed so far, please wait... @@ -82,7 +82,7 @@ - + Process was aborted by the user after %n file(s)! Process was aborted by the user after %n file! @@ -90,7 +90,7 @@ - + Error: %1 of %n file(s) failed (%2). Double-click failed items for detailed information! Error: %1 of %n file failed (%2). Double-click failed items for detailed information! @@ -98,7 +98,7 @@ - + %n file(s) skipped %n file skipped @@ -106,7 +106,7 @@ - + Error: %1 of %n file(s) failed. Double-click failed items for detailed information! Error: %1 of %n file failed. Double-click failed items for detailed information! @@ -114,7 +114,7 @@ - + All files completed successfully. Skipped %n file(s). All files completed successfully. Skipped %n file. @@ -122,7 +122,7 @@ - + %n hour(s) %n hour @@ -130,8 +130,8 @@ - - + + %n minute(s) %n minute @@ -139,8 +139,8 @@ - - + + %n second(s) %n second @@ -148,7 +148,7 @@ - + %n millisecond(s) %n millisecond diff --git a/etc/Translation/LameXP_PL.ts b/etc/Translation/LameXP_PL.ts index 0734d1e0..c1dcca51 100644 --- a/etc/Translation/LameXP_PL.ts +++ b/etc/Translation/LameXP_PL.ts @@ -2893,143 +2893,143 @@ ProcessThread - + Starting... Rozpoczynanie... - + Skipped. Pominięto. - + Not found! Nie znaleziono! - + WARNING: Decoded file size exceeds 4 GB, problems might occur! UWAGA: Plik po zdekodowaniu przekracza 4 GB, mogą wystąpić problemy! - + The format of this file is NOT supported: Format tego pliku NIE jest obsługiwany: - + Container Format: Format kontenera: - + Audio Format: Format dźwięku: - + Unsupported! Nieobsługiwany! - + Done. Zrobione. - + Aborted! Przerwano! - + Failed! Niepowodzenie! - + Encoding Kompresowanie - + Analyzing Analizowanie - + Filtering Filtrowanie - + Decoding Dekodowanie - + The source audio file could not be found: Źródłowy plik dźwiękowy nie został odnaleziony: - + The source audio file could not be opened for reading: Źródłowy plik dźwiękowy nie mógł zostać otworzony: - + The target output directory doesn't exist and could NOT be created: Lokalizacja docelowa nie istnieje lu NIE mogła zostać utworzona: - + The target output directory is NOT writable: Nie można zapisać do lokalizacji docelowej: - + Unknown File Name Nieznana nazwa pliku - + Unknown Title Nieznany Tytuł - + Unknown Artist Nieznany Artysta - + Unknown Album Nieznany Album - + Unknown Comment Nieznany Komentarz - + Target output file already exists, going to skip this file: Plik wynikowy już istnieje, zostanie pominięty plik: - + If you don't want existing files to be skipped, please change the overwrite mode! Jeśli nie chcesz aby istniejące pliki były pomijane, zmień tryb nadpisywania! - + Target output file already exists, going to delete existing file: Plik wynikowy już istnieje, zostanie usunięty plik: - + Failed to delete existing target file, will save to another file name! Usuwanie istniejącego pliku zakończone niepowodzeniem, nowy plik zostanie zapisany pod inną nazwą! @@ -3080,72 +3080,72 @@ Powrót - + Show details for selected job Pokaż szczegóły wybranego zadania - + Browse Output File Location Wybierz lokalizację dla plików wyjściowych - + Filter Log Items Filtruj długie pozycje - + Show Running Only Pokaż tylko trwające - + Show Succeeded Only Pokaż tylko zakończone pomyślnie - + Show Failed Only Pokaż tylko zakończone niepowodzeniem - + Show Skipped Only Pokaż tylko pominięte - + Show All Items Pokaż wszystkie pozycje - + Encoding Files Kompresowanie plików - + Your files are being encoded, please be patient... Twoje pliki są właśnie kompresowane, prosze być cierpliwy... - + Encoding files, please wait... Kompresowanie plików, prosze czekać... - + Multi-threading enabled: Running %1 instances in parallel! Wielowątkowosć włączona: Równolegle wykonywanych jest %1 kodowań! - + Aborted! Waiting for running jobs to terminate... Przerwano! Czekanie na wyłączenie procesu... - + Encoding: %n file(s) of %1 completed so far, please wait... Kompresowanie: %n plik z %1 został do tej pory zakończony, prosze czekać... @@ -3154,17 +3154,17 @@ - + Creating the playlist file, please wait... Tworzenie pliku playlisty, prosze czekać... - + Process was aborted prematurely by the user! Proces został przedwcześnie zakończony przez użytkownika! - + Process was aborted by the user after %n file(s)! Proces został zakończony przez użytkownika po zakończeniu %n pliku! @@ -3173,22 +3173,22 @@ - + LameXP - Aborted LameXP - Przerwano - + Process was aborted by the user. Proces został przerwany przez użytkownika. - + Process finished after %1. Proces został zakończony po %1. - + Error: %1 of %n file(s) failed (%2). Double-click failed items for detailed information! Błąd: %1 z %n pliku zakończono niepowodzeniem (%2). Kliknij dwukrotnie aby uzyskać więcej informacji! @@ -3197,7 +3197,7 @@ - + %n file(s) skipped pominięto %n plik @@ -3206,7 +3206,7 @@ - + Error: %1 of %n file(s) failed. Double-click failed items for detailed information! Błąd: %1 z %n pliku zakończono niepowodzeniem. Kliknij dwukrotnie aby uzyskać więcej informacji! @@ -3215,7 +3215,7 @@ - + All files completed successfully. Skipped %n file(s). Wszystkie zadania wykonano pomyślnie. Pominięto %n plik. @@ -3224,54 +3224,54 @@ - + LameXP - Error LameXP - Błąd - + At least one file has failed! Przynajmniej jeden plik nie został skompresowany! - - + + All files completed successfully. Kompresja wszystkich plików zakończona powodzeniem. - + LameXP - Done LameXP - Zrobione - + None of the items matches the current filtering rules Żadna z pozycji nie spełnia reguł filtra - + Playlist creation failed Tworzenie playlisty zakończone niepowodzeniem - + The playlist file could not be created: Playlista nie mogła zostać utworzona: - + Warning: Computer will shutdown in %1 seconds... Ostrzeżenie: Komputer zostanie zamknięty za %1 sekund/y... - - + + Cancel Shutdown Anuluj wyłączenie komputera - + %n hour(s) %n godzina @@ -3280,8 +3280,8 @@ - - + + %n minute(s) %n minuta @@ -3290,8 +3290,8 @@ - - + + %n second(s) %n sekunda @@ -3300,7 +3300,7 @@ - + %n millisecond(s) %n milisekunda diff --git a/etc/Translation/LameXP_SV.ts b/etc/Translation/LameXP_SV.ts index 1a59db7f..1e7b6896 100644 --- a/etc/Translation/LameXP_SV.ts +++ b/etc/Translation/LameXP_SV.ts @@ -2885,144 +2885,144 @@ ProcessThread - + Starting... Startar... - + Skipped. Överhoppad. - + Not found! Hittas ej! - + WARNING: Decoded file size exceeds 4 GB, problems might occur! VARNING! Omkodad filstorlek överstiger 4 GB. Problem kan uppstå! - + The format of this file is NOT supported: Det här filformatet saknar stöd i LameXP: - + Container Format: Behållarformat: - + Audio Format: Ljudformat: - + Unsupported! Stöd saknas! - + Aborted! Avbruten! - + Done. Klar. - + Failed! Misslyckades! - + Encoding Kodar - + Analyzing Analyserar - + Filtering Filtrerar - + Decoding Avkodar - + The source audio file could not be found: Källfilen kan inte hittas: - + The source audio file could not be opened for reading: Källfilen kan inte öppnas för läsning: - + The target output directory doesn't exist and could NOT be created: Målmappen finns inte och kan inte skapas: - + The target output directory is NOT writable: Målmappen är INTE skrivbar: - + Unknown File Name Okänt filnamn - + Unknown Title Okänd titel - + Unknown Artist Okänd artist - + Unknown Album Okänt album - + Unknown Comment Okänd kommentar - + Target output file already exists, going to skip this file: Målfilen finns redan! Den här filen hoppas över: - + If you don't want existing files to be skipped, please change the overwrite mode! Om du inte vill att befintliga filer hoppas över, måste du ändra överskrivningsläge! - + Target output file already exists, going to delete existing file: Målfilen finns redan! Befintlig fil kommer att tas bort: - + Failed to delete existing target file, will save to another file name! Kunde inte ta bort befintlig målfil. Sparar med annat filnamn! @@ -3073,72 +3073,72 @@ Stäng - + Show details for selected job Visa detaljerad info för markerad åtgärd - + Browse Output File Location Öppna utdatamnappen - + Filter Log Items Filtrera loggobjekt - + Show Running Only Visa endast aktiva - + Show Succeeded Only Visa endast klara - + Show Failed Only Visa endast misslyckade - + Show Skipped Only Visa endast överhoppade - + Show All Items Visa alla - + Encoding Files Kodar om filer - + Your files are being encoded, please be patient... Dina filer kodas om, vänta... - + Encoding files, please wait... Kodar om filer, vänta... - + Multi-threading enabled: Running %1 instances in parallel! Flertrådskörning aktiverad: Kör %1 parallella instanser! - + Aborted! Waiting for running jobs to terminate... Avbrutet! Väntar på att aktiva processer skall avslutas... - + Encoding: %n file(s) of %1 completed so far, please wait... Kodar! %n fil av%1 slutförd. vänta... @@ -3146,17 +3146,17 @@ - + Creating the playlist file, please wait... Skapar spelningslista, vänta... - + Process was aborted prematurely by the user! Åtgärden avbröts i förtid av användaren! - + Process was aborted by the user after %n file(s)! Åtgärden avbröts av användaren efter %n fil! @@ -3164,22 +3164,22 @@ - + LameXP - Aborted LameXP - Avbrutet - + Process was aborted by the user. Åtgärden avbröts av användaren. - + Process finished after %1. Åtgärden slutförd efter %1. - + Error: %1 of %n file(s) failed (%2). Double-click failed items for detailed information! Fel! %1 av %n filer misslyckades (%2). Dubbelklicka på misslyckat objekt för info! @@ -3187,7 +3187,7 @@ - + %n file(s) skipped %n fil hoppades över @@ -3195,7 +3195,7 @@ - + Error: %1 of %n file(s) failed. Double-click failed items for detailed information! Fel! %1 av %n filer misslyckades. Dubbelklicka på misslyckat objekt för info! @@ -3203,7 +3203,7 @@ - + All files completed successfully. Skipped %n file(s). Alla filer korrekt slutförda. %n fil hoppades över. @@ -3211,54 +3211,54 @@ - + LameXP - Error LameXP - Fel - + At least one file has failed! Minst en fil har misslyckats! - - + + All files completed successfully. Alla filer korrekt omkodade. - + LameXP - Done LameXP - Klar - + None of the items matches the current filtering rules Inga objekt matchar aktuell filtrering - + Playlist creation failed Kunde inte skapa spelningslista - + The playlist file could not be created: Spelningslistan kunde inte skapas: - + Warning: Computer will shutdown in %1 seconds... Varning! Datorn kommer att stängas av om %1 sekunder... - - + + Cancel Shutdown Avbryt avstängning - + %n hour(s) %n timma @@ -3266,8 +3266,8 @@ - - + + %n minute(s) %n minut @@ -3275,8 +3275,8 @@ - - + + %n second(s) %n sekund @@ -3284,7 +3284,7 @@ - + %n millisecond(s) %n millisekund diff --git a/src/Config.h b/src/Config.h index 8dd42355..408ddcd8 100644 --- a/src/Config.h +++ b/src/Config.h @@ -34,7 +34,7 @@ #define VER_LAMEXP_MINOR_LO 9 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 2 -#define VER_LAMEXP_BUILD 1372 +#define VER_LAMEXP_BUILD 1374 #define VER_LAMEXP_CONFG 1348 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 759df5a9..55f29fb2 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -545,6 +545,7 @@ void ProcessingDialog::initEncoding(void) { startNextJob(); qApp->processEvents(QEventLoop::ExcludeUserInputEvents); + QThread::yieldCurrentThread(); } m_timerStart = lamexp_perfcounter_value(); @@ -871,6 +872,8 @@ void ProcessingDialog::startNextJob(void) } m_currentFile++; + m_runningThreads++; + AudioFileModel currentFile = updateMetaInfo(m_pendingJobs.takeFirst()); bool nativeResampling = false; @@ -925,10 +928,19 @@ void ProcessingDialog::startNextJob(void) connect(thread, SIGNAL(processStateFinished(QUuid,QString,int)), this, SLOT(processFinished(QUuid,QString,int)), Qt::QueuedConnection); connect(thread, SIGNAL(processMessageLogged(QUuid,QString)), m_progressModel, SLOT(appendToLog(QUuid,QString)), Qt::QueuedConnection); connect(this, SIGNAL(abortRunningTasks()), thread, SLOT(abort()), Qt::DirectConnection); - + + + //Initialize thread object + if(!thread->init()) + { + qFatal("Fatal Error: Thread initialization has failed!"); + } + + //Update GUI + qApp->processEvents(QEventLoop::ExcludeUserInputEvents); + //Give it a go! - m_runningThreads++; - if(!thread->start(m_threadPool, QApplication::instance())) + if(!thread->start(m_threadPool)) { QTimer::singleShot(0, this, SLOT(doneEncoding())); } diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index bd20c008..1efd77b4 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -65,7 +64,7 @@ ProcessThread::ProcessThread(const AudioFileModel &audioFile, const QString &out m_renamePattern(""), m_overwriteSkipExistingFile(false), m_overwriteReplacesExisting(false), - m_initialized(false), + m_initialized(-1), m_aborted(false), m_propDetect(new WaveProperties()) { @@ -100,11 +99,11 @@ ProcessThread::~ProcessThread(void) // Init Function //////////////////////////////////////////////////////////// -bool ProcessThread::start(QThreadPool *pool, QCoreApplication *app) +bool ProcessThread::init(void) { - if(!m_initialized) + if(m_initialized < 0) { - m_initialized = true; + m_initialized = 0; //Initialize job status qDebug("Process thread %s has started.", m_jobId.toString().toLatin1().constData()); @@ -113,9 +112,22 @@ bool ProcessThread::start(QThreadPool *pool, QCoreApplication *app) //Initialize log 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"); + } - //Process pending GUI events - if(app) app->processEvents(QEventLoop::ExcludeUserInputEvents); + return true; +} + +bool ProcessThread::start(QThreadPool *pool) +{ + //Make sure object was initialized correctly + if(m_initialized < 0) + { + throw "Object not initialized yet!"; + } + + if(m_initialized < 1) + { + m_initialized = 1; //Generate output file name m_outFileName.clear(); @@ -169,7 +181,7 @@ void ProcessThread::processFile() bool bSuccess = true; //Make sure object was initialized correctly - if(!m_initialized) + if(m_initialized < 1) { throw "Object not initialized yet!"; } diff --git a/src/Thread_Process.h b/src/Thread_Process.h index 6d6d0dd1..90c974ef 100644 --- a/src/Thread_Process.h +++ b/src/Thread_Process.h @@ -41,7 +41,8 @@ public: ProcessThread(const AudioFileModel &audioFile, const QString &outputDirectory, const QString &tempDirectory, AbstractEncoder *encoder, const bool prependRelativeSourcePath); ~ProcessThread(void); - bool start(QThreadPool *pool, QCoreApplication *app = NULL); + bool init(void); + bool start(QThreadPool *pool); QUuid getId(void) { return m_jobId; } void setRenamePattern(const QString &pattern); @@ -82,7 +83,7 @@ private: void insertDownsampleFilter(void); volatile bool m_aborted; - volatile bool m_initialized; + volatile int m_initialized; const QUuid m_jobId; AudioFileModel m_audioFile;