get rid of Playlist::PlayNewlyAddedSongs / correct adding songs in Media Library
This commit is contained in:
@@ -126,9 +126,10 @@ void Browser::enterPressed()
|
||||
}
|
||||
case itPlaylist:
|
||||
{
|
||||
Mpd.LoadPlaylist(item.name);
|
||||
MPD::SongList list;
|
||||
Mpd.GetPlaylistContentNoInfo(item.name, vectorMoveInserter(list));
|
||||
addSongsToPlaylist(list.begin(), list.end(), true, -1);
|
||||
Statusbar::msg("Playlist \"%s\" loaded", item.name.c_str());
|
||||
myPlaylist->PlayNewlyAddedSongs();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,7 +167,7 @@ void Browser::spacePressed()
|
||||
list.reserve(items.size());
|
||||
for (MPD::ItemList::const_iterator it = items.begin(); it != items.end(); ++it)
|
||||
list.push_back(*it->song);
|
||||
addSongsToPlaylist(list, false, -1);
|
||||
addSongsToPlaylist(list.begin(), list.end(), false, -1);
|
||||
}
|
||||
else
|
||||
# endif // !WIN32
|
||||
|
||||
@@ -63,34 +63,6 @@ bool addSongToPlaylist(const MPD::Song &s, bool play, int position)
|
||||
return result;
|
||||
}
|
||||
|
||||
void addSongsToPlaylist(const MPD::SongList &list, bool play, int position)
|
||||
{
|
||||
if (list.size() >= 1)
|
||||
{
|
||||
int id = Mpd.AddSong(list.front(), position);
|
||||
if (id > 0)
|
||||
{
|
||||
Mpd.StartCommandsList();
|
||||
if (position == -1)
|
||||
{
|
||||
for (auto s = list.begin()+1; s != list.end(); ++s)
|
||||
if (Mpd.AddSong(*s) < 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto end = list.rend()-1;
|
||||
for (auto s = list.rbegin(); s != end; ++s)
|
||||
if (Mpd.AddSong(*s, position) < 0)
|
||||
break;
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
if (play)
|
||||
Mpd.PlayID(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Timestamp(time_t t)
|
||||
{
|
||||
char result[32];
|
||||
|
||||
@@ -485,8 +485,38 @@ template <typename BufferT> void ShowTag(BufferT &buf, const std::string &tag)
|
||||
buf << tag;
|
||||
}
|
||||
|
||||
template <typename SongIterator>
|
||||
void addSongsToPlaylist(SongIterator first, SongIterator last, bool play, int position)
|
||||
{
|
||||
if (last-first >= 1)
|
||||
{
|
||||
int id = Mpd.AddSong(*first, position);
|
||||
if (id > 0)
|
||||
{
|
||||
Mpd.StartCommandsList();
|
||||
if (position == -1)
|
||||
{
|
||||
++first;
|
||||
for(; first != last; ++first)
|
||||
if (Mpd.AddSong(*first) < 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
++position;
|
||||
--last;
|
||||
for (; first != last; --last)
|
||||
if (Mpd.AddSong(*last, position) < 0)
|
||||
break;
|
||||
}
|
||||
Mpd.CommitCommandsList();
|
||||
if (play)
|
||||
Mpd.PlayID(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool addSongToPlaylist(const MPD::Song &s, bool play, int position = -1);
|
||||
void addSongsToPlaylist(const MPD::SongList &list, bool play, int position = -1);
|
||||
|
||||
std::string Timestamp(time_t t);
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ void MediaLibrary::spacePressed()
|
||||
}
|
||||
}
|
||||
else
|
||||
AddToPlaylist(0);
|
||||
AddToPlaylist(false);
|
||||
}
|
||||
|
||||
void MediaLibrary::mouseButtonPressed(MEVENT me)
|
||||
@@ -716,19 +716,27 @@ MPD::SongList MediaLibrary::getSelectedSongs()
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, tag);
|
||||
Mpd.CommitSearchSongs(vectorMoveInserter(result));
|
||||
};
|
||||
for (auto it = Tags.begin(); it != Tags.end(); ++it)
|
||||
if (it->isSelected())
|
||||
tag_handler(it->value().tag());
|
||||
bool any_selected = false;
|
||||
for (auto &e : Tags)
|
||||
{
|
||||
if (e.isSelected())
|
||||
{
|
||||
any_selected = true;
|
||||
tag_handler(e.value().tag());
|
||||
}
|
||||
}
|
||||
// if no item is selected, add current one
|
||||
if (result.empty() && !Tags.empty())
|
||||
if (!any_selected && !Tags.empty())
|
||||
tag_handler(Tags.current().value().tag());
|
||||
}
|
||||
else if (isActiveWindow(Albums))
|
||||
{
|
||||
bool any_selected = false;
|
||||
for (auto it = Albums.begin(); it != Albums.end() && !it->isSeparator(); ++it)
|
||||
{
|
||||
if (it->isSelected())
|
||||
{
|
||||
any_selected = true;
|
||||
auto &sc = it->value();
|
||||
Mpd.StartSearch(true);
|
||||
if (hasTwoColumns)
|
||||
@@ -744,7 +752,7 @@ MPD::SongList MediaLibrary::getSelectedSongs()
|
||||
}
|
||||
}
|
||||
// if no item is selected, add songs from right column
|
||||
if (result.empty() && !Albums.empty())
|
||||
if (!any_selected && !Albums.empty())
|
||||
{
|
||||
withUnfilteredMenu(Songs, [this, &result]() {
|
||||
result.insert(result.end(), Songs.beginV(), Songs.endV());
|
||||
@@ -990,19 +998,28 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
|
||||
addSongToPlaylist(Songs.current().value(), add_n_play);
|
||||
else
|
||||
{
|
||||
addSongsToPlaylist(getSelectedSongs(), add_n_play);
|
||||
if ((!Tags.empty() && isActiveWindow(Tags))
|
||||
|| (isActiveWindow(Albums) && Albums.current().value().isAllTracksEntry()))
|
||||
{
|
||||
MPD::SongList list;
|
||||
Mpd.StartSearch(true);
|
||||
Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current().value().tag());
|
||||
Mpd.CommitSearchSongs(vectorMoveInserter(list));
|
||||
addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1);
|
||||
std::string tag_type = boost::locale::to_lower(
|
||||
tagTypeToString(Config.media_lib_primary_tag));
|
||||
Statusbar::msg("Songs with %s = \"%s\" added",
|
||||
tag_type.c_str(), Tags.current().value().tag().c_str());
|
||||
}
|
||||
else if (isActiveWindow(Albums))
|
||||
{
|
||||
withUnfilteredMenu(Songs, [&]() {
|
||||
addSongsToPlaylist(Songs.beginV(), Songs.endV(), add_n_play, -1);
|
||||
});
|
||||
Statusbar::msg("Songs from album \"%s\" added",
|
||||
Albums.current().value().entry().album().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (!add_n_play)
|
||||
{
|
||||
|
||||
@@ -493,6 +493,16 @@ void Connection::GetPlaylistContent(const std::string &path, SongConsumer f)
|
||||
checkErrors();
|
||||
}
|
||||
|
||||
void Connection::GetPlaylistContentNoInfo(const std::string &path, SongConsumer f)
|
||||
{
|
||||
prechecksNoCommandsList();
|
||||
mpd_send_list_playlist(m_connection, path.c_str());
|
||||
while (mpd_song *s = mpd_recv_song(m_connection))
|
||||
f(Song(s));
|
||||
mpd_response_finish(m_connection);
|
||||
checkErrors();
|
||||
}
|
||||
|
||||
void Connection::GetSupportedExtensions(std::set<std::string> &acc)
|
||||
{
|
||||
prechecksNoCommandsList();
|
||||
|
||||
@@ -198,6 +198,7 @@ public:
|
||||
Song GetCurrentlyPlayingSong();
|
||||
Song GetSong(const std::string &);
|
||||
void GetPlaylistContent(const std::string &name, SongConsumer f);
|
||||
void GetPlaylistContentNoInfo(const std::string &name, SongConsumer f);
|
||||
|
||||
void GetSupportedExtensions(std::set<std::string> &);
|
||||
|
||||
|
||||
@@ -313,19 +313,6 @@ std::string Playlist::TotalLength()
|
||||
return result.str();
|
||||
}
|
||||
|
||||
void Playlist::PlayNewlyAddedSongs()
|
||||
{
|
||||
// FIXME for removal
|
||||
bool is_filtered = w.isFiltered();
|
||||
w.showAll();
|
||||
size_t old_size = w.size();
|
||||
//Mpd.UpdateStatus();
|
||||
if (old_size < w.size())
|
||||
Mpd.Play(old_size);
|
||||
if (is_filtered)
|
||||
w.showFiltered();
|
||||
}
|
||||
|
||||
void Playlist::SetSelectedItemsPriority(int prio)
|
||||
{
|
||||
auto list = getSelectedOrCurrent(w.begin(), w.end(), w.currentI());
|
||||
|
||||
@@ -74,8 +74,6 @@ struct Playlist: Screen<NC::Menu<MPD::Song>>, Filterable, HasSongs, Searchable,
|
||||
void UpdateTimer();
|
||||
time_t Timer() const { return itsTimer; }
|
||||
|
||||
void PlayNewlyAddedSongs();
|
||||
|
||||
void SetSelectedItemsPriority(int prio);
|
||||
|
||||
void setStatus(MPD::Status status);
|
||||
|
||||
@@ -221,10 +221,10 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
|
||||
|
||||
if (isActiveWindow(Playlists) && !Playlists.empty())
|
||||
{
|
||||
Mpd.LoadPlaylist(Playlists.current().value());
|
||||
withUnfilteredMenu(Content, [&]() {
|
||||
addSongsToPlaylist(Content.beginV(), Content.endV(), add_n_play, -1);
|
||||
});
|
||||
Statusbar::msg("Playlist \"%s\" loaded", Playlists.current().value().c_str());
|
||||
if (add_n_play)
|
||||
myPlaylist->PlayNewlyAddedSongs();
|
||||
}
|
||||
else if (isActiveWindow(Content) && !Content.empty())
|
||||
addSongToPlaylist(Content.current().value(), add_n_play);
|
||||
@@ -454,16 +454,15 @@ MPD::SongList PlaylistEditor::getSelectedSongs()
|
||||
if (isActiveWindow(Playlists))
|
||||
{
|
||||
bool any_selected = false;
|
||||
for (auto it = Playlists.begin(); it != Playlists.end(); ++it)
|
||||
for (auto &e : Playlists)
|
||||
{
|
||||
if (it->isSelected())
|
||||
if (e.isSelected())
|
||||
{
|
||||
any_selected = true;
|
||||
Mpd.GetPlaylistContent(it->value(), vectorMoveInserter(result));
|
||||
Mpd.GetPlaylistContent(e.value(), vectorMoveInserter(result));
|
||||
}
|
||||
}
|
||||
// we don't check for empty result here as it's possible that
|
||||
// all selected playlists are empty.
|
||||
// if no item is selected, add songs from right column
|
||||
if (!any_selected && !Content.empty())
|
||||
{
|
||||
withUnfilteredMenu(Content, [this, &result]() {
|
||||
@@ -473,9 +472,9 @@ MPD::SongList PlaylistEditor::getSelectedSongs()
|
||||
}
|
||||
else if (isActiveWindow(Content))
|
||||
{
|
||||
for (auto it = Content.begin(); it != Content.end(); ++it)
|
||||
if (it->isSelected())
|
||||
result.push_back(it->value());
|
||||
for (auto &e : Content)
|
||||
if (e.isSelected())
|
||||
result.push_back(e.value());
|
||||
// if no item is selected, add current one
|
||||
if (result.empty() && !Content.empty())
|
||||
result.push_back(Content.current().value());
|
||||
|
||||
@@ -241,13 +241,13 @@ void SelectedItemsAdder::addToExistingPlaylist(const std::string &playlist) cons
|
||||
|
||||
void SelectedItemsAdder::addAtTheEndOfPlaylist() const
|
||||
{
|
||||
addSongsToPlaylist(m_selected_items, false);
|
||||
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, -1);
|
||||
exitSuccessfully();
|
||||
}
|
||||
|
||||
void SelectedItemsAdder::addAtTheBeginningOfPlaylist() const
|
||||
{
|
||||
addSongsToPlaylist(m_selected_items, false, 0);
|
||||
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, 0);
|
||||
exitSuccessfully();
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ void SelectedItemsAdder::addAfterCurrentSong() const
|
||||
return;
|
||||
size_t pos = myPlaylist->currentSongPosition();
|
||||
++pos;
|
||||
addSongsToPlaylist(m_selected_items, false, pos);
|
||||
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
|
||||
exitSuccessfully();
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ void SelectedItemsAdder::addAfterCurrentAlbum() const
|
||||
while (pos < pl.size() && pl[pos].value().getAlbum() == album)
|
||||
++pos;
|
||||
});
|
||||
addSongsToPlaylist(m_selected_items, false, pos);
|
||||
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
|
||||
exitSuccessfully();
|
||||
}
|
||||
|
||||
@@ -280,7 +280,7 @@ void SelectedItemsAdder::addAfterHighlightedSong() const
|
||||
{
|
||||
size_t pos = myPlaylist->main().current().value().getPosition();
|
||||
++pos;
|
||||
addSongsToPlaylist(m_selected_items, false, pos);
|
||||
addSongsToPlaylist(m_selected_items.begin(), m_selected_items.end(), false, pos);
|
||||
exitSuccessfully();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user