From 5e5fbe06f9746e353e1989bf5f5051fe4d50c50d Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 13 Oct 2013 20:50:12 +0200 Subject: [PATCH] Updated CueImportDialog and CueSheetModel as well as the CueSheet helper classes to use AudioFileModel_MetaInfo. Significant code simplification. --- etc/Translation/Blank.ts | 106 +++++++++---------- etc/Translation/LameXP_EN.ts | 6 +- etc/Translation/LameXP_PL.ts | 106 +++++++++---------- etc/Translation/LameXP_SV.ts | 106 +++++++++---------- src/Config.h | 2 +- src/Dialog_CueImport.cpp | 7 +- src/Dialog_Processing.cpp | 2 +- src/Model_Artwork.cpp | 7 +- src/Model_AudioFile.cpp | 121 +++++++++++++-------- src/Model_AudioFile.h | 5 +- src/Model_CueSheet.cpp | 200 +++++++++-------------------------- src/Model_CueSheet.h | 18 +--- src/Model_MetaInfo.cpp | 2 +- src/Thread_CueSplitter.cpp | 59 ++++------- 14 files changed, 331 insertions(+), 416 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index 17d90360..3642051d 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -379,56 +379,56 @@ AudioFileModel - - + + Profile - + Channels - + Samplerate - - + + Bitdepth - + Type - + Version - - - + + + Bitrate - + Constant - + Variable - + Encoder @@ -464,8 +464,8 @@ - - + + Cue Sheet Error @@ -525,110 +525,110 @@ - + Unknown Artist - + Unknown Album - - + + Choose Output Directory - - + + LameXP - + Error: The selected output directory could not be created! - + 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... - + Analysis Failed - + Warning: The format of some of the input files could not be determined! - + Continue Anyway - + Abort - + Splitting file(s), please wait... - + Process was aborted by the user after %n track(s)! - + An unexpected error has occured while splitting the Cue Sheet! - + Imported %n track(s) from the Cue Sheet. - + Skipped %n track(s). - + Cue Sheet Completed @@ -685,44 +685,44 @@ CueSheetModel - + No. - + File / Track - + Index - + Duration - + File %1 - + Track %1 - - + + Unknown Artist - - + + Unknown Title @@ -3290,23 +3290,23 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. - + Executable '%1' requires Qt v%2, but found Qt v%3. - + Executable '%1' was built for Qt '%2', but found Qt '%3'. - - + + Executable '%1' requires Windows 2000 or later. diff --git a/etc/Translation/LameXP_EN.ts b/etc/Translation/LameXP_EN.ts index 8799117a..3a906846 100644 --- a/etc/Translation/LameXP_EN.ts +++ b/etc/Translation/LameXP_EN.ts @@ -4,7 +4,7 @@ CueImportDialog - + Process was aborted by the user after %n track(s)! Process was aborted by the user after %n track! @@ -12,7 +12,7 @@ - + Imported %n track(s) from the Cue Sheet. Imported %n track from the Cue Sheet. @@ -20,7 +20,7 @@ - + Skipped %n track(s). Skipped %n track. diff --git a/etc/Translation/LameXP_PL.ts b/etc/Translation/LameXP_PL.ts index fc1b0287..bd1f50a1 100644 --- a/etc/Translation/LameXP_PL.ts +++ b/etc/Translation/LameXP_PL.ts @@ -379,56 +379,56 @@ AudioFileModel - - + + Profile Profil - + Channels Kanały - + Samplerate Częstotliwość - - + + Bitdepth Głębia bitów - + Type Typ - + Version Wersja - - - + + + Bitrate Przepływność bitów - + Constant Stały - + Variable Zmienny - + Encoder Enkoder @@ -464,8 +464,8 @@ - - + + Cue Sheet Error Błąd pliku Cue Sheet @@ -525,84 +525,84 @@ Wybrany plik Cue Sheet zawiera niespójne informacje. Prosze zachować ostrożność! - + Unknown Artist Nieznany Artysta - + Unknown Album Nieznany Album - - + + Choose Output Directory Wybierz folder wyjściowy - - + + LameXP LameXP - + Error: The selected output directory could not be created! Błąd: Wybrana lokalizacja wyjściowa nie może zostać utworzona! - + Error: The selected output directory is not writable! Błąd: Nie można zapisać w wybranej lokalizacji wyjściowej! - + Low Diskspace Warning Ostrzeżenie o małej ilości miejsca na dysku - + There are less than %1 GB of free diskspace available in the selected output directory. Jest mniej niż %1 GB wolnego miejsca w wybranej lokalizacji wyjściowej. - + It is highly recommend to free up more diskspace before proceeding with the import! Jest wysoce zalecane zwolnić miejsce na dysku zanim zaczniesz importować! - + Analyzing file(s), please wait... Analizowanie pliku/ów, prosze czekać... - + Analysis Failed Analiza zakończona niepowodzeniem - + Warning: The format of some of the input files could not be determined! Ostrzeżenie: Nie można rozpoznać formatu kilku plików wejściowych! - + Continue Anyway Kontynuuj pomimo to - + Abort Przerwij - + Splitting file(s), please wait... Dzielenie pliku/ów, prosze czekać... - + Process was aborted by the user after %n track(s)! Proces został przerwany przez użytkownika po zakończeniu %n ścieżki! @@ -611,12 +611,12 @@ - + An unexpected error has occured while splitting the Cue Sheet! Wystąpił nieoczekiwany błąd podczas podziału pliku Cue Sheet! - + Imported %n track(s) from the Cue Sheet. Zaimportowano %n ścieżkę z pliku Cue Sheet. @@ -625,7 +625,7 @@ - + Skipped %n track(s). Pominięto %n ścieżkę. @@ -634,7 +634,7 @@ - + Cue Sheet Completed Stworzono plik Cue Sheet @@ -691,44 +691,44 @@ CueSheetModel - + No. Numer. - + File / Track Plik/ŚcieżKa - + Index Indeks - + Duration Czas trwania - + File %1 Plik %1 - + Track %1 Ścieżka %1 - - + + Unknown Artist Nieznany Artysta - - + + Unknown Title Nieznany Tytuł @@ -3327,23 +3327,23 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. Plik wykonywalny '%1' nie działa w trybie kompatybilności z Windows. - + Executable '%1' requires Qt v%2, but found Qt v%3. Plik wykonywalny '%1' wymaga Qt v%2, znaleziono jednak Qt v%3. - + Executable '%1' was built for Qt '%2', but found Qt '%3'. Plik wykonywalny "%1" został skompilowany dla Qt "%2", znaleziono "%3". - - + + Executable '%1' requires Windows 2000 or later. Plik wykonywalny '%1' wymaga do uruchomienia Windows 2000 lub nowszego. diff --git a/etc/Translation/LameXP_SV.ts b/etc/Translation/LameXP_SV.ts index 49be0ff1..33d4bb08 100644 --- a/etc/Translation/LameXP_SV.ts +++ b/etc/Translation/LameXP_SV.ts @@ -379,56 +379,56 @@ AudioFileModel - - + + Profile Profil - + Channels Kanaler - + Samplerate Samplingsfrekvens - - + + Bitdepth Bitdjup - + Type Typ - + Version Version - - - + + + Bitrate Bithastighet - + Constant Konstant - + Variable Variabel - + Encoder Kodare @@ -465,8 +465,8 @@ - - + + Cue Sheet Error Cue-fel @@ -526,84 +526,84 @@ Den specificerade cue-filen innehåller inkonsekvent information. Undersök det! - + Unknown Artist Okänd artist - + Unknown Album Okänt album - - + + Choose Output Directory Välj målmapp för utdata - - + + LameXP LameXP - + Error: The selected output directory could not be created! Fel: Den specificerade målmappen kunde inte skapas! - + Error: The selected output directory is not writable! Fel: Den specificerade målmappen är skrivskyddad! - + Low Diskspace Warning Varning för lågt diskutrymme - + There are less than %1 GB of free diskspace available in the selected output directory. Det finns mindre än %1 GB ledigt diskutrymme på den specificerade måladressen. - + It is highly recommend to free up more diskspace before proceeding with the import! Du bör frigöra mer diskutrymme innan du fortsätter med importen! - + Analyzing file(s), please wait... Analyserar fil(er), vänta... - + Analysis Failed Analys misslyckades - + Warning: The format of some of the input files could not be determined! Varning! Formatet på vissa filer kunde inte avgöras! - + Continue Anyway Fortsätt ändå - + Abort Avbryt - + Splitting file(s), please wait... Delar fil(er), vänta... - + Process was aborted by the user after %n track(s)! Åtgärden avbröts av användaren efter %n spår! @@ -611,12 +611,12 @@ - + An unexpected error has occured while splitting the Cue Sheet! Ett oväntat fel uppstod vid delningen av cue-filen! - + Imported %n track(s) from the Cue Sheet. Importerade %n spår från cue-filen. @@ -624,7 +624,7 @@ - + Skipped %n track(s). Hoppade över %n spår. @@ -632,7 +632,7 @@ - + Cue Sheet Completed cue-fil färdigbearbetad @@ -689,44 +689,44 @@ CueSheetModel - + No. Nr. - + File / Track Fil / Spår - + Index Index - + Duration Varaktighet - + File %1 Fil %1 - + Track %1 Spår %1 - - + + Unknown Artist Okänd artist - - + + Unknown Title Okänd titel @@ -3310,23 +3310,23 @@ QApplication - + Executable '%1' doesn't support Windows compatibility mode. EXE-filen '%1' stöder inte Windows kompatibilitetsläge. - + Executable '%1' requires Qt v%2, but found Qt v%3. EXE-filen '%1' kräver Qt v%2, du har Qt v%3. - + Executable '%1' was built for Qt '%2', but found Qt '%3'. EXE-filen '%1' är byggd för Qt '%2', du har Qt '%3'. - - + + Executable '%1' requires Windows 2000 or later. EXE-filen '%1' kräver Windows 2000 eller senare. diff --git a/src/Config.h b/src/Config.h index 2f1039df..f0ef197a 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 1382 +#define VER_LAMEXP_BUILD 1385 #define VER_LAMEXP_CONFG 1348 /////////////////////////////////////////////////////////////////////////////// diff --git a/src/Dialog_CueImport.cpp b/src/Dialog_CueImport.cpp index b749cdec..94054cde 100644 --- a/src/Dialog_CueImport.cpp +++ b/src/Dialog_CueImport.cpp @@ -233,8 +233,11 @@ void CueImportDialog::modelChanged(void) { ui->treeView->expandAll(); ui->editOutputDir->setText(QDir::toNativeSeparators(m_outputDir)); - ui->labelArtist->setText(m_model->getAlbumPerformer().isEmpty() ? tr("Unknown Artist") : m_model->getAlbumPerformer()); - ui->labelAlbum->setText(m_model->getAlbumTitle().isEmpty() ? tr("Unknown Album") : m_model->getAlbumTitle()); + if(const AudioFileModel_MetaInfo *albumInfo = m_model->getAlbumInfo()) + { + ui->labelArtist->setText(albumInfo->artist().isEmpty() ? tr("Unknown Artist") : albumInfo->artist()); + ui->labelAlbum->setText(albumInfo->album().isEmpty() ? tr("Unknown Album") : albumInfo->album()); + } } void CueImportDialog::browseButtonClicked(void) diff --git a/src/Dialog_Processing.cpp b/src/Dialog_Processing.cpp index 22c6d968..349e8a89 100644 --- a/src/Dialog_Processing.cpp +++ b/src/Dialog_Processing.cpp @@ -1039,7 +1039,7 @@ AudioFileModel ProcessingDialog::updateMetaInfo(AudioFileModel &audioFile) return audioFile; } - audioFile.metaInfo().update(*m_metaInfo); + audioFile.metaInfo().update(*m_metaInfo, true); if(audioFile.metaInfo().position() == UINT_MAX) { diff --git a/src/Model_Artwork.cpp b/src/Model_Artwork.cpp index aeb2b3cf..679f98ed 100644 --- a/src/Model_Artwork.cpp +++ b/src/Model_Artwork.cpp @@ -132,8 +132,11 @@ ArtworkModel::ArtworkModel(const ArtworkModel &model) ArtworkModel &ArtworkModel::operator=(const ArtworkModel &model) { QMutexLocker lock(m_mutex); - ArtworkModel_SharedData::detach(&m_data); - m_data = ArtworkModel_SharedData::attach(model.m_data); + if(m_data != model.m_data) + { + ArtworkModel_SharedData::detach(&m_data); + m_data = ArtworkModel_SharedData::attach(model.m_data); + } return (*this); } diff --git a/src/Model_AudioFile.cpp b/src/Model_AudioFile.cpp index f7041648..00247b6b 100644 --- a/src/Model_AudioFile.cpp +++ b/src/Model_AudioFile.cpp @@ -32,6 +32,18 @@ const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1; +#define PRINT_S(VAR) do \ +{ \ + if((VAR).isEmpty()) qDebug(#VAR " = N/A"); else qDebug(#VAR " = \"%s\"", (VAR).toUtf8().constData()); \ +} \ +while(0) + +#define PRINT_U(VAR) do \ +{ \ + if((VAR) < 1) qDebug(#VAR " = N/A"); else qDebug(#VAR " = %u", (VAR)); \ +} \ +while(0) + /////////////////////////////////////////////////////////////////////////////// // Audio File - Meta Info /////////////////////////////////////////////////////////////////////////////// @@ -43,40 +55,50 @@ AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(void) AudioFileModel_MetaInfo::AudioFileModel_MetaInfo(const AudioFileModel_MetaInfo &model) { - m_titel = model.m_titel; - m_artist = model.m_artist; - m_album = model.m_album; - m_genre = model.m_genre; - m_comment = model.m_comment; - m_cover = model.m_cover; - m_year = model.m_year; + m_titel = model.m_titel; + m_artist = model.m_artist; + m_album = model.m_album; + m_genre = model.m_genre; + m_comment = model.m_comment; + m_cover = model.m_cover; + m_year = model.m_year; m_position = model.m_position; } AudioFileModel_MetaInfo &AudioFileModel_MetaInfo::operator=(const AudioFileModel_MetaInfo &model) { - m_titel = model.m_titel; - m_artist = model.m_artist; - m_album = model.m_album; - m_genre = model.m_genre; - m_comment = model.m_comment; - m_cover = model.m_cover; - m_year = model.m_year; + m_titel = model.m_titel; + m_artist = model.m_artist; + m_album = model.m_album; + m_genre = model.m_genre; + m_comment = model.m_comment; + m_cover = model.m_cover; + m_year = model.m_year; m_position = model.m_position; return (*this); } -void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model) +void AudioFileModel_MetaInfo::update(const AudioFileModel_MetaInfo &model, const bool replace) { - if(!model.m_titel.isEmpty()) m_titel = model.m_titel; - if(!model.m_artist.isEmpty()) m_artist = model.m_artist; - if(!model.m_album.isEmpty()) m_album = model.m_album; - if(!model.m_genre.isEmpty()) m_genre = model.m_genre; - if(!model.m_comment.isEmpty()) m_comment = model.m_comment; - if(!model.m_cover.isEmpty()) m_cover = model.m_cover; - if(model.m_year > 0) m_year = model.m_year; - if(model.m_position > 0) m_position = model.m_position; + qDebug("\n-------[AudioFileModel_MetaInfo::update]-------"); + qDebug("Updating (%p):", this); + print(); + qDebug("\nUpdating with (%p):", &model); + model.print(); + + if((!model.m_titel.isEmpty()) && (replace || m_titel.isEmpty())) m_titel = model.m_titel; + if((!model.m_artist.isEmpty()) && (replace || m_artist.isEmpty())) m_artist = model.m_artist; + if((!model.m_album.isEmpty()) && (replace || m_album.isEmpty())) m_album = model.m_album; + if((!model.m_genre.isEmpty()) && (replace || m_genre.isEmpty())) m_genre = model.m_genre; + if((!model.m_comment.isEmpty()) && (replace || m_comment.isEmpty())) m_comment = model.m_comment; + if((!model.m_cover.isEmpty()) && (replace || m_cover.isEmpty())) m_cover = model.m_cover; + if((model.m_year > 0) && (replace || (m_year == 0))) m_year = model.m_year; + if((model.m_position > 0) && (replace || (m_position == 0))) m_position = model.m_position; + + qDebug("\nResult:"); + print(); + qDebug("-----------------------------------------------\n\n"); } AudioFileModel_MetaInfo::~AudioFileModel_MetaInfo(void) @@ -96,6 +118,18 @@ void AudioFileModel_MetaInfo::reset(void) m_position = 0; } +void AudioFileModel_MetaInfo::print(void) const +{ + PRINT_S(m_titel); + PRINT_S(m_artist); + PRINT_S(m_album); + PRINT_S(m_genre); + PRINT_S(m_comment); + PRINT_S(m_cover.filePath()); + PRINT_U(m_year); + PRINT_U(m_position); +} + /////////////////////////////////////////////////////////////////////////////// // Audio File - Technical Info /////////////////////////////////////////////////////////////////////////////// @@ -107,35 +141,34 @@ AudioFileModel_TechInfo::AudioFileModel_TechInfo(void) AudioFileModel_TechInfo::AudioFileModel_TechInfo(const AudioFileModel_TechInfo &model) { - m_containerType = model.m_containerType; + m_containerType = model.m_containerType; m_containerProfile = model.m_containerProfile; - m_audioType = model.m_audioType; - m_audioProfile = model.m_audioProfile; - m_audioVersion = model.m_audioVersion; - m_audioEncodeLib = model.m_audioEncodeLib; - m_audioSamplerate = model.m_audioSamplerate; - m_audioChannels = model.m_audioChannels; - m_audioBitdepth = model.m_audioBitdepth; - m_audioBitrate = model.m_audioBitrate; + m_audioType = model.m_audioType; + m_audioProfile = model.m_audioProfile; + m_audioVersion = model.m_audioVersion; + m_audioEncodeLib = model.m_audioEncodeLib; + m_audioSamplerate = model.m_audioSamplerate; + m_audioChannels = model.m_audioChannels; + m_audioBitdepth = model.m_audioBitdepth; + m_audioBitrate = model.m_audioBitrate; m_audioBitrateMode = model.m_audioBitrateMode; - m_duration = model.m_duration; + m_duration = model.m_duration; } AudioFileModel_TechInfo &AudioFileModel_TechInfo::operator=(const AudioFileModel_TechInfo &model) { - m_containerType = model.m_containerType; + m_containerType = model.m_containerType; m_containerProfile = model.m_containerProfile; - m_audioType = model.m_audioType; - m_audioProfile = model.m_audioProfile; - m_audioVersion = model.m_audioVersion; - m_audioEncodeLib = model.m_audioEncodeLib; - m_audioSamplerate = model.m_audioSamplerate; - m_audioChannels = model.m_audioChannels; - m_audioBitdepth = model.m_audioBitdepth; - m_audioBitrate = model.m_audioBitrate; + m_audioType = model.m_audioType; + m_audioProfile = model.m_audioProfile; + m_audioVersion = model.m_audioVersion; + m_audioEncodeLib = model.m_audioEncodeLib; + m_audioSamplerate = model.m_audioSamplerate; + m_audioChannels = model.m_audioChannels; + m_audioBitdepth = model.m_audioBitdepth; + m_audioBitrate = model.m_audioBitrate; m_audioBitrateMode = model.m_audioBitrateMode; - m_duration = model.m_duration; - + m_duration = model.m_duration; return (*this); } diff --git a/src/Model_AudioFile.h b/src/Model_AudioFile.h index d8a5e72c..df22401d 100644 --- a/src/Model_AudioFile.h +++ b/src/Model_AudioFile.h @@ -65,7 +65,10 @@ public: void reset(void); //Update - void update(const AudioFileModel_MetaInfo &model); + void update(const AudioFileModel_MetaInfo &model, const bool replace); + + //Debug + void print(void) const; private: QString m_titel; diff --git a/src/Model_CueSheet.cpp b/src/Model_CueSheet.cpp index 6f4df01c..11f1056f 100644 --- a/src/Model_CueSheet.cpp +++ b/src/Model_CueSheet.cpp @@ -21,6 +21,7 @@ #include "Global.h" #include "Model_CueSheet.h" +#include "Model_AudioFile.h" #include "Genres.h" #include @@ -53,38 +54,32 @@ class CueSheetTrack : public CueSheetItem public: CueSheetTrack(CueSheetFile *parent, int trackNo) : - m_parent(parent), - m_trackNo(trackNo) + m_parent(parent) { m_startIndex = std::numeric_limits::quiet_NaN(); m_duration = std::numeric_limits::infinity(); - m_year = 0; + m_metaInfo.setPosition(trackNo); } - int trackNo(void) { return m_trackNo; } + + //Getter + CueSheetFile *parent(void) { return m_parent; } double startIndex(void) { return m_startIndex; } double duration(void) { return m_duration; } - QString title(void) { return m_title; } - QString performer(void) { return m_performer; } - QString genre(void) { return m_genre; } - unsigned int year(void) { return m_year; } - CueSheetFile *parent(void) { return m_parent; } + AudioFileModel_MetaInfo &metaInfo(void) { return m_metaInfo; } + + //Setter void setStartIndex(double startIndex) { m_startIndex = startIndex; } void setDuration(double duration) { m_duration = duration; } - void setTitle(const QString &title, bool update = false) { if(!update || (m_title.isEmpty() && !title.isEmpty())) m_title = title; } - void setPerformer(const QString &performer, bool update = false) { if(!update || (m_performer.isEmpty() && !performer.isEmpty())) m_performer = performer; } - void setGenre(const QString &genre, bool update = false) { if(!update || (m_genre.isEmpty() && !m_genre.isEmpty())) m_genre = genre; } - void setYear(const unsigned int year, bool update = false) { if(!update || (year == 0)) m_year = year; } - virtual bool isValid(void) { return !(_isnan(m_startIndex) || (m_trackNo < 0)); } + + //Misc + virtual bool isValid(void) { return !(_isnan(m_startIndex) || (m_metaInfo.position() == 0)); } virtual const char* type(void) { return "CueSheetTrack"; } + private: - int m_trackNo; double m_startIndex; double m_duration; - QString m_title; - QString m_performer; - QString m_genre; - unsigned int m_year; - CueSheetFile *m_parent; + AudioFileModel_MetaInfo m_metaInfo; + CueSheetFile *const m_parent; }; class CueSheetFile : public CueSheetItem @@ -92,13 +87,20 @@ class CueSheetFile : public CueSheetItem public: CueSheetFile(const QString &fileName) : m_fileName(fileName) {} ~CueSheetFile(void) { while(!m_tracks.isEmpty()) delete m_tracks.takeLast(); } + + //Getter QString fileName(void) { return m_fileName; } - void addTrack(CueSheetTrack *track) { m_tracks.append(track); } - void clearTracks(void) { while(!m_tracks.isEmpty()) delete m_tracks.takeLast(); } CueSheetTrack *track(int index) { return m_tracks.at(index); } int trackCount(void) { return m_tracks.count(); } + + //Modifier + void addTrack(CueSheetTrack *track) { m_tracks.append(track); } + void clearTracks(void) { while(!m_tracks.isEmpty()) delete m_tracks.takeLast(); } + + //Misc virtual bool isValid(void) { return m_tracks.count() > 0; } virtual const char* type(void) { return "CueSheetFile"; } + private: const QString m_fileName; QList m_tracks; @@ -115,21 +117,7 @@ CueSheetModel::CueSheetModel() m_fileIcon(":/icons/music.png"), m_trackIcon(":/icons/control_play_blue.png") { - int trackNo = 0; - m_albumYear = 0; - - for(int i = 0; i < 5; i++) - { - CueSheetFile *currentFile = new CueSheetFile(QString().sprintf("File %02d.wav", i+1)); - for(int j = 0; j < 8; j++) - { - CueSheetTrack *currentTrack = new CueSheetTrack(currentFile, trackNo++); - currentTrack->setTitle("ATWA (Air Trees Water Animals)"); - currentTrack->setPerformer("System of a Down"); - currentFile->addTrack(currentTrack); - } - m_files.append(currentFile); - } + /*nothing to do*/ } CueSheetModel::~CueSheetModel(void) @@ -255,23 +243,24 @@ QVariant CueSheetModel::data(const QModelIndex &index, int role) const } else if(CueSheetTrack *trackPtr = dynamic_cast(item)) { + const AudioFileModel_MetaInfo &trackInfo = trackPtr->metaInfo(); switch(index.column()) { case 0: - return tr("Track %1").arg(QString().sprintf("%02d", trackPtr->trackNo())).append(" "); + return tr("Track %1").arg(QString().sprintf("%02d", trackInfo.position())).append(" "); break; case 1: - if(!trackPtr->title().isEmpty() && !trackPtr->performer().isEmpty()) + if(!trackInfo.title().isEmpty() && !trackInfo.artist().isEmpty()) { - return QString("%1 - %2").arg(trackPtr->performer(), trackPtr->title()); + return QString("%1 - %2").arg(trackInfo.artist(), trackInfo.title()); } - else if(!trackPtr->title().isEmpty()) + else if(!trackInfo.title().isEmpty()) { - return QString("%1 - %2").arg(tr("Unknown Artist"), trackPtr->title()); + return QString("%1 - %2").arg(tr("Unknown Artist"), trackInfo.title()); } - else if(!trackPtr->performer().isEmpty()) + else if(!trackInfo.artist().isEmpty()) { - return QString("%1 - %2").arg(trackPtr->performer(), tr("Unknown Title")); + return QString("%1 - %2").arg(trackInfo.artist(), tr("Unknown Title")); } else { @@ -399,7 +388,7 @@ int CueSheetModel::getTrackCount(int fileIndex) return m_files.at(fileIndex)->trackCount(); } -int CueSheetModel::getTrackNo(int fileIndex, int trackIndex) +const AudioFileModel_MetaInfo *CueSheetModel::getTrackInfo(int fileIndex, int trackIndex) { QMutexLocker lock(&m_mutex); @@ -408,14 +397,14 @@ int CueSheetModel::getTrackNo(int fileIndex, int trackIndex) CueSheetFile *currentFile = m_files.at(fileIndex); if(trackIndex >= 0 && trackIndex < currentFile->trackCount()) { - return currentFile->track(trackIndex)->trackNo(); + return ¤tFile->track(trackIndex)->metaInfo(); } } - return -1; + return NULL; } -void CueSheetModel::getTrackIndex(int fileIndex, int trackIndex, double *startIndex, double *duration) +bool CueSheetModel::getTrackIndex(int fileIndex, int trackIndex, double *startIndex, double *duration) { QMutexLocker lock(&m_mutex); @@ -430,101 +419,19 @@ void CueSheetModel::getTrackIndex(int fileIndex, int trackIndex, double *startIn CueSheetTrack *currentTrack = currentFile->track(trackIndex); *startIndex = currentTrack->startIndex(); *duration = currentTrack->duration(); + return true; } } + + return false; } -QString CueSheetModel::getTrackPerformer(int fileIndex, int trackIndex) -{ - QMutexLocker lock(&m_mutex); - - 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) +const AudioFileModel_MetaInfo *CueSheetModel::getAlbumInfo(void) { QMutexLocker lock(&m_mutex); - - 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(); + return &m_albumInfo; } -QString CueSheetModel::getTrackGenre(int fileIndex, int trackIndex) -{ - QMutexLocker lock(&m_mutex); - - 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->genre(); - } - } - - return QString(); -} - -unsigned int CueSheetModel::getTrackYear(int fileIndex, int trackIndex) -{ - QMutexLocker lock(&m_mutex); - - 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->year(); - } - } - - return 0; -} - -QString CueSheetModel::getAlbumPerformer(void) -{ - QMutexLocker lock(&m_mutex); - return m_albumPerformer; -} - -QString CueSheetModel::getAlbumTitle(void) -{ - QMutexLocker lock(&m_mutex); - return m_albumTitle; -} - -QString CueSheetModel::getAlbumGenre(void) -{ - QMutexLocker lock(&m_mutex); - return m_albumGenre; -} - -unsigned int CueSheetModel::getAlbumYear(void) -{ - QMutexLocker lock(&m_mutex); - return m_albumYear; -} //////////////////////////////////////////////////////////// // Cue Sheet Parser //////////////////////////////////////////////////////////// @@ -594,10 +501,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic CueSheetFile *currentFile = NULL; CueSheetTrack *currentTrack = NULL; - m_albumTitle.clear(); - m_albumPerformer.clear(); - m_albumGenre.clear(); - m_albumYear = 0; + m_albumInfo.reset(); //Loop over the Cue Sheet until all lines were processed for(int lines = 0; lines < INT_MAX; lines++) @@ -720,12 +624,12 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic { if(bPreamble) { - m_albumTitle = UNQUOTE(rxTitle.cap(1)).simplified(); + m_albumInfo.setAlbum(UNQUOTE(rxTitle.cap(1)).simplified()); } else if(currentFile && currentTrack) { qDebug("%03d Title: <%s>", lines, rxTitle.cap(1).toUtf8().constData()); - currentTrack->setTitle(UNQUOTE(rxTitle.cap(1)).simplified()); + currentTrack->metaInfo().setTitle(UNQUOTE(rxTitle.cap(1)).simplified()); } continue; } @@ -735,12 +639,12 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic { if(bPreamble) { - m_albumPerformer = UNQUOTE(rxPerformer.cap(1)).simplified(); + m_albumInfo.setArtist(UNQUOTE(rxPerformer.cap(1)).simplified()); } else if(currentFile && currentTrack) { qDebug("%03d Title: <%s>", lines, rxPerformer.cap(1).toUtf8().constData()); - currentTrack->setPerformer(UNQUOTE(rxPerformer.cap(1)).simplified()); + currentTrack->metaInfo().setArtist(UNQUOTE(rxPerformer.cap(1)).simplified()); } continue; } @@ -755,7 +659,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic { if(temp.compare(g_lamexp_generes[i], Qt::CaseInsensitive) == 0) { - m_albumGenre = QString(g_lamexp_generes[i]); + m_albumInfo.setGenre(QString(g_lamexp_generes[i])); break; } } @@ -768,7 +672,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic { if(temp.compare(g_lamexp_generes[i], Qt::CaseInsensitive) == 0) { - currentTrack->setGenre(QString(g_lamexp_generes[i])); + currentTrack->metaInfo().setGenre(QString(g_lamexp_generes[i])); break; } } @@ -783,14 +687,14 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic { bool ok = false; unsigned int temp = rxYear.cap(1).toUInt(&ok); - if(ok) m_albumYear = temp; + if(ok) m_albumInfo.setYear(temp); } else if(currentFile && currentTrack) { qDebug("%03d Year: <%s>", lines, rxPerformer.cap(1).toUtf8().constData()); bool ok = false; unsigned int temp = rxYear.cap(1).toUInt(&ok); - if(ok) currentTrack->setYear(temp); + if(ok) currentTrack->metaInfo().setYear(temp); } continue; } @@ -870,7 +774,7 @@ int CueSheetModel::parseCueFile(QFile &cueFile, const QDir &baseDir, QCoreApplic { for(int j = 0; j < nTracks; j++) { - int currentTrackNo = currentFile->track(j)->trackNo(); + int currentTrackNo = currentFile->track(j)->metaInfo().position(); if(currentTrackNo > 99) { qWarning("Track #%02d is invalid (maximum is 99), Cue Sheet is inconsistent!", currentTrackNo); diff --git a/src/Model_CueSheet.h b/src/Model_CueSheet.h index 52626cf9..b093d4c3 100644 --- a/src/Model_CueSheet.h +++ b/src/Model_CueSheet.h @@ -63,16 +63,9 @@ 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); - QString getTrackGenre(int fileIndex, int trackIndex); - unsigned int getTrackYear(int fileIndex, int trackIndex); - QString getAlbumPerformer(void); - QString getAlbumTitle(void); - QString getAlbumGenre(void); - unsigned int getAlbumYear(void); + const AudioFileModel_MetaInfo *getTrackInfo(int fileIndex, int trackIndex); + const AudioFileModel_MetaInfo *getAlbumInfo(void); + bool getTrackIndex(int fileIndex, int trackIndex, double *startIndex, double *duration); //Cue Sheet functions int loadCueSheet(const QString &cueFile, QCoreApplication *application = NULL, QTextCodec *forceCodec= NULL); @@ -85,10 +78,7 @@ private: static QMutex m_mutex; QList m_files; - QString m_albumTitle; - QString m_albumPerformer; - QString m_albumGenre; - unsigned int m_albumYear; + AudioFileModel_MetaInfo m_albumInfo; const QIcon m_fileIcon; const QIcon m_trackIcon; diff --git a/src/Model_MetaInfo.cpp b/src/Model_MetaInfo.cpp index e1d6b232..b9b62507 100644 --- a/src/Model_MetaInfo.cpp +++ b/src/Model_MetaInfo.cpp @@ -478,6 +478,6 @@ Qt::ItemFlags MetaInfoModel::flags(const QModelIndex &index) const void MetaInfoModel::assignInfoFrom(const AudioFileModel &file) { beginResetModel(); - m_metaInfo->update(file.metaInfo()); + m_metaInfo->update(file.metaInfo(), true); endResetModel(); } diff --git a/src/Thread_CueSplitter.cpp b/src/Thread_CueSplitter.cpp index 62c0e33a..d98834fd 100644 --- a/src/Thread_CueSplitter.cpp +++ b/src/Thread_CueSplitter.cpp @@ -165,10 +165,7 @@ void CueSplitter::run() emit progressMaxChanged(nTracksTotal); emit progressValChanged(0); - QString albumPerformer = m_model->getAlbumPerformer(); - QString albumTitle = m_model->getAlbumTitle(); - QString albumGenre = m_model->getAlbumGenre(); - unsigned int albumYear = m_model->getAlbumYear(); + const AudioFileModel_MetaInfo *albumInfo = m_model->getAlbumInfo(); //Now split all files for(int i = 0; i < nFiles; i++) @@ -180,8 +177,8 @@ void CueSplitter::run() //Process all tracks for(int j = 0; j < nTracks; j++) { - emit progressValChanged(++nTracksComplete); - int trackNo = m_model->getTrackNo(i, j); + const AudioFileModel_MetaInfo *trackInfo = m_model->getTrackInfo(i, j); + const int trackNo = trackInfo->position(); double trackOffset = std::numeric_limits::quiet_NaN(); double trackLength = std::numeric_limits::quiet_NaN(); m_model->getTrackIndex(i, j, &trackOffset, &trackLength); @@ -193,39 +190,14 @@ void CueSplitter::run() } //Setup meta info - AudioFileModel_MetaInfo trackMetaInfo; /*QString().sprintf("cue://File%02d/Track%02d", i, j)*/; - trackMetaInfo.setTitle(m_model->getTrackTitle(i, j)); - trackMetaInfo.setArtist(m_model->getTrackPerformer(i, j)); - trackMetaInfo.setGenre(m_model->getTrackGenre(i, j)); - trackMetaInfo.setYear(m_model->getTrackYear(i, j)); - trackMetaInfo.setPosition(trackNo); + AudioFileModel_MetaInfo trackMetaInfo(*trackInfo); //Apply album meta data on files if(trackMetaInfo.title().trimmed().isEmpty()) { trackMetaInfo.setTitle(QString().sprintf("Track %02d", trackNo)); } - if(!albumTitle.isEmpty()) - { - trackMetaInfo.setAlbum(albumTitle); - } - if(!albumPerformer.isEmpty() && trackMetaInfo.artist().isEmpty()) - { - trackMetaInfo.setArtist(albumPerformer); - } - if(!albumGenre.isEmpty() && trackMetaInfo.genre().isEmpty()) - { - trackMetaInfo.setGenre(albumGenre); - } - if((albumYear > 0) && (trackMetaInfo.year() == 0)) - { - trackMetaInfo.setYear(albumYear); - } - if(_finite(trackLength)) - { - //FIXME !!! - //trackMetaInfo.setDuration(static_cast(abs(trackLength))); - } + trackMetaInfo.update(*albumInfo, false); //Generate output file name QString trackTitle = trackMetaInfo.title().isEmpty() ? QString().sprintf("Track %02d", trackNo) : trackMetaInfo.title(); @@ -238,6 +210,7 @@ void CueSplitter::run() //Call split function emit fileSelected(shortName(QFileInfo(outputFile).fileName())); splitFile(outputFile, trackNo, trackFile, trackOffset, trackLength, trackMetaInfo, maxProgress); + emit progressValChanged(++nTracksComplete); if(m_abortFlag) { @@ -248,6 +221,9 @@ void CueSplitter::run() } } + emit progressValChanged(nTracksTotal); + lamexp_sleep(333); + qDebug("All files were split.\n"); m_bSuccess = true; } @@ -258,7 +234,7 @@ void CueSplitter::run() void CueSplitter::handleUpdate(int progress) { - emit fileSelected(QString("%1 [%2%]").arg(m_activeFile, QString::number(progress))); + //QString("%1 [%2]").arg(m_activeFile, QString::number(progress))) } //////////////////////////////////////////////////////////// @@ -273,6 +249,7 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr qDebug("Length: <%f> <%s>", length, indexToString(length).toLatin1().constData()); qDebug("Artist: <%s>", metaInfo.artist().toUtf8().constData()); qDebug("Title: <%s>", metaInfo.title().toUtf8().constData()); + qDebug("Album: <%s>", metaInfo.album().toUtf8().constData()); if(!m_decompressedFiles.contains(file)) { @@ -285,13 +262,15 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr QString decompressedInput = m_decompressedFiles[file]; qDebug("Input: <%s>", decompressedInput.toUtf8().constData()); - emit fileSelected(QString("%1 [%2%]").arg(baseName, QString::number(maxProgress))); + //emit fileSelected(QString("%1 [%2%]").arg(baseName, QString::number(maxProgress))); - AudioFileModel outFileInfo; + AudioFileModel outFileInfo(output); outFileInfo.setMetaInfo(metaInfo); - outFileInfo.setFilePath(output); - outFileInfo.techInfo().setContainerType("Wave"); - outFileInfo.techInfo().setAudioType("PCM"); + + AudioFileModel_TechInfo &outFileTechInfo = outFileInfo.techInfo(); + outFileTechInfo.setContainerType("Wave"); + outFileTechInfo.setAudioType("PCM"); + outFileTechInfo.setDuration(static_cast(abs(length))); QStringList args; args << "-S" << "-V3"; @@ -359,7 +338,7 @@ void CueSplitter::splitFile(const QString &output, const int trackNo, const QStr if(ok) { maxProgress = qMax(maxProgress, progress); - emit fileSelected(QString("%1 [%2%]").arg(baseName, QString::number(maxProgress))); + //emit fileSelected(QString("%1 [%2%]").arg(baseName, QString::number(maxProgress))); } } else if(rxChannels.lastIndexIn(text) >= 0)