group: Implement basic groups support

I only handle the "All Music", "Library" and "Banned" groups at the
moment but I'll eventually add in more features (in future versions).

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-08-28 20:56:55 -04:00 committed by Anna Schumaker
parent c5f6716144
commit 7b7414c755
9 changed files with 181 additions and 11 deletions

3
config
View File

@ -27,6 +27,7 @@ class Config:
self.DATABASE = False
self.FILE = False
self.FILTER = False
self.GROUP = False
self.INDEX = False
self.TEST = False
@ -38,6 +39,7 @@ class Config:
if self.DATABASE: env.Append( CCFLAGS = [ "-DCONFIG_DATABASE" ])
if self.FILE: env.Append( CCFLAGS = [ "-DCONFIG_FILE" ])
if self.FILTER: env.Append( CCFLAGS = [ "-DCONFIG_FILTER" ])
if self.GROUP: env.Append( CCFLAGS = [ "-DCONFIG_GROUP" ])
if self.INDEX: env.Append( CCFLAGS = [ "-DCONFIG_INDEX" ])
if self.TEST: env.Append( CCFLAGS = [ "-DCONFIG_TEST" ])
@ -45,6 +47,7 @@ class Config:
self.DATABASE = False
self.FILE = False
self.FILTER = False
self.GROUP = False
self.INDEX = False
self.TEST = False
self.reconfigure()

View File

@ -15,8 +15,11 @@ Groups: (lib/group.cpp)
that cannot be deleted by the user based on library status. Similar
to the library, groups should exist in their own namespace.
In Ocarina 6.0, groups are a wrapper around a specific index. Future
releases will store user-defined groups in a file on disk.
- Index:
Index group_idx(groups.idx)
Index group_idx()
- Default groups:
All music
@ -27,13 +30,11 @@ Groups: (lib/group.cpp)
in the Library or the Banned Songs group
- API
group :: init();
Initialize the index
group :: list();
return group_idx.keys();
group :: get_tracks(name):
return group_idx[name]
group :: add(name, track_id)
void group :: add(name, track_id)
group_idx.insert(name, track_id);
group :: del(name, track_id)
void group :: del(name, track_id)
grou_idx.delete(name, track_id)
void void group :: list(list<string> &);
return group_idx.keys();
void group :: get_tracks(name):
return group_idx[name]

View File

@ -65,13 +65,14 @@ Library: (lib/library.cpp)
short last_day;
unsigned int play_count;
unsigned int length;
bool banned;
string title;
string length_str;
string filepath;
};
File << artist_id << album_id << genre_id << library_id << track << last_year
File << last_year << last_month << last_day << play_count << length << endl
File << last_year << last_month << last_day << play_count << length << banned << endl
File << title << endl;
File << filepath << endl;
@ -112,6 +113,12 @@ Library: (lib/library.cpp)
This way the user will still be able to use Ocarina and scanning can
happen while idle.
- Testing:
A test library should be created to test adding tags and anything else.
The command `arecord -d 10 </dev/zero | lame - -b 32 -h silence.mp3`
will create a 10 second long, silent mp3 file. Do something with this
command and figure out how to apply tags!
- API
library :: init();
Initialize all databases

21
include/group.h Normal file
View File

@ -0,0 +1,21 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#ifndef OCARINA_GROUP_H
#define OCARINA_GROUP_H
#include <list>
#include <set>
#include <string>
namespace group
{
void add(const std::string &, unsigned int);
void del(const std::string &, unsigned int);
void list(std::list<std::string> &);
const std::set<unsigned int> &get_tracks(const std::string &);
};
#endif /* OCARINA_GROUP_H */

View File

@ -7,6 +7,10 @@ if CONFIG.FILTER:
CONFIG.INDEX = True
build += [ env.Object("filter.cpp") ]
if CONFIG.GROUP:
CONFIG.INDEX = True
build += [ env.Object("group.cpp") ]
####################
if CONFIG.DATABASE:

31
lib/group.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <group.h>
#include <index.h>
Index group_index("");
void group :: add(const std::string &name, unsigned int track_id)
{
if ((name == "All Music") || (name == "Library") || (name == "Banned"))
group_index.insert(name, track_id);
}
void group :: del(const std::string &name, unsigned int track_id)
{
if ((name == "All Music") || (name == "Library") || (name == "Banned"))
group_index.remove(name, track_id);
}
void group :: list(std::list<std::string> &res)
{
res.push_back("All Music");
res.push_back("Library");
res.push_back("Banned");
}
const std::set<unsigned int> &group :: get_tracks(const std::string &name)
{
return group_index[name];
}

View File

@ -43,7 +43,7 @@ Export("Test")
# Read SConscript files
scripts = [ "basic", "database", "file", "filter", "index" ]
scripts = [ "basic", "database", "file", "filter", "group", "index" ]
for s in scripts:
CONFIG.reset()
CONFIG.TEST = True

6
tests/group/Sconscript Normal file
View File

@ -0,0 +1,6 @@
#!/usr/bin/python
Import("Test", "CONFIG")
CONFIG.GROUP = True
Test("group", "group.cpp")

97
tests/group/group.cpp Normal file
View File

@ -0,0 +1,97 @@
/*
* Copyright 2013 (c) Anna Schumaker.
*/
#include <group.h>
#include <print.h>
void list_tracks(const std::string &name)
{
std::set<unsigned int> tracks = group :: get_tracks(name);
std::set<unsigned int>::iterator it;
print("Group \"%s\": ", name.c_str());
for (it = tracks.begin(); it != tracks.end(); it++) {
if (it != tracks.begin())
print(", ");
print("%u", *it);
}
print("\n");
}
/*
* Add songs to different groups
*/
void test_0()
{
for (unsigned int i = 0; i < 128; i++) {
group :: add("All Music", i);
if (i % 3 == 0)
group :: add("Banned", i);
else
group :: add("Library", i);
}
}
/*
* Find group names
*/
void test_1()
{
std::list<std::string> groups;
std::list<std::string>::iterator it;
group :: list(groups);
for (it = groups.begin(); it != groups.end(); it++)
print("Found group: %s\n", it->c_str());
print("\n");
}
/*
* Find tracks in a group
*/
void test_2()
{
list_tracks("All Music");
list_tracks("Library");
list_tracks("Banned");
}
/*
* Delete tracks from a group
*/
void test_3()
{
print("\n");
for (unsigned int i = 0; i < 30; i+=3)
group :: del("Banned", i);
list_tracks("Banned");
}
/*
* Do stuff with groups that don't exist
*/
void test_4()
{
print("\n");
for (unsigned int i = 0; i < 10; i++)
group :: add("No Group", i);
list_tracks("No Group");
for (unsigned int i = 0; i < 10; i+=2)
group :: del("No Group", i);
list_tracks("No Group");
}
int main(int argc, char **argv)
{
test_0();
test_1();
test_2();
test_3();
test_4();
return 0;
}