1 /***************************************************************************
2 * Copyright (C) 2008-2021 by Ilya Kotov *
3 * forkotov02@ya.ru *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
20 #ifndef QMMP_H
21 #define QMMP_H
22
23 #include <QString>
24 #include "qmmp_export.h"
25
26 #define QMMP_VERSION_MAJOR 1
27 #define QMMP_VERSION_MINOR 5
28 #define QMMP_VERSION_PATCH 2
29 #define QMMP_VERSION_STABLE 1
30
31 #define QMMP_VERSION_INT (QMMP_VERSION_MAJOR<<16 | QMMP_VERSION_MINOR<<8 | QMMP_VERSION_PATCH)
32
33 /*!
34 * Converts a \b QString to a \b TagLib::FileName
35 */
36 #ifdef Q_OS_WIN
37 #define QStringToFileName(s) TagLib::FileName(reinterpret_cast<const wchar_t *>(s.utf16()))
38 #else
39 #define QStringToFileName(s) s.toLocal8Bit().constData()
40 #endif
41
42 #if (QT_VERSION < QT_VERSION_CHECK(5, 7, 0))
43 // this adds const to non-const objects (like std::as_const)
44 template <typename T>
qAsConst(T & t)45 Q_DECL_CONSTEXPR typename std::add_const<T>::type &qAsConst(T &t) noexcept { return t; }
46 // prevent rvalue arguments:
47 template <typename T>
48 void qAsConst(const T &&) = delete;
49 #endif
50
51
52 /*! @brief The Qmmp class stores global settings and enums.
53 * @author Ilya Kotov <forkotov02@ya.ru>
54 */
55 class QMMP_EXPORT Qmmp
56 {
57 public:
58 /*!
59 * Playback state enum
60 */
61 enum State
62 {
63 Playing = 0, /*!< The player is playing source */
64 Paused, /*!< The player has currently paused its playback */
65 Stopped, /*!< The player is ready to play source */
66 Buffering, /*!< The Player is waiting for data to be able to start playing. */
67 NormalError, /*!< Input source is invalid or unsupported. Player should skip this file */
68 FatalError /*!< This means unrecorvable error die audio output problems. Player should abort playback. */
69 };
70 /*!
71 * Metadata keys
72 */
73 enum MetaData
74 {
75 UNKNOWN = -1,
76 TITLE = 0, /*!< Title */
77 ARTIST, /*!< Artist */
78 ALBUMARTIST,/*!< Album artist */
79 ALBUM, /*!< Album */
80 COMMENT, /*!< Comment */
81 GENRE, /*!< Genre */
82 COMPOSER, /*!< Composer */
83 YEAR, /*!< Year */
84 TRACK, /*!< Track number */
85 DISCNUMBER /*!< Disc number */
86 };
87 /*!
88 * Track properties
89 */
90 enum TrackProperty
91 {
92 UNKNOWN_PROPERTY = -1,
93 BITRATE = 0,
94 SAMPLERATE,
95 CHANNELS,
96 BITS_PER_SAMPLE,
97 FORMAT_NAME,
98 DECODER,
99 FILE_SIZE
100 };
101 /*!
102 * Keys of ReplayGain information
103 */
104 enum ReplayGainKey
105 {
106 REPLAYGAIN_TRACK_GAIN = 0, /*!< track gain */
107 REPLAYGAIN_TRACK_PEAK, /*!< track peak */
108 REPLAYGAIN_ALBUM_GAIN, /*!< album gain */
109 REPLAYGAIN_ALBUM_PEAK /*!< album peak */
110 };
111 /*!
112 * Audio formats
113 */
114 enum AudioFormat
115 {
116 PCM_UNKNOWN = -1, /*!< Unknown format */
117 PCM_S8 = 0, /*!< Signed 8 bit */
118 PCM_U8, /*!< Unsigned 8 bit */
119 PCM_S16LE, /*!< Signed 16 bit Little Endian */
120 PCM_S16BE, /*!< Signed 16 bit Big Endian */
121 PCM_U16LE, /*!< Unsigned 16 bit Little Endian */
122 PCM_U16BE, /*!< Unsigned 16 bit Big Endian */
123 PCM_S24LE, /*!< Signed 24 bit Little Endian using low three bytes in 32-bit word */
124 PCM_S24BE, /*!< Signed 24 bit Big Endian using low three bytes in 32-bit word */
125 PCM_U24LE, /*!< Unsigned 24 bit Little Endian using low three bytes in 32-bit word */
126 PCM_U24BE, /*!< Unsigned 24 bit Big Endian using low three bytes in 32-bit word */
127 PCM_S32LE, /*!< Signed 32 bit Little Endian */
128 PCM_S32BE, /*!< Signed 32 bit Big Endian */
129 PCM_U32LE, /*!< Unsigned 32 bit Little Endian */
130 PCM_U32BE, /*!< Unsigned 32 bit Big Endian */
131 PCM_FLOAT /*!< Float 32 bit Native Endian, range: -1.0 to 1.0 */
132 };
133
134 /*!
135 * Audio channels enum.
136 */
137 enum ChannelPosition
138 {
139 CHAN_NULL = 0x00, /*!< No channel */
140 CHAN_FRONT_LEFT = 0x01, /*!< Front left channel */
141 CHAN_FRONT_RIGHT = 0x02, /*!< Front right channel */
142 CHAN_REAR_LEFT = 0x04, /*!< Rear left channel */
143 CHAN_REAR_RIGHT = 0x08, /*!< Rear right channel */
144 CHAN_FRONT_CENTER = 0x10, /*!< Front center channel */
145 CHAN_REAR_CENTER = 0x20, /*!< Rear center channel */
146 CHAN_SIDE_LEFT = 0x40, /*!< Side left channel */
147 CHAN_SIDE_RIGHT = 0x80, /*!< Side right channel */
148 CHAN_LFE = 0x100, /*!< Low-frequency effects channel */
149 };
150
151 /*!
152 * Returns the configuration file name, including the path.
153 */
154 static QString configFile();
155 /*!
156 * Returns the configuration directory path.
157 */
158 static QString configDir();
159 /*!
160 * Overrides default configuration directory path.
161 */
162 static void setConfigDir(const QString &path);
163 /*!
164 * Returns %Qmmp library version.
165 */
166 static QString strVersion();
167 /*!
168 * Returns the location of the installed Qmmp plugins.
169 */
170 static QString pluginPath();
171 /*!
172 * Returns a list of found Qmmp plugins (full paths).
173 * @param prefix Plugin type or directory name (examples: Inpunt, Transport, Output).
174 */
175 static QStringList findPlugins(const QString &prefix);
176 /*!
177 * Returns system language if uiLanguageID() is 'auto'. Otherwise returns uiLanguageID().
178 */
179 static QString systemLanguageID();
180 /*!
181 * Returns state of the user interface language option. Code "auto" means autodetection.
182 */
183 static QString uiLanguageID();
184 /*!
185 * Sets user interface language.
186 * @param code Language code; code "auto" means autodetection.
187 */
188 static void setUiLanguageID(const QString &code);
189 /*!
190 * Returns a directory location where persistent application data can be stored.
191 */
192 static QString dataPath();
193 #ifdef Q_OS_WIN
194 /*!
195 * Returns \b true if portable mode is enabled. Otherwise returns \b false.
196 */
197 static bool isPortable();
198 #endif
199
200 #if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
201 static QString wildcardToRegularExpression(const QString &pattern);
202 static QString anchoredPattern(const QString &expression);
203 #endif
204
205 private:
206 static QString m_configDir;
207 static QString m_langID;
208 #ifdef Q_OS_WIN
209 static QString m_appDir;
210 #endif
211
212 };
213
214 #endif
215