After my rants about Halloween I decided to become a useful part of society again by turning back to my current XS port of the mplib.
Doing XS is actually pretty cool, despite what people generally tend to say about it. But sometimes it is just a little too verbose for my taste. Consider the following chatty code that maps and i3v1_tag structure to a Perl hash (HV):
int fill_sv_v1tag(HV * hv, id3_tag * t) {
id3_content * content;
content = mp_get_content(t, MP_ARTIST);
hv_store(hv, "ARTIST", 6, newSVpv(content ? mp_parse_artist(content)->text : "", 0), 0);
content = mp_get_content(t, MP_TITLE);
hv_store(hv, "TITLE", 5, newSVpv(content ? mp_parse_title(content)->text : "", 0), 0);
content = mp_get_content(t, MP_ALBUM);
hv_store(hv, "ALBUM", 5, newSVpv(content ? mp_parse_album(content)->text : "", 0), 0);
content = mp_get_content(t, MP_GENRE);
hv_store(hv, "GENRE", 5, newSVpv(content ? mp_parse_genre(content)->text : "", 0), 0);
content = mp_get_content(t, MP_TRACK);
hv_store(hv, "TRACK", 5, newSVpv(content ? mp_parse_track(content)->text : "", 0), 0);
content = mp_get_content(t, MP_YEAR);
hv_store(hv, "YEAR", 4, newSVpv(content ? mp_parse_year(content)->text : "", 0), 0);
content = mp_get_content(t, MP_COMMENT);
hv_store(hv, "COMMENT", 7, newSVpv(content ? mp_parse_comment(content)->text : "", 0), 0);
}
The mplib's author had the guts to create all those pesky little mp_parse_FIELD
functions so I can't that easily do that in a simple for-loop. I wish C had an eval()
function! Perhaps I can come up with a macro that does this work for me.
If you wonder how I do the corresponding thing for id3v2 tags with 74 different frames: omission to the rescue! There are no such mp_parse_*
functions for those so I have to do that myself. Thanks God!