From 30b8622776e512c6169ed885a04e847964c6078b Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 9 Sep 2009 18:32:57 +0200 Subject: [PATCH] get total time from mpd status, not from currently playing track it seems that even if track info doesn't provide total track length, mpd status does, which allows for seeking and displaying progressbar. --- src/mpdpp.h | 1 + src/ncmpcpp.cpp | 53 ++++++++++++++++++++++++------------------------- src/status.cpp | 16 +++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/mpdpp.h b/src/mpdpp.h index 93b084e8..da35f33d 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -129,6 +129,7 @@ namespace MPD long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; } long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; } int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; } + int GetTotalTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->totalTime : 0; } unsigned GetBitrate() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->bitRate : 0; } size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength; } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index e2f752e6..4b4d5890 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -386,10 +386,9 @@ int main(int argc, char *argv[]) && mouse_event.y == LINES-(Config.statusbar_visibility ? 2 : 1) ) // progressbar { - const Song *s = myPlaylist->NowPlayingSong(); - if (!s) + if (!myPlaylist->isPlaying()) continue; - Mpd.Seek(s->GetTotalLength()*mouse_event.x/double(COLS)); + Mpd.Seek(Mpd.GetTotalTime()*mouse_event.x/double(COLS)); UpdateStatusImmediately = 1; } else if (mouse_event.bstate & BUTTON1_PRESSED @@ -1091,16 +1090,16 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward)) { - const Song *s = myPlaylist->NowPlayingSong(); - - if (!s) - continue; - - if (!s->GetTotalLength()) + if (!Mpd.GetTotalTime()) { ShowMessage("Unknown item length!"); continue; } + + const Song *s = myPlaylist->NowPlayingSong(); + if (!s) + continue; + LockProgressbar(); LockStatusbar(); @@ -1118,13 +1117,13 @@ int main(int argc, char *argv[]) int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time; - if (songpos < s->GetTotalLength() && Keypressed(input, Key.SeekForward)) + if (Keypressed(input, Key.SeekForward) && songpos < Mpd.GetTotalTime()) { songpos += howmuch; - if (songpos > s->GetTotalLength()) - songpos = s->GetTotalLength(); + if (songpos > Mpd.GetTotalTime()) + songpos = Mpd.GetTotalTime(); } - if (songpos < s->GetTotalLength() && songpos > 0 && Keypressed(input, Key.SeekBackward)) + else if (Keypressed(input, Key.SeekBackward) && songpos > 0) { songpos -= howmuch; if (songpos < 0) @@ -1138,12 +1137,12 @@ int main(int argc, char *argv[]) if (Config.display_remaining_time) { tracklength = "-"; - tracklength += Song::ShowTime(s->GetTotalLength()-songpos); + tracklength += Song::ShowTime(Mpd.GetTotalTime()-songpos); } else tracklength = Song::ShowTime(songpos); tracklength += "/"; - tracklength += s->GetLength(); + tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); *wHeader << XY(0, 0) << tracklength << " "; wHeader->Refresh(); } @@ -1153,16 +1152,16 @@ int main(int argc, char *argv[]) if (Config.display_remaining_time) { tracklength += "-"; - tracklength += Song::ShowTime(s->GetTotalLength()-songpos); + tracklength += Song::ShowTime(Mpd.GetTotalTime()-songpos); } else tracklength = Song::ShowTime(songpos); tracklength += "/"; - tracklength += s->GetLength(); + tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); tracklength += "]"; *wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength; } - double progressbar_size = songpos/double(s->GetTotalLength()); + double progressbar_size = songpos/double(Mpd.GetTotalTime()); unsigned howlong = wFooter->GetWidth()*progressbar_size; mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth()); @@ -1488,16 +1487,16 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.GoToPosition)) { - const Song *s = myPlaylist->NowPlayingSong(); - - if (!s) - continue; - - if (!s->GetTotalLength()) + if (!Mpd.GetTotalTime()) { ShowMessage("Unknown item length!"); continue; } + + const Song *s = myPlaylist->NowPlayingSong(); + if (!s) + continue; + LockStatusbar(); Statusbar() << "Position to go (in %/mm:ss/seconds(s)): "; std::string position = wFooter->GetString(); @@ -1514,7 +1513,7 @@ int main(int argc, char *argv[]) newpos = StrToInt(position)*60 + StrToInt(position.substr(position.find(':')+1)); } catch (std::out_of_range) { } - if (newpos >= 0 && newpos <= s->GetTotalLength()) + if (newpos >= 0 && newpos <= Mpd.GetTotalTime()) Mpd.Seek(newpos); else ShowMessage("Out of bounds, 0:00-%s possible for mm:ss, %s given.", s->GetLength().c_str(), MPD::Song::ShowTime(newpos).c_str()); @@ -1522,7 +1521,7 @@ int main(int argc, char *argv[]) else if (position.find('s') != std::string::npos) // probably position in seconds { newpos = StrToInt(position); - if (newpos >= 0 && newpos <= s->GetTotalLength()) + if (newpos >= 0 && newpos <= Mpd.GetTotalTime()) Mpd.Seek(newpos); else ShowMessage("Out of bounds, 0-%d possible for seconds, %d given.", s->GetTotalLength(), newpos); @@ -1531,7 +1530,7 @@ int main(int argc, char *argv[]) { newpos = StrToInt(position); if (newpos >= 0 && newpos <= 100) - Mpd.Seek(s->GetTotalLength()*newpos/100.0); + Mpd.Seek(Mpd.GetTotalTime()*newpos/100.0); else ShowMessage("Out of bounds, 0-100 possible for %%, %d given.", newpos); } diff --git a/src/status.cpp b/src/status.cpp index efce8873..4b2c2060 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -415,14 +415,14 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *) if (Config.display_remaining_time) { tracklength = "-"; - tracklength += Song::ShowTime(np.GetTotalLength()-elapsed); + tracklength += Song::ShowTime(Mpd.GetTotalTime()-elapsed); } else tracklength = Song::ShowTime(elapsed); - if (np.GetTotalLength()) + if (Mpd.GetTotalTime()) { tracklength += "/"; - tracklength += np.GetLength(); + tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); } // bitrate here doesn't look good, but it can be moved somewhere else later if (Config.display_bitrate && Mpd.GetBitrate()) @@ -466,17 +466,17 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *) tracklength += " kbps]"; } tracklength += " ["; - if (np.GetTotalLength()) + if (Mpd.GetTotalTime()) { if (Config.display_remaining_time) { tracklength += "-"; - tracklength += Song::ShowTime(np.GetTotalLength()-elapsed); + tracklength += Song::ShowTime(Mpd.GetTotalTime()-elapsed); } else tracklength += Song::ShowTime(elapsed); tracklength += "/"; - tracklength += np.GetLength(); + tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); tracklength += "]"; } else @@ -492,11 +492,11 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *) } if (!block_progressbar_update) { - double progressbar_size = elapsed/double(np.GetTotalLength()); + double progressbar_size = elapsed/double(Mpd.GetTotalTime()); unsigned howlong = wFooter->GetWidth()*progressbar_size; *wFooter << Config.progressbar_color; mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth()); - if (np.GetTotalLength()) + if (Mpd.GetTotalTime()) { for (unsigned i = 0; i < howlong; ++i) *wFooter << Config.progressbar[0];