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