From 5ae5a349de59e8be8b27971da5cf5ee1da9d6394 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sun, 6 Nov 2011 13:13:45 -0500 Subject: [PATCH] libsaria: Play tracks from the play_list Rather than finding the id in the LibraryPath lists, I instead find it in the play_list list and store an iterator to this track. --- libsaria/library/library.cpp | 9 --------- libsaria/library/list.cpp | 23 ++++++++++++++++++++++- libsaria/library/path.cpp | 11 ----------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/libsaria/library/library.cpp b/libsaria/library/library.cpp index 5ab07339..102509ad 100644 --- a/libsaria/library/library.cpp +++ b/libsaria/library/library.cpp @@ -41,15 +41,6 @@ namespace libsaria it->update(); } - void library::play_id(ino_t &id) - { - list::iterator it; - for (it = path_list.begin(); it != path_list.end(); it++) { - if (it->play_id(id) == true) - break; - } - } - bool library::get_info(ino_t &id, void (*func)(Track &)) { bool found = false; diff --git a/libsaria/library/list.cpp b/libsaria/library/list.cpp index b135fcdf..a727c7e6 100644 --- a/libsaria/library/list.cpp +++ b/libsaria/library/list.cpp @@ -2,9 +2,21 @@ #include using namespace std; +#include +#include #include "library.h" static list play_list; +static list::iterator cur_track = play_list.end(); + +static bool find_id(ino_t &inode, list::iterator &it) +{ + for (it = play_list.begin(); it != play_list.end(); it++) { + if (it->get_inode() == inode) + return true; + } + return false; +} namespace libsaria { @@ -14,6 +26,7 @@ namespace libsaria list *path_list = get_path_list(); list::iterator it; list *tag_list; + list::iterator i; play_list.clear(); @@ -21,7 +34,6 @@ namespace libsaria tag_list = it->get_list(); play_list.insert(play_list.end(), tag_list->begin(), tag_list->end()); } - println("Rebuilding play list"); } void library::for_each(SourceModel *model) @@ -33,6 +45,15 @@ namespace libsaria } } + void library::play_id(ino_t &id) + { + list::iterator it; + if (find_id(id, it)) { + cur_track = it; + libsaria::audio::load(it->get_filepath()); + } + } + unsigned int library::size() { return play_list.size(); diff --git a/libsaria/library/path.cpp b/libsaria/library/path.cpp index 77969d64..40577db1 100644 --- a/libsaria/library/path.cpp +++ b/libsaria/library/path.cpp @@ -2,7 +2,6 @@ #include using namespace std; -#include #include #include "library.h" @@ -46,16 +45,6 @@ bool LibraryPath::get_info_id(ino_t &id, void (*func)(Track &)) return false; } -bool LibraryPath::play_id(ino_t &id) -{ - list::iterator it; - it = find_id(id); - if (it == file_list.end()) - return false; - libsaria::audio::load(it->get_filepath()); - return true; -} - LibraryPath::LibraryPath(string dir) { path = dir;