106 explicit Queue(
unsigned max_length);
118 assert(length <= max_length);
134 assert(length <= max_length);
159 assert(position < length);
161 return items[position].
id;
166 assert(_order < 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);
206 return *items[position].
song;
221 assert(position < length);
223 return _version > version ||
224 items[position].
version >= _version ||
249 assert(position < length);
276 void SwapPositions(
unsigned position1,
unsigned position2) noexcept;
282 std::swap(order[order1], order[order2]);
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;
382 items[to] = items[from];
384 id_table.
Move(from_id, to);
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
bool IsValidOrder(unsigned _order) const
Is that a valid order number?
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.
int IdToPosition(unsigned id) const
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?
bool IsEmpty() const
Determine if the queue is empty, i.e.
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
Queue & operator=(const Queue &)=delete
bool IsValidPosition(unsigned position) const
Is that a valid position number?
int PositionToId(unsigned position) const
void Move(unsigned id, unsigned position)
void ShuffleOrder()
Shuffles the virtual order of songs, but does not move them physically.
DetachedSong & GetOrder(unsigned _order) const
Returns the song at the specified order number.
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".
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.
DetachedSong & Get(unsigned position) const
Returns the song at the specified 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.
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 IsNewerAtPosition(unsigned position, uint32_t _version) const
Is the song at the specified position newer than the specified version?
unsigned GetLength() const
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?
bool single
play only current song.
int IdToPosition(unsigned id) const
gcc_pure uint8_t GetPriorityAtPosition(unsigned position) const noexcept
bool IsFull() const
Determine if the maximum number of songs has been reached.
unsigned MoveOrder(unsigned from_order, unsigned to_order) noexcept
Moves a song to a new position in the "order" list.
const Item & GetOrderItem(unsigned i) const
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.
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.
uint8_t GetOrderPriority(unsigned i) const
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)