queue/Selection: wrap SongFilter in a new struct
This commit is contained in:
parent
4b41e766c6
commit
5588291a35
|
@ -332,6 +332,7 @@ sources = [
|
||||||
'src/queue/Queue.cxx',
|
'src/queue/Queue.cxx',
|
||||||
'src/queue/Print.cxx',
|
'src/queue/Print.cxx',
|
||||||
'src/queue/Save.cxx',
|
'src/queue/Save.cxx',
|
||||||
|
'src/queue/Selection.cxx',
|
||||||
'src/queue/Playlist.cxx',
|
'src/queue/Playlist.cxx',
|
||||||
'src/queue/PlaylistControl.cxx',
|
'src/queue/PlaylistControl.cxx',
|
||||||
'src/queue/PlaylistEdit.cxx',
|
'src/queue/PlaylistEdit.cxx',
|
||||||
|
|
|
@ -77,9 +77,9 @@ playlist_print_current(Response &r, const playlist &playlist)
|
||||||
|
|
||||||
void
|
void
|
||||||
playlist_print_find(Response &r, const playlist &playlist,
|
playlist_print_find(Response &r, const playlist &playlist,
|
||||||
const SongFilter &filter)
|
const QueueSelection &selection)
|
||||||
{
|
{
|
||||||
queue_find(r, playlist.queue, filter);
|
PrintQueue(r, playlist.queue, selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
struct playlist;
|
struct playlist;
|
||||||
struct RangeArg;
|
struct RangeArg;
|
||||||
class SongFilter;
|
struct QueueSelection;
|
||||||
class Response;
|
class Response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,7 +65,7 @@ playlist_print_current(Response &r, const playlist &playlist);
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
playlist_print_find(Response &r, const playlist &playlist,
|
playlist_print_find(Response &r, const playlist &playlist,
|
||||||
const SongFilter &filter);
|
const QueueSelection &selection);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print detailed changes since the specified playlist version.
|
* Print detailed changes since the specified playlist version.
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "song/DetachedSong.hxx"
|
#include "song/DetachedSong.hxx"
|
||||||
#include "LocateUri.hxx"
|
#include "LocateUri.hxx"
|
||||||
#include "queue/Playlist.hxx"
|
#include "queue/Playlist.hxx"
|
||||||
|
#include "queue/Selection.hxx"
|
||||||
#include "PlaylistPrint.hxx"
|
#include "PlaylistPrint.hxx"
|
||||||
#include "client/Client.hxx"
|
#include "client/Client.hxx"
|
||||||
#include "client/Response.hxx"
|
#include "client/Response.hxx"
|
||||||
|
@ -299,7 +300,10 @@ handle_playlist_match(Client &client, Request args, Response &r,
|
||||||
}
|
}
|
||||||
filter.Optimize();
|
filter.Optimize();
|
||||||
|
|
||||||
playlist_print_find(r, client.GetPlaylist(), filter);
|
QueueSelection selection;
|
||||||
|
selection.filter = &filter;
|
||||||
|
|
||||||
|
playlist_print_find(r, client.GetPlaylist(), selection);
|
||||||
return CommandResult::OK;
|
return CommandResult::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "Print.hxx"
|
#include "Print.hxx"
|
||||||
#include "Queue.hxx"
|
#include "Queue.hxx"
|
||||||
|
#include "Selection.hxx"
|
||||||
#include "song/Filter.hxx"
|
#include "song/Filter.hxx"
|
||||||
#include "SongPrint.hxx"
|
#include "SongPrint.hxx"
|
||||||
#include "song/DetachedSong.hxx"
|
#include "song/DetachedSong.hxx"
|
||||||
|
@ -100,13 +101,11 @@ queue_print_changes_position(Response &r, const Queue &queue,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
queue_find(Response &r, const Queue &queue,
|
PrintQueue(Response &r, const Queue &queue,
|
||||||
const SongFilter &filter)
|
const QueueSelection &selection)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
for (unsigned i = 0; i < queue.GetLength(); i++) {
|
||||||
const LightSong song{queue.Get(i)};
|
if (selection.MatchPosition(queue, i))
|
||||||
|
|
||||||
if (filter.Match(song))
|
|
||||||
queue_print_song_info(r, queue, i);
|
queue_print_song_info(r, queue, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
struct Queue;
|
struct Queue;
|
||||||
class SongFilter;
|
struct QueueSelection;
|
||||||
class Response;
|
class Response;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -49,5 +49,5 @@ queue_print_changes_position(Response &r, const Queue &queue,
|
||||||
unsigned start, unsigned end);
|
unsigned start, unsigned end);
|
||||||
|
|
||||||
void
|
void
|
||||||
queue_find(Response &response, const Queue &queue,
|
PrintQueue(Response &response, const Queue &queue,
|
||||||
const SongFilter &filter);
|
const QueueSelection &selection);
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2003-2021 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Selection.hxx"
|
||||||
|
#include "Queue.hxx"
|
||||||
|
#include "song/DetachedSong.hxx"
|
||||||
|
#include "song/Filter.hxx"
|
||||||
|
#include "song/LightSong.hxx"
|
||||||
|
|
||||||
|
bool
|
||||||
|
QueueSelection::MatchPosition(const Queue &queue,
|
||||||
|
unsigned position) const noexcept
|
||||||
|
{
|
||||||
|
if (filter != nullptr) {
|
||||||
|
const LightSong song{queue.Get(position)};
|
||||||
|
if (!filter->Match(song))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2003-2021 The Music Player Daemon Project
|
||||||
|
* http://www.musicpd.org
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct Queue;
|
||||||
|
class SongFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes what part of and how the client wishes to see the queue.
|
||||||
|
*/
|
||||||
|
struct QueueSelection {
|
||||||
|
/**
|
||||||
|
* An optional pointer to a #SongFilter (not owned by this
|
||||||
|
* object).
|
||||||
|
*/
|
||||||
|
const SongFilter *filter = nullptr;
|
||||||
|
|
||||||
|
[[gnu::pure]]
|
||||||
|
bool MatchPosition(const Queue &queue,
|
||||||
|
unsigned position) const noexcept;
|
||||||
|
};
|
Loading…
Reference in New Issue