various clean-ups and improvements
This commit is contained in:
@@ -596,7 +596,6 @@ void GetDirectory(string dir)
|
|||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
{
|
{
|
||||||
it->name = it->song->GetFile();
|
|
||||||
Song *s = it->song;
|
Song *s = it->song;
|
||||||
bool bold = 0;
|
bool bold = 0;
|
||||||
for (SongList::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
|
for (SongList::const_iterator it = vPlaylist.begin(); it != vPlaylist.end(); it++)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ string GetLyrics(string artist, string song)
|
|||||||
curl_easy_setopt(lyrics, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(lyrics, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(lyrics, CURLOPT_WRITEFUNCTION, write_data);
|
curl_easy_setopt(lyrics, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
curl_easy_setopt(lyrics, CURLOPT_WRITEDATA, &result);
|
curl_easy_setopt(lyrics, CURLOPT_WRITEDATA, &result);
|
||||||
curl_easy_setopt(lyrics, CURLOPT_CONNECTTIMEOUT, 30);
|
curl_easy_setopt(lyrics, CURLOPT_CONNECTTIMEOUT, 10);
|
||||||
code = curl_easy_perform(lyrics);
|
code = curl_easy_perform(lyrics);
|
||||||
curl_easy_cleanup(lyrics);
|
curl_easy_cleanup(lyrics);
|
||||||
|
|
||||||
|
|||||||
33
src/menu.cpp
33
src/menu.cpp
@@ -254,10 +254,7 @@ void Menu::Display(bool redraw_whole_window)
|
|||||||
void Menu::Refresh(bool redraw_whole_window)
|
void Menu::Refresh(bool redraw_whole_window)
|
||||||
{
|
{
|
||||||
if (!itsOptions.empty() && is_static())
|
if (!itsOptions.empty() && is_static())
|
||||||
if (itsHighlight == 0)
|
itsHighlight == 0 ? Go(DOWN) : Go(UP);
|
||||||
Go(DOWN);
|
|
||||||
else
|
|
||||||
Go(UP);
|
|
||||||
|
|
||||||
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
int MaxBeginning = itsOptions.size() < itsHeight ? 0 : itsOptions.size()-itsHeight;
|
||||||
if (itsBeginning > MaxBeginning)
|
if (itsBeginning > MaxBeginning)
|
||||||
@@ -269,32 +266,6 @@ void Menu::Refresh(bool redraw_whole_window)
|
|||||||
if (redraw_whole_window)
|
if (redraw_whole_window)
|
||||||
redraw_screen();
|
redraw_screen();
|
||||||
|
|
||||||
int line = 0;
|
|
||||||
/*int last;
|
|
||||||
|
|
||||||
if (itsOptions.size() < itsHeight)
|
|
||||||
last = itsOptions.size();
|
|
||||||
else
|
|
||||||
last = itsBeginning+itsHeight;
|
|
||||||
|
|
||||||
int check = 0;
|
|
||||||
bool next = 1;
|
|
||||||
for (int i = last-1; i > itsBeginning && next; i--)
|
|
||||||
{
|
|
||||||
next = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
itsOptions.at(i);
|
|
||||||
}
|
|
||||||
catch (std::out_of_range)
|
|
||||||
{
|
|
||||||
check++;
|
|
||||||
next = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
itsBeginning -= check;
|
|
||||||
last -= check;*/
|
|
||||||
|
|
||||||
for (vector<int>::const_iterator it = NeedsRedraw.begin(); it != NeedsRedraw.end(); it++)
|
for (vector<int>::const_iterator it = NeedsRedraw.begin(); it != NeedsRedraw.end(); it++)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -306,7 +277,7 @@ void Menu::Refresh(bool redraw_whole_window)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
line = *it-itsBeginning;
|
int line = *it-itsBeginning;
|
||||||
|
|
||||||
if (*it == itsHighlight && itsHighlightEnabled)
|
if (*it == itsHighlight && itsHighlightEnabled)
|
||||||
{
|
{
|
||||||
|
|||||||
110
src/mpdpp.cpp
110
src/mpdpp.cpp
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
const string playlist_max_message = "playlist is at the max size";
|
const string playlist_max_message = "playlist is at the max size";
|
||||||
|
|
||||||
MPDConnection::MPDConnection() : isConnected(0), MPD_HOST("localhost"), MPD_PORT(6600), MPD_TIMEOUT(30), itsUpdater(0), itsErrorHandler(0), itsQueueIndex(0), itsMaxPlaylistLength(-1)
|
MPDConnection::MPDConnection() : isConnected(0), MPD_HOST("localhost"), MPD_PORT(6600), MPD_TIMEOUT(30), itsUpdater(0), itsErrorHandler(0), itsMaxPlaylistLength(-1)
|
||||||
{
|
{
|
||||||
itsConnection = 0;
|
itsConnection = 0;
|
||||||
itsCurrentStats = 0;
|
itsCurrentStats = 0;
|
||||||
@@ -43,16 +43,23 @@ MPDConnection::~MPDConnection()
|
|||||||
mpd_freeStatus(itsOldStatus);
|
mpd_freeStatus(itsOldStatus);
|
||||||
if (itsCurrentStatus)
|
if (itsCurrentStatus)
|
||||||
mpd_freeStatus(itsCurrentStatus);
|
mpd_freeStatus(itsCurrentStatus);
|
||||||
|
ClearQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::Connect()
|
bool MPDConnection::Connect()
|
||||||
{
|
{
|
||||||
if (!isConnected && !itsConnection)
|
if (!isConnected && !itsConnection)
|
||||||
{
|
{
|
||||||
itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT);
|
itsConnection = mpd_newConnection(MPD_HOST.c_str(), MPD_PORT, MPD_TIMEOUT);
|
||||||
isConnected = 1;
|
isConnected = 1;
|
||||||
|
if (!CheckForErrors())
|
||||||
|
return isConnected;
|
||||||
|
SendPassword();
|
||||||
CheckForErrors();
|
CheckForErrors();
|
||||||
|
return isConnected;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MPDConnection::Connected()
|
bool MPDConnection::Connected()
|
||||||
@@ -79,8 +86,7 @@ void MPDConnection::Disconnect()
|
|||||||
itsOldStatus = 0;
|
itsOldStatus = 0;
|
||||||
isConnected = 0;
|
isConnected = 0;
|
||||||
itsMaxPlaylistLength = -1;
|
itsMaxPlaylistLength = -1;
|
||||||
itsQueueIndex = 0;
|
ClearQueue();
|
||||||
itsQueue.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::SendPassword()
|
void MPDConnection::SendPassword()
|
||||||
@@ -245,6 +251,15 @@ void MPDConnection::Seek(int where) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MPDConnection::Shuffle() const
|
||||||
|
{
|
||||||
|
if (isConnected)
|
||||||
|
{
|
||||||
|
mpd_sendShuffleCommand(itsConnection);
|
||||||
|
mpd_finishCommand(itsConnection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MPDConnection::ClearPlaylist() const
|
void MPDConnection::ClearPlaylist() const
|
||||||
{
|
{
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
@@ -390,83 +405,78 @@ int MPDConnection::AddSong(const string &path)
|
|||||||
|
|
||||||
int MPDConnection::AddSong(const Song &s)
|
int MPDConnection::AddSong(const Song &s)
|
||||||
{
|
{
|
||||||
int id = -1;
|
return !s.Empty() ? AddSong(s.GetFile()) : -1;
|
||||||
if (isConnected)
|
|
||||||
{
|
|
||||||
if (GetPlaylistLength() < itsMaxPlaylistLength)
|
|
||||||
{
|
|
||||||
id = mpd_sendAddIdCommand(itsConnection, s.GetFile().c_str());
|
|
||||||
mpd_finishCommand(itsConnection);
|
|
||||||
UpdateStatus();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (itsErrorHandler)
|
|
||||||
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, playlist_max_message, NULL);
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::QueueAddSong(const string &path)
|
void MPDConnection::QueueAddSong(const string &path)
|
||||||
{
|
{
|
||||||
if (isConnected && GetPlaylistLength() < itsMaxPlaylistLength)
|
if (isConnected && GetPlaylistLength() < itsMaxPlaylistLength)
|
||||||
{
|
{
|
||||||
itsQueue[itsQueueIndex].type = qctAdd;
|
QueueCommand *q = new QueueCommand;
|
||||||
itsQueue[itsQueueIndex++].path = path;
|
q->type = qctAdd;
|
||||||
|
q->path = path;
|
||||||
|
itsQueue.push_back(q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::QueueAddSong(const Song &s)
|
void MPDConnection::QueueAddSong(const Song &s)
|
||||||
{
|
{
|
||||||
itsQueue[itsQueueIndex].type = qctAdd;
|
if (!s.Empty())
|
||||||
itsQueue[itsQueueIndex++].path = s.GetFile();
|
QueueAddSong(s.GetFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::QueueDeleteSong(int id)
|
void MPDConnection::QueueDeleteSong(int id)
|
||||||
{
|
{
|
||||||
itsQueue[itsQueueIndex].type = qctDelete;
|
if (isConnected)
|
||||||
itsQueue[itsQueueIndex++].id = id;
|
{
|
||||||
|
QueueCommand *q = new QueueCommand;
|
||||||
|
q->type = qctDelete;
|
||||||
|
q->id = id;
|
||||||
|
itsQueue.push_back(q);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::QueueDeleteSongId(int id)
|
void MPDConnection::QueueDeleteSongId(int id)
|
||||||
{
|
|
||||||
itsQueue[itsQueueIndex].type = qctDeleteID;
|
|
||||||
itsQueue[itsQueueIndex++].id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MPDConnection::CommitQueue()
|
|
||||||
{
|
{
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
{
|
{
|
||||||
int playlist_length = GetPlaylistLength();
|
QueueCommand *q = new QueueCommand;
|
||||||
|
q->type = qctDeleteID;
|
||||||
|
q->id = id;
|
||||||
|
itsQueue.push_back(q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MPDConnection::CommitQueue()
|
||||||
|
{
|
||||||
|
bool retval = false;
|
||||||
|
if (isConnected)
|
||||||
|
{
|
||||||
mpd_sendCommandListBegin(itsConnection);
|
mpd_sendCommandListBegin(itsConnection);
|
||||||
for (std::map<int, QueueCommand>::const_iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
|
for (std::vector<QueueCommand *>::const_iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
|
||||||
{
|
{
|
||||||
switch (it->second.type)
|
switch ((*it)->type)
|
||||||
{
|
{
|
||||||
case qctAdd:
|
case qctAdd:
|
||||||
if (playlist_length < itsMaxPlaylistLength)
|
mpd_sendAddCommand(itsConnection, (*it)->path.c_str());
|
||||||
{
|
|
||||||
mpd_sendAddCommand(itsConnection, it->second.path.c_str());
|
|
||||||
playlist_length++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (itsErrorHandler)
|
|
||||||
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, playlist_max_message, NULL);
|
|
||||||
break;
|
break;
|
||||||
case qctDelete:
|
case qctDelete:
|
||||||
mpd_sendDeleteCommand(itsConnection, it->second.id);
|
mpd_sendDeleteCommand(itsConnection, (*it)->id);
|
||||||
break;
|
break;
|
||||||
case qctDeleteID:
|
case qctDeleteID:
|
||||||
mpd_sendDeleteIdCommand(itsConnection, it->second.id);
|
mpd_sendDeleteIdCommand(itsConnection, (*it)->id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mpd_sendCommandListEnd(itsConnection);
|
mpd_sendCommandListEnd(itsConnection);
|
||||||
mpd_finishCommand(itsConnection);
|
mpd_finishCommand(itsConnection);
|
||||||
UpdateStatus();
|
UpdateStatus();
|
||||||
|
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler)
|
||||||
|
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, playlist_max_message, NULL);
|
||||||
|
retval = !itsQueue.empty();
|
||||||
}
|
}
|
||||||
itsQueueIndex = 0;
|
ClearQueue();
|
||||||
itsQueue.clear();
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::DeletePlaylist(const string &name)
|
void MPDConnection::DeletePlaylist(const string &name)
|
||||||
@@ -487,7 +497,7 @@ bool MPDConnection::SavePlaylist(const string &name)
|
|||||||
return !(itsConnection->error == MPD_ERROR_ACK && itsConnection->errorCode == MPD_ACK_ERROR_EXIST);
|
return !(itsConnection->error == MPD_ERROR_ACK && itsConnection->errorCode == MPD_ACK_ERROR_EXIST);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPDConnection::GetArtists(TagList &v) const
|
void MPDConnection::GetArtists(TagList &v) const
|
||||||
@@ -609,6 +619,7 @@ int MPDConnection::CheckForErrors()
|
|||||||
if (itsConnection->error == MPD_ERROR_ACK)
|
if (itsConnection->error == MPD_ERROR_ACK)
|
||||||
{
|
{
|
||||||
// this is to avoid setting too small max size as we check it before fetching current status
|
// this is to avoid setting too small max size as we check it before fetching current status
|
||||||
|
// setting real max playlist length is in UpdateStatus()
|
||||||
if (itsConnection->errorCode == MPD_ACK_ERROR_PLAYLIST_MAX && itsMaxPlaylistLength == -1)
|
if (itsConnection->errorCode == MPD_ACK_ERROR_PLAYLIST_MAX && itsMaxPlaylistLength == -1)
|
||||||
itsMaxPlaylistLength = 0;
|
itsMaxPlaylistLength = 0;
|
||||||
|
|
||||||
@@ -629,6 +640,13 @@ int MPDConnection::CheckForErrors()
|
|||||||
return errid;
|
return errid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MPDConnection::ClearQueue()
|
||||||
|
{
|
||||||
|
for (std::vector<QueueCommand *>::iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
|
||||||
|
delete *it;
|
||||||
|
itsQueue.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void FreeSongList(SongList &l)
|
void FreeSongList(SongList &l)
|
||||||
{
|
{
|
||||||
for (SongList::iterator i = l.begin(); i != l.end(); i++)
|
for (SongList::iterator i = l.begin(); i != l.end(); i++)
|
||||||
|
|||||||
11
src/mpdpp.h
11
src/mpdpp.h
@@ -21,8 +21,6 @@
|
|||||||
#ifndef HAVE_MPDPP_H
|
#ifndef HAVE_MPDPP_H
|
||||||
#define HAVE_MPDPP_H
|
#define HAVE_MPDPP_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
#include "ncmpcpp.h"
|
#include "ncmpcpp.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
@@ -77,7 +75,7 @@ class MPDConnection
|
|||||||
MPDConnection();
|
MPDConnection();
|
||||||
~MPDConnection();
|
~MPDConnection();
|
||||||
|
|
||||||
void Connect();
|
bool Connect();
|
||||||
bool Connected();
|
bool Connected();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
|
||||||
@@ -101,6 +99,7 @@ class MPDConnection
|
|||||||
void Prev() const;
|
void Prev() const;
|
||||||
void Move(int, int) const;
|
void Move(int, int) const;
|
||||||
void Seek(int) const;
|
void Seek(int) const;
|
||||||
|
void Shuffle() const;
|
||||||
void ClearPlaylist() const;
|
void ClearPlaylist() const;
|
||||||
|
|
||||||
PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; }
|
PlayerState GetState() const { return isConnected && itsCurrentStatus ? (PlayerState)itsCurrentStatus->state : psUnknown; }
|
||||||
@@ -135,7 +134,7 @@ class MPDConnection
|
|||||||
void QueueAddSong(const Song &);
|
void QueueAddSong(const Song &);
|
||||||
void QueueDeleteSong(int);
|
void QueueDeleteSong(int);
|
||||||
void QueueDeleteSongId(int);
|
void QueueDeleteSongId(int);
|
||||||
void CommitQueue();
|
bool CommitQueue();
|
||||||
|
|
||||||
void DeletePlaylist(const string &);
|
void DeletePlaylist(const string &);
|
||||||
bool SavePlaylist(const string &);
|
bool SavePlaylist(const string &);
|
||||||
@@ -151,6 +150,7 @@ class MPDConnection
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int CheckForErrors();
|
int CheckForErrors();
|
||||||
|
void ClearQueue();
|
||||||
string itsLastErrorMessage;
|
string itsLastErrorMessage;
|
||||||
|
|
||||||
mpd_Connection *itsConnection;
|
mpd_Connection *itsConnection;
|
||||||
@@ -171,8 +171,7 @@ class MPDConnection
|
|||||||
ErrorHandler itsErrorHandler;
|
ErrorHandler itsErrorHandler;
|
||||||
void *itsErrorHandlerUserdata;
|
void *itsErrorHandlerUserdata;
|
||||||
|
|
||||||
std::map<int, QueueCommand> itsQueue;
|
std::vector<QueueCommand *> itsQueue;
|
||||||
int itsQueueIndex;
|
|
||||||
unsigned int itsMaxPlaylistLength;
|
unsigned int itsMaxPlaylistLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
132
src/ncmpcpp.cpp
132
src/ncmpcpp.cpp
@@ -140,6 +140,8 @@ extern string UNKNOWN_ALBUM;
|
|||||||
|
|
||||||
extern string playlist_stats;
|
extern string playlist_stats;
|
||||||
|
|
||||||
|
const string message_part_of_songs_added = "Only part of requested songs' list added to playlist!";
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
DefaultConfiguration(Config);
|
DefaultConfiguration(Config);
|
||||||
@@ -155,16 +157,14 @@ int main(int argc, char *argv[])
|
|||||||
if (getenv("MPD_PASSWORD"))
|
if (getenv("MPD_PASSWORD"))
|
||||||
Mpd->SetPassword(getenv("MPD_PASSWORD"));
|
Mpd->SetPassword(getenv("MPD_PASSWORD"));
|
||||||
|
|
||||||
Mpd->Connect();
|
Mpd->SetTimeout(Config.mpd_connection_timeout);
|
||||||
|
|
||||||
if (!Mpd->Connected())
|
if (!Mpd->Connect())
|
||||||
{
|
{
|
||||||
printf("Cannot connect to mpd (%s)\n", Mpd->GetLastErrorMessage().c_str());
|
printf("Cannot connect to mpd (%s)\n", Mpd->GetLastErrorMessage().c_str());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mpd->SendPassword();
|
|
||||||
|
|
||||||
setlocale(LC_ALL,"");
|
setlocale(LC_ALL,"");
|
||||||
initscr();
|
initscr();
|
||||||
noecho();
|
noecho();
|
||||||
@@ -314,8 +314,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
ShowMessage("Attempting to reconnect...");
|
ShowMessage("Attempting to reconnect...");
|
||||||
Mpd->Disconnect();
|
Mpd->Disconnect();
|
||||||
Mpd->Connect();
|
if (Mpd->Connect())
|
||||||
if (Mpd->Connected())
|
|
||||||
ShowMessage("Connected!");
|
ShowMessage("Connected!");
|
||||||
messages_allowed = 0;
|
messages_allowed = 0;
|
||||||
}
|
}
|
||||||
@@ -636,7 +635,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
{
|
{
|
||||||
Song s = Mpd->GetSong(vBrowser[ci].name);
|
Song &s = *vBrowser[ci].song;
|
||||||
int id = Mpd->AddSong(s);
|
int id = Mpd->AddSong(s);
|
||||||
if (id >= 0)
|
if (id >= 0)
|
||||||
{
|
{
|
||||||
@@ -649,21 +648,17 @@ int main(int argc, char *argv[])
|
|||||||
case itPlaylist:
|
case itPlaylist:
|
||||||
{
|
{
|
||||||
SongList list;
|
SongList list;
|
||||||
ShowMessage("Loading and playing playlist " + vBrowser[ci].name + "...");
|
|
||||||
Mpd->GetPlaylistContent(vBrowser[ci].name, list);
|
Mpd->GetPlaylistContent(vBrowser[ci].name, list);
|
||||||
for(SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||||
Mpd->QueueAddSong(**it);
|
Mpd->QueueAddSong(**it);
|
||||||
Mpd->CommitQueue();
|
if (Mpd->CommitQueue())
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Song *s = vPlaylist.at(vPlaylist.size()-list.size());
|
ShowMessage("Loading and playing playlist " + vBrowser[ci].name + "...");
|
||||||
if (s->GetHash() == list.at(0)->GetHash())
|
Song *s = vPlaylist[vPlaylist.size()-list.size()];
|
||||||
|
if (s->GetHash() == list[0]->GetHash())
|
||||||
Mpd->PlayID(s->GetID());
|
Mpd->PlayID(s->GetID());
|
||||||
}
|
else
|
||||||
catch (std::out_of_range)
|
ShowMessage(message_part_of_songs_added);
|
||||||
{
|
|
||||||
ShowMessage("Couldn't play playlist!");
|
|
||||||
}
|
}
|
||||||
FreeSongList(list);
|
FreeSongList(list);
|
||||||
break;
|
break;
|
||||||
@@ -956,8 +951,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
int ci = mSearcher->GetRealChoice()-1;
|
Song &s = *vSearched[mSearcher->GetRealChoice()-2];
|
||||||
Song s = Mpd->GetSong(vSearched[ci-1]->GetFile());
|
|
||||||
int id = Mpd->AddSong(s);
|
int id = Mpd->AddSong(s);
|
||||||
if (id >= 0)
|
if (id >= 0)
|
||||||
{
|
{
|
||||||
@@ -979,47 +973,40 @@ int main(int argc, char *argv[])
|
|||||||
if (wCurrent == mLibArtists)
|
if (wCurrent == mLibArtists)
|
||||||
{
|
{
|
||||||
const string &artist = mLibArtists->GetCurrentOption();
|
const string &artist = mLibArtists->GetCurrentOption();
|
||||||
ShowMessage("Adding all songs artist's: " + artist);
|
|
||||||
Mpd->StartSearch(1);
|
Mpd->StartSearch(1);
|
||||||
Mpd->AddSearch(MPD_TAG_ITEM_ARTIST, artist);
|
Mpd->AddSearch(MPD_TAG_ITEM_ARTIST, artist);
|
||||||
Mpd->CommitSearch(list);
|
Mpd->CommitSearch(list);
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||||
Mpd->QueueAddSong(**it);
|
Mpd->QueueAddSong(**it);
|
||||||
Mpd->CommitQueue();
|
if (Mpd->CommitQueue())
|
||||||
|
|
||||||
if (input == ENTER)
|
|
||||||
{
|
{
|
||||||
try
|
ShowMessage("Adding all songs artist's: " + artist);
|
||||||
|
Song *s = vPlaylist[vPlaylist.size()-list.size()];
|
||||||
|
if (s->GetHash() == list[0]->GetHash())
|
||||||
{
|
{
|
||||||
Song *s = vPlaylist.at(vPlaylist.size()-list.size());
|
if (input == ENTER)
|
||||||
if (s->GetHash() == list.at(0)->GetHash())
|
|
||||||
Mpd->PlayID(s->GetID());
|
Mpd->PlayID(s->GetID());
|
||||||
}
|
}
|
||||||
catch (std::out_of_range)
|
else
|
||||||
{
|
ShowMessage(message_part_of_songs_added);
|
||||||
ShowMessage("Couldn't play!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wCurrent == mLibAlbums)
|
if (wCurrent == mLibAlbums)
|
||||||
{
|
{
|
||||||
ShowMessage("Adding songs from album: " + mLibAlbums->GetCurrentOption());
|
|
||||||
for (SongList::const_iterator it = vSongs.begin(); it != vSongs.end(); it++)
|
for (SongList::const_iterator it = vSongs.begin(); it != vSongs.end(); it++)
|
||||||
Mpd->QueueAddSong(**it);
|
Mpd->QueueAddSong(**it);
|
||||||
Mpd->CommitQueue();
|
if (Mpd->CommitQueue())
|
||||||
if (input == ENTER)
|
|
||||||
{
|
{
|
||||||
try
|
ShowMessage("Adding songs from album: " + mLibAlbums->GetCurrentOption());
|
||||||
|
Song *s = vPlaylist[vPlaylist.size()-vSongs.size()];
|
||||||
|
if (s->GetHash() == vSongs[0]->GetHash())
|
||||||
{
|
{
|
||||||
Song *s = vPlaylist.at(vPlaylist.size()-vSongs.size());
|
if (input == ENTER)
|
||||||
if (s->GetHash() == vSongs.at(0)->GetHash())
|
|
||||||
Mpd->PlayID(s->GetID());
|
Mpd->PlayID(s->GetID());
|
||||||
}
|
}
|
||||||
catch (std::out_of_range)
|
else
|
||||||
{
|
ShowMessage(message_part_of_songs_added);
|
||||||
ShowMessage("Couldn't play!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1066,29 +1053,37 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||||
Mpd->QueueAddSong(**it);
|
Mpd->QueueAddSong(**it);
|
||||||
|
if (Mpd->CommitQueue())
|
||||||
|
{
|
||||||
|
ShowMessage("Added folder: " + getdir);
|
||||||
|
Song *s = vPlaylist[vPlaylist.size()-list.size()];
|
||||||
|
if (s->GetHash() != list[0]->GetHash())
|
||||||
|
ShowMessage(message_part_of_songs_added);
|
||||||
|
}
|
||||||
FreeSongList(list);
|
FreeSongList(list);
|
||||||
ShowMessage("Added folder: " + getdir);
|
|
||||||
Mpd->CommitQueue();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
{
|
{
|
||||||
Song s = Mpd->GetSong(vBrowser[ci].name);
|
Song &s = *vBrowser[ci].song;
|
||||||
int id = Mpd->AddSong(s);
|
if (Mpd->AddSong(s) != -1)
|
||||||
if (id >= 0)
|
|
||||||
ShowMessage("Added to playlist: " + OmitBBCodes(DisplaySong(s)));
|
ShowMessage("Added to playlist: " + OmitBBCodes(DisplaySong(s)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case itPlaylist:
|
case itPlaylist:
|
||||||
{
|
{
|
||||||
ShowMessage("Loading playlist " + vBrowser[ci].name + "...");
|
|
||||||
SongList list;
|
SongList list;
|
||||||
Mpd->GetPlaylistContent(vBrowser[ci].name, list);
|
Mpd->GetPlaylistContent(vBrowser[ci].name, list);
|
||||||
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||||
Mpd->QueueAddSong(**it);
|
Mpd->QueueAddSong(**it);
|
||||||
|
if (Mpd->CommitQueue())
|
||||||
|
{
|
||||||
|
ShowMessage("Loading playlist " + vBrowser[ci].name + "...");
|
||||||
|
Song *s = vPlaylist[vPlaylist.size()-list.size()];
|
||||||
|
if (s->GetHash() != list[0]->GetHash())
|
||||||
|
ShowMessage(message_part_of_songs_added);
|
||||||
|
}
|
||||||
FreeSongList(list);
|
FreeSongList(list);
|
||||||
Mpd->CommitQueue();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1101,8 +1096,8 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
Song &s = *vSearched[id];
|
Song &s = *vSearched[id];
|
||||||
Mpd->AddSong(s);
|
if (Mpd->AddSong(s) != -1)
|
||||||
ShowMessage("Added to playlist: " + OmitBBCodes(DisplaySong(s)));
|
ShowMessage("Added to playlist: " + OmitBBCodes(DisplaySong(s)));
|
||||||
mSearcher->Go(DOWN);
|
mSearcher->Go(DOWN);
|
||||||
}
|
}
|
||||||
if (current_screen == csLibrary)
|
if (current_screen == csLibrary)
|
||||||
@@ -1162,7 +1157,7 @@ int main(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case '-': //volume down
|
case '-': // volume down
|
||||||
{
|
{
|
||||||
Mpd->SetVolume(Mpd->GetVolume()-1);
|
Mpd->SetVolume(Mpd->GetVolume()-1);
|
||||||
break;
|
break;
|
||||||
@@ -1230,12 +1225,12 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '<':
|
case '<': // previous
|
||||||
{
|
{
|
||||||
Mpd->Prev();
|
Mpd->Prev();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '>':
|
case '>': // next
|
||||||
{
|
{
|
||||||
Mpd->Next();
|
Mpd->Next();
|
||||||
break;
|
break;
|
||||||
@@ -1301,7 +1296,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'n': //move song down
|
case 'n': // move song down
|
||||||
{
|
{
|
||||||
block_playlist_update = 1;
|
block_playlist_update = 1;
|
||||||
int pos = mPlaylist->GetChoice()-1;
|
int pos = mPlaylist->GetChoice()-1;
|
||||||
@@ -1398,12 +1393,12 @@ int main(int argc, char *argv[])
|
|||||||
Mpd->SetRepeat(!Mpd->GetRepeat());
|
Mpd->SetRepeat(!Mpd->GetRepeat());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'Z':
|
case 'Z': // shuffle playlist
|
||||||
{
|
{
|
||||||
//mpd_playlist_shuffle(conn);
|
Mpd->Shuffle();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'z': //switch random state
|
case 'z': // switch random state
|
||||||
{
|
{
|
||||||
Mpd->SetRandom(!Mpd->GetRandom());
|
Mpd->SetRandom(!Mpd->GetRandom());
|
||||||
break;
|
break;
|
||||||
@@ -1609,26 +1604,26 @@ int main(int argc, char *argv[])
|
|||||||
|| (wCurrent == mSearcher && !vSearched.empty() && mSearcher->GetChoice() > search_engine_static_option)
|
|| (wCurrent == mSearcher && !vSearched.empty() && mSearcher->GetChoice() > search_engine_static_option)
|
||||||
|| (wCurrent == mLibSongs))
|
|| (wCurrent == mLibSongs))
|
||||||
{
|
{
|
||||||
Song s;
|
Song *s;
|
||||||
switch (current_screen)
|
switch (current_screen)
|
||||||
{
|
{
|
||||||
case csPlaylist:
|
case csPlaylist:
|
||||||
s = *vPlaylist[mPlaylist->GetChoice()-1];
|
s = vPlaylist[mPlaylist->GetChoice()-1];
|
||||||
break;
|
break;
|
||||||
case csBrowser:
|
case csBrowser:
|
||||||
s = Mpd->GetSong(vBrowser[mBrowser->GetChoice()-1].name.c_str());
|
s = vBrowser[mBrowser->GetChoice()-1].song;
|
||||||
break;
|
break;
|
||||||
case csSearcher:
|
case csSearcher:
|
||||||
s = *vSearched[mSearcher->GetChoice()-search_engine_static_option-1];
|
s = vSearched[mSearcher->GetChoice()-search_engine_static_option-1];
|
||||||
break;
|
break;
|
||||||
case csLibrary:
|
case csLibrary:
|
||||||
s = *vSongs[mLibSongs->GetChoice()-1];
|
s = vSongs[mLibSongs->GetChoice()-1];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.GetArtist() != UNKNOWN_ARTIST && s.GetTitle() != UNKNOWN_TITLE)
|
if (s->GetArtist() != UNKNOWN_ARTIST && s->GetTitle() != UNKNOWN_TITLE)
|
||||||
{
|
{
|
||||||
wPrev = wCurrent;
|
wPrev = wCurrent;
|
||||||
prev_screen = current_screen;
|
prev_screen = current_screen;
|
||||||
@@ -1639,8 +1634,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
sLyrics->WriteXY(0, 0, "Fetching lyrics...");
|
sLyrics->WriteXY(0, 0, "Fetching lyrics...");
|
||||||
sLyrics->Refresh();
|
sLyrics->Refresh();
|
||||||
sLyrics->Add("[b]" + s.GetArtist() + " - " + s.GetTitle() + "[/b]\n\n");
|
sLyrics->Add("[b]" + s->GetArtist() + " - " + s->GetTitle() + "[/b]\n\n");
|
||||||
sLyrics->Add(GetLyrics(s.GetArtist(), s.GetTitle()));
|
sLyrics->Add(GetLyrics(s->GetArtist(), s->GetTitle()));
|
||||||
sLyrics->Timeout(ncmpcpp_window_timeout);
|
sLyrics->Timeout(ncmpcpp_window_timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1656,7 +1651,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case KEY_TAB: //switch between playlist and browser
|
case KEY_TAB: // switch between playlist and browser
|
||||||
{
|
{
|
||||||
if (wCurrent == mPlaylist)
|
if (wCurrent == mPlaylist)
|
||||||
goto KEY_TAB_BROWSER_REDIRECT;
|
goto KEY_TAB_BROWSER_REDIRECT;
|
||||||
@@ -1779,12 +1774,11 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'q': case 'Q':
|
case 'q': case 'Q': // quit
|
||||||
main_exit = 1;
|
main_exit = 1;
|
||||||
default: continue;
|
default: continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mpd->Disconnect();
|
Mpd->Disconnect();
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
endwin();
|
endwin();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
|
|||||||
conf.header_visibility = true;
|
conf.header_visibility = true;
|
||||||
conf.statusbar_visibility = true;
|
conf.statusbar_visibility = true;
|
||||||
conf.set_window_title = true;
|
conf.set_window_title = true;
|
||||||
conf.mpd_connection_timeout = 60;
|
conf.mpd_connection_timeout = 15;
|
||||||
conf.crossfade_time = 5;
|
conf.crossfade_time = 5;
|
||||||
conf.playlist_disable_highlight_delay = 5;
|
conf.playlist_disable_highlight_delay = 5;
|
||||||
conf.message_delay_time = 4;
|
conf.message_delay_time = 4;
|
||||||
|
|||||||
@@ -22,8 +22,6 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
#define FOR_EACH_MPD_DATA(x) for (; (x); (x) = mpd_data_get_next(x))
|
|
||||||
|
|
||||||
extern MPDConnection *Mpd;
|
extern MPDConnection *Mpd;
|
||||||
|
|
||||||
extern ncmpcpp_config Config;
|
extern ncmpcpp_config Config;
|
||||||
@@ -447,12 +445,11 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *da
|
|||||||
wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, volume_state);
|
wHeader->WriteXY(wHeader->GetWidth()-volume_state.length(), 0, volume_state);
|
||||||
wHeader->SetColor(Config.header_color);
|
wHeader->SetColor(Config.header_color);
|
||||||
}
|
}
|
||||||
|
wCurrent->Refresh();
|
||||||
wFooter->Bold(0);
|
wFooter->Bold(0);
|
||||||
wFooter->GotoXY(sx, sy);
|
wFooter->GotoXY(sx, sy);
|
||||||
wFooter->Refresh();
|
wFooter->Refresh();
|
||||||
wFooter->AutoRefresh(1);
|
wFooter->AutoRefresh(1);
|
||||||
wFooter->EnableBB();
|
wFooter->EnableBB();
|
||||||
if (changed.SongID || changed.PlayerState)
|
|
||||||
wCurrent->Refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user