libsaria: Move the next() function into the Playlist class
I plan on removing the extra playlist classes to simplify code a bit, so this function needs to be implemented for everything. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
0600556ca4
commit
64b5b78a42
|
@ -58,8 +58,8 @@ namespace libsaria
|
|||
list<Track *> plist;
|
||||
PlaylistRenderer *renderer;
|
||||
|
||||
Track *pick_random();
|
||||
Track *pick_sequential();
|
||||
void pick_random();
|
||||
void pick_sequential();
|
||||
void add_sorted(list<Track *> &);
|
||||
|
||||
public:
|
||||
|
@ -71,6 +71,7 @@ namespace libsaria
|
|||
void push_front(Track *);
|
||||
void push_back(Track *);
|
||||
void push_back(list<Track *> &);
|
||||
Track *next();
|
||||
|
||||
void save(ofstream &);
|
||||
bool is_static();
|
||||
|
@ -82,7 +83,6 @@ namespace libsaria
|
|||
|
||||
void set_disabled(bool);
|
||||
|
||||
virtual Track *next() = 0;
|
||||
string &get_name();
|
||||
void renumber(int);
|
||||
unsigned int get_number();
|
||||
|
@ -101,8 +101,6 @@ namespace libsaria
|
|||
Set(unsigned int);
|
||||
Set(string, unsigned int);
|
||||
~Set();
|
||||
|
||||
Track *next();
|
||||
};
|
||||
|
||||
|
||||
|
@ -111,8 +109,6 @@ namespace libsaria
|
|||
Queue(unsigned int);
|
||||
Queue(string, unsigned int);
|
||||
~Queue();
|
||||
|
||||
Track *next();
|
||||
};
|
||||
|
||||
|
||||
|
@ -121,8 +117,6 @@ namespace libsaria
|
|||
Stack(unsigned int);
|
||||
Stack(string, unsigned int);
|
||||
~Stack();
|
||||
|
||||
Track *next();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -36,28 +36,20 @@ namespace libsaria
|
|||
return res;
|
||||
}
|
||||
|
||||
Track *Playlist::pick_sequential()
|
||||
void Playlist::pick_sequential()
|
||||
{
|
||||
if (get_size() == 0)
|
||||
return NULL;
|
||||
|
||||
if (flags & PL_NO_DRAIN)
|
||||
incr_iter();
|
||||
|
||||
return picked_next();
|
||||
}
|
||||
|
||||
Track *Playlist::pick_random()
|
||||
void Playlist::pick_random()
|
||||
{
|
||||
unsigned int n, range = get_size();
|
||||
unsigned int min = 1;
|
||||
|
||||
if (range == 0)
|
||||
return NULL;
|
||||
|
||||
if (range == 1) {
|
||||
cur = plist.begin();
|
||||
return picked_next();
|
||||
return;
|
||||
}
|
||||
|
||||
if (range > 10) {
|
||||
|
@ -66,11 +58,21 @@ namespace libsaria
|
|||
} else
|
||||
range *= 2;
|
||||
n = min + (rand() % range);
|
||||
//println("min: %u, max: %u, n: %u", min, min + range, n);
|
||||
println("min: %u, max: %u, n: %u", min, min + range, n);
|
||||
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
incr_iter();
|
||||
}
|
||||
|
||||
Track *Playlist::next()
|
||||
{
|
||||
if (get_size() == 0)
|
||||
return NULL;
|
||||
|
||||
if (type == PLIST_SET)
|
||||
pick_random();
|
||||
else
|
||||
pick_sequential();
|
||||
return picked_next();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,4 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
Track *Queue::next()
|
||||
{
|
||||
return pick_sequential();
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -16,9 +16,4 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
Track *Set::next()
|
||||
{
|
||||
return pick_random();
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
|
@ -16,9 +16,4 @@ namespace libsaria
|
|||
{
|
||||
}
|
||||
|
||||
Track *Stack::next()
|
||||
{
|
||||
return pick_sequential();
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
Loading…
Reference in New Issue