From 46e613dcca9a020c8199600cfc7b85c4ce2f256d Mon Sep 17 00:00:00 2001
From: Tsuda Kageyu <tsuda.kageyu@gmail.com>
Date: Thu, 4 Oct 2012 19:23:10 +0900
Subject: [PATCH] Add reading/writing ID3v1 genre in number

---
 taglib/mpeg/id3v1/id3v1tag.cpp | 14 ++++++++++++--
 taglib/mpeg/id3v1/id3v1tag.h   | 23 +++++++++++++++++++----
 2 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp
index e9eb47bf..9fc8cfd7 100644
--- a/taglib/mpeg/id3v1/id3v1tag.cpp
+++ b/taglib/mpeg/id3v1/id3v1tag.cpp
@@ -182,16 +182,26 @@ void ID3v1::Tag::setGenre(const String &s)
   d->genre = ID3v1::genreIndex(s);
 }
 
-void ID3v1::Tag::setYear(uint i)
+void ID3v1::Tag::setYear(TagLib::uint i)
 {
   d->year = i > 0 ? String::number(i) : String::null;
 }
 
-void ID3v1::Tag::setTrack(uint i)
+void ID3v1::Tag::setTrack(TagLib::uint i)
 {
   d->track = i < 256 ? i : 0;
 }
 
+TagLib::uint ID3v1::Tag::genreNumber() const
+{
+  return d->genre;
+}
+
+void ID3v1::Tag::setGenreNumber(TagLib::uint i)
+{
+  d->genre = i < 256 ? i : 255;
+}
+
 void ID3v1::Tag::setStringHandler(const StringHandler *handler)
 {
   if (handler)
diff --git a/taglib/mpeg/id3v1/id3v1tag.h b/taglib/mpeg/id3v1/id3v1tag.h
index 9332d4dc..7b26d023 100644
--- a/taglib/mpeg/id3v1/id3v1tag.h
+++ b/taglib/mpeg/id3v1/id3v1tag.h
@@ -140,16 +140,31 @@ namespace TagLib {
       virtual String album() const;
       virtual String comment() const;
       virtual String genre() const;
-      virtual uint year() const;
-      virtual uint track() const;
+      virtual TagLib::uint year() const;
+      virtual TagLib::uint track() const;
 
       virtual void setTitle(const String &s);
       virtual void setArtist(const String &s);
       virtual void setAlbum(const String &s);
       virtual void setComment(const String &s);
       virtual void setGenre(const String &s);
-      virtual void setYear(uint i);
-      virtual void setTrack(uint i);
+      virtual void setYear(TagLib::uint i);
+      virtual void setTrack(TagLib::uint i);
+
+      /*!
+       * Returns the genre in number.
+       *
+       * /note Normally 255 indicates that this tag contains no genre.
+       */
+      TagLib::uint genreNumber() const;
+
+      /*!
+       * Sets the genre in number to \a i.
+       *
+       * /note Valid value is from 0 up to 255. Normally 255 indicates that
+       * this tag contains no genre.
+       */
+      void setGenreNumber(TagLib::uint i);
 
       /*!
        * Sets the string handler that decides how the ID3v1 data will be