split PressSpace action into modular pieces

This commit is contained in:
Andrzej Rybczak
2015-05-17 18:10:42 +02:00
parent c68631b2f0
commit 2caf08aaa7
36 changed files with 306 additions and 275 deletions

1
NEWS
View File

@@ -24,6 +24,7 @@ ncmpcpp-0.7 (????-??-??)
* Support for Alt, Ctrl and Shift modifiers as well as Escape key was added.
* Action that updates the environment can now be used in bindings configuration file.
* Searching in text fields now respects regular expression configuration.
* Monolithic 'press_space' action was split into 'add_item_to_playlist', 'toggle_lyrics_update_on_song_change' and 'toggle_visualization_type'.
ncmpcpp-0.6.4 (2015-05-02)

View File

@@ -184,12 +184,18 @@
#def_key "insert"
# select_item
#
#def_key "space"
# press_space
#
#def_key "enter"
# press_enter
#
#def_key "space"
# add_item_to_playlist
#
#def_key "space"
# toggle_lyrics_update_on_song_change
#
#def_key "space"
# toggle_visualization_type
#
#def_key "delete"
# delete_playlist_items
#

View File

@@ -377,10 +377,6 @@
##
#lastfm_preferred_language = en
#
## Available values: add_remove, always_add.
##
#space_add_mode = always_add
#
#show_hidden_files_in_local_browser = no
#
##

View File

@@ -245,9 +245,6 @@ If set to yes, it will be possible to physically delete files and directories fr
.B lastfm_preferred_language = ISO 639 alpha-2 language code
If set, ncmpcpp will try to get info from last.fm in language you set and if it fails, it will fall back to english. Otherwise it will use english the first time.
.TP
.B space_add_mode = add_remove/always_add
If set to add_remove, pressing space on item which is already in playlist will remove it, otherwise add it again.
.TP
.B show_hidden_files_in_local_browser = yes/no
Trigger for displaying in local browser files and directories that begin with '.'
.TP

View File

