diff options
| -rw-r--r-- | src/plugins/Input/Input.pro | 2 | ||||
| -rw-r--r-- | src/plugins/Input/sndfile/decodersndfilefactory.cpp | 77 | ||||
| -rw-r--r-- | src/plugins/Input/sndfile/decodersndfilefactory.h | 12 |
3 files changed, 57 insertions, 34 deletions
diff --git a/src/plugins/Input/Input.pro b/src/plugins/Input/Input.pro index 6dbbfee34..35ce4208f 100644 --- a/src/plugins/Input/Input.pro +++ b/src/plugins/Input/Input.pro @@ -1,7 +1,7 @@ include(../../../qmmp.pri) TEMPLATE = subdirs -SUBDIRS += vorbis cue #sndfile wavpack +SUBDIRS += vorbis cue sndfile #wavpack contains(CONFIG, WITH_MAD)|contains(CONFIG, WITH_MPG123){ SUBDIRS += mpeg diff --git a/src/plugins/Input/sndfile/decodersndfilefactory.cpp b/src/plugins/Input/sndfile/decodersndfilefactory.cpp index c1235d068..55638b133 100644 --- a/src/plugins/Input/sndfile/decodersndfilefactory.cpp +++ b/src/plugins/Input/sndfile/decodersndfilefactory.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2015 by Ilya Kotov * + * Copyright (C) 2007-2018 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -21,6 +21,7 @@ #include <QMessageBox> #include <QTranslator> #include <QRegExp> +#include <QFileInfo> #ifdef Q_OS_WIN #include <windows.h> #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 @@ -99,9 +100,8 @@ Decoder *DecoderSndFileFactory::create(const QString &, QIODevice *input) return new DecoderSndFile(input); } -QList<FileInfo *> DecoderSndFileFactory::createPlayList(const QString &fileName, bool useMetaData, QStringList *) +QList<TrackInfo *> DecoderSndFileFactory::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *) { - QList <FileInfo *> list; SF_INFO snd_info; SNDFILE *sndfile = 0; memset (&snd_info, 0, sizeof(snd_info)); @@ -109,35 +109,66 @@ QList<FileInfo *> DecoderSndFileFactory::createPlayList(const QString &fileName, #ifdef Q_OS_WIN sndfile = sf_wchar_open(reinterpret_cast<LPCWSTR>(fileName.utf16()), SFM_READ, &snd_info); #else - sndfile = sf_open(fileName.toLocal8Bit().constData(), SFM_READ, &snd_info); + sndfile = sf_open(path.toLocal8Bit().constData(), SFM_READ, &snd_info); #endif if (!sndfile) - return list; + return QList<TrackInfo *>(); - list << new FileInfo(fileName); - if (useMetaData) + TrackInfo *info = new TrackInfo(path); + info->setDuration(int(snd_info.frames * 1000 / snd_info.samplerate)); + + if(parts & TrackInfo::MetaData) { - if (sf_get_string(sndfile, SF_STR_TITLE)) - { - char* title = strdup(sf_get_string(sndfile, SF_STR_TITLE)); - list.at(0)->setMetaData(Qmmp::TITLE, QString::fromUtf8(title).trimmed()); - } - if (sf_get_string(sndfile, SF_STR_ARTIST)) - { - char* artist = strdup(sf_get_string(sndfile, SF_STR_ARTIST)); - list.at(0)->setMetaData(Qmmp::ARTIST, QString::fromUtf8(artist).trimmed()); - } - if (sf_get_string(sndfile, SF_STR_COMMENT)) + const char *title = sf_get_string(sndfile, SF_STR_TITLE); + info->setValue(Qmmp::TITLE, title ? QString::fromUtf8(title) : QString()); + const char *date = sf_get_string(sndfile, SF_STR_DATE); + info->setValue(Qmmp::YEAR, date ? QString::fromUtf8(date) : QString()); + const char *album = sf_get_string(sndfile, SF_STR_ALBUM); + info->setValue(Qmmp::ALBUM, album ? QString::fromUtf8(album) : QString()); + const char *track = sf_get_string(sndfile, SF_STR_TRACKNUMBER); + info->setValue(Qmmp::TRACK, track ? QString::fromUtf8(track) : QString()); + const char *artist = sf_get_string(sndfile, SF_STR_ARTIST); + info->setValue(Qmmp::ARTIST, artist ? QString::fromUtf8(artist) : QString()); + const char *comment = sf_get_string(sndfile, SF_STR_COMMENT); + info->setValue(Qmmp::COMMENT, comment ? QString::fromUtf8(comment) : QString()); + const char *genre = sf_get_string(sndfile, SF_STR_GENRE); + info->setValue(Qmmp::COMMENT, genre ? QString::fromUtf8(genre) : QString()); + } + + if(parts & TrackInfo::Properties) + { + info->setValue(Qmmp::BITRATE, QFileInfo(path).size() * 8000.0 / info->duration() + 0.5); + info->setValue(Qmmp::SAMPLERATE, snd_info.samplerate); + info->setValue(Qmmp::CHANNELS, snd_info.channels); + switch(snd_info.format & SF_FORMAT_SUBMASK) { - char* comment = strdup(sf_get_string(sndfile, SF_STR_COMMENT)); - list.at(0)->setMetaData(Qmmp::COMMENT, QString::fromUtf8(comment).trimmed()); + case SF_FORMAT_PCM_S8: + case SF_FORMAT_PCM_U8: + info->setValue(Qmmp::BITS_PER_SAMPLE, 8); + break; + case SF_FORMAT_PCM_16: + info->setValue(Qmmp::BITS_PER_SAMPLE, 16); + break; + case SF_FORMAT_PCM_24: + info->setValue(Qmmp::BITS_PER_SAMPLE, 24); + break; + case SF_FORMAT_PCM_32: + case SF_FORMAT_FLOAT: + info->setValue(Qmmp::BITS_PER_SAMPLE, 32); + break; + case SF_FORMAT_DOUBLE: + info->setValue(Qmmp::BITS_PER_SAMPLE, 64); + break; } + SF_FORMAT_INFO format_info; + memset(&format_info, 0, sizeof(format_info)); + format_info.format = (snd_info.format & SF_FORMAT_TYPEMASK); + sf_command(0, SFC_GET_FORMAT_INFO, &format_info, sizeof(format_info)); + info->setValue(Qmmp::FORMAT_NAME, QString::fromLatin1(format_info.name)); } - list.at(0)->setLength(int(snd_info.frames / snd_info.samplerate)); - sf_close(sndfile); - return list; + return QList<TrackInfo *>() << info; } MetaDataModel* DecoderSndFileFactory::createMetaDataModel(const QString&, QObject *) diff --git a/src/plugins/Input/sndfile/decodersndfilefactory.h b/src/plugins/Input/sndfile/decodersndfilefactory.h index 95931e428..4882fcef8 100644 --- a/src/plugins/Input/sndfile/decodersndfilefactory.h +++ b/src/plugins/Input/sndfile/decodersndfilefactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2007-2016 by Ilya Kotov * + * Copyright (C) 2007-2018 by Ilya Kotov * * forkotov02@ya.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -20,15 +20,7 @@ #ifndef DECODERSNDFILEFACTORY_H #define DECODERSNDFILEFACTORY_H -#include <QObject> -#include <QString> -#include <QIODevice> -#include <QWidget> - -#include <qmmp/decoder.h> -#include <qmmp/output.h> #include <qmmp/decoderfactory.h> -#include <qmmp/fileinfo.h> class DecoderSndFileFactory : public QObject, DecoderFactory @@ -41,7 +33,7 @@ public: bool canDecode(QIODevice *input) const; const DecoderProperties properties() const; Decoder *create(const QString &, QIODevice *); - QList<FileInfo *> createPlayList(const QString &fileName, bool useMetaData, QStringList *); + QList<TrackInfo *> createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *); MetaDataModel* createMetaDataModel(const QString &path, QObject *parent = 0); void showSettings(QWidget *parent); void showAbout(QWidget *parent); |
