aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-05-27 19:43:58 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-05-27 19:43:58 +0000
commit9e9636ada5475874f9eeb704d2af1af7b0447e9a (patch)
treecde2e6c960197693bc521a7b47210d4190a3e0e0 /src
parent833d350aee61c16a2472b3f491f4cc6b71b5c40a (diff)
downloadqmmp-9e9636ada5475874f9eeb704d2af1af7b0447e9a.tar.gz
qmmp-9e9636ada5475874f9eeb704d2af1af7b0447e9a.tar.bz2
qmmp-9e9636ada5475874f9eeb704d2af1af7b0447e9a.zip
fixed sndfile plugin
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7967 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Input/Input.pro2
-rw-r--r--src/plugins/Input/sndfile/decodersndfilefactory.cpp77
-rw-r--r--src/plugins/Input/sndfile/decodersndfilefactory.h12
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);