diff --git a/doc/keys b/doc/keys index be59821b..9550e6f8 100644 --- a/doc/keys +++ b/doc/keys @@ -148,6 +148,8 @@ # #key_go_to_containing_directory = 'G' # +#key_go_to_media_library = '~' +# #key_go_to_parent_dir = 263 127 # #key_switch_tag_type_list = '`' diff --git a/src/help.cpp b/src/help.cpp index a0a4de73..828af7fa 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -195,6 +195,7 @@ void Help::GetKeybindings() *w << DisplayKeys(Key.NextFoundPosition) << "Go to next found position\n"; *w << DisplayKeys(Key.ToggleFindMode) << "Toggle find mode (normal/wrapped)\n"; *w << DisplayKeys(Key.GoToContainingDir) << "Locate song in browser\n"; + *w << DisplayKeys(Key.GoToMediaLibrary) << "Locate current song in media library\n"; *w << DisplayKeys(Key.ToggleDisplayMode) << "Toggle display mode\n"; *w << DisplayKeys(Key.ToggleInterface) << "Toggle user interface\n"; *w << DisplayKeys(Key.GoToPosition) << "Go to given position in current song (in % by default)\n"; diff --git a/src/media_library.cpp b/src/media_library.cpp index 4cbc209b..a5de57e4 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -542,6 +542,95 @@ void MediaLibrary::PrevColumn() } } +void MediaLibrary::LocateSong(const MPD::Song &s) +{ + std::string primary_tag; + switch (Config.media_lib_primary_tag) + { + case MPD_TAG_ARTIST: + primary_tag = s.GetArtist(); + break; + case MPD_TAG_DATE: + primary_tag = s.GetDate(); + break; + case MPD_TAG_GENRE: + primary_tag = s.GetGenre(); + break; + case MPD_TAG_COMPOSER: + primary_tag = s.GetComposer(); + break; + case MPD_TAG_PERFORMER: + primary_tag = s.GetPerformer(); + break; + default: + ShowMessage("Invalid tag type in left column of the media library"); + return; + } + if (primary_tag == "") + { + std::string item_type = IntoStr(Config.media_lib_primary_tag); + ToLower(item_type); + ShowMessage("Can't jump to media library because the song has no %s tag set.", item_type.c_str()); + return; + } + + if (myScreen != this) + SwitchTo(); + Statusbar() << "Jumping to song..."; + wFooter->Refresh(); + + if (Artists->Empty() || primary_tag != Artists->Current()) + { + Update(); + for (size_t i = 0; i < Artists->Size(); ++i) + { + if (primary_tag == Artists->at(i)) + { + Artists->Highlight(i); + Albums->Clear(); + break; + } + } + } + + std::string album = s.GetAlbum(); + std::string date = s.GetDate(); + if (Albums->Empty() || (album != Albums->Current().second.Album + && date != Albums->Current().second.Year)) + { + Update(); + for (size_t i = 0; i < Albums->Size(); ++i) + { + if (album == Albums->at(i).second.Album && date == Albums->at(i).second.Year) + { + Albums->Highlight(i); + Songs->Clear(); + break; + } + } + } + + std::string song = s.GetTitle(); + if (Songs->Empty() || song != Songs->Current().GetTitle()) + { + Update(); + for (size_t i = 0; i < Songs->Size(); ++i) + { + if (song == Songs->at(i).GetTitle()) + { + Songs->Highlight(i); + break; + } + } + } + + Artists->HighlightColor(Config.main_highlight_color); + Albums->HighlightColor(Config.main_highlight_color); + Songs->HighlightColor(Config.active_column_color); + w = Songs; + Refresh(); +} + void MediaLibrary::AddToPlaylist(bool add_n_play) { if (w == Songs && !Songs->Empty()) diff --git a/src/media_library.h b/src/media_library.h index 5c2a361d..58a7b47a 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -64,6 +64,8 @@ class MediaLibrary : public Screen void NextColumn(); void PrevColumn(); + void LocateSong(const MPD::Song &); + Menu *Artists; Menu< std::pair > *Albums; Menu *Songs; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index cca961d5..5ffb1bdf 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -1545,6 +1545,12 @@ int main(int argc, char *argv[]) if (s) myBrowser->LocateSong(*s); } + else if (Keypressed(input, Key.GoToMediaLibrary)) + { + Song *s = myScreen->CurrentSong(); + if (s) + myLibrary->LocateSong(*s); + } else if (Keypressed(input, Key.GoToPosition)) { if (!Mpd.GetTotalTime()) diff --git a/src/settings.cpp b/src/settings.cpp index 3609136c..fc1f6a70 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -166,6 +166,7 @@ void DefaultKeys(ncmpcpp_keys &keys) keys.SavePlaylist[0] = 'S'; keys.GoToNowPlaying[0] = 'o'; keys.GoToContainingDir[0] = 'G'; + keys.GoToMediaLibrary[0] = '~'; keys.ToggleAutoCenter[0] = 'U'; keys.ToggleDisplayMode[0] = 'p'; keys.ToggleInterface[0] = '\\'; @@ -239,6 +240,7 @@ void DefaultKeys(ncmpcpp_keys &keys) keys.SavePlaylist[1] = null_key; keys.GoToNowPlaying[1] = null_key; keys.GoToContainingDir[1] = null_key; + keys.GoToMediaLibrary[1] = null_key; keys.ToggleAutoCenter[1] = null_key; keys.ToggleDisplayMode[1] = null_key; keys.ToggleInterface[1] = null_key; @@ -490,6 +492,8 @@ void ReadKeys(ncmpcpp_keys &keys) GetKeys(key, keys.ToggleLyricsDB); else if (key.find("key_go_to_containing_directory ") != std::string::npos) GetKeys(key, keys.GoToContainingDir); + else if (key.find("key_go_to_media_library ") != std::string::npos) + GetKeys(key, keys.GoToMediaLibrary); else if (key.find("key_go_to_parent_dir ") != std::string::npos) GetKeys(key, keys.GoToParentDir); else if (key.find("key_switch_tag_type_list ") != std::string::npos) diff --git a/src/settings.h b/src/settings.h index 7b755d03..006da7de 100644 --- a/src/settings.h +++ b/src/settings.h @@ -117,6 +117,7 @@ struct ncmpcpp_keys int SavePlaylist[2]; int GoToNowPlaying[2]; int GoToContainingDir[2]; + int GoToMediaLibrary[2]; int ToggleAutoCenter[2]; int ToggleDisplayMode[2]; int ToggleInterface[2];