Пример #1
0
ByteVector APE::Item::render() const
{
  ByteVector data;
  TagLib::uint flags = ((d->readOnly) ? 1 : 0) | (d->type << 1);
  ByteVector value;

  if(isEmpty())
    return data;

  if(d->type == Text) {
    StringList::ConstIterator it = d->text.begin();

    value.append(it->data(String::UTF8));
    it++;
    for(; it != d->text.end(); ++it) {
      value.append('\0');
      value.append(it->data(String::UTF8));
    }
    d->value = value;
  }
  else
    value.append(d->value);

  data.append(ByteVector::fromUInt(value.size(), false));
  data.append(ByteVector::fromUInt(flags, false));
  data.append(d->key.data(String::UTF8));
  data.append(ByteVector('\0'));
  data.append(value);

  return data;
}
Пример #2
0
static const std::vector<std::string> StringListToVectorString(const StringList& stringList)
{
  std::vector<std::string> values;
  for (StringList::ConstIterator it = stringList.begin(); it != stringList.end(); ++it)
    values.push_back(it->to8Bit(true));
  return values;
}
Пример #3
0
  void TOPPASResources::load(const QString& file_name)
  {
    Param load_param;
    ParamXMLFile paramFile;
    paramFile.load(String(file_name), load_param);

    for (Param::ParamIterator it = load_param.begin(); it != load_param.end(); ++it)
    {
      StringList substrings;
      it.getName().split(':', substrings);
      if (substrings.size() != 2 ||
          substrings.back() != "url_list" ||
          (it->value).valueType() != DataValue::STRING_LIST)
      {
        std::cerr << "Invalid file format." << std::endl;
        return;
      }

      QString key = (substrings[0]).toQString();
      StringList url_list = (StringList)(it->value);
      QList<TOPPASResource> resource_list;
      for (StringList::ConstIterator it = url_list.begin(); it != url_list.end(); ++it)
      {
        resource_list << TOPPASResource(QUrl(it->toQString()));
      }

      add(key, resource_list);
    }
  }
