summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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
5 files changed, 13 insertions, 5 deletions
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;