From 24c37eb5925d67d05cd626dfc18615bf485421e7 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 12 Mar 2009 17:30:25 +0100 Subject: [PATCH] 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. --- src/browser.cpp | 38 ++++--- src/libmpdclient.c | 2 +- src/libmpdclient.h | 2 +- src/media_library.cpp | 27 +++-- src/mpdpp.cpp | 214 ++++++++++++++-------------------------- src/mpdpp.h | 29 ++---- src/ncmpcpp.cpp | 94 +++++++++++------- src/playlist.cpp | 2 + src/playlist_editor.cpp | 16 ++- src/search_engine.cpp | 5 +- src/tag_editor.cpp | 3 +- 11 files changed, 202 insertions(+), 230 deletions(-) diff --git a/src/browser.cpp b/src/browser.cpp index 340d186a..35cd3df3 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -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()); diff --git a/src/libmpdclient.c b/src/libmpdclient.c index e141b636..1096400c 100644 --- a/src/libmpdclient.c +++ b/src/libmpdclient.c @@ -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; diff --git a/src/libmpdclient.h b/src/libmpdclient.h index 9834f659..19035e0a 100644 --- a/src/libmpdclient.h +++ b/src/libmpdclient.h @@ -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 diff --git a/src/media_library.cpp b/src/media_library.cpp index 985cbe1f..97d5b7d7 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -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); } } diff --git a/src/mpdpp.cpp b/src/mpdpp.cpp index 3188958e..ff31a376 100644 --- a/src/mpdpp.cpp +++ b/src/mpdpp.cpp @@ -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,7 +217,8 @@ void Connection::Execute(const string &command) const if (isConnected) { mpd_executeCommand(itsConnection, command.c_str()); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -232,7 +233,8 @@ void Connection::Play(int pos) const if (isConnected) { mpd_sendPlayCommand(itsConnection, pos); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -241,7 +243,8 @@ void Connection::PlayID(int id) const if (isConnected) { mpd_sendPlayIdCommand(itsConnection, id); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -250,7 +253,8 @@ void Connection::Pause() const if (isConnected) { mpd_sendPauseCommand(itsConnection, itsCurrentStatus->state != psPause); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -259,7 +263,8 @@ void Connection::Stop() const if (isConnected) { mpd_sendStopCommand(itsConnection); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -268,7 +273,8 @@ void Connection::Next() const if (isConnected) { mpd_sendNextCommand(itsConnection); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -277,7 +283,8 @@ void Connection::Prev() const if (isConnected) { mpd_sendPrevCommand(itsConnection); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -286,7 +293,8 @@ void Connection::Move(int from, int to) const if (isConnected) { mpd_sendMoveCommand(itsConnection, from, to); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -295,7 +303,8 @@ void Connection::Swap(int from, int to) const if (isConnected) { mpd_sendSwapCommand(itsConnection, from, to); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -304,7 +313,8 @@ void Connection::Seek(int where) const if (isConnected) { mpd_sendSeekCommand(itsConnection, itsCurrentStatus->song, where); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -313,7 +323,8 @@ void Connection::Shuffle() const if (isConnected) { mpd_sendShuffleCommand(itsConnection); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -322,7 +333,8 @@ void Connection::ClearPlaylist() const if (isConnected) { mpd_sendClearCommand(itsConnection); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -337,7 +349,8 @@ void Connection::AddToPlaylist(const string &path, const string &file) const if (isConnected) { mpd_sendPlaylistAddCommand(itsConnection, (char *) path.c_str(), (char *) file.c_str()); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -346,7 +359,8 @@ void Connection::Move(const string &path, int from, int to) const if (isConnected) { mpd_sendPlaylistMoveCommand(itsConnection, (char *) path.c_str(), from, to); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -355,7 +369,8 @@ void Connection::Rename(const string &from, const string &to) const if (isConnected) { mpd_sendRenameCommand(itsConnection, from.c_str(), to.c_str()); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -453,7 +468,8 @@ void Connection::SetRepeat(bool mode) const if (isConnected) { mpd_sendRepeatCommand(itsConnection, mode); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -462,7 +478,8 @@ void Connection::SetRandom(bool mode) const if (isConnected) { mpd_sendRandomCommand(itsConnection, mode); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -471,7 +488,8 @@ void Connection::SetVolume(int vol) const if (isConnected) { mpd_sendSetvolCommand(itsConnection, vol); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -480,7 +498,8 @@ void Connection::SetCrossfade(int crossfade) const if (isConnected) { mpd_sendCrossfadeCommand(itsConnection, crossfade); - mpd_finishCommand(itsConnection); + 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()); - mpd_finishCommand(itsConnection); - UpdateStatus(); + if (!isCommandsListEnabled) + { + mpd_finishCommand(itsConnection); + UpdateStatus(); + } + else + id = 0; } - else - if (itsErrorHandler) + 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::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,7 +588,8 @@ void Connection::DeletePlaylist(const string &name) const if (isConnected) { mpd_sendRmCommand(itsConnection, name.c_str()); - mpd_finishCommand(itsConnection); + if (!isCommandsListEnabled) + mpd_finishCommand(itsConnection); } } @@ -888,13 +827,6 @@ int Connection::CheckForErrors() return itsErrorCode; } -void Connection::ClearQueue() -{ - for (std::vector::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++) diff --git a/src/mpdpp.h b/src/mpdpp.h index b3501eb9..76f988a7 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -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 itsQueue; }; } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 01997dd4..a344b9b4 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -442,11 +442,13 @@ int main(int argc, char *argv[]) { vector list; myPlaylist->Main()->GetSelected(list); - for (vector::const_reverse_iterator it = list.rbegin(); it != ((const vector &)list).rend(); it++) + Mpd->StartCommandsList(); + for (vector::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 list; myPlaylistEditor->Content->GetSelected(list); locale_to_utf(myPlaylistEditor->Playlists->Current()); - for (vector::const_reverse_iterator it = list.rbegin(); it != ((const vector &)list).rend(); it++) + Mpd->StartCommandsList(); + for (vector::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::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::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 diff --git a/src/playlist.cpp b/src/playlist.cpp index 4b33a1c9..fdd1ee99 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -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!"); } diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index b93e30d5..1d167eb3 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -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); } } diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 5d8b4429..710a4aa7 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -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 diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index bcf6306c..e279a378 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -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) {