@@ -512,11 +512,6 @@ void PressEnter::run()
myScreen->enterPressed();
}
void PressSpace::run()
{
myScreen->spacePressed();
}
bool PreviousColumn::canBeRun()
{
auto hc = hasColumns(myScreen);
@@ -593,6 +588,23 @@ void VolumeDown::run()
Mpd.SetVolume(volume);
}
bool AddItemToPlaylist::canBeRun()
{
if (m_hs != static_cast<void *>(myScreen))
m_hs = dynamic_cast<HasSongs *>(myScreen);
return m_hs != nullptr;
}
void AddItemToPlaylist::run()
{
bool success = m_hs->addItemToPlaylist();
if (success)
{
myScreen->scroll(NC::Scroll::Down);
listsChangeFinisher();
}
}
bool DeletePlaylistItems::canBeRun()
{
return (myScreen == myPlaylist && !myPlaylist->main().empty())
@@ -1060,6 +1072,19 @@ void ToggleSeparatorsBetweenAlbums::run()
);
}
bool ToggleLyricsUpdateOnSongChange::canBeRun()
{
return myScreen == myLyrics;
}
void ToggleLyricsUpdateOnSongChange::run()
{
Config.now_playing_lyrics = !Config.now_playing_lyrics;
Statusbar::printf("Update lyrics if song changes: %1%",
Config.now_playing_lyrics ? "on" : "off"
);
}
#ifndef HAVE_CURL_CURL_H
bool ToggleLyricsFetcher::canBeRun()
{
@@ -2121,6 +2146,22 @@ void SetSelectedItemsPriority::run()
myPlaylist->SetSelectedItemsPriority(prio);
}
bool ToggleVisualizationType::canBeRun()
{
# ifdef ENABLE_VISUALIZER
return myScreen == myVisualizer;
# else
return false;
# endif // ENABLE_VISUALIZER
}
void ToggleVisualizationType::run()
{
# ifdef ENABLE_VISUALIZER
myVisualizer->ToggleVisualizationType();
# endif // ENABLE_VISUALIZER
}
bool SetVisualizerSampleMultiplier::canBeRun()
{
# ifdef ENABLE_VISUALIZER
@@ -2472,7 +2513,6 @@ void populateActions()
insert_action(new Actions::ToggleInterface());
insert_action(new Actions::JumpToParentDirectory());
insert_action(new Actions::PressEnter());
insert_action(new Actions::PressSpace());
insert_action(new Actions::SelectItem());
insert_action(new Actions::PreviousColumn());
insert_action(new Actions::NextColumn());
@@ -2480,6 +2520,7 @@ void populateActions()
insert_action(new Actions::SlaveScreen());
insert_action(new Actions::VolumeUp());
insert_action(new Actions::VolumeDown());
insert_action(new Actions::AddItemToPlaylist());
insert_action(new Actions::DeletePlaylistItems());
insert_action(new Actions::DeleteStoredPlaylist());
insert_action(new Actions::DeleteBrowserItems());
@@ -2500,6 +2541,7 @@ void populateActions()
insert_action(new Actions::SeekBackward());
insert_action(new Actions::ToggleDisplayMode());
insert_action(new Actions::ToggleSeparatorsBetweenAlbums());
insert_action(new Actions::ToggleLyricsUpdateOnSongChange());
insert_action(new Actions::ToggleLyricsFetcher());
insert_action(new Actions::ToggleFetchingLyricsInBackground());
insert_action(new Actions::TogglePlayingSongCentering());
@@ -2553,6 +2595,7 @@ void populateActions()
insert_action(new Actions::ToggleMediaLibrarySortMode());
insert_action(new Actions::RefetchLyrics());
insert_action(new Actions::SetSelectedItemsPriority());
insert_action(new Actions::ToggleVisualizationType());
insert_action(new Actions::SetVisualizerSampleMultiplier());
insert_action(new Actions::ShowSongInfo());
insert_action(new Actions::ShowArtistInfo());

View File

@@ -37,15 +37,15 @@ enum class Type
MacroUtility = 0,
Dummy, UpdateEnvironment, MouseEvent, ScrollUp, ScrollDown, ScrollUpArtist, ScrollUpAlbum,
ScrollDownArtist, ScrollDownAlbum, PageUp, PageDown, MoveHome, MoveEnd,
ToggleInterface, JumpToParentDirectory, PressEnter, PressSpace, PreviousColumn,
NextColumn, MasterScreen, SlaveScreen, VolumeUp, VolumeDown, DeletePlaylistItems,
DeleteStoredPlaylist, DeleteBrowserItems, ReplaySong, Previous, Next, Pause,
Stop, ExecuteCommand, SavePlaylist, MoveSortOrderUp, MoveSortOrderDown,
ToggleInterface, JumpToParentDirectory, PressEnter, PreviousColumn,
NextColumn, MasterScreen, SlaveScreen, VolumeUp, VolumeDown, AddItemToPlaylist,
DeletePlaylistItems, DeleteStoredPlaylist, DeleteBrowserItems, ReplaySong, Previous,
Next, Pause, Stop, ExecuteCommand, SavePlaylist, MoveSortOrderUp, MoveSortOrderDown,
MoveSelectedItemsUp, MoveSelectedItemsDown, MoveSelectedItemsTo, Add,
SeekForward, SeekBackward, ToggleDisplayMode, ToggleSeparatorsBetweenAlbums,
ToggleLyricsFetcher, ToggleFetchingLyricsInBackground, TogglePlayingSongCentering,
UpdateDatabase, JumpToPlayingSong, ToggleRepeat, Shuffle, ToggleRandom,
StartSearching, SaveTagChanges, ToggleSingle, ToggleConsume, ToggleCrossfade,
ToggleLyricsUpdateOnSongChange, ToggleLyricsFetcher, ToggleFetchingLyricsInBackground,
TogglePlayingSongCentering, UpdateDatabase, JumpToPlayingSong, ToggleRepeat, Shuffle,
ToggleRandom, StartSearching, SaveTagChanges, ToggleSingle, ToggleConsume, ToggleCrossfade,
SetCrossfade, SetVolume, EditSong, EditLibraryTag, EditLibraryAlbum, EditDirectoryName,
EditPlaylistName, EditLyrics, JumpToBrowser, JumpToMediaLibrary,
JumpToPlaylistEditor, ToggleScreenLock, JumpToTagEditor, JumpToPositionInSong,
@@ -56,7 +56,7 @@ enum class Type
ToggleAddMode, ToggleMouse, ToggleBitrateVisibility,
AddRandomItems, ToggleBrowserSortMode, ToggleLibraryTagType,
ToggleMediaLibrarySortMode, RefetchLyrics,
SetSelectedItemsPriority, SetVisualizerSampleMultiplier,
SetSelectedItemsPriority, ToggleVisualizationType, SetVisualizerSampleMultiplier,
ShowSongInfo, ShowArtistInfo, ShowLyrics, Quit, NextScreen, PreviousScreen,
ShowHelp, ShowPlaylist, ShowBrowser, ChangeBrowseMode, ShowSearchEngine,
ResetSearchEngine, ShowMediaLibrary, ToggleMediaLibraryColumnsMode,
@@ -272,14 +272,6 @@ private:
virtual void run() OVERRIDE;
};
struct PressSpace: BaseAction
{
PressSpace(): BaseAction(Type::PressSpace, "press_space") { }
private:
virtual void run() OVERRIDE;
};
struct PreviousColumn: BaseAction
{
PreviousColumn(): BaseAction(Type::PreviousColumn, "previous_column") { }
@@ -332,6 +324,17 @@ private:
virtual void run() OVERRIDE;
};
struct AddItemToPlaylist: BaseAction
{
AddItemToPlaylist(): BaseAction(Type::AddItemToPlaylist, "add_item_to_playlist") { }
private:
virtual bool canBeRun() OVERRIDE;
virtual void run() OVERRIDE;
HasSongs *m_hs;
};
struct DeletePlaylistItems: BaseAction
{
DeletePlaylistItems(): BaseAction(Type::DeletePlaylistItems, "delete_playlist_items") { }
@@ -506,6 +509,16 @@ private:
virtual void run() OVERRIDE;
};
struct ToggleLyricsUpdateOnSongChange: BaseAction
{
ToggleLyricsUpdateOnSongChange()
: BaseAction(Type::ToggleLyricsUpdateOnSongChange, "toggle_lyrics_update_on_song_change") { }
private:
virtual bool canBeRun() OVERRIDE;
virtual void run() OVERRIDE;
};
struct ToggleLyricsFetcher: BaseAction
{
ToggleLyricsFetcher(): BaseAction(Type::ToggleLyricsFetcher, "toggle_lyrics_fetcher") { }
@@ -998,6 +1011,17 @@ private:
virtual void run() OVERRIDE;
};
struct ToggleVisualizationType: BaseAction
{
ToggleVisualizationType()
: BaseAction(Type::ToggleVisualizationType, "toggle_visualization_type") { }
private:
virtual bool canBeRun() OVERRIDE;
virtual void run() OVERRIDE;
};
struct SetVisualizerSampleMultiplier: BaseAction
{
SetVisualizerSampleMultiplier()

View File

@@ -472,10 +472,14 @@ void BindingsConfiguration::generateDefaults()
bind(k, Actions::Type::MoveEnd);
if (notBound(k = stringToKey("insert")))
bind(k, Actions::Type::SelectItem);
if (notBound(k = stringToKey("space")))
bind(k, Actions::Type::PressSpace);
if (notBound(k = stringToKey("enter")))
bind(k, Actions::Type::PressEnter);
if (notBound(k = stringToKey("space")))
{
bind(k, Actions::Type::AddItemToPlaylist);
bind(k, Actions::Type::ToggleLyricsUpdateOnSongChange);
bind(k, Actions::Type::ToggleVisualizationType);
}
if (notBound(k = stringToKey("delete")))
{
bind(k, Actions::Type::DeletePlaylistItems);

View File

@@ -243,46 +243,6 @@ void Browser::enterPressed()
}
}
void Browser::spacePressed()
{
if (w.empty())
return;
const MPD::Item &item = w.current()->value();
// ignore parent directory
if (isParentDirectory(item))
return;
switch (item.type())
{
case MPD::Item::Type::Directory:
{
bool success = true;
if (m_local_browser)
{
std::vector<MPD::Song> songs;
getLocalDirectoryRecursively(songs, item.directory().path());
success = addSongsToPlaylist(songs.begin(), songs.end(), false, -1);
}
else
Mpd.Add(item.directory().path());
Statusbar::printf("Directory \"%1%\" added%2%",
item.directory().path(), withErrors(success)
);
break;
}
case MPD::Item::Type::Song:
addSongToPlaylist(item.song(), false);
break;
case MPD::Item::Type::Playlist:
Mpd.LoadPlaylist(item.playlist().path());
Statusbar::printf("Playlist \"%1%\" loaded", item.playlist().path());
break;
}
w.scroll(NC::Scroll::Down);
}
void Browser::mouseButtonPressed(MEVENT me)
{
if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
@@ -299,22 +259,12 @@ void Browser::mouseButtonPressed(MEVENT me)
drawHeader();
}
else
{
size_t pos = w.choice();
spacePressed();
if (pos < w.size()-1)
w.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
break;
case MPD::Item::Type::Playlist:
case MPD::Item::Type::Song:
if (me.bstate & BUTTON1_PRESSED)
{
size_t pos = w.choice();
spacePressed();
if (pos < w.size()-1)
w.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
else
enterPressed();
break;
@@ -351,6 +301,46 @@ bool Browser::find(SearchDirection direction, bool wrap, bool skip_current)
/***********************************************************************/
bool Browser::addItemToPlaylist()
{
bool result = false;
if (w.empty())
return result;
const MPD::Item &item = w.current()->value();
// ignore parent directory
if (isParentDirectory(item))
return result;
switch (item.type())
{
case MPD::Item::Type::Directory:
{
if (m_local_browser)
{
std::vector<MPD::Song> songs;
getLocalDirectoryRecursively(songs, item.directory().path());
result = addSongsToPlaylist(songs.begin(), songs.end(), false, -1);
}
else
Mpd.Add(item.directory().path());
Statusbar::printf("Directory \"%1%\" added%2%",
item.directory().path(), withErrors(result)
);
break;
}
case MPD::Item::Type::Song:
result = addSongToPlaylist(item.song(), false);
break;
case MPD::Item::Type::Playlist:
Mpd.LoadPlaylist(item.playlist().path());
Statusbar::printf("Playlist \"%1%\" loaded", item.playlist().path());
result = true;
break;
}
return result;
}
std::vector<MPD::Song> Browser::getSelectedSongs()
{
std::vector<MPD::Song> songs;

View File

@@ -57,7 +57,6 @@ struct Browser: Screen<BrowserWindow>, HasSongs, Searchable, Tabbable
virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }
@@ -70,6 +69,7 @@ struct Browser: Screen<BrowserWindow>, HasSongs, Searchable, Tabbable
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
// HasSongs implementation
virtual bool addItemToPlaylist() OVERRIDE;
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
// private members

View File

@@ -43,7 +43,6 @@ struct Clock: Screen<NC::Window>, Tabbable
virtual void scroll(NC::Scroll) OVERRIDE { }
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT) OVERRIDE { }
virtual bool isLockable() OVERRIDE { return false; }

View File

@@ -246,7 +246,7 @@ void write_bindings(NC::Scrollpad &w)
key_section(w, "Browser");
key(w, Type::PressEnter, "Enter directory/Add item to playlist and play it");
key(w, Type::PressSpace, "Add item to playlist");
key(w, Type::AddItemToPlaylist, "Add item to playlist");
# ifdef HAVE_TAGLIB_H
key(w, Type::EditSong, "Edit song");
# endif // HAVE_TAGLIB_H
@@ -261,7 +261,7 @@ void write_bindings(NC::Scrollpad &w)
key_section(w, "Search engine");
key(w, Type::PressEnter, "Add item to playlist and play it/change option");
key(w, Type::PressSpace, "Add item to playlist");
key(w, Type::AddItemToPlaylist, "Add item to playlist");
# ifdef HAVE_TAGLIB_H
key(w, Type::EditSong, "Edit song");
# endif // HAVE_TAGLIB_H
@@ -273,7 +273,7 @@ void write_bindings(NC::Scrollpad &w)
key(w, Type::PreviousColumn, "Previous column");
key(w, Type::NextColumn, "Next column");
key(w, Type::PressEnter, "Add item to playlist and play it");
key(w, Type::PressSpace, "Add item to playlist");
key(w, Type::AddItemToPlaylist, "Add item to playlist");
# ifdef HAVE_TAGLIB_H
key(w, Type::EditSong, "Edit song");
# endif // HAVE_TAGLIB_H
@@ -285,7 +285,7 @@ void write_bindings(NC::Scrollpad &w)
key(w, Type::PreviousColumn, "Previous column");
key(w, Type::NextColumn, "Next column");
key(w, Type::PressEnter, "Add item to playlist and play it");
key(w, Type::PressSpace, "Add item to playlist");
key(w, Type::AddItemToPlaylist, "Add item to playlist");
# ifdef HAVE_TAGLIB_H
key(w, Type::EditSong, "Edit song");
# endif // HAVE_TAGLIB_H
@@ -298,7 +298,7 @@ void write_bindings(NC::Scrollpad &w)
key(w, Type::CropPlaylist, "Clear playlist except selected items");
key_section(w, "Lyrics");
key(w, Type::PressSpace, "Toggle reloading lyrics upon song change");
key(w, Type::ToggleLyricsUpdateOnSongChange, "Toggle lyrics update on song change");
key(w, Type::EditLyrics, "Open lyrics in external editor");
key(w, Type::RefetchLyrics, "Refetch lyrics");
@@ -322,7 +322,7 @@ void write_bindings(NC::Scrollpad &w)
# if defined(ENABLE_VISUALIZER) && defined(HAVE_FFTW3_H)
key_section(w, "Music visualizer");
key(w, Type::PressSpace, "Toggle visualization type");
key(w, Type::ToggleVisualizationType, "Toggle visualization type");
key(w, Type::SetVisualizerSampleMultiplier, "Set visualizer sample multiplier");
# endif // ENABLE_VISUALIZER && HAVE_FFTW3_H

View File

@@ -38,7 +38,6 @@ struct Help: Screen<NC::Scrollpad>, Tabbable
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE { }
virtual bool isLockable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; }

