Example #1
0
int SoundSourceFLAC::parseHeader() {
    setType("flac");
#ifdef __WINDOWS__
    /* From Tobias: A Utf-8 string did not work on my Windows XP (German edition)
     * If you try this conversion, f.isValid() will return false in many cases
     * and processTaglibFile() will fail
     *
     * The method toLocal8Bit() returns the local 8-bit representation of the string as a QByteArray.
     * The returned byte array is undefined if the string contains characters not supported
     * by the local 8-bit encoding.
     */
    QByteArray qBAFilename = m_qFilename.toLocal8Bit();
#else
    QByteArray qBAFilename = m_qFilename.toUtf8();
#endif
    TagLib::FLAC::File f(qBAFilename.constData());
    bool result = processTaglibFile(f);
    TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag());
    TagLib::Ogg::XiphComment *xiph(f.xiphComment());
    if (id3v2) {
        processID3v2Tag(id3v2);
    }
    if (xiph) {
        processXiphComment(xiph);
    }
    return result ? OK : ERR;
}
Example #2
0
int SoundSourceCoreAudio::parseHeader() {
    if (getFilename().endsWith(".m4a"))
        setType("m4a");
    else if (getFilename().endsWith(".mp3"))
        setType("mp3");
    else if (getFilename().endsWith(".mp2"))
        setType("mp2");

    bool result = false;

    if (getType() == "m4a") {
        // No need for toLocal8Bit on Windows since CoreAudio is OS X only.
        TagLib::MP4::File f(getFilename().toUtf8().constData());
        result = processTaglibFile(f);
        TagLib::MP4::Tag* tag = f.tag();
        if (tag) {
            processMP4Tag(tag);
        }
    } else if (getType() == "mp3") {
        // No need for toLocal8Bit on Windows since CoreAudio is OS X only.
        TagLib::MPEG::File f(getFilename().toUtf8().constData());

        // Takes care of all the default metadata
        result = processTaglibFile(f);

        // Now look for MP3 specific metadata (e.g. BPM)
        TagLib::ID3v2::Tag* id3v2 = f.ID3v2Tag();
        if (id3v2) {
            processID3v2Tag(id3v2);
        }

        TagLib::APE::Tag *ape = f.APETag();
        if (ape) {
            processAPETag(ape);
        }
    } else if (getType() == "mp2") {
        //TODO: MP2 metadata. Does anyone use mp2 files anymore?
        //      Feels like 1995 again...
    }


    if (result)
        return OK;
    return ERR;
}
Example #3
0
Result SoundSourceFLAC::parseHeader() {
    setType("flac");
    QByteArray qBAFilename = m_qFilename.toLocal8Bit();
    TagLib::FLAC::File f(qBAFilename.constData());
    bool result = processTaglibFile(f);
    TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag());
    TagLib::Ogg::XiphComment *xiph(f.xiphComment());
    if (id3v2) {
        processID3v2Tag(id3v2);
    }
    if (xiph) {
        processXiphComment(xiph);
    }

    return result ? OK : ERR;
}
Example #4
0
/*
   Parse the the file to get metadata
 */
int SoundSourceOggVorbis::parseHeader() {
    setType("ogg");
    QByteArray qBAFilename = m_qFilename.toLocal8Bit();
    TagLib::Ogg::Vorbis::File f(qBAFilename.constData());

    // Takes care of all the default metadata
    bool result = processTaglibFile(f);


    TagLib::Ogg::XiphComment *tag = f.tag();

    if (tag) {
        processXiphComment(tag);
    }

    return result ? OK : ERR;
}
int SoundSourceMediaFoundation::parseHeader()
{
    setType("m4a");

    // Must be toLocal8Bit since Windows fopen does not do UTF-8
    TagLib::MP4::File f(getFilename().toLocal8Bit().constData());
    bool result = processTaglibFile(f);
    TagLib::MP4::Tag* tag = f.tag();

    if (tag) {
        processMP4Tag(tag);
    }

    if (result)
        return OK;
    return ERR;
}
Example #6
0
/*
   Parse the the file to get metadata
 */
