diff options
author | 2012-08-19 23:18:43 +0200 | |
---|---|---|
committer | 2012-08-19 23:18:43 +0200 | |
commit | 5ecc34ef1e8e7e26e57f373babaa194cb9328ab1 (patch) | |
tree | 12a6ffba5eb628524a230241cf8bb0b334adf457 | |
parent | Add read tag program. Fix uninitialized error. (diff) | |
download | music-file-organizer-5ecc34ef1e8e7e26e57f373babaa194cb9328ab1.tar.xz music-file-organizer-5ecc34ef1e8e7e26e57f373babaa194cb9328ab1.zip |
Support audio properties too.
-rw-r--r-- | AudioFile.cpp | 43 | ||||
-rw-r--r-- | AudioFile.h | 8 | ||||
-rw-r--r-- | readtags.cpp | 4 |
3 files changed, 47 insertions, 8 deletions
diff --git a/AudioFile.cpp b/AudioFile.cpp index 5157b11..9c3f612 100644 --- a/AudioFile.cpp +++ b/AudioFile.cpp @@ -74,6 +74,10 @@ AudioFile::AudioFile(const std::string &filename) : m_disc(0), m_bpm(0), m_year(0), + m_length(0), + m_bitrate(0), + m_sampleRate(0), + m_channels(0), m_compilation(false) { TagLib::FileRef fileRef(filename.c_str()); @@ -81,14 +85,21 @@ AudioFile::AudioFile(const std::string &filename) : return; /* First we copy out everything TagLib actually supports. */ - const TagLib::Tag *tag = fileRef.tag(); - m_title = tag->title().to8Bit(true); - m_artist = tag->artist().to8Bit(true); - m_album = tag->album().to8Bit(true); - m_comment = tag->comment().to8Bit(true); - m_genre = tag->genre().to8Bit(true); - m_year = tag->year(); - m_track = tag->track(); + if (const TagLib::Tag *tag = fileRef.tag()) { + m_title = tag->title().to8Bit(true); + m_artist = tag->artist().to8Bit(true); + m_album = tag->album().to8Bit(true); + m_comment = tag->comment().to8Bit(true); + m_genre = tag->genre().to8Bit(true); + m_year = tag->year(); + m_track = tag->track(); + } + if (const TagLib::AudioProperties *audio = fileRef.audioProperties()) { + m_length = audio->length(); + m_bitrate = audio->bitrate(); + m_sampleRate = audio->sampleRate(); + m_channels = audio->channels(); + } /* Now we look at format specific tags. */ if (TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File*>(fileRef.file())) { @@ -183,6 +194,22 @@ unsigned int AudioFile::year() const { return m_year; } +unsigned int AudioFile::length() const +{ + return m_length; +} +unsigned int AudioFile::bitrate() const +{ + return m_bitrate; +} +unsigned int AudioFile::sampleRate() const +{ + return m_sampleRate; +} +unsigned int AudioFile::channels() const +{ + return m_channels; +} bool AudioFile::compilation() const { return m_compilation; diff --git a/AudioFile.h b/AudioFile.h index 73618ba..64ecdbc 100644 --- a/AudioFile.h +++ b/AudioFile.h @@ -18,6 +18,10 @@ public: unsigned int disc() const; unsigned int bpm() const; unsigned int year() const; + unsigned int length() const; + unsigned int bitrate() const; + unsigned int sampleRate() const; + unsigned int channels() const; bool compilation() const; private: @@ -35,5 +39,9 @@ private: unsigned int m_disc; unsigned int m_bpm; unsigned int m_year; + unsigned int m_length; + unsigned int m_bitrate; + unsigned int m_sampleRate; + unsigned int m_channels; bool m_compilation; }; diff --git a/readtags.cpp b/readtags.cpp index b5a3ef4..169645c 100644 --- a/readtags.cpp +++ b/readtags.cpp @@ -24,6 +24,10 @@ int main(int argc, char *argv[]) cout << "Disc: " << f.disc() << endl; cout << "Bpm: " << f.bpm() << endl; cout << "Year: " << f.year() << endl; + cout << "Length: " << f.length() << endl; + cout << "Bitrate: " << f.bitrate() << endl; + cout << "Sample Rate: " << f.sampleRate() << endl; + cout << "Channels: " << f.channels() << endl; cout << "Compilation: " << f.compilation() << endl; cout << endl; } |