added a key to jump to a song in the media library
This commit introduces a new key to bind, key_go_to_media_library. It will switch to the media library and select the song under the cursor.
This commit is contained in:
2
doc/keys
2
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 = '`'
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -64,6 +64,8 @@ class MediaLibrary : public Screen<Window>
|
||||
void NextColumn();
|
||||
void PrevColumn();
|
||||
|
||||
void LocateSong(const MPD::Song &);
|
||||
|
||||
Menu<std::string> *Artists;
|
||||
Menu< std::pair<std::string, SearchConstraints> > *Albums;
|
||||
Menu<MPD::Song> *Songs;
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user