예제 #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
Result SoundSourceSndFile::parseHeader()
{
    QString location = getFilename();
    setType(location.section(".",-1).toLower());

    bool is_flac = location.endsWith("flac", Qt::CaseInsensitive);
    bool is_wav = location.endsWith("wav", Qt::CaseInsensitive);
    QByteArray qBAFilename = getFilename().toLocal8Bit();

    if (is_flac) {
        TagLib::FLAC::File f(qBAFilename.constData());
        if (!readFileHeader(this, f)) {
            return ERR;
        }
        TagLib::Ogg::XiphComment* xiph = f.xiphComment();
        if (xiph) {
            readXiphComment(this, *xiph);
        }
        else {
            TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag());
            if (id3v2) {
                readID3v2Tag(this, *id3v2);
            } else {
                // fallback
                const TagLib::Tag *tag(f.tag());
                if (tag) {
                    readTag(this, *tag);
                } else {
                    return ERR;
                }
            }
        }
    } else if (is_wav) {
        TagLib::RIFF::WAV::File f(qBAFilename.constData());
        if (!readFileHeader(this, f)) {
            return ERR;
        }
        TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag());
        if (id3v2) {
            readID3v2Tag(this, *id3v2);
        } else {
            // fallback
            const TagLib::Tag *tag(f.tag());
            if (tag) {
                readTag(this, *tag);
            } else {
                return ERR;
            }
        }

        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 (fh == NULL) {
                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());
        if (!readFileHeader(this, f)) {
            return ERR;
        }
        TagLib::ID3v2::Tag *id3v2(f.tag());
        if (id3v2) {
            readID3v2Tag(this, *id3v2);
        } else {
            return ERR;
        }
    }

    return OK;
}