From 9e9636ada5475874f9eeb704d2af1af7b0447e9a Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sun, 27 May 2018 19:43:58 +0000 Subject: fixed sndfile plugin git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7967 90c681e8-e032-0410-971d-27865f9a5e38 --- .../Input/sndfile/decodersndfilefactory.cpp | 77 +++++++++++++++------- src/plugins/Input/sndfile/decodersndfilefactory.h | 12 +--- 2 files changed, 56 insertions(+), 33 deletions(-) (limited to 'src/plugins/Input/sndfile') 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 #include #include +#include #ifdef Q_OS_WIN #include #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1 @@ -99,9 +100,8 @@ Decoder *DecoderSndFileFactory::create(const QString &, QIODevice *input) return new DecoderSndFile(input); } -QList DecoderSndFileFactory::createPlayList(const QString &fileName, bool useMetaData, QStringList *) +QList DecoderSndFileFactory::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *) { - QList list; SF_INFO snd_info; SNDFILE *sndfile = 0; memset (&snd_info, 0, sizeof(snd_info)); @@ -109,35 +109,66 @@ QList DecoderSndFileFactory::createPlayList(const QString &fileName, #ifdef Q_OS_WIN sndfile = sf_wchar_open(reinterpret_cast(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(); - 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() << 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 -#include -#include -#include - -#include -#include #include -#include 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 createPlayList(const QString &fileName, bool useMetaData, QStringList *); + QList createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *); MetaDataModel* createMetaDataModel(const QString &path, QObject *parent = 0); void showSettings(QWidget *parent); void showAbout(QWidget *parent); -- cgit v1.2.3-13-gbd6f