libsaria: New current_track() function
Instead of taking a callback function, I instead find a pointer to the current track and return this to the caller.
This commit is contained in:
parent
0ef8e44207
commit
4dac0fe096
|
@ -8,7 +8,7 @@ namespace libsaria
|
|||
void init(int, char **);
|
||||
void quit();
|
||||
|
||||
void current_track(void (*)(Track *));
|
||||
libsaria::Track *current_track();
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_H */
|
||||
|
|
|
@ -17,6 +17,6 @@ struct file
|
|||
|
||||
string get_saria_dir();
|
||||
void make_saria_dir();
|
||||
bool get_inode(string, sid_t &);
|
||||
sid_t lookup_songid(string &);
|
||||
|
||||
#endif /* LIBSARIA_PATH_H */
|
||||
|
|
|
@ -4,27 +4,28 @@
|
|||
#include <libsaria/audio.h>
|
||||
#include <libsaria/path.h>
|
||||
|
||||
static int current_inode(sid_t &inode)
|
||||
{
|
||||
string file = libsaria::audio::get_current_file();
|
||||
if (file == "")
|
||||
return false;
|
||||
return get_inode(file, inode);
|
||||
}
|
||||
static libsaria::Track tmp_track;
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void current_track(void (*func)(Track *))
|
||||
libsaria::Track *current_track()
|
||||
{
|
||||
sid_t inode;
|
||||
Track blank, *current;
|
||||
sid_t songid;
|
||||
libsaria::Track *current;
|
||||
string file = libsaria::audio::get_current_file();
|
||||
|
||||
if (current_inode(inode) < 0)
|
||||
current = ␣
|
||||
else
|
||||
current = libsaria::library::get_info(inode);
|
||||
func(current);
|
||||
if (file == "")
|
||||
return NULL;
|
||||
|
||||
songid = lookup_songid(file);
|
||||
current = libsaria::library::get_info(songid);
|
||||
if (current)
|
||||
return current;
|
||||
|
||||
tmp_track = libsaria::Track(file, songid);
|
||||
tmp_track.do_cleanup();
|
||||
return &tmp_track;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -40,14 +40,11 @@ void make_saria_dir()
|
|||
mkdir(saria.c_str(), mode);
|
||||
}
|
||||
|
||||
bool get_inode(string filepath, sid_t &ino)
|
||||
sid_t lookup_songid(string &filepath)
|
||||
{
|
||||
int err;
|
||||
struct stat stat;
|
||||
|
||||
err = lstat(filepath.c_str(), &stat);
|
||||
int err = lstat(filepath.c_str(), &stat);
|
||||
if (err != 0)
|
||||
return false;
|
||||
ino = stat.st_ino;
|
||||
return true;
|
||||
return stat.st_ino;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue