TTKMusicPlayer  4.3.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicobject.h
Go to the documentation of this file.
1 #ifndef MUSICOBJECT_H
2 #define MUSICOBJECT_H
3 
4 /***************************************************************************
5  * This file is part of the TTK Music Player project
6  * Copyright (C) 2015 - 2026 Greedysky Studio
7 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License along
19  * with this program; If not, see <http://www.gnu.org/licenses/>.
20  ***************************************************************************/
21 
22 #include <QDir>
23 
24 #include "ttkqtglobal.h"
25 #include "ttkqtobject.h"
26 
27 #define TKF_FILE_SUFFIX "tkf"
28 #define TKX_FILE_SUFFIX "tkx"
29 #define TKM_FILE_SUFFIX "tkm"
30 #define TKB_FILE_SUFFIX "tkb"
31 //
32 #define SKN_FILE_SUFFIX "skn"
33 #define JPG_FILE_SUFFIX "jpg"
34 #define PNG_FILE_SUFFIX "png"
35 #define XML_FILE_SUFFIX "xml"
36 //
37 #define LRC_FILE_SUFFIX "lrc"
38 #define KRC_FILE_SUFFIX "krc"
39 #define QRC_FILE_SUFFIX "qrc"
40 #define TRC_FILE_SUFFIX "trc"
41 #define YRC_FILE_SUFFIX "yrc"
42 #define KSC_FILE_SUFFIX "ksc"
43 // playlist ext
44 #define TPL_FILE_SUFFIX "tkpl"
45 #define M3U_FILE_SUFFIX "m3u"
46 #define M3U8_FILE_SUFFIX "m3u8"
47 #define PLS_FILE_SUFFIX "pls"
48 #define WPL_FILE_SUFFIX "wpl"
49 #define XSPF_FILE_SUFFIX "xspf"
50 #define JSPF_FILE_SUFFIX "jspf"
51 #define ASX_FILE_SUFFIX "asx"
52 #define CSV_FILE_SUFFIX "csv"
53 #define TXT_FILE_SUFFIX "txt"
54 #define FPL_FILE_SUFFIX "fpl"
55 #define DBPL_FILE_SUFFIX "dbpl"
56 // file ext
57 #define AAC_FILE_SUFFIX "aac"
58 #define MP3_FILE_SUFFIX "mp3"
59 #define APE_FILE_SUFFIX "ape"
60 #define FLAC_FILE_SUFFIX "flac"
61 #define MP4_FILE_SUFFIX "mp4"
62 #define FLV_FILE_SUFFIX "flv"
63 
64 
65 #define TKF_FILE TTK_STR_CAT(TTK_DOT, TKF_FILE_SUFFIX)
66 #define TKX_FILE TTK_STR_CAT(TTK_DOT, TKX_FILE_SUFFIX)
67 #define TKM_FILE TTK_STR_CAT(TTK_DOT, TKM_FILE_SUFFIX)
68 #define TKB_FILE TTK_STR_CAT(TTK_DOT, TKB_FILE_SUFFIX)
69 //
70 #define SKN_FILE TTK_STR_CAT(TTK_DOT, SKN_FILE_SUFFIX)
71 #define JPG_FILE TTK_STR_CAT(TTK_DOT, JPG_FILE_SUFFIX)
72 #define PNG_FILE TTK_STR_CAT(TTK_DOT, PNG_FILE_SUFFIX)
73 #define XML_FILE TTK_STR_CAT(TTK_DOT, XML_FILE_SUFFIX)
74 #define TPL_FILE TTK_STR_CAT(TTK_DOT, TPL_FILE_SUFFIX)
75 //
76 #define LRC_FILE TTK_STR_CAT(TTK_DOT, LRC_FILE_SUFFIX)
77 #define KRC_FILE TTK_STR_CAT(TTK_DOT, KRC_FILE_SUFFIX)
78 #define QRC_FILE TTK_STR_CAT(TTK_DOT, QRC_FILE_SUFFIX)
79 #define TRC_FILE TTK_STR_CAT(TTK_DOT, TRC_FILE_SUFFIX)
80 #define YRC_FILE TTK_STR_CAT(TTK_DOT, YRC_FILE_SUFFIX)
81 #define KSC_FILE TTK_STR_CAT(TTK_DOT, KSC_FILE_SUFFIX)
82 // file ext
83 #define AAC_FILE TTK_STR_CAT(TTK_DOT, AAC_FILE_SUFFIX)
84 #define MP3_FILE TTK_STR_CAT(TTK_DOT, MP3_FILE_SUFFIX)
85 #define APE_FILE TTK_STR_CAT(TTK_DOT, APE_FILE_SUFFIX)
86 #define FLAC_FILE TTK_STR_CAT(TTK_DOT, FLAC_FILE_SUFFIX)
87 #define MP4_FILE TTK_STR_CAT(TTK_DOT, MP4_FILE_SUFFIX)
88 #define FLV_FILE TTK_STR_CAT(TTK_DOT, FLV_FILE_SUFFIX)
89 
90 
91 #define APPDATA_DIR TTK_STR_CAT("AppData", TTK_SEPARATOR)
92 #define APPCACHE_DIR TTK_STR_CAT("AppCache", TTK_SEPARATOR)
93 #define APPBACKUP_DIR TTK_STR_CAT("AppBackup", TTK_SEPARATOR)
94 #define DOWNLOAD_DIR TTK_STR_CAT("Downloads", TTK_SEPARATOR)
95 //
96 #define LRC_DIR TTK_STR_CAT("Lyric", TTK_SEPARATOR)
97 #define MUSIC_DIR TTK_STR_CAT("Music", TTK_SEPARATOR)
98 #define ARCHIVE_DIR TTK_STR_CAT("Archive", TTK_SEPARATOR)
99 //
100 #define LANGUAGE_DIR TTK_STR_CAT("GLanguage", TTK_SEPARATOR)
101 #define PLUGINS_DIR TTK_STR_CAT("GPlugins", TTK_SEPARATOR)
102 #define THEME_DIR TTK_STR_CAT("GTheme", TTK_SEPARATOR)
103 //
104 #define ART_DIR TTK_STR_CAT("Art", TTK_SEPARATOR)
105 #define BACKGROUND_DIR TTK_STR_CAT("Background", TTK_SEPARATOR)
106 #define CACHE_DIR TTK_STR_CAT("Cache", TTK_SEPARATOR)
107 #define RESOURCE_DIR TTK_STR_CAT("resource", TTK_SEPARATOR)
108 //
109 #define CONFIG_DIR TTK_STR_CAT("config", TTK_SEPARATOR)
110 #define USER_THEME_DIR TTK_STR_CAT("theme", TTK_SEPARATOR)
111 
112 
113 #define MAKE_TRANSFORM_NAME TTK_STR_CAT("avconv", TKX_FILE)
114 #define MAKE_PLAYER_NAME TTK_STR_CAT("avplayer", TKX_FILE)
115 #define MAKE_GAIN_NAME TTK_STR_CAT("avgain", TKX_FILE)
116 
117 
118 #define MAKE_CONFIG_DIR TTK_STR_CAT(PLUGINS_DIR, CONFIG_DIR)
119 #define MAKE_TRANSFORM_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_TRANSFORM_NAME)
120 #define MAKE_PLAYER_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_PLAYER_NAME)
121 #define MAKE_GAIN_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_GAIN_NAME)
122 
123 
124 #define COFIG_PATH TTK_STR_CAT("config", XML_FILE)
125 #define PLAYLIST_PATH TTK_STR_CAT("playlist", TPL_FILE)
126 #define NORMAL_DOWN_PATH TTK_STR_CAT("download", TKF_FILE)
127 #define CLOUD_DOWN_PATH TTK_STR_CAT("cdownload", TKF_FILE)
128 #define CLOUD_UP_PATH TTK_STR_CAT("cupload", TKF_FILE)
129 #define SEARCH_PATH TTK_STR_CAT("search", TKF_FILE)
130 
131 
132 #define MAIN_DIR_FULL TTK::applicationPath() + TTK_PARENT_DIR
133 //
134 #ifdef Q_OS_WIN
135 # define DOWNLOAD_DIR_FULL MAIN_DIR_FULL + DOWNLOAD_DIR
136 #else
137 # define DOWNLOAD_DIR_FULL QDir::homePath() + TTK_STR_CAT("/.cache/", TTK_APP_NAME, TTK_SEPARATOR) + DOWNLOAD_DIR
138 #endif
139 #define APPDATA_DIR_FULL TTK::configPath() + APPDATA_DIR
140 #define APPCACHE_DIR_FULL TTK::configPath() + APPCACHE_DIR
141 #define APPBACKUP_DIR_FULL TTK::configPath() + APPBACKUP_DIR
142 //
143 #define LRC_DIR_FULL DOWNLOAD_DIR_FULL + LRC_DIR
144 #define MUSIC_DIR_FULL DOWNLOAD_DIR_FULL + MUSIC_DIR
145 #define ARCHIVE_DIR_FULL DOWNLOAD_DIR_FULL + ARCHIVE_DIR
146 //
147 #define ART_DIR_FULL APPCACHE_DIR_FULL + ART_DIR
148 #define BACKGROUND_DIR_FULL APPCACHE_DIR_FULL + BACKGROUND_DIR
149 #define CACHE_DIR_FULL APPCACHE_DIR_FULL + CACHE_DIR
150 #define RESOURCE_DIR_FULL APPCACHE_DIR_FULL + RESOURCE_DIR
151 //
152 #define COFIG_PATH_FULL APPDATA_DIR_FULL + COFIG_PATH
153 #define PLAYLIST_PATH_FULL APPDATA_DIR_FULL + PLAYLIST_PATH
154 #define NORMAL_DOWN_PATH_FULL APPDATA_DIR_FULL + NORMAL_DOWN_PATH
155 #define CLOUD_DOWN_PATH_FULL APPDATA_DIR_FULL + CLOUD_DOWN_PATH
156 #define CLOUD_UP_PATH_FULL APPDATA_DIR_FULL + CLOUD_UP_PATH
157 #define SEARCH_PATH_FULL APPDATA_DIR_FULL + SEARCH_PATH
158 #define USER_THEME_DIR_FULL APPDATA_DIR_FULL + USER_THEME_DIR
159 
160 
161 #define THEME_DIR_FULL TTK::applicationPath() + THEME_DIR
162 #define PLUGINS_DIR_FULL TTK::applicationPath() + PLUGINS_DIR
163 #define LANGUAGE_DIR_FULL TTK::applicationPath() + LANGUAGE_DIR
164 
165 
166 #define MAKE_CONFIG_DIR_FULL TTK::applicationPath() + MAKE_CONFIG_DIR
167 #define MAKE_TRANSFORM_PATH_FULL TTK::applicationPath() + MAKE_TRANSFORM_PATH
168 #define MAKE_PLAYER_PATH_FULL TTK::applicationPath() + MAKE_PLAYER_PATH
169 #define MAKE_GAIN_PATH_FULL TTK::applicationPath() + MAKE_GAIN_PATH
170 
171 
172 #define WINDOW_WIDTH_MIN 1000
173 #define WINDOW_HEIGHT_MIN 665
174 #define LEFT_SIDE_WIDTH_MIN 320
175 #define CONCISE_WIDTH_MIN LEFT_SIDE_WIDTH_MIN + 2
176 
177 
181 namespace TTK
182 {
183  enum class PlayState
184  {
185  Stopped,
186  Playing,
187  Paused
188  };
189 
190  enum class PlayMode
191  {
192  Order,
193  Random,
194  ListLoop,
195  OneLoop,
196  Once
197  };
198 
199  enum class FontStyleMode
200  {
201  Bold = 0x0001,
202  Italic = 0x0002,
203  Underline = 0x0004,
204  Overline = 0x0008,
205  StrikeOut = 0x0010,
206  FixedPitch = 0x0020,
207  Kerningt = 0x0040
208  };
209 
210  enum class QueryQuality
211  {
212  None,
213  Standard,
214  High,
215  Super,
216  Lossless
217  };
218 
219 
224  {
225  int m_first;
226  int m_second;
227 
228  IndexProperty() = default;
229  IndexProperty(int first, int second) noexcept
230  : m_first(first),
231  m_second(second)
232  {
233 
234  }
235  };
236  TTK_DECLARE_LIST(IndexProperty);
237 
238 
243  {
245  QString m_format;
246  QString m_url;
247  QString m_size;
248 
249  MusicSongProperty() noexcept
250  : m_bitrate(-1)
251  {
252 
253  }
254 
255  inline bool isEmpty() const noexcept
256  {
257  return m_url.isEmpty();
258  }
259 
260  inline bool operator< (const MusicSongProperty &other) const noexcept
261  {
262  return m_bitrate < other.m_bitrate;
263  }
264 
265  inline bool operator== (const MusicSongProperty &other) const noexcept
266  {
267  return m_bitrate == other.m_bitrate || m_url == other.m_url;
268  }
269  };
270  TTK_DECLARE_LIST(MusicSongProperty);
271 
272 
277  {
278  QString m_id;
279  QString m_name;
280 
281  MusicArtistProperty() = default;
282  MusicArtistProperty(const QString &id, const QString &name) noexcept
283  : m_id(id),
284  m_name(name)
285  {
286 
287  }
288 
289  inline bool isEmpty() const noexcept
290  {
291  return m_id.isEmpty() || m_name.isEmpty();
292  }
293  };
294  TTK_DECLARE_LIST(MusicArtistProperty);
295 
296 
301  {
302  QString m_songId;
303  QString m_songName;
304  QString m_artistId;
305  QString m_artistName;
306  QString m_albumId;
307  QString m_albumName;
308  QString m_coverUrl;
309  QString m_lrcUrl;
310  QString m_duration;
311  QString m_year;
312  QString m_trackNumber;
313  QString m_formatProps;
314  MusicSongPropertyList m_songProps;
315  };
317 
318 
322  inline static QString configPath()
323  {
324  const bool portable = QFile::exists(MAIN_DIR_FULL + "ttk_portable");
325 #ifdef Q_OS_WIN
326  return (portable ? MAIN_DIR_FULL : QString::fromLocal8Bit(qgetenv("APPDATA")) + TTK_SEPARATOR) + "ttkmp/";
327 #else
328  return (portable ? MAIN_DIR_FULL : QDir::homePath() + TTK_SEPARATOR) + ".config/ttkmp/";
329 #endif
330  }
331 }
332 
333 #endif // MUSICOBJECT_H
PlayState
Definition: musicobject.h:183
IndexProperty(int first, int second) noexcept
Definition: musicobject.h:229
The class of the music song property.
Definition: musicobject.h:242
bool isEmpty() const noexcept
Definition: musicobject.h:289
MusicSongPropertyList m_songProps
Definition: musicobject.h:314
The class of the index property.
Definition: musicobject.h:223
#define MAIN_DIR_FULL
Definition: musicobject.h:132
The class of the music artist property.
Definition: musicobject.h:276
const char * name
Definition: http_parser.c:458
QueryQuality
Definition: musicobject.h:210
MusicSongProperty() noexcept
Definition: musicobject.h:249
The namespace of the application object.
Definition: ttkcompat.h:24
FontStyleMode
Definition: musicobject.h:199
PlayMode
Definition: musicobject.h:190
bool isEmpty() const noexcept
Definition: musicobject.h:255
#define TTK_SEPARATOR
Definition: ttkglobal.h:269
MusicArtistProperty(const QString &id, const QString &name) noexcept
Definition: musicobject.h:282
bool operator==(const MusicSongProperty &other) const noexcept
Definition: musicobject.h:265
IndexProperty()=default
static QString configPath()
Definition: musicobject.h:322
#define const
Definition: zconf.h:233
bool operator<(const MusicSongProperty &other) const noexcept
Definition: musicobject.h:260
TTK_DECLARE_LIST(IndexProperty)
The class of the music song information.
Definition: musicobject.h:300