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/Playlist/PlaylistFwd.h"
28#include "Utils/Playlist/PlaylistMode.h"
29
30#include "Utils/Pimpl.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 currentTrackIndex() const;
70
71 [[nodiscard]] int index() const;
72 void setIndex(int idx);
73
74 [[nodiscard]] Mode mode() const;
75 void setMode(const Mode& mode);
76
77 void play();
78 void stop();
79 void fwd();
80 void bwd();
81 void next();
82 bool continueFromStop();
83
84 [[nodiscard]] int count() const;
85
86 [[nodiscard]] bool isBusy() const;
87 void setBusy(bool b);
88
89 [[nodiscard]] const MetaDataList& tracks() const override;
90
91 bool changeTrack(int index, MilliSeconds positionMs = 0);
92 bool prepareTrack(int index);
93
94 [[nodiscard]] bool wasChanged() const override;
95 void resetChangedStatus();
96
97 using Modificator = std::function<MetaDataList(MetaDataList)>;
98 void modifyTracks(Modificator&& modificator, Reason reason, Operation operation);
99
100 protected:
101 void setChanged(bool b) override;
102 void emitLockChanged() override;
103
104 private slots:
105 void metadataChanged();
106 void metadataDeleted();
107 void settingPlaylistModeChanged();
108 void currentMetadataChanged();
109 void durationChanged();
110
111 private: // NOLINT(*-redundant-access-specifiers)
112 void replaceTrack(int index, const MetaData& track);
113 [[nodiscard]] int findFirstValidIndex(int index) const;
114 };
115}
116
117#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