libsaria: Added a current_track() function
This function will generate a Track object based on the current file stored by the audio. I then pass this object to to provided function so the UI can be updated.
This commit is contained in:
parent
9997e6ffa6
commit
a975fcc2cc
|
@ -9,6 +9,7 @@ namespace libsaria
|
|||
namespace audio
|
||||
{
|
||||
void init(int, char**);
|
||||
string get_current_file();
|
||||
|
||||
/* Playback control functions */
|
||||
void load(string);
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace libsaria
|
|||
void add_path(string);
|
||||
void remove_path(string);
|
||||
void play_id(ino_t);
|
||||
void get_info(ino_t &, void(*)(Track &));
|
||||
void for_each(void (*)(Track &));
|
||||
void for_each_path(void (*)(struct PathInfo &));
|
||||
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#ifndef LIBSARIA_H
|
||||
#define LIBSARIA_H
|
||||
|
||||
#include <libsaria/track.h>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
void init(int, char **);
|
||||
void quit();
|
||||
|
||||
void current_track(void (*)(Track &));
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_H */
|
||||
|
|
|
@ -16,5 +16,6 @@ struct file
|
|||
void readdir(string, list<file> &, list<file> &);
|
||||
string get_saria_dir();
|
||||
void make_saria_dir();
|
||||
bool get_inode(string, ino_t &);
|
||||
|
||||
#endif /* LIBSARIA_PATH_H */
|
||||
|
|
|
@ -59,4 +59,9 @@ namespace libsaria
|
|||
play();
|
||||
}
|
||||
|
||||
string audio::get_current_file()
|
||||
{
|
||||
return cur_file;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
|
||||
#include <libsaria/libsaria.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/audio.h>
|
||||
#include <libsaria/path.h>
|
||||
|
||||
static int current_inode(ino_t &inode)
|
||||
{
|
||||
string file = libsaria::audio::get_current_file();
|
||||
if (file == "")
|
||||
return false;
|
||||
return get_inode(file, inode);
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
void current_track(void (*func)(Track &))
|
||||
{
|
||||
ino_t inode;
|
||||
/* TODO: Set to blank in error cases */
|
||||
if (current_inode(inode) < 0)
|
||||
return;
|
||||
library::get_info(inode, func);
|
||||
}
|
||||
|
||||
};
|
|
@ -42,7 +42,19 @@ void LibraryPath::get_info(void (*info_func)(struct libsaria::library::PathInfo
|
|||
info_func(info);
|
||||
}
|
||||
|
||||
bool LibraryPath::play_id(ino_t id)
|
||||
bool LibraryPath::get_info_id(ino_t &id, void (*func)(Track &))
|
||||
{
|
||||
map<ino_t, TrackTag>::iterator it;
|
||||
it = file_map.find(id);
|
||||
if (it != file_map.end()) {
|
||||
Track track = Track(it->first, &it->second);
|
||||
func(track);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LibraryPath::play_id(ino_t &id)
|
||||
{
|
||||
map<ino_t, TrackTag>::iterator it;
|
||||
it = file_map.find(id);
|
||||
|
@ -85,6 +97,15 @@ namespace libsaria
|
|||
}
|
||||
}
|
||||
|
||||
void library::get_info(ino_t &id, void (*func)(Track &))
|
||||
{
|
||||
map<string, LibraryPath>::iterator it;
|
||||
for (it = path_map.begin(); it != path_map.end(); it++) {
|
||||
if (it->second.get_info_id(id, func) == true)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int library::size()
|
||||
{
|
||||
unsigned int size = 0;
|
||||
|
|
|
@ -21,6 +21,7 @@ class LibraryPath
|
|||
|
||||
void for_each(void (*)(Track &));
|
||||
void get_info(void (*)(struct libsaria::library::PathInfo &));
|
||||
bool get_info_id(ino_t &, void (*)(Track &));
|
||||
void insert_track(ino_t, TrackTag &);
|
||||
bool play_id(ino_t);
|
||||
void save(OutFile &);
|
||||
|
|
|
@ -73,3 +73,15 @@ void make_saria_dir()
|
|||
mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
|
||||
mkdir(saria.c_str(), mode);
|
||||
}
|
||||
|
||||
bool get_inode(string filepath, ino_t &ino)
|
||||
{
|
||||
int err;
|
||||
struct stat stat;
|
||||
|
||||
err = lstat(filepath.c_str(), &stat);
|
||||
if (err != 0)
|
||||
return false;
|
||||
ino = stat.st_ino;
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue