TTKMusicPlayer  4.1.3.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 - 2025 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 //
31 #define SKN_FILE_SUFFIX "skn"
32 #define JPG_FILE_SUFFIX "jpg"
33 #define PNG_FILE_SUFFIX "png"
34 #define LRC_FILE_SUFFIX "lrc"
35 #define KRC_FILE_SUFFIX "krc"
36 #define XML_FILE_SUFFIX "xml"
37 // playlist ext
38 #define TPL_FILE_SUFFIX "tkpl"
39 #define M3U_FILE_SUFFIX "m3u"
40 #define M3U8_FILE_SUFFIX "m3u8"
41 #define PLS_FILE_SUFFIX "pls"
42 #define WPL_FILE_SUFFIX "wpl"
43 #define XSPF_FILE_SUFFIX "xspf"
44 #define JSPF_FILE_SUFFIX "jspf"
45 #define ASX_FILE_SUFFIX "asx"
46 #define CSV_FILE_SUFFIX "csv"
47 #define TXT_FILE_SUFFIX "txt"
48 #define FPL_FILE_SUFFIX "fpl"
49 #define DBPL_FILE_SUFFIX "dbpl"
50 // file ext
51 #define MP3_FILE_SUFFIX "mp3"
52 #define APE_FILE_SUFFIX "ape"
53 #define FLAC_FILE_SUFFIX "flac"
54 #define MP4_FILE_SUFFIX "mp4"
55 #define FLV_FILE_SUFFIX "flv"
56 
57 
58 #define TKF_FILE TTK_STR_CAT(TTK_DOT, TKF_FILE_SUFFIX)
59 #define TKX_FILE TTK_STR_CAT(TTK_DOT, TKX_FILE_SUFFIX)
60 #define TKM_FILE TTK_STR_CAT(TTK_DOT, TKM_FILE_SUFFIX)
61 //
62 #define SKN_FILE TTK_STR_CAT(TTK_DOT, SKN_FILE_SUFFIX)
63 #define JPG_FILE TTK_STR_CAT(TTK_DOT, JPG_FILE_SUFFIX)
64 #define PNG_FILE TTK_STR_CAT(TTK_DOT, PNG_FILE_SUFFIX)
65 #define LRC_FILE TTK_STR_CAT(TTK_DOT, LRC_FILE_SUFFIX)
66 #define KRC_FILE TTK_STR_CAT(TTK_DOT, KRC_FILE_SUFFIX)
67 #define MP3_FILE TTK_STR_CAT(TTK_DOT, MP3_FILE_SUFFIX)
68 #define TPL_FILE TTK_STR_CAT(TTK_DOT, TPL_FILE_SUFFIX)
69 #define XML_FILE TTK_STR_CAT(TTK_DOT, XML_FILE_SUFFIX)
70 // file ext
71 #define MP3_FILE TTK_STR_CAT(TTK_DOT, MP3_FILE_SUFFIX)
72 #define APE_FILE TTK_STR_CAT(TTK_DOT, APE_FILE_SUFFIX)
73 #define FLAC_FILE TTK_STR_CAT(TTK_DOT, FLAC_FILE_SUFFIX)
74 #define MP4_FILE TTK_STR_CAT(TTK_DOT, MP4_FILE_SUFFIX)
75 #define FLV_FILE TTK_STR_CAT(TTK_DOT, FLV_FILE_SUFFIX)
76 
77 
78 #define APPDATA_DIR TTK_STR_CAT("AppData", TTK_SEPARATOR)
79 #define APPCACHE_DIR TTK_STR_CAT("AppCache", TTK_SEPARATOR)
80 #define APPBACKUP_DIR TTK_STR_CAT("AppBackup", TTK_SEPARATOR)
81 #define DOWNLOAD_DIR TTK_STR_CAT("Downloads", TTK_SEPARATOR)
82 //
83 #define LRC_DIR TTK_STR_CAT("Lyric", TTK_SEPARATOR)
84 #define MUSIC_DIR TTK_STR_CAT("Music", TTK_SEPARATOR)
85 #define ARCHIVE_DIR TTK_STR_CAT("Archive", TTK_SEPARATOR)
86 //
87 #define LANGUAGE_DIR TTK_STR_CAT("GLanguage", TTK_SEPARATOR)
88 #define PLUGINS_DIR TTK_STR_CAT("GPlugins", TTK_SEPARATOR)
89 #define THEME_DIR TTK_STR_CAT("GTheme", TTK_SEPARATOR)
90 //
91 #define ART_DIR TTK_STR_CAT("Art", TTK_SEPARATOR)
92 #define BACKGROUND_DIR TTK_STR_CAT("Background", TTK_SEPARATOR)
93 #define CACHE_DIR TTK_STR_CAT("Cache", TTK_SEPARATOR)
94 #define RESOURCE_DIR TTK_STR_CAT("resource", TTK_SEPARATOR)
95 //
96 #define CONFIG_DIR TTK_STR_CAT("config", TTK_SEPARATOR)
97 #define USER_THEME_DIR TTK_STR_CAT("theme", TTK_SEPARATOR)
98 
99 
100 #define MAKE_TRANSFORM_NAME TTK_STR_CAT("avconv", TKX_FILE)
101 #define MAKE_PLAYER_NAME TTK_STR_CAT("avplayer", TKX_FILE)
102 #define MAKE_GAIN_NAME TTK_STR_CAT("avgain", TKX_FILE)
103 
104 
105 #define MAKE_CONFIG_DIR TTK_STR_CAT(PLUGINS_DIR, CONFIG_DIR)
106 #define MAKE_TRANSFORM_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_TRANSFORM_NAME)
107 #define MAKE_PLAYER_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_PLAYER_NAME)
108 #define MAKE_GAIN_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_GAIN_NAME)
109 
110 
111 #define COFIG_PATH TTK_STR_CAT("config", XML_FILE)
112 #define PLAYLIST_PATH TTK_STR_CAT("playlist", TPL_FILE)
113 #define NORMAL_DOWN_PATH TTK_STR_CAT("download", TKF_FILE)
114 #define CLOUD_DOWN_PATH TTK_STR_CAT("cdownload", TKF_FILE)
115 #define CLOUD_UP_PATH TTK_STR_CAT("cupload", TKF_FILE)
116 #define SEARCH_PATH TTK_STR_CAT("search", TKF_FILE)
117 
118 
119 #define MAIN_DIR_FULL TTK::applicationPath() + TTK_PARENT_DIR
120 //
121 #define DOWNLOAD_DIR_FULL MAIN_DIR_FULL + DOWNLOAD_DIR
122 #define APPDATA_DIR_FULL TTK::configPath() + APPDATA_DIR
123 #define APPCACHE_DIR_FULL TTK::configPath() + APPCACHE_DIR
124 #define APPBACKUP_DIR_FULL TTK::configPath() + APPBACKUP_DIR
125 //
126 #define LRC_DIR_FULL DOWNLOAD_DIR_FULL + LRC_DIR
127 #define MUSIC_DIR_FULL DOWNLOAD_DIR_FULL + MUSIC_DIR
128 #define ARCHIVE_DIR_DIR_FULL DOWNLOAD_DIR_FULL + ARCHIVE_DIR
129 //
130 #define ART_DIR_FULL APPCACHE_DIR_FULL + ART_DIR
131 #define BACKGROUND_DIR_FULL APPCACHE_DIR_FULL + BACKGROUND_DIR
132 #define CACHE_DIR_FULL APPCACHE_DIR_FULL + CACHE_DIR
133 #define RESOURCE_DIR_FULL APPCACHE_DIR_FULL + RESOURCE_DIR
134 //
135 #define COFIG_PATH_FULL APPDATA_DIR_FULL + COFIG_PATH
136 #define PLAYLIST_PATH_FULL APPDATA_DIR_FULL + PLAYLIST_PATH
137 #define NORMAL_DOWN_PATH_FULL APPDATA_DIR_FULL + NORMAL_DOWN_PATH
138 #define CLOUD_DOWN_PATH_FULL APPDATA_DIR_FULL + CLOUD_DOWN_PATH
139 #define CLOUD_UP_PATH_FULL APPDATA_DIR_FULL + CLOUD_UP_PATH
140 #define SEARCH_PATH_FULL APPDATA_DIR_FULL + SEARCH_PATH
141 #define USER_THEME_DIR_FULL APPDATA_DIR_FULL + USER_THEME_DIR
142 
143 
144 #define THEME_DIR_FULL TTK::applicationPath() + THEME_DIR
145 #define PLUGINS_DIR_FULL TTK::applicationPath() + PLUGINS_DIR
146 #define LANGUAGE_DIR_FULL TTK::applicationPath() + LANGUAGE_DIR
147 
148 
149 #define MAKE_CONFIG_DIR_FULL TTK::applicationPath() + MAKE_CONFIG_DIR
150 #define MAKE_TRANSFORM_PATH_FULL TTK::applicationPath() + MAKE_TRANSFORM_PATH
151 #define MAKE_PLAYER_PATH_FULL TTK::applicationPath() + MAKE_PLAYER_PATH
152 #define MAKE_GAIN_PATH_FULL TTK::applicationPath() + MAKE_GAIN_PATH
153 
154 
155 #define WINDOW_WIDTH_MIN 1000
156 #define WINDOW_HEIGHT_MIN 665
157 #define LEFT_SIDE_WIDTH_MIN 320
158 #define CONCISE_WIDTH_MIN LEFT_SIDE_WIDTH_MIN + 2
159 
160 
164 namespace TTK
165 {
166  enum class PlayState
167  {
168  Stopped,
169  Playing,
170  Paused
171  };
172 
173  enum class PlayMode
174  {
175  Order,
176  Random,
177  ListLoop,
178  OneLoop,
179  Once
180  };
181 
182  enum class FontStyleMode
183  {
184  Bold = 0x0001,
185  Italic = 0x0002,
186  Underline = 0x0004,
187  Overline = 0x0008,
188  StrikeOut = 0x0010,
189  FixedPitch = 0x0020,
190  Kerningt = 0x0040
191  };
192 
193  enum class QueryQuality
194  {
195  None,
196  Standard,
197  High,
198  Super,
199  Lossless
200  };
201 
202 
207  {
208  int m_first;
209  int m_second;
210 
211  IndexProperty() = default;
212  IndexProperty(int first, int second)
213  : m_first(first),
214  m_second(second)
215  {
216 
217  }
218  };
219  TTK_DECLARE_LIST(IndexProperty);
220 
221 
226  {
228  QString m_format;
229  QString m_url;
230  QString m_size;
231 
232  MusicSongProperty() noexcept
233  : m_bitrate(-1)
234  {
235 
236  }
237 
238  inline bool isEmpty() const noexcept
239  {
240  return m_url.isEmpty();
241  }
242 
243  inline bool operator< (const MusicSongProperty &other) const noexcept
244  {
245  return m_bitrate < other.m_bitrate;
246  }
247 
248  inline bool operator== (const MusicSongProperty &other) const noexcept
249  {
250  return m_bitrate == other.m_bitrate || m_url == other.m_url;
251  }
252  };
253  TTK_DECLARE_LIST(MusicSongProperty);
254 
255 
260  {
261  QString m_id;
262  QString m_name;
263 
264  MusicArtistProperty() = default;
265  MusicArtistProperty(const QString &id, const QString &name) noexcept
266  : m_id(id),
267  m_name(name)
268  {
269 
270  }
271 
272  inline bool isEmpty() const noexcept
273  {
274  return m_id.isEmpty() || m_name.isEmpty();
275  }
276  };
277  TTK_DECLARE_LIST(MusicArtistProperty);
278 
279 
284  {
285  QString m_songId;
286  QString m_songName;
287  QString m_artistId;
288  QString m_artistName;
289  QString m_albumId;
290  QString m_albumName;
291  QString m_coverUrl;
292  QString m_lrcUrl;
293  QString m_duration;
294  QString m_year;
295  QString m_trackNumber;
296  QString m_formatProps;
297  MusicSongPropertyList m_songProps;
298  };
300 
301 
305  inline static QString configPath()
306  {
307  const bool portable = QFile::exists(MAIN_DIR_FULL + "ttk_portable");
308 #ifdef Q_OS_WIN
309  return (portable ? MAIN_DIR_FULL : QString::fromLocal8Bit(getenv("APPDATA")) + TTK_SEPARATOR) + "ttkmp/";
310 #else
311  return (portable ? MAIN_DIR_FULL : QDir::homePath() + TTK_SEPARATOR) + ".config/ttkmp/";
312 #endif
313  }
314 }
315 
316 #endif // MUSICOBJECT_H
PlayState
Definition: musicobject.h:166
The class of the music song property.
Definition: musicobject.h:225
bool isEmpty() const noexcept
Definition: musicobject.h:272
MusicSongPropertyList m_songProps
Definition: musicobject.h:297
The class of the index property.
Definition: musicobject.h:206
#define MAIN_DIR_FULL
Definition: musicobject.h:119
The class of the music artist property.
Definition: musicobject.h:259
const char * name
Definition: http_parser.c:458
QueryQuality
Definition: musicobject.h:193
MusicSongProperty() noexcept
Definition: musicobject.h:232
The namespace of the process utils.
Definition: ttkcompat.h:24
FontStyleMode
Definition: musicobject.h:182
PlayMode
Definition: musicobject.h:173
bool isEmpty() const noexcept
Definition: musicobject.h:238
#define TTK_SEPARATOR
Definition: ttkglobal.h:196
MusicArtistProperty(const QString &id, const QString &name) noexcept
Definition: musicobject.h:265
bool operator==(const MusicSongProperty &other) const noexcept
Definition: musicobject.h:248
IndexProperty()=default
static QString configPath()
Definition: musicobject.h:305
#define const
Definition: zconf.h:233
bool operator<(const MusicSongProperty &other) const noexcept
Definition: musicobject.h:243
TTK_DECLARE_LIST(IndexProperty)
IndexProperty(int first, int second)
Definition: musicobject.h:212
The class of the music song information.
Definition: musicobject.h:283