summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Arnoud <laurent@spkdev.net>2018-12-01 14:55:03 +0100
committerLaurent Arnoud <laurent@spkdev.net>2019-10-01 19:05:44 +0200
commit69f49d558d46fd93c387475675e8188a0948c8fb (patch)
treee724f98b770cd187429d2328a9292ff93f4125e6
parent20d660177d79d20a7b9c103006be4dac176bd9e8 (diff)
Add random_exclude_pattern option for random songs
-rw-r--r--doc/config4
-rw-r--r--src/actions.cpp2
-rw-r--r--src/mpdpp.cpp12
-rw-r--r--src/mpdpp.h2
-rw-r--r--src/settings.cpp1
-rw-r--r--src/settings.h1
6 files changed, 17 insertions, 5 deletions
diff --git a/doc/config b/doc/config
index fe6d4252..a9687145 100644
--- a/doc/config
+++ b/doc/config
@@ -34,6 +34,10 @@
#
#mpd_crossfade_time = 5
#
+# Exclude pattern for random song action
+# http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
+#random_exclude_pattern = "^(temp|midi_songs).*"
+#
##### music visualizer #####
##
## Note: In order to make music visualizer work you'll need to use mpd fifo
diff --git a/src/actions.cpp b/src/actions.cpp
index 5ef97771..cc309a5f 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -2208,7 +2208,7 @@ void AddRandomItems::run()
{
bool success;
if (rnd_type == 's')
- success = Mpd.AddRandomSongs(number, Global::RNG);
+ success = Mpd.AddRandomSongs(number, Config.random_exclude_pattern, Global::RNG);
else
success = Mpd.AddRandomTag(tag_type, number, Global::RNG);
if (success)
diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp
index 3b199af7..f576e5ff 100644
--- a/src/mpdpp.cpp
+++ b/src/mpdpp.cpp
@@ -22,6 +22,7 @@
#include <cstdlib>
#include <algorithm>
#include <map>
+#include <boost/regex.hpp>
#include "charset.h"
#include "mpdpp.h"
@@ -601,7 +602,7 @@ bool Connection::AddRandomTag(mpd_tag_type tag, size_t number, std::mt19937 &rng
return true;
}
-bool Connection::AddRandomSongs(size_t number, std::mt19937 &rng)
+bool Connection::AddRandomSongs(size_t number, std::string random_exclude_pattern, std::mt19937 &rng)
{
prechecksNoCommandsList();
std::vector<std::string> files;
@@ -625,8 +626,13 @@ bool Connection::AddRandomSongs(size_t number, std::mt19937 &rng)
std::shuffle(files.begin(), files.end(), rng);
StartCommandsList();
auto it = files.begin();
- for (size_t i = 0; i < number && it != files.end(); ++i, ++it)
- AddSong(*it);
+ boost::regex re(random_exclude_pattern);
+ for (size_t i = 0; i < number && it != files.end(); ++it) {
+ if (random_exclude_pattern.empty() || !boost::regex_match((*it), re)) {
+ AddSong(*it);
+ i++;
+ }
+ }
CommitCommandsList();
}
return true;
diff --git a/src/mpdpp.h b/src/mpdpp.h
index 75ce6ec3..a2bb79eb 100644
--- a/src/mpdpp.h
+++ b/src/mpdpp.h
@@ -546,7 +546,7 @@ struct Connection
int AddSong(const std::string &, int = -1); // returns id of added song
int AddSong(const Song &, int = -1); // returns id of added song
bool AddRandomTag(mpd_tag_type, size_t, std::mt19937 &rng);
- bool AddRandomSongs(size_t number, std::mt19937 &rng);
+ bool AddRandomSongs(size_t number, std::string random_exclude_pattern, std::mt19937 &rng);
void Add(const std::string &path);
void Delete(unsigned int pos);
void PlaylistDelete(const std::string &playlist, unsigned int pos);
diff --git a/src/settings.cpp b/src/settings.cpp
index 76b2f2e0..8ef95943 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -275,6 +275,7 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
p.add("mpd_music_dir", &mpd_music_dir, "~/music", adjust_directory);
p.add("mpd_connection_timeout", &mpd_connection_timeout, "5");
p.add("mpd_crossfade_time", &crossfade_time, "5");
+ p.add("random_exclude_pattern", &random_exclude_pattern, "");
p.add("visualizer_fifo_path", &visualizer_fifo_path, "/tmp/mpd.fifo", adjust_path);
p.add("visualizer_output_name", &visualizer_output_name, "Visualizer feed");
p.add("visualizer_in_stereo", &visualizer_in_stereo, "yes", yes_no);
diff --git a/src/settings.h b/src/settings.h
index 676f278c..2bbf9324 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -178,6 +178,7 @@ struct Configuration
unsigned mpd_connection_timeout;
unsigned crossfade_time;
+ std::string random_exclude_pattern;
unsigned seek_time;
unsigned volume_change_step;
unsigned message_delay_time;