MPD 0.20.6

- Main Page
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

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
Queue & | operator= (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
gcc_pure unsigned | PositionToOrder (unsigned position) const
gcc_pure uint8_t | GetPriorityAtPosition (unsigned position) const
const Item & | GetOrderItem (unsigned i) const
uint8_t | GetOrderPriority (unsigned i) const
DetachedSong & | Get (unsigned position) const
| Returns the song at the specified position. More...
DetachedSong & | GetOrder (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
| Returns the order number following the specified one. More...
void | IncrementVersion ()
| Increments the queue's version number. More...
void | ModifyAtPosition (unsigned position)
| Marks the specified song as "modified". More...
void | ModifyAtOrder (unsigned order)
| 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)
| Swaps two songs, addressed by their position. More...
void | SwapOrders (unsigned order1, unsigned order2)
| Swaps two songs, addressed by their order number. More...
void | MoveOrder (unsigned from_order, unsigned to_order)
| Moves a song to a new position in the "order" list. More...
void | MovePostion (unsigned from, unsigned to)
| Moves a song to a new position. More...
void | MoveRange (unsigned start, unsigned end, unsigned to)
| Moves a range of songs to a new position. More...
void | DeletePosition (unsigned position)
| Removes a song from the playlist. More...
void | Clear ()
| 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 | ShuffleOrderLast (unsigned start, unsigned end)
| Shuffles the virtual order of the last song in the specified (order) range. 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...
Item * | items
| 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:

- the position in the queue
- the unique id (which stays the same, regardless of moves)
- the order number (which only differs from "position" in random mode)

Definition at line 44 of file Queue.hxx.

## Constructor & Destructor Documentation

Queue::Queue | ( | unsigned | max_length | ) |
| explicit

Queue::~Queue | ( |  | ) |

Deinitializes a queue object.

It does not free the queue pointer itself.

Queue::Queue | ( | const Queue & |  | ) |
| delete

## Member Function Documentation

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

  priority | the priority of this new queue item

void Queue::Clear | ( |  | ) |

Removes all songs from the playlist.

void Queue::DeletePosition | ( | unsigned | position | ) |

Removes a song from the playlist.

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

Returns the song at the specified position.

Definition at line 203 of file Queue.hxx.

unsigned Queue::GetLength | ( |  | ) | const
| inline

Definition at line 117 of file Queue.hxx.

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

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

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

Returns the song at the specified order number.

Definition at line 212 of file Queue.hxx.

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

Definition at line 190 of file Queue.hxx.

uint8_t Queue::GetOrderPriority | ( | unsigned | i | ) | const
| inline

Definition at line 196 of file Queue.hxx.

gcc_pure uint8_t Queue::GetPriorityAtPosition | ( | unsigned | position | ) | const
| inline

Definition at line 184 of file Queue.hxx.

int Queue::IdToPosition | ( | unsigned | id | ) | const
| inline

Definition at line 153 of file Queue.hxx.

void Queue::IncrementVersion | ( |  | ) |

Increments the queue's version number.

This handles integer overflow well.

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.

bool Queue::IsFull | ( |  | ) | const
| inline

Determine if the maximum number of songs has been reached.

Definition at line 133 of file Queue.hxx.

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.

bool Queue::IsValidOrder | ( | unsigned | _order | ) | const
| inline

Is that a valid order number?

Definition at line 149 of file Queue.hxx.

bool Queue::IsValidPosition | ( | unsigned | position | ) | const
| inline

Is that a valid position number?

Definition at line 142 of file Queue.hxx.

void Queue::ModifyAtOrder | ( | unsigned | order | ) |

Marks the specified song as "modified".

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

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.

void Queue::MoveOrder | ( | unsigned | from_order,
|  | unsigned | to_order
| ) |  |

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

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

Moves a song to a new position.

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

Moves a range of songs to a new position.

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

gcc_pure unsigned Queue::OrderToPosition | ( | unsigned | _order | ) | const
| inline

Definition at line 165 of file Queue.hxx.

int Queue::PositionToId | ( | unsigned | position | ) | const
| inline

Definition at line 157 of file Queue.hxx.

gcc_pure unsigned Queue::PositionToOrder | ( | unsigned | position | ) | const
| inline

Definition at line 172 of file Queue.hxx.

void Queue::RestoreOrder | ( |  | ) |
| inline

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

Definition at line 313 of file Queue.hxx.

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

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

void Queue::ShuffleOrder | ( |  | ) |

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

This is used in random mode.

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

void Queue::ShuffleOrderLast | ( | unsigned | start,
|  | unsigned | end
| ) |  |

Shuffles the virtual order of the last song in the specified (order) range.

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

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

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

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

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

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.

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

Swaps two songs, addressed by their order number.

Definition at line 281 of file Queue.hxx.

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

Swaps two songs, addressed by their position.

## Field Documentation

bool Queue::consume

remove each played files.

Definition at line 98 of file Queue.hxx.

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.

IdTable Queue::id_table

map song ids to positions

Definition at line 88 of file Queue.hxx.

Item* Queue::items

all songs in "position" order

Definition at line 82 of file Queue.hxx.

unsigned Queue::length

number of songs in the queue

Definition at line 76 of file Queue.hxx.

unsigned Queue::max_length

configured maximum length of the queue

Definition at line 73 of file Queue.hxx.

unsigned* Queue::order

map order numbers to positions

Definition at line 85 of file Queue.hxx.

LazyRandomEngine Queue::rand

random number generator for shuffle and random mode

Definition at line 104 of file Queue.hxx.

bool Queue::random

play back songs in random order?

Definition at line 101 of file Queue.hxx.

bool Queue::repeat

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

Definition at line 92 of file Queue.hxx.

bool Queue::single

play only current song.

Definition at line 95 of file Queue.hxx.

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:

- queue/Queue.hxx