Esempio n. 1
0
// Too bad can't use STL copy alogirthm....
// copy(src.begin(), src.end(), back_inserter(dest));
void MetaDSF::MetaDSFImpl::dupFrameList(const TagLib::ID3v2::FrameList &src, 
					TagLib::ID3v2::FrameList &dest) 
{
  TagLib::ID3v2::FrameList::ConstIterator it;

  for (it = src.begin(); it != src.end(); it++) {
    dest.append(*it);
  }
}
Esempio n. 2
0
int MetaDSF::deletePictures(const TagLib::String &ptype) 
{
  TagLib::ID3v2::FrameList l = _i->_file.ID3v2Tag()->frameList("APIC");
  TagLib::ID3v2::FrameList dl; // a list of frames to be deleted
  TagLib::ID3v2::FrameList::ConstIterator it;
  std::string pt = ptype.toCString();
  // retrieve a list of frames that matches the given type
  for (it = l.begin(); it != l.end(); it++) {
    TagLib::ID3v2::AttachedPictureFrame *f = 
      static_cast<TagLib::ID3v2::AttachedPictureFrame *>(*it);
    TagLib::ID3v2::AttachedPictureFrame::Type t = 
      static_cast<TagLib::ID3v2::AttachedPictureFrame::Type>(std::stoi(pt, 
								       0, 16));
    if (f->type() == t) {
      dl.append(f);
    }
  }  

  _i->deleteFrames(dl);
  _i->_changed = true;
  return dl.size();
}
Esempio n. 3
0
static Meta::ReplayGainTagMap readID3v2Tags( TagLib::ID3v2::Tag *tag )
{
    Meta::ReplayGainTagMap map;
    {   // ID3v2.4.0 native replay gain tag support (as written by Quod Libet, for example).
        TagLib::ID3v2::FrameList frames = tag->frameListMap()["RVA2"];
        frames.append(tag->frameListMap()["XRVA"]);
        if ( !frames.isEmpty() )
        {
            for ( unsigned int i = 0; i < frames.size(); ++i )
            {
                // we have to parse this frame ourselves
                // ID3v2 frame header is 10 bytes, so skip that
                TagLib::ByteVector data = frames[i]->render().mid( 10 );
                unsigned int offset = 0;
                QString desc( data.data() );
                offset += desc.count() + 1;
                unsigned int channel = data.mid( offset, 1 ).toUInt( true );
                // channel 1 is the main volume - the only one we care about
                if ( channel == 1 )
                {
                    ++offset;
                    qint16 adjustment512 = data.mid( offset, 2 ).toShort( true );
                    qreal adjustment = ( (qreal)adjustment512 ) / 512.0;
                    offset += 2;
                    unsigned int peakBits = data.mid( offset, 1 ).toUInt( true );
                    ++offset;
                    bool ok = false;
                    qreal peak = readRVA2PeakValue( data.mid( offset ), peakBits, &ok );
                    if ( ok )
                    {
                        if ( desc.toLower() == "album" )
                        {
                            map[Meta::ReplayGain_Album_Gain] = adjustment;
                            map[Meta::ReplayGain_Album_Peak] = peakToDecibels( peak );
                        }
                        else if ( desc.toLower() == "track" || !map.contains( Meta::ReplayGain_Track_Gain ) )
                        {
                            map[Meta::ReplayGain_Track_Gain] = adjustment;
                            map[Meta::ReplayGain_Track_Peak] = peakToDecibels( peak );
                        }
                    }
                }
            }
            if ( !map.isEmpty() )
                return map;
        }
    }

    {   // Foobar2000-style ID3v2.3.0 tags
        TagLib::ID3v2::FrameList frames = tag->frameListMap()["TXXX"];
        for ( TagLib::ID3v2::FrameList::Iterator it = frames.begin(); it != frames.end(); ++it ) {
            TagLib::ID3v2::UserTextIdentificationFrame* frame =
                dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>( *it );
            if ( frame && frame->fieldList().size() >= 2 )
            {
                QString desc = TStringToQString( frame->description() ).toLower();
                if ( desc == "replaygain_album_gain" )
                    maybeAddGain( frame->fieldList()[1], Meta::ReplayGain_Album_Gain, &map );
                if ( desc == "replaygain_album_peak" )
                    maybeAddPeak( frame->fieldList()[1], Meta::ReplayGain_Album_Peak, &map );
                if ( desc == "replaygain_track_gain" )
                    maybeAddGain( frame->fieldList()[1], Meta::ReplayGain_Track_Gain, &map );
                if ( desc == "replaygain_track_peak" )
                    maybeAddPeak( frame->fieldList()[1], Meta::ReplayGain_Track_Peak, &map );
            }
        }
    }
    return map;
}