Skip to content

Commit

Permalink
more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sapht committed Jan 15, 2012
1 parent 5f00d72 commit c69d4c8
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 209 deletions.
1 change: 1 addition & 0 deletions env_live.sh
Expand Up @@ -3,3 +3,4 @@ export SAPHTUNE_SONG_DIR="/Volumes/Audio/Workspace/songs"
export SAPHTUNE_ALBUM_DIR="/Volumes/Audio/Workspace/album"
export SAPHTUNE_GIT_SONG_DIR="/Volumes/Audio/git/songs"
export SAPHTUNE_GIT_ALBUM_DIR="/Volumes/Audio/git/album"
export SAPHTUNE_CACHE_FILE="/Volumes/Audio/Workspace/saphtunes/cache.dat"
54 changes: 53 additions & 1 deletion src/album.c
Expand Up @@ -12,19 +12,71 @@ album_create(char *root, char *name)

git_load_generic(&r->git, root, name);
r->path = r->git.path;
r->m3u_path = malloc(PATH_MAX_LEN * sizeof(char));
sprintf(r->m3u_path, "%s/%s/playlist.m3u", root, name);
r->slug = name;

/*printf("Album path is %s\n", r->path);*/

return r;
}

void
album_make_m3u(struct album *album)
{
char *buf = malloc(sizeof(char) * album->songs.len * PATH_MAX_LEN);
FILE *fp = fopen(album->m3u_path, "w");
struct song *song;
for (int i=0; i<album->songs.len; i++) {
song = album->songs.e[i];
fwrite(song->render_path, strlen(song->render_path), 1, fp);
fwrite("\n", 1, 1, fp);
}

fclose(fp);
}

void
album_list_make_m3u(struct album_list *album_list)
{
struct album *album;
for(int i=0; i<album_list->len; i++) {
album = album_list->e[i];
album_make_m3u(album);
}
}



struct song_list *
album_list_find_exclusions(
struct album_list *album_list,
struct song_list *song_list)
{
return song_list;
struct song_list orphans;
orphans.e = malloc(1024 * sizeof(void*)); /* let's say max 1024 songs... */
orphans.len = 0;

for(int i=0; i<song_list->len; i++) {
int found = 0;
for(int j=0; j<album_list->len; j++) {
for(int k=0; k<album_list->e[j]->songs.len; k++) {
if (album_list->e[j]->songs.e[k] == song_list->e[i]) {
found = 1;
}
}
}

if(!found) {
orphans.e[
orphans.len++
] = song_list->e[i];
}
}

struct song_list *retval = malloc(sizeof(orphans));
*retval = orphans;
return retval;
}

void
Expand Down
3 changes: 3 additions & 0 deletions src/album.h
Expand Up @@ -9,6 +9,7 @@
struct album {
char *slug;
char *path;
char *m3u_path;
struct git_repo git;
struct song_list songs;
};
Expand All @@ -18,6 +19,8 @@ struct album_list {
int len;
};

void album_make_m3u(struct album *album);
void album_list_make_m3u(struct album_list *album_list);
int album_load_dir(char* dir, struct album_list *album_list);
void album_list_match_songs(struct album_list *album_list, struct song_list *song_list);
struct album * album_create(char *root, char *name);
Expand Down
6 changes: 3 additions & 3 deletions src/git.c
Expand Up @@ -16,10 +16,10 @@ git_load_generic(struct git_repo *repo,
char *root,
char *name)
{
repo->path = malloc(255 * sizeof(char));
repo->path = malloc(PATH_MAX_LEN * sizeof(char));
sprintf(repo->path, "%s/%s", root, name);

repo->config_path = malloc(255 * sizeof(char));
repo->config_path = malloc(PATH_MAX_LEN * sizeof(char));
sprintf(repo->config_path, "%s/.git/config", repo->path);

repo->status = 0;
Expand Down Expand Up @@ -143,7 +143,7 @@ git_repo_fill_submodules(struct git_repo *root_repo, char **paths)

int path_num = 0;

char *submodule_dotfile_path = malloc(255);
char *submodule_dotfile_path = malloc(PATH_MAX_LEN * sizeof(char));
sprintf(submodule_dotfile_path, "%s/%s", root_repo->path, ".gitmodules");

FILE *fp = fopen(submodule_dotfile_path, "rb");
Expand Down
9 changes: 6 additions & 3 deletions src/main.c
Expand Up @@ -13,13 +13,12 @@ static int load_data() {
if ((st.p.song_dir = getenv("SAPHTUNE_SONG_DIR")) == NULL ||
(st.p.album_dir = getenv("SAPHTUNE_ALBUM_DIR")) == NULL ||
(st.p.song_git_dir = getenv("SAPHTUNE_GIT_SONG_DIR")) == NULL ||
(st.p.cache = getenv("SAPHTUNE_CACHE_FILE")) == NULL ||
(st.p.album_git_dir = getenv("SAPHTUNE_GIT_ALBUM_DIR")) == NULL) {
fprintf(stderr, "Could not load paths from env\n");
exit(1);
}

st.p.cache = "/tmp/saphtune-cache.dat";

cache_load(st.p.cache);

st.songs = malloc(sizeof(struct song_list));
Expand All @@ -32,6 +31,8 @@ static int load_data() {

printf("Matching album repos to songs...\n");
album_list_match_songs(_st.albums, _st.songs);
printf("Making album m3u...\n");
album_list_make_m3u(_st.albums);

return 1;
}
Expand All @@ -45,14 +46,16 @@ static int main_from_args(int argc, char **argv)
exit(1);
}

struct song_list*orphans = album_list_find_exclusions(
struct song_list *orphans = album_list_find_exclusions(
st.albums, st.songs
);

if (orphans->len > 0) {
for (int i=0; i<orphans->len; i++) {
printf("%s\n", orphans->e[i]->slug);
}
}

} else if (strcmp(argv[1], "analyze") == 0) {
printf("Supercool analyze finder initialized\n");
struct song_render_stat stat = song_render_analyze(argv[2]);
Expand Down
33 changes: 0 additions & 33 deletions src/ui_common.c
Expand Up @@ -16,39 +16,6 @@ song_format_duration(int duration)
return retval;
}

void
ui_fill_song_list(GtkWidget *song_list_wdg,
struct song_list *song_list)
{
GtkTreeIter song_iter;
gtk_list_store_clear(GTK_LIST_STORE(song_list_wdg));

int j, i;
for(i=0; i<song_list->len; i++) {
j=i;
if (song_list != st.songs) {
/* Find matching real id */
for(j=0; j<st.songs->len; j++) {
if(st.songs->e[j] == song_list->e[i]) { break; }
}
}

char *duration = song_format_duration(
song_list->e[i]->render_stat.duration
);

gtk_list_store_append(GTK_LIST_STORE(song_list_wdg), &song_iter);
gtk_list_store_set(GTK_LIST_STORE(song_list_wdg),
&song_iter,
0, j,
1, song_list->e[i]->slug,
2, duration,
3, song_list->e[i]->render_stat.nullspace,
4, song_list->e[i]->render_stat.clipping,
5, (0 != song_list->e[i]->git.status),
-1);
}
}

int
treesel_offset_item(
Expand Down

0 comments on commit c69d4c8

Please sign in to comment.