MPD  0.20.18
Data Structures | Public Member Functions | Data Fields | Static Public Attributes
Queue Struct Reference

A queue of songs. More...

#include <Queue.hxx>

Collaboration diagram for Queue:
[legend]

Data Structures

struct  Item
 One element of the queue: basically a song plus some queue specific information attached. More...
 

Public Member Functions

 Queue (unsigned max_length)
 
 ~Queue ()
 Deinitializes a queue object. More...
 
 Queue (const Queue &)=delete
 
Queueoperator= (const Queue &)=delete
 
unsigned GetLength () const
 
bool IsEmpty () const
 Determine if the queue is empty, i.e. More...
 
bool IsFull () const
 Determine if the maximum number of songs has been reached. More...
 
bool IsValidPosition (unsigned position) const
 Is that a valid position number? More...
 
bool IsValidOrder (unsigned _order) const
 Is that a valid order number? More...
 
int IdToPosition (unsigned id) const
 
int PositionToId (unsigned position) const
 
gcc_pure unsigned OrderToPosition (unsigned _order) const noexcept
 
gcc_pure unsigned PositionToOrder (unsigned position) const noexcept
 
gcc_pure uint8_t GetPriorityAtPosition (unsigned position) const noexcept
 
const ItemGetOrderItem (unsigned i) const
 
uint8_t GetOrderPriority (unsigned i) const
 
DetachedSongGet (unsigned position) const
 Returns the song at the specified position. More...
 
DetachedSongGetOrder (unsigned _order) const
 Returns the song at the specified order number. More...
 
bool IsNewerAtPosition (unsigned position, uint32_t _version) const
 Is the song at the specified position newer than the specified version? More...
 
gcc_pure int GetNextOrder (unsigned order) const noexcept
 Returns the order number following the specified one. More...
 
void IncrementVersion () noexcept
 Increments the queue's version number. More...
 
void ModifyAtPosition (unsigned position)
 Marks the specified song as "modified". More...
 
void ModifyAtOrder (unsigned order) noexcept
 Marks the specified song as "modified". More...
 
unsigned Append (DetachedSong &&song, uint8_t priority)
 Appends a song to the queue and returns its position. More...
 
void SwapPositions (unsigned position1, unsigned position2) noexcept
 Swaps two songs, addressed by their position. More...
 
void SwapOrders (unsigned order1, unsigned order2)
 Swaps two songs, addressed by their order number. More...
 
unsigned MoveOrder (unsigned from_order, unsigned to_order) noexcept
 Moves a song to a new position in the "order" list. More...
 
unsigned MoveOrderBefore (unsigned from_order, unsigned to_order) noexcept
 Moves a song to a new position in the "order" list before the given one. More...
 
unsigned MoveOrderAfter (unsigned from_order, unsigned to_order) noexcept
 Moves a song to a new position in the "order" list after the given one. More...
 
void MovePostion (unsigned from, unsigned to) noexcept
 Moves a song to a new position. More...
 
void MoveRange (unsigned start, unsigned end, unsigned to) noexcept
 Moves a range of songs to a new position. More...
 
void DeletePosition (unsigned position) noexcept
 Removes a song from the playlist. More...
 
void Clear () noexcept
 Removes all songs from the playlist. More...
 
void RestoreOrder ()
 Initializes the "order" array, and restores "normal" order. More...
 
void ShuffleOrderRange (unsigned start, unsigned end)
 Shuffle the order of items in the specified range, ignoring their priorities. More...
 
void ShuffleOrderRangeWithPriority (unsigned start, unsigned end)
 Shuffle the order of items in the specified range, taking their priorities into account. More...
 
void ShuffleOrder ()
 Shuffles the virtual order of songs, but does not move them physically. More...
 
void ShuffleOrderFirst (unsigned start, unsigned end)
 
void ShuffleOrderLastWithPriority (unsigned start, unsigned end)
 Shuffles the virtual order of the last song in the specified (order) range; only songs which match this song's priority are considered. More...
 
void ShuffleRange (unsigned start, unsigned end)
 Shuffles a (position) range in the queue. More...
 
bool SetPriority (unsigned position, uint8_t priority, int after_order, bool reorder=true)
 
bool SetPriorityRange (unsigned start_position, unsigned end_position, uint8_t priority, int after_order)
 

Data Fields

unsigned max_length
 configured maximum length of the queue More...
 
unsigned length
 number of songs in the queue More...
 
uint32_t version
 the current version number More...
 
Itemitems
 all songs in "position" order More...
 
unsigned * order
 map order numbers to positions More...
 
IdTable id_table
 map song ids to positions More...
 
bool repeat
 repeat playback when the end of the queue has been reached? More...
 
bool single
 play only current song. More...
 
