From 9e411c8fe5f3a7b507bca0c4e132454d7d57650c Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 27 Dec 2010 01:14:27 +0100 Subject: Initial commit. --- .gitignore | 10 ++++++++++ SConstruct | 16 ++++++++++++++++ main.cpp | 12 ++++++++++++ music.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ music.h | 30 ++++++++++++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 .gitignore create mode 100644 SConstruct create mode 100644 main.cpp create mode 100644 music.cpp create mode 100644 music.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2fa971 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.swp +*.o +*.conf +*.sock +*.vim +/audistd +.sconf_temp +.sconsign.dblite +.sconf_temp +config.log diff --git a/SConstruct b/SConstruct new file mode 100644 index 0000000..325abe5 --- /dev/null +++ b/SConstruct @@ -0,0 +1,16 @@ +AddOption('--release', action = 'store_true') + +env = Environment(CPPPATH = ['.'], CCFLAGS = ['-pthread'], LINKFLAGS = ['-pthread']) + +conf = Configure(env) +conf.CheckLib('boost_system') +env = conf.Finish() + +if GetOption('release'): + env.Append(CCFLAGS = ['-O2']) +else: + env.Append(CCFLAGS = ['-Wall', '-g']) + +env.Program('audistd', Glob('*.cpp')) + +# vim: syn=python diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..55c1de0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,12 @@ +#include +#include "music.h" + +int main(int argc, char **argv) { + try { + music::init(argv[1]); + } catch(std::exception& e) { + std::cerr << e.what() << std::endl; + } + + return 0; +} diff --git a/music.cpp b/music.cpp new file mode 100644 index 0000000..bd50719 --- /dev/null +++ b/music.cpp @@ -0,0 +1,44 @@ +#include "music.h" + +#include +#include +#include +#include +#include +#include + +namespace music { + +MusicDirectory *root_directory = NULL; + +void init(const std::string root) { + root_directory = new MusicDirectory(root); +} + +}; + +MusicTrack::MusicTrack(const std::string filename) { + printf("%s\n", filename.c_str()); + this->filename = filename; +} + +MusicDirectory::MusicDirectory(const std::string root) { + printf("%s\n", root.c_str()); + + DIR *d = opendir(root.c_str()); + if(!d) { + throw std::runtime_error(strerror(errno)); + } + + struct dirent *dir; + while((dir = readdir(d)) != NULL) { + if(strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue; + if(dir->d_type == DT_DIR) { + directories.push_back(MusicDirectory(root + "/" + dir->d_name)); + } else if(dir->d_type == DT_REG) { + tracks.push_back(MusicTrack(root + "/" + dir->d_name)); + } + } + + closedir(d); +} diff --git a/music.h b/music.h new file mode 100644 index 0000000..8e0bd9e --- /dev/null +++ b/music.h @@ -0,0 +1,30 @@ +#ifndef MUSIC_H +#define MUSIC_H + +#include +#include + +class MusicTrack { + public: + MusicTrack(const std::string filename); + std::string filename; +}; + +class MusicDirectory; +typedef std::vector MusicDirectories; +typedef std::vector MusicTracks; + +class MusicDirectory { + public: + MusicDirectory(const std::string root); + std::string path; + MusicDirectories directories; + MusicTracks tracks; +}; + +namespace music { + extern MusicDirectory *root_directory; + void init(const std::string root); +}; + +#endif -- cgit v1.2.3