From debe2d56341cb7160cf008a02f1914642b95b6a0 Mon Sep 17 00:00:00 2001 From: Jonathan Matthew Date: Mon, 14 Jun 2010 19:58:11 +1000 Subject: [PATCH] id3v2mux: write beats-per-minute tag using TBPM frame https://bugzilla.gnome.org/show_bug.cgi?id=621520 --- ext/taglib/gstid3v2mux.cc | 23 ++++++++++++++++++++++- tests/check/elements/id3v2mux.c | 8 ++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ext/taglib/gstid3v2mux.cc b/ext/taglib/gstid3v2mux.cc index ac84a5379c..c916c4b5f8 100644 --- a/ext/taglib/gstid3v2mux.cc +++ b/ext/taglib/gstid3v2mux.cc @@ -626,6 +626,26 @@ add_relative_volume_tag (ID3v2::Tag * id3v2tag, const GstTagList * list, id3v2tag->addFrame (frame); } +static void +add_bpm_tag (ID3v2::Tag * id3v2tag, const GstTagList * list, + const gchar * tag, guint num_tags, const gchar * frame_id) +{ + gdouble bpm; + + if (gst_tag_list_get_double_index (list, tag, 0, &bpm)) { + ID3v2::TextIdentificationFrame * frame; + gchar *tag_str; + + tag_str = g_strdup_printf ("%u", (guint)bpm); + + GST_DEBUG ("Setting %s to %s", tag, tag_str); + frame = new ID3v2::TextIdentificationFrame ("TBPM", String::UTF8); + id3v2tag->addFrame (frame); + frame->setText (tag_str); + g_free (tag_str); + } +} + /* id3demux produces these for frames it cannot parse */ #define GST_ID3_DEMUX_TAG_ID3V2_FRAME "private-id3v2-frame" @@ -669,7 +689,8 @@ static const struct GST_TAG_TRACK_PEAK, add_relative_volume_tag, ""}, { GST_TAG_TRACK_GAIN, add_relative_volume_tag, ""}, { GST_TAG_ALBUM_PEAK, add_relative_volume_tag, ""}, { - GST_TAG_ALBUM_GAIN, add_relative_volume_tag, ""} + GST_TAG_ALBUM_GAIN, add_relative_volume_tag, ""}, { + GST_TAG_BEATS_PER_MINUTE, add_bpm_tag, ""} }; diff --git a/tests/check/elements/id3v2mux.c b/tests/check/elements/id3v2mux.c index 4afc0178af..b32827db92 100644 --- a/tests/check/elements/id3v2mux.c +++ b/tests/check/elements/id3v2mux.c @@ -37,6 +37,7 @@ #define TEST_ALBUM_GAIN 0.78 #define TEST_TRACK_PEAK 0.83 #define TEST_ALBUM_PEAK 0.18 +#define TEST_BPM 113.0 /* for dummy mp3 frame sized MP3_FRAME_SIZE bytes, * start: ff fb b0 44 00 00 08 00 00 4b 00 00 00 00 00 00 */ @@ -117,6 +118,8 @@ test_taglib_id3mux_create_tags (guint32 mask) GST_TAG_ALBUM_PEAK, TEST_ALBUM_PEAK, NULL); } if (mask & (1 << 12)) { + gst_tag_list_add (tags, GST_TAG_MERGE_KEEP, + GST_TAG_BEATS_PER_MINUTE, TEST_BPM, NULL); } if (mask & (1 << 13)) { } @@ -239,6 +242,11 @@ test_taglib_id3mux_check_tags (GstTagList * tags, guint32 mask) fail_unless_sorta_equals_float (peak, TEST_ALBUM_PEAK); } if (mask & (1 << 12)) { + gdouble bpm; + + fail_unless (gst_tag_list_get_double (tags, GST_TAG_BEATS_PER_MINUTE, + &bpm)); + fail_unless_sorta_equals_float (bpm, TEST_BPM); } if (mask & (1 << 13)) { }