File indexing completed on 2024-05-19 04:56:11

0001 /**
0002  * \file genres.h
0003  * Alphabetical list of genres.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 9 Jan 2003
0008  *
0009  * Copyright (C) 2003-2018  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #pragma once
0028 
0029 #include <QtGlobal>
0030 #include "kid3api.h"
0031 
0032 class QString;
0033 
0034 /** Alphabetically sorted list of genres, conversion to/from genre numbers */
0035 class KID3_CORE_EXPORT Genres {
0036 public:
0037   /**
0038    * Get name assigned to genre number.
0039    *
0040    * @param num genre number
0041    *
0042    * @return name, empty string for unknown number.
0043    */
0044   static const char* getName(int num);
0045 
0046   /**
0047    * Get the index in the alphabetically sorted list from the genre number.
0048    *
0049    * @param num genre number
0050    *
0051    * @return index, 0 for unknown number.
0052    */
0053   static int getIndex(int num);
0054 
0055   /**
0056    * Get the genre number from a string containing a genre text.
0057    *
0058    * @param str string with genre
0059    *
0060    * @return genre number, 255 for unknown index.
0061    */
0062   static int getNumber(const QString& str);
0063 
0064   /**
0065    * Get a name string from a string with a number or a name.
0066    * ID3v2 genres can be stored as "9", "(9)", "(9)Metal" or "Metal".
0067    *
0068    * @param str genre string, it can also reference multiple ID3v1 genres
0069    * and have a refinement such as "(9)(138)Viking Metal".
0070    * Multiple genres can be separated by Frame::stringListSeparator().
0071    *
0072    * @return genre name or multiple genre names separated by
0073    * Frame::stringListSeparator().
0074    */
0075   static QString getNameString(const QString& str);
0076 
0077   /**
0078    * Get a number representation of a genre name if possible.
0079    *
0080    * @param str string with genre name, can also contain multiple genres
0081    * separated by Frame::stringListSeparator()
0082    * @param parentheses true to put the numbers in parentheses, this will
0083    * result in an ID3v2.3.0 genre string, which can containing multiple
0084    * references to ID3v1 genres and optionally a refinement as a genre text
0085    *
0086    * @return genre string using numbers where possible. If @a parentheses
0087    * is true, an ID3v2.3.0 genre string such as "(9)(138)Viking Metal" is
0088    * returned, else if @a str contains multiple genres, they are returned
0089    * as numbers (where possible) separated by Frame::stringListSeparator().
0090    */
0091   static QString getNumberString(const QString& str, bool parentheses);
0092 
0093   /** Number of genres */
0094 #ifdef Q_OS_WIN32
0095   enum { count = 192 };
0096 #else
0097   static const int count = 192;
0098 #endif
0099   /**
0100    * Pointer to alphabetic list of genres.
0101    * NULL terminated, to be used in combo box.
0102    */
0103   static const char** s_strList;
0104 
0105 private:
0106   /**
0107    * Alphabetic list of genres, starts with unknown (empty) entry.
0108    *
0109    * 125: Last ID3v1, 142: WinAmp 1.91, 145: WinAmp 1.92, 255: unknown
0110    */
0111   static const char* s_genre[Genres::count + 3];
0112   /**
0113    * s_genreNum[n] gives the number of the n-th genre
0114    * in the alphabetically sorted list.
0115    */
0116   static const unsigned char s_genreNum[Genres::count + 1];
0117 };