Ejemplo n.º 1
0
ID3v2_CommentsFrame* ID3v2_Tag::findCommentFrame() const
{
	ID3v2_FrameList*        list = frameList(wxT("COMM"));
	ID3v2_CommentsFrame*    frame;
	if( list )
	{
		// prefer comments without description, start searching with the last (mostly the newest)
		ID3v2_FrameList::Node* node = list->GetLast();
		while( node )
		{
			frame = (ID3v2_CommentsFrame*)node->GetData();
			if(  frame->description().IsEmpty()
			        && !frame->text().IsEmpty() )
			{
				return frame;
			}
			node = node->GetPrevious();
		}

		// try to return empty frames without description
		list->GetLast();
		while( node )
		{
			frame = (ID3v2_CommentsFrame*)node->GetData();
			if(  frame->description().IsEmpty() )
			{
				return frame;
			}
			node = node->GetPrevious();
		}

		/*
		if( !forWrite ) // do not overwrite eg. MusicMatch comments
		{
		    // okay, no comment so far, check all comment frames and return the first non-empty comment
		    node = list->GetFirst();
		    while( node )
		    {
		        frame = (ID3v2_CommentsFrame*)node->GetData();
		        if( !frame->text().IsEmpty() )
		        {
		            return frame;
		        }
		        node = node->GetNext();
		    }

		    // just use the first frame
		    node = list->GetFirst();
		    if( node )
		    {
		        return (ID3v2_CommentsFrame*)node->GetData();
		    }
		}*/
	}
	return NULL;
}