예제 #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;
}
예제 #2
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;
}
예제 #3
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;
}
예제 #4
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;
}