From ff18160e2001b8586895ab493082dac5f78480a4 Mon Sep 17 00:00:00 2001 From: kraxarn Date: Sat, 30 Nov 2024 13:42:06 +0100 Subject: [PATCH] Remove deprecated audio features/analysis from side panel --- src/enum/sidepaneltype.hpp | 5 -- src/view/CMakeLists.txt | 1 - src/view/audiofeatures.cpp | 108 ------------------------------------ src/view/audiofeatures.hpp | 28 ---------- src/view/sidepanel/view.cpp | 34 ------------ src/view/sidepanel/view.hpp | 2 - 6 files changed, 178 deletions(-) delete mode 100644 src/view/audiofeatures.cpp delete mode 100644 src/view/audiofeatures.hpp diff --git a/src/enum/sidepaneltype.hpp b/src/enum/sidepaneltype.hpp index 912910cee..ab5d0b7ab 100644 --- a/src/enum/sidepaneltype.hpp +++ b/src/enum/sidepaneltype.hpp @@ -15,11 +15,6 @@ enum class SidePanelType: char */ Search, - /** - * Audio features, paired with track ID - */ - AudioFeatures, - /** * Lyrics, paired with track ID */ diff --git a/src/view/CMakeLists.txt b/src/view/CMakeLists.txt index ba9fa81b7..190be7b0f 100644 --- a/src/view/CMakeLists.txt +++ b/src/view/CMakeLists.txt @@ -5,7 +5,6 @@ add_subdirectory(search) add_subdirectory(sidepanel) target_sources(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/audiofeatures.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cacheview.cpp ${CMAKE_CURRENT_SOURCE_DIR}/configview.cpp ${CMAKE_CURRENT_SOURCE_DIR}/crashes.cpp diff --git a/src/view/audiofeatures.cpp b/src/view/audiofeatures.cpp deleted file mode 100644 index 93f6518c1..000000000 --- a/src/view/audiofeatures.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "view/audiofeatures.hpp" - -View::AudioFeatures::AudioFeatures(QWidget *parent) - : QTreeWidget(parent) -{ - setEnabled(false); - - setEditTriggers(QAbstractItemView::NoEditTriggers); - header()->hide(); - setSelectionMode(QAbstractItemView::NoSelection); - setRootIsDecorated(false); - setAllColumnsShowFocus(true); - setColumnCount(2); - header()->setSectionResizeMode(QHeaderView::ResizeToContents); -} - -View::AudioFeatures::AudioFeatures(lib::spt::api &spotify, - const std::string &trackId, QWidget *parent) - : AudioFeatures(parent) -{ - spotify.track_audio_features(trackId, - [this](const lib::spt::audio_features &features) - { - loaded(features); - }); -} - -View::AudioFeatures::AudioFeatures(lib::spt::api &spotify, - const std::vector &trackIds, QWidget *parent) - : AudioFeatures(parent) -{ - spotify.track_audio_features(trackIds, - [this](const std::vector &features) - { - loaded(features); - }); -} - -void View::AudioFeatures::loaded(const lib::spt::audio_features &features) -{ - for (const auto &item: features.items()) - { - auto *treeItem = new QTreeWidgetItem(this, { - QString::fromStdString(item.get_feature_string()), - QString::fromStdString(item.get_value_string()), - }); - - treeItem->setToolTip(1, - QString::fromStdString(item.get_description())); - } - - setEnabled(true); -} - -void View::AudioFeatures::loaded(const std::vector &features) -{ - if (features.empty()) - { - return; - } - - for (const auto &frontItem: features.front().items()) - { - const auto feature = frontItem.get_feature(); - std::vector values; - std::string tooltip; - constexpr size_t maxTooltip = 5; - - // TODO: These can't easily be averaged - if (feature == lib::audio_feature::key - || feature == lib::audio_feature::mode) - { - continue; - } - - // Loop through other tracks - for (const auto ¤t: features) - { - // Loop through features for that track - for (const auto &item: current.items()) - { - if (item.get_feature() == feature) - { - values.push_back(item.get_value()); - if (features.size() <= maxTooltip) - { - tooltip += lib::fmt::format("{}\n", item.get_description()); - } - break; - } - } - } - - const auto value = lib::vector::average(values); - lib::spt::audio_feature item(feature, value); - - auto *treeItem = new QTreeWidgetItem(this, { - QString::fromStdString(item.get_feature_string()), - QString::fromStdString(item.get_value_string()), - }); - - treeItem->setToolTip(1, QString::fromStdString(tooltip - + (tooltip.empty() ? "" : "= ") - + item.get_description())); - } - - setEnabled(true); -} diff --git a/src/view/audiofeatures.hpp b/src/view/audiofeatures.hpp deleted file mode 100644 index 7a6642d4a..000000000 --- a/src/view/audiofeatures.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "lib/spotify/api.hpp" - -#include -#include -#include -#include - -namespace View -{ - class AudioFeatures: public QTreeWidget - { - Q_OBJECT - - public: - AudioFeatures(lib::spt::api &spotify, const std::string &trackId, QWidget *parent); - - AudioFeatures(lib::spt::api &spotify, const std::vector &trackIds, - QWidget *parent); - - private: - explicit AudioFeatures(QWidget *parent); - - void loaded(const lib::spt::audio_features &features); - void loaded(const std::vector &features); - }; -} diff --git a/src/view/sidepanel/view.cpp b/src/view/sidepanel/view.cpp index 496ef72bd..621242e3a 100644 --- a/src/view/sidepanel/view.cpp +++ b/src/view/sidepanel/view.cpp @@ -32,37 +32,6 @@ void SidePanel::View::openArtist(const std::string &artistId) SidePanelType::Artist, QString::fromStdString(artistId)); } -void SidePanel::View::openAudioFeatures(const std::vector &tracks) -{ - QWidget *view; - QString tabTitle; - QString tabId; - - if (tracks.size() == 1) - { - const auto &track = tracks.front(); - view = new ::View::AudioFeatures(spotify, track.id, this); - tabTitle = QString::fromStdString(track.title()); - tabId = QString::fromStdString(track.id); - } - else - { - std::vector trackIds; - trackIds.reserve(tracks.size()); - for (const auto &track: tracks) - { - trackIds.push_back(track.id); - tabId += QString::fromStdString(track.id); - } - - view = new ::View::AudioFeatures(spotify, trackIds, this); - tabTitle = QString("%1 tracks").arg(tracks.size()); - } - - addTab(view, "view-statistics", tabTitle, - SidePanelType::AudioFeatures, tabId); -} - void SidePanel::View::openLyrics(const lib::spt::track &track) { auto *view = new ::View::Lyrics(httpClient, cache, this); @@ -111,9 +80,6 @@ auto SidePanel::View::findTab(SidePanelType type, const QString &name) -> QWidge case SidePanelType::Search: return nullptr; - case SidePanelType::AudioFeatures: - return find<::View::AudioFeatures *>(name); - case SidePanelType::Lyrics: return find<::View::Lyrics *>(name); diff --git a/src/view/sidepanel/view.hpp b/src/view/sidepanel/view.hpp index ad9c82dac..c01631b6b 100644 --- a/src/view/sidepanel/view.hpp +++ b/src/view/sidepanel/view.hpp @@ -3,7 +3,6 @@ #include "lib/spotify/track.hpp" #include "view/artist/view.hpp" #include "view/search/view.hpp" -#include "view/audiofeatures.hpp" #include "view/lyrics.hpp" #include "view/sidepanel/title.hpp" #include "enum/sidepaneltype.hpp" @@ -22,7 +21,6 @@ namespace SidePanel const lib::http_client &httpClient, QWidget *parent); void openArtist(const std::string &artistId); - void openAudioFeatures(const std::vector &tracks); void openLyrics(const lib::spt::track &track); void openLyrics(int lyricsId);