Sayonara Player
Playlist.h
1 /* Playlist.h */
2 
3 /* Copyright (C) 2011-2016 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 
22 
23 #ifndef PLAYLIST_H
24 #define PLAYLIST_H
25 
26 #include "Helper/PlaylistMode.h"
27 #include "Helper/Settings/SayonaraClass.h"
28 #include "PlaylistDBInterface.h"
29 
30 #include <QString>
31 #include <QList>
32 #include <memory>
33 
38 class Playlist :
39  public PlaylistDBInterface,
40  protected SayonaraClass
41 {
42 
43  Q_OBJECT
44 
45  friend class PlaylistHandler;
46 
47 signals:
48  void sig_data_changed(int idx);
49 
50 public:
51 
52  enum class Type : quint8
53  {
54  Std=0,
55  Stream
56  };
57 
58 private:
59  bool _playlist_changed;
60 
61 
62 protected:
63 
64  bool _is_storable;
65  int _cur_play_idx;
66  int _playlist_idx;
67 
68  MetaDataList _v_md;
69  Type _playlist_type;
70  PlaylistMode _playlist_mode;
71 
72  Playlist(int idx, QString name="");
73  virtual ~Playlist();
74 
75  virtual void play()=0;
76  virtual void pause()=0;
77  virtual void stop()=0;
78  virtual void fwd()=0;
79  virtual void bwd()=0;
80  virtual void next()=0;
81 
82  virtual int create_playlist(const MetaDataList& v_md)=0;
83 
84  virtual void replace_track(int idx, const MetaData& md);
85 
86 public:
87 
88  QStringList toStringList() const;
89 
90  IdxList find_tracks(int id) const;
91  IdxList find_tracks(const QString& filepath) const;
92 
93  Type get_type() const;
94  int get_cur_track_idx() const;
95  bool get_cur_track(MetaData& md) const;
96  int get_idx() const;
97  void set_idx(int idx);
98  PlaylistMode get_playlist_mode() const;
99  void set_playlist_mode(const PlaylistMode& mode);
100  qint64 get_running_time() const;
101 
102 
103  // from PlaylistDBInterface
104  virtual bool is_empty() const override;
105  virtual int get_count() const override;
106  virtual const MetaDataList& get_playlist() const override;
107 
108  virtual void set_changed(bool b) override;
109  virtual bool was_changed() const override;
110  virtual bool is_storable() const override;
111 
112 
113 
114  const MetaData& operator[](int idx) const{
115  return _v_md[idx];
116  }
117 
118  const MetaData& at_const_ref(int idx) const {
119  return _v_md[idx];
120  }
121 
122  MetaData& at_ref(int idx) {
123  return _v_md[idx];
124  }
125 
126 
127  virtual void clear();
128 
129  virtual void move_track(const int idx, int tgt);
130  virtual void move_tracks(const SP::Set<int>& indexes, int tgt);
131 
132  virtual void delete_track(const int idx);
133  virtual void delete_tracks(const SP::Set<int>& indexes);
134 
135  virtual void insert_track(const MetaData& md, int tgt);
136  virtual void insert_tracks(const MetaDataList& lst, int tgt);
137 
138  virtual void append_track(const MetaData& md);
139  virtual void append_tracks(const MetaDataList& lst);
140 
141  virtual bool change_track(int idx)=0;
142 
143  virtual void metadata_changed(const MetaDataList& v_md_old, const MetaDataList& v_md_new)=0;
144  virtual void metadata_changed_single(const MetaData& md)=0;
145 
146 
147 private slots:
148  void _sl_playlist_mode_changed();
149 };
150 
151 
155 typedef std::shared_ptr<Playlist> PlaylistPtr;
156 
160 typedef std::shared_ptr<const Playlist> PlaylistConstPtr;
161 
162 
163 
164 
165 #endif // PLAYLIST_H
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: PlaylistMode.h:34
Definition: MetaData.h:49
Definition: MetaDataList.h:46
Global handler for playlists.
Definition: PlaylistHandler.h:48
The Playlist class.
Definition: Playlist.h:38
The PlaylistDBInterface class.
Definition: PlaylistDBInterface.h:34