Add random_exclude_pattern option for random songs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user