but there may be a bug about that; if you can give me specific info about how it is calling libFLAC I can take a look.
I'm afraid I can't be specific as such, as I don't really understand the code.
I have uploaded the cpp file in question, here, and the specific function is below:
int WriteFLACTag ( const char* filename, FileInfo* Info )
{
const char* Items_OggApe[] = {
"TITLE=", APE_TAG_FIELD_TITLE,
"VERSION=", APE_TAG_FIELD_SUBTITLE,
"ARTIST=", APE_TAG_FIELD_ARTIST,
"ALBUM=", APE_TAG_FIELD_ALBUM,
"TRACKNUMBER=", APE_TAG_FIELD_TRACK,
//"ORGANIZATION=", APE_TAG_FIELD_PUBLISHER,
//"DESCRIPTION=", APE_TAG_FIELD_COMMENT,
"GENRE=", APE_TAG_FIELD_GENRE,
"DATE=", APE_TAG_FIELD_YEAR,
//"LOCATION=", APE_TAG_FIELD_RECORDLOCATION,
//"COPYRIGHT=", APE_TAG_FIELD_COPYRIGHT,
//"ISRC=", APE_TAG_FIELD_ISRC
};
char* item;
char* value;
char* p;
size_t item_len;
size_t i, j;
int tag_written = 0;
int needs_new_block = 1;
struct FLAC__Metadata_SimpleIterator* si;
si = FLAC__metadata_simple_iterator_new ();
if ( !FLAC__metadata_simple_iterator_init ( si, filename, 0, 0 ) ) {
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
if ( !FLAC__metadata_simple_iterator_is_writable ( si ) ) {
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
do {
FLAC__MetadataType type = FLAC__metadata_simple_iterator_get_block_type ( si );
if ( type == FLAC__METADATA_TYPE_VORBIS_COMMENT || type == FLAC__METADATA_TYPE_PADDING ) {
needs_new_block = 0;
break;
}
} while ( FLAC__metadata_simple_iterator_next ( si ) );
if ( !needs_new_block ) {
FLAC__metadata_simple_iterator_delete ( si );
si = FLAC__metadata_simple_iterator_new ();
if ( !FLAC__metadata_simple_iterator_init ( si, filename, 0, 0 ) ) {
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
if ( !FLAC__metadata_simple_iterator_is_writable ( si ) ) {
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
}
do {
FLAC__MetadataType type = FLAC__metadata_simple_iterator_get_block_type ( si );
// Vorbis comment block or padding block
if ( needs_new_block || (type == FLAC__METADATA_TYPE_VORBIS_COMMENT || type == FLAC__METADATA_TYPE_PADDING) ) {
if ( !tag_written ) {
FLAC__StreamMetadata* data;
FLAC__StreamMetadata_VorbisComment_Entry entry;
size_t comments = 0;
if ( (data = FLAC__metadata_object_new ( FLAC__METADATA_TYPE_VORBIS_COMMENT )) == NULL ) {
fprintf ( Options.output, "Failed to create FLAC metadata block.\n" );
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
for ( i = 0; i < Info->TagItemCount; i++ ) {
if ( Info->TagItems[i].Item[0] != '\0' && Info->TagItems[i].ValueU[0] != '\0' )
comments++;
}
if ( !FLAC__metadata_object_vorbiscomment_resize_comments ( data, comments ) ) {
fprintf ( Options.output, "Failed to create FLAC metadata block.\n" );
FLAC__metadata_object_delete ( data );
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
comments = 0;
for ( i = 0; i < Info->TagItemCount; i++ ) {
int replaced_item = 0;
if ( Info->TagItems[i].Item[0] == '\0' || Info->TagItems[i].ValueU[0] == '\0' )
continue;
for ( j = 0; j < (sizeof (Items_OggApe) / sizeof (*Items_OggApe)) / 2; j++ ) {
if ( stricmp ( (char *)Info->TagItems[i].Item, (char *)Items_OggApe[j*2+1] ) == 0 ) {
replaced_item = 1;
item_len = strlen ((char *)Items_OggApe[j*2]) - 1;
if ( (item = (char *)malloc ( item_len + 1 )) == NULL ) {
fprintf ( Options.output, "WriteFLACTag: Memory allocation failed.\n" );
exit (1);
}
strncpy ( item, Items_OggApe[j*2], item_len );
item[item_len] = '\0';
break;
}
}
if ( !replaced_item ) {
item_len = Info->TagItems[i].ItemSize;
if ( (item = (char *)malloc ( item_len + 1 )) == NULL ) {
fprintf ( Options.output, "WriteFLACTag: Memory allocation failed.\n" );
exit (1);
}
strcpy ( (char *)item, (char *)Info->TagItems[i].Item );
}
p = item;
while ( *p != '\0' ) {
int ch = *p;
if ( ch == '=' || ch < 0x20 || ch > 0x7D ) ch = '_';
*p++ = ch;
}
entry.length = strlen (item) + 1 + Info->TagItems[i].ValueUSize;
if ( (value = (char *)malloc ( entry.length + 1 )) == NULL ) {
fprintf ( Options.output, "WriteFLACTag: Memory allocation failed.\n" );
exit (1);
}
sprintf ( value, "%s=%s", item, Info->TagItems[i].ValueU );
entry.entry = (unsigned char *)value;
if ( !FLAC__metadata_object_vorbiscomment_set_comment ( data, comments++, entry, 1 ) ) {
fprintf ( Options.output, "Failed to create FLAC metadata block.\n" );
FLAC__metadata_object_delete ( data );
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
free ( item );
free ( value );
}
//FLAC__metadata_object_vorbiscomment_set_vendor_string ( data, entry, 1 );
/*
FLAC__metadata_object_vorbiscomment_resize_comments ( FLAC__StreamMetadata *object, unsigned new_num_comments);
FLAC__metadata_object_vorbiscomment_set_comment ( FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
FLAC__metadata_object_vorbiscomment_insert_comment (FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
FLAC__metadata_object_vorbiscomment_delete_comment (FLAC__StreamMetadata *object, unsigned comment_num);
*/
if ( !needs_new_block ) {
if ( !FLAC__metadata_simple_iterator_set_block ( si, data, 1 ) ) { // 1 = use padding
fprintf ( Options.output, "Failed to write FLAC metadata block.\n" );
FLAC__metadata_object_delete ( data );
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
} else {
if ( !FLAC__metadata_simple_iterator_insert_block_after ( si, data, 1 ) ) { // 1 = use padding
fprintf ( Options.output, "Failed to write FLAC metadata block.\n" );
FLAC__metadata_object_delete ( data );
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
}
FLAC__metadata_object_delete ( data );
tag_written = 1;
} else if ( type == FLAC__METADATA_TYPE_VORBIS_COMMENT ) {
if ( !FLAC__metadata_simple_iterator_delete_block ( si, 0 ) ) { // 0 = no padding
fprintf ( Options.output, "Failed to remove FLAC metadata block.\n" );
FLAC__metadata_simple_iterator_delete ( si );
return 1;
}
}
}
} while ( FLAC__metadata_simple_iterator_next ( si ) );
FLAC__metadata_simple_iterator_delete ( si );
fprintf ( Options.output, "FLAC tag written.\n" );
return 0;
}
Unfortunately, if you, or another developer familiar with the FLAC library, are not prepared to look at the code then we're stuck. Perhaps, if you could help resolve this for version 2.0.50, it could be distributed with the FLAC Windows installer, and Windows FLAC users can sleep easy...
That said, I don't expect you to resolve this. I was mainly querying whether this was standard for the library or not. As you say it is not then I must put it down to the specific code and forget about it, until someone with the proper skills takes on the mantle.