From 52d01ffb7b5ffc0b0689cadb4ae6eccb01ed8f14 Mon Sep 17 00:00:00 2001 From: casey Date: Fri, 3 Jun 2016 21:05:01 -0700 Subject: [PATCH] - A bit of Transport.h header cleanup - Ensure fields are using the correct keys for queries and data access (we were using ALBUM_ID, ARTIST_ID, GENRE_ID incorrectly). --- src/core/playback/Transport.h | 7 ++-- src/musikbox/app/layout/BrowseLayout.cpp | 8 ++--- src/musikbox/app/layout/LibraryLayout.cpp | 4 --- .../app/query/CategoryListViewQuery.cpp | 6 ++-- .../app/query/CategoryTrackListQuery.cpp | 23 ++++++++++--- src/musikbox/app/query/SingleTrackQuery.cpp | 33 ------------------- src/musikbox/app/query/SingleTrackQuery.h | 26 --------------- src/musikbox/app/window/TrackListView.cpp | 6 ++-- src/musikbox/app/window/TransportWindow.cpp | 2 +- src/musikbox/musikbox.vcxproj | 2 -- src/musikbox/musikbox.vcxproj.filters | 6 ---- 11 files changed, 32 insertions(+), 91 deletions(-) delete mode 100755 src/musikbox/app/query/SingleTrackQuery.cpp delete mode 100755 src/musikbox/app/query/SingleTrackQuery.h diff --git a/src/core/playback/Transport.h b/src/core/playback/Transport.h index dbcae2697..a00bbea5d 100644 --- a/src/core/playback/Transport.h +++ b/src/core/playback/Transport.h @@ -98,14 +98,13 @@ namespace musik { namespace core { namespace audio { void OnPlaybackError(Player* player); private: - double volume; PlaybackState state; - bool nextCanStart; boost::recursive_mutex stateMutex; - Player* nextPlayer; musik::core::audio::OutputPtr output; std::list active; - + Player* nextPlayer; + double volume; + bool nextCanStart; }; } } } diff --git a/src/musikbox/app/layout/BrowseLayout.cpp b/src/musikbox/app/layout/BrowseLayout.cpp index ae49d2afd..a6122cd35 100755 --- a/src/musikbox/app/layout/BrowseLayout.cpp +++ b/src/musikbox/app/layout/BrowseLayout.cpp @@ -9,7 +9,7 @@ using namespace musik::core::library::constants; #define CATEGORY_WIDTH 25 -#define DEFAULT_CATEGORY constants::Track::ARTIST_ID +#define DEFAULT_CATEGORY constants::Track::ARTIST using namespace musik::core; using namespace musik::core::audio; @@ -120,15 +120,15 @@ bool BrowseLayout::KeyPress(const std::string& key) { return true; } else if (key == "ALT_1" || key == "M-1") { - this->categoryList->SetFieldName(constants::Track::ARTIST_ID); + this->categoryList->SetFieldName(constants::Track::ARTIST); return true; } else if (key == "ALT_2" || key == "M-2") { - this->categoryList->SetFieldName(constants::Track::ALBUM_ID); + this->categoryList->SetFieldName(constants::Track::ALBUM); return true; } else if (key == "ALT_3" || key == "M-3") { - this->categoryList->SetFieldName(constants::Track::GENRE_ID); + this->categoryList->SetFieldName(constants::Track::GENRE); return true; } diff --git a/src/musikbox/app/layout/LibraryLayout.cpp b/src/musikbox/app/layout/LibraryLayout.cpp index 4822030b5..7138828d4 100755 --- a/src/musikbox/app/layout/LibraryLayout.cpp +++ b/src/musikbox/app/layout/LibraryLayout.cpp @@ -11,16 +11,12 @@ using namespace musik::core::library::constants; -#define CATEGORY_WIDTH 25 - #ifdef WIN32 #define TRANSPORT_HEIGHT 3 #else #define TRANSPORT_HEIGHT 2 #endif -#define DEFAULT_CATEGORY constants::Track::ARTIST_ID - using namespace musik::core; using namespace musik::core::audio; using namespace musik::core::library; diff --git a/src/musikbox/app/query/CategoryListViewQuery.cpp b/src/musikbox/app/query/CategoryListViewQuery.cpp index a48d9b0e5..8f533e88f 100755 --- a/src/musikbox/app/query/CategoryListViewQuery.cpp +++ b/src/musikbox/app/query/CategoryListViewQuery.cpp @@ -39,9 +39,9 @@ static boost::mutex QUERY_MAP_MUTEX; static std::map FIELD_TO_QUERY_MAP; static void initFieldToQueryMap() { - FIELD_TO_QUERY_MAP[Track::ALBUM_ID] = ALBUM_QUERY; - FIELD_TO_QUERY_MAP[Track::ARTIST_ID] = ARTIST_QUERY; - FIELD_TO_QUERY_MAP[Track::GENRE_ID] = GENRE_QUERY; + FIELD_TO_QUERY_MAP[Track::ALBUM] = ALBUM_QUERY; + FIELD_TO_QUERY_MAP[Track::ARTIST] = ARTIST_QUERY; + FIELD_TO_QUERY_MAP[Track::GENRE] = GENRE_QUERY; } CategoryListViewQuery::CategoryListViewQuery(const std::string& trackField) { diff --git a/src/musikbox/app/query/CategoryTrackListQuery.cpp b/src/musikbox/app/query/CategoryTrackListQuery.cpp index fecec63a3..73b996b98 100755 --- a/src/musikbox/app/query/CategoryTrackListQuery.cpp +++ b/src/musikbox/app/query/CategoryTrackListQuery.cpp @@ -5,6 +5,8 @@ #include #include +#include + using musik::core::db::Statement; using musik::core::db::Row; using musik::core::TrackPtr; @@ -15,15 +17,26 @@ using namespace musik::core::db; using namespace musik::core::library::constants; using namespace musik::box; +static std::map FIELD_TO_FOREIGN_KEY = + { + std::make_pair(Track::ALBUM, Track::ALBUM_ID), + std::make_pair(Track::ARTIST, Track::ARTIST_ID), + std::make_pair(Track::GENRE, Track::GENRE_ID), + std::make_pair(Track::ALBUM_ARTIST, Track::ALBUM_ARTIST_ID) + }; + CategoryTrackListQuery::CategoryTrackListQuery(LibraryPtr library, const std::string& column, DBID id) { this->library = library; - this->column = column; this->id = id; this->result.reset(new std::vector()); this->headers.reset(new std::set()); this->hash = 0; - this->GetQueryHash(); + if (FIELD_TO_FOREIGN_KEY.find(column) == FIELD_TO_FOREIGN_KEY.end()) { + throw std::runtime_error("invalid input column specified"); + } + + this->column = FIELD_TO_FOREIGN_KEY[column]; } CategoryTrackListQuery::~CategoryTrackListQuery() { @@ -85,9 +98,9 @@ bool CategoryTrackListQuery::OnRun(Connection& db) { track->SetValue(Track::TITLE, trackQuery.ColumnText(6)); track->SetValue(Track::FILENAME, trackQuery.ColumnText(7)); track->SetValue(Track::THUMBNAIL_ID, trackQuery.ColumnText(8)); - track->SetValue(Track::ALBUM_ID, album.c_str()); - track->SetValue(Track::GENRE_ID, trackQuery.ColumnText(10)); - track->SetValue(Track::ARTIST_ID, trackQuery.ColumnText(11)); + track->SetValue(Track::ALBUM, album.c_str()); + track->SetValue(Track::GENRE, trackQuery.ColumnText(10)); + track->SetValue(Track::ARTIST, trackQuery.ColumnText(11)); track->SetValue(Track::FILETIME, trackQuery.ColumnText(12)); result->push_back(track); diff --git a/src/musikbox/app/query/SingleTrackQuery.cpp b/src/musikbox/app/query/SingleTrackQuery.cpp deleted file mode 100755 index b146b5363..000000000 --- a/src/musikbox/app/query/SingleTrackQuery.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "stdafx.h" -#include "SingleTrackQuery.h" - -#include -#include -#include - -using musik::core::db::Statement; -using musik::core::db::Row; -using musik::core::TrackPtr; -using musik::core::LibraryTrack; - -using namespace musik::core::library::constants; -using namespace musik::core::db; -using namespace musik::box; - -SingleTrackQuery::SingleTrackQuery(const std::string& filename) { - this->filename = filename; -} - -SingleTrackQuery::~SingleTrackQuery() { - -} - -TrackPtr SingleTrackQuery::GetResult() { - return this->result; -} - -bool SingleTrackQuery::OnRun(Connection& db) { - result.reset(new LibraryTrack()); - result->SetValue("filename", filename.c_str()); - return LibraryTrack::Load(result.get(), db); -} diff --git a/src/musikbox/app/query/SingleTrackQuery.h b/src/musikbox/app/query/SingleTrackQuery.h deleted file mode 100755 index 28213693b..000000000 --- a/src/musikbox/app/query/SingleTrackQuery.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include -#include -#include "CategoryListViewQuery.h" - -namespace musik { - namespace box { - class SingleTrackQuery : public musik::core::query::QueryBase { - public: - SingleTrackQuery(const std::string& path); - virtual ~SingleTrackQuery(); - - virtual std::string Name() { return "SingleTrackQuery"; } - virtual musik::core::TrackPtr GetResult(); - - protected: - virtual bool OnRun(musik::core::db::Connection &db); - - private: - musik::core::TrackPtr result; - std::string filename; - }; - } -} diff --git a/src/musikbox/app/window/TrackListView.cpp b/src/musikbox/app/window/TrackListView.cpp index 84a432ef5..c3d2658de 100755 --- a/src/musikbox/app/window/TrackListView.cpp +++ b/src/musikbox/app/window/TrackListView.cpp @@ -136,8 +136,8 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { } std::string trackNum = track->GetValue(constants::Track::TRACK_NUM); - std::string artist = track->GetValue(constants::Track::ARTIST_ID); - std::string album = track->GetValue(constants::Track::ALBUM_ID); + std::string artist = track->GetValue(constants::Track::ARTIST); + std::string album = track->GetValue(constants::Track::ALBUM); std::string title = track->GetValue(constants::Track::TITLE); std::string duration = track->GetValue(constants::Track::DURATION); @@ -170,7 +170,7 @@ IScrollAdapter::EntryPtr TrackListView::Adapter::GetEntry(size_t index) { % group(setw(column4Width), setiosflags(std::ios::left), setfill(' '), album)); if (this->parent.headers->find(index) != this->parent.headers->end()) { - std::string album = track->GetValue(constants::Track::ALBUM_ID); + std::string album = track->GetValue(constants::Track::ALBUM); std::shared_ptr entry(new EntryWithHeader(album, text)); entry->SetAttrs(COLOR_PAIR(BOX_COLOR_GREEN_ON_BLACK), attrs); return entry; diff --git a/src/musikbox/app/window/TransportWindow.cpp b/src/musikbox/app/window/TransportWindow.cpp index 8344108dc..e319bb7ce 100755 --- a/src/musikbox/app/window/TransportWindow.cpp +++ b/src/musikbox/app/window/TransportWindow.cpp @@ -111,7 +111,7 @@ void TransportWindow::Update() { if (this->currentTrack) { title = this->currentTrack->GetValue(constants::Track::TITLE); - album = this->currentTrack->GetValue(constants::Track::ALBUM_ID); + album = this->currentTrack->GetValue(constants::Track::ALBUM); duration = this->currentTrack->GetValue(constants::Track::DURATION); } diff --git a/src/musikbox/musikbox.vcxproj b/src/musikbox/musikbox.vcxproj index bc705907d..ea91272c6 100755 --- a/src/musikbox/musikbox.vcxproj +++ b/src/musikbox/musikbox.vcxproj @@ -121,7 +121,6 @@ - @@ -163,7 +162,6 @@ - diff --git a/src/musikbox/musikbox.vcxproj.filters b/src/musikbox/musikbox.vcxproj.filters index 0ad18597f..343865559 100755 --- a/src/musikbox/musikbox.vcxproj.filters +++ b/src/musikbox/musikbox.vcxproj.filters @@ -60,9 +60,6 @@ app\window - - app\query - app\util @@ -195,9 +192,6 @@ app\window - - app\query - app\util