queue/Selection: add "window" field
This commit is contained in:
parent
5588291a35
commit
e9e3d8c57c
@ -25,6 +25,7 @@
|
|||||||
#include "song/DetachedSong.hxx"
|
#include "song/DetachedSong.hxx"
|
||||||
#include "song/LightSong.hxx"
|
#include "song/LightSong.hxx"
|
||||||
#include "client/Response.hxx"
|
#include "client/Response.hxx"
|
||||||
|
#include "PlaylistError.hxx"
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
|
||||||
@ -104,8 +105,29 @@ void
|
|||||||
PrintQueue(Response &r, const Queue &queue,
|
PrintQueue(Response &r, const Queue &queue,
|
||||||
const QueueSelection &selection)
|
const QueueSelection &selection)
|
||||||
{
|
{
|
||||||
|
auto window = selection.window;
|
||||||
|
|
||||||
|
if (!window.CheckClip(queue.GetLength()))
|
||||||
|
throw PlaylistError::BadRange();
|
||||||
|
|
||||||
|
if (selection.window.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
unsigned skip = window.start;
|
||||||
|
unsigned n = window.Count();
|
||||||
|
|
||||||
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
||||||
if (selection.MatchPosition(queue, i))
|
if (!selection.MatchPosition(queue, i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (skip > 0) {
|
||||||
|
--skip;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
queue_print_song_info(r, queue, i);
|
queue_print_song_info(r, queue, i);
|
||||||
|
|
||||||
|
if (--n == 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "protocol/RangeArg.hxx"
|
||||||
|
|
||||||
struct Queue;
|
struct Queue;
|
||||||
class SongFilter;
|
class SongFilter;
|
||||||
|
|
||||||
@ -32,6 +34,8 @@ struct QueueSelection {
|
|||||||
*/
|
*/
|
||||||
const SongFilter *filter = nullptr;
|
const SongFilter *filter = nullptr;
|
||||||
|
|
||||||
|
RangeArg window = RangeArg::All();
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
bool MatchPosition(const Queue &queue,
|
bool MatchPosition(const Queue &queue,
|
||||||
unsigned position) const noexcept;
|
unsigned position) const noexcept;
|
||||||
|
Loading…
Reference in New Issue
Block a user