View File

@@ -24,6 +24,7 @@
#include "helpers.h"
#include "playlist.h"
#include "statusbar.h"
#include "utility/functional.h"
const MPD::Song *currentSong(const BaseScreen *screen)
{
@@ -88,31 +89,27 @@ bool addSongsToPlaylist(VectorSongIterator first, VectorSongIterator last, bool
return result;
}
void removeSongFromPlaylist(const SongMenu &playlist, const MPD::Song &s)
{
Mpd.StartCommandsList();
for (auto &item : reverse_iteration(playlist))
if (item.value() == s)
Mpd.Delete(item.value().getPosition());
Mpd.CommitCommandsList();
}
bool addSongToPlaylist(const MPD::Song &s, bool play, int position)
{
bool result = false;
if (Config.space_add_mode == SpaceAddMode::AddRemove && myPlaylist->checkForSong(s))
if (Config.space_add_mode == SpaceAddMode::AddRemove
&& !play
&& myPlaylist->checkForSong(s)
)
{
auto &w = myPlaylist->main();
if (play)
{
auto song = std::find(w.beginV(), w.endV(), s);
assert(song != w.endV());
Mpd.PlayID(song->getID());
result = true;
removeSongFromPlaylist(myPlaylist->main(), s);
return result;
}
else
{
Mpd.StartCommandsList();
for (auto it = w.rbeginV(); it != w.rendV(); ++it)
if (*it == s)
Mpd.Delete(it->getPosition());
Mpd.CommitCommandsList();
// we return false in this case
}
}
else
{
int id = Mpd.AddSong(s, position);
if (id >= 0)
{
@@ -123,7 +120,6 @@ bool addSongToPlaylist(const MPD::Song &s, bool play, int position)
Mpd.PlayID(id);
result = true;
}
}
return result;
}

View File

@@ -39,6 +39,7 @@ struct Searchable
struct HasSongs
{
virtual bool addItemToPlaylist() = 0;
virtual std::vector<MPD::Song> getSelectedSongs() = 0;
};

View File

@@ -46,7 +46,6 @@ struct Lastfm: Screen<NC::Scrollpad>, Tabbable
virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE { }
virtual bool isLockable() OVERRIDE { return false; }
virtual bool isMergable() OVERRIDE { return true; }

View File

@@ -137,14 +137,6 @@ std::wstring Lyrics::title()
return result;
}
void Lyrics::spacePressed()
{
Config.now_playing_lyrics = !Config.now_playing_lyrics;
Statusbar::printf("Reload lyrics if song changes: %1%",
Config.now_playing_lyrics ? "on" : "off"
);
}
#ifdef HAVE_CURL_CURL_H
void Lyrics::DownloadInBackground(const MPD::Song &s)
{

View File

@@ -43,7 +43,6 @@ struct Lyrics: Screen<NC::Scrollpad>, Tabbable
virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE;
virtual bool isLockable() OVERRIDE { return false; }
virtual bool isMergable() OVERRIDE { return true; }

View File

@@ -451,12 +451,7 @@ int MediaLibrary::windowTimeout()
void MediaLibrary::enterPressed()
{
AddToPlaylist(true);
}
void MediaLibrary::spacePressed()
{
AddToPlaylist(false);
addItemToPlaylist(true);
}
void MediaLibrary::mouseButtonPressed(MEVENT me)
@@ -491,12 +486,7 @@ void MediaLibrary::mouseButtonPressed(MEVENT me)
{
Tags.Goto(me.y);
if (me.bstate & BUTTON3_PRESSED)
{
size_t pos = Tags.choice();
spacePressed();
if (pos < Tags.size()-1)
Tags.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
}
else
Screen<WindowType>::mouseButtonPressed(me);
@@ -519,12 +509,7 @@ void MediaLibrary::mouseButtonPressed(MEVENT me)
{
Albums.Goto(me.y);
if (me.bstate & BUTTON3_PRESSED)
{
size_t pos = Albums.choice();
spacePressed();
if (pos < Albums.size()-1)
Albums.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
}
else
Screen<WindowType>::mouseButtonPressed(me);
@@ -538,12 +523,7 @@ void MediaLibrary::mouseButtonPressed(MEVENT me)
{
Songs.Goto(me.y);
if (me.bstate & BUTTON1_PRESSED)
{
size_t pos = Songs.choice();
spacePressed();
if (pos < Songs.size()-1)
Songs.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
else
enterPressed();
}
@@ -608,6 +588,11 @@ bool MediaLibrary::find(SearchDirection direction, bool wrap, bool skip_current)
/***********************************************************************/
bool MediaLibrary::addItemToPlaylist()
{
return addItemToPlaylist(false);
}
std::vector<MPD::Song> MediaLibrary::getSelectedSongs()
{
std::vector<MPD::Song> result;
@@ -923,10 +908,11 @@ void MediaLibrary::LocateSong(const MPD::Song &s)
refresh();
}
void MediaLibrary::AddToPlaylist(bool add_n_play)
bool MediaLibrary::addItemToPlaylist(bool play)
{
bool result = false;
if (isActiveWindow(Songs) && !Songs.empty())
addSongToPlaylist(Songs.current()->value(), add_n_play);
result = addSongToPlaylist(Songs.current()->value(), play);
else
{
if ((!Tags.empty() && isActiveWindow(Tags))
@@ -938,11 +924,11 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
std::make_move_iterator(Mpd.CommitSearchSongs()),
std::make_move_iterator(MPD::SongIterator())
);
bool success = addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1);
result = addSongsToPlaylist(list.begin(), list.end(), play, -1);
std::string tag_type = boost::locale::to_lower(
tagTypeToString(Config.media_lib_primary_tag));
Statusbar::printf("Songs with %1% \"%2%\" added%3%",
tag_type, Tags.current()->value().tag(), withErrors(success)
tag_type, Tags.current()->value().tag(), withErrors(result)
);
}
else if (isActiveWindow(Albums))
@@ -951,24 +937,13 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
std::make_move_iterator(getSongsFromAlbum(Albums.current()->value())),
std::make_move_iterator(MPD::SongIterator())
);
bool success = addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1);
result = addSongsToPlaylist(list.begin(), list.end(), play, -1);
Statusbar::printf("Songs from album \"%1%\" added%2%",
Albums.current()->value().entry().album(), withErrors(success)
Albums.current()->value().entry().album(), withErrors(result)
);
}
}
if (!add_n_play)
{
w->scroll(NC::Scroll::Down);
if (isActiveWindow(Tags))
{
Albums.clear();
Songs.clear();
}
else if (isActiveWindow(Albums))
Songs.clear();
}
return result;
}
namespace {

View File

@@ -44,7 +44,6 @@ struct MediaLibrary: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tab
virtual int windowTimeout() OVERRIDE;
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }
@@ -57,6 +56,7 @@ struct MediaLibrary: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tab
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
// HasSongs implementation
virtual bool addItemToPlaylist() OVERRIDE;
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
// HasColumns implementation
@@ -133,7 +133,7 @@ struct MediaLibrary: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tab
SongMenu Songs;
private:
void AddToPlaylist(bool);
bool addItemToPlaylist(bool play);
bool m_tags_update_request;
bool m_albums_update_request;

