make Playlist::NowPlayingSong() return pointer, not reference
This commit is contained in:
@@ -78,8 +78,8 @@ void Lyrics::Update()
|
||||
if (!Reload)
|
||||
return;
|
||||
|
||||
const MPD::Song &s = myPlaylist->NowPlayingSong();
|
||||
if (!s.GetArtist().empty() && !s.GetTitle().empty())
|
||||
const MPD::Song *s = myPlaylist->NowPlayingSong();
|
||||
if (s && !s->GetArtist().empty() && !s->GetTitle().empty())
|
||||
SwitchTo();
|
||||
else
|
||||
Reload = 0;
|
||||
@@ -106,7 +106,7 @@ void Lyrics::SwitchTo()
|
||||
}
|
||||
# endif
|
||||
|
||||
const MPD::Song *s = Reload ? &myPlaylist->NowPlayingSong() : myScreen->CurrentSong();
|
||||
const MPD::Song *s = Reload ? myPlaylist->NowPlayingSong() : myScreen->CurrentSong();
|
||||
|
||||
if (!s)
|
||||
return;
|
||||
@@ -117,6 +117,7 @@ void Lyrics::SwitchTo()
|
||||
Resize();
|
||||
itsScrollBegin = 0;
|
||||
itsSong = *s;
|
||||
itsSong.Localize();
|
||||
if (!Reload)
|
||||
{
|
||||
myOldScreen = myScreen;
|
||||
|
||||
@@ -851,12 +851,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
|
||||
{
|
||||
if (!myPlaylist->isPlaying())
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
const Song &s = Mpd->GetCurrentSong();
|
||||
|
||||
if (!s.GetTotalLength())
|
||||
if (!s->GetTotalLength())
|
||||
{
|
||||
ShowMessage("Unknown item length!");
|
||||
continue;
|
||||
@@ -877,13 +877,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
int howmuch = Config.incremental_seeking ? (timer-t)/2+Config.seek_time : Config.seek_time;
|
||||
|
||||
if (songpos < s.GetTotalLength() && Keypressed(input, Key.SeekForward))
|
||||
if (songpos < s->GetTotalLength() && Keypressed(input, Key.SeekForward))
|
||||
{
|
||||
songpos += howmuch;
|
||||
if (songpos > s.GetTotalLength())
|
||||
songpos = s.GetTotalLength();
|
||||
if (songpos > s->GetTotalLength())
|
||||
songpos = s->GetTotalLength();
|
||||
}
|
||||
if (songpos < s.GetTotalLength() && songpos > 0 && Keypressed(input, Key.SeekBackward))
|
||||
if (songpos < s->GetTotalLength() && songpos > 0 && Keypressed(input, Key.SeekBackward))
|
||||
{
|
||||
songpos -= howmuch;
|
||||
if (songpos < 0)
|
||||
@@ -891,9 +891,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
wFooter->Bold(1);
|
||||
string tracklength = "[" + Song::ShowTime(songpos) + "/" + s.GetLength() + "]";
|
||||
string tracklength = "[" + Song::ShowTime(songpos) + "/" + s->GetLength() + "]";
|
||||
*wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength;
|
||||
double progressbar_size = (double)songpos/(s.GetTotalLength());
|
||||
double progressbar_size = (double)songpos/(s->GetTotalLength());
|
||||
int howlong = wFooter->GetWidth()*progressbar_size;
|
||||
|
||||
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
|
||||
@@ -1211,12 +1211,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.GoToPosition))
|
||||
{
|
||||
if (!myPlaylist->isPlaying())
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
|
||||
if (!s)
|
||||
continue;
|
||||
|
||||
const Song &s = Mpd->GetCurrentSong();
|
||||
|
||||
if (!s.GetTotalLength())
|
||||
if (!s->GetTotalLength())
|
||||
{
|
||||
ShowMessage("Unknown item length!");
|
||||
continue;
|
||||
@@ -1226,7 +1226,7 @@ int main(int argc, char *argv[])
|
||||
string position = wFooter->GetString(3);
|
||||
int newpos = StrToInt(position);
|
||||
if (newpos > 0 && newpos < 100 && !position.empty())
|
||||
Mpd->Seek(s.GetTotalLength()*newpos/100.0);
|
||||
Mpd->Seek(s->GetTotalLength()*newpos/100.0);
|
||||
UnlockStatusbar();
|
||||
}
|
||||
else if (Keypressed(input, Key.ReverseSelection))
|
||||
@@ -1382,7 +1382,7 @@ int main(int argc, char *argv[])
|
||||
// if mpd deletes now playing song deletion will be sluggishly slow
|
||||
// then so we have to assure it will be deleted at the very end.
|
||||
if (myPlaylist->isPlaying() && !myPlaylist->Main()->isSelected(myPlaylist->NowPlaying))
|
||||
Mpd->QueueDeleteSongId(myPlaylist->NowPlayingSong().GetID());
|
||||
Mpd->QueueDeleteSongId(myPlaylist->NowPlayingSong()->GetID());
|
||||
|
||||
ShowMessage("Deleting all items but selected...");
|
||||
Mpd->CommitQueue();
|
||||
|
||||
@@ -327,10 +327,14 @@ std::string Playlist::TotalLength()
|
||||
return result.str();
|
||||
}
|
||||
|
||||
const MPD::Song &Playlist::NowPlayingSong()
|
||||
const MPD::Song *Playlist::NowPlayingSong()
|
||||
{
|
||||
static MPD::Song null;
|
||||
return isPlaying() ? w->at(NowPlaying) : null;
|
||||
bool was_filtered = w->isFiltered();
|
||||
w->ShowAll();
|
||||
const MPD::Song *s = isPlaying() ? &w->at(NowPlaying) : 0;
|
||||
if (was_filtered)
|
||||
w->ShowFiltered();
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string Playlist::SongToString(const MPD::Song &s, void *data)
|
||||
|
||||
@@ -51,7 +51,7 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
virtual List *GetList() { return w; }
|
||||
|
||||
bool isPlaying() { return NowPlaying >= 0 && !w->Empty(); }
|
||||
const MPD::Song &NowPlayingSong();
|
||||
const MPD::Song *NowPlayingSong();
|
||||
|
||||
void Sort();
|
||||
|
||||
|
||||
@@ -351,26 +351,26 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
}
|
||||
if (changed.ElapsedTime)
|
||||
{
|
||||
const Song &s = Mpd->GetCurrentSong();
|
||||
if (!player_state.empty() && !s.Empty())
|
||||
const Song *s = myPlaylist->NowPlayingSong();
|
||||
if (s)
|
||||
{
|
||||
int elapsed = Mpd->GetElapsedTime();
|
||||
|
||||
// 'repeat one' mode check - be sure that we deal with item with known length
|
||||
if (s.GetTotalLength() && elapsed == s.GetTotalLength()-1)
|
||||
if (s->GetTotalLength() && elapsed == s->GetTotalLength()-1)
|
||||
repeat_one_allowed = 1;
|
||||
|
||||
WindowTitle(utf_to_locale_cpy(s.toString(Config.song_window_title_format)));
|
||||
WindowTitle(utf_to_locale_cpy(s->toString(Config.song_window_title_format)));
|
||||
|
||||
if (!block_statusbar_update && Config.statusbar_visibility)
|
||||
{
|
||||
string tracklength;
|
||||
if (s.GetTotalLength())
|
||||
if (s->GetTotalLength())
|
||||
{
|
||||
tracklength = " [";
|
||||
tracklength += Song::ShowTime(elapsed);
|
||||
tracklength += "/";
|
||||
tracklength += s.GetLength();
|
||||
tracklength += s->GetLength();
|
||||
tracklength += "]";
|
||||
}
|
||||
else
|
||||
@@ -381,17 +381,17 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
}
|
||||
*wFooter << XY(0, 1) << wclrtoeol << player_state
|
||||
<< fmtBoldEnd
|
||||
<< Scroller(utf_to_locale_cpy(s.toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin)
|
||||
<< Scroller(utf_to_locale_cpy(s->toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin)
|
||||
<< fmtBold
|
||||
<< XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength;
|
||||
}
|
||||
if (!block_progressbar_update)
|
||||
{
|
||||
double progressbar_size = (double)elapsed/(s.GetTotalLength());
|
||||
double progressbar_size = (double)elapsed/(s->GetTotalLength());
|
||||
int howlong = wFooter->GetWidth()*progressbar_size;
|
||||
wFooter->SetColor(Config.progressbar_color);
|
||||
mvwhline(wFooter->Raw(), 0, 0, 0, wFooter->GetWidth());
|
||||
if (s.GetTotalLength())
|
||||
if (s->GetTotalLength())
|
||||
{
|
||||
mvwhline(wFooter->Raw(), 0, 0, '=',howlong);
|
||||
mvwaddch(wFooter->Raw(), 0, howlong, '>');
|
||||
|
||||
Reference in New Issue
Block a user