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);
282 std::swap(order[order1], order[order2]);
288 void MoveOrder(
unsigned from_order,
unsigned to_order);
298 void MoveRange(
unsigned start,
unsigned end,
unsigned to);
314 for (
unsigned i = 0; i <
length; ++i)
351 bool SetPriority(
unsigned position, uint8_t priority,
int after_order,
355 uint8_t priority,
int after_order);
358 void MoveItemTo(
unsigned from,
unsigned to) {
359 unsigned from_id = items[from].
id;
361 items[to] = items[from];
363 id_table.
Move(from_id, to);
371 unsigned FindPriorityOrder(
unsigned start_order, uint8_t priority,
372 unsigned exclude_order)
const;
375 unsigned CountSamePriority(
unsigned start_order,
376 uint8_t priority)
const;
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
uint32_t version
the current version number
gcc_pure unsigned PositionToOrder(unsigned position) const
bool IsValidOrder(unsigned _order) const
Is that a valid order number?
void ShuffleOrderLast(unsigned start, unsigned end)
Shuffles the virtual order of the last song in the specified (order) range.
gcc_pure int GetNextOrder(unsigned order) const
Returns the order number following the specified one.
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.
void MoveOrder(unsigned from_order, unsigned to_order)
Moves a song to a new position in the "order" list.
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
void MovePostion(unsigned from, unsigned to)
Moves a song to a new position.
Queue & operator=(const Queue &)=delete
bool IsValidPosition(unsigned position) const
Is that a valid position number?
void MoveRange(unsigned start, unsigned end, unsigned to)
Moves a range of songs to a new position.
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.
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.
void RestoreOrder()
Initializes the "order" array, and restores "normal" order.
~Queue()
Deinitializes a queue object.
void IncrementVersion()
Increments the queue's version number.
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)
void ModifyAtOrder(unsigned order)
Marks the specified song as "modified".
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)
gcc_pure unsigned OrderToPosition(unsigned _order) const
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
void DeletePosition(unsigned position)
Removes a song from the playlist.
bool IsFull() const
Determine if the maximum number of songs has been reached.
const Item & GetOrderItem(unsigned i) const
IdTable id_table
map song ids to positions
void ModifyAtPosition(unsigned position)
Marks the specified song as "modified".
gcc_pure uint8_t GetPriorityAtPosition(unsigned position) const
void SwapPositions(unsigned position1, unsigned position2)
Swaps two songs, addressed by their position.
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 Clear()
Removes all songs from the playlist.
unsigned length
number of songs in the queue
void ShuffleRange(unsigned start, unsigned end)
Shuffles a (position) range in the queue.
bool SetPriority(unsigned position, uint8_t priority, int after_order, bool reorder=true)