Rename playlist and group source files
Playlist -> playqueue Group -> playlist Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
parent
ee100c0238
commit
914473e10a
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_GROUP_H
|
||||
#define OCARINA_GROUP_H
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace group
|
||||
{
|
||||
|
||||
void add(const std::string &, unsigned int);
|
||||
void del(const std::string &, unsigned int);
|
||||
void list(std::list<std::string> &);
|
||||
const std::set<unsigned int> &get_tracks(const std::string &);
|
||||
|
||||
};
|
||||
|
||||
#endif /* OCARINA_GROUP_H */
|
|
@ -1,40 +1,21 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_PLAYLIST_H
|
||||
#define OCARINA_PLAYLIST_H
|
||||
#ifndef OCARINA_GROUP_H
|
||||
#define OCARINA_GROUP_H
|
||||
|
||||
#include <file.h>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace group
|
||||
{
|
||||
|
||||
void add(const std::string &, unsigned int);
|
||||
void del(const std::string &, unsigned int);
|
||||
void list(std::list<std::string> &);
|
||||
const std::set<unsigned int> &get_tracks(const std::string &);
|
||||
|
||||
enum playlist_flags {
|
||||
PL_ENABLED = (1 << 0),
|
||||
PL_RANDOM = (1 << 1),
|
||||
PL_LOCKED = (1 << 2),
|
||||
};
|
||||
|
||||
class Playlist {
|
||||
private:
|
||||
std :: vector <unsigned int> tracks;
|
||||
unsigned int flags;
|
||||
unsigned int cur;
|
||||
|
||||
public:
|
||||
Playlist();
|
||||
Playlist(playlist_flags);
|
||||
~Playlist();
|
||||
void write(File &);
|
||||
void read(File &);
|
||||
|
||||
void set_flag(playlist_flags);
|
||||
void unset_flag(playlist_flags);
|
||||
const unsigned int get_flags();
|
||||
|
||||
unsigned int add(unsigned int);
|
||||
void del(unsigned int);
|
||||
unsigned int size();
|
||||
|
||||
unsigned int next();
|
||||
};
|
||||
|
||||
#endif /* OCARINA_PLAYLIST_H */
|
||||
#endif /* OCARINA_GROUP_H */
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_PLAYLIST_H
|
||||
#define OCARINA_PLAYLIST_H
|
||||
|
||||
#include <file.h>
|
||||
#include <vector>
|
||||
|
||||
enum playlist_flags {
|
||||
PL_ENABLED = (1 << 0),
|
||||
PL_RANDOM = (1 << 1),
|
||||
PL_LOCKED = (1 << 2),
|
||||
};
|
||||
|
||||
class Playlist {
|
||||
private:
|
||||
std :: vector <unsigned int> tracks;
|
||||
unsigned int flags;
|
||||
unsigned int cur;
|
||||
|
||||
public:
|
||||
Playlist();
|
||||
Playlist(playlist_flags);
|
||||
~Playlist();
|
||||
void write(File &);
|
||||
void read(File &);
|
||||
|
||||
void set_flag(playlist_flags);
|
||||
void unset_flag(playlist_flags);
|
||||
const unsigned int get_flags();
|
||||
|
||||
unsigned int add(unsigned int);
|
||||
void del(unsigned int);
|
||||
unsigned int size();
|
||||
|
||||
unsigned int next();
|
||||
};
|
||||
|
||||
#endif /* OCARINA_PLAYLIST_H */
|
|
@ -15,15 +15,15 @@ modules = {
|
|||
# #
|
||||
###########################
|
||||
|
||||
"AUDIO" : Module("audio.cpp", package = "gstreamer-1.0", depends = [ "DECK", "LIBRARY" ]),
|
||||
"DATABASE" : Module("database.cpp", depends = [ "FILE" ]),
|
||||
"DECK" : Module("deck.cpp", depends = [ "PLAYLIST" ]),
|
||||
"FILE" : Module("file.cpp", package = "glib-2.0"),
|
||||
"FILTER" : Module("filter.cpp", depends = [ "DATABASE" ]),
|
||||
"GROUP" : Module("group.cpp", depends = [ "DATABASE" ]),
|
||||
"IDLE" : Module("idle.cpp"),
|
||||
"LIBRARY" : Module("library.cpp", package = "taglib", depends = [ "DATABASE", "IDLE" ]),
|
||||
"PLAYLIST" : Module("playlist.cpp", depends = [ "FILE" ]),
|
||||
"AUDIO" : Module("audio.cpp", package = "gstreamer-1.0", depends = [ "DECK", "LIBRARY" ]),
|
||||
"DATABASE" : Module("database.cpp", depends = [ "FILE" ]),
|
||||
"DECK" : Module("deck.cpp", depends = [ "PLAYQUEUE" ]),
|
||||
"FILE" : Module("file.cpp", package = "glib-2.0"),
|
||||
"FILTER" : Module("filter.cpp", depends = [ "DATABASE" ]),
|
||||
"PLAYLIST" : Module("playlist.cpp", depends = [ "DATABASE" ]),
|
||||
"IDLE" : Module("idle.cpp"),
|
||||
"LIBRARY" : Module("library.cpp", package = "taglib", depends = [ "DATABASE", "IDLE" ]),
|
||||
"PLAYQUEUE" : Module("playlist.cpp", depends = [ "FILE" ]),
|
||||
|
||||
###########################
|
||||
###########################
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <database.h>
|
||||
#include <group.h>
|
||||
|
||||
static std::set<unsigned int> empty_set;
|
||||
Database<IndexEntry, const std::string> group_index("");
|
||||
|
||||
void group :: add(const std::string &name, unsigned int track_id)
|
||||
{
|
||||
if ((name == "All Music") || (name == "Library") || (name == "Banned")) {
|
||||
try {
|
||||
index_insert(group_index, name, track_id);
|
||||
} catch (...) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void group :: del(const std::string &name, unsigned int track_id)
|
||||
{
|
||||
if ((name == "All Music") || (name == "Library") || (name == "Banned")) {
|
||||
try {
|
||||
index_remove(group_index, name, track_id);
|
||||
} catch (...) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void group :: list(std::list<std::string> &res)
|
||||
{
|
||||
res.push_back("All Music");
|
||||
res.push_back("Library");
|
||||
res.push_back("Banned");
|
||||
}
|
||||
|
||||
const std::set<unsigned int> &group :: get_tracks(const std::string &name)
|
||||
{
|
||||
try {
|
||||
return group_index.find(name).values;
|
||||
} catch (...) {
|
||||
return empty_set;
|
||||
}
|
||||
}
|
120
lib/playlist.cpp
120
lib/playlist.cpp
|
@ -1,88 +1,46 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <playlist.h>
|
||||
#include <stdlib.h>
|
||||
#include <database.h>
|
||||
#include <group.h>
|
||||
|
||||
Playlist :: Playlist()
|
||||
: flags(0), cur(-1)
|
||||
static std::set<unsigned int> empty_set;
|
||||
Database<IndexEntry, const std::string> group_index("");
|
||||
|
||||
void group :: add(const std::string &name, unsigned int track_id)
|
||||
{
|
||||
}
|
||||
|
||||
Playlist :: Playlist(playlist_flags f)
|
||||
: flags(f), cur(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Playlist :: ~Playlist()
|
||||
{
|
||||
}
|
||||
|
||||
void Playlist :: write(File &f)
|
||||
{
|
||||
f << flags << " " << tracks.size();
|
||||
for (unsigned int i = 0; i < tracks.size(); i++)
|
||||
f << " " << tracks[i];
|
||||
}
|
||||
|
||||
void Playlist :: read(File &f)
|
||||
{
|
||||
unsigned int n;
|
||||
f >> flags >> n;
|
||||
tracks.resize(n);
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
f >> tracks[i];
|
||||
}
|
||||
|
||||
void Playlist :: set_flag(playlist_flags f)
|
||||
{
|
||||
flags |= f;
|
||||
}
|
||||
|
||||
void Playlist :: unset_flag(playlist_flags f)
|
||||
{
|
||||
flags &= ~f;
|
||||
}
|
||||
|
||||
const unsigned int Playlist :: get_flags()
|
||||
{
|
||||
return flags;
|
||||
}
|
||||
|
||||
unsigned int Playlist :: add(unsigned int track_id)
|
||||
{
|
||||
tracks.push_back(track_id);
|
||||
return tracks.size() - 1;
|
||||
}
|
||||
|
||||
void Playlist :: del(unsigned int plist_id)
|
||||
{
|
||||
tracks.erase(tracks.begin() + plist_id);
|
||||
}
|
||||
|
||||
unsigned int Playlist :: size()
|
||||
{
|
||||
return tracks.size();
|
||||
}
|
||||
|
||||
unsigned int Playlist :: next()
|
||||
{
|
||||
unsigned int res;
|
||||
|
||||
if (tracks.size() == 1)
|
||||
cur = 0;
|
||||
else if (flags & PL_RANDOM)
|
||||
cur += rand() % (tracks.size() / 2) + 1;
|
||||
else
|
||||
cur++;
|
||||
|
||||
if (cur >= tracks.size())
|
||||
cur -= tracks.size();
|
||||
|
||||
res = tracks[cur];
|
||||
if (!(flags & PL_LOCKED)) {
|
||||
tracks.erase(tracks.begin() + cur);
|
||||
cur--;
|
||||
if ((name == "All Music") || (name == "Library") || (name == "Banned")) {
|
||||
try {
|
||||
index_insert(group_index, name, track_id);
|
||||
} catch (...) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void group :: del(const std::string &name, unsigned int track_id)
|
||||
{
|
||||
if ((name == "All Music") || (name == "Library") || (name == "Banned")) {
|
||||
try {
|
||||
index_remove(group_index, name, track_id);
|
||||
} catch (...) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void group :: list(std::list<std::string> &res)
|
||||
{
|
||||
res.push_back("All Music");
|
||||
res.push_back("Library");
|
||||
res.push_back("Banned");
|
||||
}
|
||||
|
||||
const std::set<unsigned int> &group :: get_tracks(const std::string &name)
|
||||
{
|
||||
try {
|
||||
return group_index.find(name).values;
|
||||
} catch (...) {
|
||||
return empty_set;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2013 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <playlist.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
Playlist :: Playlist()
|
||||
: flags(0), cur(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Playlist :: Playlist(playlist_flags f)
|
||||
: flags(f), cur(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Playlist :: ~Playlist()
|
||||
{
|
||||
}
|
||||
|
||||
void Playlist :: write(File &f)
|
||||
{
|
||||
f << flags << " " << tracks.size();
|
||||
for (unsigned int i = 0; i < tracks.size(); i++)
|
||||
f << " " << tracks[i];
|
||||
}
|
||||
|
||||
void Playlist :: read(File &f)
|
||||
{
|
||||
unsigned int n;
|
||||
f >> flags >> n;
|
||||
tracks.resize(n);
|
||||
for (unsigned int i = 0; i < n; i++)
|
||||
f >> tracks[i];
|
||||
}
|
||||
|
||||
void Playlist :: set_flag(playlist_flags f)
|
||||
{
|
||||
flags |= f;
|
||||
}
|
||||
|
||||
void Playlist :: unset_flag(playlist_flags f)
|
||||
{
|
||||
flags &= ~f;
|
||||
}
|
||||
|
||||
const unsigned int Playlist :: get_flags()
|
||||
{
|
||||
return flags;
|
||||
}
|
||||
|
||||
unsigned int Playlist :: add(unsigned int track_id)
|
||||
{
|
||||
tracks.push_back(track_id);
|
||||
return tracks.size() - 1;
|
||||
}
|
||||
|
||||
void Playlist :: del(unsigned int plist_id)
|
||||
{
|
||||
tracks.erase(tracks.begin() + plist_id);
|
||||
}
|
||||
|
||||
unsigned int Playlist :: size()
|
||||
{
|
||||
return tracks.size();
|
||||
}
|
||||
|
||||
unsigned int Playlist :: next()
|
||||
{
|
||||
unsigned int res;
|
||||
|
||||
if (tracks.size() == 1)
|
||||
cur = 0;
|
||||
else if (flags & PL_RANDOM)
|
||||
cur += rand() % (tracks.size() / 2) + 1;
|
||||
else
|
||||
cur++;
|
||||
|
||||
if (cur >= tracks.size())
|
||||
cur -= tracks.size();
|
||||
|
||||
res = tracks[cur];
|
||||
if (!(flags & PL_LOCKED)) {
|
||||
tracks.erase(tracks.begin() + cur);
|
||||
cur--;
|
||||
}
|
||||
return res;
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
#!/usr/bin/python
|
||||
Import("Test", "CONFIG")
|
||||
|
||||
CONFIG.GROUP = True
|
||||
|
||||
Test("group", "group.cpp")
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
Import("Test", "CONFIG")
|
||||
|
||||
CONFIG.PLAYLIST = True
|
||||
CONFIG.GROUP = True
|
||||
|
||||
Test("playlist", "playlist.cpp")
|
||||
Test("group", "group.cpp")
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
Import("Test", "CONFIG")
|
||||
|
||||
CONFIG.PLAYLIST = True
|
||||
|
||||
Test("playlist", "playlist.cpp")
|
Loading…
Reference in New Issue