From 032b6a008faee9da6ae15165a91c1c2d2f8e67c1 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 22 Jul 2004 17:53:52 +0000 Subject: [PATCH] Handle the global data from CUE sheets. --- src/mkvextract_cuesheets.cpp | 93 ++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/src/mkvextract_cuesheets.cpp b/src/mkvextract_cuesheets.cpp index 9177d3980..c5bd4ed11 100644 --- a/src/mkvextract_cuesheets.cpp +++ b/src/mkvextract_cuesheets.cpp @@ -127,22 +127,43 @@ get_tag_tuid(KaxTag &tag) { return uint64(*static_cast(tuid)); } +static int64_t +get_tag_cuid(KaxTag &tag) { + KaxTagTargets *targets; + KaxTagChapterUID *cuid; + + targets = FINDFIRST(&tag, KaxTagTargets); + if (targets == NULL) + return -1; + cuid = FINDFIRST(targets, KaxTagChapterUID); + if (cuid == NULL) + return -1; + return uint64(*static_cast(cuid)); +} + static KaxTag * find_tag_for_track(int idx, int64_t tuid, + int64_t cuid, EbmlMaster &m) { string sidx; int i; - int64_t tag_tuid; + int64_t tag_tuid, tag_cuid; sidx = mxsprintf("%d", idx); for (i = 0; i < m.ListSize(); i++) if (EbmlId(*m[i]) == KaxTag::ClassInfos.GlobalId) { + tag_cuid = get_tag_cuid(*static_cast(m[i])); + if ((cuid == 0) && (tag_cuid != -1) && (tag_cuid != 0)) + continue; + if ((cuid > 0) && (tag_cuid != cuid)) + continue; tag_tuid = get_tag_tuid(*static_cast(m[i])); if (((tuid == -1) || (tag_tuid == -1) || (tuid == tag_tuid)) && - (get_simple_tag("TRACKNUMBER", - *static_cast(m[i])) == sidx)) + ((get_simple_tag("TRACKNUMBER", + *static_cast(m[i])) == sidx) || + (idx == -1))) return static_cast(m[i]); } @@ -150,29 +171,16 @@ find_tag_for_track(int idx, } static string -get_global_from_tags(int num_tracks, - const char *name, - int64_t tuid, - KaxTags &tags) { +get_global_tag(const char *name, + int64_t tuid, + KaxTags &tags) { KaxTag *tag; - string global_value, value; - int i; - tag = find_tag_for_track(1, tuid, tags); - if (tag != NULL) - global_value = get_simple_tag(name, *tag); - if (global_value == "") + tag = find_tag_for_track(-1, tuid, 0, tags); + if (tag == NULL) return ""; - for (i = 2; i <= num_tracks; i++) { - tag = find_tag_for_track(i, tuid, tags); - if (tag != NULL) { - value = get_simple_tag(name, *tag); - if ((value != "") && (value != global_value)) - return ""; - } - } - return global_value; + return get_simple_tag(name, *tag); } static int64_t @@ -199,6 +207,16 @@ get_chapter_name(KaxChapterAtom &atom) { return UTFstring_to_cstrutf8(UTFstring(*name)); } +static int64_t +get_chapter_uid(KaxChapterAtom &atom) { + KaxChapterUID *uid; + + uid = FINDFIRST(&atom, KaxChapterUID); + if (uid == NULL) + return -1; + return uint64(*static_cast(uid)); +} + static int64_t get_chapter_index(int idx, KaxChapterAtom &atom) { @@ -225,22 +243,25 @@ _print_if_global(mm_io_c &out, KaxTags &tags) { string global; - global = get_global_from_tags(num_entries, name, tuid, tags); + global = get_global_tag(name, tuid, tags); if (global != "") out.printf(format, global.c_str()); } #define print_if_available(name, format) \ - _print_if_available(out, name, format, *tag) + _print_if_available(out, name, format, tuid, tags, *tag) static void _print_if_available(mm_io_c &out, const char *name, const char *format, + int64_t tuid, + KaxTags &tags, KaxTag &tag) { string value; value = get_simple_tag(name, tag); - if (value != "") + if ((value != "") && + (value != get_global_tag(name, tuid, tags))) out.printf(format, value.c_str()); } @@ -261,20 +282,20 @@ write_cuesheet(const char *file_name, print_if_global("DATE", "REM DATE %s\n"); print_if_global("GENRE", "REM GENRE %s\n"); print_if_global("DISCID", "REM DISCID %s\n"); - print_if_global("ARTIST", "PERFORMER \"%s\"\n"); + print_if_global("ALBUM_ARTIST", "PERFORMER \"%s\"\n"); print_if_global("ALBUM", "TITLE \"%s\"\n"); out.printf("FILE \"%s\" WAVE\n", file_name); for (i = 0; i < chapters.ListSize(); i++) { - out.printf(" TRACK %02d AUDIO\n", i + 1); - tag = find_tag_for_track(i + 1, tuid, tags); + KaxChapterAtom &atom = *static_cast(chapters[i]); + + out.printf(" TRACK %02d AUDIO\n", i + 1); + tag = find_tag_for_track(i + 1, tuid, get_chapter_uid(atom), tags); if (tag != NULL) { - KaxChapterAtom &atom = - *static_cast(chapters[i]); - print_if_available("TITLE", " TITLE \"%s\"\n"); - print_if_available("ARTIST", " PERFORMER \"%s\"\n"); - print_if_available("ISRC", " ISRC %s\n"); + print_if_available("TITLE", " TITLE \"%s\"\n"); + print_if_available("ARTIST", " PERFORMER \"%s\"\n"); + print_if_available("ISRC", " ISRC %s\n"); index_00 = get_chapter_index(0, atom); index_01 = get_chapter_index(1, atom); if (index_01 == -1) { @@ -283,16 +304,18 @@ write_cuesheet(const char *file_name, index_01 = 0; } if (index_00 != -1) - out.printf(" INDEX 00 %02lld:%02lld:%02lld\n", + out.printf(" INDEX 00 %02lld:%02lld:%02lld\n", index_00 / 1000000 / 1000 / 60, (index_00 / 1000000 / 1000) % 60, irnd((double)(index_00 % 1000000000ll) * 75.0 / 1000000000.0)); - out.printf(" INDEX 01 %02lld:%02lld:%02lld\n", + out.printf(" INDEX 01 %02lld:%02lld:%02lld\n", index_01 / 1000000 / 1000 / 60, (index_01 / 1000000 / 1000) % 60, irnd((double)(index_01 % 1000000000ll) * 75.0 / 1000000000.0)); + print_if_available("DATE", " REM DATE %s\n"); + print_if_available("GENRE", " REM GENRE %s\n"); } } }