TTKMusicPlayer  3.7.0.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 - 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 "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;
99 
103  const MusicPlayItemList& mediaList() const;
107  const MusicPlayItemList& queueList() const;
108 
112  int count() const;
116  bool isEmpty() const;
120  void clear();
121 
125  void update(const TTK::IndexPropertyList &indexs);
126 
130  int find(const MusicPlayItem &item) const;
134  int find(int playlistRow, const QString &content, int from = 0);
135 
139  void add(int playlistRow, const QString &content);
143  void add(int playlistRow, const QStringList &items);
144 
148  void append(int playlistRow, const QString &content);
152  void append(int playlistRow, const QStringList &items);
156  void appendQueue(int playlistRow, const QString &content);
157 
161  bool remove(int pos);
165  int remove(int playlistRow, const QString &content);
169  void removeQueue();
170 
171 Q_SIGNALS:
175  void currentIndexChanged(int index);
179  void playbackModeChanged(TTK::PlayMode mode);
180 
181 public Q_SLOTS:
185  void setCurrentIndex(int index);
189  void setCurrentIndex(int playlistRow, const QString &path);
190 
191 private:
193  MusicPlayItemList m_mediaList;
194  MusicPlayItemList m_queueList;
196 
197  class Shuffle
198  {
199  public:
203  Shuffle();
204 
208  void setEnabled(bool enable);
212  bool isEnabled() const;
216  void initialize(const MusicPlayItemList &items);
220  void setCurrentIndex(const MusicPlayItem &item);
224  MusicPlayItem setCurrentIndex(int index);
225 
226  private:
227  int m_index;
228  bool m_enable;
229  MusicPlayItemList m_data;
230 
231  } m_shuffle;
232 
233 };
234 
235 #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:171
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:152
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)