added support for a shuffle key in the [music] music to allow selecting between random and non-random music play
This commit is contained in:
parent
ede5148bfb
commit
b7e8590120
3 changed files with 26 additions and 10 deletions
|
@ -160,6 +160,7 @@ std::vector<std::string> played_before;
|
|||
std::vector<sound::music_track> current_track_list;
|
||||
sound::music_track current_track;
|
||||
sound::music_track last_track;
|
||||
unsigned int current_track_index = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -224,17 +225,25 @@ static const sound::music_track &choose_track()
|
|||
{
|
||||
assert(!current_track_list.empty());
|
||||
|
||||
unsigned int track = 0;
|
||||
if (current_track_index == current_track_list.size()) {
|
||||
current_track_index = 0;
|
||||
}
|
||||
|
||||
if (current_track_list.size() > 1) {
|
||||
do {
|
||||
track = rand()%current_track_list.size();
|
||||
} while (!track_ok( current_track_list[track].file_path() ));
|
||||
if (current_track_list[current_track_index].shuffle()) {
|
||||
unsigned int track = 0;
|
||||
|
||||
if (current_track_list.size() > 1) {
|
||||
do {
|
||||
track = rand()%current_track_list.size();
|
||||
} while (!track_ok( current_track_list[track].file_path() ));
|
||||
}
|
||||
|
||||
current_track_index = track;
|
||||
}
|
||||
|
||||
//LOG_AUDIO << "Next track will be " << current_track_list[track].file_path() << "\n";
|
||||
played_before.push_back( current_track_list[track].file_path() );
|
||||
return current_track_list[track];
|
||||
played_before.push_back( current_track_list[current_track_index].file_path() );
|
||||
return current_track_list[current_track_index++];
|
||||
}
|
||||
|
||||
static std::string pick_one(const std::string &files)
|
||||
|
|
|
@ -37,7 +37,8 @@ music_track::music_track() :
|
|||
ms_after_(0),
|
||||
once_(false),
|
||||
append_(false),
|
||||
immediate_(false)
|
||||
immediate_(false),
|
||||
shuffle_(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,7 +50,8 @@ music_track::music_track(const config& node) :
|
|||
ms_after_(node["ms_after"]),
|
||||
once_(node["play_once"].to_bool()),
|
||||
append_(node["append"].to_bool()),
|
||||
immediate_(node["immediate"].to_bool())
|
||||
immediate_(node["immediate"].to_bool()),
|
||||
shuffle_(node["shuffle"].to_bool(true))
|
||||
{
|
||||
resolve();
|
||||
}
|
||||
|
@ -62,7 +64,8 @@ music_track::music_track(const std::string& v_name) :
|
|||
ms_after_(0),
|
||||
once_(false),
|
||||
append_(false),
|
||||
immediate_(false)
|
||||
immediate_(false),
|
||||
shuffle_(true)
|
||||
{
|
||||
resolve();
|
||||
}
|
||||
|
@ -133,6 +136,8 @@ void music_track::write(config &parent_node, bool append) const
|
|||
if(append) {
|
||||
m["append"] = true;
|
||||
}
|
||||
//default behaviour is to shuffle
|
||||
m["shuffle"] = shuffle_;
|
||||
}
|
||||
|
||||
} /* end namespace sound */
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
|
||||
bool append() const { return append_; }
|
||||
bool immediate() const { return immediate_; }
|
||||
bool shuffle() const { return shuffle_; }
|
||||
bool play_once() const { return once_; }
|
||||
int ms_before() const { return ms_before_; }
|
||||
int ms_after() const { return ms_after_; }
|
||||
|
@ -59,6 +60,7 @@ private:
|
|||
bool once_;
|
||||
bool append_;
|
||||
bool immediate_;
|
||||
bool shuffle_;
|
||||
};
|
||||
|
||||
} /* end namespace sound */
|
||||
|
|
Loading…
Add table
Reference in a new issue