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