diff --git a/LameXP_VS2010.vcxproj b/LameXP_VS2010.vcxproj index 4725119a..9c3e62f8 100644 --- a/LameXP_VS2010.vcxproj +++ b/LameXP_VS2010.vcxproj @@ -280,6 +280,7 @@ del "$(TargetDir)imageformats\q???d4.dll" + @@ -314,6 +315,7 @@ del "$(TargetDir)imageformats\q???d4.dll" + @@ -364,6 +366,17 @@ del "$(TargetDir)imageformats\q???d4.dll" $(SolutionDir)tmp\MOC_%(Filename).cpp;%(Outputs) $(SolutionDir)tmp\MOC_%(Filename).cpp;%(Outputs) + + "$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_%(Filename).cpp" "%(FullPath)" + "$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_%(Filename).cpp" "%(FullPath)" + "$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_%(Filename).cpp" "%(FullPath)" + MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp" + MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp" + MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp" + $(SolutionDir)tmp\MOC_%(Filename).cpp;%(Outputs) + $(SolutionDir)tmp\MOC_%(Filename).cpp;%(Outputs) + $(SolutionDir)tmp\MOC_%(Filename).cpp;%(Outputs) + diff --git a/LameXP_VS2010.vcxproj.filters b/LameXP_VS2010.vcxproj.filters index a5fbdcd7..dc022bfe 100644 --- a/LameXP_VS2010.vcxproj.filters +++ b/LameXP_VS2010.vcxproj.filters @@ -301,6 +301,12 @@ Generated Files\MOC + + Source Files\Threads + + + Generated Files\MOC + @@ -569,6 +575,9 @@ Header Files\Models + + Header Files\Threads + diff --git a/doc/Changelog.html b/doc/Changelog.html index 018b34b7..aa29f669 100644 --- a/doc/Changelog.html +++ b/doc/Changelog.html @@ -19,6 +19,7 @@ a:visited { color: #0000EE; } Changes between v4.01 and v4.02:
  • Upgraded build environment to Microsoft Visual Studio 2010
  • Dropping support for Windows 2000 and for Windows XP RTM/SP1, Windows XP needs SP2 or SP3 now! +
  • Added Cue Sheet import wizard, only uncompressed Wave/PCM files are suppported at the moment
  • Added ATSC A/52 (AC-3) encoding support, based on Aften encoder v0.0.8+ (Git Master)
  • Added one new translation: Korean
  • Added a method to use custom tools instead of the "built-in" ones (see FAQ doc for details) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index e8277f34..fae5335f 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + + DecoderRegistry diff --git a/etc/Translation/LameXP_DE.ts b/etc/Translation/LameXP_DE.ts index 591f21d5..78c71abd 100644 --- a/etc/Translation/LameXP_DE.ts +++ b/etc/Translation/LameXP_DE.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + Warnung: Wenig freier Festplattenspeicher + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard Schließen + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + Dauer + DecoderRegistry diff --git a/etc/Translation/LameXP_ES.ts b/etc/Translation/LameXP_ES.ts index 09e9db73..5f2eb955 100644 --- a/etc/Translation/LameXP_ES.ts +++ b/etc/Translation/LameXP_ES.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + Alerta de poco espacio en disco + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + Duración + DecoderRegistry diff --git a/etc/Translation/LameXP_FR.ts b/etc/Translation/LameXP_FR.ts index 52cd9c84..63b5ebd3 100644 --- a/etc/Translation/LameXP_FR.ts +++ b/etc/Translation/LameXP_FR.ts @@ -261,18 +261,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -281,6 +269,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + Avertissement d'espace disque faible + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -300,6 +344,14 @@ Discard Abandonner + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -331,6 +383,10 @@ Unknown Title + + Duration + Durée + DecoderRegistry diff --git a/etc/Translation/LameXP_IT.ts b/etc/Translation/LameXP_IT.ts index e70a9081..43f4b88f 100644 --- a/etc/Translation/LameXP_IT.ts +++ b/etc/Translation/LameXP_IT.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + Attenzione: Poco spazio su disco + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard Annulla + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + Durata + DecoderRegistry diff --git a/etc/Translation/LameXP_KR.ts b/etc/Translation/LameXP_KR.ts index 6a6b3080..f3ae76cd 100644 --- a/etc/Translation/LameXP_KR.ts +++ b/etc/Translation/LameXP_KR.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + 디스크 공간 부족 알림 + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard 닫기 + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + 길이 + DecoderRegistry diff --git a/etc/Translation/LameXP_RU.ts b/etc/Translation/LameXP_RU.ts index d8d96de5..7181c092 100644 --- a/etc/Translation/LameXP_RU.ts +++ b/etc/Translation/LameXP_RU.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + Предупреждение: Мало свободного места на диске + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard Отменить + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + Длителность + DecoderRegistry diff --git a/etc/Translation/LameXP_UK.ts b/etc/Translation/LameXP_UK.ts index 620abed1..e577d303 100644 --- a/etc/Translation/LameXP_UK.ts +++ b/etc/Translation/LameXP_UK.ts @@ -257,18 +257,6 @@ An unknown error has occured! - - The file could not be opened for reading! - - - - The file does not look like a valid Cue Sheet disc image file! - - - - Could not find a supported audio track in the Cue Sheet! - - Failed to load the Cue Sheet file: @@ -277,6 +265,62 @@ Cue Sheet Error + + The specified file could not be found! + + + + The file could not be opened for reading. Make sure you have the required rights! + + + + The provided file does not look like a valid Cue Sheet disc image file! + + + + Could not find any supported audio track in the Cue Sheet image! + + + + Note that LameXP can not handle "binary" Cue Sheet images. + + + + The selected Cue Sheet file contains inconsistent information. Take care! + + + + Choose Output Directory + + + + LameXP + LameXP + + + Error: The selected output directory is not writable! + + + + Low Diskspace Warning + Попередження про те, що недостатньо місця на диску + + + There are less than %1 GB of free diskspace available in the selected output directory. + + + + It is highly recommend to free up more diskspace before proceeding with the import! + + + + Analyzing file(s), please wait... + + + + Splitting file(s), please wait... + + CueSheetImport @@ -296,6 +340,14 @@ Discard Відмінити + + Existing Source File + + + + Missing Source File (Tracks will be skipped!) + + CueSheetModel @@ -327,6 +379,10 @@ Unknown Title + + Duration + Тривалість + DecoderRegistry diff --git a/res/localization/LameXP_DE.qm b/res/localization/LameXP_DE.qm index fb7d81fc..6efffd57 100644 Binary files a/res/localization/LameXP_DE.qm and b/res/localization/LameXP_DE.qm differ diff --git a/res/localization/LameXP_ES.qm b/res/localization/LameXP_ES.qm index 0ab8505b..d37c7224 100644 Binary files a/res/localization/LameXP_ES.qm and b/res/localization/LameXP_ES.qm differ diff --git a/res/localization/LameXP_FR.qm b/res/localization/LameXP_FR.qm index f2d4b746..b902e77e 100644 Binary files a/res/localization/LameXP_FR.qm and b/res/localization/LameXP_FR.qm differ diff --git a/res/localization/LameXP_IT.qm b/res/localization/LameXP_IT.qm index 651f2f86..6d156327 100644 Binary files a/res/localization/LameXP_IT.qm and b/res/localization/LameXP_IT.qm differ diff --git a/res/localization/LameXP_KR.qm b/res/localization/LameXP_KR.qm index 80ef04e7..a5202191 100644 Binary files a/res/localization/LameXP_KR.qm and b/res/localization/LameXP_KR.qm differ diff --git a/res/localization/LameXP_RU.qm b/res/localization/LameXP_RU.qm index 6eadece4..5dfd160a 100644 Binary files a/res/localization/LameXP_RU.qm and b/res/localization/LameXP_RU.qm differ diff --git a/res/localization/LameXP_UK.qm b/res/localization/LameXP_UK.qm index 4217f36b..b6a52a74 100644 Binary files a/res/localization/LameXP_UK.qm and b/res/localization/LameXP_UK.qm differ diff --git a/src/Config.h b/src/Config.h index 10c2c019..9b97d6fd 100644 --- a/src/Config.h +++ b/src/Config.h @@ -29,8 +29,8 @@ #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 2 #define VER_LAMEXP_TYPE Alpha -#define VER_LAMEXP_PATCH 14 -#define VER_LAMEXP_BUILD 515 +#define VER_LAMEXP_PATCH 15 +#define VER_LAMEXP_BUILD 520 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index 3a2c0fc1..64bb5296 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -24,8 +24,11 @@ #include "Global.h" #include "Model_CueSheet.h" #include "Model_AudioFile.h" +#include "Model_FileList.h" #include "Dialog_WorkingBanner.h" #include "Thread_FileAnalyzer.h" +#include "Thread_CueSplitter.h" +#include "LockedFile.h" #include #include @@ -40,9 +43,11 @@ // Constructor & Destructor //////////////////////////////////////////////////////////// -CueImportDialog::CueImportDialog(QWidget *parent) +CueImportDialog::CueImportDialog(QWidget *parent, FileListModel *fileList, const QString &cueFile) : - QDialog(parent) + QDialog(parent), + m_cueFileName(cueFile), + m_fileList(fileList) { //Init the dialog, from the .ui file setupUi(this); @@ -90,26 +95,33 @@ void CueImportDialog::showEvent(QShowEvent *event) // Slots //////////////////////////////////////////////////////////// -int CueImportDialog::exec(const QString &cueFile) +int CueImportDialog::exec(void) { WorkingBanner *progress = new WorkingBanner(dynamic_cast(parent())); progress->show(tr("Loading Cue Sheet file, please be patient...")); - - QFileInfo cueFileInfo(cueFile); - m_outputDir = QFileInfo(cueFile).canonicalPath(); + + QFileInfo cueFileInfo(m_cueFileName); + QDir outputDir(cueFileInfo.canonicalPath()); + m_outputDir = outputDir.canonicalPath(); setWindowTitle(QString("%1: %2").arg(windowTitle().split(":", QString::SkipEmptyParts).first().trimmed(), cueFileInfo.fileName())); if(!cueFileInfo.exists() || !cueFileInfo.isFile() || m_outputDir.isEmpty()) { - QString text = QString("%1
    %2

    %3").arg(tr("Failed to load the Cue Sheet file:"), QDir::toNativeSeparators(cueFile), tr("The specified file could not be found!")).replace("-", "−"); + QString text = QString("%1
    %2

    %3").arg(tr("Failed to load the Cue Sheet file:"), QDir::toNativeSeparators(m_cueFileName), tr("The specified file could not be found!")).replace("-", "−"); QMessageBox::warning(progress, tr("Cue Sheet Error"), text); progress->close(); LAMEXP_DELETE(progress); return CueSheetModel::ErrorIOFailure; } - int iResult = m_model->loadCueSheet(cueFile, QApplication::instance()); + outputDir.mkdir(cueFileInfo.completeBaseName()); + if(outputDir.cd(cueFileInfo.completeBaseName())) + { + m_outputDir = outputDir.canonicalPath(); + } + + int iResult = m_model->loadCueSheet(m_cueFileName, QApplication::instance()); if(iResult != CueSheetModel::ErrorSuccess) { QString errorMsg = tr("An unknown error has occured!"); @@ -130,7 +142,7 @@ int CueImportDialog::exec(const QString &cueFile) break; } - QString text = QString("%1
    %2

    %3").arg(tr("Failed to load the Cue Sheet file:"), QDir::toNativeSeparators(cueFile), errorMsg).replace("-", "−"); + QString text = QString("%1
    %2

    %3").arg(tr("Failed to load the Cue Sheet file:"), QDir::toNativeSeparators(m_cueFileName), errorMsg).replace("-", "−"); QMessageBox::warning(progress, tr("Cue Sheet Error"), text); progress->close(); LAMEXP_DELETE(progress); @@ -184,31 +196,51 @@ void CueImportDialog::importButtonClicked(void) } importCueSheet(); + accept(); } void CueImportDialog::analyzedFile(const AudioFileModel &file) { - qWarning("Received results for: %s", file.filePath().toLatin1().constData()); - m_fileInfo.insert(file.filePath(), file); + qDebug("Received result: <%s> <%s/%s>", file.filePath().toLatin1().constData(), file.formatContainerType().toLatin1().constData(), file.formatAudioType().toLatin1().constData()); + m_fileInfo << file; } //////////////////////////////////////////////////////////// -// Private FUnctions +// Private Functions //////////////////////////////////////////////////////////// void CueImportDialog::importCueSheet(void) { QStringList files; - int nFiles = m_model->getFileCount(); - //Fetch all files that are referenced in the Cue Sheet + //Fetch all files that are referenced in the Cue Sheet and lock them + int nFiles = m_model->getFileCount(); for(int i = 0; i < nFiles; i++) { - files << m_model->getFileName(i); + QString temp = m_model->getFileName(i); + try + { + m_locks << new LockedFile(temp); + } + catch(char *err) + { + qWarning("Failed to lock file: %s", err); + continue; + } + files << temp; } //Analyze all source files analyzeFiles(files); + + //Now split files according to Cue Sheet + splitFiles(); + + //Release locks + while(!m_locks.isEmpty()) + { + delete m_locks.takeFirst(); + } } void CueImportDialog::analyzeFiles(QStringList &files) @@ -217,10 +249,54 @@ void CueImportDialog::analyzeFiles(QStringList &files) WorkingBanner *progress = new WorkingBanner(dynamic_cast(parent())); FileAnalyzer *analyzer = new FileAnalyzer(files); + connect(analyzer, SIGNAL(fileSelected(QString)), progress, SLOT(setText(QString)), Qt::QueuedConnection); connect(analyzer, SIGNAL(fileAnalyzed(AudioFileModel)), this, SLOT(analyzedFile(AudioFileModel)), Qt::QueuedConnection); - progress->show(tr("Adding file(s), please wait..."), analyzer); + progress->show(tr("Analyzing file(s), please wait..."), analyzer); progress->close(); LAMEXP_DELETE(progress); } + +void CueImportDialog::splitFiles(void) +{ + WorkingBanner *progress = new WorkingBanner(this); + CueSplitter *splitter = new CueSplitter(m_outputDir, QFileInfo(m_cueFileName).completeBaseName().replace(".", " ").left(42).trimmed(), m_fileInfo); + + connect(splitter, SIGNAL(fileSelected(QString)), progress, SLOT(setText(QString)), Qt::QueuedConnection); + connect(splitter, SIGNAL(fileSplit(AudioFileModel)), m_fileList, SLOT(addFile(AudioFileModel)), Qt::QueuedConnection); + + int nFiles = m_model->getFileCount(); + for(int i = 0; i < nFiles; i++) + { + QString currentFileName = m_model->getFileName(i); + int nTracks = m_model->getTrackCount(i); + + for(int j = 0; j < nTracks; j++) + { + int trackNo = m_model->getTrackNo(i, j); + double startIndex = std::numeric_limits::quiet_NaN(); + double duration = std::numeric_limits::quiet_NaN(); + m_model->getTrackIndex(i, j, &startIndex, &duration); + + AudioFileModel metaInfo(QString().sprintf("cue://File%02d/Track%02d", i, j)); + metaInfo.setFileName(m_model->getTrackTitle(i, j)); + metaInfo.setFileArtist(m_model->getTrackPerformer(i, j)); + + try + { + splitter->addTrack(trackNo, currentFileName, startIndex, duration, metaInfo); + } + catch(char *err) + { + qWarning("Failed to add track #%02d: %s", trackNo, err); + } + } + } + + progress->show(tr("Splitting file(s), please wait..."), splitter); + progress->close(); + + LAMEXP_DELETE(splitter); + LAMEXP_DELETE(progress); +} diff --git a/src/Dialog_CueImport.h b/src/Dialog_CueImport.h index 5fc542de..523306ab 100644 --- a/src/Dialog_CueImport.h +++ b/src/Dialog_CueImport.h @@ -27,16 +27,18 @@ #include "Model_AudioFile.h" class CueSheetModel; +class LockedFile; +class FileListModel; class CueImportDialog : public QDialog, private Ui::CueSheetImport { Q_OBJECT public: - CueImportDialog(QWidget *parent); + CueImportDialog(QWidget *parent, FileListModel *fileList, const QString &cueFile); ~CueImportDialog(void); - int exec(const QString &cueFile); + int exec(void); protected: void CueImportDialog::showEvent(QShowEvent *event); @@ -50,8 +52,13 @@ private slots: private: void importCueSheet(void); void analyzeFiles(QStringList &files); + void CueImportDialog::splitFiles(void); CueSheetModel *m_model; - QMap m_fileInfo; + FileListModel *m_fileList; + + QList m_locks; + QList m_fileInfo; + QString m_cueFileName; QString m_outputDir; }; diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 1aa069bc..baec9ad6 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -2571,8 +2571,8 @@ void MainWindow::importCueSheetActionTriggered(bool checked) QString selectedCueFile = QFileDialog::getOpenFileName(this, tr("Open Cue Sheet"), QString(), QString("%1 (*.cue)").arg(tr("Cue Sheet File"))); if(!selectedCueFile.isEmpty()) { - CueImportDialog *cueImporter = new CueImportDialog(this); - cueImporter->exec(selectedCueFile); + CueImportDialog *cueImporter = new CueImportDialog(this, m_fileListModel, selectedCueFile); + cueImporter->exec(); LAMEXP_DELETE(cueImporter); } ) diff --git a/src/Model_CueSheet.cpp b/src/Model_CueSheet.cpp index 91e89121..4a9a9f79 100644 --- a/src/Model_CueSheet.cpp +++ b/src/Model_CueSheet.cpp @@ -346,6 +346,20 @@ int CueSheetModel::getTrackCount(int fileIndex) return m_files.at(fileIndex)->trackCount(); } +int CueSheetModel::getTrackNo(int fileIndex, int trackIndex) +{ + if(fileIndex >= 0 && fileIndex < m_files.count()) + { + CueSheetFile *currentFile = m_files.at(fileIndex); + if(trackIndex >= 0 && trackIndex < currentFile->trackCount()) + { + return currentFile->track(trackIndex)->trackNo(); + } + } + + return -1; +} + void CueSheetModel::getTrackIndex(int fileIndex, int trackIndex, double *startIndex, double *duration) { *startIndex = std::numeric_limits::quiet_NaN(); @@ -363,6 +377,34 @@ void CueSheetModel::getTrackIndex(int fileIndex, int trackIndex, double *startIn } } +QString CueSheetModel::getTrackPerformer(int fileIndex, int trackIndex) +{ + if(fileIndex >= 0 && fileIndex < m_files.count()) + { + CueSheetFile *currentFile = m_files.at(fileIndex); + if(trackIndex >= 0 && trackIndex < currentFile->trackCount()) + { + CueSheetTrack *currentTrack = currentFile->track(trackIndex); + return currentTrack->performer(); + } + } + return QString(); +} + +QString CueSheetModel::getTrackTitle(int fileIndex, int trackIndex) +{ + if(fileIndex >= 0 && fileIndex < m_files.count()) + { + CueSheetFile *currentFile = m_files.at(fileIndex); + if(trackIndex >= 0 && trackIndex < currentFile->trackCount()) + { + CueSheetTrack *currentTrack = currentFile->track(trackIndex); + return currentTrack->title(); + } + } + return QString(); +} + //////////////////////////////////////////////////////////// // Cue Sheet Parser //////////////////////////////////////////////////////////// @@ -624,6 +666,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic //Sanity check of track numbers if(nFiles > 0) { + int previousTrackNo = -1; bool trackNo[100]; for(int i = 0; i < 100; i++) { @@ -640,7 +683,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic int nTracks = currentFile->trackCount(); if(nTracks > 1) { - for(int j = 1; j < nTracks; j++) + for(int j = 0; j < nTracks; j++) { int currentTrackNo = currentFile->track(j)->trackNo(); if(currentTrackNo > 99) @@ -648,12 +691,18 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic qWarning("Track #%02d is invalid (maximum is 99), Cue Sheet is inconsistent!", currentTrackNo); return ErrorInconsistent; } + if(currentTrackNo <= previousTrackNo) + { + qWarning("Non-increasing track numbers, Cue Sheet is inconsistent!", currentTrackNo); + return ErrorInconsistent; + } if(trackNo[currentTrackNo]) { qWarning("Track #%02d exists multiple times, Cue Sheet is inconsistent!", currentTrackNo); return ErrorInconsistent; } trackNo[currentTrackNo] = true; + previousTrackNo = currentTrackNo; } } } diff --git a/src/Model_CueSheet.h b/src/Model_CueSheet.h index fa509f33..d0ff6403 100644 --- a/src/Model_CueSheet.h +++ b/src/Model_CueSheet.h @@ -61,7 +61,10 @@ public: int CueSheetModel::getFileCount(void); QString getFileName(int fileIndex); int getTrackCount(int fileIndex); + int getTrackNo(int fileIndex, int trackIndex); void getTrackIndex(int fileIndex, int trackIndex, double *startIndex, double *duration); + QString getTrackPerformer(int fileIndex, int trackIndex); + QString getTrackTitle(int fileIndex, int trackIndex); //Cue Sheet functions int loadCueSheet(const QString &cueFile, QCoreApplication *application = NULL); diff --git a/src/Thread_CueSplitter.cpp b/src/Thread_CueSplitter.cpp new file mode 100644 index 00000000..1f01f4ae --- /dev/null +++ b/src/Thread_CueSplitter.cpp @@ -0,0 +1,253 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2011 LoRd_MuldeR +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +#include "Thread_CueSplitter.h" + +#include "Global.h" +#include "LockedFile.h" +#include "Model_AudioFile.h" +#include "PlaylistImporter.h" + +#include +#include +#include +#include +#include +#include + +#include + +//////////////////////////////////////////////////////////// +// Constructor +//////////////////////////////////////////////////////////// + +CueSplitter::CueSplitter(const QString &outputDir, const QString &baseName, const QList &inputFiles) +: + m_outputDir(outputDir), + m_baseName(baseName), + m_soxBin(lamexp_lookup_tool("sox.exe")) +{ + if(m_soxBin.isEmpty()) + { + qFatal("Invalid path to SoX binary. Tool not initialized properly."); + } + + qDebug("\n[CueSplitter::CueSplitter]"); + + int nInputFiles = inputFiles.count(); + for(int i = 0; i < nInputFiles; i++) + { + m_inputFiles.insert(inputFiles[i].filePath(), inputFiles[i]); + qDebug("%02d <%s>", i, inputFiles[i].filePath()); + } + + qDebug("All input files added."); + m_bSuccess = false; +} + +//////////////////////////////////////////////////////////// +// Thread Main +//////////////////////////////////////////////////////////// + +void CueSplitter::run() +{ + m_bSuccess = false; + m_abortFlag = false; + + int nTracks = min(min(min(m_trackFile.count(), m_trackNo.count()), min(m_trackOffset.count(), m_trackLength.count())), m_trackMetaInfo.count()); + + if(!QDir(m_outputDir).exists()) + { + qWarning("Output directory \"%s\" does not exist!", m_outputDir.toUtf8().constData()); + return; + } + + for(int i = 0; i < nTracks; i++) + { + QString outputFile = QString("%1/%2 - Track %3.wav").arg(m_outputDir, m_baseName, QString().sprintf("%02d", m_trackNo.at(i))); + for(int n = 2; QFileInfo(outputFile).exists(); n++) + { + outputFile = QString("%1/%2 - Track %3 (%4).wav").arg(m_outputDir, m_baseName, QString().sprintf("%02d", m_trackNo.at(i)), QString::number(n)); + } + + emit fileSelected(QFileInfo(outputFile).fileName()); + splitFile(outputFile, m_trackNo.at(i), m_trackFile.at(i), m_trackOffset.at(i), m_trackLength.at(i), m_trackMetaInfo.at(i)); + } + + qDebug("All files were split.\n"); + m_bSuccess = true; +} + +void CueSplitter::addTrack(const int trackNo, const QString &file, const double offset, const double length, const AudioFileModel &metaInfo) +{ + + if(m_inputFiles.contains(file)) + { + m_trackFile << file; + m_trackNo << trackNo; + m_trackOffset << offset; + m_trackLength << length; + m_trackMetaInfo << metaInfo; + } + else + { + throw "Unknown input file!"; + } +} + +//////////////////////////////////////////////////////////// +// Privtae Functions +//////////////////////////////////////////////////////////// + +void CueSplitter::splitFile(const QString &output, const int trackNo, const QString &file, const double offset, const double length, const AudioFileModel &metaInfo) +{ + qDebug("\n[Track %02d]", trackNo); + qDebug("File: <%s>", file.toUtf8().constData()); + qDebug("Offset: %f", offset); + qDebug("Length: %f", length); + qDebug("Artist: <%s>", metaInfo.fileArtist().toUtf8().constData()); + qDebug("Title: <%s>", metaInfo.fileName().toUtf8().constData()); + + QRegExp regExp("In:(\\d+)(\\.\\d+)*%"); + QString baseName = QFileInfo(output).fileName(); + + if(!m_inputFiles.contains(file)) + { + qWarning("Unknown input file, skipping!"); + return; + } + + AudioFileModel &inputFileInfo = m_inputFiles[file]; + if(inputFileInfo.formatContainerType().compare("Wave", Qt::CaseInsensitive) || inputFileInfo.formatAudioType().compare("PCM", Qt::CaseInsensitive)) + { + qWarning("Sorry, only Wave/PCM files are supported at this time!"); + return; + } + + QStringList args; + args << "-S" << "-V3"; + args << "--guard" << "--temp" << "."; + args << QDir::toNativeSeparators(file); + args << QDir::toNativeSeparators(output); + args << "trim"; + args << indexToString(offset); + + if((length != std::numeric_limits::quiet_NaN()) && (length != std::numeric_limits::infinity())) + { + args << indexToString(length); + } + + QProcess process; + process.setProcessChannelMode(QProcess::MergedChannels); + process.setReadChannel(QProcess::StandardOutput); + process.setWorkingDirectory(m_outputDir); + process.start(m_soxBin, args); + + if(!process.waitForStarted()) + { + qWarning("SoX process failed to create!"); + qWarning("Error message: \"%s\"\n", process.errorString().toLatin1().constData()); + process.kill(); + process.waitForFinished(-1); + return; + } + + while(process.state() != QProcess::NotRunning) + { + if(m_abortFlag) + { + process.kill(); + break; + } + process.waitForReadyRead(); + if(!process.bytesAvailable() && process.state() == QProcess::Running) + { + process.kill(); + qWarning("SoX process timed out <-- killing!"); + 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 fileSelected(QString("%1 [%2%]").arg(baseName, QString::number(progress))); + } + } + } + } + + if(process.state() != QProcess::NotRunning) + { + process.kill(); + process.waitForFinished(-1); + } + + if(process.exitStatus() != QProcess::NormalExit || QFileInfo(output).size() == 0) + { + qWarning("Splitting has failed!"); + return; + } + + AudioFileModel outFileInfo(metaInfo); + outFileInfo.setFilePath(output); + outFileInfo.setFormatContainerType(inputFileInfo.formatContainerType()); + outFileInfo.setFormatAudioType(inputFileInfo.formatAudioType()); + outFileInfo.setFileDuration(static_cast(abs(length))); + emit fileSplit(outFileInfo); +} + +QString CueSplitter::indexToString(const double index) const +{ + if(index == std::numeric_limits::quiet_NaN() || index == std::numeric_limits::infinity() || index < 0.0) + { + return QString(); + } + + int temp = static_cast(index * 1000.0); + + int msec = temp % 1000; + int secs = temp / 1000; + + if(secs >= 3600) + { + return QString().sprintf("%d:%02d:%02d.%03d", min(99, secs / 3600), min(59, (secs % 3600) / 60), min(59, (secs % 3600) % 60), min(99, msec)); + } + else if(secs >= 60) + { + return QString().sprintf("%d:%02d.%03d", min(99, secs / 60), min(59, secs % 60), min(99, msec)); + } + else + { + return QString().sprintf("%d.%03d", min(59, secs % 60), min(99, msec)); + } +} + +//////////////////////////////////////////////////////////// +// EVENTS +//////////////////////////////////////////////////////////// + +/*NONE*/ diff --git a/src/Thread_CueSplitter.h b/src/Thread_CueSplitter.h new file mode 100644 index 00000000..b31efad1 --- /dev/null +++ b/src/Thread_CueSplitter.h @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// LameXP - Audio Encoder Front-End +// Copyright (C) 2004-2011 LoRd_MuldeR +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// http://www.gnu.org/licenses/gpl-2.0.txt +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include + +class AudioFileModel; +class QFile; +class QDir; +class QFileInfo; + +//////////////////////////////////////////////////////////// +// Splash Thread +//////////////////////////////////////////////////////////// + +class CueSplitter: public QThread +{ + Q_OBJECT + +public: + CueSplitter(const QString &outputDir, const QString &baseName, const QList &inputFiles); + void run(); + bool getSuccess(void) { return !isRunning() && m_bSuccess; } + void addTrack(const int trackNo, const QString &file, const double offset, const double length, const AudioFileModel &metaInfo); + +signals: + void fileSelected(const QString &fileName); + void fileSplit(const AudioFileModel &file); + +private: + void splitFile(const QString &output, const int trackNo, const QString &file, const double offset, const double length, const AudioFileModel &metaInfo); + QString indexToString(const double index) const; + + const QString m_soxBin; + const QString m_outputDir; + const QString m_baseName; + bool m_bSuccess; + volatile bool m_abortFlag; + + QMap m_inputFiles; + QList m_trackFile; + QList m_trackNo; + QList m_trackOffset; + QList m_trackLength; + QList m_trackMetaInfo; +};