TTKMusicPlayer  4.2.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 - 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 #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 MP3_FILE_SUFFIX "mp3"
58 #define APE_FILE_SUFFIX "ape"
59 #define FLAC_FILE_SUFFIX "flac"
60 #define MP4_FILE_SUFFIX "mp4"
61 #define FLV_FILE_SUFFIX "flv"
62 
63 
64 #define TKF_FILE TTK_STR_CAT(TTK_DOT, TKF_FILE_SUFFIX)
65 #define TKX_FILE TTK_STR_CAT(TTK_DOT, TKX_FILE_SUFFIX)
66 #define TKM_FILE TTK_STR_CAT(TTK_DOT, TKM_FILE_SUFFIX)
67 #define TKB_FILE TTK_STR_CAT(TTK_DOT, TKB_FILE_SUFFIX)
68 //
69 #define SKN_FILE TTK_STR_CAT(TTK_DOT, SKN_FILE_SUFFIX)
70 #define JPG_FILE TTK_STR_CAT(TTK_DOT, JPG_FILE_SUFFIX)
71 #define PNG_FILE TTK_STR_CAT(TTK_DOT, PNG_FILE_SUFFIX)
72 #define MP3_FILE TTK_STR_CAT(TTK_DOT, MP3_FILE_SUFFIX)
73 #define TPL_FILE TTK_STR_CAT(TTK_DOT, TPL_FILE_SUFFIX)
74 #define XML_FILE TTK_STR_CAT(TTK_DOT, XML_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 MP3_FILE TTK_STR_CAT(TTK_DOT, MP3_FILE_SUFFIX)
84 #define APE_FILE TTK_STR_CAT(TTK_DOT, APE_FILE_SUFFIX)
85 #define FLAC_FILE TTK_STR_CAT(TTK_DOT, FLAC_FILE_SUFFIX)
86 #define MP4_FILE TTK_STR_CAT(TTK_DOT, MP4_FILE_SUFFIX)
87 #define FLV_FILE TTK_STR_CAT(TTK_DOT, FLV_FILE_SUFFIX)
88 
89 
90 #define APPDATA_DIR TTK_STR_CAT("AppData", TTK_SEPARATOR)
91 #define APPCACHE_DIR TTK_STR_CAT("AppCache", TTK_SEPARATOR)
92 #define APPBACKUP_DIR TTK_STR_CAT("AppBackup", TTK_SEPARATOR)
93 #define DOWNLOAD_DIR TTK_STR_CAT("Downloads", TTK_SEPARATOR)
94 //
95 #define LRC_DIR TTK_STR_CAT("Lyric", TTK_SEPARATOR)
96 #define MUSIC_DIR TTK_STR_CAT("Music", TTK_SEPARATOR)
97 #define ARCHIVE_DIR TTK_STR_CAT("Archive", TTK_SEPARATOR)
98 //
99 #define LANGUAGE_DIR TTK_STR_CAT("GLanguage", TTK_SEPARATOR)
100 #define PLUGINS_DIR TTK_STR_CAT("GPlugins", TTK_SEPARATOR)
101 #define THEME_DIR TTK_STR_CAT("GTheme", TTK_SEPARATOR)
102 //
103 #define ART_DIR TTK_STR_CAT("Art", TTK_SEPARATOR)
104 #define BACKGROUND_DIR TTK_STR_CAT("Background", TTK_SEPARATOR)
105 #define CACHE_DIR TTK_STR_CAT("Cache", TTK_SEPARATOR)
106 #define RESOURCE_DIR TTK_STR_CAT("resource", TTK_SEPARATOR)
107 //
108 #define CONFIG_DIR TTK_STR_CAT("config", TTK_SEPARATOR)
109 #define USER_THEME_DIR TTK_STR_CAT("theme", TTK_SEPARATOR)
110 
111 
112 #define MAKE_TRANSFORM_NAME TTK_STR_CAT("avconv", TKX_FILE)
113 #define MAKE_PLAYER_NAME TTK_STR_CAT("avplayer", TKX_FILE)
114 #define MAKE_GAIN_NAME TTK_STR_CAT("avgain", TKX_FILE)
115 
116 
117 #define MAKE_CONFIG_DIR TTK_STR_CAT(PLUGINS_DIR, CONFIG_DIR)
118 #define MAKE_TRANSFORM_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_TRANSFORM_NAME)
119 #define MAKE_PLAYER_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_PLAYER_NAME)
120 #define MAKE_GAIN_PATH TTK_STR_CAT(PLUGINS_DIR, MAKE_GAIN_NAME)
121 
122 
123 #define COFIG_PATH TTK_STR_CAT("config", XML_FILE)
124 #define PLAYLIST_PATH TTK_STR_CAT("playlist", TPL_FILE)
125 #define NORMAL_DOWN_PATH TTK_STR_CAT("download", TKF_FILE)
126 #define CLOUD_DOWN_PATH TTK_STR_CAT("cdownload", TKF_FILE)
127 #define CLOUD_UP_PATH TTK_STR_CAT("cupload", TKF_FILE)
128 #define SEARCH_PATH TTK_STR_CAT("search", TKF_FILE)
129 
130 
131 #define MAIN_DIR_FULL TTK::applicationPath() + TTK_PARENT_DIR
132 //
133 #define DOWNLOAD_DIR_FULL MAIN_DIR_FULL + DOWNLOAD_DIR
134 #define APPDATA_DIR_FULL TTK::configPath() + APPDATA_DIR
135 #define APPCACHE_DIR_FULL TTK::configPath() + APPCACHE_DIR
136 #define APPBACKUP_DIR_FULL TTK::configPath() + APPBACKUP_DIR
137 //
138 #define LRC_DIR_FULL DOWNLOAD_DIR_FULL + LRC_DIR
139 #define MUSIC_DIR_FULL DOWNLOAD_DIR_FULL + MUSIC_DIR
140 #define ARCHIVE_DIR_DIR_FULL DOWNLOAD_DIR_FULL + ARCHIVE_DIR
141 //
142 #define ART_DIR_FULL APPCACHE_DIR_FULL + ART_DIR
143 #define BACKGROUND_DIR_FULL APPCACHE_DIR_FULL + BACKGROUND_DIR
144 #define CACHE_DIR_FULL APPCACHE_DIR_FULL + CACHE_DIR
145 #define RESOURCE_DIR_FULL APPCACHE_DIR_FULL + RESOURCE_DIR
146 //
147 #define COFIG_PATH_FULL APPDATA_DIR_FULL + COFIG_PATH
148 #define PLAYLIST_PATH_FULL APPDATA_DIR_FULL + PLAYLIST_PATH
149 #define NORMAL_DOWN_PATH_FULL APPDATA_DIR_FULL + NORMAL_DOWN_PATH
150 #define CLOUD_DOWN_PATH_FULL APPDATA_DIR_FULL + CLOUD_DOWN_PATH
151 #define CLOUD_UP_PATH_FULL APPDATA_DIR_FULL + CLOUD_UP_PATH
152 #define SEARCH_PATH_FULL APPDATA_DIR_FULL + SEARCH_PATH
153 #define USER_THEME_DIR_FULL APPDATA_DIR_FULL + USER_THEME_DIR
154 
155 
156 #define THEME_DIR_FULL TTK::applicationPath() + THEME_DIR
157 #define PLUGINS_DIR_FULL TTK::applicationPath() + PLUGINS_DIR
158 #define LANGUAGE_DIR_FULL TTK::applicationPath() + LANGUAGE_DIR
159 
160 
161 #define MAKE_CONFIG_DIR_FULL TTK::applicationPath() + MAKE_CONFIG_DIR
162 #define MAKE_TRANSFORM_PATH_FULL TTK::applicationPath() + MAKE_TRANSFORM_PATH
163 #define MAKE_PLAYER_PATH_FULL TTK::applicationPath() + MAKE_PLAYER_PATH
164 #define MAKE_GAIN_PATH_FULL TTK::applicationPath() + MAKE_GAIN_PATH
165 
166 
167 #define WINDOW_WIDTH_MIN 1000
168 #define WINDOW_HEIGHT_MIN 665
169 #define LEFT_SIDE_WIDTH_MIN 320
170 #define CONCISE_WIDTH_MIN LEFT_SIDE_WIDTH_MIN + 2
171 
172 
176 namespace TTK
177 {
178  enum class PlayState
179  {
180  Stopped,
181  Playing,
182  Paused
183  };
184 
185  enum class PlayMode
186  {
187  Order,
188  Random,
189  ListLoop,
190  OneLoop,
191  Once
192  };
193 
194  enum class FontStyleMode
195  {
196  Bold = 0x0001,
197  Italic = 0x0002,
198  Underline = 0x0004,
199  Overline = 0x0008,
200  StrikeOut = 0x0010,
201  FixedPitch = 0x0020,
202  Kerningt = 0x0040
203  };
204 
205  enum class QueryQuality
206  {
207  None,
208  Standard,
209  High,
210  Super,
211  Lossless
212  };
213 
214 
219  {
220  int m_first;
221  int m_second;
222 
223  IndexProperty() = default;
224  IndexProperty(int first, int second) noexcept
225  : m_first(first),
226  m_second(second)
227  {
228 
229  }
230  };
231  TTK_DECLARE_LIST(IndexProperty);
232 
233 
238  {
240  QString m_format;
241  QString m_url;
242  QString m_size;
243 
244  MusicSongProperty() noexcept
245  : m_bitrate(-1)
246  {
247 
248  }
249 
250  inline bool isEmpty() const noexcept
251  {
252  return m_url.isEmpty();
253  }
254 
255  inline bool operator< (const MusicSongProperty &other) const noexcept
256  {
257  return m_bitrate < other.m_bitrate;
258  }
259 
260  inline bool operator== (const MusicSongProperty &other) const noexcept
261  {
262  return m_bitrate == other.m_bitrate || m_url == other.m_url;
263  }
264  };
265  TTK_DECLARE_LIST(MusicSongProperty);
266 
267 
272  {
273  QString m_id;
274  QString m_name;
275 
276  MusicArtistProperty() = default;
277  MusicArtistProperty(const QString &id, const QString &name) noexcept
278  : m_id(id),
279  m_name(name)
280  {
281 
282  }
283 
284  inline bool isEmpty() const noexcept
285  {
286  return m_id.isEmpty() || m_name.isEmpty();
287  }
288  };
289  TTK_DECLARE_LIST(MusicArtistProperty);
290 
291 
296  {
297  QString m_songId;
298  QString m_songName;
299  QString m_artistId;
300  QString m_artistName;
301  QString m_albumId;
302  QString m_albumName;
303  QString m_coverUrl;
304  QString m_lrcUrl;
305  QString m_duration;
306  QString m_year;
307  QString m_trackNumber;
308  QString m_formatProps;
309  MusicSongPropertyList m_songProps;
310  };
312 
313 
317  inline static QString configPath()
318  {
319  const bool portable = QFile::exists(MAIN_DIR_FULL + "ttk_portable");
320 #ifdef Q_OS_WIN
321  return (portable ? MAIN_DIR_FULL : QString::fromLocal8Bit(getenv("APPDATA")) + TTK_SEPARATOR) + "ttkmp/";
322 #else
323  return (portable ? MAIN_DIR_FULL : QDir::homePath() + TTK_SEPARATOR) + ".config/ttkmp/";
324 #endif
325  }
326 }
327 
328 #endif // MUSICOBJECT_H
PlayState
Definition: musicobject.h:178
IndexProperty(int first, int second) noexcept
Definition: musicobject.h:224
The class of the music song property.
Definition: musicobject.h:237
bool isEmpty() const noexcept
Definition: musicobject.h:284
MusicSongPropertyList m_songProps
Definition: musicobject.h:309
The class of the index property.
Definition: musicobject.h:218
#define MAIN_DIR_FULL
Definition: musicobject.h:131
The class of the music artist property.
Definition: musicobject.h:271
const char * name
Definition: http_parser.c:458
QueryQuality
Definition: musicobject.h:205
MusicSongProperty() noexcept
Definition: musicobject.h:244
The namespace of the application object.
Definition: ttkcompat.h:24
FontStyleMode
Definition: musicobject.h:194
PlayMode
Definition: musicobject.h:185
bool isEmpty() const noexcept
Definition: musicobject.h:250
#define TTK_SEPARATOR
Definition: ttkglobal.h:269
MusicArtistProperty(const QString &id, const QString &name) noexcept
Definition: musicobject.h:277
bool operator==(const MusicSongProperty &other) const noexcept
Definition: musicobject.h:260
IndexProperty()=default
static QString configPath()
Definition: musicobject.h:317
#define const
Definition: zconf.h:233
bool operator<(const MusicSongProperty &other) const noexcept
Definition: musicobject.h:255
TTK_DECLARE_LIST(IndexProperty)
The class of the music song information.
Definition: musicobject.h:295