aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-08-20 17:32:59 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-08-20 17:32:59 +0200
commitff5043389228e1de70d6e02f558de53e9f0ade8d (patch)
tree76603cf9f0739f9cd9806e81a4db3226a9dec088
parentFix up the prototypes. (diff)
downloadmusic-file-organizer-ff5043389228e1de70d6e02f558de53e9f0ade8d.tar.xz
music-file-organizer-ff5043389228e1de70d6e02f558de53e9f0ade8d.zip
Make the accesors inline and document AudioFile.cpp.
-rw-r--r--AudioFile.cpp86
-rw-r--r--AudioFile.h39
2 files changed, 31 insertions, 94 deletions
diff --git a/AudioFile.cpp b/AudioFile.cpp
index 6c84dc5..1e5e6fb 100644
--- a/AudioFile.cpp
+++ b/AudioFile.cpp
@@ -16,6 +16,7 @@
#include <mp4file.h>
#include <mp4tag.h>
+/* Turn a string into an integer type for any map class. */
template <typename T, typename M>
inline T extractTag(M &map, const char *key)
{
@@ -24,6 +25,7 @@ inline T extractTag(M &map, const char *key)
stream >> ret;
return ret;
}
+/* Turn a string into a bool, based on "1" and "true", for any map class. */
template <typename M>
inline bool extractTag(M &map, const char *key)
{
@@ -31,6 +33,7 @@ inline bool extractTag(M &map, const char *key)
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
return (str == "1" || str == "true");
}
+/* Extract a string out of an MP3 map. */
template <>
inline std::string extractTag(const TagLib::ID3v2::FrameListMap &map, const char *key)
{
@@ -38,6 +41,7 @@ inline std::string extractTag(const TagLib::ID3v2::FrameListMap &map, const char
return std::string();
return map[key].front()->toString().to8Bit(true);
}
+/* Extract a string out of an OGG map. */
template <>
inline std::string extractTag(const TagLib::Ogg::FieldListMap &map, const char *key)
{
@@ -45,6 +49,7 @@ inline std::string extractTag(const TagLib::Ogg::FieldListMap &map, const char *
return std::string();
return map[key].front().to8Bit(true);
}
+/* Extract an integer out of an MP4 map. */
template <>
inline unsigned int extractTag(const TagLib::MP4::ItemListMap &map, const char *key)
{
@@ -52,6 +57,7 @@ inline unsigned int extractTag(const TagLib::MP4::ItemListMap &map, const char *
return 0;
return map[key].toInt();
}
+/* Extract a string out of an MP4 map. */
template <>
inline std::string extractTag(const TagLib::MP4::ItemListMap &map, const char *key)
{
@@ -59,6 +65,7 @@ inline std::string extractTag(const TagLib::MP4::ItemListMap &map, const char *k
return std::string();
return map[key].toStringList().toString().to8Bit(true);
}
+/* Extract a bool out of an MP4 map. */
template <>
inline bool extractTag(const TagLib::MP4::ItemListMap &map, const char *key)
{
@@ -93,11 +100,14 @@ AudioFile::AudioFile(const std::string &filename) :
m_genre = tag->genre().to8Bit(true);
m_year = tag->year();
m_track = tag->track();
+ /* Sometimes these integers are supposed to wrap,
+ * and taglib doesn't know about it, so we do it manually. */
if (m_track == 4294967295)
m_track = 0;
if (m_year == 4294967295)
m_year = 0;
}
+ /* If there isn't a title, generate one from the basename sans-extension of the file. */
if (m_title.length() == 0) {
size_t pos;
m_title = filename;
@@ -108,6 +118,7 @@ AudioFile::AudioFile(const std::string &filename) :
if (pos != std::string::npos)
m_title.erase(pos);
}
+ /* TagLib also provides AudioProperties. */
if (const TagLib::AudioProperties *audio = fileRef.audioProperties()) {
m_length = audio->length();
m_bitrate = audio->bitrate();
@@ -115,7 +126,7 @@ AudioFile::AudioFile(const std::string &filename) :
m_channels = audio->channels();
}
- /* Now we look at format specific tags. */
+ /* Now we look at format specific tags, attempting to upcast, and then extracting fields. */
if (TagLib::MPEG::File *file = dynamic_cast<TagLib::MPEG::File*>(fileRef.file())) {
if (file->ID3v2Tag()) {
const TagLib::ID3v2::FrameListMap &map = file->ID3v2Tag()->frameListMap();
@@ -155,76 +166,3 @@ AudioFile::AudioFile(const std::string &filename) :
m_isValid = true;
}
-
-bool AudioFile::isValid() const
-{
- return m_isValid;
-}
-std::string AudioFile::filename() const
-{
- return m_filename;
-}
-std::string AudioFile::artist() const
-{
- return m_artist;
-}
-std::string AudioFile::composer() const
-{
- return m_composer;
-}
-std::string AudioFile::album() const
-{
- return m_album;
-}
-std::string AudioFile::albumArtist() const
-{
- return m_albumArtist;
-}
-std::string AudioFile::title() const
-{
- return m_title;
-}
-std::string AudioFile::genre() const
-{
- return m_genre;
-}
-std::string AudioFile::comment() const
-{
- return m_comment;
-}
-unsigned int AudioFile::track() const
-{
- return m_track;
-}
-unsigned int AudioFile::disc() const
-{
- return m_disc;
-}
-unsigned int AudioFile::bpm() const
-{
- return m_bpm;
-}
-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 64ecdbc..f44c741 100644
--- a/AudioFile.h
+++ b/AudioFile.h
@@ -4,29 +4,28 @@ class AudioFile
{
public:
AudioFile(const std::string &filename);
- bool isValid() const;
-
- std::string filename() const;
- std::string artist() const;
- std::string composer() const;
- std::string album() const;
- std::string albumArtist() const;
- std::string title() const;
- std::string genre() const;
- std::string comment() const;
- unsigned int track() const;
- 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;
+
+ inline bool isValid() const { return m_isValid; };
+ inline std::string filename() const { return m_filename; };
+ inline std::string artist() const { return m_artist; };
+ inline std::string composer() const { return m_composer; };
+ inline std::string album() const { return m_album; };
+ inline std::string albumArtist() const { return m_albumArtist; };
+ inline std::string title() const { return m_title; };
+ inline std::string genre() const { return m_genre; };
+ inline std::string comment() const { return m_comment; };
+ inline unsigned int track() const { return m_track; };
+ inline unsigned int disc() const { return m_disc; };
+ inline unsigned int bpm() const { return m_bpm; };
+ inline unsigned int year() const { return m_year; };
+ inline unsigned int length() const { return m_length; };
+ inline unsigned int bitrate() const { return m_bitrate; };
+ inline unsigned int sampleRate() const { return m_sampleRate; };
+ inline unsigned int channels() const { return m_channels; };
+ inline bool compilation() const { return m_compilation; };
private:
bool m_isValid;
-
std::string m_filename;
std::string m_artist;
std::string m_composer;