View File

@@ -44,7 +44,6 @@ struct Outputs: Screen<NC::Menu<MPD::Output>>, Tabbable
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }

View File

@@ -44,7 +44,6 @@ struct Playlist: Screen<SongMenu>, HasSongs, Searchable, Tabbable
virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }
@@ -57,6 +56,7 @@ struct Playlist: Screen<SongMenu>, HasSongs, Searchable, Tabbable
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
// HasSongs implementation
virtual bool addItemToPlaylist() OVERRIDE { return false; };
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
// private members

View File

@@ -225,34 +225,9 @@ int PlaylistEditor::windowTimeout()
return Screen<WindowType>::windowTimeout();
}
void PlaylistEditor::AddToPlaylist(bool add_n_play)
{
if (isActiveWindow(Playlists) && !Playlists.empty())
{
std::vector<MPD::Song> list(
std::make_move_iterator(Mpd.GetPlaylistContent(Playlists.current()->value().path())),
std::make_move_iterator(MPD::SongIterator())
);
bool success = addSongsToPlaylist(list.begin(), list.end(), add_n_play, -1);
Statusbar::printf("Playlist \"%1%\" loaded%2%",
Playlists.current()->value().path(), withErrors(success)
);
}
else if (isActiveWindow(Content) && !Content.empty())
addSongToPlaylist(Content.current()->value(), add_n_play);
if (!add_n_play)
w->scroll(NC::Scroll::Down);
}
void PlaylistEditor::enterPressed()
{
AddToPlaylist(true);
}
void PlaylistEditor::spacePressed()
{
AddToPlaylist(false);
addItemToPlaylist(true);
}
void PlaylistEditor::mouseButtonPressed(MEVENT me)
@@ -270,12 +245,7 @@ void PlaylistEditor::mouseButtonPressed(MEVENT me)
{
Playlists.Goto(me.y);
if (me.bstate & BUTTON3_PRESSED)
{
size_t pos = Playlists.choice();
spacePressed();
if (pos < Playlists.size()-1)
Playlists.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
}
else
Screen<WindowType>::mouseButtonPressed(me);
@@ -294,12 +264,7 @@ void PlaylistEditor::mouseButtonPressed(MEVENT me)
{
Content.Goto(me.y);
if (me.bstate & BUTTON1_PRESSED)
{
size_t pos = Content.choice();
spacePressed();
if (pos < Content.size()-1)
Content.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
else
enterPressed();
}
@@ -353,6 +318,11 @@ bool PlaylistEditor::find(SearchDirection direction, bool wrap, bool skip_curren
/***********************************************************************/
bool PlaylistEditor::addItemToPlaylist()
{
return addItemToPlaylist(false);
}
std::vector<MPD::Song> PlaylistEditor::getSelectedSongs()
{
std::vector<MPD::Song> result;
@@ -450,6 +420,25 @@ void PlaylistEditor::Locate(const MPD::Playlist &playlist)
}
}
bool PlaylistEditor::addItemToPlaylist(bool play)
{
bool result = false;
if (isActiveWindow(Playlists) && !Playlists.empty())
{
std::vector<MPD::Song> list(
std::make_move_iterator(Mpd.GetPlaylistContent(Playlists.current()->value().path())),
std::make_move_iterator(MPD::SongIterator())
);
result = addSongsToPlaylist(list.begin(), list.end(), play, -1);
Statusbar::printf("Playlist \"%1%\" loaded%2%",
Playlists.current()->value().path(), withErrors(result)
);
}
else if (isActiveWindow(Content) && !Content.empty())
result = addSongToPlaylist(Content.current()->value(), play);
return result;
}
namespace {
std::string SongToString(const MPD::Song &s)

View File

@@ -44,7 +44,6 @@ struct PlaylistEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, T
virtual int windowTimeout() OVERRIDE;
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }
@@ -57,6 +56,7 @@ struct PlaylistEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, T
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
// HasSongs implementation
virtual bool addItemToPlaylist() OVERRIDE;
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
// HasColumns implementation
@@ -78,7 +78,7 @@ struct PlaylistEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, T
SongMenu Content;
private:
void AddToPlaylist(bool);
bool addItemToPlaylist(bool play);
bool m_playlists_update_requested;
bool m_content_update_requested;

View File

@@ -76,9 +76,6 @@ struct BaseScreen
/// Invoked after Enter was pressed
virtual void enterPressed() = 0;
/// Invoked after Space was pressed
virtual void spacePressed() = 0;
/// @see Screen::mouseButtonPressed()
virtual void mouseButtonPressed(MEVENT me) = 0;

View File

@@ -268,15 +268,6 @@ void SearchEngine::enterPressed()
addSongToPlaylist(w.current()->value().song(), true);
}
void SearchEngine::spacePressed()
{
if (w.current()->value().isSong())
{
addSongToPlaylist(w.current()->value().song(), false);
w.scroll(NC::Scroll::Down);
}
}
void SearchEngine::mouseButtonPressed(MEVENT me)
{
if (w.empty() || !w.hasCoords(me.x, me.y) || size_t(me.y) >= w.size())
@@ -291,12 +282,7 @@ void SearchEngine::mouseButtonPressed(MEVENT me)
else if (w.choice() >= StaticOptions)
{
if (me.bstate & BUTTON1_PRESSED)
{
size_t pos = w.choice();
spacePressed();
if (pos < w.size()-1)
w.scroll(NC::Scroll::Up);
}
addItemToPlaylist();
else
enterPressed();
}
@@ -332,6 +318,14 @@ bool SearchEngine::find(SearchDirection direction, bool wrap, bool skip_current)
/***********************************************************************/
bool SearchEngine::addItemToPlaylist()
{
bool result = false;
if (!w.empty() && w.current()->value().isSong())
result = addSongToPlaylist(w.current()->value().song(), false);
return result;
}
std::vector<MPD::Song> SearchEngine::getSelectedSongs()
{
std::vector<MPD::Song> result;

View File

@@ -105,7 +105,6 @@ struct SearchEngine: Screen<SearchEngineWindow>, HasSongs, Searchable, Tabbable
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }
@@ -118,6 +117,7 @@ struct SearchEngine: Screen<SearchEngineWindow>, HasSongs, Searchable, Tabbable
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
// HasSongs implementation
virtual bool addItemToPlaylist() OVERRIDE;
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
// private members

View File

@@ -44,7 +44,6 @@ struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return false; }

View File

@@ -40,7 +40,6 @@ struct ServerInfo: Screen<NC::Scrollpad>, Tabbable
virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE { }
virtual bool isLockable() OVERRIDE { return false; }
virtual bool isMergable() OVERRIDE { return false; }

View File

@@ -46,7 +46,6 @@ struct SongInfo: Screen<NC::Scrollpad>, Tabbable
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE { }
virtual bool isLockable() OVERRIDE { return false; }
virtual bool isMergable() OVERRIDE { return true; }

View File

@@ -42,7 +42,6 @@ struct SortPlaylistDialog
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return false; }

