From 3bbe2c50542701e797e4a2f8c24b5b6ea45fdccd Mon Sep 17 00:00:00 2001 From: unK Date: Wed, 17 Sep 2008 20:30:11 +0200 Subject: [PATCH] add incremental seeking as an option (enabled by default) --- doc/ncmpcpprc | 6 ++++-- src/ncmpcpp.cpp | 49 ++++++++++++++++++++++++++---------------------- src/settings.cpp | 5 +++++ src/settings.h | 1 + 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/doc/ncmpcpprc b/doc/ncmpcpprc index f5093e9a..01787cfd 100644 --- a/doc/ncmpcpprc +++ b/doc/ncmpcpprc @@ -96,6 +96,8 @@ # #playlist_display_mode = "normal" (classic/columns) # +#incremental_seeking = "yes" +# #autocenter_mode = "no" # #repeat_one_mode = "no" @@ -112,14 +114,14 @@ # #statusbar_visibility = "yes" # +#fancy_scrolling = "yes" +# #enable_window_title = "yes" # ##### colors definitions ##### # #colors_enabled = "yes" # -#fancy_scrolling = "yes" -# #empty_tag_color = "cyan" # #header_window_color = "default" diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 34d3856f..c3306c72 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -2090,39 +2090,44 @@ int main(int argc, char *argv[]) block_progressbar_update = 1; LockStatusbar(); - int songpos, in; + int songpos; + time_t t = time(NULL); songpos = Mpd->GetElapsedTime(); Song &s = mPlaylist->at(now_playing); - while (1) + while (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward)) { TraceMpdStatus(); timer = time(NULL); - mPlaylist->ReadKey(in); - if (Keypressed(in, Key.SeekForward) || Keypressed(in, Key.SeekBackward)) + mPlaylist->ReadKey(input); + + int howmuch = Config.incremental_seeking ? (timer-t)/2+1 : 1; + + if (songpos < s.GetTotalLength() && Keypressed(input, Key.SeekForward)) { - if (songpos < s.GetTotalLength() && Keypressed(in, Key.SeekForward)) - songpos++; - if (songpos < s.GetTotalLength() && songpos > 0 && Keypressed(in, Key.SeekBackward)) - songpos--; + songpos += howmuch; + if (songpos > s.GetTotalLength()) + songpos = s.GetTotalLength(); + } + if (songpos < s.GetTotalLength() && songpos > 0 && Keypressed(input, Key.SeekBackward)) + { + songpos -= howmuch; if (songpos < 0) songpos = 0; - - wFooter->Bold(1); - string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]"; - wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength); - double progressbar_size = (double)songpos/(s.GetTotalLength()); - int howlong = wFooter->GetWidth()*progressbar_size; - - mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth()); - mvwhline(wFooter->RawWin(), 0, 0, '=',howlong); - mvwaddch(wFooter->RawWin(), 0, howlong, '>'); - wFooter->Bold(0); - wFooter->Refresh(); } - else - break; + + wFooter->Bold(1); + string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]"; + wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, tracklength); + double progressbar_size = (double)songpos/(s.GetTotalLength()); + int howlong = wFooter->GetWidth()*progressbar_size; + + mvwhline(wFooter->RawWin(), 0, 0, 0, wFooter->GetWidth()); + mvwhline(wFooter->RawWin(), 0, 0, '=',howlong); + mvwaddch(wFooter->RawWin(), 0, howlong, '>'); + wFooter->Bold(0); + wFooter->Refresh(); } Mpd->Seek(songpos); diff --git a/src/settings.cpp b/src/settings.cpp index 7021f0ed..e27056c1 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -185,6 +185,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.wrapped_search = true; conf.space_selects = false; conf.albums_in_tag_editor = false; + conf.incremental_seeking = true; conf.set_window_title = true; conf.mpd_connection_timeout = 15; conf.crossfade_time = 5; @@ -564,6 +565,10 @@ void ReadConfiguration(ncmpcpp_config &conf) { conf.albums_in_tag_editor = v == "albums"; } + else if (it->find("incremental_seeking") != string::npos) + { + conf.incremental_seeking = v == "yes"; + } else if (it->find("enable_window_title") != string::npos) { conf.set_window_title = v == "yes"; diff --git a/src/settings.h b/src/settings.h index a6eec8b2..d9f709e6 100644 --- a/src/settings.h +++ b/src/settings.h @@ -134,6 +134,7 @@ struct ncmpcpp_config bool wrapped_search; bool space_selects; bool albums_in_tag_editor; + bool incremental_seeking; int mpd_connection_timeout; int crossfade_time;