song/PrioritySongFilter: new filter
Closes https://github.com/MusicPlayerDaemon/MPD/issues/1412
This commit is contained in:
parent
c68dbc4e5c
commit
2172aaf1ce
1
NEWS
1
NEWS
|
@ -1,6 +1,7 @@
|
|||
ver 0.24 (not yet released)
|
||||
* protocol
|
||||
- "playlistfind"/"playlistsearch" have "sort" and "window" parameters
|
||||
- filter "prio" (for "playlistfind"/"playlistsearch")
|
||||
* player
|
||||
- add option "mixramp_analyzer" to scan MixRamp tags on-the-fly
|
||||
* tags
|
||||
|
|
|
@ -220,6 +220,9 @@ of:
|
|||
matches the audio format with the given mask (i.e. one
|
||||
or more attributes may be ``*``).
|
||||
|
||||
- ``(priority >= 42)``:
|
||||
compares the priority of queued songs.
|
||||
|
||||
- ``(!EXPRESSION)``: negate an expression. Note that each expression
|
||||
must be enclosed in parentheses, e.g. :code:`(!(artist == 'VALUE'))`
|
||||
(which is equivalent to :code:`(artist != 'VALUE')`)
|
||||
|
|
|
@ -45,6 +45,7 @@ Queue::GetLight(unsigned position) const noexcept
|
|||
assert(position < length);
|
||||
|
||||
LightSong song{Get(position)};
|
||||
song.priority = GetPriorityAtPosition(position);
|
||||
return song;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "TagSongFilter.hxx"
|
||||
#include "ModifiedSinceSongFilter.hxx"
|
||||
#include "AudioFormatSongFilter.hxx"
|
||||
#include "PrioritySongFilter.hxx"
|
||||
#include "pcm/AudioParser.hxx"
|
||||
#include "tag/ParseName.hxx"
|
||||
#include "time/ISO8601.hxx"
|
||||
|
@ -53,6 +54,7 @@ enum {
|
|||
|
||||
LOCATE_TAG_MODIFIED_SINCE,
|
||||
LOCATE_TAG_AUDIO_FORMAT,
|
||||
LOCATE_TAG_PRIORITY,
|
||||
LOCATE_TAG_FILE_TYPE,
|
||||
LOCATE_TAG_ANY_TYPE,
|
||||
};
|
||||
|
@ -80,6 +82,9 @@ locate_parse_type(const char *str) noexcept
|
|||
if (StringEqualsCaseASCII(str, "AudioFormat"))
|
||||
return LOCATE_TAG_AUDIO_FORMAT;
|
||||
|
||||
if (StringEqualsCaseASCII(str, "prio"))
|
||||
return LOCATE_TAG_PRIORITY;
|
||||
|
||||
return tag_name_parse_i(str);
|
||||
}
|
||||
|
||||
|
@ -322,6 +327,27 @@ SongFilter::ParseExpression(const char *&s, bool fold_case)
|
|||
s = StripLeft(s + 1);
|
||||
|
||||
return std::make_unique<AudioFormatSongFilter>(value);
|
||||
} else if (type == LOCATE_TAG_PRIORITY) {
|
||||
if (s[0] == '>' && s[1] == '=') {
|
||||
// TODO support more operators
|
||||
} else
|
||||
throw std::runtime_error("'>=' expected");
|
||||
|
||||
s = StripLeft(s + 2);
|
||||
|
||||
char *endptr;
|
||||
const auto value = strtoul(s, &endptr, 10);
|
||||
if (endptr == s)
|
||||
throw std::runtime_error("Number expected");
|
||||
|
||||
if (value > 0xff)
|
||||
throw std::runtime_error("Invalid priority value");
|
||||
|
||||
if (*endptr != ')')
|
||||
throw std::runtime_error("')' expected");
|
||||
s = StripLeft(endptr + 1);
|
||||
|
||||
return std::make_unique<PrioritySongFilter>(value);
|
||||
} else {
|
||||
auto string_filter = ParseStringFilter(s, fold_case);
|
||||
if (*s != ')')
|
||||
|
|
|
@ -84,6 +84,11 @@ struct LightSong {
|
|||
*/
|
||||
AudioFormat audio_format = AudioFormat::Undefined();
|
||||
|
||||
/**
|
||||
* Copy of Queue::Item::priority.
|
||||
*/
|
||||
uint8_t priority = 0;
|
||||
|
||||
LightSong(const char *_uri, const Tag &_tag) noexcept
|
||||
:uri(_uri), tag(_tag) {}
|
||||
|
||||
|
|
|
@ -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 "PrioritySongFilter.hxx"
|
||||
#include "LightSong.hxx"
|
||||
#include "time/ISO8601.hxx"
|
||||
#include "util/StringBuffer.hxx"
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
std::string
|
||||
PrioritySongFilter::ToExpression() const noexcept
|
||||
{
|
||||
return fmt::format(FMT_STRING("(prio >= {})"), value);
|
||||
}
|
||||
|
||||
bool
|
||||
PrioritySongFilter::Match(const LightSong &song) const noexcept
|
||||
{
|
||||
return song.priority >= value;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
#include "ISongFilter.hxx"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class PrioritySongFilter final : public ISongFilter {
|
||||
const uint8_t value;
|
||||
|
||||
public:
|
||||
explicit PrioritySongFilter(uint8_t _value) noexcept
|
||||
:value(_value) {}
|
||||
|
||||
ISongFilterPtr Clone() const noexcept override {
|
||||
return std::make_unique<PrioritySongFilter>(*this);
|
||||
}
|
||||
|
||||
std::string ToExpression() const noexcept override;
|
||||
bool Match(const LightSong &song) const noexcept override;
|
||||
};
|
|
@ -7,6 +7,7 @@ song = static_library(
|
|||
'BaseSongFilter.cxx',
|
||||
'TagSongFilter.cxx',
|
||||
'ModifiedSinceSongFilter.cxx',
|
||||
'PrioritySongFilter.cxx',
|
||||
'AudioFormatSongFilter.cxx',
|
||||
'AndSongFilter.cxx',
|
||||
'OptimizeFilter.cxx',
|
||||
|
@ -15,6 +16,7 @@ song = static_library(
|
|||
include_directories: inc,
|
||||
dependencies: [
|
||||
pcre_dep,
|
||||
fmt_dep,
|
||||
],
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue