TTKMusicPlayer  4.2.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 - 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 
32  MusicPlayItem() noexcept
33  : m_playlistRow(-1)
34  {
35 
36  }
37 
38  MusicPlayItem(int index, const QString &path) noexcept
39  : m_playlistRow(index),
40  m_path(path)
41  {
42 
43  }
44 
45  inline bool isValid() const noexcept
46  {
47  return m_playlistRow != -1 && !m_path.isEmpty();
48  }
49 
50  inline bool operator== (const MusicPlayItem &other) const noexcept
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) noexcept;
77 
81  TTK::PlayMode playbackMode() const noexcept;
85  void setPlaybackMode(TTK::PlayMode mode) noexcept;
86 
90  int currentIndex() const noexcept;
94  MusicPlayItem currentItem() const noexcept;
98  QString currentMediaPath() const;
102  bool isSameMediaPath(const QString &path) const;
103 
107  const MusicPlayItemList& mediaList() const noexcept;
111  const MusicPlayItemList& queueList() const noexcept;
112 
116  int count() const noexcept;
120  bool isEmpty() const noexcept;
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() noexcept;
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() noexcept;
208 
212  void setEnabled(bool enable) noexcept;
216  bool isEnabled() const noexcept;
220  void initialize(const MusicPlayItemList &items) noexcept;
224  void setCurrentIndex(const MusicPlayItem &item) noexcept;
228  MusicPlayItem setCurrentIndex(int index) noexcept;
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
The class of the music play item.
Definition: musicplaylist.h:27
#define TTK_MODULE_EXPORT
QString m_path
Definition: musicplaylist.h:30
bool operator==(const TTKOptional< T > &v, const T &other)
Definition: ttkoptional.h:144
MusicPlayItemList m_queueList
static constexpr int PLAY_PREVIOUS_LEVEL
Definition: musicplaylist.h:58
MusicPlayItemList m_data
MusicPlayItem() noexcept
Definition: musicplaylist.h:32
PlayMode
Definition: musicobject.h:185
#define TTK_DECLARE_MODULE(Class)
Definition: ttkqtglobal.h:164
MusicPlayItemList m_mediaList
static constexpr int PLAY_NEXT_LEVEL
Definition: musicplaylist.h:57
TTK::PlayMode m_playbackMode
MusicPlayItem(int index, const QString &path) noexcept
Definition: musicplaylist.h:38
const char int mode
Definition: ioapi.h:135
bool isValid() const noexcept
Definition: musicplaylist.h:45
#define const
Definition: zconf.h:233
The class of the music play list.
Definition: musicplaylist.h:63
TTK_DECLARE_LIST(MusicPlayItem)