MCPcopy Create free account
hub / github.com/audacity/audacity / AddID3Chunk

Method AddID3Chunk

modules/import-export/mod-pcm/ExportPCM.cpp:950–1090  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

948#endif
949
950bool PCMExportProcessor::AddID3Chunk(
951 const wxFileNameWrapper &fName, const Tags *tags, int sf_format)
952{
953#ifdef USE_LIBID3TAG
954 id3_tag_holder tp { id3_tag_new() };
955
956 for (const auto &pair : tags->GetRange()) {
957 const auto &n = pair.first;
958 const auto &v = pair.second;
959 const char *name = "TXXX";
960
961 if (n.CmpNoCase(TAG_TITLE) == 0) {
962 name = ID3_FRAME_TITLE;
963 }
964 else if (n.CmpNoCase(TAG_ARTIST) == 0) {
965 name = ID3_FRAME_ARTIST;
966 }
967 else if (n.CmpNoCase(TAG_ALBUM) == 0) {
968 name = ID3_FRAME_ALBUM;
969 }
970 else if (n.CmpNoCase(TAG_YEAR) == 0) {
971 name = ID3_FRAME_YEAR;
972 }
973 else if (n.CmpNoCase(TAG_GENRE) == 0) {
974 name = ID3_FRAME_GENRE;
975 }
976 else if (n.CmpNoCase(TAG_COMMENTS) == 0) {
977 name = ID3_FRAME_COMMENT;
978 }
979 else if (n.CmpNoCase(TAG_TRACK) == 0) {
980 name = ID3_FRAME_TRACK;
981 }
982 else if (n.CmpNoCase(wxT("composer")) == 0) {
983 name = "TCOM";
984 }
985
986 struct id3_frame *frame = id3_frame_new(name);
987
988 if (!n.IsAscii() || !v.IsAscii()) {
989 id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_UTF_16);
990 }
991 else {
992 id3_field_settextencoding(id3_frame_field(frame, 0), ID3_FIELD_TEXTENCODING_ISO_8859_1);
993 }
994
995 MallocString<id3_ucs4_t> ucs4{
996 id3_utf8_ucs4duplicate((id3_utf8_t *) (const char *) v.mb_str(wxConvUTF8)) };
997
998 if (strcmp(name, ID3_FRAME_COMMENT) == 0) {
999 // A hack to get around iTunes not recognizing the comment. The
1000 // language defaults to XXX and, since it's not a valid language,
1001 // iTunes just ignores the tag. So, either set it to a valid language
1002 // (which one???) or just clear it. Unfortunately, there's no supported
1003 // way of clearing the field, so do it directly.
1004 id3_field *f = id3_frame_field(frame, 1);
1005 memset(f->immediate.value, 0, sizeof(f->immediate.value));
1006 id3_field_setfullstring(id3_frame_field(frame, 3), ucs4.get());
1007 }

Callers

nothing calls this directly

Calls 8

GetRangeMethod · 0.80
IsOpenedMethod · 0.80
getMethod · 0.45
resetMethod · 0.45
WriteMethod · 0.45
SeekMethod · 0.45
FlushMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected