Compare commits

...

4 Commits

Author SHA1 Message Date
1a671dfad5
Document PulseAudio integration 2021-11-16 05:17:15 +01:00
587a02fa15
Indent man page snippets with spaces 2021-11-16 05:16:51 +01:00
227b8e0fa2
Do not show both volumes if unnecessary
Also, make it apparent which value comes from where.
2021-11-16 04:48:52 +01:00
e66e9f249a
Rename an action to be shorter
Also, fix make dependencies to include the source file for actions.
2021-11-16 04:48:52 +01:00
4 changed files with 84 additions and 48 deletions

View File

@ -91,9 +91,10 @@ configure_file (${PROJECT_SOURCE_DIR}/config.h.in
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR}) include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
# Assuming a Unix-compatible system with a standalone preprocessor # Assuming a Unix-compatible system with a standalone preprocessor
set (actions_list ${PROJECT_SOURCE_DIR}/nncmpp.actions)
set (actions ${PROJECT_BINARY_DIR}/nncmpp-actions.h) set (actions ${PROJECT_BINARY_DIR}/nncmpp-actions.h)
add_custom_command (OUTPUT ${actions} add_custom_command (OUTPUT ${actions}
COMMAND cpp -I${PROJECT_BINARY_DIR} -P ${PROJECT_SOURCE_DIR}/nncmpp.actions COMMAND cpp -I${PROJECT_BINARY_DIR} -P ${actions_list}
| grep . | tr [[\n]] ^ | sed -ne [[h; s/,[^^]*/,/g]] -e [[s/$/COUNT/]] | grep . | tr [[\n]] ^ | sed -ne [[h; s/,[^^]*/,/g]] -e [[s/$/COUNT/]]
-e [[s/[^^]*/\tACTION_&/g]] -e [[s/.*/enum action {\n&\n};\n/p]] -e [[s/[^^]*/\tACTION_&/g]] -e [[s/.*/enum action {\n&\n};\n/p]]
-e [[g; s/,[^^]*//g; y/_/-/]] -e [[s/[^^]\{1,\}/\t"&",/g]] -e [[g; s/,[^^]*//g; y/_/-/]] -e [[s/[^^]\{1,\}/\t"&",/g]]
@ -102,7 +103,7 @@ add_custom_command (OUTPUT ${actions}
-e [[s/.*/static const char *g_action_descriptions[] = {\n&};/p]] -e [[s/.*/static const char *g_action_descriptions[] = {\n&};/p]]
| tr ^ [[\n]] > ${actions} | tr ^ [[\n]] > ${actions}
COMMAND test -s ${actions} COMMAND test -s ${actions}
DEPENDS ${PROJECT_BINARY_DIR}/config.h VERBATIM) DEPENDS ${actions_list} ${PROJECT_BINARY_DIR}/config.h VERBATIM)
# Build the main executable and link it # Build the main executable and link it
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c ${actions}) add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c ${actions})

View File

@ -15,8 +15,8 @@ MPD_PREVIOUS, Previous song
MPD_NEXT, Next song MPD_NEXT, Next song
MPD_BACKWARD, Seek backwards MPD_BACKWARD, Seek backwards
MPD_FORWARD, Seek forwards MPD_FORWARD, Seek forwards
MPD_VOLUME_UP, Increase volume MPD_VOLUME_UP, Increase MPD volume
MPD_VOLUME_DOWN, Decrease volume MPD_VOLUME_DOWN, Decrease MPD volume
MPD_SEARCH, Global search MPD_SEARCH, Global search
MPD_ADD, Add selection to playlist MPD_ADD, Add selection to playlist
@ -31,7 +31,7 @@ MPD_COMMAND, Send raw command to MPD
#ifdef WITH_PULSE #ifdef WITH_PULSE
PULSE_VOLUME_UP, Increase PulseAudio volume PULSE_VOLUME_UP, Increase PulseAudio volume
PULSE_VOLUME_DOWN, Decrease PulseAudio volume PULSE_VOLUME_DOWN, Decrease PulseAudio volume
PULSE_MUTE, Toggle mute of MPD PulseAudio sink PULSE_MUTE, Toggle PulseAudio sink mute
#endif #endif
CHOOSE, Choose item CHOOSE, Choose item

View File

@ -47,7 +47,6 @@ snippet:
settings = { settings = {
address = "~/.mpd/mpd.socket" address = "~/.mpd/mpd.socket"
password = "<your password>" password = "<your password>"
root = "~/Music"
pulseaudio = on pulseaudio = on
} }
colors = { colors = {
@ -98,6 +97,28 @@ settings = {
The sample rate should be greater than 40 kHz, the number of bits 8 or 16, The sample rate should be greater than 40 kHz, the number of bits 8 or 16,
and the number of channels doesn't matter, as they're simply averaged together. and the number of channels doesn't matter, as they're simply averaged together.
PulseAudio
----------
If you find standard MPD volume control useless, you may instead configure
*nncmpp* to show and control the volume of any PulseAudio sink MPD is currently
connected to.
This feature may be enabled with the *settings.pulseaudio* configuration option,
as in the snippet above. To replace the default volume control bindings, use:
....
normal = {
"M-PageUp" = "pulse-volume-up"
"M-PageDown" = "pulse-volume-down"
}
....
The respective actions may also be invoked from the help tab directly.
For this to work, *nncmpp* needs to access the right PulseAudio daemon--in case
your setup is unusual, consult the list of environment variables in
*pulseaudio*(1). MPD-compatibles are currently unsupported.
Files Files
----- -----
*nncmpp* follows the XDG Base Directory Specification. *nncmpp* follows the XDG Base Directory Specification.
@ -112,4 +133,4 @@ or submit pull requests.
See also See also
-------- --------
*mpd*(1) *mpd*(1), *pulseaudio*(1)

View File

@ -1243,6 +1243,7 @@ static struct app_context
#ifdef WITH_PULSE #ifdef WITH_PULSE
struct pulse pulse; ///< PulseAudio control struct pulse pulse; ///< PulseAudio control
#endif // WITH_PULSE #endif // WITH_PULSE
bool pulse_control_requested; ///< PulseAudio control desired by user
struct line_editor editor; ///< Line editor struct line_editor editor; ///< Line editor
struct poller_idle refresh_event; ///< Refresh the screen struct poller_idle refresh_event; ///< Refresh the screen
@ -1304,6 +1305,13 @@ on_poll_elapsed_time_changed (struct config_item *item)
g.elapsed_poll = item->value.boolean; g.elapsed_poll = item->value.boolean;
} }
static void
on_pulseaudio_changed (struct config_item *item)
{
// This is only set once, on application startup
g.pulse_control_requested = item->value.boolean;
}
static struct config_schema g_config_settings[] = static struct config_schema g_config_settings[] =
{ {
{ .name = "address", { .name = "address",
@ -1340,6 +1348,7 @@ static struct config_schema g_config_settings[] =
{ .name = "pulseaudio", { .name = "pulseaudio",
.comment = "Look up MPD in PulseAudio for improved volume controls", .comment = "Look up MPD in PulseAudio for improved volume controls",
.type = CONFIG_ITEM_BOOLEAN, .type = CONFIG_ITEM_BOOLEAN,
.on_change = on_pulseaudio_changed,
.default_ = "off" }, .default_ = "off" },
#endif // WITH_PULSE #endif // WITH_PULSE
@ -1376,14 +1385,6 @@ get_config_string (struct config_item *root, const char *key)
return item->value.string.str; return item->value.string.str;
} }
static bool
get_config_boolean (struct config_item *root, const char *key)
{
struct config_item *item = config_item_get (root, key, NULL);
hard_assert (item && item->type == CONFIG_ITEM_BOOLEAN);
return item->value.boolean;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void static void
@ -1782,18 +1783,31 @@ app_draw_status (void)
// It gets a bit complicated due to the only right-aligned item on the row // It gets a bit complicated due to the only right-aligned item on the row
struct str volume = str_make (); struct str volume = str_make ();
int remaining = COLS - buf.total_width;
if (g.volume >= 0)
{
str_append (&volume, " ");
#ifdef WITH_PULSE #ifdef WITH_PULSE
if (pulse_volume_status (&g.pulse, &volume)) if (g.pulse_control_requested)
str_append (&volume, " @ "); {
#endif // WITH_PULSE struct str buf = str_make ();
str_append_printf (&volume, "%3d%%", g.volume); if (pulse_volume_status (&g.pulse, &buf))
remaining -= volume.len; {
if (g.volume >= 0 && g.volume != 100)
str_append_printf (&buf, " (%d%%)", g.volume);
} }
else
{
if (g.volume >= 0)
str_append_printf (&buf, "(%d%%)", g.volume);
}
if (buf.len)
str_append_printf (&volume, " %s", buf.str);
str_free (&buf);
}
else
#endif // WITH_PULSE
if (g.volume >= 0)
str_append_printf (&volume, " %3d%%", g.volume);
int remaining = COLS - buf.total_width - volume.len;
if (!stopped && g.song_elapsed >= 0 && g.song_duration >= 1 if (!stopped && g.song_elapsed >= 0 && g.song_duration >= 1
&& remaining > 0) && remaining > 0)
{ {
@ -4173,7 +4187,7 @@ static void
pulse_update (void) pulse_update (void)
{ {
struct mpd_client *c = &g.client; struct mpd_client *c = &g.client;
if (!get_config_boolean (g.config.root, "settings.pulseaudio")) if (!g.pulse_control_requested)
return; return;
// The read permission is sufficient for this command // The read permission is sufficient for this command