Пример #4
0
ByteVector
MP4::Tag::renderText(const ByteVector &name, const MP4::Item &item, int flags) const
{
  ByteVectorList data;
  StringList value = item.toStringList();
  for(StringList::ConstIterator it = value.begin(); it != value.end(); ++it) {
    data.append(it->data(String::UTF8));
  }
  return renderData(name, flags, data);
}
Пример #5
0
ByteVector
MP4::Tag::renderFreeForm(const String &name, const MP4::Item &item) const
{
  StringList header = StringList::split(name, ":");
  if(header.size() != 3) {
    debug("MP4: Invalid free-form item name \"" + name + "\"");
    return ByteVector();
  }
  ByteVector data;
  data.append(renderAtom("mean", ByteVector::fromUInt(0) + header[1].data(String::UTF8)));
  data.append(renderAtom("name", ByteVector::fromUInt(0) + header[2].data(String::UTF8)));
  AtomDataType type = item.atomDataType();
  if(type == TypeUndefined) {
    if(!item.toStringList().isEmpty()) {
      type = TypeUTF8;
    }
    else {
      type = TypeImplicit;
    }
  }
  if(type == TypeUTF8) {
    StringList value = item.toStringList();
    for(StringList::ConstIterator it = value.begin(); it != value.end(); ++it) {
      data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + it->data(String::UTF8)));
    }
  }
  else {
    ByteVectorList value = item.toByteVectorList();
    for(ByteVectorList::ConstIterator it = value.begin(); it != value.end(); ++it) {
      data.append(renderAtom("data", ByteVector::fromUInt(type) + ByteVector(4, '\0') + *it));
    }
  }
  return renderAtom("----", data);
}
PropertyMap TextIdentificationFrame::makeTMCLProperties() const
{
  PropertyMap map;
  if(fieldList().size() % 2 != 0){
    // according to the ID3 spec, TMCL must contain an even number of entries
    map.unsupportedData().append(frameID());
    return map;
  }
  StringList l = fieldList();
  for(StringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
    String instrument = it->upper();
    if(instrument.isEmpty()) {
      // instrument is not a valid key -> frame unsupported
      map.clear();
      map.unsupportedData().append(frameID());
      return map;
    }
    map.insert(L"PERFORMER:" + instrument, (++it)->split(","));
  }
  return map;
}
Пример #7
0
int APE::Item::size() const
{
  // SFB: Why is d->key.size() used when size() returns the length in UniChars and not UTF-8?
  int result = 8 + d->key.size() /* d->key.data(String::UTF8).size() */ + 1;
  switch (d->type) {
    case Text:
      if(d->text.size()) {
        StringList::ConstIterator it = d->text.begin();
		  
        result += it->data(String::UTF8).size();
        it++;
        for(; it != d->text.end(); ++it)
          result += 1 + it->data(String::UTF8).size();
      }
      break;

    case Binary:
    case Locator:
      result += d->value.size();
      break;
  }
  return result;
}
Пример #8
0
void ID3v2::Tag::removeUnsupportedProperties(const StringList &properties)
{
  for(StringList::ConstIterator it = properties.begin(); it != properties.end(); ++it){
    if(it->startsWith("UNKNOWN/")) {
      String frameID = it->substr(String("UNKNOWN/").size());
      if(frameID.size() != 4)
        continue; // invalid specification
      ByteVector id = frameID.data(String::Latin1);
      // delete all unknown frames of given type
      FrameList l = frameList(id);
      for(FrameList::ConstIterator fit = l.begin(); fit != l.end(); fit++)
        if (dynamic_cast<const UnknownFrame *>(*fit) != 0)
          removeFrame(*fit);
    }
    else if(it->size() == 4){
      ByteVector id = it->data(String::Latin1);
      removeFrames(id);
    }
    else {
      ByteVector id = it->substr(0,4).data(String::Latin1);
      if(it->size() <= 5)
        continue; // invalid specification
      String description = it->substr(5);
      Frame *frame = 0;
      if(id == "TXXX")
        frame = UserTextIdentificationFrame::find(this, description);
      else if(id == "WXXX")
        frame = UserUrlLinkFrame::find(this, description);
      else if(id == "COMM")
        frame = CommentsFrame::findByDescription(this, description);
      else if(id == "USLT")
        frame = UnsynchronizedLyricsFrame::findByDescription(this, description);
      else if(id == "UFID")
        frame = UniqueFileIdentifierFrame::findByOwner(this, description);
      if(frame)
        removeFrame(frame);
    }
  }
}
  Matrix<double> IsobaricQuantitationMethod::stringListToIsotopCorrectionMatrix_(const StringList& stringlist) const
  {
    // check the string list
    if (stringlist.size() != getNumberOfChannels())
    {
      throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("IsobaricQuantitationMethod: Invalid string representation of the isotope correction matrix. Expected ") + getNumberOfChannels() + " entries but got " + stringlist.size() + ".");
    }

    // create matrix to fill from stringlist
    Matrix<double> isotope_correction_matrix(getNumberOfChannels(), 4);

    // channel index
    Size channel_index = 0;

    // fill row-wise
    for (StringList::ConstIterator it = stringlist.begin(); it != stringlist.end(); ++it)
    {
      StringList corrections;
      it->split('/', corrections);
      if (corrections.size() != 4)
      {
        throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "IsobaricQuantitationMethod: Invalid entry in string representation of the isotope correction matrx. Expected four correction values separated by '/', got: '" + *it + "'");
      }

      // overwrite line in Matrix with custom values
      isotope_correction_matrix.setValue(channel_index, 0, corrections[0].toDouble());
      isotope_correction_matrix.setValue(channel_index, 1, corrections[1].toDouble());
      isotope_correction_matrix.setValue(channel_index, 2, corrections[2].toDouble());
      isotope_correction_matrix.setValue(channel_index, 3, corrections[3].toDouble());

      // increment channel index
      ++channel_index;
    }

    // compute frequency matrix based on the deviation matrix
    Matrix<double> channel_frequency(getNumberOfChannels(), getNumberOfChannels());

    // matrix element i, j == what contributes channel i to the intensity of channel j
    for (Size contributing_channel = 0; contributing_channel < getNumberOfChannels(); ++contributing_channel)
    {
      for (Size target_channel = 0; target_channel < getNumberOfChannels(); ++target_channel)
      {
        // as the isotope_correction_matrix encodes what channel i contributes to theoretical -2/-1/+1/+2 channels
        // hence we check if the target_channel corresponds to the contributing_channel -2/-1/+1/+2
        // if yes, we assign the corresponding contribution
        // contribution to itself is handled separately
        if ((getChannelInformation()[contributing_channel].name - 2) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 0) / 100);
        }
        else if ((getChannelInformation()[contributing_channel].name - 1) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 1) / 100);
        }
        else if ((getChannelInformation()[contributing_channel].name + 1) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 2) / 100);
        }
        else if ((getChannelInformation()[contributing_channel].name + 2) == getChannelInformation()[target_channel].name)
        {
          channel_frequency.setValue(target_channel, contributing_channel, isotope_correction_matrix.getValue(contributing_channel, 3) / 100);
        }
        else if (target_channel == contributing_channel)
        {
          double self_contribution = 100.0;
          for (Size column_idx = 0; column_idx < 4; ++column_idx)
          {
            self_contribution -= isotope_correction_matrix.getValue(contributing_channel, column_idx);
          }
          channel_frequency.setValue(contributing_channel, contributing_channel, (self_contribution / 100));
        }
      }
    }

    return channel_frequency;
  }