Jellyfin Qt
QML Library for interacting with the Jellyfin multimedia server
Loading...
Searching...
No Matches
shuffle.h
Go to the documentation of this file.
1/*
2 * Sailfin: a Jellyfin client written using Qt
3 * Copyright (C) 2021 Chris Josten and the Sailfin Contributors.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#ifndef JELLYFIN_MODEL_SHUFFLE_H
20#define JELLYFIN_MODEL_SHUFFLE_H
21
22#include "playlist.h"
23#include "../model/item.h"
24
25
26namespace Jellyfin {
27namespace Model {
28
32class Shuffle {
33public:
34 Shuffle(const Playlist *parent) : m_playlist(parent) {}
35
42 virtual bool canShuffleInAdvance() { return true; }
43
48 virtual void shuffleInAdvance() {}
49
53 virtual void next() {};
54
58 virtual void previous() {};
59
64 virtual void setIndex(int i) {};
65
69 virtual int currentItem() const { return -1; }
70
79 virtual int itemAt(int index) const { return -1; }
80
84 virtual int nextItem() const { return -1; }
85
86 virtual bool hasPrevious() const { return false; }
87 virtual bool hasNext() const { return false; }
88
92 void setRepeatAll(bool repeatAll) { m_repeatAll = repeatAll; }
93protected:
96 bool m_repeatAll = false;
97 static int random(int max, int min = 0);
98};
99
103class NoShuffle : public Shuffle {
104public:
105 NoShuffle(const Playlist *parent);
106
107 virtual int currentItem() const override;
108 virtual int nextItem() const override;
109 virtual int itemAt(int index) const override;
110
111 virtual void previous() override;
112 virtual void next() override;
113 virtual void setIndex(int i) override;
114 virtual bool hasPrevious() const override;
115 virtual bool hasNext() const override;
116protected:
117 int nextIndex() const;
118 int previousIndex() const;
119 int m_index = 0;
120
121};
122
127public:
128 ListShuffleBase(const Playlist *parent);
129 virtual int currentItem() const override;
130 virtual int nextItem() const override;
131 virtual int itemAt(int index) const override;
132protected:
133 QVector<int> m_map;
134};
135
140public:
141 SimpleListShuffle(const Playlist *parent);
142 virtual void shuffleInAdvance() override;
143};
144
148class RandomShuffle : public Shuffle {
149public:
150 RandomShuffle(const Playlist *parent);
151 bool canShuffleInAdvance() override;
152 virtual int currentItem() const override;
153 virtual int nextItem() const override;
154 virtual void previous() override;
155 virtual void next() override;
156 virtual bool hasPrevious() const override;
157 virtual bool hasNext() const override;
158protected:
160};
161
169
170};
171
172} // NS Model
173} // NS Jellyfin
174
175#endif // SHUFFLE_H
Base class for shuffles that shuffle the entire list in advance.
Definition shuffle.h:126
virtual int itemAt(int index) const override
Determine the item index at at the shuffled index.
Definition shuffle.cpp:110
virtual int nextItem() const override
Definition shuffle.cpp:106
ListShuffleBase(const Playlist *parent)
Definition shuffle.cpp:99
virtual int currentItem() const override
Definition shuffle.cpp:102
QVector< int > m_map
Definition shuffle.h:133
A shuffler that does not shuffle.
Definition shuffle.h:103
int m_index
Definition shuffle.h:119
virtual void setIndex(int i) override
Set the index of the now playing item.
Definition shuffle.cpp:90
NoShuffle(const Playlist *parent)
Definition shuffle.cpp:36
int nextIndex() const
Definition shuffle.cpp:78
virtual bool hasPrevious() const override
Definition shuffle.cpp:47
virtual int nextItem() const override
Definition shuffle.cpp:58
virtual void next() override
The shuffle should determine the next item.
Definition shuffle.cpp:39
virtual bool hasNext() const override
Definition shuffle.cpp:51
virtual int itemAt(int index) const override
Determine the item index at at the shuffled index.
Definition shuffle.cpp:74
int previousIndex() const
Definition shuffle.cpp:62
virtual void previous() override
The shuffle should determine the previous item.
Definition shuffle.cpp:43
virtual int currentItem() const override
Definition shuffle.cpp:55
Model of a playlist, a list of items that can be played.
Definition playlist.h:47
A shuffler that is pretty random. Does not care about repeating items in a list.
Definition shuffle.h:148
bool canShuffleInAdvance() override
If this Shuffle implementation shuffles the entire list in advance.
Definition shuffle.cpp:140
virtual void previous() override
The shuffle should determine the previous item.
Definition shuffle.cpp:151
RandomShuffle(const Playlist *parent)
Definition shuffle.cpp:137
virtual bool hasPrevious() const override
Definition shuffle.cpp:165
virtual void next() override
The shuffle should determine the next item.
Definition shuffle.cpp:156
virtual int nextItem() const override
Definition shuffle.cpp:148
int m_previous
Definition shuffle.h:159
int m_next
Definition shuffle.h:159
int m_current
Definition shuffle.h:159
virtual bool hasNext() const override
Definition shuffle.cpp:169
virtual int currentItem() const override
Definition shuffle.cpp:144
Interface for an algorithm shuffling a playlist.
Definition shuffle.h:32
virtual bool canShuffleInAdvance()
If this Shuffle implementation shuffles the entire list in advance.
Definition shuffle.h:42
virtual bool hasPrevious() const
Definition shuffle.h:86
virtual void next()
The shuffle should determine the next item.
Definition shuffle.h:53
virtual void previous()
The shuffle should determine the previous item.
Definition shuffle.h:58
void setRepeatAll(bool repeatAll)
Sets whether the shuffler to loop over the list if all items are played.
Definition shuffle.h:92
Shuffle(const Playlist *parent)
Definition shuffle.h:34
static int random(int max, int min=0)
Definition shuffle.cpp:28
virtual void shuffleInAdvance()
Shuffle the list in advance. Should only be called if canShuffleInAdvance() is called.
Definition shuffle.h:48
bool m_repeatAll
Definition shuffle.h:96
virtual int nextItem() const
Definition shuffle.h:84
virtual int itemAt(int index) const
Determine the item index at at the shuffled index.
Definition shuffle.h:79
virtual bool hasNext() const
Definition shuffle.h:87
virtual int currentItem() const
Definition shuffle.h:69
virtual void setIndex(int i)
Set the index of the now playing item.
Definition shuffle.h:64
const Playlist * m_playlist
Playlist that can be used to gather information about the songs if needed for the algorithm.
Definition shuffle.h:95
A simple shuffler which shuffles each item in the list in advance.
Definition shuffle.h:139
virtual void shuffleInAdvance() override
Shuffle the list in advance. Should only be called if canShuffleInAdvance() is called.
Definition shuffle.cpp:118
SimpleListShuffle(const Playlist *parent)
Definition shuffle.cpp:115
A smart shuffler that shuffles a list with a few constraints to make it appear "more random" to an us...
Definition shuffle.h:168