do not store commands list in MPD::Connection

it should have sent commandlist begin and end commands from the beginning,
having separated functions just to handle queueing commands was plainly ugly.
This commit is contained in:
Andrzej Rybczak
2009-03-12 17:30:25 +01:00
parent 8a4ee22b61
commit 24c37eb592
11 changed files with 202 additions and 230 deletions

View File

@@ -133,9 +133,14 @@ void Browser::EnterPressed()
{
SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = list.begin();
for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != list.begin())
{
ShowMessage("Loading and playing playlist %s...", item.name.c_str());
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
@@ -179,9 +184,14 @@ void Browser::SpacePressed()
SongList list;
Mpd->GetDirectoryRecursive(locale_to_utf_cpy(item.name), list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = list.begin();
for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != list.begin())
{
ShowMessage("Added folder: %s", item.name.c_str());
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
@@ -198,16 +208,17 @@ void Browser::SpacePressed()
{
Playlist::BlockUpdate = 1;
long long hash = w->Current().song->GetHash();
Mpd->StartCommandsList();
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
{
if (myPlaylist->Main()->at(i).GetHash() == hash)
{
Mpd->QueueDeleteSong(i);
Mpd->Delete(i);
myPlaylist->Main()->DeleteOption(i);
i--;
}
}
Mpd->CommitQueue();
Mpd->CommitCommandsList();
w->BoldOption(w->Choice(), 0);
}
else
@@ -225,9 +236,14 @@ void Browser::SpacePressed()
{
SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = list.begin();
for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != list.begin())
{
ShowMessage("Loading playlist %s...", item.name.c_str());
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());

View File

@@ -2066,7 +2066,7 @@ void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
}
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
char *playlist, int pos)
const char *playlist, int pos)
{
char *sPlaylist = mpd_sanitizeArg(playlist);
int len = strlen("playlistdelete")+2+strlen(sPlaylist)+3+INTLEN+3;

View File

@@ -673,7 +673,7 @@ void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
char *playlist, int from, int to);
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
char *playlist, int pos);
const char *playlist, int pos);
#ifdef __cplusplus
}
#endif

View File