Result SoundSourceOpus::parseHeader() {
    int error = 0;

    QByteArray qBAFilename = m_qFilename.toLocal8Bit();

    OggOpusFile *l_ptrOpusFile = op_open_file(qBAFilename.constData(), &error);
    this->setBitrate((int)op_bitrate(l_ptrOpusFile, -1) / 1000);
    this->setSampleRate(48000);
    this->setChannels(2);
    qint64 l_lLength = op_pcm_total(l_ptrOpusFile, -1) * 2;
    this->setDuration(l_lLength / (48000 * 2));
    this->setType("opus");

// If we don't have new enough Taglib we use libopusfile parser!
#if (TAGLIB_MAJOR_VERSION >= 1) && (TAGLIB_MINOR_VERSION >= 9)
    TagLib::Ogg::Opus::File f(qBAFilename.constData());

    // Takes care of all the default metadata
    bool result = processTaglibFile(f);

    TagLib::Ogg::XiphComment *tag = f.tag();

    if (tag) {
        processXiphComment(tag);
    }
#else
    // From Taglib 1.9.x Opus is supported
    // Before that we have parse tags by this code
    int i = 0;
    const OpusTags *l_ptrOpusTags = op_tags(l_ptrOpusFile, -1);


    // This is left for debug reasons !!
    // qDebug() << "opus: We have " << l_ptrOpusTags->comments;
    for( i = 0; i < l_ptrOpusTags->comments; i ++){
      QString l_SWholeTag = QString(l_ptrOpusTags->user_comments[i]);
      QString l_STag = l_SWholeTag.left(l_SWholeTag.indexOf("="));
      QString l_SPayload = l_SWholeTag.right((l_SWholeTag.length() - l_SWholeTag.indexOf("=")) - 1);

      if (!l_STag.compare("ARTIST") ) {
            this->setArtist(l_SPayload);
      } else if (!l_STag.compare("ALBUM")) {
            this->setAlbum(l_SPayload);
      } else if (!l_STag.compare("BPM")) {
            this->setBPM(l_SPayload.toFloat());
      } else if (!l_STag.compare("YEAR") || !l_STag.compare("DATE")) {
            this->setYear(l_SPayload);
      } else if (!l_STag.compare("GENRE")) {
            this->setGenre(l_SPayload);
      } else if (!l_STag.compare("TRACKNUMBER")) {
            this->setTrackNumber(l_SPayload);
      } else if (!l_STag.compare("COMPOSER")) {
            this->setComposer(l_SPayload);
      } else if (!l_STag.compare("ALBUMARTIST")) {
            this->setAlbumArtist(l_SPayload);
      } else if (!l_STag.compare("TITLE")) {
            this->setTitle(l_SPayload);
      } else if (!l_STag.compare("REPLAYGAIN_TRACK_PEAK")) {
      } else if (!l_STag.compare("REPLAYGAIN_TRACK_GAIN")) {
            this->parseReplayGainString (l_SPayload);
      } else if (!l_STag.compare("REPLAYGAIN_ALBUM_PEAK")) {
      } else if (!l_STag.compare("REPLAYGAIN_ALBUM_GAIN")) {
      }

      // This is left fot debug reasons!!
      //qDebug() << "Comment" << i << l_ptrOpusTags->comment_lengths[i] <<
      //" (" << l_ptrOpusTags->user_comments[i] << ")" << l_STag << "*" << l_SPayload;
    }

    op_free(l_ptrOpusFile);
    return OK;
#endif


#if TAGLIB_MAJOR_VERSION >= 1 && TAGLIB_MINOR_VERSION >= 9
    return result ? OK : ERR;
#endif

}
Example #7
0
int SoundSourceSndFile::parseHeader()
{
    QString location = getFilename();
    setType(location.section(".",-1).toLower());

    bool result;
    bool is_flac = location.endsWith("flac", Qt::CaseInsensitive);
    bool is_wav = location.endsWith("wav", Qt::CaseInsensitive);

#ifdef __WINDOWS__
    /* From Tobias: A Utf-8 string did not work on my Windows XP (German edition)
     * If you try this conversion, f.isValid() will return false in many cases
     * and processTaglibFile() will fail
     *
     * The method toLocal8Bit() returns the local 8-bit representation of the string as a QByteArray.
     * The returned byte array is undefined if the string contains characters not supported
     * by the local 8-bit encoding.
     */
    QByteArray qBAFilename = m_qFilename.toLocal8Bit();
#else
    QByteArray qBAFilename = m_qFilename.toUtf8();
#endif

    if (is_flac) {
        TagLib::FLAC::File f(qBAFilename.constData());
        result = processTaglibFile(f);
        TagLib::ID3v2::Tag* id3v2 = f.ID3v2Tag();
        TagLib::Ogg::XiphComment* xiph = f.xiphComment();
        if (id3v2) {
            processID3v2Tag(id3v2);
        }
        if (xiph) {
            processXiphComment(xiph);
        }
    } else if (is_wav) {
        TagLib::RIFF::WAV::File f(qBAFilename.constData());
        result = processTaglibFile(f);

        TagLib::ID3v2::Tag* id3v2 = f.tag();
        if (id3v2) {
            processID3v2Tag(id3v2);
        }

        if (getDuration() <= 0) {
            // we're using a taglib version which doesn't know how to do wav
            // durations, set it with info from sndfile -bkgood
            // XXX remove this when ubuntu ships with an sufficiently
            // intelligent version of taglib, should happen in 11.10

            // Have to open the file for info to be valid.
            if (!m_bOpened) {
                open();
            }

            if (info->samplerate > 0) {
                setDuration(info->frames / info->samplerate);
            } else {
                qDebug() << "WARNING: WAV file with invalid samplerate."
                         << "Can't get duration using libsndfile.";
            }
        }
    } else {
        // Try AIFF
        TagLib::RIFF::AIFF::File f(qBAFilename.constData());
        result = processTaglibFile(f);

        TagLib::ID3v2::Tag* id3v2 = f.tag();
        if (id3v2) {
            processID3v2Tag(id3v2);
        }
    }

    return result ? OK : ERR;
}