TTKMusicPlayer  4.3.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 - 2026 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
66 public:
70  explicit MusicPlaylist(QObject *parent = nullptr);
71 
75  void setShuffleMode(bool shuffle) noexcept;
76 
80  TTK::PlayMode playbackMode() const noexcept;
84  void setPlaybackMode(TTK::PlayMode mode) noexcept;
85 
89  int currentIndex() const noexcept;
93  MusicPlayItem currentItem() const noexcept;
94 
98  const MusicPlayItemList& mediaList() const noexcept;
102  const MusicPlayItemList& queueList() const noexcept;
103 
107  int count() const noexcept;
111  bool isEmpty() const noexcept;
115  void clear();
116 
120  void update(const TTK::IndexPropertyList &rows);
121 
125  int find(const MusicPlayItem &item) const;
129  int find(int playlistRow, const QString &content, int from = 0);
130 
134  void add(int playlistRow, const QString &content);
138  void add(int playlistRow, const QStringList &items);
139 
143  void append(int playlistRow, const QString &content);
147  void append(int playlistRow, const QStringList &items);
151  void appendQueue(int playlistRow, const QString &content);
152 
156  bool remove(int index);
160  int remove(int playlistRow, const QString &content);
164  void removeQueue() noexcept;
165 
166 Q_SIGNALS:
170  void currentIndexChanged(int index);
174  void playbackModeChanged(TTK::PlayMode mode);
175 
176 public Q_SLOTS:
180  void setCurrentIndex(int index);
184  void setCurrentIndex(int playlistRow, const QString &path);
185 
186 private:
188  MusicPlayItemList m_mediaList;
189  MusicPlayItemList m_queueList;
191 
192  class Shuffle
193  {
194  public:
198  Shuffle() noexcept;
199 
203  void setEnabled(bool enable) noexcept;
207  bool isEnabled() const noexcept;
211  void initialize(const MusicPlayItemList &items) noexcept;
215  void setCurrentIndex(const MusicPlayItem &item) noexcept;
219  MusicPlayItem setCurrentIndex(int index) noexcept;
220 
221  private:
222  int m_index;
223  bool m_enable;
224  MusicPlayItemList m_data;
225 
226  } m_shuffle;
227 
228 };
229 
230 #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:190
MusicPlayItemList m_mediaList
TTK_MODULE_EXPORT void initialize(TTK::Attribute attr)
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)