ref: 1e053787ab15808cdd927592f7310f4bd8123308
parent: 140b16cb7ae7c8dbe6c28f196e4dad10dc6890dc
author: Jacob Moody <jsmoody@iastate.edu>
date: Tue Sep 24 11:46:06 EDT 2019
Parse tracknumber for FLAC files Sort songs in an album based on track number bug fix for parsing empty dirs
--- a/dir.c
+++ b/dir.c
@@ -62,7 +62,50 @@
return nil;
}
-void
+int
+songcmp(void *a, void *b)
+{
+ Song *s1 = *((Song**)a);
+ Song *s2 = *((Song**)b);
+ int t1, t2;
+ t1 = t2 = 0;
+
+ //ID3 does not hold tracknumber so we assume all are equal
+ if(s1->type == MP3 || s2->type == MP3)
+ return 0;
+
+ switch(s1->type){
+ case FLAC:
+ t1 = s1->fmeta->com->tracknumber;
+ break;
+ case VORBIS:
+ t1 = s1->vmeta->tracknumber;
+ break;
+ default:
+ sysfatal("bad type in songcmp");
+ }
+
+ switch(s2->type){
+ case FLAC:
+ t2 = s2->fmeta->com->tracknumber;
+ break;
+ case VORBIS:
+ t2 = s2->vmeta->tracknumber;
+ break;
+ default:
+ sysfatal("bad type in songcmp");
+ }
+
+ if(t1 < t2)
+ return -1;
+
+ if(t1 > t2)
+ return 1;
+
+ return 0;
+}
+
+int
dir2album(Album *a, char *path)
{
Dir *files;
@@ -77,12 +120,12 @@
fd = open(path, OREAD);
if(fd < 0)
- return;
+ return 0;
n = dirreadall(fd, &files);
close(fd);
if(n <= 0)
- return;
+ return 0;
/* Do a single pass to find cover.^(jp^(eg g) png) */
for(i=0;i<n;i++){
@@ -148,8 +191,10 @@
a->nsong = songcount;
a->songs = realloc(a->songs, sizeof(Song*) * songcount);
+ qsort(a->songs, songcount, sizeof(Song*), songcmp);
+
free(files);
- return;
+ return 1;
}
int
@@ -180,7 +225,7 @@
if(files[i].qid.type&QTDIR){
snprint(buf, 512, "%s/%s", path, files[i].name);
dir2album(*als+alcount, buf);
- if(*als+alcount != nil)
+ if(dir2album(*als+alcount, buf))
alcount++;
}
--- a/fncs.h
+++ b/fncs.h
@@ -30,5 +30,4 @@
void drawvolume(int, Image*);
/* dir.c */
-void dir2album(Album*,char*);
int parselibrary(Album**,char*);
\ No newline at end of file
--- a/mpl.c
+++ b/mpl.c
@@ -127,14 +127,6 @@
}
void
-usage(void)
-{
- fprint(2, "Usage: %s file", argv0);
- sysfatal("usage");
-}
-
-
-void
readvol(int fd, int *level)
{
int n;
@@ -172,6 +164,12 @@
write(fd, buf, n);
}
+void
+usage(void)
+{
+ fprint(2, "Usage: %s file", argv0);
+ sysfatal("usage");
+}
void
volthread(void *arg)
--- a/vorbis.c
+++ b/vorbis.c
@@ -23,6 +23,12 @@
v->artist = v->val[i];
continue;
}
+ if(runecstrcmp(v->key[i], L"tracknumber") == 0){
+ char buf[16];
+ snprint(buf, sizeof buf, "%S", v->val[i]);
+ v->tracknumber = atoi(buf);
+ continue;
+ }
}
}