159 assert(position <
length);
168 return order[_order];
173 assert(position <
length);
175 for (
unsigned i = 0;; ++i) {
178 if (
order[i] == position)
185 assert(position <
length);
204 assert(position <
length);
221 assert(position <
length);
249 assert(position <
length);
276 void SwapPositions(
unsigned position1,
unsigned position2) noexcept;
290 unsigned MoveOrder(
unsigned from_order,
unsigned to_order) noexcept;
299 unsigned to_order) noexcept;
308 unsigned to_order) noexcept;
313 void MovePostion(
unsigned from,
unsigned to) noexcept;
318 void MoveRange(
unsigned start,
unsigned end,
unsigned to) noexcept;
328 void Clear() noexcept;
334 for (
unsigned i = 0; i <
length; ++i)
372 bool SetPriority(
unsigned position, uint8_t priority,
int after_order,
376 uint8_t priority,
int after_order);
379 void MoveItemTo(
unsigned from,
unsigned to) {
380 unsigned from_id =
items[from].
id;
392 unsigned FindPriorityOrder(
unsigned start_order, uint8_t priority,
393 unsigned exclude_order)
const noexcept;
396 unsigned CountSamePriority(
unsigned start_order,
397 uint8_t priority)
const noexcept;
void SwapOrders(unsigned order1, unsigned order2)
Swaps two songs, addressed by their order number.
uint32_t version
when was this item last changed?
unsigned * order
map order numbers to positions
void MoveRange(unsigned start, unsigned end, unsigned to) noexcept
Moves a range of songs to a new position.
uint32_t version
the current version number
int PositionToId(unsigned position) const
static constexpr unsigned HASH_MULT
reserve max_length * HASH_MULT elements in the id number space
uint8_t priority
The priority of this item, between 0 and 255.
bool consume
remove each played files.
A table that maps id numbers to position numbers.
bool repeat
repeat playback when the end of the queue has been reached?
Item * items
all songs in "position" order
unsigned max_length
configured maximum length of the queue
LazyRandomEngine rand
random number generator for shuffle and random mode
bool IsNewerAtPosition(unsigned position, uint32_t _version) const
Is the song at the specified position newer than the specified version?
Queue & operator=(const Queue &)=delete
void Move(unsigned id, unsigned position)
void ShuffleOrder()
Shuffles the virtual order of songs, but does not move them physically.
int IdToPosition(unsigned id) const
void Clear() noexcept
Removes all songs from the playlist.
void SwapPositions(unsigned position1, unsigned position2) noexcept
Swaps two songs, addressed by their position.
void ModifyAtOrder(unsigned order) noexcept
Marks the specified song as "modified".
int IdToPosition(unsigned id) const
unsigned id
the unique id of this item in the queue
unsigned Append(DetachedSong &&song, uint8_t priority)
Appends a song to the queue and returns its position.
gcc_pure unsigned PositionToOrder(unsigned position) const noexcept
gcc_pure unsigned OrderToPosition(unsigned _order) const noexcept
void RestoreOrder()
Initializes the "order" array, and restores "normal" order.
~Queue()
Deinitializes a queue object.
void ShuffleOrderRangeWithPriority(unsigned start, unsigned end)
Shuffle the order of items in the specified range, taking their priorities into account.
bool IsValidOrder(unsigned _order) const
Is that a valid order number?
One element of the queue: basically a song plus some queue specific information attached.
Queue(unsigned max_length)
gcc_pure int GetNextOrder(unsigned order) const noexcept
Returns the order number following the specified one.
bool IsValidPosition(unsigned position) const
Is that a valid position number?
void ShuffleOrderFirst(unsigned start, unsigned end)
void ShuffleOrderRange(unsigned start, unsigned end)
Shuffle the order of items in the specified range, ignoring their priorities.
bool random
play back songs in random order?
unsigned GetLength() const
bool single
play only current song.
bool IsFull() const
Determine if the maximum number of songs has been reached.
const Item & GetOrderItem(unsigned i) const
gcc_pure uint8_t GetPriorityAtPosition(unsigned position) const noexcept
DetachedSong & GetOrder(unsigned _order) const
Returns the song at the specified order number.
uint8_t GetOrderPriority(unsigned i) const
unsigned MoveOrder(unsigned from_order, unsigned to_order) noexcept
Moves a song to a new position in the "order" list.
void IncrementVersion() noexcept
Increments the queue's version number.
IdTable id_table
map song ids to positions
unsigned MoveOrderBefore(unsigned from_order, unsigned to_order) noexcept
Moves a song to a new position in the "order" list before the given one.
bool IsEmpty() const
Determine if the queue is empty, i.e.
void ModifyAtPosition(unsigned position)
Marks the specified song as "modified".
void ShuffleOrderLastWithPriority(unsigned start, unsigned end)
Shuffles the virtual order of the last song in the specified (order) range; only songs which match th...
bool SetPriorityRange(unsigned start_position, unsigned end_position, uint8_t priority, int after_order)
A random engine that will be created and seeded on demand.
void MovePostion(unsigned from, unsigned to) noexcept
Moves a song to a new position.
unsigned MoveOrderAfter(unsigned from_order, unsigned to_order) noexcept
Moves a song to a new position in the "order" list after the given one.
unsigned length
number of songs in the queue
void ShuffleRange(unsigned start, unsigned end)
Shuffles a (position) range in the queue.
void DeletePosition(unsigned position) noexcept
Removes a song from the playlist.
bool SetPriority(unsigned position, uint8_t priority, int after_order, bool reorder=true)
DetachedSong & Get(unsigned position) const
Returns the song at the specified position.