From a14b77338d5464e1c678b287fd7872775404226a Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Fri, 13 Jul 2012 23:23:44 +0200 Subject: [PATCH] jump to current song at startup even if it's not currently played --- src/helpers.cpp | 2 +- src/mpdpp.cpp | 13 +++++++++---- src/mpdpp.h | 3 ++- src/ncmpcpp.cpp | 5 +++-- src/sel_items_adder.cpp | 4 ++-- src/status.cpp | 8 ++++---- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 1847d146..38922f03 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -206,7 +206,7 @@ void ParseArgv(int argc, char **argv) Replace(now_playing_format, "\\t", "\t"); } } - std::cout << utf_to_locale_cpy(Mpd.GetCurrentSong().toString(now_playing_format)) << "\n"; + std::cout << utf_to_locale_cpy(Mpd.GetCurrentlyPlayingSong().toString(now_playing_format)) << "\n"; } exit(0); } diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp index ea3ca429..b735e957 100644 --- a/src/mpdpp.cpp +++ b/src/mpdpp.cpp @@ -519,12 +519,12 @@ void MPD::Connection::Seek(unsigned where) if (!isCommandsListEnabled) { GoBusy(); - mpd_run_seek_pos(itsConnection, Mpd.GetCurrentSongPos(), where); + mpd_run_seek_pos(itsConnection, Mpd.GetCurrentlyPlayingSongPos(), where); } else { assert(!isIdle); - mpd_send_seek_pos(itsConnection, Mpd.GetCurrentSongPos(), where); + mpd_send_seek_pos(itsConnection, Mpd.GetCurrentlyPlayingSongPos(), where); } } @@ -657,10 +657,15 @@ MPD::Song MPD::Connection::GetSong(const std::string &path) int MPD::Connection::GetCurrentSongPos() const { - return itsCurrentStatus && isPlaying() ? mpd_status_get_song_pos(itsCurrentStatus) : -1; + return itsCurrentStatus ? mpd_status_get_song_pos(itsCurrentStatus) : -1; } -MPD::Song MPD::Connection::GetCurrentSong() +int MPD::Connection::GetCurrentlyPlayingSongPos() const +{ + return isPlaying() ? GetCurrentSongPos() : -1; +} + +MPD::Song MPD::Connection::GetCurrentlyPlayingSong() { assert(!isCommandsListEnabled); GoBusy(); diff --git a/src/mpdpp.h b/src/mpdpp.h index a1301a4d..04f4b94a 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -158,7 +158,8 @@ namespace MPD const std::string & GetErrorMessage() const { return itsErrorMessage; } - Song GetCurrentSong(); + Song GetCurrentlyPlayingSong(); + int GetCurrentlyPlayingSongPos() const; int GetCurrentSongPos() const; Song GetSong(const std::string &); void GetPlaylistContent(const std::string &, SongList &); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 1e003aec..bf01f074 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -342,8 +342,9 @@ int main(int argc, char **argv) if (Config.jump_to_now_playing_song_at_start) { TraceMpdStatus(); - if (myPlaylist->isPlaying()) - myPlaylist->Items->Highlight(myPlaylist->NowPlaying); + int curr_pos = Mpd.GetCurrentSongPos(); + if (curr_pos >= 0) + myPlaylist->Items->Highlight(curr_pos); } while (!main_exit) diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index 6c8b039f..fd650dc3 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -223,13 +223,13 @@ void SelectedItemsAdder::EnterPressed() } else if (pos == 2) // after currently playing track { - successful_operation = myPlaylist->Add(list, 0, Mpd.GetCurrentSongPos()+1); + successful_operation = myPlaylist->Add(list, 0, Mpd.GetCurrentlyPlayingSongPos()+1); } else if (pos == 3) // after currently playing album { std::string album = myPlaylist->NowPlayingSong()->GetAlbum(); int i; - for (i = Mpd.GetCurrentSongPos()+1; i < int(myPlaylist->Items->Size()); ++i) + for (i = Mpd.GetCurrentlyPlayingSongPos()+1; i < int(myPlaylist->Items->Size()); ++i) if ((*myPlaylist->Items)[i].GetAlbum() != album) break; successful_operation = myPlaylist->Add(list, 0, i); diff --git a/src/status.cpp b/src/status.cpp index f26e025e..6a421f88 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -229,13 +229,13 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) wFooter->GetXY(sx, sy); if (!Playlist::BlockNowPlayingUpdate) - myPlaylist->NowPlaying = Mpd.GetCurrentSongPos(); + myPlaylist->NowPlaying = Mpd.GetCurrentlyPlayingSongPos(); if (changed.Playlist) { if (!Playlist::BlockUpdate) { - if (!(np = Mpd.GetCurrentSong()).Empty()) + if (!(np = Mpd.GetCurrentlyPlayingSong()).Empty()) WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); bool was_filtered = myPlaylist->Items->isFiltered(); @@ -408,7 +408,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) Lyrics::DownloadInBackground(myPlaylist->NowPlayingSong()); # endif // HAVE_CURL_CURL_H - if (Mpd.isPlaying() && !(np = Mpd.GetCurrentSong()).Empty()) + if (Mpd.isPlaying() && !(np = Mpd.GetCurrentlyPlayingSong()).Empty()) WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); if (Config.autocenter_mode && !myPlaylist->Items->isFiltered()) @@ -424,7 +424,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) } if (changed.ElapsedTime || changed.SongID || Global::RedrawStatusbar) { - if (np.Empty() && !(np = Mpd.GetCurrentSong()).Empty()) + if (np.Empty() && !(np = Mpd.GetCurrentlyPlayingSong()).Empty()) WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format))); if (!np.Empty() && Mpd.isPlaying()) {