Sayonara Player
Loading...
Searching...
No Matches
Playlist.h
1/* Playlist.h */
2
3/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef SAYONARA_COMPONENTS_PLAYLIST
22#define SAYONARA_COMPONENTS_PLAYLIST
23
24#include "PlaylistDBInterface.h"
25#include "PlaylistModifiers.h"
26
27#include "Utils/MetaData/LibraryItem.h"
28#include "Utils/Pimpl.h"
29#include "Utils/Playlist/PlaylistFwd.h"
30#include "Utils/Playlist/PlaylistMode.h"
31
32#include <QObject>
33#include <functional>
34#include <optional>
35
36class PlayManager;
37class MetaDataList;
38
39namespace Util
40{
41 class FileSystem;
42}
43
44namespace Playlist
45{
46 class Playlist :
47 public QObject,
48 public DBInterface
49 {
50 Q_OBJECT
51 PIMPL(Playlist)
52
53 friend class Handler;
54
55 signals:
56 void sigLockChanged();
57 void sigItemsChanged(int index);
58 void sigTrackChanged(int oldIndex, int newIndex);
59 void sigBusyChanged(bool b);
60 void sigCurrentScannedFileChanged(const QString& currentFile);
61
62 public:
63 Playlist(int playlistIndex, const QString& name, PlayManager* playManager,
64 const std::shared_ptr<Util::FileSystem>& fileSystem);
65 ~Playlist() override;
66
67 int createPlaylist(const MetaDataList& tracks);
68
69 [[nodiscard]] int findCurrentTrackIndex() const;
70 [[nodiscard]] bool isCurrentTrack(int index) const;
71
72 [[nodiscard]] int index() const;
73 void setIndex(int idx);
74
75 [[nodiscard]] Mode mode() const;
76 void setMode(const Mode& mode);
77
78 void play();
79 void stop();
80 void previous();
81 void next();
82 bool continueFromStop();
83 bool canContinueFromStop() const;
84
85 void toggleStopAfterTrack(int index);
86 [[nodiscard]] bool isLastTrackBeforeStop(int index) const;
87 [[nodiscard]] int findLastIndexBeforeStop() const;
88
89 [[nodiscard]] int count() const;
90
91 [[nodiscard]] bool isBusy() const;
92 void setBusy(bool b);
93
94 [[nodiscard]] const MetaDataList& tracks() const override;
95
96 bool changeTrack(int index, MilliSeconds positionMs = 0);
97 bool prepareTrack(int index);
98
99 [[nodiscard]] bool wasChanged() const override;
100 void resetChangedStatus();
101
102 using Modificator = std::function<MetaDataList(MetaDataList)>;
103 void modifyTracks(Modificator&& modificator, Reason reason, Operation operation);
104
105 protected:
106 void setChanged(bool b) override;
107 void emitLockChanged() override;
108
109 private slots:
110 void metadataChanged();
111 void metadataDeleted();
112 void settingPlaylistModeChanged();
113 void currentMetadataChanged();
114 void durationChanged();
115
116 private: // NOLINT(*-redundant-access-specifiers)
117 void replaceTrack(int index, const MetaData& track);
118 [[nodiscard]] int findFirstValidIndex(int index) const;
119 };
120}
121
122#endif // SAYONARA_COMPONENTS_PLAYLIST
Definition MetaDataList.h:34
Definition MetaData.h:43
Definition PlayManager.h:34
Definition PlaylistDBInterface.h:35
Definition PlaylistHandler.h:57
The Mode class.
Definition PlaylistMode.h:42
Definition Playlist.h:49
Helper functions.
Definition MetaTypeRegistry.h:25