diff --git a/include/group.h b/include/group.h deleted file mode 100644 index 9c49eaa4..00000000 --- a/include/group.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2013 (c) Anna Schumaker. - */ -#ifndef OCARINA_GROUP_H -#define OCARINA_GROUP_H - -#include -#include -#include - -namespace group -{ - - void add(const std::string &, unsigned int); - void del(const std::string &, unsigned int); - void list(std::list &); - const std::set &get_tracks(const std::string &); - -}; - -#endif /* OCARINA_GROUP_H */ diff --git a/include/playlist.h b/include/playlist.h index 99ca519f..9c49eaa4 100644 --- a/include/playlist.h +++ b/include/playlist.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 -#include +#include +#include +#include + +namespace group +{ + + void add(const std::string &, unsigned int); + void del(const std::string &, unsigned int); + void list(std::list &); + const std::set &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 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 */ diff --git a/include/playqueue.h b/include/playqueue.h new file mode 100644 index 00000000..99ca519f --- /dev/null +++ b/include/playqueue.h @@ -0,0 +1,40 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#ifndef OCARINA_PLAYLIST_H +#define OCARINA_PLAYLIST_H + +#include +#include + +enum playlist_flags { + PL_ENABLED = (1 << 0), + PL_RANDOM = (1 << 1), + PL_LOCKED = (1 << 2), +}; + +class Playlist { +private: + std :: vector 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 */ diff --git a/lib/Sconscript b/lib/Sconscript index 564aa329..097a7c66 100644 --- a/lib/Sconscript +++ b/lib/Sconscript @@ -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" ]), ########################### ########################### diff --git a/lib/group.cpp b/lib/group.cpp deleted file mode 100644 index c11e6c98..00000000 --- a/lib/group.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013 (c) Anna Schumaker. - */ -#include -#include - -static std::set empty_set; -Database 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 &res) -{ - res.push_back("All Music"); - res.push_back("Library"); - res.push_back("Banned"); -} - -const std::set &group :: get_tracks(const std::string &name) -{ - try { - return group_index.find(name).values; - } catch (...) { - return empty_set; - } -} diff --git a/lib/playlist.cpp b/lib/playlist.cpp index 26f1254b..c11e6c98 100644 --- a/lib/playlist.cpp +++ b/lib/playlist.cpp @@ -1,88 +1,46 @@ /* * Copyright 2013 (c) Anna Schumaker. */ -#include -#include +#include +#include -Playlist :: Playlist() - : flags(0), cur(-1) +static std::set empty_set; +Database 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 &res) +{ + res.push_back("All Music"); + res.push_back("Library"); + res.push_back("Banned"); +} + +const std::set &group :: get_tracks(const std::string &name) +{ + try { + return group_index.find(name).values; + } catch (...) { + return empty_set; } - return res; } diff --git a/lib/playqueue.cpp b/lib/playqueue.cpp new file mode 100644 index 00000000..26f1254b --- /dev/null +++ b/lib/playqueue.cpp @@ -0,0 +1,88 @@ +/* + * Copyright 2013 (c) Anna Schumaker. + */ +#include +#include + +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; +} diff --git a/tests/group/Sconscript b/tests/group/Sconscript deleted file mode 100644 index bf58917a..00000000 --- a/tests/group/Sconscript +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/python -Import("Test", "CONFIG") - -CONFIG.GROUP = True - -Test("group", "group.cpp") diff --git a/tests/playlist/Sconscript b/tests/playlist/Sconscript index 4c0ff2c3..bf58917a 100644 --- a/tests/playlist/Sconscript +++ b/tests/playlist/Sconscript @@ -1,6 +1,6 @@ #!/usr/bin/python Import("Test", "CONFIG") -CONFIG.PLAYLIST = True +CONFIG.GROUP = True -Test("playlist", "playlist.cpp") +Test("group", "group.cpp") diff --git a/tests/group/group.cpp b/tests/playlist/group.cpp similarity index 100% rename from tests/group/group.cpp rename to tests/playlist/group.cpp diff --git a/tests/group/group.good b/tests/playlist/group.good similarity index 100% rename from tests/group/group.good rename to tests/playlist/group.good diff --git a/tests/playqueue/Sconscript b/tests/playqueue/Sconscript new file mode 100644 index 00000000..4c0ff2c3 --- /dev/null +++ b/tests/playqueue/Sconscript @@ -0,0 +1,6 @@ +#!/usr/bin/python +Import("Test", "CONFIG") + +CONFIG.PLAYLIST = True + +Test("playlist", "playlist.cpp") diff --git a/tests/playlist/playlist.cpp b/tests/playqueue/playlist.cpp similarity index 100% rename from tests/playlist/playlist.cpp rename to tests/playqueue/playlist.cpp diff --git a/tests/playlist/playlist.good b/tests/playqueue/playlist.good similarity index 100% rename from tests/playlist/playlist.good rename to tests/playqueue/playlist.good