mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-04 01:42:44 +00:00
WIP: Add playlists/queues and add support for Sailfish back
This commit is contained in:
parent
fbc154fb56
commit
86672be051
89 changed files with 1637 additions and 849 deletions
|
@ -1,39 +1,110 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 Chris Josten and the Sailfin Contributors.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef JELLYFIN_MODEL_PLAYLIST_H
|
||||
#define JELLYFIN_MODEL_PLAYLIST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
#include <QVector>
|
||||
|
||||
#include "../viewmodel/itemmodel.h"
|
||||
#include "item.h"
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace Model {
|
||||
|
||||
// Forward declaration
|
||||
class Item;
|
||||
class Shuffle;
|
||||
|
||||
class Playlist {
|
||||
/**
|
||||
* @brief Model of a playlist, a list of items that can be played.
|
||||
*
|
||||
* This tries to take the managing what items to play away from the PlaybackManager,
|
||||
* which now only will be informed about the current and next item to play.
|
||||
*
|
||||
* The playlist has actually two list, one named list and the other named queue. When
|
||||
* playing, the queue has priority over the list and will not be affected by the
|
||||
* shuffle mode. After all items of the queue are played, the items in the list are played.
|
||||
* Items in the list may be shuffled.
|
||||
*/
|
||||
class Playlist : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Playlist();
|
||||
explicit Playlist(QObject *parent = nullptr);
|
||||
|
||||
/// Start loading data for the next item.
|
||||
void preloadNext();
|
||||
/// Returns the current item in the queue
|
||||
QSharedPointer<Item> currentItem();
|
||||
QSharedPointer<Item> nextItem();
|
||||
|
||||
/**
|
||||
* @brief Determine the previous item to be played.
|
||||
*/
|
||||
void previous();
|
||||
|
||||
/**
|
||||
* @brief Determine the next item to be played.
|
||||
*/
|
||||
void next();
|
||||
|
||||
// int queueSize() { return m_queue.size(); };
|
||||
int listSize() const { return m_list.size(); };
|
||||
int totalSize() const { return m_queue.size() + m_list.size(); }
|
||||
|
||||
QSharedPointer<const Item> listAt(int index) const;
|
||||
/**
|
||||
* @brief Removes all the items from the playlist
|
||||
*/
|
||||
void clearList();
|
||||
|
||||
/**
|
||||
* @brief Appends all items from the given itemModel to this list
|
||||
*/
|
||||
void appendToList(const ViewModel::ItemModel &model);
|
||||
|
||||
/**
|
||||
* @brief Start playing this playlist
|
||||
* @param index The index to start from.
|
||||
*/
|
||||
void play(int index = 0);
|
||||
signals:
|
||||
void listCleared();
|
||||
void itemsAddedToQueue(int index, int count);
|
||||
void itemsAddedToList(int index, int count);
|
||||
void listReshuffled();
|
||||
private:
|
||||
/// Extra data about each itemId that this playlist manages
|
||||
struct ExtendedItem {
|
||||
QSharedPointer<Item> item;
|
||||
/// The url from which this item can be streamed.
|
||||
QUrl url;
|
||||
/// Playsession that should be reported to Jellyfin's server.
|
||||
QString playSession;
|
||||
/// Text to be shown when an error occurred while fetching playback information.
|
||||
QString errorText;
|
||||
};
|
||||
void reshuffle();
|
||||
|
||||
QVector<ExtendedItem> list;
|
||||
QSharedPointer<Item> m_currentItem;
|
||||
bool m_currentItemFromQueue = false;
|
||||
QSharedPointer<Item> m_nextItem;
|
||||
bool m_nextItemFromQueue = false;
|
||||
|
||||
/// list of the items in the queue
|
||||
QVector<QSharedPointer<Item>> m_queue;
|
||||
/// list of the items in the playlist
|
||||
QVector<QSharedPointer<Item>> m_list;
|
||||
/// The current position in the playlist
|
||||
int m_pos = 0;
|
||||
|
||||
/// Algorithm for shuffling the playlist.
|
||||
Shuffle *m_shuffler;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
166
core/include/JellyfinQt/model/shuffle.h
Normal file
166
core/include/JellyfinQt/model/shuffle.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* Sailfin: a Jellyfin client written using Qt
|
||||
* Copyright (C) 2021 Chris Josten and the Sailfin Contributors.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef JELLYFIN_MODEL_SHUFFLE_H
|
||||
#define JELLYFIN_MODEL_SHUFFLE_H
|
||||
|
||||
#include "playlist.h"
|
||||
#include "../model/item.h"
|
||||
|
||||
|
||||
namespace Jellyfin {
|
||||
namespace Model {
|
||||
|
||||
/**
|
||||
* @brief Interface for an algorithm shuffling a playlist.
|
||||
*/
|
||||
class Shuffle {
|
||||
public:
|
||||
Shuffle(const Playlist *parent) : m_playlist(parent) {}
|
||||
|
||||
/**
|
||||
* @brief If this Shuffle implementation shuffles the entire list in advance.
|
||||
* @return True if this shuffle class shuffles the entire list in advance
|
||||
*
|
||||
* Some shuffle implementations may only shuffle the next item as they go.
|
||||
*/
|
||||
virtual bool canShuffleInAdvance() { return true; }
|
||||
|
||||
/**
|
||||
* @brief Shuffle the list in advance. Should only be called if canShuffleInAdvance()
|
||||
* is called.
|
||||
*/
|
||||
virtual void shuffleInAdvance() {}
|
||||
|
||||
/**
|
||||
* @brief The shuffle should determine the next item.
|
||||
*/
|
||||
virtual void next() {};
|
||||
|
||||
/**
|
||||
* @brief The shuffle should determine the previous item.
|
||||
*/
|
||||
virtual void previous() {};
|
||||
|
||||
/**
|
||||
* @brief Set the index of the now playing item.
|
||||
* @param i
|
||||
*/
|
||||
virtual void setIndex(int i) {};
|
||||
|
||||
/**
|
||||
* @return the index of the currently playing item
|
||||
*/
|
||||
virtual int currentItem() const { return -1; }
|
||||
|
||||
/**
|
||||
* @brief Determine the item index at at the shuffled index
|
||||
* @param index The shuffled index
|
||||
* @return The actual index
|
||||
*
|
||||
* If canShuffleInAdvance() returns false, a new implemention is not needed
|
||||
* or -1 may be returned. This function should not even be called in that case.
|
||||
*/
|
||||
virtual int itemAt(int index) const { return -1; }
|
||||
|
||||
/**
|
||||
* @return the index of the next item
|
||||
*/
|
||||
virtual int nextItem() const { return -1; }
|
||||
|
||||
/**
|
||||
* @brief Sets whether the shuffler to loop over the list if all items are played.
|
||||
*/
|
||||
void setRepeatAll(bool repeatAll) { m_repeatAll = repeatAll; }
|
||||
protected:
|
||||
/// Playlist that can be used to gather information about the songs if needed for the algorithm
|
||||
const Playlist *m_playlist;
|
||||
bool m_repeatAll = false;
|
||||
static int random(int max, int min = 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A shuffler that does not shuffle.
|
||||
*/
|
||||
class NoShuffle : public Shuffle {
|
||||
public:
|
||||
NoShuffle(const Playlist *parent);
|
||||
|
||||
virtual int currentItem() const override;
|
||||
virtual int nextItem() const override;
|
||||
|
||||
virtual void previous() override;
|
||||
virtual void next() override;
|
||||
virtual void setIndex(int i) override;
|
||||
protected:
|
||||
int nextIndex() const;
|
||||
int previousIndex() const;
|
||||
int m_index = 0;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Base class for shuffles that shuffle the entire list in advance
|
||||
*/
|
||||
class ListShuffleBase : public NoShuffle {
|
||||
public:
|
||||
ListShuffleBase(const Playlist *parent);
|
||||
virtual int currentItem() const override;
|
||||
virtual int nextItem() const override;
|
||||
protected:
|
||||
QVector<int> m_map;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A simple shuffler which shuffles each item in the list in advance
|
||||
*/
|
||||
class SimpleListShuffle : public ListShuffleBase {
|
||||
public:
|
||||
SimpleListShuffle(const Playlist *parent);
|
||||
virtual void shuffleInAdvance() override;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A shuffler that is pretty random. Does not care about repeating items in a list.
|
||||
*/
|
||||
class RandomShuffle : public Shuffle {
|
||||
public:
|
||||
RandomShuffle(const Playlist *parent);
|
||||
bool canShuffleInAdvance() override;
|
||||
virtual int currentItem() const override;
|
||||
virtual int nextItem() const override;
|
||||
virtual void previous() override;
|
||||
virtual void next() override;
|
||||
protected:
|
||||
int m_previous, m_current, m_next = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A smart shuffler that shuffles a list with a few constraints to make it appear "more random" to an user.
|
||||
*
|
||||
* This shuffler tries to place to avoid placing tracks of the same album, artist, and genre next to each other.
|
||||
* This way, the user may perceive the list as more random
|
||||
*/
|
||||
class VariedListShuffle {
|
||||
|
||||
};
|
||||
|
||||
} // NS Model
|
||||
} // NS Jellyfin
|
||||
|
||||
#endif // SHUFFLE_H
|
Loading…
Add table
Add a link
Reference in a new issue