settings: add 'execute_on_player_state_change' option

master
ben01189998819991197253@users.noreply.github.com 10 years ago committed by Andrzej Rybczak
parent 8d12ac790f
commit 4130d3ba24
  1. 1
      NEWS
  2. 9
      doc/config
  3. 5
      doc/ncmpcpp.1
  4. 3
      src/settings.cpp
  5. 2
      src/settings.h
  6. 18
      src/status.cpp

@ -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

@ -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:

Loading…
Cancel
Save