View File

@@ -714,8 +714,6 @@ void TagEditor::mouseButtonPressed(MEVENT me)
Dirs->Goto(me.y);
if (me.bstate & BUTTON1_PRESSED)
enterPressed();
else
spacePressed();
}
else
Screen<WindowType>::mouseButtonPressed(me);
@@ -806,6 +804,14 @@ bool TagEditor::find(SearchDirection direction, bool wrap, bool skip_current)
/***********************************************************************/
bool TagEditor::addItemToPlaylist()
{
bool result = false;
if (w == Tags && !Tags->empty())
result = addSongToPlaylist(*Tags->currentV(), false);
return result;
}
std::vector<MPD::Song> TagEditor::getSelectedSongs()
{
std::vector<MPD::Song> result;

View File

@@ -63,7 +63,6 @@ struct TagEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tabbab
virtual void update() OVERRIDE;
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT) OVERRIDE;
virtual bool isLockable() OVERRIDE { return true; }
@@ -76,6 +75,7 @@ struct TagEditor: Screen<NC::Window *>, HasColumns, HasSongs, Searchable, Tabbab
virtual bool find(SearchDirection direction, bool wrap, bool skip_current) OVERRIDE;
// HasSongs implementation
virtual bool addItemToPlaylist() OVERRIDE;
virtual std::vector<MPD::Song> getSelectedSongs() OVERRIDE;
// HasColumns implementation

