TTKMusicPlayer  4.1.3.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicplaylist.h
Go to the documentation of this file.
1 #ifndef MUSICPLAYLIST_H
2 #define MUSICPLAYLIST_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 "musicglobaldefine.h"
23 
28 {
30  QString m_path;
31 
33  : m_playlistRow(-1)
34  {
35 
36  }
37 
38  MusicPlayItem(int index, const QString &path)
39  : m_playlistRow(index),
40  m_path(path)
41  {
42 
43  }
44 
45  inline bool isValid() const
46  {
47  return m_playlistRow != -1 && !m_path.isEmpty();
48  }
49 
50  inline bool operator== (const MusicPlayItem &other) const
51  {
52  return m_playlistRow == other.m_playlistRow && m_path == other.m_path;
53  }
54 };
56 
57 static constexpr int PLAY_NEXT_LEVEL = -123;
58 static constexpr int PLAY_PREVIOUS_LEVEL = -321;
59 
63 class TTK_MODULE_EXPORT MusicPlaylist : public QObject
64 {
65  Q_OBJECT
67 public:
71  explicit MusicPlaylist(QObject *parent = nullptr);
72 
76  void setShuffleMode(bool shuffle);
77 
81  TTK::PlayMode playbackMode() const;
85  void setPlaybackMode(TTK::PlayMode mode);
86 
90  int currentIndex() const;
94  MusicPlayItem currentItem() const;
98  QString currentMediaPath() const;
102  bool isSameMediaPath(const QString &path) const;
103 
107  const MusicPlayItemList& mediaList() const;
111  const MusicPlayItemList& queueList() const;
112 
116  int count() const;
120  bool isEmpty() const;
124  void clear();
125 
129  void update(const TTK::IndexPropertyList &indexs);
130 
134  int find(const MusicPlayItem &item) const;
138  int find(int playlistRow, const QString &content, int from = 0);
139 
143  void add(int playlistRow, const QString &content);
147  void add(int playlistRow, const QStringList &items);
148 
152  void append(int playlistRow, const QString &content);
156  void append(int playlistRow, const QStringList &items);
160  void appendQueue(int playlistRow, const QString &content);
161 
165  bool remove(int pos);
169  int remove(int playlistRow, const QString &content);
173  void removeQueue();
174 
175 Q_SIGNALS:
179  void currentIndexChanged(int index);
183  void playbackModeChanged(TTK::PlayMode mode);
184 
185 public Q_SLOTS:
189  void setCurrentIndex(int index);
193  void setCurrentIndex(int playlistRow, const QString &path);
194 
195 private:
197  MusicPlayItemList m_mediaList;
198  MusicPlayItemList m_queueList;
200 
201  class Shuffle
202  {
203  public:
207  Shuffle();
208 
212  void setEnabled(bool enable);
216  bool isEnabled() const;
220  void initialize(const MusicPlayItemList &items);
224  void setCurrentIndex(const MusicPlayItem &item);
228  MusicPlayItem setCurrentIndex(int index);
229 
230  private:
231  int m_index;
232  bool m_enable;
233  MusicPlayItemList m_data;
234 
235  } m_shuffle;
236 
237 };
238 
239 #endif // MUSICPLAYLIST_H
bool operator==(const VolumeSettings &v1, const VolumeSettings &v2)
Definition: volume.h:38
The class of the music play item.
Definition: musicplaylist.h:27
#define TTK_MODULE_EXPORT
QString m_path
Definition: musicplaylist.h:30
MusicPlayItemList m_queueList
MusicPlayItem(int index, const QString &path)
Definition: musicplaylist.h:38
static constexpr int PLAY_PREVIOUS_LEVEL
Definition: musicplaylist.h:58
MusicPlayItemList m_data
PlayMode
Definition: musicobject.h:173
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:168
MusicPlayItemList m_mediaList
static constexpr int PLAY_NEXT_LEVEL
Definition: musicplaylist.h:57
TTK::PlayMode m_playbackMode
const char int mode
Definition: ioapi.h:135
bool isValid() const
Definition: musicplaylist.h:45
The class of the music play list.
Definition: musicplaylist.h:63
TTK_DECLARE_LIST(MusicPlayItem)