Refactor audio file model.

This commit is contained in:
LoRd_MuldeR 2011-02-06 23:43:26 +01:00
parent 18bc47cb9a
commit 0fd4b56a87
4 changed files with 52 additions and 22 deletions

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0 #define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 291 #define VER_LAMEXP_BUILD 293
#define VER_LAMEXP_SUFFIX Beta-3 #define VER_LAMEXP_SUFFIX Beta-3
/* /*

View File

@ -596,18 +596,16 @@ AudioFileModel ProcessingDialog::updateMetaInfo(const AudioFileModel &audioFile)
{ {
if(!m_settings->writeMetaTags()) if(!m_settings->writeMetaTags())
{ {
AudioFileModel result(audioFile, false); return AudioFileModel(audioFile, false);
return result;
} }
AudioFileModel result = audioFile; AudioFileModel result = audioFile;
result.updateMetaInfo(*m_metaInfo);
if(!m_metaInfo->fileArtist().isEmpty()) result.setFileArtist(m_metaInfo->fileArtist());
if(!m_metaInfo->fileAlbum().isEmpty()) result.setFileAlbum(m_metaInfo->fileAlbum()); if(m_metaInfo->filePosition() == UINT_MAX)
if(!m_metaInfo->fileGenre().isEmpty()) result.setFileGenre(m_metaInfo->fileGenre()); {
if(m_metaInfo->fileYear()) result.setFileYear(m_metaInfo->fileYear()); result.setFilePosition(m_currentFile);
if(m_metaInfo->filePosition() == UINT_MAX) result.setFilePosition(m_currentFile); }
if(!m_metaInfo->fileComment().isEmpty()) result.setFileComment(m_metaInfo->fileComment());
return result; return result;
} }

View File

@ -30,24 +30,15 @@
AudioFileModel::AudioFileModel(const QString &path, const QString &name) AudioFileModel::AudioFileModel(const QString &path, const QString &name)
{ {
resetAll();
m_filePath = path; m_filePath = path;
m_fileName = name; m_fileName = name;
m_fileYear = 0;
m_filePosition = 0;
m_fileDuration = 0;
m_formatAudioSamplerate = 0;
m_formatAudioChannels = 0;
m_formatAudioBitdepth = 0;
} }
AudioFileModel::AudioFileModel(const AudioFileModel &model, bool copyMetaInfo) AudioFileModel::AudioFileModel(const AudioFileModel &model, bool copyMetaInfo)
{ {
m_fileYear = 0; resetAll();
m_filePosition = 0;
m_fileDuration = 0;
m_formatAudioSamplerate = 0;
m_formatAudioChannels = 0;
m_formatAudioBitdepth = 0;
setFilePath(model.m_filePath); setFilePath(model.m_filePath);
setFormatContainerType(model.m_formatContainerType); setFormatContainerType(model.m_formatContainerType);
@ -100,6 +91,34 @@ AudioFileModel::~AudioFileModel(void)
{ {
} }
////////////////////////////////////////////////////////////
// Private Functions
////////////////////////////////////////////////////////////
void AudioFileModel::resetAll(void)
{
m_filePath.clear();
m_fileName.clear();
m_fileArtist.clear();
m_fileAlbum.clear();
m_fileGenre.clear();
m_fileComment.clear();
m_fileYear = 0;
m_filePosition = 0;
m_fileDuration = 0;
m_formatContainerType.clear();
m_formatContainerProfile.clear();
m_formatAudioType.clear();
m_formatAudioProfile.clear();
m_formatAudioVersion.clear();
m_formatAudioSamplerate = 0;
m_formatAudioChannels = 0;
m_formatAudioBitdepth = 0;
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Public Functions // Public Functions
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -362,3 +381,12 @@ void AudioFileModel::setFormatAudioBitdepth(unsigned int bitdepth)
{ {
m_formatAudioBitdepth = bitdepth; m_formatAudioBitdepth = bitdepth;
} }
void AudioFileModel::updateMetaInfo(const AudioFileModel &model)
{
if(!model.fileArtist().isEmpty()) setFileArtist(model.fileArtist());
if(!model.fileAlbum().isEmpty()) setFileAlbum(model.fileAlbum());
if(!model.fileGenre().isEmpty()) setFileGenre(model.fileGenre());
if(!model.fileComment().isEmpty()) setFileComment(model.fileComment());
if(model.fileYear()) setFileYear(model.fileYear());
}

View File

@ -85,6 +85,8 @@ public:
void setFormatAudioChannels(unsigned int channels); void setFormatAudioChannels(unsigned int channels);
void setFormatAudioBitdepth(unsigned int bitdepth); void setFormatAudioBitdepth(unsigned int bitdepth);
void updateMetaInfo(const AudioFileModel &model);
private: private:
QString m_filePath; QString m_filePath;
QString m_fileName; QString m_fileName;
@ -104,4 +106,6 @@ private:
unsigned int m_formatAudioSamplerate; unsigned int m_formatAudioSamplerate;
unsigned int m_formatAudioChannels; unsigned int m_formatAudioChannels;
unsigned int m_formatAudioBitdepth; unsigned int m_formatAudioBitdepth;
void resetAll(void);
}; };