bool consume
 remove each played files. More...
 
bool random
 play back songs in random order? More...
 
LazyRandomEngine rand
 random number generator for shuffle and random mode More...
 

Static Public Attributes

static constexpr unsigned HASH_MULT = 4
 reserve max_length * HASH_MULT elements in the id number space More...
 

Detailed Description

A queue of songs.

This is the backend of the playlist: it contains an ordered list of songs.

Songs can be addressed in three possible ways:

Definition at line 44 of file Queue.hxx.

Constructor & Destructor Documentation

◆ Queue() [1/2]

Queue::Queue ( unsigned  max_length)
explicit

◆ ~Queue()

Queue::~Queue ( )

Deinitializes a queue object.

It does not free the queue pointer itself.

◆ Queue() [2/2]

Queue::Queue ( const Queue )
delete

Member Function Documentation

◆ Append()

unsigned Queue::Append ( DetachedSong &&  song,
uint8_t  priority 
)

Appends a song to the queue and returns its position.

Prior to that, the caller must check if the queue is already full.

If a song is not in the database (determined by Song::IsInDatabase()), it is freed when removed from the queue.

Parameters
prioritythe priority of this new queue item

◆ Clear()

void Queue::Clear ( )
noexcept

Removes all songs from the playlist.

◆ DeletePosition()

void Queue::DeletePosition ( unsigned  position)
noexcept

Removes a song from the playlist.

◆ Get()

DetachedSong& Queue::Get ( unsigned  position) const
inline

Returns the song at the specified position.

Definition at line 203 of file Queue.hxx.

◆ GetLength()

unsigned Queue::GetLength ( ) const
inline

Definition at line 117 of file Queue.hxx.

◆ GetNextOrder()

gcc_pure int Queue::GetNextOrder ( unsigned  order) const
noexcept

Returns the order number following the specified one.

This takes end of queue and "repeat" mode into account.

Returns
the next order number, or -1 to stop playback

◆ GetOrder()

DetachedSong& Queue::GetOrder ( unsigned  _order) const
inline

Returns the song at the specified order number.

Definition at line 212 of file Queue.hxx.

◆ GetOrderItem()

const Item& Queue::GetOrderItem ( unsigned  i) const
inline

Definition at line 190 of file Queue.hxx.

◆ GetOrderPriority()

uint8_t Queue::GetOrderPriority ( unsigned  i) const
inline

Definition at line 196 of file Queue.hxx.

◆ GetPriorityAtPosition()

gcc_pure uint8_t Queue::GetPriorityAtPosition ( unsigned  position) const
inlinenoexcept

Definition at line 184 of file Queue.hxx.

◆ IdToPosition()

int Queue::IdToPosition ( unsigned  id) const
inline

Definition at line 153 of file Queue.hxx.

◆ IncrementVersion()

void Queue::IncrementVersion ( )
noexcept

Increments the queue's version number.

This handles integer overflow well.

◆ IsEmpty()

bool Queue::IsEmpty ( ) const
inline

Determine if the queue is empty, i.e.

there are no songs.

Definition at line 126 of file Queue.hxx.

◆ IsFull()

bool Queue::IsFull ( ) const
inline

Determine if the maximum number of songs has been reached.

Definition at line 133 of file Queue.hxx.

◆ IsNewerAtPosition()

bool Queue::IsNewerAtPosition ( unsigned  position,
uint32_t  _version 
) const
inline

Is the song at the specified position newer than the specified version?

Definition at line 220 of file Queue.hxx.

◆ IsValidOrder()

bool Queue::IsValidOrder ( unsigned  _order) const
inline

Is that a valid order number?

Definition at line 149 of file Queue.hxx.

◆ IsValidPosition()

bool Queue::IsValidPosition ( unsigned  position) const
inline

Is that a valid position number?

Definition at line 142 of file Queue.hxx.

◆ ModifyAtOrder()

void Queue::ModifyAtOrder ( unsigned  order)
noexcept

Marks the specified song as "modified".

Call IncrementVersion() after all modifications have been made. number.

◆ ModifyAtPosition()

void Queue::ModifyAtPosition ( unsigned  position)
inline

Marks the specified song as "modified".

Call IncrementVersion() after all modifications have been made. number.

Definition at line 248 of file Queue.hxx.

◆ MoveOrder()

unsigned Queue::MoveOrder ( unsigned  from_order,
unsigned  to_order 
)
noexcept

Moves a song to a new position in the "order" list.

Returns
to_order

◆ MoveOrderAfter()

unsigned Queue::MoveOrderAfter ( unsigned  from_order,
unsigned  to_order 
)
noexcept

Moves a song to a new position in the "order" list after the given one.

