diff --git a/src/musikcube/app/layout/BrowseLayout.cpp b/src/musikcube/app/layout/BrowseLayout.cpp index 11ea43d71..a27b8afee 100755 --- a/src/musikcube/app/layout/BrowseLayout.cpp +++ b/src/musikcube/app/layout/BrowseLayout.cpp @@ -72,7 +72,7 @@ static int kMinListTitleHeight = 26; #define DEFAULT_CATEGORY constants::Track::ARTIST #define DEFAULT_CATEGORY_NAME FIELD_TO_TITLE[DEFAULT_CATEGORY] -static std::set EDIT_KEYS; +static std::set kEditKeys; static std::map FIELD_TO_TITLE { std::make_pair(constants::Track::ARTIST, "browse_title_artists"), @@ -110,7 +110,7 @@ BrowseLayout::BrowseLayout( : LayoutBase() , playlistModified(false) , playback(playback) { - EDIT_KEYS = { + kEditKeys = { Hotkeys::Get(Hotkeys::PlayQueueMoveUp), Hotkeys::Get(Hotkeys::PlayQueueMoveDown), Hotkeys::Get(Hotkeys::PlayQueueDelete) @@ -390,7 +390,7 @@ bool BrowseLayout::ProcessPlaylistOperation(const std::string& key) { } bool BrowseLayout::ProcessEditOperation(const std::string& key) { - if (this->GetFocus() != this->trackList || EDIT_KEYS.find(key) == EDIT_KEYS.end()) { + if (this->GetFocus() != this->trackList || kEditKeys.find(key) == kEditKeys.end()) { return false; } @@ -399,7 +399,7 @@ bool BrowseLayout::ProcessEditOperation(const std::string& key) { } std::shared_ptr tracks = this->trackList->GetTrackList(); - if (tracks && EDIT_KEYS.find(key) != EDIT_KEYS.end()) { + if (tracks && kEditKeys.find(key) != kEditKeys.end()) { const size_t selected = this->trackList->GetSelectedTrackIndex(); size_t to = -1; bool modified = this->playlistModified; diff --git a/src/musikcube/app/layout/HotkeysLayout.cpp b/src/musikcube/app/layout/HotkeysLayout.cpp index 6244f2e89..1d2c2dc86 100644 --- a/src/musikcube/app/layout/HotkeysLayout.cpp +++ b/src/musikcube/app/layout/HotkeysLayout.cpp @@ -53,7 +53,7 @@ using Entry = IScrollAdapter::EntryPtr; using Callback = std::function; static std::string formattedTime() { - char buffer[128]; + char buffer[128] = { 0 }; time_t rawtime; struct tm* timeinfo; time(&rawtime); @@ -63,7 +63,7 @@ static std::string formattedTime() { } static void confirmResetHotkeys(Callback cb) { - std::shared_ptr dialog(new DialogOverlay()); + auto dialog = std::make_shared(); (*dialog) .SetTitle(_TSTR("hotkeys_reset_all_title")) @@ -89,7 +89,7 @@ static void checkConflictAndSave(Hotkeys::Id id, const std::string& key, Callbac } if (existing.size()) { - std::shared_ptr dialog(new DialogOverlay()); + auto dialog = std::make_shared(); std::string message = _TSTR("hotkeys_conflict_message"); ReplaceAll(message, "{{hotkey}}", key); @@ -122,7 +122,7 @@ static void backupAndShowDialog() { std::string out = dir + "hotkeys-" + formattedTime() + ".json"; if (CopyFile(in, out)) { - std::shared_ptr dialog(new DialogOverlay()); + auto dialog = std::make_shared(); std::string message = _TSTR("hotkeys_backup_success_message"); ReplaceAll(message, "{{path}}", out); @@ -135,7 +135,7 @@ static void backupAndShowDialog() { App::Overlays().Push(dialog); } else { - std::shared_ptr dialog(new DialogOverlay()); + auto dialog = std::make_shared(); std::string message = _TSTR("hotkeys_backup_failure_message"); ReplaceAll(message, "{{path}}", dir); @@ -150,7 +150,7 @@ static void backupAndShowDialog() { } static void showDeleteOverlay(Hotkeys::Id id, Callback cb) { - std::shared_ptr dialog(new DialogOverlay()); + auto dialog = std::make_shared(); std::string message = _TSTR("hotkeys_delete_binding_message"); ReplaceAll(message, "{{key}}", Hotkeys::Name(id)); @@ -191,12 +191,9 @@ HotkeysLayout::HotkeysLayout() { this->listWindow->SetFocusOrder(0); } -HotkeysLayout::~HotkeysLayout() { -} - void HotkeysLayout::OnEntryActivated(cursespp::ListWindow* list, size_t index) { - Hotkeys::Id id = static_cast(index); - auto shortcuts = this->shortcuts; + const Hotkeys::Id id = static_cast(index); + const auto shortcuts = this->shortcuts; ReassignHotkeyOverlay::Show(id, [this, list, id](std::string key) { checkConflictAndSave(id, key, [this, list]() { @@ -237,13 +234,13 @@ void HotkeysLayout::SetShortcutsWindow(ShortcutsWindow* shortcuts) { } bool HotkeysLayout::KeyPress(const std::string& kn) { - auto refresh = [this]() { + const auto refresh = [this]() { this->listWindow->OnAdapterChanged(); this->SetShortcutsWindow(this->shortcuts); }; if (kn == "KEY_DC") { - auto index = this->listWindow->GetSelectedIndex(); + const auto index = this->listWindow->GetSelectedIndex(); if (index != ListWindow::NO_SELECTION) { showDeleteOverlay(static_cast(index), refresh); return true; diff --git a/src/musikcube/app/layout/HotkeysLayout.h b/src/musikcube/app/layout/HotkeysLayout.h index 218502889..72d290e39 100644 --- a/src/musikcube/app/layout/HotkeysLayout.h +++ b/src/musikcube/app/layout/HotkeysLayout.h @@ -48,9 +48,9 @@ namespace musik { public sigslot::has_slots<> { public: - HotkeysLayout(); + DELETE_COPY_AND_ASSIGNMENT_DEFAULTS(HotkeysLayout) - ~HotkeysLayout(); + HotkeysLayout(); /* ITopLevelLayout */ void SetShortcutsWindow( diff --git a/src/musikcube/app/layout/LibraryLayout.cpp b/src/musikcube/app/layout/LibraryLayout.cpp index 2c4e2243f..31e219ef7 100755 --- a/src/musikcube/app/layout/LibraryLayout.cpp +++ b/src/musikcube/app/layout/LibraryLayout.cpp @@ -53,20 +53,26 @@ #include "LibraryLayout.h" +using namespace musik; +using namespace musik::core; +using namespace musik::core::audio; +using namespace musik::core::library; using namespace musik::core::library::constants; +using namespace musik::cube; using namespace musik::core::runtime; +using namespace cursespp; + +namespace keys = musik::cube::prefs::keys; +namespace components = musik::core::prefs::components; #define SHOULD_REFOCUS(target) \ (this->visibleLayout == target) && \ (this->shortcuts && !this->shortcuts->IsFocused()) -using namespace musik; -using namespace musik::core; -using namespace musik::core::audio; -using namespace musik::core::library; -using namespace musik::cube; -using namespace musik::core::runtime; -using namespace cursespp; +#define REMEMBER(key, value) { \ + auto prefs = Preferences::ForComponent(components::Session); \ + prefs->SetString(key, value.c_str()); this->prefs->Save(); \ +} namespace type { const std::string CategoryFilter = "CategoryFilter"; @@ -76,14 +82,6 @@ namespace type { const std::string NowPlaying = "NowPlaying"; }; -namespace keys = musik::cube::prefs::keys; -namespace components = musik::core::prefs::components; - -#define REMEMBER(key, value) { \ - auto prefs = Preferences::ForComponent(components::Session); \ - prefs->SetString(key, value.c_str()); this->prefs->Save(); \ -} - LibraryLayout::LibraryLayout(musik::core::audio::PlaybackService& playback, ILibraryPtr library) : LayoutBase() , playback(playback) @@ -94,19 +92,16 @@ LibraryLayout::LibraryLayout(musik::core::audio::PlaybackService& playback, ILib this->InitializeWindows(); } -LibraryLayout::~LibraryLayout() { -} - void LibraryLayout::OnLayout() { - bool autoHideCommandBar = this->prefs->GetBool(keys::AutoHideCommandBar, false); - int x = 0, y = 0; - int cx = this->GetWidth(), cy = this->GetHeight(); + const bool autoHideCommandBar = this->prefs->GetBool(keys::AutoHideCommandBar, false); + const int x = 0, y = 0; + const int cx = this->GetWidth(), cy = this->GetHeight(); #ifdef WIN32 - int transportCy = 3; + const int transportCy = 3; #else - int transportCy = (autoHideCommandBar ? 2 : 3); + const int transportCy = (autoHideCommandBar ? 2 : 3); #endif - int mainHeight = cy - transportCy; + const int mainHeight = cy - transportCy; this->transportView->MoveAndResize(1, mainHeight, cx - 2, transportCy); if (this->visibleLayout) { this->visibleLayout->MoveAndResize(x, y, cx, mainHeight); @@ -200,13 +195,13 @@ void LibraryLayout::ShowDirectories(const std::string& directory) { } void LibraryLayout::InitializeWindows() { - this->browseLayout.reset(new BrowseLayout(this->playback, this->library)); - this->directoryLayout.reset(new DirectoryLayout(this->playback, this->library)); - this->nowPlayingLayout.reset(new NowPlayingLayout(this->playback, this->library)); - this->categorySearchLayout.reset(new CategorySearchLayout(this->playback, this->library)); + this->browseLayout = std::make_shared(this->playback, this->library); + this->directoryLayout = std::make_shared(this->playback, this->library); + this->nowPlayingLayout = std::make_shared(this->playback, this->library); + this->categorySearchLayout = std::make_shared(this->playback, this->library); this->categorySearchLayout->SearchResultSelected.connect(this, &LibraryLayout::OnCategorySearchResultSelected); - this->trackSearchLayout.reset(new TrackSearchLayout(this->playback, this->library)); - this->transportView.reset(new TransportWindow(this->library, this->playback)); + this->trackSearchLayout = std::make_shared(this->playback, this->library); + this->transportView = std::make_shared(this->library, this->playback); this->AddWindow(this->transportView); this->LoadLastSession(); @@ -376,30 +371,33 @@ bool LibraryLayout::SetFocus(cursespp::IWindowPtr window) { void LibraryLayout::ProcessMessage(musik::core::runtime::IMessage &message) { switch (message.Type()) { case message::JumpToCategory: { - static std::map JUMP_TYPE_TO_COLUMN = { - { cube::message::category::Album, constants::Track::ALBUM }, - { cube::message::category::Artist, constants::Track::ARTIST }, - { cube::message::category::AlbumArtist, constants::Track::ALBUM_ARTIST }, - { cube::message::category::Genre, constants::Track::GENRE } - }; + static std::map JUMP_TYPE_TO_COLUMN = { + { cube::message::category::Album, constants::Track::ALBUM }, + { cube::message::category::Artist, constants::Track::ARTIST }, + { cube::message::category::AlbumArtist, constants::Track::ALBUM_ARTIST }, + { cube::message::category::Genre, constants::Track::GENRE } + }; - auto type = JUMP_TYPE_TO_COLUMN[(int)message.UserData1()]; - auto id = message.UserData2(); - this->OnCategorySearchResultSelected(nullptr, type, id); - } - break; + auto type = JUMP_TYPE_TO_COLUMN[(int)message.UserData1()]; + const auto id = message.UserData2(); + this->OnCategorySearchResultSelected(nullptr, type, id); + } + break; case core::message::PlaylistModified: case core::message::PlaylistCreated: case core::message::PlaylistRenamed: case core::message::PlaylistDeleted: { - MessageQueue().Post(Message::Create( - this->browseLayout.get(), - message.Type(), - message.UserData1(), - message.UserData2())); - } - break; + MessageQueue().Post(Message::Create( + this->browseLayout.get(), + message.Type(), + message.UserData1(), + message.UserData2())); + } + break; + + default: + break; } LayoutBase::ProcessMessage(message); diff --git a/src/musikcube/app/layout/LibraryLayout.h b/src/musikcube/app/layout/LibraryLayout.h index f8b38e3b0..62553eb68 100755 --- a/src/musikcube/app/layout/LibraryLayout.h +++ b/src/musikcube/app/layout/LibraryLayout.h @@ -57,12 +57,12 @@ namespace musik { public sigslot::has_slots<> { public: + DELETE_CLASS_DEFAULTS(LibraryLayout) + LibraryLayout( musik::core::audio::PlaybackService& playback, musik::core::ILibraryPtr library); - virtual ~LibraryLayout(); - cursespp::IWindowPtr FocusNext() override; cursespp::IWindowPtr FocusPrev() override; cursespp::IWindowPtr GetFocus() override; diff --git a/src/musikcube/app/layout/LibraryNotConnectedLayout.cpp b/src/musikcube/app/layout/LibraryNotConnectedLayout.cpp index b033d2d2b..9b3826345 100644 --- a/src/musikcube/app/layout/LibraryNotConnectedLayout.cpp +++ b/src/musikcube/app/layout/LibraryNotConnectedLayout.cpp @@ -62,8 +62,8 @@ static inline std::string resolveErrorMessage(MasterLibraryPtr library) { auto remoteLibrary = dynamic_cast(library->Wrapped().get()); if (remoteLibrary) { - auto error = remoteLibrary->WebSocketClient().LastConnectionError(); - auto it = kStateToErrorString.find(error); + const auto error = remoteLibrary->WebSocketClient().LastConnectionError(); + const auto it = kStateToErrorString.find(error); if (it != kStateToErrorString.end()) { std::string value = _TSTR(it->second); if (error == WebSocketClient::ConnectionError::IncompatibleVersion) { @@ -110,8 +110,8 @@ LibraryNotConnectedLayout::LibraryNotConnectedLayout(MasterLibraryPtr library) void LibraryNotConnectedLayout::OnLayout() { LayoutBase::OnLayout(); - int cx = this->GetContentWidth(); - int cy = this->GetContentHeight(); + const int cx = this->GetContentWidth(); + const int cy = this->GetContentHeight(); this->messageText->MoveAndResize(1, (cy / 2) - 2, cx - 2, 1); this->errorText->MoveAndResize(1, (cy / 2) - 1, cx - 2, 1); this->helpText->MoveAndResize(1, (cy / 2) + 1, cx - 2, 1); diff --git a/src/musikcube/app/layout/LibraryNotConnectedLayout.h b/src/musikcube/app/layout/LibraryNotConnectedLayout.h index d6b419199..599e16b0e 100644 --- a/src/musikcube/app/layout/LibraryNotConnectedLayout.h +++ b/src/musikcube/app/layout/LibraryNotConnectedLayout.h @@ -50,6 +50,8 @@ namespace musik { namespace cube { public: using MasterLibraryPtr = std::shared_ptr; + DELETE_CLASS_DEFAULTS(LibraryNotConnectedLayout) + LibraryNotConnectedLayout(MasterLibraryPtr library); /* IWindow */ diff --git a/src/musikcube/app/layout/LocalLibrarySettingsLayout.cpp b/src/musikcube/app/layout/LocalLibrarySettingsLayout.cpp index e964737a3..8bad7417b 100644 --- a/src/musikcube/app/layout/LocalLibrarySettingsLayout.cpp +++ b/src/musikcube/app/layout/LocalLibrarySettingsLayout.cpp @@ -66,22 +66,19 @@ LocalLibrarySettingsLayout::LocalLibrarySettingsLayout() : LayoutBase() , library(LibraryFactory::Instance().DefaultLocalLibrary()) , indexer(library->Indexer()) { - this->browseAdapter.reset(new DirectoryAdapter()); - this->addedPathsAdapter.reset(new SimpleScrollAdapter()); + this->browseAdapter = std::make_shared(); + this->addedPathsAdapter = std::make_shared(); this->SetFocusMode(FocusModeTerminating); this->InitializeWindows(); } -LocalLibrarySettingsLayout::~LocalLibrarySettingsLayout() { -} - void LocalLibrarySettingsLayout::OnLayout() { - int cx = this->GetWidth(); - int leftX = 0; - int leftWidth = cx / 3; /* 1/3 width */ - int rightX = leftWidth; - int rightWidth = cx - rightX; /* remainder (~2/3) */ - int pathsHeight = this->GetHeight() - 1; + const int cx = this->GetWidth(); + const int leftX = 0; + const int leftWidth = cx / 3; /* 1/3 width */ + const int rightX = leftWidth; + const int rightWidth = cx - rightX; /* remainder (~2/3) */ + const int pathsHeight = this->GetHeight() - 1; this->browseList->MoveAndResize(leftX, 1, leftWidth, pathsHeight); this->addedPathsList->MoveAndResize(rightX, 1, rightWidth, pathsHeight); } @@ -94,7 +91,7 @@ void LocalLibrarySettingsLayout::LoadPreferences() { for (size_t i = 0; i < paths.size(); i++) { auto v = paths.at(i); - auto e = EntryPtr(new SingleLineEntry(v)); + auto e = std::make_shared(v); this->addedPathsAdapter->AddEntry(e); } @@ -110,8 +107,8 @@ Color LocalLibrarySettingsLayout::ListItemDecorator( if (scrollable == this->addedPathsList.get() || scrollable == this->browseList.get()) { - ListWindow* lw = static_cast(scrollable); - if (lw->GetSelectedIndex() == index) { + ListWindow* lw = dynamic_cast(scrollable); + if (lw && lw->GetSelectedIndex() == index) { return Color::ListItemHighlighted; } } @@ -121,10 +118,10 @@ Color LocalLibrarySettingsLayout::ListItemDecorator( void LocalLibrarySettingsLayout::InitializeWindows() { this->SetFrameVisible(false); - this->addedPathsList.reset(new cursespp::ListWindow(this->addedPathsAdapter)); + this->addedPathsList = std::make_shared(this->addedPathsAdapter); this->addedPathsList->SetFrameTitle(_TSTR("settings_backspace_to_remove")); - this->browseList.reset(new cursespp::ListWindow(this->browseAdapter)); + this->browseList = std::make_shared(this->browseAdapter); this->browseList->SetFrameTitle(_TSTR("settings_space_to_add")); ScrollAdapterBase::ItemDecorator decorator = @@ -173,7 +170,7 @@ void LocalLibrarySettingsLayout::RemoveSelectedDirectory() { std::vector paths; this->indexer->GetPaths(paths); - size_t index = this->addedPathsList->GetSelectedIndex(); + const size_t index = this->addedPathsList->GetSelectedIndex(); if (index != ListWindow::NO_SELECTION) { this->indexer->RemovePath(paths.at(index)); this->LoadPreferences(); diff --git a/src/musikcube/app/layout/LocalLibrarySettingsLayout.h b/src/musikcube/app/layout/LocalLibrarySettingsLayout.h index 2520b558d..49230a8bf 100644 --- a/src/musikcube/app/layout/LocalLibrarySettingsLayout.h +++ b/src/musikcube/app/layout/LocalLibrarySettingsLayout.h @@ -43,8 +43,9 @@ namespace musik { namespace cube { class LocalLibrarySettingsLayout: public cursespp::LayoutBase { public: + DELETE_COPY_AND_ASSIGNMENT_DEFAULTS(LocalLibrarySettingsLayout) + LocalLibrarySettingsLayout(); - virtual ~LocalLibrarySettingsLayout(); void ToggleShowDotFiles(); void LoadPreferences(); diff --git a/src/musikcube/app/layout/LyricsLayout.cpp b/src/musikcube/app/layout/LyricsLayout.cpp index 4767efd9b..cedd26928 100644 --- a/src/musikcube/app/layout/LyricsLayout.cpp +++ b/src/musikcube/app/layout/LyricsLayout.cpp @@ -76,8 +76,8 @@ LyricsLayout::LyricsLayout(PlaybackService& playback, ILibraryPtr library) void LyricsLayout::OnLayout() { LayoutBase::OnLayout(); - int cx = this->GetContentWidth(); - int cy = this->GetContentHeight(); + const int cx = this->GetContentWidth(); + const int cy = this->GetContentHeight(); this->listView->MoveAndResize(0, 0, cx, cy); this->infoText->MoveAndResize(1, cy / 2, cx - 2, 1); } @@ -137,11 +137,12 @@ void LyricsLayout::OnVisibilityChanged(bool visible) { void LyricsLayout::ProcessMessage(musik::core::runtime::IMessage &m) { if (m.Type() == message::LyricsLoaded) { - if ((State) m.UserData1() == State::Loaded && this->currentLyrics.size()) { + const auto state = static_cast(m.UserData1()); + if (state == State::Loaded && this->currentLyrics.size()) { this->OnLyricsLoaded(); } else { - this->SetState((State) m.UserData1()); + this->SetState(state); } } else { @@ -155,20 +156,20 @@ void LyricsLayout::LoadLyricsForCurrentTrack() { this->currentTrackId = track->GetId(); this->currentLyrics = ""; this->SetState(State::Loading); - auto trackExternalId = track->GetString("external_id"); + const auto trackExternalId = track->GetString("external_id"); auto lyricsDbQuery = std::make_shared(trackExternalId); this->library->Enqueue(lyricsDbQuery, [this, lyricsDbQuery, track](auto q) { auto localLyrics = lyricsDbQuery->GetResult(); if (localLyrics.size()) { this->currentLyrics = localLyrics; - this->Post(message::LyricsLoaded, (int64_t) State::Loaded); + this->Post(message::LyricsLoaded, static_cast(State::Loaded)); } else { auddio::FindLyrics(track, [this](TrackPtr track, std::string remoteLyrics) { if (this->currentTrackId == track->GetId()) { this->currentLyrics = remoteLyrics; - auto state = remoteLyrics.size() ? State::Loaded : State::Failed; - this->Post(message::LyricsLoaded, (int64_t) state); + const auto state = remoteLyrics.size() ? State::Loaded : State::Failed; + this->Post(message::LyricsLoaded, static_cast(state)); } }); } diff --git a/src/musikcube/app/layout/LyricsLayout.h b/src/musikcube/app/layout/LyricsLayout.h index e37e85085..5c1a6cf08 100644 --- a/src/musikcube/app/layout/LyricsLayout.h +++ b/src/musikcube/app/layout/LyricsLayout.h @@ -16,6 +16,8 @@ namespace musik { namespace cube { public sigslot::has_slots<> { public: + DELETE_CLASS_DEFAULTS(LyricsLayout) + LyricsLayout( musik::core::audio::PlaybackService& playback, musik::core::ILibraryPtr library); diff --git a/src/musikcube/app/layout/MainLayout.cpp b/src/musikcube/app/layout/MainLayout.cpp index cec9e626a..50c0edf97 100755 --- a/src/musikcube/app/layout/MainLayout.cpp +++ b/src/musikcube/app/layout/MainLayout.cpp @@ -121,7 +121,7 @@ MainLayout::MainLayout( this->settingsLayout = std::make_shared(app, library, playback); this->hotkeysLayout = std::make_shared(); - this->topBanner.reset(new TextLabel()); + this->topBanner = std::make_shared(); this->topBanner->SetContentColor(Color::Header); this->topBanner->Hide(); this->AddWindow(this->topBanner); @@ -139,7 +139,7 @@ MainLayout::~MainLayout() { } bool MainLayout::ShowTopBanner() { - auto libraryType = this->library->GetType(); + const auto libraryType = this->library->GetType(); if (libraryType == ILibrary::Type::Local) { return this->library->Indexer()->GetState() == IIndexer::StateIndexing; } @@ -150,7 +150,7 @@ bool MainLayout::ShowTopBanner() { } void MainLayout::UpdateTopBannerText() { - auto libraryType = this->library->GetType(); + const auto libraryType = this->library->GetType(); if (libraryType == ILibrary::Type::Local) { updateSyncingText(this->topBanner.get(), this->syncUpdateCount); } @@ -161,9 +161,9 @@ void MainLayout::UpdateTopBannerText() { void MainLayout::OnLayout() { if (this->ShowTopBanner()) { - size_t cx = this->GetContentWidth(); + const int cx = this->GetContentWidth(); this->SetPadding(1, 0, 0, 0); - this->topBanner->MoveAndResize(0, 0, (int) cx, 1); + this->topBanner->MoveAndResize(0, 0, cx, 1); this->topBanner->Show(); this->UpdateTopBannerText(); } @@ -217,7 +217,7 @@ void MainLayout::Stop() { } void MainLayout::ProcessMessage(musik::core::runtime::IMessage &message) { - int type = message.Type(); + const int type = message.Type(); if (type == message::JumpToConsole) { this->SetLayout(consoleLayout); @@ -245,7 +245,7 @@ void MainLayout::ProcessMessage(musik::core::runtime::IMessage &message) { this->Layout(); } else if (type == message::IndexerProgress) { - this->syncUpdateCount = (int) message.UserData1(); + this->syncUpdateCount = narrow_cast(message.UserData1()); this->UpdateTopBannerText(); if (!topBanner->IsVisible()) { this->Layout(); @@ -280,7 +280,7 @@ void MainLayout::SwitchToPlayQueue() { void MainLayout::SwitchToLibraryLayout() { if (IsLibraryConnected()) { if (!this->libraryLayout) { - this->libraryLayout.reset(new LibraryLayout(playback, library)); + this->libraryLayout = std::make_shared(playback, library); } this->SetLayout(libraryLayout); } diff --git a/src/musikcube/app/layout/MainLayout.h b/src/musikcube/app/layout/MainLayout.h index 414fb3b5a..5fa63cd16 100755 --- a/src/musikcube/app/layout/MainLayout.h +++ b/src/musikcube/app/layout/MainLayout.h @@ -55,6 +55,8 @@ namespace musik { public: using MasterLibraryPtr = std::shared_ptr; + DELETE_CLASS_DEFAULTS(MainLayout) + MainLayout( cursespp::App& app, ConsoleLogger* logger, diff --git a/src/musikcube/app/layout/NowPlayingLayout.cpp b/src/musikcube/app/layout/NowPlayingLayout.cpp index da19ba494..38c66e3d1 100755 --- a/src/musikcube/app/layout/NowPlayingLayout.cpp +++ b/src/musikcube/app/layout/NowPlayingLayout.cpp @@ -62,7 +62,7 @@ using namespace cursespp; namespace keys = musik::cube::prefs::keys; namespace components = musik::core::prefs::components; -static std::set EDIT_KEYS; +static std::set kEditKeys; static std::string formatWithAlbum(TrackPtr track, size_t index, size_t width); @@ -82,21 +82,18 @@ NowPlayingLayout::NowPlayingLayout( this->trackListView->SetRowRenderer( TrackRowRenderers::Get(TrackRowRenderers::Type::NowPlaying)); - EDIT_KEYS = { + kEditKeys = { Hotkeys::Get(Hotkeys::PlayQueueMoveUp), Hotkeys::Get(Hotkeys::PlayQueueMoveDown), Hotkeys::Get(Hotkeys::PlayQueueDelete) }; } -NowPlayingLayout::~NowPlayingLayout() { -} - Color NowPlayingLayout::RowDecorator(musik::core::TrackPtr track, size_t index) { - bool selected = index == trackListView->GetSelectedIndex(); + const bool selected = index == trackListView->GetSelectedIndex(); Color attrs = selected ? Color::ListItemHighlighted : Color::Default; - size_t playingIndex = playback.GetIndex(); + const size_t playingIndex = playback.GetIndex(); if (index == playingIndex) { TrackPtr playing = playback.GetPlaying(); @@ -128,10 +125,14 @@ void NowPlayingLayout::OnLayout() { } void NowPlayingLayout::InitializeWindows() { - this->trackListView.reset(new TrackListView( + this->trackListView = std::make_shared( this->playback, this->library, - std::bind(&NowPlayingLayout::RowDecorator, this, std::placeholders::_1, std::placeholders::_2))); + std::bind( + &NowPlayingLayout::RowDecorator, + this, + std::placeholders::_1, + std::placeholders::_2)); this->trackListView->SetFrameTitle(_TSTR("playqueue_title")); this->trackListView->Requeried.connect(this, &NowPlayingLayout::OnTrackListRequeried); @@ -162,14 +163,14 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::library::query::TrackLi if (playback.Count()) { /* regular logic (i.e, no edit operation) */ if (this->reselectIndex == -1) { - size_t index = playback.GetIndex(); + const size_t index = playback.GetIndex(); if (index == ListWindow::NO_SELECTION) { /* not playing? */ this->trackListView->ScrollTo(0); this->trackListView->SetSelectedIndex(0); } else { /* playing... */ - size_t scrollToIndex = index == 0 ? index : index - 1; + const size_t scrollToIndex = index == 0 ? index : index - 1; if (!this->trackListView->IsEntryVisible(scrollToIndex)) { this->trackListView->ScrollTo(scrollToIndex); } @@ -184,10 +185,10 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::library::query::TrackLi /* ensure the correct index is selected, and that it's properly scrolled into view */ this->reselectIndex = std::min((int) this->trackListView->TrackCount() - 1, this->reselectIndex); - this->trackListView->SetSelectedIndex((size_t)this->reselectIndex); + this->trackListView->SetSelectedIndex(narrow_cast(this->reselectIndex)); - if (!this->trackListView->IsEntryVisible((size_t) this->reselectIndex)) { - this->trackListView->ScrollTo((size_t)this->reselectIndex); + if (!this->trackListView->IsEntryVisible(narrow_cast(this->reselectIndex))) { + this->trackListView->ScrollTo(narrow_cast(this->reselectIndex)); } this->reselectIndex = -1; @@ -195,7 +196,7 @@ void NowPlayingLayout::OnTrackListRequeried(musik::core::library::query::TrackLi /* if after a bunch of monkeying around there's still nothing selected, but we have contents, let's just select the first item */ - auto sel = this->trackListView->GetSelectedIndex(); + const auto sel = this->trackListView->GetSelectedIndex(); if (sel == ListWindow::NO_SELECTION || sel >= this->trackListView->TrackCount()) { this->trackListView->SetSelectedIndex(0); this->trackListView->ScrollTo(0); @@ -213,9 +214,7 @@ void NowPlayingLayout::RequeryTrackList() { } void NowPlayingLayout::OnPlaylistSelected(int64_t playlistId) { - auto query = std::shared_ptr( - new GetPlaylistQuery(library, playlistId)); - + auto query = std::make_shared(library, playlistId); this->lastPlaylistQueryId = query->GetId(); this->trackListView->Requery(query); } @@ -253,30 +252,30 @@ bool NowPlayingLayout::KeyPress(const std::string& key) { } bool NowPlayingLayout::ProcessEditOperation(const std::string& key) { - if (EDIT_KEYS.find(key) != EDIT_KEYS.end()) { + if (kEditKeys.find(key) != kEditKeys.end()) { if (!playback.IsShuffled()) { - size_t selected = this->trackListView->GetSelectedIndex(); + const size_t selected = this->trackListView->GetSelectedIndex(); this->reselectIndex = -1; { PlaybackService::Editor editor = this->playback.Edit(); if (Hotkeys::Is(Hotkeys::PlayQueueMoveUp, key)) { if (selected > 0) { - size_t to = selected - 1; + const size_t to = selected - 1; editor.Move(selected, to); - reselectIndex = (int)to; + reselectIndex = narrow_cast(to); } } else if (Hotkeys::Is(Hotkeys::PlayQueueMoveDown, key)) { if (selected < this->playback.Count() - 1) { - size_t to = selected + 1; + const size_t to = selected + 1; editor.Move(selected, to); - reselectIndex = (int)to; + reselectIndex = narrow_cast(to); } } else if (Hotkeys::Is(Hotkeys::PlayQueueDelete, key)) { editor.Delete(selected); - reselectIndex = (int)selected; + reselectIndex = narrow_cast(selected); } } diff --git a/src/musikcube/app/layout/NowPlayingLayout.h b/src/musikcube/app/layout/NowPlayingLayout.h index 9f4a7d1c2..a5cf19ce5 100755 --- a/src/musikcube/app/layout/NowPlayingLayout.h +++ b/src/musikcube/app/layout/NowPlayingLayout.h @@ -52,12 +52,12 @@ namespace musik { public sigslot::has_slots<> { public: + DELETE_CLASS_DEFAULTS(NowPlayingLayout) + NowPlayingLayout( musik::core::audio::PlaybackService& playback, musik::core::ILibraryPtr library); - virtual ~NowPlayingLayout(); - /* IWindow */ void OnVisibilityChanged(bool visible) override; bool KeyPress(const std::string& key) override; diff --git a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp index 39ab80f58..0baea90b9 100644 --- a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp +++ b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.cpp @@ -202,8 +202,8 @@ void RemoteLibrarySettingsLayout::LoadPreferences() { this->httpTlsCheckbox->CheckChanged.disconnect(this); auto host = prefs->GetString(core::prefs::keys::RemoteLibraryHostname, "127.0.0.1"); - auto const wssPort = (unsigned short) prefs->GetInt(core::prefs::keys::RemoteLibraryWssPort, 7905); - auto const httpPort = (unsigned short) prefs->GetInt(core::prefs::keys::RemoteLibraryHttpPort, 7906); + auto const wssPort = narrow_cast(prefs->GetInt(core::prefs::keys::RemoteLibraryWssPort, 7905)); + auto const httpPort = narrow_cast(prefs->GetInt(core::prefs::keys::RemoteLibraryHttpPort, 7906)); auto const password = prefs->GetString(core::prefs::keys::RemoteLibraryPassword, ""); auto const wssTls = prefs->GetBool(core::prefs::keys::RemoteLibraryWssTls, false); auto const httpTls = prefs->GetBool(core::prefs::keys::RemoteLibraryHttpTls, false); diff --git a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h index cf65c8ee5..95e5a81e2 100644 --- a/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h +++ b/src/musikcube/app/layout/RemoteLibrarySettingsLayout.h @@ -44,8 +44,9 @@ namespace musik { namespace cube { class RemoteLibrarySettingsLayout: public cursespp::LayoutBase, public sigslot::has_slots<> { public: - RemoteLibrarySettingsLayout(); + DELETE_COPY_AND_ASSIGNMENT_DEFAULTS(RemoteLibrarySettingsLayout) + RemoteLibrarySettingsLayout(); virtual ~RemoteLibrarySettingsLayout(); void LoadPreferences(); diff --git a/src/musikcube/app/layout/TrackSearchLayout.cpp b/src/musikcube/app/layout/TrackSearchLayout.cpp index b82c31c6c..02b46bd0d 100755 --- a/src/musikcube/app/layout/TrackSearchLayout.cpp +++ b/src/musikcube/app/layout/TrackSearchLayout.cpp @@ -62,8 +62,8 @@ using namespace cursespp; namespace keys = musik::cube::prefs::keys; namespace components = musik::core::prefs::components; -#define SEARCH_HEIGHT 3 -#define REQUERY_INTERVAL_MS 300 +constexpr int kSearchHeight = 3; +constexpr int kRequeryIntervalMs = 300; static TrackSortType getDefaultTrackSort(std::shared_ptr prefs) { return (TrackSortType) prefs->GetInt( @@ -104,32 +104,32 @@ void TrackSearchLayout::SaveSession() { } void TrackSearchLayout::OnLayout() { - int cx = this->GetWidth(), cy = this->GetHeight(); - int x = 0, y = 0; + const int cx = this->GetWidth(), cy = this->GetHeight(); + const int x = 0, y = 0; - int inputWidth = cx / 2; - int inputX = x + ((cx - inputWidth) / 2); - this->input->MoveAndResize(inputX, y, cx / 2, SEARCH_HEIGHT); + const int inputWidth = cx / 2; + const int inputX = x + ((cx - inputWidth) / 2); + this->input->MoveAndResize(inputX, y, cx / 2, kSearchHeight); - bool inputIsRegex = this->matchType == MatchType::Regex; + const bool inputIsRegex = this->matchType == MatchType::Regex; this->input->SetHint(_TSTR(inputIsRegex ? "search_regex_hint" : "search_filter_hint")); this->input->SetFocusedFrameColor(inputIsRegex ? Color::FrameImportant : Color::FrameFocused); this->trackList->MoveAndResize( x, - y + SEARCH_HEIGHT, + y + kSearchHeight, this->GetWidth(), - this->GetHeight() - SEARCH_HEIGHT); + this->GetHeight() - kSearchHeight); } void TrackSearchLayout::InitializeWindows() { - this->input.reset(new cursespp::TextInput()); + this->input = std::make_shared(); this->input->TextChanged.connect(this, &TrackSearchLayout::OnInputChanged); this->input->EnterPressed.connect(this, &TrackSearchLayout::OnEnterPressed); this->input->SetFocusOrder(0); this->AddWindow(this->input); - this->trackList.reset(new TrackListView(this->playback, this->library)); + this->trackList = std::make_shared(this->playback, this->library); this->trackList->SetFocusOrder(1); this->trackList->SetAllowArrowKeyPropagation(); this->trackList->Requeried.connect(this, &TrackSearchLayout::OnRequeried); @@ -157,9 +157,12 @@ void TrackSearchLayout::FocusInput() { void TrackSearchLayout::Requery() { const std::string& filter = this->input->GetText(); const TrackSortType sortOrder = getDefaultTrackSort(this->prefs); - this->trackList->Requery(std::shared_ptr( - new SearchTrackListQuery( - this->library, this->matchType, filter, sortOrder))); + this->trackList->Requery( + std::make_shared( + this->library, + this->matchType, + filter, + sortOrder)); } void TrackSearchLayout::PlayFromTop() { @@ -186,7 +189,7 @@ void TrackSearchLayout::OnRequeried(TrackListQueryBase* query) { void TrackSearchLayout::OnInputChanged(cursespp::TextInput* sender, std::string value) { if (this->IsVisible()) { - Debounce(message::RequeryTrackList, 0, 0, REQUERY_INTERVAL_MS); + Debounce(message::RequeryTrackList, 0, 0, kRequeryIntervalMs); } } diff --git a/src/musikcube/app/layout/TrackSearchLayout.h b/src/musikcube/app/layout/TrackSearchLayout.h index 197179861..31e137a2a 100755 --- a/src/musikcube/app/layout/TrackSearchLayout.h +++ b/src/musikcube/app/layout/TrackSearchLayout.h @@ -52,6 +52,8 @@ namespace musik { public sigslot::has_slots<> { public: + DELETE_COPY_AND_ASSIGNMENT_DEFAULTS(TrackSearchLayout) + TrackSearchLayout( musik::core::audio::PlaybackService& playback, musik::core::ILibraryPtr library); diff --git a/src/musikcube/app/overlay/PlayQueueOverlays.cpp b/src/musikcube/app/overlay/PlayQueueOverlays.cpp index 0d575a26c..af4ede735 100644 --- a/src/musikcube/app/overlay/PlayQueueOverlays.cpp +++ b/src/musikcube/app/overlay/PlayQueueOverlays.cpp @@ -87,11 +87,11 @@ static inline milliseconds now() noexcept { system_clock::now().time_since_epoch()); } -static inline bool lastOperationExpired() { +static inline bool lastOperationExpired() noexcept { return now() > lastOperationExpiry; } -static inline void touchOperationExpiry() { +static inline void touchOperationExpiry() noexcept { lastOperationExpiry = now() + duration_cast(Seconds(60)); } @@ -393,7 +393,7 @@ static void showAddCategorySelectionToPlaylistOverlay( if (!lastOperationExpired() && lastPlaylistId >= 0) { const int index = findPlaylistIndex(result, lastPlaylistId); if (index >= 0) { - selectedIndex = (size_t) index + 1; /* +1 offsets "new..." */ + selectedIndex = narrow_cast(index) + 1; /* +1 offsets "new..." */ } } @@ -440,7 +440,7 @@ static void showAddTrackToPlaylistOverlay( if (!lastOperationExpired() && lastPlaylistId >= 0) { const int index = findPlaylistIndex(result, lastPlaylistId); if (index >= 0) { - selectedIndex = (size_t) index + 1; /* +1 offsets "new..." */ + selectedIndex = narrow_cast(index) + 1; /* +1 offsets "new..." */ } } diff --git a/src/musikcube/app/overlay/SettingsOverlays.cpp b/src/musikcube/app/overlay/SettingsOverlays.cpp index e3745fa5c..7374b6576 100644 --- a/src/musikcube/app/overlay/SettingsOverlays.cpp +++ b/src/musikcube/app/overlay/SettingsOverlays.cpp @@ -62,19 +62,19 @@ using namespace std::chrono; using Callback = std::function; static const std::string kTlsInfoUrl = "https://github.com/clangen/musikcube/wiki/ssl-server-setup"; -static const int64_t kTlsWarningCooldownMs = 20000; +constexpr int64_t kTlsWarningCooldownMs = 20000; int64_t lastTlsWarningTime = 0; static const std::vector kTranscoderFormats = { "mp3", "opus", "ogg", "flac", "aac" }; static const std::string kDefaultTranscoderFormat = "ogg"; -static const int kDefaultTranscoderFormatOverlayWidth = 24; +constexpr int kDefaultTranscoderFormatOverlayWidth = 24; static const std::vector kTranscoderBitrates = { 64, 96, 128, 192, 256, 320 }; -static const int kDefaultTranscoderBitrate = 192; -static const int kDefaultTranscoderBitrateOverlayWidth = 24; +constexpr int kDefaultTranscoderBitrate = 192; +constexpr int kDefaultTranscoderBitrateOverlayWidth = 24; static void showNeedsRestart(Callback cb = Callback()) { - std::shared_ptr dialog(new DialogOverlay()); + auto dialog = std::make_shared(); (*dialog) .SetTitle(_TSTR("default_overlay_title")) @@ -99,18 +99,18 @@ void musik::cube::SettingsOverlays::ShowLocaleOverlay(std::function call std::string currentLocale = locale.GetSelectedLocale(); allLocales = locale.GetLocales(); - std::shared_ptr adapter(new Adapter()); + auto adapter = std::make_shared(); adapter->SetSelectable(true); int selectedIndex = 0; for (size_t i = 0; i < allLocales.size(); i++) { adapter->AddEntry(allLocales[i]); if (allLocales[i] == currentLocale) { - selectedIndex = (int)i; + selectedIndex = narrow_cast(i); } } - std::shared_ptr dialog(new ListOverlay()); + auto dialog = std::make_shared(); dialog->SetAdapter(adapter) .SetTitle(_TSTR("locale_overlay_select_title")) @@ -130,20 +130,20 @@ void musik::cube::SettingsOverlays::ShowLocaleOverlay(std::function call void musik::cube::SettingsOverlays::ShowLibraryTypeOverlay(std::function callback) { auto prefs = Preferences::ForComponent(core::prefs::components::Settings); - const auto libraryType = (ILibrary::Type) prefs->GetInt( - core::prefs::keys::LibraryType, (int) ILibrary::Type::Local); + const auto libraryType = static_cast(prefs->GetInt( + core::prefs::keys::LibraryType, (int) ILibrary::Type::Local)); using Adapter = cursespp::SimpleScrollAdapter; using ListOverlay = cursespp::ListOverlay; - std::shared_ptr adapter(new Adapter()); + auto adapter = std::make_shared(); adapter->SetSelectable(true); adapter->AddEntry(_TSTR("settings_library_type_local")); adapter->AddEntry(_TSTR("settings_library_type_remote")); - int selectedIndex = libraryType == ILibrary::Type::Local ? 0 : 1; + const int selectedIndex = libraryType == ILibrary::Type::Local ? 0 : 1; - std::shared_ptr dialog(new ListOverlay()); + auto dialog = std::make_shared(); dialog->SetAdapter(adapter) .SetTitle(_TSTR("settings_library_type_overlay_title")) @@ -151,8 +151,8 @@ void musik::cube::SettingsOverlays::ShowLibraryTypeOverlay(std::function .SetItemSelectedCallback( [prefs, callback] (ListOverlay* overlay, IScrollAdapterPtr adapter, size_t index) { - auto updatedType = index == 0 ? ILibrary::Type::Local : ILibrary::Type::Remote; - prefs->SetInt(core::prefs::keys::LibraryType, (int)updatedType); + const auto updatedType = index == 0 ? ILibrary::Type::Local : ILibrary::Type::Remote; + prefs->SetInt(core::prefs::keys::LibraryType, narrow_cast(updatedType)); callback(); }); @@ -232,7 +232,7 @@ void musik::cube::SettingsOverlays::CheckShowTlsWarningDialog() { void musik::cube::SettingsOverlays::ShowTranscoderBitrateOverlay(std::function callback) { auto prefs = Preferences::ForComponent(core::prefs::components::Settings); - int currentBitrate = prefs->GetInt( + const int currentBitrate = prefs->GetInt( core::prefs::keys::RemoteLibraryTranscoderBitrate, kDefaultTranscoderBitrate); diff --git a/src/musikcube/app/util/GlobalHotkeys.h b/src/musikcube/app/util/GlobalHotkeys.h index 8d7755cfb..52ce08e6c 100755 --- a/src/musikcube/app/util/GlobalHotkeys.h +++ b/src/musikcube/app/util/GlobalHotkeys.h @@ -43,6 +43,8 @@ namespace musik { namespace cube { class GlobalHotkeys { public: + DELETE_CLASS_DEFAULTS(GlobalHotkeys) + GlobalHotkeys( musik::core::audio::PlaybackService& playback, musik::core::ILibraryPtr library); diff --git a/src/musikcube/app/util/Hotkeys.cpp b/src/musikcube/app/util/Hotkeys.cpp index a02e19be6..ca96bde2f 100755 --- a/src/musikcube/app/util/Hotkeys.cpp +++ b/src/musikcube/app/util/Hotkeys.cpp @@ -50,7 +50,7 @@ using Id = Hotkeys::Id; /* sigh: http://stackoverflow.com/a/24847480 */ struct EnumHasher { template - std::size_t operator()(T t) const { + std::size_t operator()(T t) const noexcept { return static_cast(t); } }; @@ -256,7 +256,7 @@ static void loadPreferences() { std::vector names; preferences->GetKeys(names); for (auto n : names) { - auto it = NAME_TO_ID.find(n); + const auto it = NAME_TO_ID.find(n); if (it != NAME_TO_ID.end()) { customIdToKey[it->second] = preferences->GetString(n); } @@ -273,21 +273,18 @@ static void loadPreferences() { } } -Hotkeys::Hotkeys() { -} - bool Hotkeys::Is(Id id, const std::string& kn) { ENSURE_LOADED() /* see if the user has specified a custom value for this hotkey. if they have, compare it to the custom value. */ - auto custom = customIdToKey.find(id); + const auto custom = customIdToKey.find(id); if (custom != customIdToKey.end()) { return (custom->second == kn); } /* otherwise, let's compare against the default key */ - auto it = ID_TO_DEFAULT.find(id); + const auto it = ID_TO_DEFAULT.find(id); if (it != ID_TO_DEFAULT.end() && it->second == kn) { return true; } @@ -297,7 +294,7 @@ bool Hotkeys::Is(Id id, const std::string& kn) { template std::string find(Id id, T& map) { - auto it = map.find(id); + const auto it = map.find(id); if (it != map.end()) { return it->second; } @@ -365,31 +362,31 @@ std::string Hotkeys::Name(Id id) { class NavigationKeysImpl : public cursespp::INavigationKeys { public: - virtual bool Up(const std::string& key) override { return Up() == key; } - virtual bool Down(const std::string& key) override { return Down() == key; } - virtual bool Left(const std::string& key) override { return Left() == key; } - virtual bool Right(const std::string& key) override { return Right() == key; } - virtual bool PageUp(const std::string& key) override { return PageUp() == key; } - virtual bool PageDown(const std::string& key) override { return PageDown() == key; } - virtual bool Home(const std::string& key) override { return Home() == key; } - virtual bool End(const std::string& key) override { return End() == key; } - virtual bool Next(const std::string& key) override { return Next() == key; } - virtual bool Prev(const std::string& key) override { return Prev() == key; } - virtual bool Mode(const std::string& key) override { return Mode() == key; } + bool Up(const std::string& key) override { return Up() == key; } + bool Down(const std::string& key) override { return Down() == key; } + bool Left(const std::string& key) override { return Left() == key; } + bool Right(const std::string& key) override { return Right() == key; } + bool PageUp(const std::string& key) override { return PageUp() == key; } + bool PageDown(const std::string& key) override { return PageDown() == key; } + bool Home(const std::string& key) override { return Home() == key; } + bool End(const std::string& key) override { return End() == key; } + bool Next(const std::string& key) override { return Next() == key; } + bool Prev(const std::string& key) override { return Prev() == key; } + bool Mode(const std::string& key) override { return Mode() == key; } - virtual std::string Up() override { return Hotkeys::Get(Hotkeys::Up); } - virtual std::string Down() override { return Hotkeys::Get(Hotkeys::Down); } - virtual std::string Left() override { return Hotkeys::Get(Hotkeys::Left); } - virtual std::string Right() override { return Hotkeys::Get(Hotkeys::Right); } - virtual std::string PageUp() override { return Hotkeys::Get(Hotkeys::PageUp); } - virtual std::string PageDown() override { return Hotkeys::Get(Hotkeys::PageDown); } - virtual std::string Home() override { return Hotkeys::Get(Hotkeys::Home); } - virtual std::string End() override { return Hotkeys::Get(Hotkeys::End); } - virtual std::string Next() override { return "KEY_TAB"; } - virtual std::string Prev() override { return "KEY_BTAB"; } - virtual std::string Mode() override { return "^["; } + std::string Up() override { return Hotkeys::Get(Hotkeys::Up); } + std::string Down() override { return Hotkeys::Get(Hotkeys::Down); } + std::string Left() override { return Hotkeys::Get(Hotkeys::Left); } + std::string Right() override { return Hotkeys::Get(Hotkeys::Right); } + std::string PageUp() override { return Hotkeys::Get(Hotkeys::PageUp); } + std::string PageDown() override { return Hotkeys::Get(Hotkeys::PageDown); } + std::string Home() override { return Hotkeys::Get(Hotkeys::Home); } + std::string End() override { return Hotkeys::Get(Hotkeys::End); } + std::string Next() override { return "KEY_TAB"; } + std::string Prev() override { return "KEY_BTAB"; } + std::string Mode() override { return "^["; } }; std::shared_ptr Hotkeys::NavigationKeys() { - return std::shared_ptr(new NavigationKeysImpl()); + return std::make_shared(); } diff --git a/src/musikcube/app/util/Hotkeys.h b/src/musikcube/app/util/Hotkeys.h index 7debe76a5..70ecf5d14 100755 --- a/src/musikcube/app/util/Hotkeys.h +++ b/src/musikcube/app/util/Hotkeys.h @@ -147,7 +147,7 @@ namespace musik { static std::shared_ptr NavigationKeys(); private: - Hotkeys(); + DELETE_CLASS_DEFAULTS(Hotkeys) }; } } diff --git a/src/musikcube/app/util/TrackRowRenderers.cpp b/src/musikcube/app/util/TrackRowRenderers.cpp index 9ee40e7c0..a08dcf9d1 100644 --- a/src/musikcube/app/util/TrackRowRenderers.cpp +++ b/src/musikcube/app/util/TrackRowRenderers.cpp @@ -53,10 +53,10 @@ using namespace cursespp; #define DIGITS(x) (x > 9 ? (int) log10((double) x) + 1 : 1) -static const bool kEnableSkeletonRows = true; +constexpr bool kEnableSkeletonRows = true; +constexpr int kDurationColWidth = 5; /* 00:00 */ +constexpr int kRatingBreakpointWidth = 90; static const std::string kSkeletonChar = "-"; // "░"; -static const int kDurationColWidth = 5; /* 00:00 */ -static const int kRatingBreakpointWidth = 90; /* this method does a couple things slower than it probably should, but it shouldn't cause any issues. TODO: make this better? does it matter? */ @@ -81,9 +81,9 @@ static std::string placeholder(int width) { } namespace AlbumSort { - static const int kTrackColWidth = 3; - static const int kArtistColWidth = 17; - static const int kRatingColumnWidth = 5; + constexpr int kTrackColWidth = 3; + constexpr int kArtistColWidth = 17; + constexpr int kRatingColumnWidth = 5; static std::string skeleton(TrackPtr track, size_t width) { auto const id = track->GetId(); @@ -94,16 +94,19 @@ namespace AlbumSort { std::string artist = text::Align(placeholder(1 + (id % (kArtistColWidth - 2))), text::AlignLeft, kArtistColWidth); int titleWidth = - (int) width - - (int) kTrackColWidth - + narrow_cast(width) - + narrow_cast(kTrackColWidth) - kDurationColWidth - kArtistColWidth - - (int) u8len(rating) - + narrow_cast(u8len(rating)) - (3 * 3); /* 3 = spacing */ titleWidth = std::max(0, titleWidth); - std::string title = text::Align(placeholder(1 + (id % ((int64_t) titleWidth - 2))), text::AlignLeft, (int) titleWidth); + std::string title = text::Align(placeholder( + 1 + (id % (static_cast(titleWidth) - 2))), + text::AlignLeft, + narrow_cast(titleWidth)); return u8fmt( "%s %s%s %s %s", @@ -148,11 +151,11 @@ namespace AlbumSort { int titleWidth = 0; titleWidth = - (int) width - - (int) trackColWidth - + narrow_cast(width) - + narrow_cast(trackColWidth) - kDurationColWidth - kArtistColWidth - - (int) u8len(rating) - + narrow_cast(u8len(rating)) - (3 * 3); /* 3 = spacing */ titleWidth = std::max(0, titleWidth); @@ -160,7 +163,7 @@ namespace AlbumSort { std::string title = text::Align( track->GetString(constants::Track::TITLE), text::AlignLeft, - (int) titleWidth); + narrow_cast(titleWidth)); return u8fmt( "%s %s%s %s %s", @@ -173,9 +176,9 @@ namespace AlbumSort { } namespace NowPlaying { - static const int kTrackColWidth = 3; - static const int kArtistColWidth = 14; - static const int kAlbumColWidth = 14; + constexpr int kTrackColWidth = 3; + constexpr int kArtistColWidth = 14; + constexpr int kAlbumColWidth = 14; static std::string skeleton(TrackPtr track, size_t width) { auto const id = track->GetId(); @@ -187,17 +190,20 @@ namespace NowPlaying { std::string artist = text::Align(placeholder(1 + (id % (kArtistColWidth - 2))), text::AlignLeft, kArtistColWidth); int titleWidth = - (int)width - - (int)kTrackColWidth - + narrow_cast(width) - + narrow_cast(kTrackColWidth) - kDurationColWidth - kAlbumColWidth - kArtistColWidth - - (int)u8len(rating) - + narrow_cast(u8len(rating)) - (4 * 3); /* 3 = spacing */ titleWidth = std::max(0, titleWidth); - std::string title = text::Align(placeholder(1 + (id % ((int64_t) titleWidth - 2))), text::AlignLeft, (int) titleWidth); + std::string title = text::Align(placeholder( + 1 + (id % (static_cast(titleWidth) - 2))), + text::AlignLeft, + narrow_cast(titleWidth)); return u8fmt( "%s %s%s %s %s %s", @@ -234,12 +240,12 @@ namespace NowPlaying { kArtistColWidth); int titleWidth = - (int) width - - (int) trackColWidth - + narrow_cast(width) - + narrow_cast(trackColWidth) - kDurationColWidth - kAlbumColWidth - kArtistColWidth - - (int) u8cols(rating) - + narrow_cast(u8cols(rating)) - (4 * 3); /* 3 = spacing */ titleWidth = std::max(0, titleWidth); diff --git a/src/musikcube/app/util/UpdateCheck.cpp b/src/musikcube/app/util/UpdateCheck.cpp index 4f8cd9582..836f652b2 100644 --- a/src/musikcube/app/util/UpdateCheck.cpp +++ b/src/musikcube/app/util/UpdateCheck.cpp @@ -75,7 +75,7 @@ static const std::string PLATFORM = "openbsd"; static const std::string PLATFORM = "linux"; #endif -static inline int64_t versionCode(short major, short minor, short patch) { +constexpr int64_t versionCode(short major, short minor, short patch) noexcept { int64_t version = major; version = (version << 16) | minor; version = (version << 16) | patch; diff --git a/src/musikcube/app/util/UpdateCheck.h b/src/musikcube/app/util/UpdateCheck.h index fb339a7fd..9a7c8bf56 100644 --- a/src/musikcube/app/util/UpdateCheck.h +++ b/src/musikcube/app/util/UpdateCheck.h @@ -52,6 +52,8 @@ namespace musik { namespace cube { static void ShowNoUpgradeFoundOverlay(); + DELETE_COPY_AND_ASSIGNMENT_DEFAULTS(UpdateCheck) + UpdateCheck(); ~UpdateCheck(); @@ -61,7 +63,8 @@ namespace musik { namespace cube { private: void Reset(); - virtual void ProcessMessage(musik::core::runtime::IMessage &message); + /* IMessageHandler */ + void ProcessMessage(musik::core::runtime::IMessage &message) override; std::recursive_mutex mutex; Callback callback;