From 12946d6bdd30e7206349362b1ef84f7d3192b4ec Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Aug 2008 08:30:03 +0200 Subject: [PATCH] make taglib optional + more colors to define + other improvements --- configure.in | 22 ++++++------ examples/{.ncmpcpprc => ncmpcpprc} | 23 +++++++++--- src/helpers.cpp | 32 ++++++++++++++--- src/menu.cpp | 3 +- src/ncmpcpp.cpp | 56 +++++++++++++++++++----------- src/ncmpcpp.h | 13 ++++--- src/scrollpad.cpp | 6 ---- src/settings.cpp | 18 +++++++++- src/settings.h | 3 ++ src/status_checker.cpp | 22 ++++++++++-- src/window.cpp | 15 +++++--- src/window.h | 2 ++ 12 files changed, 155 insertions(+), 60 deletions(-) rename examples/{.ncmpcpprc => ncmpcpprc} (73%) diff --git a/configure.in b/configure.in index bf391cee..a74dad7c 100644 --- a/configure.in +++ b/configure.in @@ -1,14 +1,14 @@ AC_INIT(configure.in) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(ncmpcpp, 0.1) +AM_INIT_AUTOMAKE(ncmpcpp, 0.1.1) AC_LANG_CPLUSPLUS AC_PROG_CXX AM_PROG_LIBTOOL -AC_ARG_ENABLE(unicode,[ --enable-unicode Enable utf8 support ], [unicode=$enableval], [unicode=yes]) - +AC_ARG_ENABLE(unicode, AS_HELP_STRING([--enable-unicode], [Enable utf8 support]), [unicode=$enableval], [unicode=yes]) +AC_ARG_WITH(taglib, AS_HELP_STRING([--with-taglib], [Enable tag editor]), [taglib=$withval], [taglib=yes]) dnl ======================== dnl = checking for ncurses = @@ -49,13 +49,15 @@ AC_CHECK_HEADERS([libmpd/libmpd.h], , AC_MSG_ERROR([missing libmpd.h header])) dnl ======================= dnl = checking for taglib = dnl ======================= -AC_PATH_PROG(TAGLIB_CONFIG, taglib-config) -if test "$TAGLIB_CONFIG" != "" ; then - CPPFLAGS="$CPPFLAGS `$TAGLIB_CONFIG --cflags`" - PKG_CHECK_MODULES([taglib], taglib, LDFLAGS="$LDFLAGS `$TAGLIB_CONFIG --libs`", AC_MSG_ERROR([taglib library is required])) - AC_CHECK_HEADERS([taglib.h], , AC_MSG_ERROR([missing taglib.h header])) -else - AC_MSG_ERROR([taglib-config executable is missing]) +if test "$taglib" = "yes" ; then + AC_PATH_PROG(TAGLIB_CONFIG, taglib-config) + if test "$TAGLIB_CONFIG" != "" ; then + CPPFLAGS="$CPPFLAGS `$TAGLIB_CONFIG --cflags`" + PKG_CHECK_MODULES([taglib], taglib, LDFLAGS="$LDFLAGS `$TAGLIB_CONFIG --libs`", AC_MSG_ERROR([taglib library is required])) + AC_CHECK_HEADERS([taglib.h], , AC_MSG_ERROR([missing taglib.h header])) + else + AC_MSG_ERROR([taglib-config executable is missing]) + fi fi diff --git a/examples/.ncmpcpprc b/examples/ncmpcpprc similarity index 73% rename from examples/.ncmpcpprc rename to examples/ncmpcpprc index e6f18bb8..779647bc 100644 --- a/examples/.ncmpcpprc +++ b/examples/ncmpcpprc @@ -1,4 +1,9 @@ -### ncmpc++ config file ### +########################################################### +## this is example configuration file, copy it to your ## +## home folder as .ncmpcpprc and set up your preferences ## +########################################################### +# +##### connection settings ##### # ## set it in order to make tag editor work # @@ -8,6 +13,8 @@ # #mpd_crossfade_time = "5" # +##### delays ##### +# ## delay after playlist highlighting will be disabled (0 = don't disable) # #playlist_disable_highlight_delay = "5" @@ -16,6 +23,8 @@ # #message_delay_time = "4" # +##### song format ##### +## ## for song format you can use: ## ## %l - length @@ -52,21 +61,27 @@ # #song_status_format = "(%l) {%a - }{%t}|{%f}" # -## window title settings +##### window title settings ##### # #enable_window_title = "yes" # #song_window_title_format = "{%a - }{%t}|{%f}" # -## colors definitions +##### colors definitions ##### # #empty_tag_color = "cyan" # #header_window_color = "default" # +#volume_color = "default" +# +#state_line_color = "default" +# +#state_flags_color = "default" +# #main_window_color = "yellow" # #progressbar_color = "default" # #statusbar_color = "default" - +# diff --git a/src/helpers.cpp b/src/helpers.cpp index 7b48466a..f2217e6e 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -116,7 +116,15 @@ string DisplaySong(const Song &s, const string &song_template) { case 'l': { - result += s.GetLength(); + if (link_tags) + { + if (s.GetTotalLength() > 0) + result += s.GetLength(); + else + tags_present = 0; + } + else + result += s.GetLength(); break; } case 'F': @@ -388,23 +396,26 @@ bool GetSongInfo(Song &s) string path_to_file = Config.mpd_music_dir + "/" + s.GetFile(); +# ifdef HAVE_TAGLIB_H TagLib::FileRef f(path_to_file.c_str()); - if (f.isNull()) return false; - s.SetComment(f.tag()->comment().to8Bit(UNICODE)); +# endif mTagEditor->AddStaticOption("[b][white]Song name: [green][/b]" + s.GetShortFilename()); mTagEditor->AddStaticOption("[b][white]Location in DB: [green][/b]" + s.GetDirectory()); mTagEditor->AddStaticOption(""); - mTagEditor->AddStaticOption("[b][white]Length: [green][/b]" + s.GetLength()); + mTagEditor->AddStaticOption("[b][white]Length: [green][/b]" + s.GetLength() + "[/green]"); +# ifdef HAVE_TAGLIB_H mTagEditor->AddStaticOption("[b][white]Bitrate: [green][/b]" + IntoStr(f.audioProperties()->bitrate()) + " kbps"); mTagEditor->AddStaticOption("[b][white]Sample rate: [green][/b]" + IntoStr(f.audioProperties()->sampleRate()) + " Hz"); mTagEditor->AddStaticOption("[b][white]Channels: [green][/b]" + (string)(f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") + "[/green]"); +# endif mTagEditor->AddSeparator(); +# ifdef HAVE_TAGLIB_H mTagEditor->AddOption("[b]Title:[/b] " + s.GetTitle()); mTagEditor->AddOption("[b]Artist:[/b] " + s.GetArtist()); mTagEditor->AddOption("[b]Album:[/b] " + s.GetAlbum()); @@ -415,7 +426,18 @@ bool GetSongInfo(Song &s) mTagEditor->AddSeparator(); mTagEditor->AddOption("Save"); mTagEditor->AddOption("Cancel"); - +# else + mTagEditor->AddStaticOption("[b]Title:[/b] " + s.GetTitle()); + mTagEditor->AddStaticOption("[b]Artist:[/b] " + s.GetArtist()); + mTagEditor->AddStaticOption("[b]Album:[/b] " + s.GetAlbum()); + mTagEditor->AddStaticOption("[b]Year:[/b] " + s.GetYear()); + mTagEditor->AddStaticOption("[b]Track:[/b] " + s.GetTrack()); + mTagEditor->AddStaticOption("[b]Genre:[/b] " + s.GetGenre()); + mTagEditor->AddStaticOption("[b]Comment:[/b] " + s.GetComment()); + mTagEditor->AddSeparator(); + mTagEditor->AddOption("Back"); +# endif + edited_song = s; return true; } diff --git a/src/menu.cpp b/src/menu.cpp index 4a4a177b..d49921f0 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -379,8 +379,9 @@ void Menu::Highlight(int which) { if (which <= itsOptions.size()) itsHighlight = which-1; + if (which > itsHeight) - itsBeginning = which-itsHeight; + itsBeginning = which-itsHeight/2; else itsBeginning = 0; } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index a2c89eae..b4731269 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -18,10 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifdef HAVE_CONFIG_H -#include -#endif - #include "ncmpcpp.h" #include "status_checker.h" #include "helpers.h" @@ -32,12 +28,18 @@ #define BLOCK_STATUSBAR_UPDATE \ block_statusbar_update = 1; \ - allow_statusbar_unblock = 0; + allow_statusbar_unblock = 0 #define UNBLOCK_STATUSBAR_UPDATE \ allow_statusbar_unblock = 1; \ if (block_statusbar_update_delay < 0) \ - block_statusbar_update = 0; + block_statusbar_update = 0 + +#ifdef HAVE_TAGLIB_H + const string tag_screen_keydesc = "\tE e : Edit song's tags\n"; +#else + const string tag_screen_keydesc = "\tE e : Show song's tags\n"; +#endif char *MPD_HOST = getenv("MPD_HOST"); int MPD_PORT = getenv("MPD_PORT") ? atoi(getenv("MPD_PORT")) : 6600; @@ -182,19 +184,19 @@ int main(int argc, char *argv[]) sHelp->Add("\tm : Move song up\n"); sHelp->Add("\tn : Move song down\n"); sHelp->Add("\tS : Save playlist\n"); - sHelp->Add("\tE e : Edit song's tags\n"); + sHelp->Add(tag_screen_keydesc); sHelp->Add("\to : Go to currently playing position\n\n\n"); sHelp->Add(" [b]Keys - Browse screen\n -----------------------------------------[/b]\n"); sHelp->Add("\tEnter : Enter directory/Select and play song\n"); sHelp->Add("\tSpace : Add song to playlist\n"); sHelp->Add("\tDelete : Delete playlist\n"); - sHelp->Add("\tE e : Edit song's tags\n\n\n"); + sHelp->Add(tag_screen_keydesc + "\n\n"); sHelp->Add(" [b]Keys - Search engine\n -----------------------------------------[/b]\n"); sHelp->Add("\tEnter : Change option/Select and play song\n"); sHelp->Add("\tSpace : Add song to playlist\n"); - sHelp->Add("\tE e : Edit song's tags\n\n\n"); + sHelp->Add(tag_screen_keydesc + "\n\n"); sHelp->Add(" [b]Keys - Tag Editor\n -----------------------------------------[/b]\n"); sHelp->Add("\tEnter : Change option\n"); @@ -251,7 +253,11 @@ int main(int argc, char *argv[]) title = "Browse: "; break; case csTagEditor: +# ifdef HAVE_TAGLIB_H title = "Tag editor"; +# else + title = "Tag info"; +# endif break; case csSearcher: title = "Search engine"; @@ -266,7 +272,9 @@ int main(int argc, char *argv[]) else wHeader->WriteXY(0, 0, "[b]1:[/b]Help [b]2:[/b]Playlist [b]3:[/b]Browse [b]4:[/b]Search", 1); + wHeader->SetColor(Config.volume_color); wHeader->WriteXY(max_allowed_title_length, 0, volume_state); + wHeader->SetColor(Config.header_color); if (current_screen == csBrowser) { @@ -446,9 +454,10 @@ int main(int argc, char *argv[]) } case csTagEditor: { +# ifdef HAVE_TAGLIB_H int id = mTagEditor->GetRealChoice(); int option = mTagEditor->GetChoice(); - BLOCK_STATUSBAR_UPDATE + BLOCK_STATUSBAR_UPDATE; Song &s = edited_song; switch (id) @@ -558,14 +567,19 @@ int main(int argc, char *argv[]) break; } } - UNBLOCK_STATUSBAR_UPDATE + UNBLOCK_STATUSBAR_UPDATE; +# else + wCurrent->Clear(); + wCurrent = wPrev; + current_screen = prev_screen; +# endif // HAVE_TAGLIB_H break; } case csSearcher: { int id = mSearcher->GetChoice(); int option = mSearcher->GetChoice(); - BLOCK_STATUSBAR_UPDATE + BLOCK_STATUSBAR_UPDATE; Song &s = searched_song; switch (id) @@ -718,7 +732,7 @@ int main(int argc, char *argv[]) break; } } - UNBLOCK_STATUSBAR_UPDATE + UNBLOCK_STATUSBAR_UPDATE; break; } } @@ -832,7 +846,7 @@ int main(int argc, char *argv[]) } if (current_screen == csBrowser) { - BLOCK_STATUSBAR_UPDATE + BLOCK_STATUSBAR_UPDATE; int id = mBrowser->GetChoice()-1; if (vFileType[id] == MPD_DATA_TYPE_PLAYLIST) { @@ -856,7 +870,7 @@ int main(int argc, char *argv[]) else ShowMessage("Aborted!"); curs_set(0); - UNBLOCK_STATUSBAR_UPDATE + UNBLOCK_STATUSBAR_UPDATE; } } break; @@ -879,10 +893,10 @@ int main(int argc, char *argv[]) case 'S': // save playlist { string playlist_name; - BLOCK_STATUSBAR_UPDATE + BLOCK_STATUSBAR_UPDATE; wFooter->WriteXY(0, 1, "Save playlist as: ", 1); playlist_name = wFooter->GetString("", TraceMpdStatus); - UNBLOCK_STATUSBAR_UPDATE + UNBLOCK_STATUSBAR_UPDATE; if (playlist_name.find("/") != string::npos) { ShowMessage("Playlist name cannot contain slashes!"); @@ -935,7 +949,7 @@ int main(int argc, char *argv[]) break; block_progressbar_update = 1; - BLOCK_STATUSBAR_UPDATE + BLOCK_STATUSBAR_UPDATE; int songpos, in; @@ -974,7 +988,7 @@ int main(int argc, char *argv[]) mpd_player_seek(conn, songpos); block_progressbar_update = 0; - UNBLOCK_STATUSBAR_UPDATE + UNBLOCK_STATUSBAR_UPDATE; break; } @@ -1074,13 +1088,13 @@ int main(int argc, char *argv[]) break; int newpos = 0; string position; - BLOCK_STATUSBAR_UPDATE + BLOCK_STATUSBAR_UPDATE; wFooter->WriteXY(0, 1, "Position to go (in %): ", 1); position = wFooter->GetString(3, TraceMpdStatus); newpos = atoi(position.c_str()); if (newpos > 0 && newpos < 100 && !position.empty()) mpd_player_seek(conn, vPlaylist[now_playing].GetTotalLength()*newpos/100.0); - UNBLOCK_STATUSBAR_UPDATE + UNBLOCK_STATUSBAR_UPDATE; break; } case 'c': // clear playlist diff --git a/src/ncmpcpp.h b/src/ncmpcpp.h index b4bcf26d..ff0f66b3 100644 --- a/src/ncmpcpp.h +++ b/src/ncmpcpp.h @@ -21,6 +21,10 @@ #ifndef HAVE_NCMPCPP_H #define HAVE_NCMPCPP_H +#ifdef HAVE_CONFIG_H +#include +#endif + #ifdef UTF8_ENABLED const bool UNICODE = 1; # define ncmpcpp_string_t wstring @@ -31,13 +35,14 @@ const bool UNICODE = 0; # define NCMPCPP_TO_WSTRING(x) (x) #endif -#define NCMPCPP_VERSION "0.1" - #define ENTER 10 #define KEY_SPACE 32 -#include "fileref.h" -#include "tag.h" +#ifdef HAVE_TAGLIB_H +# include "fileref.h" +# include "tag.h" +#endif + #include "libmpd/libmpd.h" #include diff --git a/src/scrollpad.cpp b/src/scrollpad.cpp index 5d4a759e..7b6c480e 100644 --- a/src/scrollpad.cpp +++ b/src/scrollpad.cpp @@ -39,12 +39,6 @@ void Scrollpad::Add(string str) int space_pos = 0; bool collect = 0; - // no idea why does it work, but it prevents text from going out of the window - // ugly hack, but i didn't come up with anything better - /*if (!itsContent.empty()) - for (int i = itsContent.length()-1; itsContent[i] != '\0' && i >= 0; i--) - x++;*/ - for (size_t i = 0; i <= s.length(); i++, itsXPos++) { if (BBEnabled) diff --git a/src/settings.cpp b/src/settings.cpp index 08215de4..0b2030bb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -28,10 +28,13 @@ void DefaultConfiguration(ncmpcpp_config &conf) { conf.mpd_music_dir = "/var/lib/mpd/music"; conf.song_list_format = "[green](%l)[/green] {%a - }{%t}|{[white]%f[/white]}"; - conf.song_status_format = conf.song_list_format; + conf.song_status_format = "(%l) {%a - }{%t}|{%f}"; conf.song_window_title_format = "{%a - }{%t}|{%f}"; conf.empty_tags_color = clCyan; conf.header_color = clDefault; + conf.volume_color = clDefault; + conf.state_line_color = clDefault; + conf.state_flags_color = clDefault; conf.main_color = clYellow; conf.progressbar_color = clDefault; conf.statusbar_color = clDefault; @@ -173,6 +176,18 @@ void ReadConfiguration(ncmpcpp_config &conf) if (!v.empty()) conf.header_color = IntoColor(v); + if (it->find("volume_color") != string::npos) + if (!v.empty()) + conf.volume_color = IntoColor(v); + + if (it->find("state_line_color") != string::npos) + if (!v.empty()) + conf.state_line_color = IntoColor(v); + + if (it->find("state_flags_color") != string::npos) + if (!v.empty()) + conf.state_flags_color = IntoColor(v); + if (it->find("main_window_color") != string::npos) if (!v.empty()) conf.main_color = IntoColor(v); @@ -185,6 +200,7 @@ void ReadConfiguration(ncmpcpp_config &conf) if (!v.empty()) conf.statusbar_color = IntoColor(v); } + f.close(); } } diff --git a/src/settings.h b/src/settings.h index 783b4eac..b812fd2b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -36,6 +36,9 @@ struct ncmpcpp_config COLOR empty_tags_color; COLOR header_color; + COLOR volume_color; + COLOR state_line_color; + COLOR state_flags_color; COLOR main_color; COLOR progressbar_color; COLOR statusbar_color; diff --git a/src/status_checker.cpp b/src/status_checker.cpp index 9c51acbc..6af37d30 100644 --- a/src/status_checker.cpp +++ b/src/status_checker.cpp @@ -116,6 +116,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what) { int sx, sy; wFooter->DisableBB(); + wFooter->AutoRefresh(0); wFooter->Bold(1); wFooter->GetXY(sx, sy); @@ -242,7 +243,7 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what) } case MPD_PLAYER_STOP: { - WindowTitle("ncmpc++ ver. "NCMPCPP_VERSION); + WindowTitle("ncmpc++ ver. "VERSION); wFooter->SetColor(Config.progressbar_color); mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth()); wFooter->SetColor(Config.statusbar_color); @@ -266,7 +267,11 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what) if (!block_statusbar_update) { - string tracklength = " [" + ShowTime(elapsed) + "/" + s.GetLength() + "]"; + string tracklength; + if (s.GetTotalLength() > 0) + tracklength = " [" + ShowTime(elapsed) + "/" + s.GetLength() + "]"; + else + tracklength = " [" + ShowTime(elapsed) + "]"; ncmpcpp_string_t playing_song = NCMPCPP_TO_WSTRING(OmitBBCodes(DisplaySong(s, Config.song_status_format))); int max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length(); @@ -343,10 +348,18 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what) wHeader->DisableBB(); wHeader->Bold(1); + wHeader->SetColor(Config.state_line_color); mvwhline(wHeader->RawWin(), 1, 0, 0, wHeader->GetWidth()); if (!switch_state.empty()) - wHeader->WriteXY(wHeader->GetWidth()-switch_state.length()-3, 1, "[" + switch_state + "]"); + { + wHeader->WriteXY(wHeader->GetWidth()-switch_state.length()-3, 1, "["); + wHeader->SetColor(Config.state_flags_color); + wHeader->WriteXY(wHeader->GetWidth()-switch_state.length()-2, 1, switch_state); + wHeader->SetColor(Config.state_line_color); + wHeader->WriteXY(wHeader->GetWidth()-2, 1, "]"); + } wHeader->Refresh(); + wHeader->SetColor(Config.header_color); wHeader->Bold(0); wHeader->EnableBB(); header_update_status = 0; @@ -372,11 +385,14 @@ void NcmpcppStatusChanged(MpdObj *conn, ChangedStatusType what) { int vol = mpd_status_get_volume(conn); volume_state = " Volume: " + IntoStr(vol) + "%"; + wHeader->SetColor(Config.volume_color); wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, volume_state); + wHeader->SetColor(Config.header_color); } wFooter->Bold(0); wFooter->GotoXY(sx, sy); wFooter->Refresh(); + wFooter->AutoRefresh(1); wFooter->EnableBB(); } diff --git a/src/window.cpp b/src/window.cpp index 99ba6d90..87a5fa5d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -20,7 +20,7 @@ #include "window.h" -Window::Window(int startx, int starty, int width, int height, string title, COLOR color, BORDER border) : itsWindow(0), itsWinBorder(0), itsStartX(startx), itsStartY(starty), itsWidth(width), itsHeight(height), BBEnabled(1), itsTitle(title), itsColor(color), itsBaseColor(color), itsBgColor(clDefault), itsBaseBgColor(clDefault), itsBorder(border) +Window::Window(int startx, int starty, int width, int height, string title, COLOR color, BORDER border) : itsWindow(0), itsWinBorder(0), itsStartX(startx), itsStartY(starty), itsWidth(width), itsHeight(height), BBEnabled(1), AutoRefreshEnabled(1), itsTitle(title), itsColor(color), itsBaseColor(color), itsBgColor(clDefault), itsBaseBgColor(clDefault), itsBorder(border) { if (itsStartX < 0) itsStartX = 0; if (itsStartY < 0) itsStartY = 0; @@ -308,8 +308,10 @@ void Window::Write(const string &str, CLEAR_TO_EOL clrtoeol) else waddstr(itsWindow,str.c_str()); - if (clrtoeol) wclrtoeol(itsWindow); - wrefresh(itsWindow); + if (clrtoeol) + wclrtoeol(itsWindow); + if (AutoRefreshEnabled) + wrefresh(itsWindow); } #ifdef UTF8_ENABLED @@ -359,8 +361,11 @@ void Window::Write(const wstring &str, CLEAR_TO_EOL clrtoeol) } else waddwstr(itsWindow,str.c_str()); - if (clrtoeol) wclrtoeol(itsWindow); - wrefresh(itsWindow); + + if (clrtoeol) + wclrtoeol(itsWindow); + if (AutoRefreshEnabled) + wrefresh(itsWindow); } void Window::WriteXY(int x, int y, const wstring &str, CLEAR_TO_EOL cleartoeol) diff --git a/src/window.h b/src/window.h index 6ba334cf..58d89083 100644 --- a/src/window.h +++ b/src/window.h @@ -77,6 +77,7 @@ class Window virtual void AltCharset(bool) const; virtual void Delay(bool) const; virtual void Timeout(int) const; + virtual void AutoRefresh(bool val) { AutoRefreshEnabled = val; } virtual void ReadKey(int &) const; virtual void ReadKey() const; virtual void Write(const string &, CLEAR_TO_EOL = 1); @@ -117,6 +118,7 @@ class Window int itsWidth; int itsHeight; bool BBEnabled; + bool AutoRefreshEnabled; string itsTitle; COLOR itsColor; COLOR itsBaseColor;