@@ -336,9 +336,14 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
Mpd->StartSearch(1);
Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->Current()));
Mpd->CommitSearch(list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = list.begin();
for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != list.begin())
{
string tag_type = IntoStr(Config.media_lib_primary_tag);
ToLower(tag_type);
@@ -355,9 +360,14 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
}
else if (w == Albums)
{
for (size_t i = 0; i < Songs->Size(); i++)
Mpd->QueueAddSong(Songs->at(i));
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
size_t i = 0;
for (; i < Songs->Size(); i++)
if (Mpd->AddSong(Songs->at(i)) < 0)
break;
Mpd->CommitCommandsList();
if (i)
{
ShowMessage("Adding songs from album \"%s\"", Albums->Current().second.Album.c_str());
Song *s = &myPlaylist->Main()->at(myPlaylist->Main()->Size()-Songs->Size());
@@ -392,16 +402,17 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
else
{
Playlist::BlockUpdate = 1;
Mpd->StartCommandsList();
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
{
if (myPlaylist->Main()->at(i).GetHash() == hash)
{
Mpd->QueueDeleteSong(i);
Mpd->Delete(i);
myPlaylist->Main()->DeleteOption(i);
i--;
}
}
Mpd->CommitQueue();
Mpd->CommitCommandsList();
Songs->BoldOption(Songs->Choice(), 0);
}
}

View File

@@ -30,6 +30,7 @@ const char *MPD::Message::FullPlaylist = "Playlist is full!";
const char *MPD::Message::FunctionDisabledFilteringEnabled = "Function disabled due to enabled filtering in playlist";
Connection::Connection() : isConnected(0),
isCommandsListEnabled(0),
itsErrorCode(0),
itsMaxPlaylistLength(-1),
itsHost("localhost"),
@@ -57,7 +58,6 @@ Connection::~Connection()
mpd_freeStatus(itsOldStatus);
if (itsCurrentStatus)
mpd_freeStatus(itsCurrentStatus);
ClearQueue();
}
bool Connection::Connect()
@@ -99,8 +99,8 @@ void Connection::Disconnect()
itsCurrentStatus = 0;
itsOldStatus = 0;
isConnected = 0;
isCommandsListEnabled = 0;
itsMaxPlaylistLength = -1;
ClearQueue();
}
float Connection::Version() const
@@ -217,6 +217,7 @@ void Connection::Execute(const string &command) const
if (isConnected)
{
mpd_executeCommand(itsConnection, command.c_str());
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -232,6 +233,7 @@ void Connection::Play(int pos) const
if (isConnected)
{
mpd_sendPlayCommand(itsConnection, pos);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -241,6 +243,7 @@ void Connection::PlayID(int id) const
if (isConnected)
{
mpd_sendPlayIdCommand(itsConnection, id);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -250,6 +253,7 @@ void Connection::Pause() const
if (isConnected)
{
mpd_sendPauseCommand(itsConnection, itsCurrentStatus->state != psPause);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -259,6 +263,7 @@ void Connection::Stop() const
if (isConnected)
{
mpd_sendStopCommand(itsConnection);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -268,6 +273,7 @@ void Connection::Next() const
if (isConnected)
{
mpd_sendNextCommand(itsConnection);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -277,6 +283,7 @@ void Connection::Prev() const
if (isConnected)
{
mpd_sendPrevCommand(itsConnection);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -286,6 +293,7 @@ void Connection::Move(int from, int to) const
if (isConnected)
{
mpd_sendMoveCommand(itsConnection, from, to);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -295,6 +303,7 @@ void Connection::Swap(int from, int to) const
if (isConnected)
{
mpd_sendSwapCommand(itsConnection, from, to);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -304,6 +313,7 @@ void Connection::Seek(int where) const
if (isConnected)
{
mpd_sendSeekCommand(itsConnection, itsCurrentStatus->song, where);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -313,6 +323,7 @@ void Connection::Shuffle() const
if (isConnected)
{
mpd_sendShuffleCommand(itsConnection);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -322,6 +333,7 @@ void Connection::ClearPlaylist() const
if (isConnected)
{
mpd_sendClearCommand(itsConnection);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -337,6 +349,7 @@ void Connection::AddToPlaylist(const string &path, const string &file) const
if (isConnected)
{
mpd_sendPlaylistAddCommand(itsConnection, (char *) path.c_str(), (char *) file.c_str());
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -346,6 +359,7 @@ void Connection::Move(const string &path, int from, int to) const
if (isConnected)
{
mpd_sendPlaylistMoveCommand(itsConnection, (char *) path.c_str(), from, to);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -355,6 +369,7 @@ void Connection::Rename(const string &from, const string &to) const
if (isConnected)
{
mpd_sendRenameCommand(itsConnection, from.c_str(), to.c_str());
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -453,6 +468,7 @@ void Connection::SetRepeat(bool mode) const
if (isConnected)
{
mpd_sendRepeatCommand(itsConnection, mode);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -462,6 +478,7 @@ void Connection::SetRandom(bool mode) const
if (isConnected)
{
mpd_sendRandomCommand(itsConnection, mode);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -471,6 +488,7 @@ void Connection::SetVolume(int vol) const
if (isConnected)
{
mpd_sendSetvolCommand(itsConnection, vol);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -480,6 +498,7 @@ void Connection::SetCrossfade(int crossfade) const
if (isConnected)
{
mpd_sendCrossfadeCommand(itsConnection, crossfade);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -492,11 +511,15 @@ int Connection::AddSong(const string &path)
if (GetPlaylistLength() < itsMaxPlaylistLength)
{
id = mpd_sendAddIdCommand(itsConnection, path.c_str());
if (!isCommandsListEnabled)
{
mpd_finishCommand(itsConnection);
UpdateStatus();
}
else
if (itsErrorHandler)
id = 0;
}
else if (itsErrorHandler)
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, Message::FullPlaylist, NULL);
}
return id;
@@ -507,142 +530,57 @@ int Connection::AddSong(const Song &s)
return !s.Empty() ? (AddSong((!s.IsFromDB() ? "file://" : "") + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()))) : -1;
}
void Connection::QueueAddSong(const string &path)
{
if (isConnected && GetPlaylistLength() < itsMaxPlaylistLength)
{
QueueCommand *q = new QueueCommand;
q->type = qctAdd;
q->item_path = path;
itsQueue.push_back(q);
}
}
void Connection::QueueAddSong(const Song &s)
{
if (!s.Empty())
QueueAddSong((!s.IsFromDB() ? "file://" : "") + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()));
}
void Connection::QueueAddToPlaylist(const string &playlist, const string &path)
void Connection::Delete(int pos) const
{
if (isConnected)
{
QueueCommand *q = new QueueCommand;
q->type = qctAddToPlaylist;
q->playlist_path = playlist;
q->item_path = path;
itsQueue.push_back(q);
mpd_sendDeleteCommand(itsConnection, pos);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
void Connection::QueueAddToPlaylist(const string &playlist, const Song &s)
{
if (!s.Empty())
QueueAddToPlaylist(playlist, s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile());
}
void Connection::QueueDeleteSong(int id)
void Connection::DeleteID(int id) const
{
if (isConnected)
{
QueueCommand *q = new QueueCommand;
q->type = qctDelete;
q->id = id;
itsQueue.push_back(q);
mpd_sendDeleteIdCommand(itsConnection, id);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
void Connection::QueueDeleteSongId(int id)
void Connection::Delete(const string &playlist, int pos) const
{
if (isConnected)
{
QueueCommand *q = new QueueCommand;
q->type = qctDeleteID;
q->id = id;
itsQueue.push_back(q);
mpd_sendPlaylistDeleteCommand(itsConnection, playlist.c_str(), pos);
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
void Connection::QueueMove(int from, int to)
void Connection::StartCommandsList()
{
if (isConnected)
{
QueueCommand *q = new QueueCommand;
q->type = qctMove;
q->id = from;
q->id2 = to;
itsQueue.push_back(q);
}
}
void Connection::QueueMove(const string &playlist, int from, int to)
{
if (isConnected)
{
QueueCommand *q = new QueueCommand;
q->type = qctPlaylistMove;
q->playlist_path = playlist;
q->id = from;
q->id2 = to;
itsQueue.push_back(q);
}
}
void Connection::QueueDeleteFromPlaylist(const string &playlist, int pos)
{
if (isConnected)
{
QueueCommand *q = new QueueCommand;
q->type = qctDeleteFromPlaylist;
q->playlist_path = playlist;
q->id = pos;
itsQueue.push_back(q);
}
}
bool Connection::CommitQueue()
{
bool retval = false;
if (isConnected)
{
mpd_sendCommandListBegin(itsConnection);
for (std::vector<QueueCommand *>::const_iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
{
switch ((*it)->type)
{
case qctAdd:
mpd_sendAddCommand(itsConnection, (*it)->item_path.c_str());
break;
case qctAddToPlaylist:
mpd_sendPlaylistAddCommand(itsConnection, (char *) (*it)->playlist_path.c_str(), (char *) (*it)->item_path.c_str());
break;
case qctDelete:
mpd_sendDeleteCommand(itsConnection, (*it)->id);
break;
case qctDeleteID:
mpd_sendDeleteIdCommand(itsConnection, (*it)->id);
break;
case qctMove:
mpd_sendMoveCommand(itsConnection, (*it)->id, (*it)->id2);
break;
case qctPlaylistMove:
mpd_sendPlaylistMoveCommand(itsConnection, (char *) (*it)->playlist_path.c_str(), (*it)->id, (*it)->id2);
break;
case qctDeleteFromPlaylist:
mpd_sendPlaylistDeleteCommand(itsConnection, (char *) (*it)->playlist_path.c_str(), (*it)->id);
break;
}
isCommandsListEnabled = 1;
}
}
void Connection::CommitCommandsList()
{
if (isConnected)
{
mpd_sendCommandListEnd(itsConnection);
mpd_finishCommand(itsConnection);
UpdateStatus();
if (GetPlaylistLength() == itsMaxPlaylistLength && itsErrorHandler)
itsErrorHandler(this, MPD_ACK_ERROR_PLAYLIST_MAX, Message::FullPlaylist, NULL);
retval = !itsQueue.empty();
isCommandsListEnabled = 0;
}
ClearQueue();
return retval;
}
void Connection::DeletePlaylist(const string &name) const
@@ -650,6 +588,7 @@ void Connection::DeletePlaylist(const string &name) const
if (isConnected)
{
mpd_sendRmCommand(itsConnection, name.c_str());
if (!isCommandsListEnabled)
mpd_finishCommand(itsConnection);
}
}
@@ -888,13 +827,6 @@ int Connection::CheckForErrors()
return itsErrorCode;
}
void Connection::ClearQueue()
{
for (std::vector<QueueCommand *>::iterator it = itsQueue.begin(); it != itsQueue.end(); it++)
delete *it;
itsQueue.clear();
}
void MPD::FreeSongList(SongList &l)
{
for (SongList::iterator i = l.begin(); i != l.end(); i++)

View File

@@ -35,7 +35,6 @@ namespace MPD
extern const char *FunctionDisabledFilteringEnabled;
}
enum QueueCommandType { qctAdd, qctAddToPlaylist, qctDelete, qctDeleteID, qctMove, qctPlaylistMove, qctDeleteFromPlaylist };
enum ItemType { itDirectory, itSong, itPlaylist };
enum PlayerState { psUnknown, psStop, psPlay, psPause };
@@ -72,16 +71,6 @@ namespace MPD
class Connection
{
struct QueueCommand
{
QueueCommand() : id(0), id2(0) { }
QueueCommandType type;
std::string playlist_path;
std::string item_path;
int id;
int id2;
};
typedef void (*StatusUpdater) (Connection *, StatusChanges, void *);
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
@@ -153,16 +142,11 @@ namespace MPD
int AddSong(const std::string &); // returns id of added song
int AddSong(const Song &); // returns id of added song
void QueueAddSong(const std::string &);
void QueueAddSong(const Song &);
void QueueAddToPlaylist(const std::string &, const std::string &);
void QueueAddToPlaylist(const std::string &, const Song &);
void QueueDeleteSong(int);
void QueueDeleteSongId(int);
void QueueMove(int, int);
void QueueMove(const std::string &, int, int);
void QueueDeleteFromPlaylist(const std::string &, int);
bool CommitQueue();
void Delete(int) const;
void DeleteID(int) const;
void Delete(const std::string &, int) const;
void StartCommandsList();
void CommitCommandsList();
void DeletePlaylist(const std::string &) const;
bool SavePlaylist(const std::string &) const;
@@ -187,11 +171,11 @@ namespace MPD
void GetDirectories(const std::string &, TagList &) const;
private:
void ClearQueue();
int CheckForErrors();
mpd_Connection *itsConnection;
bool isConnected;
bool isCommandsListEnabled;
std::string itsErrorMessage;
int itsErrorCode;
@@ -215,7 +199,6 @@ namespace MPD
void *itsErrorHandlerUserdata;
mpd_TagItems itsSearchedField;
std::vector<QueueCommand *> itsQueue;
};
}

View File

@@ -442,11 +442,13 @@ int main(int argc, char *argv[])
{
vector<size_t> list;
myPlaylist->Main()->GetSelected(list);
for (vector<size_t>::const_reverse_iterator it = list.rbegin(); it != ((const vector<size_t> &)list).rend(); it++)
Mpd->StartCommandsList();
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{
Mpd->QueueDeleteSongId((*myPlaylist->Main())[*it].GetID());
Mpd->DeleteID((*myPlaylist->Main())[*it].GetID());
myPlaylist->Main()->DeleteOption(*it);
}
Mpd->CommitCommandsList();
myPlaylist->FixPositions(list.front());
ShowMessage("Selected items deleted!");
}
@@ -461,7 +463,7 @@ int main(int argc, char *argv[])
time(&Timer);
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()) // needed for keeping proper
myPlaylist->NowPlaying--; // position of now playing song.
Mpd->QueueDeleteSongId(myPlaylist->CurrentSong()->GetID());
Mpd->DeleteID(myPlaylist->CurrentSong()->GetID());
myPlaylist->Main()->DeleteOption(id);
myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input);
@@ -470,7 +472,6 @@ int main(int argc, char *argv[])
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
Playlist::BlockNowPlayingUpdate = 0;
}
Mpd->CommitQueue();
}
else if (myScreen == myBrowser || myScreen->Cmp() == myPlaylistEditor->Playlists)
{
@@ -508,11 +509,13 @@ int main(int argc, char *argv[])
vector<size_t> list;
myPlaylistEditor->Content->GetSelected(list);
locale_to_utf(myPlaylistEditor->Playlists->Current());
for (vector<size_t>::const_reverse_iterator it = list.rbegin(); it != ((const vector<size_t> &)list).rend(); it++)
Mpd->StartCommandsList();
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->Playlists->Current(), *it);
Mpd->Delete(myPlaylistEditor->Playlists->Current(), *it);
myPlaylistEditor->Content->DeleteOption(*it);
}
Mpd->CommitCommandsList();
utf_to_locale(myPlaylistEditor->Playlists->Current());
ShowMessage("Selected items deleted from playlist '%s'!", myPlaylistEditor->Playlists->Current().c_str());
}
@@ -524,7 +527,7 @@ int main(int argc, char *argv[])
{
TraceMpdStatus();
time(&Timer);
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice());
Mpd->Delete(myPlaylistEditor->Playlists->Current(), myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
@@ -532,7 +535,6 @@ int main(int argc, char *argv[])
utf_to_locale(myPlaylistEditor->Playlists->Current());
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
Mpd->CommitQueue();
}
}
else if (Keypressed(input, Key.Prev))
@@ -639,9 +641,10 @@ int main(int argc, char *argv[])
myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input);
}
Mpd->StartCommandsList();
for (size_t i = 0; i < list.size(); i++)
Mpd->QueueMove(origs[i], list[i]);
Mpd->CommitQueue();
Mpd->Move(origs[i], list[i]);
Mpd->CommitCommandsList();
}
else
{
@@ -689,10 +692,11 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
Mpd->StartCommandsList();
for (size_t i = 0; i < list.size(); i++)
if (origs[i] != list[i])
Mpd->QueueMove(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitQueue();
Mpd->Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitCommandsList();
}
else
{
@@ -752,9 +756,10 @@ int main(int argc, char *argv[])
myPlaylist->Main()->Refresh();
myPlaylist->Main()->ReadKey(input);
}
Mpd->StartCommandsList();
for (int i = list.size()-1; i >= 0; i--)
Mpd->QueueMove(origs[i], list[i]);
Mpd->CommitQueue();
Mpd->Move(origs[i], list[i]);
Mpd->CommitCommandsList();
}
else
{
@@ -803,10 +808,11 @@ int main(int argc, char *argv[])
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
Mpd->StartCommandsList();
for (int i = list.size()-1; i >= 0; i--)
if (origs[i] != list[i])
Mpd->QueueMove(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitQueue();
Mpd->Move(myPlaylistEditor->Playlists->Current(), origs[i], list[i]);
Mpd->CommitCommandsList();
}
else
{
@@ -850,13 +856,14 @@ int main(int argc, char *argv[])
if (pos >= list.front() && pos <= list.back())
continue;
int diff = pos-list.front();
Mpd->StartCommandsList();
if (diff > 0)
{
pos -= list.size();
size_t i = list.size()-1;
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++, i--)
{
Mpd->QueueMove(*it, pos+i);
Mpd->Move(*it, pos+i);
myPlaylist->Main()->Move(*it, pos+i);
}
}
@@ -865,11 +872,11 @@ int main(int argc, char *argv[])
size_t i = 0;
for (vector<size_t>::const_iterator it = list.begin(); it != list.end(); it++, i++)
{
Mpd->QueueMove(*it, pos+i);
Mpd->Move(*it, pos+i);
myPlaylist->Main()->Move(*it, pos+i);
}
}
Mpd->CommitQueue();
Mpd->CommitCommandsList();
myPlaylist->Main()->Highlight(pos);
myPlaylist->FixPositions();
}
@@ -885,9 +892,14 @@ int main(int argc, char *argv[])
Mpd->GetDirectoryRecursive(path, list);
if (!list.empty())
{
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = list.begin();
for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != list.begin())
{
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
if (s.GetHash() != list[0]->GetHash())
@@ -1388,9 +1400,14 @@ int main(int argc, char *argv[])
if (id == 0)
{
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = result.begin();
for (; it != result.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != result.begin())
{
ShowMessage("Selected items added!");
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-result.size());
@@ -1408,18 +1425,20 @@ int main(int argc, char *argv[])
UnlockStatusbar();
if (!playlist.empty())
{
Mpd->StartCommandsList();
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
Mpd->QueueAddToPlaylist(real_playlist, **it);
Mpd->CommitQueue();
Mpd->AddToPlaylist(real_playlist, **it);
Mpd->CommitCommandsList();
ShowMessage("Selected items added to playlist '%s'!", playlist.c_str());
}
}
else if (id > 1 && id < mDialog.Size()-1)
{
locale_to_utf(playlists[id-3]);
Mpd->StartCommandsList();
for (SongList::const_iterator it = result.begin(); it != result.end(); it++)
Mpd->QueueAddToPlaylist(playlists[id-3], **it);
Mpd->CommitQueue();
Mpd->AddToPlaylist(playlists[id-3], **it);
Mpd->CommitCommandsList();
utf_to_locale(playlists[id-3]);
ShowMessage("Selected items added to playlist '%s'!", playlists[id-3].c_str());
}
@@ -1443,18 +1462,19 @@ int main(int argc, char *argv[])
}
if (myPlaylist->Main()->hasSelected())
{
Mpd->StartCommandsList();
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
{
if (!myPlaylist->Main()->isSelected(i) && i != myPlaylist->NowPlaying)
Mpd->QueueDeleteSong(i);
Mpd->Delete(i);
}
// 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 (myPlaylist->isPlaying() && !myPlaylist->Main()->isSelected(myPlaylist->NowPlaying))
Mpd->QueueDeleteSongId(myPlaylist->NowPlayingSong()->GetID());
Mpd->DeleteID(myPlaylist->NowPlayingSong()->GetID());
ShowMessage("Deleting all items but selected...");
Mpd->CommitQueue();
Mpd->CommitCommandsList();
ShowMessage("Items deleted!");
}
else
@@ -1464,11 +1484,12 @@ int main(int argc, char *argv[])
ShowMessage("Nothing is playing now!");
continue;
}
Mpd->StartCommandsList();
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
if (i != myPlaylist->NowPlaying)
Mpd->QueueDeleteSong(i);
Mpd->Delete(i);
ShowMessage("Deleting all items except now playing one...");
Mpd->CommitQueue();
Mpd->CommitCommandsList();
ShowMessage("Items deleted!");
}
}
@@ -1477,9 +1498,10 @@ int main(int argc, char *argv[])
if (myPlaylist->Main()->isFiltered())
{
ShowMessage("Deleting filtered items...");
Mpd->StartCommandsList();
for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
Mpd->QueueDeleteSong((*myPlaylist->Main())[i].GetPosition());
Mpd->CommitQueue();
Mpd->Delete((*myPlaylist->Main())[i].GetPosition());
Mpd->CommitCommandsList();
ShowMessage("Filtered items deleted!");
}
else

View File

@@ -243,6 +243,7 @@ void Playlist::Sort()
BlockUpdate = 1;
ShowMessage("Sorting playlist...");
Mpd->StartCommandsList();
do
{
for (size_t i = 0; i < playlist.size(); i++)
@@ -257,6 +258,7 @@ void Playlist::Sort()
}
}
while (playlist != cmp);
Mpd->CommitCommandsList();
ShowMessage("Playlist sorted!");
}

View File

@@ -192,9 +192,14 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
if (w == Playlists && !Playlists->Empty())
{
Mpd->GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
Mpd->StartCommandsList();
SongList::const_iterator it = list.begin();
for (; it != list.end(); it++)
if (Mpd->AddSong(**it) < 0)
break;
Mpd->CommitCommandsList();
if (it != list.begin())
{
ShowMessage("Loading playlist %s...", Playlists->Current().c_str());
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
@@ -229,16 +234,17 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
else
{
Playlist::BlockUpdate = 1;
Mpd->StartCommandsList();
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
{
if (myPlaylist->Main()->at(i).GetHash() == hash)
{
Mpd->QueueDeleteSong(i);
Mpd->Delete(i);
myPlaylist->Main()->DeleteOption(i);
i--;
}
}
Mpd->CommitQueue();
Mpd->CommitCommandsList();
Content->BoldOption(Content->Choice(), 0);
}
}

View File

@@ -268,16 +268,17 @@ void SearchEngine::SpacePressed()
{
Playlist::BlockUpdate = 1;
long long hash = w->Current().second->GetHash();
Mpd->StartCommandsList();
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
{
if (myPlaylist->Main()->at(i).GetHash() == hash)
{
Mpd->QueueDeleteSong(i);
Mpd->Delete(i);
myPlaylist->Main()->DeleteOption(i);
i--;
}
}
Mpd->CommitQueue();
Mpd->CommitCommandsList();
w->BoldOption(w->Choice(), 0);
}
else

View File

@@ -902,8 +902,7 @@ bool TagEditor::WriteTags(Song &s)
// if we rename local file, it won't get updated
// so just remove it from playlist and add again
size_t pos = myPlaylist->Main()->Choice();
Mpd->QueueDeleteSong(pos);
Mpd->CommitQueue();
Mpd->Delete(pos);
int id = Mpd->AddSong("file://" + new_name);
if (id >= 0)
{