diff options
| -rw-r--r-- | src/qmmp/qmmp.h | 13 | ||||
| -rw-r--r-- | src/qmmp/trackinfo.cpp | 215 | ||||
| -rw-r--r-- | src/qmmp/trackinfo.h | 84 |
3 files changed, 312 insertions, 0 deletions
diff --git a/src/qmmp/qmmp.h b/src/qmmp/qmmp.h index dddafb0c5..34c09b905 100644 --- a/src/qmmp/qmmp.h +++ b/src/qmmp/qmmp.h @@ -77,6 +77,19 @@ public: URL /*!< Stream url or local file path */ }; /*! + * Track properties + */ + enum TrackProperty + { + BITRATE = 0, + SAMPLERATE, + CHANNELS, + BITS_PER_SAMPLE, + FORMAT_NAME, + DECODER, + FILE_SIZE + }; + /*! * Keys of ReplayGain information */ enum ReplayGainKey diff --git a/src/qmmp/trackinfo.cpp b/src/qmmp/trackinfo.cpp new file mode 100644 index 000000000..1bf07d84d --- /dev/null +++ b/src/qmmp/trackinfo.cpp @@ -0,0 +1,215 @@ +/*************************************************************************** + * Copyright (C) 2018 by Ilya Kotov * + * forkotov02@ya.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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <QRegExp> +#include "trackinfo.h" + +TrackInfo::TrackInfo(const QString &path) +{ + m_path = path; + m_duration = 0; + m_parts = NoParts; + m_metaData.insert(Qmmp::URL, path); +} + +TrackInfo::TrackInfo(const TrackInfo &other) +{ + *this = other; +} + +TrackInfo::~TrackInfo() +{} + +TrackInfo &TrackInfo::operator=(const TrackInfo &info) +{ + setDuration(info.duration()); + setValues(info.metaData()); + setValues(info.properties()); + setValues(info.replayGainInfo()); + setPath(info.path()); + setParts(info.parts()); + return *this; +} + +bool TrackInfo::operator==(const TrackInfo &info) const +{ + return m_metaData == info.metaData () && + m_properties == info.properties() && + m_replayGainInfo == info.replayGainInfo() && + m_parts == info.parts(); +} + +bool TrackInfo::operator!=(const TrackInfo &info) const +{ + return !operator==(info); +} + +qint64 TrackInfo::duration () const +{ + return m_duration; +} + +bool TrackInfo::isEmpty() const +{ + return m_metaData.isEmpty() && m_properties.isEmpty() && m_replayGainInfo.isEmpty() && m_path.isEmpty(); +} + +const QString TrackInfo::path() const +{ + return m_path; +} + +const QString &TrackInfo::operator [](Qmmp::MetaData key) const +{ + return m_metaData.find(key).value(); +} + +const QString &TrackInfo::operator [](Qmmp::TrackProperty key) const +{ + return m_properties.find(key).value(); +} + +const double &TrackInfo::operator [](Qmmp::ReplayGainKey key) const +{ + return m_replayGainInfo.find(key).value(); +} + +const QMap<Qmmp::MetaData, QString> &TrackInfo::metaData() const +{ + return m_metaData; +} + +const QMap<Qmmp::TrackProperty, QString> &TrackInfo::properties() const +{ + return m_properties; +} + +const QMap<Qmmp::ReplayGainKey, double> &TrackInfo::replayGainInfo() const +{ + return m_replayGainInfo; +} + +TrackInfo::Parts TrackInfo::parts() const +{ + return m_parts; +} + +void TrackInfo::setDuration(qint64 length) +{ + m_duration = length; +} + +void TrackInfo::setValue(Qmmp::MetaData key, const QVariant &value) +{ + QString strValue = value.toString(); + if(strValue.isEmpty() || strValue == "0") + return; + + m_parts |= MetaData; + m_metaData[key] = strValue; +} + +void TrackInfo::setValue(Qmmp::TrackProperty key, const QVariant &value) +{ + QString strValue = value.toString(); + if(strValue.isEmpty() || strValue == "0") + return; + + m_parts |= Properties; + m_properties[key] = strValue; +} + +void TrackInfo::setValue(Qmmp::ReplayGainKey key, double value) +{ + if(!qFuzzyIsNull(value)) + return; + + m_parts |= ReplayGainInfo; + m_replayGainInfo[key] = value; +} + +void TrackInfo::setValue(Qmmp::ReplayGainKey key, const QString &value) +{ + QString str = value; + str.remove(QRegExp("[\\sA-Za-z]")); + str = str.trimmed(); + bool ok = false; + double v = str.toDouble(&ok); + if(ok) + setValue(key, v); +} + +void TrackInfo::setValues(const QMap<Qmmp::MetaData, QString> &metaData) +{ + m_parts |= MetaData; + m_metaData = metaData; +} + +void TrackInfo::setValues(const QMap<Qmmp::TrackProperty, QString> &properties) +{ + m_parts |= Properties; + m_properties = properties; +} + +void TrackInfo::setValues(const QMap<Qmmp::ReplayGainKey, double> &replayGainInfo) +{ + m_parts |= ReplayGainInfo; + m_replayGainInfo = replayGainInfo; +} + +void TrackInfo::updateValues(const QMap<Qmmp::MetaData, QString> &metaData) +{ + foreach (Qmmp::MetaData key, metaData.keys()) + setValue(key, metaData[key]); +} + +void TrackInfo::updateValues(const QMap<Qmmp::TrackProperty, QString> &properties) +{ + foreach (Qmmp::TrackProperty key, properties.keys()) + setValue(key, properties[key]); +} + +void TrackInfo::updateValues(const QMap<Qmmp::ReplayGainKey, double> &replayGainInfo) +{ + foreach (Qmmp::ReplayGainKey key, replayGainInfo.keys()) + setValue(key, replayGainInfo[key]); +} + +void TrackInfo::setPath(const QString &path) +{ + m_path = path; + m_metaData.insert(Qmmp::URL, path); +} + +void TrackInfo::setParts(Parts parts) +{ + m_parts = parts; +} + +void TrackInfo::clear(Parts parts) +{ + if(parts & MetaData) + m_metaData.clear(); + if(parts & Properties) + m_properties.clear(); + if(parts & ReplayGainInfo) + m_replayGainInfo.clear(); + m_parts &= ~parts; +} diff --git a/src/qmmp/trackinfo.h b/src/qmmp/trackinfo.h new file mode 100644 index 000000000..575025b20 --- /dev/null +++ b/src/qmmp/trackinfo.h @@ -0,0 +1,84 @@ +/*************************************************************************** + * Copyright (C) 2018 by Ilya Kotov * + * forkotov02@ya.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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef TRACKINFO_H +#define TRACKINFO_H + +#include <QMap> +#include <QString> +#include "qmmp.h" + +class QMMP_EXPORT TrackInfo +{ +public: + TrackInfo(const QString &path); + TrackInfo(const TrackInfo &other); + ~TrackInfo(); + + enum Part + { + NoParts = 0x0, + MetaData = 0x1, + Properties = 0x2, + ReplayGain = 0x4 + }; + + Q_DECLARE_FLAGS(Parts, Part) + + TrackInfo &operator=(const TrackInfo &info); + bool operator==(const TrackInfo &info) const; + bool operator!=(const TrackInfo &info) const; + qint64 duration () const; + bool isEmpty() const; + const QString path() const; + const QString &operator [](Qmmp::MetaData key) const; + const QString &operator [](Qmmp::TrackProperty key) const; + const double &operator [](Qmmp::ReplayGainKey key) const; + const QMap<Qmmp::MetaData, QString> &metaData() const; + const QMap<Qmmp::TrackProperty, QString> &properties() const; + const QMap<Qmmp::ReplayGainKey, double> &replayGainInfo() const; + Parts parts() const; + void setDuration(qint64 length); + void setValue(Qmmp::MetaData key, const QVariant &value); + void setValue(Qmmp::TrackProperty key, const QVariant &value); + void setValue(Qmmp::ReplayGainKey key, double value); + void setValue(Qmmp::ReplayGainKey key, const QString &value); + void setValues(const QMap<Qmmp::MetaData, QString> &metaData); + void setValues(const QMap<Qmmp::TrackProperty, QString> &properties); + void setValues(const QMap<Qmmp::ReplayGainKey, double> &replayGainInfo); + void updateValues(const QMap<Qmmp::MetaData, QString> &metaData); + void updateValues(const QMap<Qmmp::TrackProperty, QString> &properties); + void updateValues(const QMap<Qmmp::ReplayGainKey, double> &replayGainInfo); + void setPath(const QString &path); + void setParts(Parts parts); + void clear(Parts parts); + +private: + QMap<Qmmp::MetaData, QString> m_metaData; + QMap<Qmmp::TrackProperty, QString> m_properties; + QMap<Qmmp::ReplayGainKey, double> m_replayGainInfo; + Parts m_parts; + QString m_path; + qint64 m_duration; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(TrackInfo::Parts) + + +#endif |
