settings: add 'execute_on_player_state_change' option
This commit is contained in:
committed by
Andrzej Rybczak
parent
8d12ac790f
commit
4130d3ba24
1
NEWS
1
NEWS
@@ -1,4 +1,5 @@
|
||||
ncmpcpp-0.8 (????-??-??)
|
||||
* Configuration variable 'execute_on_player_state_change' was added.
|
||||
|
||||
ncmpcpp 0.7.4 (2016-04-17)
|
||||
* Fetching lyrics from lyricwiki.org was fixed.
|
||||
|
||||
@@ -286,6 +286,15 @@
|
||||
##
|
||||
#execute_on_song_change = ""
|
||||
#
|
||||
##
|
||||
## Note: Custom command that will be executed each
|
||||
## time player state changes. The environment variable
|
||||
## MPD_PLAYER_STATE is set to the current state (either
|
||||
## unknown, play, pause, or stop) for its duration.
|
||||
##
|
||||
#
|
||||
#execute_on_player_state_change = ""
|
||||
#
|
||||
#playlist_show_mpd_host = no
|
||||
#
|
||||
#playlist_show_remaining_time = no
|
||||
|
||||
@@ -152,6 +152,11 @@ Format for songs' list displayed in columns.
|
||||
.B execute_on_song_change = COMMAND
|
||||
Shell command to execute on song change.
|
||||
.TP
|
||||
.B execute_on_player_state_change = COMMAND
|
||||
Shell command to execute on player state change. The environment variable
|
||||
.B MPD_PLAYER_STATE
|
||||
is set to the current state (either unknown, play, pause, or stop) for its duration.
|
||||
.TP
|
||||
.B playlist_show_mpd_host = yes/no
|
||||
If enabled, current MPD host will be shown in playlist.
|
||||
.TP
|
||||
|
||||
@@ -375,6 +375,9 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
|
||||
p.add("execute_on_song_change", assign_default(
|
||||
execute_on_song_change, ""
|
||||
));
|
||||
p.add("execute_on_player_state_change", assign_default(
|
||||
execute_on_player_state_change, ""
|
||||
));
|
||||
p.add("playlist_show_mpd_host", yes_no(
|
||||
playlist_show_mpd_host, false
|
||||
));
|
||||
|
||||
@@ -76,6 +76,7 @@ struct Configuration
|
||||
std::string external_editor;
|
||||
std::string system_encoding;
|
||||
std::string execute_on_song_change;
|
||||
std::string execute_on_player_state_change;
|
||||
std::string lastfm_preferred_language;
|
||||
std::wstring progressbar;
|
||||
std::wstring visualizer_chars;
|
||||
@@ -199,4 +200,3 @@ struct Configuration
|
||||
extern Configuration Config;
|
||||
|
||||
#endif // NCMPCPP_SETTINGS_H
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ void Status::update(int event)
|
||||
m_playlist_length = st.playlistLength();
|
||||
m_total_time = st.totalTime();
|
||||
m_volume = st.volume();
|
||||
|
||||
|
||||
if (event & MPD_IDLE_DATABASE)
|
||||
Changes::database();
|
||||
if (event & MPD_IDLE_STORED_PLAYLIST)
|
||||
@@ -432,10 +432,10 @@ void Status::Changes::playlist(unsigned previous_version)
|
||||
else // otherwise just add it to playlist
|
||||
myPlaylist->main().addItem(std::move(*s));
|
||||
}
|
||||
|
||||
|
||||
myPlaylist->reloadTotalLength();
|
||||
myPlaylist->reloadRemaining();
|
||||
|
||||
|
||||
if (isVisible(myBrowser))
|
||||
markSongsInPlaylist(myBrowser->main());
|
||||
if (isVisible(mySearcher))
|
||||
@@ -473,6 +473,24 @@ void Status::Changes::database()
|
||||
|
||||
void Status::Changes::playerState()
|
||||
{
|
||||
if (!Config.execute_on_player_state_change.empty())
|
||||
{
|
||||
auto stateToEnv = [](MPD::PlayerState st) -> const char * {
|
||||
switch (st)
|
||||
{
|
||||
case MPD::psPlay: return "play";
|
||||
case MPD::psStop: return "stop";
|
||||
case MPD::psPause: return "pause";
|
||||
case MPD::psUnknown: return "unknown";
|
||||
}
|
||||
throw std::logic_error("unreachable");
|
||||
};
|
||||
GNUC_UNUSED int res;
|
||||
setenv("MPD_PLAYER_STATE", stateToEnv(m_player_state), 1);
|
||||
res = system(Config.execute_on_player_state_change.c_str());
|
||||
unsetenv("MPD_PLAYER_STATE");
|
||||
}
|
||||
|
||||
switch (m_player_state)
|
||||
{
|
||||
case MPD::psPlay:
|
||||
@@ -503,7 +521,7 @@ void Status::Changes::playerState()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
std::string state = playerStateToString(m_player_state);
|
||||
if (Config.design == Design::Alternative)
|
||||
{
|
||||
@@ -518,7 +536,7 @@ void Status::Changes::playerState()
|
||||
else
|
||||
*wFooter << NC::Format::Bold << state << NC::Format::NoBold;
|
||||
}
|
||||
|
||||
|
||||
// needed for immediate display after starting
|
||||
// player from stopped state or seeking
|
||||
elapsedTime(false);
|
||||
@@ -680,7 +698,7 @@ void Status::Changes::flags()
|
||||
{
|
||||
if (!Config.header_visibility && Config.design == Design::Classic)
|
||||
return;
|
||||
|
||||
|
||||
std::string switch_state;
|
||||
switch (Config.design)
|
||||
{
|
||||
@@ -739,7 +757,7 @@ void Status::Changes::mixer()
|
||||
{
|
||||
if (!Config.display_volume_level || (!Config.header_visibility && Config.design == Design::Classic))
|
||||
return;
|
||||
|
||||
|
||||
switch (Config.design)
|
||||
{
|
||||
case Design::Classic:
|
||||
|
||||
Reference in New Issue
Block a user