From 362d4e2b4f57a39efeef52a3fd7b5dc432207c0a Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Tue, 22 Sep 2009 14:30:46 +0000 Subject: enabled flac plugin git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1246 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Input/cue/decoder_cue.h | 1 - src/plugins/Input/flac/CMakeLists.txt | 4 +- src/plugins/Input/flac/cueparser.cpp | 5 + src/plugins/Input/flac/cueparser.h | 1 + src/plugins/Input/flac/decoder_flac.cpp | 169 +++++++++++++-------- src/plugins/Input/flac/decoder_flac.h | 31 ++-- src/plugins/Input/flac/decoderflacfactory.cpp | 16 +- src/plugins/Input/flac/decoderflacfactory.h | 4 +- src/plugins/Input/flac/detailsdialog.cpp | 104 ------------- src/plugins/Input/flac/detailsdialog.h | 44 ------ src/plugins/Input/flac/flac.pro | 8 +- src/plugins/Input/flac/flacmetadatamodel.cpp | 155 +++++++++++++++++++ src/plugins/Input/flac/flacmetadatamodel.h | 57 +++++++ .../Input/flac/translations/flac_plugin_cs.ts | 64 ++++---- .../Input/flac/translations/flac_plugin_de.ts | 64 ++++---- .../Input/flac/translations/flac_plugin_it.ts | 54 +++---- .../Input/flac/translations/flac_plugin_lt.ts | 52 +++---- .../Input/flac/translations/flac_plugin_pl.ts | 62 ++++---- .../Input/flac/translations/flac_plugin_ru.ts | 52 +++---- .../Input/flac/translations/flac_plugin_tr.ts | 54 +++---- .../Input/flac/translations/flac_plugin_uk_UA.ts | 64 ++++---- .../Input/flac/translations/flac_plugin_zh_CN.ts | 52 +++---- .../Input/flac/translations/flac_plugin_zh_TW.ts | 52 +++---- 23 files changed, 592 insertions(+), 577 deletions(-) delete mode 100644 src/plugins/Input/flac/detailsdialog.cpp delete mode 100644 src/plugins/Input/flac/detailsdialog.h create mode 100644 src/plugins/Input/flac/flacmetadatamodel.cpp create mode 100644 src/plugins/Input/flac/flacmetadatamodel.h diff --git a/src/plugins/Input/cue/decoder_cue.h b/src/plugins/Input/cue/decoder_cue.h index 6ff6e85a1..cb77e2c3c 100644 --- a/src/plugins/Input/cue/decoder_cue.h +++ b/src/plugins/Input/cue/decoder_cue.h @@ -50,7 +50,6 @@ private: qint64 length_in_bytes; qint64 m_totalBytes; QString m_path; - QString m_nextURL; CUEParser *m_parser; int m_track; char *m_buf; //buffer for remainig data diff --git a/src/plugins/Input/flac/CMakeLists.txt b/src/plugins/Input/flac/CMakeLists.txt index 5a4694d97..5585a747a 100644 --- a/src/plugins/Input/flac/CMakeLists.txt +++ b/src/plugins/Input/flac/CMakeLists.txt @@ -39,14 +39,14 @@ link_directories(${FLAC_LIBRARY_DIRS} ${TAGLIB_LIBRARY_DIRS}) SET(libflac_SRCS decoder_flac.cpp decoderflacfactory.cpp - detailsdialog.cpp + flacmetadatamodel.cpp cueparser.cpp ) SET(libflac_MOC_HDRS decoderflacfactory.h decoder_flac.h - detailsdialog.h + flacmetadatamodel.h cueparser.h ) diff --git a/src/plugins/Input/flac/cueparser.cpp b/src/plugins/Input/flac/cueparser.cpp index 873beb7b5..9272cec19 100644 --- a/src/plugins/Input/flac/cueparser.cpp +++ b/src/plugins/Input/flac/cueparser.cpp @@ -152,6 +152,11 @@ FileInfo *CUEParser::info(int track) return &m_infoList[track - 1]; } +const QString CUEParser::trackURL(int track) +{ + return m_infoList[track - 1].path(); +} + QStringList CUEParser::splitLine(const QString &line) { //qDebug("row string = %s",qPrintable(line)); diff --git a/src/plugins/Input/flac/cueparser.h b/src/plugins/Input/flac/cueparser.h index b30b87bfa..7491cf05d 100644 --- a/src/plugins/Input/flac/cueparser.h +++ b/src/plugins/Input/flac/cueparser.h @@ -45,6 +45,7 @@ public: qint64 length(int track); int count(); FileInfo *info(int track); + const QString trackURL(int track); private: QString m_filePath; diff --git a/src/plugins/Input/flac/decoder_flac.cpp b/src/plugins/Input/flac/decoder_flac.cpp index 9c104d5ec..ff865a68b 100644 --- a/src/plugins/Input/flac/decoder_flac.cpp +++ b/src/plugins/Input/flac/decoder_flac.cpp @@ -257,15 +257,20 @@ static void flac_callback_error (const FLAC__StreamDecoder *, // Decoder class -DecoderFLAC::DecoderFLAC(QObject *parent, DecoderFactory *d, QIODevice *i, Output *o, const QString &path) - : Decoder(parent, d, i, o) +DecoderFLAC::DecoderFLAC(const QString &path, QIODevice *i) + : Decoder(i) { m_data = 0; m_path = path; m_data = new flac_data; m_data->decoder = NULL; data()->input = i; - m_cue_parser = 0; + m_parser = 0; + length_in_bytes = 0; + m_totalBytes = 0; + m_sz = 0; + m_buf = 0; + m_offset = 0; } @@ -279,6 +284,9 @@ DecoderFLAC::~DecoderFLAC() delete data(); m_data = 0; } + if(m_buf) + delete[] m_buf; + m_buf = 0; } bool DecoderFLAC::initialize() @@ -303,26 +311,18 @@ bool DecoderFLAC::initialize() if (xiph_comment && xiph_comment->fieldListMap().contains("CUESHEET")) { qDebug("DecoderFLAC: using cuesheet xiph comment."); - m_cue_parser = new CUEParser(xiph_comment->fieldListMap()["CUESHEET"].toString() + m_parser = new CUEParser(xiph_comment->fieldListMap()["CUESHEET"].toString() .toCString(TRUE), p); - int track = m_path.section("#", -1).toInt(); - if(track > m_cue_parser->count()) + m_track = m_path.section("#", -1).toInt(); + if(m_track > m_parser->count()) { qWarning("DecoderFLAC: invalid cuesheet xiph comment"); return FALSE; } data()->input = new QFile(p); - //send metadata - QMap metaData = m_cue_parser->info(track)->metaData(); - StateHandler::instance()->dispatch(metaData); - - connect(stateHandler(),SIGNAL(aboutToFinish()),SLOT(processFinish())); - //next url - m_nextUrl.clear(); - if(track <= m_cue_parser->count() - 1) - m_nextUrl = m_cue_parser->info(track + 1)->path(); - m_totalTime = m_cue_parser->length(track); - setFragment(m_cue_parser->offset(track), m_cue_parser->length(track)); + data()->input->open(QIODevice::ReadOnly); + QMap metaData = m_parser->info(m_track)->metaData(); + StateHandler::instance()->dispatch(metaData); //send metadata } else { @@ -339,19 +339,10 @@ bool DecoderFLAC::initialize() if (!data()->input->isOpen()) { - if (!data()->input->open(QIODevice::ReadOnly)) - { - return FALSE; - } + qWarning("DecoderFLAC: unable to open input file"); + return FALSE; } - if (! data()->input->isOpen()) - { - if (! data()->input->open(QIODevice::ReadOnly)) - { - return FALSE; - } - } m_data->bitrate = -1; m_data->abort = 0; m_data->sample_buffer_fill = 0; @@ -388,8 +379,18 @@ bool DecoderFLAC::initialize() configure(data()->sample_rate, data()->channels, 32); else configure(data()->sample_rate, data()->channels, data()->bits_per_sample); - if(!m_cue_parser) - m_totalTime = data()->length; + + if(m_parser) + { + m_length = m_parser->length(m_track); + m_offset = m_parser->offset(m_track); + length_in_bytes = audioParameters().sampleRate() * + audioParameters().channels() * + audioParameters().bits() * m_length/8000; + seek(0); + } + m_totalBytes = 0; + m_sz = audioParameters().bits() * audioParameters().channels()/8; qDebug("DecoderFLAC: initialize succes"); return TRUE; @@ -397,7 +398,9 @@ bool DecoderFLAC::initialize() qint64 DecoderFLAC::totalTime() { - return m_totalTime; + if(m_parser) + return m_length; + return data()->length; } int DecoderFLAC::bitrate() @@ -405,16 +408,65 @@ int DecoderFLAC::bitrate() return data()->bitrate; } -void DecoderFLAC::seekAudio(qint64 time) +void DecoderFLAC::seek(qint64 time) { + m_totalBytes = audioParameters().sampleRate() * + audioParameters().channels() * + audioParameters().bits() * time/8000; + if(m_parser) + time += m_offset; FLAC__uint64 target_sample; - target_sample = (FLAC__uint64)((time/(double)data()->length) * (double)data()->total_samples); + target_sample = (FLAC__uint64)(((time) * data()->total_samples /data()->length)); FLAC__stream_decoder_seek_absolute(data()->decoder, target_sample); + } -qint64 DecoderFLAC::readAudio(char *data, qint64 maxSize) +qint64 DecoderFLAC::read(char *data, qint64 size) { - return flac_decode (this, (char *) (data), maxSize); + if(m_parser) + { + if(length_in_bytes - m_totalBytes < m_sz) //end of cue track + return 0; + + qint64 len = 0; + + if(m_buf) //read remaining data first + { + len = qMin(m_buf_size, size); + memmove(data, m_buf, len); + if(size >= m_buf_size) + { + delete[] m_buf; + m_buf = 0; + m_buf_size = 0; + } + else + memmove(m_buf, m_buf + len, size - len); + } + else + len = flac_decode (this, data, size); + + if(len <= 0) //end of file + return 0; + + if(len + m_totalBytes <= length_in_bytes) + { + m_totalBytes += len; + return len; + } + + qint64 len2 = qMax(qint64(0), length_in_bytes - m_totalBytes); + len2 = (len2 / m_sz) * m_sz; //returned size must contain integer number of samples + m_totalBytes += len2; + //save data of the next track + if(m_buf) + delete[] m_buf; + m_buf_size = len - len2; + m_buf = new char[m_buf_size]; + memmove(m_buf, data + len2, m_buf_size); + return len2; + } + return flac_decode (this, data, size); } void DecoderFLAC::deinit() @@ -428,35 +480,30 @@ void DecoderFLAC::deinit() delete data()->input; data()->input = 0; }; - if(m_cue_parser) - delete m_cue_parser; - m_cue_parser = 0; + if(m_parser) + delete m_parser; + m_parser = 0; +} + +const QString DecoderFLAC::nextURL() +{ + if(m_parser && m_track +1 <= m_parser->count()) + return m_parser->trackURL(m_track + 1); + else + return QString(); } -void DecoderFLAC::processFinish() +void DecoderFLAC::next() { - if(m_cue_parser && nextUrlRequest(m_nextUrl)) + if(m_parser && m_track +1 <= m_parser->count()) { - qDebug("DecoderFLAC: going to next track"); - int track = m_nextUrl.section("#", -1).toInt(); - QString p = QUrl(m_nextUrl).path(); - p.replace(QString(QUrl::toPercentEncoding("#")), "#"); - p.replace(QString(QUrl::toPercentEncoding("%")), "%"); - //update current fragment - mutex()->lock(); - setFragment(m_cue_parser->offset(track), m_cue_parser->length(track)); - m_totalTime = m_cue_parser->length(track); - output()->seek(0); //reset time counter - mutex()->unlock(); - // find next track - m_nextUrl.clear(); - if(track <= m_cue_parser->count() - 1) - m_nextUrl = m_cue_parser->info(track + 1)->path(); - //change track - emit playbackFinished(); - //send metadata - QMap metaData = m_cue_parser->info(track)->metaData(); - stateHandler()->dispatch(metaData); + m_track++; + m_offset = m_parser->length(m_track); + m_length = m_parser->length(m_track); + length_in_bytes = audioParameters().sampleRate() * + audioParameters().channels() * + audioParameters().bits() * m_length/8000; + StateHandler::instance()->dispatch(m_parser->info(m_track)->metaData()); + m_totalBytes = 0; } } - diff --git a/src/plugins/Input/flac/decoder_flac.h b/src/plugins/Input/flac/decoder_flac.h index a00860ec4..ea66a652f 100644 --- a/src/plugins/Input/flac/decoder_flac.h +++ b/src/plugins/Input/flac/decoder_flac.h @@ -25,9 +25,8 @@ #include -#define MAX_SUPPORTED_CHANNELS 2 - -#define SAMPLES_PER_WRITE 512 +#define MAX_SUPPORTED_CHANNELS 2 +#define SAMPLES_PER_WRITE 512 #define SAMPLE_BUFFER_SIZE ((FLAC__MAX_BLOCK_SIZE + SAMPLES_PER_WRITE) * MAX_SUPPORTED_CHANNELS * (32/8)) class CUEParser; @@ -60,40 +59,44 @@ struct flac_data class DecoderFLAC : public Decoder { -Q_OBJECT public: - DecoderFLAC(QObject *, DecoderFactory *, QIODevice *, Output *, const QString &path); + DecoderFLAC(const QString &path, QIODevice *i); virtual ~DecoderFLAC(); // Standard Decoder API bool initialize(); qint64 totalTime(); int bitrate(); + qint64 read(char *data, qint64 maxSize); + void seek(qint64 time); + const QString nextURL(); + void next(); struct flac_data *data() { return m_data; } -private slots: - void processFinish(); - private: - // Standard Decoder API - qint64 readAudio(char *data, qint64 maxSize); - void seekAudio(qint64 time); - struct flac_data *m_data; // helper functions void deinit(); // FLAC Decoder FLAC__StreamDecoder *m_flacDecoder; + struct flac_data *m_data; qint64 m_totalTime; + qint64 length_in_bytes; + qint64 m_totalBytes; + qint64 m_offset; + qint64 m_length; QString m_path; - CUEParser *m_cue_parser; - QString m_nextUrl; + CUEParser *m_parser; + int m_track; + char *m_buf; //buffer for remainig data + qint64 m_buf_size; + qint64 m_sz; //sample size }; diff --git a/src/plugins/Input/flac/decoderflacfactory.cpp b/src/plugins/Input/flac/decoderflacfactory.cpp index 54224eeab..af1f1ad86 100644 --- a/src/plugins/Input/flac/decoderflacfactory.cpp +++ b/src/plugins/Input/flac/decoderflacfactory.cpp @@ -26,8 +26,8 @@ #include #include "cueparser.h" -#include "detailsdialog.h" #include "decoder_flac.h" +#include "flacmetadatamodel.h" #include "decoderflacfactory.h" @@ -35,7 +35,6 @@ bool DecoderFLACFactory::supports(const QString &source) const { - return (source.right(5).toLower() == ".flac"); } @@ -59,10 +58,9 @@ const DecoderProperties DecoderFLACFactory::properties() const return properties; } -Decoder *DecoderFLACFactory::create(QObject *parent, QIODevice *input, - Output *output, const QString &path) +Decoder *DecoderFLACFactory::create(const QString &path, QIODevice *i) { - return new DecoderFLAC(parent, this, input, output, path); + return new DecoderFLAC(path, i); } QList DecoderFLACFactory::createPlayList(const QString &fileName, bool useMetaData) @@ -120,11 +118,9 @@ QList DecoderFLACFactory::createPlayList(const QString &fileName, bo return list; } -QObject* DecoderFLACFactory::showDetails(QWidget *parent, const QString &path) +MetaDataModel*DecoderFLACFactory::createMetaDataModel(const QString &path, QObject *parent) { - DetailsDialog *d = new DetailsDialog(parent, path); - d -> show(); - return d; + return new FLACMetaDataModel(path, parent); } void DecoderFLACFactory::showSettings(QWidget *) @@ -145,4 +141,4 @@ QTranslator *DecoderFLACFactory::createTranslator(QObject *parent) return translator; } -Q_EXPORT_PLUGIN(DecoderFLACFactory) +Q_EXPORT_PLUGIN2(flac,DecoderFLACFactory) diff --git a/src/plugins/Input/flac/decoderflacfactory.h b/src/plugins/Input/flac/decoderflacfactory.h index 7fd7dcb42..696fe6208 100644 --- a/src/plugins/Input/flac/decoderflacfactory.h +++ b/src/plugins/Input/flac/decoderflacfactory.h @@ -39,9 +39,9 @@ public: bool supports(const QString &source) const; bool canDecode(QIODevice *input) const; const DecoderProperties properties() const; - Decoder *create(QObject *, QIODevice *, Output *, const QString &); + Decoder *create(const QString &, QIODevice *); QList createPlayList(const QString &fileName, bool useMetaData); - QObject* showDetails(QWidget *parent, const QString &path); + MetaDataModel* createMetaDataModel(const QString &path, QObject *parent = 0); void showSettings(QWidget *parent); void showAbout(QWidget *parent); QTranslator *createTranslator(QObject *parent); diff --git a/src/plugins/Input/flac/detailsdialog.cpp b/src/plugins/Input/flac/detailsdialog.cpp deleted file mode 100644 index a3740b3f9..000000000 --- a/src/plugins/Input/flac/detailsdialog.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2009 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#include -#include -#include -#include -#include - -#include -#include - -#include "detailsdialog.h" - -#define QStringToTString_qt4(s) TagLib::String(s.toUtf8().constData(), TagLib::String::UTF8) -#define TStringToQString_qt4(s) QString::fromUtf8(s.toCString(TRUE)).trimmed() - -DetailsDialog::DetailsDialog(QWidget *parent, const QString &path) - : AbstractDetailsDialog(parent) -{ - m_path = path; - if (QFile::exists(m_path)) - { - loadFLACInfo(); - loadTags(); - blockSaveButton(!QFileInfo(m_path).isWritable()); - } - else - blockSaveButton(); -} - -DetailsDialog::~DetailsDialog() -{} - -void DetailsDialog::loadFLACInfo() -{ - TagLib::FLAC::File f (m_path.toLocal8Bit()); - QMap ap; - QString text = QString("%1").arg(f.audioProperties()->length()/60); - text +=":"+QString("%1").arg(f.audioProperties()->length()%60,2,10,QChar('0')); - ap.insert(tr("Length"), text); - ap.insert(tr("Sample rate"), QString("%1 " + tr("Hz")).arg(f.audioProperties()->sampleRate())); - ap.insert(tr("Channels"), QString("%1").arg(f.audioProperties()->channels())); - ap.insert(tr("Bitrate"), QString("%1 " + tr("kbps")).arg(f.audioProperties()->bitrate())); - ap.insert(tr("Sample width"), QString("%1 "+tr("bits")).arg(f.audioProperties()->sampleWidth())); - ap.insert(tr("File size"), QString("%1 "+tr("KB")).arg(f.length()/1024)); - setAudioProperties(ap); -} - -void DetailsDialog::loadTags() -{ - TagLib::FileRef f (m_path.toLocal8Bit()); - setMetaData(Qmmp::TITLE, TStringToQString_qt4(f.tag()->title())); - setMetaData(Qmmp::ARTIST, TStringToQString_qt4(f.tag()->artist())); - setMetaData(Qmmp::ALBUM, TStringToQString_qt4(f.tag()->album())); - setMetaData(Qmmp::COMMENT, TStringToQString_qt4(f.tag()->comment())); - setMetaData(Qmmp::GENRE, TStringToQString_qt4(f.tag()->genre())); - setMetaData(Qmmp::YEAR, f.tag()->year()); - setMetaData(Qmmp::TRACK, f.tag()->track()); - setMetaData(Qmmp::URL, m_path); - TagLib::FLAC::File *file = dynamic_cast< TagLib::FLAC::File *>(f.file()); - TagLib::StringList fld; - if(file->xiphComment() && !(fld = file->xiphComment()->fieldListMap()["COMPOSER"]).isEmpty()) - setMetaData(Qmmp::COMPOSER, TStringToQString_qt4(fld.toString())); - if(file->xiphComment() && !(fld = file->xiphComment()->fieldListMap()["DISCNUMBER"]).isEmpty()) - setMetaData(Qmmp::DISCNUMBER, TStringToQString_qt4(fld.toString())); -} - -void DetailsDialog::writeTags() -{ - TagLib::FileRef f (m_path.toLocal8Bit()); - f.tag()->setTitle(QStringToTString_qt4(strMetaData(Qmmp::TITLE))); - f.tag()->setArtist(QStringToTString_qt4(strMetaData(Qmmp::ARTIST))); - f.tag()->setAlbum(QStringToTString_qt4(strMetaData(Qmmp::ALBUM))); - f.tag()->setComment(QStringToTString_qt4(strMetaData(Qmmp::COMMENT))); - f.tag()->setGenre(QStringToTString_qt4(strMetaData(Qmmp::GENRE))); - f.tag()->setYear(intMetaData(Qmmp::YEAR)); - f.tag()->setTrack(intMetaData(Qmmp::TRACK)); - TagLib::FLAC::File *file = dynamic_cast< TagLib::FLAC::File *>(f.file()); - strMetaData(Qmmp::COMPOSER).isEmpty() ? - file->xiphComment()->removeField("COMPOSER"): - file->xiphComment()->addField("COMPOSER", QStringToTString_qt4(strMetaData(Qmmp::COMPOSER)), TRUE); - intMetaData(Qmmp::DISCNUMBER) == 0 ? - file->xiphComment()->removeField("DISCNUMBER"): - file->xiphComment()->addField("DISCNUMBER", - QStringToTString_qt4(strMetaData(Qmmp::DISCNUMBER)), TRUE); - f.save(); -} diff --git a/src/plugins/Input/flac/detailsdialog.h b/src/plugins/Input/flac/detailsdialog.h deleted file mode 100644 index 97069306a..000000000 --- a/src/plugins/Input/flac/detailsdialog.h +++ /dev/null @@ -1,44 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2009 by Ilya Kotov * - * forkotov02@hotmail.ru * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef DETAILSDIALOG_H -#define DETAILSDIALOG_H - -#include - -/** - @author Ilya Kotov -*/ -class DetailsDialog : public AbstractDetailsDialog -{ -Q_OBJECT -public: - DetailsDialog(QWidget *parent = 0, const QString &path = 0); - - ~DetailsDialog(); - -private: - void loadFLACInfo(); - void loadTags(); - void writeTags(); - QString m_path; - -}; - -#endif diff --git a/src/plugins/Input/flac/flac.pro b/src/plugins/Input/flac/flac.pro index 3f13de9c0..7a8573c38 100644 --- a/src/plugins/Input/flac/flac.pro +++ b/src/plugins/Input/flac/flac.pro @@ -2,12 +2,12 @@ include(../../plugins.pri) FORMS += HEADERS += decoderflacfactory.h \ decoder_flac.h \ - detailsdialog.h \ - cueparser.h + cueparser.h \ + flacmetadatamodel.h SOURCES += decoder_flac.cpp \ decoderflacfactory.cpp \ - detailsdialog.cpp \ - cueparser.cpp + cueparser.cpp \ + flacmetadatamodel.cpp TARGET = $$PLUGINS_PREFIX/Input/flac QMAKE_CLEAN = $$PLUGINS_PREFIX/Input/libflac.so INCLUDEPATH += ../../../ diff --git a/src/plugins/Input/flac/flacmetadatamodel.cpp b/src/plugins/Input/flac/flacmetadatamodel.cpp new file mode 100644 index 000000000..d18048f29 --- /dev/null +++ b/src/plugins/Input/flac/flacmetadatamodel.cpp @@ -0,0 +1,155 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include +#include +#include "flacmetadatamodel.h" + +#define QStringToTString_qt4(s) TagLib::String(s.toUtf8().constData(), TagLib::String::UTF8) +#define TStringToQString_qt4(s) QString::fromUtf8(s.toCString(TRUE)).trimmed() + +FLACMetaDataModel::FLACMetaDataModel(const QString &path, QObject *parent) : MetaDataModel(parent) +{ + m_path = path; + m_tags << new VorbisCommentModel(path); +} + +FLACMetaDataModel::~FLACMetaDataModel() +{ + while(!m_tags.isEmpty()) + delete m_tags.takeFirst(); +} + +QHash FLACMetaDataModel::audioProperties() +{ + QHash ap; + TagLib::FLAC::File f (m_path.toLocal8Bit()); + QString text = QString("%1").arg(f.audioProperties()->length()/60); + text +=":"+QString("%1").arg(f.audioProperties()->length()%60,2,10,QChar('0')); + ap.insert(tr("Length"), text); + ap.insert(tr("Sample rate"), QString("%1 " + tr("Hz")).arg(f.audioProperties()->sampleRate())); + ap.insert(tr("Channels"), QString("%1").arg(f.audioProperties()->channels())); + ap.insert(tr("Bitrate"), QString("%1 " + tr("kbps")).arg(f.audioProperties()->bitrate())); + ap.insert(tr("File size"), QString("%1 "+tr("KB")).arg(f.length()/1024)); + return ap; +} + +QList FLACMetaDataModel::tags() +{ + return m_tags; +} + +VorbisCommentModel::VorbisCommentModel(const QString &path) : TagModel(TagModel::Save) +{ + m_file = new TagLib::FLAC::File (path.toLocal8Bit().constData()); + m_tag = m_file->xiphComment(); +} + +VorbisCommentModel::~VorbisCommentModel() +{ + delete m_file; +} + +const QString VorbisCommentModel::name() +{ + return "Vorbis Comment"; +} + +const QString VorbisCommentModel::value(Qmmp::MetaData key) +{ + if(!m_tag) + return QString(); + switch((int) key) + { + case Qmmp::TITLE: + return TStringToQString_qt4(m_tag->title()); + case Qmmp::ARTIST: + return TStringToQString_qt4(m_tag->artist()); + case Qmmp::ALBUM: + return TStringToQString_qt4(m_tag->album()); + case Qmmp::COMMENT: + return TStringToQString_qt4(m_tag->comment()); + case Qmmp::GENRE: + return TStringToQString_qt4(m_tag->genre()); + case Qmmp::COMPOSER: + if(m_tag->fieldListMap()["COMPOSER"].isEmpty()) + return QString(); + else + return TStringToQString_qt4(m_tag->fieldListMap()["COMPOSER"].front()); + case Qmmp::YEAR: + return QString::number(m_tag->year()); + case Qmmp::TRACK: + return QString::number(m_tag->track()); + case Qmmp::DISCNUMBER: + if(m_tag->fieldListMap()["DISCNUMBER"].isEmpty()) + return QString(); + else + return TStringToQString_qt4(m_tag->fieldListMap()["DISCNUMBER"].front()); + } + return QString(); +} + +void VorbisCommentModel::setValue(Qmmp::MetaData key, const QString &value) +{ + if(!m_tag) + return; + + TagLib::String str = QStringToTString_qt4(value); + + switch((int) key) + { + case Qmmp::TITLE: + m_tag->setTitle(str); + return; + case Qmmp::ARTIST: + m_tag->setArtist(str); + return; + case Qmmp::ALBUM: + m_tag->setAlbum(str); + return; + case Qmmp::COMMENT: + m_tag->setComment(str); + return; + case Qmmp::GENRE: + m_tag->setGenre(str); + return; + case Qmmp::COMPOSER: + value.isEmpty() ? + m_tag->removeField("COMPOSER"): + m_tag->addField("COMPOSER", str, TRUE); + return; + case Qmmp::TRACK: + m_tag->setTrack(value.toInt()); + return; + case Qmmp::YEAR: + m_tag->setYear(value.toInt()); + return; + case Qmmp::DISCNUMBER: + value == "0" ? + m_tag->removeField("DISCNUMBER"): + m_tag->addField("DISCNUMBER", str, TRUE); + } +} + +void VorbisCommentModel::save() +{ + m_file->save(); +} diff --git a/src/plugins/Input/flac/flacmetadatamodel.h b/src/plugins/Input/flac/flacmetadatamodel.h new file mode 100644 index 000000000..4a5310c90 --- /dev/null +++ b/src/plugins/Input/flac/flacmetadatamodel.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef FLACMETADATAMODEL_H +#define FLACMETADATAMODEL_H + +#include +#include +#include + +class FLACMetaDataModel : public MetaDataModel +{ +Q_OBJECT +public: + FLACMetaDataModel(const QString &path, QObject *parent); + ~FLACMetaDataModel(); + QHash audioProperties(); + QList tags(); + +private: + QString m_path; + QList m_tags; +}; + +class VorbisCommentModel : public TagModel +{ +public: + VorbisCommentModel(const QString &path); + ~VorbisCommentModel(); + const QString name(); + const QString value(Qmmp::MetaData key); + void setValue(Qmmp::MetaData key, const QString &value); + void save(); + +private: + TagLib::FLAC::File *m_file; + TagLib::Ogg::XiphComment *m_tag; +}; + +#endif // FLACMETADATAMODEL_H diff --git a/src/plugins/Input/flac/translations/flac_plugin_cs.ts b/src/plugins/Input/flac/translations/flac_plugin_cs.ts index ad9443290..d1b2068d0 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_cs.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_cs.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin Modul FLAC - + FLAC Files Soubory FLAC - + About FLAC Audio Plugin O modulu FLAC - + Qmmp FLAC Audio Plugin Vstupní modul Qmmp FLAC - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autor: Ilja Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - - kbps - kbps - - - - Hz - Hz - - - + Length - Délka + Délka - + Sample rate - Vzorkovací frekvence + Vzorkovací frekvence - - Channels - Počet kanálů + + Hz + Hz - - Bitrate - Datový tok + + Channels + Počet kanálů - - Sample width - Šířka vzorku + + Bitrate + Datový tok - - KB - KB + + kbps + kbps - + File size - Velikost souboru + Velikost souboru - - bits - bitů + + KB + KB diff --git a/src/plugins/Input/flac/translations/flac_plugin_de.ts b/src/plugins/Input/flac/translations/flac_plugin_de.ts index 3987e5284..733872d4b 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_de.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_de.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin FLAC-Modul - + FLAC Files FLAC-Dateien - + About FLAC Audio Plugin Über FLAC-Audio-Modul - + Qmmp FLAC Audio Plugin Qmmp FLAC-Audio-Modul - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autor: Ilja Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - - kbps - kbps - - - - Hz - Hz - - - + Length - Länge + Länge - + Sample rate - Abtastrate + Abtastrate - - Channels - Kanäle + + Hz + Hz - - Bitrate - Bitrate + + Channels + Kanäle - - Sample width - Abtastauflösung + + Bitrate + Bitrate - - KB - KB + + kbps + kbps - + File size - Dateigröße + Dateigröße - - bits - Bits + + KB + KB diff --git a/src/plugins/Input/flac/translations/flac_plugin_it.ts b/src/plugins/Input/flac/translations/flac_plugin_it.ts index 1f6de5dca..511145393 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_it.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_it.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin Modulo FLAC - + FLAC Files Brani FLAC - + About FLAC Audio Plugin Info sul modulo audio FLAC - + Qmmp FLAC Audio Plugin Modulo Audio FLAC per Qmmp - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autore: Ilja Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - - kbps - kbps - - - - Hz - Hz - - - + Length - + Sample rate - - Channels - + + Hz + Hz - - Bitrate + + Channels - - Sample width + + Bitrate - - KB - KB + + kbps + kbps - + File size - - bits - Bits + + KB + KB diff --git a/src/plugins/Input/flac/translations/flac_plugin_lt.ts b/src/plugins/Input/flac/translations/flac_plugin_lt.ts index 38508cc5f..633d57ad8 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_lt.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_lt.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin FLAC įskiepis - + FLAC Files FLAC bylos - + About FLAC Audio Plugin Apie FLAC audio įskiepį - + Qmmp FLAC Audio Plugin Qmmp FLAC audio įskiepis - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Sukūrė: Ilya Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length - - Hz - Hz - - - + Sample rate - - Channels - + + Hz + Hz - - Bitrate + + Channels - - bits - bitai - - - - File size + + Bitrate - + kbps - kbps + kbps - - Sample width + + File size - + KB - KB + KB diff --git a/src/plugins/Input/flac/translations/flac_plugin_pl.ts b/src/plugins/Input/flac/translations/flac_plugin_pl.ts index 95ad83ef3..6bb2070e8 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_pl.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_pl.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin Wtyczka FLAC - + FLAC Files Pliki FLAC - + About FLAC Audio Plugin O wtyczce FLAC Audio - + Qmmp FLAC Audio Plugin Wtyczka FLAC Audio dla Qmmp - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Autor: Ilja Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length - Długość + Długość - - Hz - - - - + Sample rate - Próbkowanie + Próbkowanie - - Channels - Kanały + + Hz + - - kbps - + + Channels + Kanały - + Bitrate - Szybkość transmisji + Szybkość transmisji - - bits - + + kbps + - - Sample width - Długość próbkowania + + File size + Wielkość pliku - + KB - - - - - File size - Wielkość pliku + diff --git a/src/plugins/Input/flac/translations/flac_plugin_ru.ts b/src/plugins/Input/flac/translations/flac_plugin_ru.ts index 41f3bd331..1064e6b40 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_ru.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_ru.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin Модуль FLAC - + FLAC Files Файлы FLAC - + About FLAC Audio Plugin Об аудио-модуле FLAC - + Qmmp FLAC Audio Plugin Аудио-модуль FLAC для Qmmp - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Разработчик: Илья Котов <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length Длительность - - Hz - Гц + + Sample rate + Дискретизация - - Sample rate - Частота сэмплов + + Hz + Гц - + Channels Каналов - + Bitrate Битовая частота - - bits - бит - - - - File size - Размер файла - - - + kbps Кб/с - - Sample width - Ширина кадра + + File size + Размер файла - + KB - Кб + КБ diff --git a/src/plugins/Input/flac/translations/flac_plugin_tr.ts b/src/plugins/Input/flac/translations/flac_plugin_tr.ts index f36b6c819..70c9bda89 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_tr.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_tr.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin FLAC Eklentisi - + FLAC Files FLAC Dosyaları - + About FLAC Audio Plugin FLAC Ses Eklentisi Hakkında - + Qmmp FLAC Audio Plugin Qmmp FLAC Ses Eklentisi - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Yazan: Ilya Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length - - Hz - Hz - - - + Sample rate - - Channels - + + Hz + Hz - - kbps - kbps + + Channels + - + Bitrate - - bits - bits + + kbps + kbps - - Sample width + + File size - + KB - KB - - - - File size - + KB diff --git a/src/plugins/Input/flac/translations/flac_plugin_uk_UA.ts b/src/plugins/Input/flac/translations/flac_plugin_uk_UA.ts index da7922687..a78ae5fde 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_uk_UA.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_uk_UA.ts @@ -1,85 +1,75 @@ - - + + DecoderFLACFactory - + FLAC Plugin Модуль FLAC - + FLAC Files Файли FLAC - + About FLAC Audio Plugin Про аудіо-модуль FLAC - + Qmmp FLAC Audio Plugin Аудіо-модуль FLAC для Qmmp - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> Розробник: Ілля Котов <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length - Тривалість + Тривалість - - Hz - Гц + + Sample rate + Частота - - Sample rate - Частота + + Hz + Гц - + Channels - Канали + Канали - + Bitrate - Бітрейт - - - - bits - біт + Бітрейт - - File size - Розмір файлу - - - + kbps - Кб/с + Кб/с - - Sample width - Ширина кадру + + File size + Розмір файлу - + KB - Кб + Кб diff --git a/src/plugins/Input/flac/translations/flac_plugin_zh_CN.ts b/src/plugins/Input/flac/translations/flac_plugin_zh_CN.ts index 23850e0f4..fc059781a 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_zh_CN.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_zh_CN.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin FLAC 插件 - + FLAC Files FLAC 文件 - + About FLAC Audio Plugin 关于 FLAC 音频插件 - + Qmmp FLAC Audio Plugin Qmmp FLAC 音频插件 - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> 作者:Ilya Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length - - Hz - Hz - - - + Sample rate - - Channels - + + Hz + Hz - - Bitrate + + Channels - - bits - - - - - File size + + Bitrate - + kbps - kbps + kbps - - Sample width + + File size - + KB - KB + KB diff --git a/src/plugins/Input/flac/translations/flac_plugin_zh_TW.ts b/src/plugins/Input/flac/translations/flac_plugin_zh_TW.ts index 5d7773275..5b7e41732 100644 --- a/src/plugins/Input/flac/translations/flac_plugin_zh_TW.ts +++ b/src/plugins/Input/flac/translations/flac_plugin_zh_TW.ts @@ -4,82 +4,72 @@ DecoderFLACFactory - + FLAC Plugin FLAC 插件 - + FLAC Files FLAC 檔案 - + About FLAC Audio Plugin 關於 FLAC 聲訊插件 - + Qmmp FLAC Audio Plugin Qmmp FLAC 聲訊插件 - + Writen by: Ilya Kotov <forkotov02@hotmail.ru> 作者:Ilya Kotov <forkotov02@hotmail.ru> - DetailsDialog + FLACMetaDataModel - + Length - - Hz - Hz - - - + Sample rate - - Channels - + + Hz + Hz - - Bitrate + + Channels - - bits - - - - - File size + + Bitrate - + kbps - kbps + kbps - - Sample width + + File size - + KB - KB + KB -- cgit v1.2.3-13-gbd6f