jump to current song at startup even if it's not currently played

This commit is contained in:
Andrzej Rybczak
2012-07-13 23:23:44 +02:00
parent f96b4fc776
commit a14b77338d
6 changed files with 21 additions and 14 deletions

View File

@@ -206,7 +206,7 @@ void ParseArgv(int argc, char **argv)
Replace(now_playing_format, "\\t", "\t"); 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); exit(0);
} }

View File

@@ -519,12 +519,12 @@ void MPD::Connection::Seek(unsigned where)
if (!isCommandsListEnabled) if (!isCommandsListEnabled)
{ {
GoBusy(); GoBusy();
mpd_run_seek_pos(itsConnection, Mpd.GetCurrentSongPos(), where); mpd_run_seek_pos(itsConnection, Mpd.GetCurrentlyPlayingSongPos(), where);
} }
else else
{ {
assert(!isIdle); 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 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); assert(!isCommandsListEnabled);
GoBusy(); GoBusy();

View File

@@ -158,7 +158,8 @@ namespace MPD
const std::string & GetErrorMessage() const { return itsErrorMessage; } const std::string & GetErrorMessage() const { return itsErrorMessage; }
Song GetCurrentSong(); Song GetCurrentlyPlayingSong();
int GetCurrentlyPlayingSongPos() const;
int GetCurrentSongPos() const; int GetCurrentSongPos() const;
Song GetSong(const std::string &); Song GetSong(const std::string &);
void GetPlaylistContent(const std::string &, SongList &); void GetPlaylistContent(const std::string &, SongList &);

View File

@@ -342,8 +342,9 @@ int main(int argc, char **argv)
if (Config.jump_to_now_playing_song_at_start) if (Config.jump_to_now_playing_song_at_start)
{ {
TraceMpdStatus(); TraceMpdStatus();
if (myPlaylist->isPlaying()) int curr_pos = Mpd.GetCurrentSongPos();
myPlaylist->Items->Highlight(myPlaylist->NowPlaying); if (curr_pos >= 0)
myPlaylist->Items->Highlight(curr_pos);
} }
while (!main_exit) while (!main_exit)

View File

@@ -223,13 +223,13 @@ void SelectedItemsAdder::EnterPressed()
} }
else if (pos == 2) // after currently playing track 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 else if (pos == 3) // after currently playing album
{ {
std::string album = myPlaylist->NowPlayingSong()->GetAlbum(); std::string album = myPlaylist->NowPlayingSong()->GetAlbum();
int i; 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) if ((*myPlaylist->Items)[i].GetAlbum() != album)
break; break;
successful_operation = myPlaylist->Add(list, 0, i); successful_operation = myPlaylist->Add(list, 0, i);

View File

@@ -229,13 +229,13 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
wFooter->GetXY(sx, sy); wFooter->GetXY(sx, sy);
if (!Playlist::BlockNowPlayingUpdate) if (!Playlist::BlockNowPlayingUpdate)
myPlaylist->NowPlaying = Mpd.GetCurrentSongPos(); myPlaylist->NowPlaying = Mpd.GetCurrentlyPlayingSongPos();
if (changed.Playlist) if (changed.Playlist)
{ {
if (!Playlist::BlockUpdate) 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))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
bool was_filtered = myPlaylist->Items->isFiltered(); bool was_filtered = myPlaylist->Items->isFiltered();
@@ -408,7 +408,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
Lyrics::DownloadInBackground(myPlaylist->NowPlayingSong()); Lyrics::DownloadInBackground(myPlaylist->NowPlayingSong());
# endif // HAVE_CURL_CURL_H # 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))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
if (Config.autocenter_mode && !myPlaylist->Items->isFiltered()) 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 (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))); WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
if (!np.Empty() && Mpd.isPlaying()) if (!np.Empty() && Mpd.isPlaying())
{ {