From cb79ecdb2a4de2efc9c48755ee4c95a8fca8f79d Mon Sep 17 00:00:00 2001 From: unK Date: Wed, 10 Sep 2008 17:25:35 +0200 Subject: [PATCH] brand new song info screen --- doc/ncmpcpp_keys | 2 ++ src/helpers.cpp | 35 +++++++++++++++++++++++++ src/helpers.h | 1 + src/ncmpcpp.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++--- src/ncmpcpp.h | 1 + src/settings.cpp | 4 +++ src/settings.h | 1 + 7 files changed, 109 insertions(+), 3 deletions(-) diff --git a/doc/ncmpcpp_keys b/doc/ncmpcpp_keys index d725ab36..82d125e3 100644 --- a/doc/ncmpcpp_keys +++ b/doc/ncmpcpp_keys @@ -93,6 +93,8 @@ # #key_go_to_position = 'g' # +#key_song_info = 'i' +# #key_lyrics = 'l' # #key_reverse_selection = 'v' diff --git a/src/helpers.cpp b/src/helpers.cpp index 251a086c..0074ec31 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -20,6 +20,7 @@ #include #include "helpers.h" +#include "tag_editor.h" extern MPDConnection *Mpd; @@ -698,6 +699,40 @@ string DisplaySong(const Song &s, void *s_template) return result; } +string GetInfo(Song &s) +{ + string result; +# ifdef HAVE_TAGLIB_H + string path_to_file = Config.mpd_music_dir + "/" + s.GetFile(); + TagLib::FileRef f(path_to_file.c_str()); + if (!f.isNull()) + s.SetComment(f.tag()->comment().to8Bit(UNICODE)); +# endif // HAVE_TAGLIB_H + + result = "[.b][.white]Filename: [/white][.green][/b]" + s.GetShortFilename() + "[/green]\n"; + result += "[.b][.white]Directory: [/white][.green][/b]" + s.GetDirectory() + "[/green]\n\n"; + result += "[.b][.white]Length: [/white][.green][/b]" + s.GetLength() + "[/green]\n"; +# ifdef HAVE_TAGLIB_H + if (!f.isNull()) + { + result += "[.b][.white]Bitrate: [/white][.green][/b]" + IntoStr(f.audioProperties()->bitrate()) + " kbps[/green]\n"; + result += "[.b][.white]Sample rate: [/white][.green][/b]" + IntoStr(f.audioProperties()->sampleRate()) + " Hz[/green]\n"; + result += "[.b][.white]Channels: [/white][.green][/b]" + string(f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") + "[/green]\n"; + } +# endif // HAVE_TAGLIB_H + result += "\n[.b]Title:[/b] " + s.GetTitle(); + result += "\n[.b]Artist:[/b] " + s.GetArtist(); + result += "\n[.b]Album:[/b] " + s.GetAlbum(); + result += "\n[.b]Year:[/b] " + s.GetYear(); + result += "\n[.b]Track:[/b] " + s.GetTrack(); + result += "\n[.b]Genre:[/b] " + s.GetGenre(); + result += "\n[.b]Composer:[/b] " + s.GetComposer(); + result += "\n[.b]Performer:[/b] " + s.GetPerformer(); + result += "\n[.b]Disc:[/b] " + s.GetDisc(); + result += "\n[.b]Comment:[/b] " + s.GetComment(); + return result; +} + void ShowMessage(const string &message, int delay) { if (messages_allowed) diff --git a/src/helpers.h b/src/helpers.h index 9518d6e9..df64aa4b 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -51,6 +51,7 @@ string DisplayItem(const Item &, void * = NULL); string DisplayColumns(string); string DisplaySongInColumns(const Song &, void *); string DisplaySong(const Song &, void * = &Config.song_list_format); +string GetInfo(Song &); void ShowMessage(const string &, int = Config.message_delay_time); void GetDirectory(string, string = "/"); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index fe0338df..f2319c93 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -94,6 +94,7 @@ Menu *mPlaylistEditor; Scrollpad *sHelp; Scrollpad *sLyrics; +Scrollpad *sInfo; Window *wHeader; Window *wFooter; @@ -232,6 +233,7 @@ int main(int argc, char *argv[]) sHelp = new Scrollpad(0, main_start_y, COLS, main_height, "", Config.main_color, brNone); sLyrics = static_cast(sHelp->EmptyClone()); + sInfo = static_cast(sHelp->EmptyClone()); sHelp->Add(" [.b]Keys - Movement\n -----------------------------------------[/b]\n"); sHelp->Add(DisplayKeys(Key.Up) + "Move Cursor up\n"); @@ -283,6 +285,7 @@ int main(int argc, char *argv[]) sHelp->Add(DisplayKeys(Key.EditTags) + "Edit song's tags/playlist's name\n"); # endif // HAVE_TAGLIB_H sHelp->Add(DisplayKeys(Key.GoToPosition) + "Go to chosen position in current song\n"); + sHelp->Add(DisplayKeys(Key.ShowInfo) + "Show song's info\n"); sHelp->Add(DisplayKeys(Key.Lyrics) + "Show/hide song's lyrics\n\n"); sHelp->Add(DisplayKeys(Key.Quit) + "Quit\n\n\n"); @@ -365,6 +368,7 @@ int main(int argc, char *argv[]) mEditorTags->SetTimeout(ncmpcpp_window_timeout); # endif // HAVE_TAGLIB_H sLyrics->SetTimeout(ncmpcpp_window_timeout); + sInfo->SetTimeout(ncmpcpp_window_timeout); wFooter->SetTimeout(ncmpcpp_window_timeout); mPlaylistList->SetTimeout(ncmpcpp_window_timeout); mPlaylistEditor->SetTimeout(ncmpcpp_window_timeout); @@ -435,6 +439,9 @@ int main(int argc, char *argv[]) case csTagEditor: title = "Tag editor"; break; + case csInfo: + title = "Song info"; + break; case csSearcher: title = "Search engine"; break; @@ -811,6 +818,7 @@ int main(int argc, char *argv[]) mPlaylist->SetTitle(Config.columns_in_playlist ? DisplayColumns(Config.song_columns_list_format) : ""); mBrowser->Resize(COLS, main_height); mSearcher->Resize(COLS, main_height); + sInfo->Resize(COLS, main_height); sLyrics->Resize(COLS, main_height); lib_artist_width = COLS/3-1; @@ -846,8 +854,7 @@ int main(int argc, char *argv[]) wFooter->MoveTo(0, footer_start_y); wFooter->Resize(COLS, wFooter->GetHeight()); - if (wCurrent != sHelp && wCurrent != sLyrics) - wCurrent->Window::Clear(); + wCurrent->Hide(); # ifdef HAVE_TAGLIB_H if (current_screen == csLibrary) @@ -2624,11 +2631,66 @@ int main(int argc, char *argv[]) Config.space_selects = !Config.space_selects; ShowMessage("Space mode: " + string(Config.space_selects ? "Select/deselect" : "Add") + " item"); } + else if (Keypressed(input, Key.ShowInfo)) + { + if (wCurrent == sInfo) + { + wCurrent->Hide(); + current_screen = prev_screen; + wCurrent = wPrev; + redraw_screen = 1; + if (current_screen == csLibrary) + { + REFRESH_MEDIA_LIBRARY_SCREEN; + } + else if (current_screen == csPlaylistEditor) + { + REFRESH_PLAYLIST_EDITOR_SCREEN; + } + } + else if ( + (wCurrent == mPlaylist && !mPlaylist->Empty()) + || (wCurrent == mBrowser && mBrowser->at(mBrowser->GetChoice()).type == itSong) + || (wCurrent == mSearcher && mSearcher->Current().first == ".") + || (wCurrent == mLibSongs && !mLibSongs->Empty()) + || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())) + { + Song *s; + int id = wCurrent->GetChoice(); + switch (current_screen) + { + case csPlaylist: + s = &mPlaylist->at(id); + break; + case csBrowser: + s = mBrowser->at(id).song; + break; + case csSearcher: + s = &mSearcher->at(id).second; + break; + case csLibrary: + s = &mLibSongs->at(id); + break; + case csPlaylistEditor: + s = &mPlaylistEditor->at(id); + break; + default: + break; + } + wPrev = wCurrent; + wCurrent = sInfo; + prev_screen = current_screen; + current_screen = csInfo; + sInfo->Clear(); + sInfo->Add(GetInfo(*s)); + sInfo->Hide(); + } + } else if (Keypressed(input, Key.Lyrics)) { if (wCurrent == sLyrics) { - wCurrent->Window::Clear(); + wCurrent->Hide(); current_screen = prev_screen; wCurrent = wPrev; redraw_screen = 1; diff --git a/src/ncmpcpp.h b/src/ncmpcpp.h index 1f6c4e89..0cca037e 100644 --- a/src/ncmpcpp.h +++ b/src/ncmpcpp.h @@ -49,6 +49,7 @@ enum NcmpcppScreen csPlaylist, csBrowser, csTagEditor, + csInfo, csSearcher, csLibrary, csLyrics, diff --git a/src/settings.cpp b/src/settings.cpp index 075335aa..d3d8f0ae 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -66,6 +66,7 @@ void DefaultKeys(ncmpcpp_keys &keys) keys.PrevFoundPosition[0] = ','; keys.ToggleFindMode[0] = 'w'; keys.EditTags[0] = 'e'; + keys.ShowInfo[0] = 'i'; keys.GoToPosition[0] = 'g'; keys.Lyrics[0] = 'l'; keys.ReverseSelection[0] = 'v'; @@ -124,6 +125,7 @@ void DefaultKeys(ncmpcpp_keys &keys) keys.PrevFoundPosition[1] = null_key; keys.ToggleFindMode[1] = null_key; keys.EditTags[1] = null_key; + keys.ShowInfo[1] = null_key; keys.GoToPosition[1] = null_key; keys.Lyrics[1] = null_key; keys.ReverseSelection[1] = null_key; @@ -369,6 +371,8 @@ void ReadKeys(ncmpcpp_keys &keys) GetKeys(*it, keys.EditTags); else if (it->find("key_go_to_position ") != string::npos) GetKeys(*it, keys.GoToPosition); + else if (it->find("key_song_info ") != string::npos) + GetKeys(*it, keys.ShowInfo); else if (it->find("key_lyrics ") != string::npos) GetKeys(*it, keys.Lyrics); else if (it->find("key_reverse_selection ") != string::npos) diff --git a/src/settings.h b/src/settings.h index d1ea7a6e..819bf6b2 100644 --- a/src/settings.h +++ b/src/settings.h @@ -68,6 +68,7 @@ struct ncmpcpp_keys int PrevFoundPosition[2]; int ToggleFindMode[2]; int EditTags[2]; + int ShowInfo[2]; int GoToPosition[2]; int Lyrics[2]; int ReverseSelection[2];