Returns
the new order number of the given "from" song

◆ MoveOrderBefore()

unsigned Queue::MoveOrderBefore ( unsigned  from_order,
unsigned  to_order 
)
noexcept

Moves a song to a new position in the "order" list before the given one.

Returns
the new order number of the given "from" song

◆ MovePostion()

void Queue::MovePostion ( unsigned  from,
unsigned  to 
)
noexcept

Moves a song to a new position.

◆ MoveRange()

void Queue::MoveRange ( unsigned  start,
unsigned  end,
unsigned  to 
)
noexcept

Moves a range of songs to a new position.

◆ operator=()

Queue& Queue::operator= ( const Queue )
delete

◆ OrderToPosition()

gcc_pure unsigned Queue::OrderToPosition ( unsigned  _order) const
inlinenoexcept

Definition at line 165 of file Queue.hxx.

◆ PositionToId()

int Queue::PositionToId ( unsigned  position) const
inline

Definition at line 157 of file Queue.hxx.

◆ PositionToOrder()

gcc_pure unsigned Queue::PositionToOrder ( unsigned  position) const
inlinenoexcept

Definition at line 172 of file Queue.hxx.

◆ RestoreOrder()

void Queue::RestoreOrder ( )
inline

Initializes the "order" array, and restores "normal" order.

Definition at line 333 of file Queue.hxx.

◆ SetPriority()

bool Queue::SetPriority ( unsigned  position,
uint8_t  priority,
int  after_order,
bool  reorder = true 
)

◆ SetPriorityRange()

bool Queue::SetPriorityRange ( unsigned  start_position,
unsigned  end_position,
uint8_t  priority,
int  after_order 
)

◆ ShuffleOrder()

void Queue::ShuffleOrder ( )

Shuffles the virtual order of songs, but does not move them physically.

This is used in random mode.

◆ ShuffleOrderFirst()

void Queue::ShuffleOrderFirst ( unsigned  start,
unsigned  end 
)

◆ ShuffleOrderLastWithPriority()

void Queue::ShuffleOrderLastWithPriority ( unsigned  start,
unsigned  end 
)

Shuffles the virtual order of the last song in the specified (order) range; only songs which match this song's priority are considered.

This is used in random mode after a song has been appended by Append().

◆ ShuffleOrderRange()

void Queue::ShuffleOrderRange ( unsigned  start,
unsigned  end 
)

Shuffle the order of items in the specified range, ignoring their priorities.

◆ ShuffleOrderRangeWithPriority()

void Queue::ShuffleOrderRangeWithPriority ( unsigned  start,
unsigned  end 
)

Shuffle the order of items in the specified range, taking their priorities into account.

◆ ShuffleRange()

void Queue::ShuffleRange ( unsigned  start,
unsigned  end 
)

Shuffles a (position) range in the queue.

The songs are physically shuffled, not by using the "order" mapping.

◆ SwapOrders()

void Queue::SwapOrders ( unsigned  order1,
unsigned  order2 
)
inline

Swaps two songs, addressed by their order number.

Definition at line 281 of file Queue.hxx.

◆ SwapPositions()

void Queue::SwapPositions ( unsigned  position1,
unsigned  position2 
)
noexcept

Swaps two songs, addressed by their position.

Field Documentation

◆ consume

bool Queue::consume

remove each played files.

Definition at line 98 of file Queue.hxx.

◆ HASH_MULT

constexpr unsigned Queue::HASH_MULT = 4
static

reserve max_length * HASH_MULT elements in the id number space

Definition at line 49 of file Queue.hxx.

◆ id_table

IdTable Queue::id_table

map song ids to positions

Definition at line 88 of file Queue.hxx.

◆ items

Item* Queue::items

all songs in "position" order

Definition at line 82 of file Queue.hxx.

◆ length

unsigned Queue::length

number of songs in the queue

Definition at line 76 of file Queue.hxx.

◆ max_length

unsigned Queue::max_length

configured maximum length of the queue

Definition at line 73 of file Queue.hxx.

◆ order

unsigned* Queue::order

map order numbers to positions

Definition at line 85 of file Queue.hxx.

◆ rand

LazyRandomEngine Queue::rand

random number generator for shuffle and random mode

Definition at line 104 of file Queue.hxx.

◆ random

bool Queue::random

play back songs in random order?

Definition at line 101 of file Queue.hxx.

◆ repeat

bool Queue::repeat

repeat playback when the end of the queue has been reached?

Definition at line 92 of file Queue.hxx.

◆ single

bool Queue::single

play only current song.

Definition at line 95 of file Queue.hxx.

◆ version

uint32_t Queue::version

the current version number

Definition at line 79 of file Queue.hxx.


The documentation for this struct was generated from the following file: