libsaria: Choose songs after filtering
Songs are only picked from the set of visible songs after filtering.
This commit is contained in:
parent
f0decd07d6
commit
a14cedc942
|
@ -4,6 +4,8 @@
|
|||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <libsaria/callback.h>
|
||||
#include <libsaria/format.h>
|
||||
#include "library.h"
|
||||
|
@ -193,4 +195,14 @@ namespace libsaria
|
|||
return results.size();
|
||||
}
|
||||
|
||||
ino_t library::index_rand()
|
||||
{
|
||||
set<ino_t>::iterator it = results.begin();
|
||||
unsigned int index = rand() % filter_size();
|
||||
|
||||
for (unsigned int i = 0; i < index; i++)
|
||||
it++;
|
||||
return *it;
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -75,6 +75,7 @@ namespace libsaria
|
|||
void reindex();
|
||||
bool is_filtered();
|
||||
unsigned int filter_size();
|
||||
ino_t index_rand();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,19 +79,49 @@ static void insert_list(list<TrackTag> *tag_list)
|
|||
play_list.push_back(&(*it));
|
||||
}
|
||||
|
||||
static void print_cur_track()
|
||||
{
|
||||
println("Selected track:");
|
||||
println(" Title: " + (*cur_track)->get_title());
|
||||
println(" Album: " + (*cur_track)->get_album());
|
||||
println(" Artist: " + (*cur_track)->get_artist());
|
||||
println(" File: " + (*cur_track)->get_filepath());
|
||||
}
|
||||
|
||||
static void random_next()
|
||||
{
|
||||
unsigned int index = rand() % play_list.size();
|
||||
cur_track = play_list.begin();
|
||||
for (unsigned int i = 0; i < index; i++)
|
||||
cur_track++;
|
||||
if (libsaria::library::is_filtered()) {
|
||||
println("Picking random track from index");
|
||||
ino_t inode = libsaria::library::index_rand();
|
||||
libsaria::library::play_id(inode);
|
||||
} else {
|
||||
unsigned int index = rand() % play_list.size();
|
||||
println("Picking random track from list");
|
||||
for (unsigned int i = 0; i < index; i++)
|
||||
cur_track++;
|
||||
}
|
||||
}
|
||||
|
||||
static void sequential_next()
|
||||
{
|
||||
cur_track++;
|
||||
if (cur_track == play_list.end())
|
||||
cur_track = play_list.begin();
|
||||
ino_t inode;
|
||||
do {
|
||||
cur_track++;
|
||||
println("Picking sequentially next track");
|
||||
if (cur_track == play_list.end())
|
||||
cur_track = play_list.begin();
|
||||
inode = (*cur_track)->get_inode();
|
||||
} while (!libsaria::library::is_visible(inode));
|
||||
}
|
||||
|
||||
static void pick_next()
|
||||
{
|
||||
if (libsaria::prefs::get_bool("random") == true)
|
||||
random_next();
|
||||
else
|
||||
sequential_next();
|
||||
print_cur_track();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
|
@ -139,11 +169,18 @@ namespace libsaria
|
|||
|
||||
void library::next()
|
||||
{
|
||||
if (libsaria::prefs::get_bool("random") == true)
|
||||
random_next();
|
||||
else
|
||||
sequential_next();
|
||||
libsaria::audio::load((*cur_track)->get_filepath());
|
||||
string filepath = "";
|
||||
|
||||
if (libsaria::library::size() == 0) {
|
||||
libsaria::audio::stop();
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
pick_next();
|
||||
filepath = (*cur_track)->get_filepath();
|
||||
} while (filepath == "");
|
||||
libsaria::audio::load(filepath);
|
||||
}
|
||||
|
||||
unsigned int library::size()
|
||||
|
|
Loading…
Reference in New Issue