status: improve dealing with now playing song
This commit is contained in:
@@ -68,6 +68,14 @@ void WindowTitle(const std::string &status)
|
|||||||
}
|
}
|
||||||
#endif // !USE_PDCURSES
|
#endif // !USE_PDCURSES
|
||||||
|
|
||||||
|
void DrawNowPlayingTitle(MPD::Song &np)
|
||||||
|
{
|
||||||
|
if (np.empty())
|
||||||
|
np = myPlaylist->nowPlayingSong();
|
||||||
|
if (!np.empty())
|
||||||
|
WindowTitle(np.toString(Config.song_window_title_format));
|
||||||
|
}
|
||||||
|
|
||||||
void StatusbarMPDCallback()
|
void StatusbarMPDCallback()
|
||||||
{
|
{
|
||||||
Mpd.OrderDataFetching();
|
Mpd.OrderDataFetching();
|
||||||
@@ -136,6 +144,32 @@ void UnlockStatusbar()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TryToClearStatusbarMessage()
|
||||||
|
{
|
||||||
|
using Global::Timer;
|
||||||
|
if (lock_statusbar_delay > 0)
|
||||||
|
{
|
||||||
|
if (Timer.tv_sec >= time_of_statusbar_lock.tv_sec+lock_statusbar_delay)
|
||||||
|
{
|
||||||
|
lock_statusbar_delay = -1;
|
||||||
|
|
||||||
|
if (Config.statusbar_visibility)
|
||||||
|
block_statusbar_update = !allow_statusbar_unlock;
|
||||||
|
else
|
||||||
|
block_progressbar_update = !allow_statusbar_unlock;
|
||||||
|
|
||||||
|
if (Mpd.GetState() != MPD::psPlay && !block_statusbar_update && !block_progressbar_update)
|
||||||
|
{
|
||||||
|
if (Config.new_design)
|
||||||
|
DrawProgressbar(Mpd.GetElapsedTime(), Mpd.GetTotalTime());
|
||||||
|
else
|
||||||
|
Statusbar() << wclrtoeol;
|
||||||
|
wFooter->refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TraceMpdStatus()
|
void TraceMpdStatus()
|
||||||
{
|
{
|
||||||
static timeval past = { 0, 0 };
|
static timeval past = { 0, 0 };
|
||||||
@@ -169,27 +203,7 @@ void TraceMpdStatus()
|
|||||||
myPlaylist->Items->refresh();
|
myPlaylist->Items->refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lock_statusbar_delay > 0)
|
TryToClearStatusbarMessage();
|
||||||
{
|
|
||||||
if (Timer.tv_sec >= time_of_statusbar_lock.tv_sec+lock_statusbar_delay)
|
|
||||||
{
|
|
||||||
lock_statusbar_delay = -1;
|
|
||||||
|
|
||||||
if (Config.statusbar_visibility)
|
|
||||||
block_statusbar_update = !allow_statusbar_unlock;
|
|
||||||
else
|
|
||||||
block_progressbar_update = !allow_statusbar_unlock;
|
|
||||||
|
|
||||||
if (Mpd.GetState() != MPD::psPlay && !block_statusbar_update && !block_progressbar_update)
|
|
||||||
{
|
|
||||||
if (Config.new_design)
|
|
||||||
DrawProgressbar(Mpd.GetElapsedTime(), Mpd.GetTotalTime());
|
|
||||||
else
|
|
||||||
Statusbar() << wclrtoeol;
|
|
||||||
wFooter->refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NcmpcppErrorCallback(MPD::Connection *, int errorid, const char *msg, void *)
|
void NcmpcppErrorCallback(MPD::Connection *, int errorid, const char *msg, void *)
|
||||||
@@ -221,17 +235,14 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
|||||||
static size_t first_line_scroll_begin = 0;
|
static size_t first_line_scroll_begin = 0;
|
||||||
static size_t second_line_scroll_begin = 0;
|
static size_t second_line_scroll_begin = 0;
|
||||||
static std::string player_state;
|
static std::string player_state;
|
||||||
static MPD::Song np;
|
|
||||||
|
MPD::Song np;
|
||||||
|
|
||||||
int sx = wFooter->getX();
|
int sx = wFooter->getX();
|
||||||
int sy = wFooter->getY();
|
int sy = wFooter->getY();
|
||||||
|
|
||||||
if (changed.Playlist)
|
if (changed.Playlist)
|
||||||
{
|
{
|
||||||
np = Mpd.GetCurrentlyPlayingSong();
|
|
||||||
if (!np.empty())
|
|
||||||
WindowTitle(np.toString(Config.song_window_title_format));
|
|
||||||
|
|
||||||
myPlaylist->Items->clearSearchResults();
|
myPlaylist->Items->clearSearchResults();
|
||||||
withUnfilteredMenuReapplyFilter(*myPlaylist->Items, []() {
|
withUnfilteredMenuReapplyFilter(*myPlaylist->Items, []() {
|
||||||
size_t playlist_length = Mpd.GetPlaylistLength();
|
size_t playlist_length = Mpd.GetPlaylistLength();
|
||||||
@@ -261,6 +272,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
DrawNowPlayingTitle(np);
|
||||||
|
|
||||||
Playlist::ReloadTotalLength = true;
|
Playlist::ReloadTotalLength = true;
|
||||||
Playlist::ReloadRemaining = true;
|
Playlist::ReloadRemaining = true;
|
||||||
|
|
||||||
@@ -323,8 +336,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
|||||||
}
|
}
|
||||||
case MPD::psPlay:
|
case MPD::psPlay:
|
||||||
{
|
{
|
||||||
if (!np.empty())
|
DrawNowPlayingTitle(np);
|
||||||
WindowTitle(np.toString(Config.song_window_title_format));
|
|
||||||
player_state = Config.new_design ? "[playing]" : "Playing: ";
|
player_state = Config.new_design ? "[playing]" : "Playing: ";
|
||||||
Playlist::ReloadRemaining = true;
|
Playlist::ReloadRemaining = true;
|
||||||
if (Mpd.GetOldState() == MPD::psStop) // show track info in status immediately
|
if (Mpd.GetOldState() == MPD::psStop) // show track info in status immediately
|
||||||
@@ -389,12 +401,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())
|
DrawNowPlayingTitle(np);
|
||||||
{
|
|
||||||
np = Mpd.GetCurrentlyPlayingSong();
|
|
||||||
if (!np.empty())
|
|
||||||
WindowTitle(np.toString(Config.song_window_title_format));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Config.autocenter_mode && !myPlaylist->Items->isFiltered())
|
if (Config.autocenter_mode && !myPlaylist->Items->isFiltered())
|
||||||
myPlaylist->Items->highlight(Mpd.GetCurrentlyPlayingSongPos());
|
myPlaylist->Items->highlight(Mpd.GetCurrentlyPlayingSongPos());
|
||||||
@@ -409,14 +416,10 @@ 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())
|
if (Mpd.isPlaying())
|
||||||
{
|
|
||||||
np = Mpd.GetCurrentlyPlayingSong();
|
|
||||||
if (!np.empty())
|
|
||||||
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
|
||||||
}
|
|
||||||
if (!np.empty() && Mpd.isPlaying())
|
|
||||||
{
|
{
|
||||||
|
DrawNowPlayingTitle(np);
|
||||||
|
|
||||||
std::string tracklength;
|
std::string tracklength;
|
||||||
if (Config.new_design)
|
if (Config.new_design)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
# define WindowTitle(x);
|
# define WindowTitle(x);
|
||||||
#endif // USE_PDCURSES
|
#endif // USE_PDCURSES
|
||||||
|
|
||||||
|
void DrawNowPlayingTitle();
|
||||||
|
|
||||||
void LockProgressbar();
|
void LockProgressbar();
|
||||||
void UnlockProgressbar();
|
void UnlockProgressbar();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user