remove extern int now_playing
This commit is contained in:
@@ -70,7 +70,7 @@ namespace Global
|
||||
|
||||
extern MPD::Connection *Mpd;
|
||||
|
||||
extern int now_playing;
|
||||
// extern int now_playing;
|
||||
extern int lock_statusbar_delay;
|
||||
|
||||
// extern size_t browsed_dir_scroll_begin;
|
||||
|
||||
@@ -74,7 +74,7 @@ void Lyrics::Update()
|
||||
if (!reload_lyrics)
|
||||
return;
|
||||
|
||||
const MPD::Song &s = myPlaylist->Main()->at(now_playing);
|
||||
const MPD::Song &s = myPlaylist->NowPlayingSong();
|
||||
if (!s.GetArtist().empty() && !s.GetTitle().empty())
|
||||
Get();
|
||||
else
|
||||
@@ -133,7 +133,7 @@ void Lyrics::Get()
|
||||
current_screen = csPlaylist;
|
||||
wCurrent = myPlaylist->Main();
|
||||
reload_lyrics = 0;
|
||||
id = now_playing;
|
||||
id = myPlaylist->NowPlaying;
|
||||
}
|
||||
else
|
||||
id = ((Menu<MPD::Song> *)wCurrent)->Choice();
|
||||
|
||||
@@ -71,7 +71,6 @@ Window *Global::wFooter;
|
||||
|
||||
Connection *Global::Mpd;
|
||||
|
||||
int Global::now_playing = -1;
|
||||
int Global::lock_statusbar_delay = -1;
|
||||
|
||||
size_t Global::main_start_y;
|
||||
@@ -813,8 +812,8 @@ int main(int argc, char *argv[])
|
||||
size_t id = myPlaylist->Main()->Choice();
|
||||
TraceMpdStatus();
|
||||
timer = time(NULL);
|
||||
if (size_t(now_playing) > id) // needed for keeping proper
|
||||
now_playing--; // position of now playing song.
|
||||
if (size_t(myPlaylist->NowPlaying) > id) // needed for keeping proper
|
||||
myPlaylist->NowPlaying--; // position of now playing song.
|
||||
Mpd->QueueDeleteSong(id);
|
||||
myPlaylist->Main()->DeleteOption(id);
|
||||
myPlaylist->Main()->Refresh();
|
||||
@@ -967,8 +966,8 @@ int main(int argc, char *argv[])
|
||||
myPlaylist->Main()->GetSelected(list);
|
||||
|
||||
for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++)
|
||||
if (*it == size_t(now_playing) && list.front() > 0)
|
||||
myPlaylist->Main()->BoldOption(now_playing, 0);
|
||||
if (*it == size_t(myPlaylist->NowPlaying) && list.front() > 0)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
|
||||
vector<size_t> origs(list);
|
||||
|
||||
@@ -994,8 +993,8 @@ int main(int argc, char *argv[])
|
||||
size_t from, to;
|
||||
from = to = myPlaylist->Main()->Choice();
|
||||
// unbold now playing as if song changes during move, this won't be unbolded.
|
||||
if (to == size_t(now_playing) && to > 0)
|
||||
myPlaylist->Main()->BoldOption(now_playing, 0);
|
||||
if (to == size_t(myPlaylist->NowPlaying) && to > 0)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
while (Keypressed(input, Key.MvSongUp) && to > 0)
|
||||
{
|
||||
TraceMpdStatus();
|
||||
@@ -1070,8 +1069,8 @@ int main(int argc, char *argv[])
|
||||
myPlaylist->Main()->GetSelected(list);
|
||||
|
||||
for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++)
|
||||
if (*it == size_t(now_playing) && list.back() < myPlaylist->Main()->Size()-1)
|
||||
myPlaylist->Main()->BoldOption(now_playing, 0);
|
||||
if (*it == size_t(myPlaylist->NowPlaying) && list.back() < myPlaylist->Main()->Size()-1)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
|
||||
vector<size_t> origs(list);
|
||||
|
||||
@@ -1097,8 +1096,8 @@ int main(int argc, char *argv[])
|
||||
size_t from, to;
|
||||
from = to = myPlaylist->Main()->Choice();
|
||||
// unbold now playing as if song changes during move, this won't be unbolded.
|
||||
if (to == size_t(now_playing) && to < myPlaylist->Main()->Size()-1)
|
||||
myPlaylist->Main()->BoldOption(now_playing, 0);
|
||||
if (to == size_t(myPlaylist->NowPlaying) && to < myPlaylist->Main()->Size()-1)
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 0);
|
||||
while (Keypressed(input, Key.MvSongDown) && to < myPlaylist->Main()->Size()-1)
|
||||
{
|
||||
TraceMpdStatus();
|
||||
@@ -1190,9 +1189,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
|
||||
{
|
||||
if (now_playing < 0)
|
||||
if (!myPlaylist->isPlaying())
|
||||
continue;
|
||||
if (!myPlaylist->Main()->at(now_playing).GetTotalLength())
|
||||
if (!myPlaylist->NowPlayingSong().GetTotalLength())
|
||||
{
|
||||
ShowMessage("Unknown item length!");
|
||||
continue;
|
||||
@@ -1204,7 +1203,7 @@ int main(int argc, char *argv[])
|
||||
time_t t = time(NULL);
|
||||
|
||||
songpos = Mpd->GetElapsedTime();
|
||||
Song &s = myPlaylist->Main()->at(now_playing);
|
||||
const Song &s = myPlaylist->NowPlayingSong();
|
||||
|
||||
while (Keypressed(input, Key.SeekForward) || Keypressed(input, Key.SeekBackward))
|
||||
{
|
||||
@@ -1284,8 +1283,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
Config.autocenter_mode = !Config.autocenter_mode;
|
||||
ShowMessage("Auto center mode: %s", Config.autocenter_mode ? "On" : "Off");
|
||||
if (Config.autocenter_mode && now_playing >= 0)
|
||||
myPlaylist->Main()->Highlight(now_playing);
|
||||
if (Config.autocenter_mode && myPlaylist->isPlaying())
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
}
|
||||
else if (Keypressed(input, Key.UpdateDB))
|
||||
{
|
||||
@@ -1300,8 +1299,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.GoToNowPlaying))
|
||||
{
|
||||
if (current_screen == csPlaylist && now_playing >= 0)
|
||||
myPlaylist->Main()->Highlight(now_playing);
|
||||
if (current_screen == csPlaylist && myPlaylist->isPlaying())
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
}
|
||||
else if (Keypressed(input, Key.ToggleRepeat))
|
||||
{
|
||||
@@ -1608,9 +1607,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.GoToPosition))
|
||||
{
|
||||
if (now_playing < 0)
|
||||
if (!myPlaylist->isPlaying())
|
||||
continue;
|
||||
if (!myPlaylist->Main()->at(now_playing).GetTotalLength())
|
||||
if (!myPlaylist->NowPlayingSong().GetTotalLength())
|
||||
{
|
||||
ShowMessage("Unknown item length!");
|
||||
continue;
|
||||
@@ -1620,7 +1619,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(myPlaylist->Main()->at(now_playing).GetTotalLength()*newpos/100.0);
|
||||
Mpd->Seek(myPlaylist->NowPlayingSong().GetTotalLength()*newpos/100.0);
|
||||
UnlockStatusbar();
|
||||
}
|
||||
else if (Keypressed(input, Key.ReverseSelection))
|
||||
@@ -1865,13 +1864,13 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
||||
{
|
||||
if (!myPlaylist->Main()->isSelected(i) && i != size_t(now_playing))
|
||||
if (!myPlaylist->Main()->isSelected(i) && i != size_t(myPlaylist->NowPlaying))
|
||||
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(i).GetID());
|
||||
}
|
||||
// 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 (now_playing >= 0 && !myPlaylist->Main()->isSelected(now_playing))
|
||||
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(now_playing).GetID());
|
||||
if (myPlaylist->isPlaying() && !myPlaylist->Main()->isSelected(myPlaylist->NowPlaying))
|
||||
Mpd->QueueDeleteSongId(myPlaylist->NowPlayingSong().GetID());
|
||||
|
||||
ShowMessage("Deleting all items but selected...");
|
||||
Mpd->CommitQueue();
|
||||
@@ -1879,14 +1878,14 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
if (now_playing < 0)
|
||||
if (!myPlaylist->isPlaying())
|
||||
{
|
||||
ShowMessage("Nothing is playing now!");
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < now_playing; i++)
|
||||
for (int i = 0; i < myPlaylist->NowPlaying; i++)
|
||||
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(i).GetID());
|
||||
for (size_t i = now_playing+1; i < myPlaylist->Main()->Size(); i++)
|
||||
for (size_t i = myPlaylist->NowPlaying+1; i < myPlaylist->Main()->Size(); i++)
|
||||
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(i).GetID());
|
||||
ShowMessage("Deleting all items except now playing one...");
|
||||
Mpd->CommitQueue();
|
||||
|
||||
@@ -20,11 +20,14 @@
|
||||
|
||||
#include "display.h"
|
||||
#include "global.h"
|
||||
#include "helpers.h"
|
||||
#include "menu.h"
|
||||
#include "playlist.h"
|
||||
#include "song.h"
|
||||
#include "status_checker.h"
|
||||
|
||||
using namespace Global;
|
||||
using std::vector;
|
||||
|
||||
Playlist *myPlaylist = new Playlist;
|
||||
|
||||
@@ -141,3 +144,8 @@ std::string Playlist::TotalLength()
|
||||
return result.str();
|
||||
}
|
||||
|
||||
const MPD::Song &Playlist::NowPlayingSong()
|
||||
{
|
||||
static MPD::Song null;
|
||||
return isPlaying() ? w->at(NowPlaying) : null;
|
||||
}
|
||||
@@ -28,6 +28,9 @@
|
||||
class Playlist : public Screen< Menu<MPD::Song> >
|
||||
{
|
||||
public:
|
||||
Playlist() : NowPlaying(-1), OldPlaying(-1) { }
|
||||
~Playlist() { }
|
||||
|
||||
virtual void Init();
|
||||
virtual void SwitchTo();
|
||||
virtual void Resize();
|
||||
@@ -37,6 +40,12 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
virtual void EnterPressed();
|
||||
virtual void SpacePressed();
|
||||
|
||||
bool isPlaying() { return NowPlaying >= 0 && !w->Empty(); }
|
||||
const MPD::Song &NowPlayingSong();
|
||||
|
||||
int NowPlaying;
|
||||
int OldPlaying;
|
||||
|
||||
protected:
|
||||
std::string TotalLength();
|
||||
};
|
||||
|
||||
@@ -42,8 +42,6 @@ namespace
|
||||
{
|
||||
time_t time_of_statusbar_lock;
|
||||
|
||||
int old_playing;
|
||||
|
||||
string switch_state;
|
||||
|
||||
bool block_statusbar_update = 0;
|
||||
@@ -143,14 +141,14 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
wFooter->Bold(1);
|
||||
wFooter->GetXY(sx, sy);
|
||||
|
||||
if ((now_playing != Mpd->GetCurrentSongPos() || changed.SongID) && !dont_change_now_playing)
|
||||
if ((myPlaylist->NowPlaying != Mpd->GetCurrentSongPos() || changed.SongID) && !dont_change_now_playing)
|
||||
{
|
||||
old_playing = now_playing;
|
||||
now_playing = Mpd->GetCurrentSongPos();
|
||||
myPlaylist->OldPlaying = myPlaylist->NowPlaying;
|
||||
myPlaylist->NowPlaying = Mpd->GetCurrentSongPos();
|
||||
try
|
||||
{
|
||||
myPlaylist->Main()->BoldOption(old_playing, 0);
|
||||
myPlaylist->Main()->BoldOption(now_playing, 1);
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->OldPlaying, 0);
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 1);
|
||||
}
|
||||
catch (std::out_of_range) { }
|
||||
}
|
||||
@@ -183,7 +181,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
else
|
||||
{
|
||||
// otherwise just add it to playlist
|
||||
myPlaylist->Main()->AddOption(**it, now_playing == pos);
|
||||
myPlaylist->Main()->AddOption(**it, myPlaylist->NowPlaying == pos);
|
||||
}
|
||||
myPlaylist->Main()->at(pos).CopyPtr(0);
|
||||
(*it)->NullMe();
|
||||
@@ -265,7 +263,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
case psPlay:
|
||||
{
|
||||
player_state = "Playing: ";
|
||||
myPlaylist->Main()->BoldOption(now_playing, 1);
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 1);
|
||||
changed.ElapsedTime = 1;
|
||||
break;
|
||||
}
|
||||
@@ -282,10 +280,10 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
wFooter->SetColor(Config.statusbar_color);
|
||||
try
|
||||
{
|
||||
myPlaylist->Main()->BoldOption(old_playing, 0);
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->OldPlaying, 0);
|
||||
}
|
||||
catch (std::out_of_range) { }
|
||||
now_playing = -1;
|
||||
myPlaylist->NowPlaying = -1;
|
||||
player_state.clear();
|
||||
break;
|
||||
}
|
||||
@@ -295,21 +293,21 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
}
|
||||
if (changed.SongID)
|
||||
{
|
||||
if (!myPlaylist->Main()->Empty() && now_playing >= 0)
|
||||
if (myPlaylist->isPlaying())
|
||||
{
|
||||
if (Config.repeat_one_mode && repeat_one_allowed)
|
||||
{
|
||||
std::swap(now_playing, old_playing);
|
||||
Mpd->Play(now_playing);
|
||||
std::swap(myPlaylist->NowPlaying, myPlaylist->OldPlaying);
|
||||
Mpd->Play(myPlaylist->NowPlaying);
|
||||
}
|
||||
try
|
||||
{
|
||||
myPlaylist->Main()->BoldOption(old_playing, 0);
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->OldPlaying, 0);
|
||||
}
|
||||
catch (std::out_of_range &) { }
|
||||
myPlaylist->Main()->BoldOption(now_playing, 1);
|
||||
myPlaylist->Main()->BoldOption(myPlaylist->NowPlaying, 1);
|
||||
if (Config.autocenter_mode)
|
||||
myPlaylist->Main()->Highlight(now_playing);
|
||||
myPlaylist->Main()->Highlight(myPlaylist->NowPlaying);
|
||||
repeat_one_allowed = 0;
|
||||
|
||||
if (!Mpd->GetElapsedTime())
|
||||
|
||||
Reference in New Issue
Block a user