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