aboutsummaryrefslogtreecommitdiffstats
path: root/src/cue
diff options
context:
space:
mode:
Diffstat (limited to 'src/cue')
-rw-r--r--src/cue/cue_tag.c258
-rw-r--r--src/cue/cue_tag.h21
2 files changed, 127 insertions, 152 deletions
diff --git a/src/cue/cue_tag.c b/src/cue/cue_tag.c
index 6251b03e2..67919ce37 100644
--- a/src/cue/cue_tag.c
+++ b/src/cue/cue_tag.c
@@ -1,76 +1,78 @@
+#include "config.h"
#include "cue_tag.h"
+#include "tag.h"
-static struct tag*
-cue_tag_cd(struct Cdtext* cdtext, struct Rem* rem)
+#include <libcue/libcue.h>
+#include <assert.h>
+
+static struct tag *
+cue_tag_cd(struct Cdtext *cdtext, struct Rem *rem)
{
- char* tmp = NULL;
- struct tag* tag = NULL;
+ struct tag *tag;
+ char *tmp;
- //if (cdtext == NULL)
- //return NULL;
+ assert(cdtext != NULL);
tag = tag_new();
tag_begin_add(tag);
- { /* TAG_ITEM_ALBUM_ARTIST */
+ /* TAG_ALBUM_ARTIST */
if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ALBUM_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_SONGWRITER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ALBUM_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ALBUM_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_ARRANGER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ALBUM_ARTIST, tmp);
- /* TAG_ITEM_ALBUM_ARTIST */ }
+ tag_add_item(tag, TAG_ALBUM_ARTIST, tmp);
- { /* TAG_ITEM_ARTIST */
+ /* TAG_ARTIST */
if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_SONGWRITER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_ARRANGER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
- /* TAG_ITEM_ARTIST */ }
+ tag_add_item(tag, TAG_ARTIST, tmp);
- /* TAG_ITEM_PERFORMER */
+ /* TAG_PERFORMER */
if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_PERFORMER, tmp);
+ tag_add_item(tag, TAG_PERFORMER, tmp);
- /* TAG_ITEM_COMPOSER */
+ /* TAG_COMPOSER */
if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_COMPOSER, tmp);
+ tag_add_item(tag, TAG_COMPOSER, tmp);
- /* TAG_ITEM_ALBUM */
+ /* TAG_ALBUM */
if ((tmp = cdtext_get(PTI_TITLE, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ALBUM, tmp);
+ tag_add_item(tag, TAG_ALBUM, tmp);
- /* TAG_ITEM_GENRE */
+ /* TAG_GENRE */
if ((tmp = cdtext_get(PTI_GENRE, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_GENRE, tmp);
+ tag_add_item(tag, TAG_GENRE, tmp);
- /* TAG_ITEM_DATE */
+ /* TAG_DATE */
if ((tmp = rem_get(REM_DATE, rem)) != NULL)
- tag_add_item(tag, TAG_ITEM_DATE, tmp);
+ tag_add_item(tag, TAG_DATE, tmp);
- /* TAG_ITEM_COMMENT */
+ /* TAG_COMMENT */
if ((tmp = cdtext_get(PTI_MESSAGE, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_COMMENT, tmp);
+ tag_add_item(tag, TAG_COMMENT, tmp);
- /* TAG_ITEM_DISC */
+ /* TAG_DISC */
if ((tmp = cdtext_get(PTI_DISC_ID, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_DISC, tmp);
+ tag_add_item(tag, TAG_DISC, tmp);
/* stream name, usually empty
- * tag_add_item(tag, TAG_ITEM_NAME,);
+ * tag_add_item(tag, TAG_NAME,);
*/
/* REM MUSICBRAINZ entry?
@@ -82,175 +84,145 @@ cue_tag_cd(struct Cdtext* cdtext, struct Rem* rem)
tag_end_add(tag);
- if (tag != NULL)
- {
- if (tag_is_empty(tag))
- {
- tag_free(tag);
- return NULL;
- }
- else
- return tag;
- }
- else
+ if (tag_is_empty(tag)) {
+ tag_free(tag);
return NULL;
+ }
+
+ return tag;
}
-static struct tag*
-cue_tag_track(struct Cdtext* cdtext, struct Rem* rem)
+static struct tag *
+cue_tag_track(struct Cdtext *cdtext, struct Rem *rem)
{
- char* tmp = NULL;
- struct tag* tag = NULL;
+ struct tag *tag;
+ char *tmp;
- //if (cdtext == NULL)
- //return NULL;
+ assert(cdtext != NULL);
tag = tag_new();
tag_begin_add(tag);
- { /* TAG_ITEM_ARTIST */
+ /* TAG_ARTIST */
if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_SONGWRITER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
+ tag_add_item(tag, TAG_ARTIST, tmp);
else if ((tmp = cdtext_get(PTI_ARRANGER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_ARTIST, tmp);
- /* TAG_ITEM_ARTIST */ }
+ tag_add_item(tag, TAG_ARTIST, tmp);
- /* TAG_ITEM_TITLE */
+ /* TAG_TITLE */
if ((tmp = cdtext_get(PTI_TITLE, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_TITLE, tmp);
+ tag_add_item(tag, TAG_TITLE, tmp);
- /* TAG_ITEM_GENRE */
+ /* TAG_GENRE */
if ((tmp = cdtext_get(PTI_GENRE, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_GENRE, tmp);
+ tag_add_item(tag, TAG_GENRE, tmp);
- /* TAG_ITEM_DATE */
+ /* TAG_DATE */
if ((tmp = rem_get(REM_DATE, rem)) != NULL)
- tag_add_item(tag, TAG_ITEM_DATE, tmp);
+ tag_add_item(tag, TAG_DATE, tmp);
- /* TAG_ITEM_COMPOSER */
+ /* TAG_COMPOSER */
if ((tmp = cdtext_get(PTI_COMPOSER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_COMPOSER, tmp);
+ tag_add_item(tag, TAG_COMPOSER, tmp);
- /* TAG_ITEM_PERFORMER */
+ /* TAG_PERFORMER */
if ((tmp = cdtext_get(PTI_PERFORMER, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_PERFORMER, tmp);
+ tag_add_item(tag, TAG_PERFORMER, tmp);
- /* TAG_ITEM_COMMENT */
+ /* TAG_COMMENT */
if ((tmp = cdtext_get(PTI_MESSAGE, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_COMMENT, tmp);
+ tag_add_item(tag, TAG_COMMENT, tmp);
- /* TAG_ITEM_DISC */
+ /* TAG_DISC */
if ((tmp = cdtext_get(PTI_DISC_ID, cdtext)) != NULL)
- tag_add_item(tag, TAG_ITEM_DISC, tmp);
+ tag_add_item(tag, TAG_DISC, tmp);
tag_end_add(tag);
- if (tag != NULL)
- {
- if (tag_is_empty(tag))
- {
- tag_free(tag);
- return NULL;
- }
- else
- return tag;
- }
- else
+ if (tag_is_empty(tag)) {
+ tag_free(tag);
return NULL;
+ }
+
+ return tag;
}
-struct tag*
-cue_tag_file( FILE* fp,
- const unsigned int tnum)
+struct tag *
+cue_tag(struct Cd *cd, unsigned tnum)
{
- struct tag* cd_tag = NULL;
- struct tag* track_tag = NULL;
- struct Cd* cd = NULL;
+ struct tag *cd_tag, *track_tag, *tag;
+ struct Track *track;
- if (tnum > 256)
- return NULL;
+ assert(cd != NULL);
- if (fp == NULL)
+ track = cd_get_track(cd, tnum);
+ if (track == NULL)
return NULL;
- else
- cd = cue_parse_file(fp);
- if (cd == NULL)
- return NULL;
- else
- {
- /* tag from CDtext info */
- cd_tag = cue_tag_cd( cd_get_cdtext(cd),
- cd_get_rem(cd));
+ /* tag from CDtext info */
+ cd_tag = cue_tag_cd(cd_get_cdtext(cd), cd_get_rem(cd));
- /* tag from TRACKtext info */
- track_tag = cue_tag_track( track_get_cdtext( cd_get_track(cd, tnum)),
- track_get_rem( cd_get_track(cd, tnum)));
+ /* tag from TRACKtext info */
+ track_tag = cue_tag_track(track_get_cdtext(track),
+ track_get_rem(track));
- cd_delete(cd);
- }
+ tag = tag_merge_replace(cd_tag, track_tag);
+ if (tag == NULL)
+ return NULL;
+
+ /* libcue returns the track duration in frames, and there are
+ 75 frames per second; this formula rounds up */
+ tag->time = (track_get_length(track) + 74) / 75;
- return tag_merge_replace(cd_tag, track_tag);
+ return tag;
}
-struct tag*
-cue_tag_string( char* str,
- const unsigned int tnum)
+struct tag *
+cue_tag_file(FILE *fp, unsigned tnum)
{
- struct tag* cd_tag = NULL;
- struct tag* track_tag = NULL;
- struct tag* merge_tag = NULL;
- struct Cd* cd = NULL;
+ struct Cd *cd;
+ struct tag *tag;
- if (tnum > 256)
- return NULL;
+ assert(fp != NULL);
- if (str == NULL)
+ if (tnum > 256)
return NULL;
- else
- cd = cue_parse_string(str);
+ cd = cue_parse_file(fp);
if (cd == NULL)
return NULL;
- else
- {
- /* tag from CDtext info */
- cd_tag = cue_tag_cd( cd_get_cdtext(cd),
- cd_get_rem(cd));
- /* tag from TRACKtext info */
- track_tag = cue_tag_track( track_get_cdtext( cd_get_track(cd, tnum)),
- track_get_rem( cd_get_track(cd, tnum)));
+ tag = cue_tag(cd, tnum);
+ cd_delete(cd);
- cd_delete(cd);
- }
+ return tag;
+}
- if ((cd_tag != NULL) && (track_tag != NULL))
- {
- merge_tag = tag_merge(cd_tag, track_tag);
- tag_free(cd_tag);
- tag_free(track_tag);
- return merge_tag;
- }
+struct tag *
+cue_tag_string(const char *str, unsigned tnum)
+{
+ struct Cd *cd;
+ struct tag *tag;
- else if (cd_tag != NULL)
- {
- return cd_tag;
- }
+ assert(str != NULL);
- else if (track_tag != NULL)
- {
- return track_tag;
- }
+ if (tnum > 256)
+ return NULL;
- else
+ cd = cue_parse_string(str);
+ if (cd == NULL)
return NULL;
+
+ tag = cue_tag(cd, tnum);
+ cd_delete(cd);
+
+ return tag;
}
diff --git a/src/cue/cue_tag.h b/src/cue/cue_tag.h
index adc4c466e..1ddaa59c8 100644
--- a/src/cue/cue_tag.h
+++ b/src/cue/cue_tag.h
@@ -1,20 +1,23 @@
#ifndef MPD_CUE_TAG_H
#define MPD_CUE_TAG_H
-#include "config.h"
+#include "check.h"
#ifdef HAVE_CUE /* libcue */
-#include <libcue/libcue.h>
-#include "../tag.h"
+#include <stdio.h>
-struct tag*
-cue_tag_file( FILE*,
- const unsigned int);
+struct tag;
+struct Cd;
-struct tag*
-cue_tag_string( char*,
- const unsigned int);
+struct tag *
+cue_tag(struct Cd *cd, unsigned tnum);
+
+struct tag *
+cue_tag_file(FILE *file, unsigned tnum);
+
+struct tag *
+cue_tag_string(const char *str, unsigned tnum);
#endif /* libcue */
#endif