From 257f15600dd619d2854046a4a483831c9e99e414 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Thu, 14 Jan 2021 20:03:58 +0000 Subject: added playlist load optimization git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9632 90c681e8-e032-0410-971d-27865f9a5e38 --- src/qmmpui/playlistmanager.cpp | 59 +++++++++++++++++++++--------------------- src/qmmpui/playlistmanager.h | 7 ++--- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/qmmpui/playlistmanager.cpp b/src/qmmpui/playlistmanager.cpp index a0f6da00c..e3714398b 100644 --- a/src/qmmpui/playlistmanager.cpp +++ b/src/qmmpui/playlistmanager.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include "qmmpuisettings.h" @@ -32,6 +31,30 @@ PlayListManager *PlayListManager::m_instance = nullptr; +//key names +const QHash PlayListManager::m_metaKeys = { + { "title", Qmmp::TITLE }, + { "artist", Qmmp::ARTIST }, + { "albumartist", Qmmp::ALBUMARTIST }, + { "album", Qmmp::ALBUM }, + { "comment", Qmmp::COMMENT }, + { "genre", Qmmp::GENRE }, + { "composer", Qmmp::COMPOSER }, + { "year", Qmmp::YEAR }, + { "track", Qmmp::TRACK }, + { "disk", Qmmp::DISCNUMBER } +}; + +const QHash PlayListManager::m_propKeys = { + { "bitrate", Qmmp::BITRATE }, + { "samplerate", Qmmp::SAMPLERATE }, + { "channels", Qmmp::CHANNELS }, + { "bits_per_sample", Qmmp::BITS_PER_SAMPLE }, + { "format_name", Qmmp::FORMAT_NAME }, + { "decoder", Qmmp::DECODER }, + { "file_size", Qmmp::FILE_SIZE } +}; + PlayListManager::PlayListManager(QObject *parent) : QObject(parent) { if(m_instance) @@ -44,28 +67,6 @@ PlayListManager::PlayListManager(QObject *parent) : QObject(parent) m_timer->setInterval(5000); m_timer->setSingleShot(true); connect(m_timer, SIGNAL(timeout()), SLOT(writePlayLists())); - //key names - m_metaKeys = { - { "title", Qmmp::TITLE }, - { "artist", Qmmp::ARTIST }, - { "albumartist", Qmmp::ALBUMARTIST }, - { "album", Qmmp::ALBUM }, - { "comment", Qmmp::COMMENT }, - { "genre", Qmmp::GENRE }, - { "composer", Qmmp::COMPOSER }, - { "year", Qmmp::YEAR }, - { "track", Qmmp::TRACK }, - { "disk", Qmmp::DISCNUMBER } - }; - m_propKeys = { - { "bitrate", Qmmp::BITRATE }, - { "samplerate", Qmmp::SAMPLERATE }, - { "channels", Qmmp::CHANNELS }, - { "bits_per_sample", Qmmp::BITS_PER_SAMPLE }, - { "format_name", Qmmp::FORMAT_NAME }, - { "decoder", Qmmp::DECODER }, - { "file_size", Qmmp::FILE_SIZE } - }; readPlayLists(); //read playlists } @@ -367,16 +368,16 @@ void PlayListManager::writePlayLists() PlayListTrack *t = dynamic_cast(m); plFile.write(QString("file=%1\n").arg(t->path()).toUtf8()); - for(const Qmmp::MetaData &metaKey : m_metaKeys.values()) + for(QHash::const_iterator it = m_metaKeys.constBegin(); it != m_metaKeys.constEnd(); ++it) { - if(!(value = t->value(metaKey)).isEmpty()) - plFile.write(QString("%1=%2\n").arg(m_metaKeys.key(metaKey)).arg(value).toUtf8()); + if(!(value = t->value(it.value())).isEmpty()) + plFile.write(QString("%1=%2\n").arg(it.key()).arg(value).toUtf8()); } - for(const Qmmp::TrackProperty &propKey : m_propKeys.values()) + for(QHash::const_iterator it = m_propKeys.constBegin(); it != m_propKeys.constEnd(); ++it) { - if(!(value = t->value(propKey)).isEmpty()) - plFile.write(QString("%1=%2\n").arg(m_propKeys.key(propKey)).arg(value).toLatin1()); + if(!(value = t->value(it.value())).isEmpty()) + plFile.write(QString("%1=%2\n").arg(it.key()).arg(value).toLatin1()); } if(t->duration() > 0) diff --git a/src/qmmpui/playlistmanager.h b/src/qmmpui/playlistmanager.h index 50f42326c..071fe57c6 100644 --- a/src/qmmpui/playlistmanager.h +++ b/src/qmmpui/playlistmanager.h @@ -21,7 +21,7 @@ #define PLAYLISTMANAGER_H #include -#include +#include #include #include "playlistheadermodel.h" #include "playlistmodel.h" @@ -266,15 +266,16 @@ private slots: private: void readPlayLists(); + static PlayListManager* m_instance; + static const QHash m_metaKeys; + static const QHash m_propKeys; QList m_models; PlayListModel *m_current = nullptr; PlayListModel *m_selected = nullptr; QTimer *m_timer; PlayListHeaderModel *m_header; QmmpUiSettings *m_ui_settings; - QMap m_propKeys; - QMap m_metaKeys; }; #endif // PLAYLISTMANAGER_H -- cgit v1.2.3-13-gbd6f