View File

@@ -43,7 +43,6 @@ struct TinyTagEditor: Screen<NC::Menu<NC::Buffer>>
virtual void update() OVERRIDE { }
virtual void enterPressed() OVERRIDE;
virtual void spacePressed() OVERRIDE { }
virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
virtual bool isLockable() OVERRIDE { return false; }

View File

@@ -24,6 +24,36 @@
#include <boost/locale/encoding_utf.hpp>
#include <utility>
template <typename BaseT>
struct reversed_iteration
{
reversed_iteration(BaseT &base_)
: base(base_) { }
BaseT &base;
};
template <typename BaseT>
reversed_iteration<BaseT> reverse_iteration(BaseT &base_) {
return reversed_iteration<BaseT>(base_);
}
template <typename BaseT>
auto begin(reversed_iteration<BaseT> &rev) -> decltype(rev.base.rbegin()) {
return rev.base.rbegin();
}
template <typename BaseT>
auto begin(reversed_iteration<const BaseT> &rev) -> decltype(rev.base.rbegin()) {
return rev.base.rbegin();
}
template <typename BaseT>
auto end(reversed_iteration<BaseT> &rev) -> decltype(rev.base.rend()) {
return rev.base.rend();
}
template <typename BaseT>
auto end(reversed_iteration<const BaseT> &rev) -> decltype(rev.base.rend()) {
return rev.base.rend();
}
template <typename ValueT>
struct pointer_extractor
{

View File

@@ -187,32 +187,6 @@ int Visualizer::windowTimeout()
return Screen<WindowType>::windowTimeout();
}
void Visualizer::spacePressed()
{
switch (Config.visualizer_type)
{
case VisualizerType::Wave:
Config.visualizer_type = VisualizerType::WaveFilled;
break;
case VisualizerType::WaveFilled:
# ifdef HAVE_FFTW3_H
Config.visualizer_type = VisualizerType::Spectrum;
# else
Config.visualizer_type = VisualizerType::Ellipse;
# endif // HAVE_FFTW3_H
break;
# ifdef HAVE_FFTW3_H
case VisualizerType::Spectrum:
Config.visualizer_type = VisualizerType::Ellipse;
break;
# endif // HAVE_FFTW3_H
case VisualizerType::Ellipse:
Config.visualizer_type = VisualizerType::Wave;
break;
}
Statusbar::printf("Visualization type: %1%", Config.visualizer_type);
}
/**********************************************************************/
void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, size_t height)
@@ -443,6 +417,32 @@ void Visualizer::DrawFrequencySpectrumStereo(int16_t *buf_left, int16_t *buf_rig
/**********************************************************************/
void Visualizer::ToggleVisualizationType()
{
switch (Config.visualizer_type)
{
case VisualizerType::Wave:
Config.visualizer_type = VisualizerType::WaveFilled;
break;
case VisualizerType::WaveFilled:
# ifdef HAVE_FFTW3_H
Config.visualizer_type = VisualizerType::Spectrum;
# else
Config.visualizer_type = VisualizerType::Ellipse;
# endif // HAVE_FFTW3_H
break;
# ifdef HAVE_FFTW3_H
case VisualizerType::Spectrum:
Config.visualizer_type = VisualizerType::Ellipse;
break;
# endif // HAVE_FFTW3_H
case VisualizerType::Ellipse:
Config.visualizer_type = VisualizerType::Wave;
break;
}
Statusbar::printf("Visualization type: %1%", Config.visualizer_type);
}
void Visualizer::SetFD()
{
if (m_fifo < 0 && (m_fifo = open(Config.visualizer_fifo_path.c_str(), O_RDONLY | O_NONBLOCK)) < 0)

View File

@@ -50,13 +50,13 @@ struct Visualizer: Screen<NC::Window>, Tabbable
virtual int windowTimeout() OVERRIDE;
virtual void enterPressed() OVERRIDE { }
virtual void spacePressed() OVERRIDE;
virtual void mouseButtonPressed(MEVENT) OVERRIDE { }
virtual bool isLockable() OVERRIDE { return true; }
virtual bool isMergable() OVERRIDE { return true; }
// private members
void ToggleVisualizationType();
void SetFD();
void ResetFD();
void FindOutputID();