aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--doc/examples/audio-volume-control/README33
-rwxr-xr-xdoc/examples/audio-volume-control/amixer8
-rwxr-xr-xdoc/examples/audio-volume-control/cleanup3
-rwxr-xr-xdoc/examples/audio-volume-control/init12
-rwxr-xr-xdoc/examples/audio-volume-control/monitor15
5 files changed, 71 insertions, 0 deletions
diff --git a/doc/examples/audio-volume-control/README b/doc/examples/audio-volume-control/README
new file mode 100644
index 0000000..f3864b7
--- /dev/null
+++ b/doc/examples/audio-volume-control/README
@@ -0,0 +1,33 @@
+Use-case example.
+
+Assume you have program that display the audio volume.
+This program checks every second third if the volume
+have changed.
+
+Also assume that you use amixer to change the volume,
+most often by using keybindings via xbindkeys.
+
+To reduce the delay, you want to send a signal to the
+monitor program that the volume have changed. For this
+more primitive IPC is sufficient, but lets assume there
+are other programs interested in this information too.
+
+To accomplish this, you create a wrapper for amixer
+than broadcasts updates on a bus. This wrapper is
+installed as ~/.local/bin/amixer, and ~/.local/bin/
+is included in $PATH before /usr/bin.
+
+
+
+Before starting run ~/.init, this code is
+should be run from your profile file if you
+want to implement this on your system.
+
+After running ~/.init, you can start one
+or more listeners by running ~/.alsa-monitor.
+
+To change the volume run
+`./amixer -c 0 -- set Master 5%+` or similar.
+
+When you are done run ~/.cleanup
+
diff --git a/doc/examples/audio-volume-control/amixer b/doc/examples/audio-volume-control/amixer
new file mode 100755
index 0000000..c46d4e5
--- /dev/null
+++ b/doc/examples/audio-volume-control/amixer
@@ -0,0 +1,8 @@
+#!/bin/sh
+/usr/bin/amixer "$@"
+for arg in "$@"; do
+ if [ "${arg}" = "set" ] || [ "${arg}" = "sset" ] || [ "${arg}" = "cset" ]; then
+ exec bus broadcast "/tmp/example-bus" '0 volume-changed *'
+ fi
+done
+
diff --git a/doc/examples/audio-volume-control/cleanup b/doc/examples/audio-volume-control/cleanup
new file mode 100755
index 0000000..a711e4c
--- /dev/null
+++ b/doc/examples/audio-volume-control/cleanup
@@ -0,0 +1,3 @@
+#!/bin/sh
+exec bus remove "/tmp/example-bus"
+
diff --git a/doc/examples/audio-volume-control/init b/doc/examples/audio-volume-control/init
new file mode 100755
index 0000000..a429174
--- /dev/null
+++ b/doc/examples/audio-volume-control/init
@@ -0,0 +1,12 @@
+#!/bin/sh
+bus create "/tmp/example-bus"
+
+# The following code is more suitable in the real world,
+# if used, the other files should use "${BUS_AUDIO}"
+# instead of "/tmp/example-bus".
+#
+# export BUS_AUDIO="${XDG_RUNTIME_DIR}/bus/audio"
+# if [ ! -f "${BUS_AUDIO}" ]; then
+# bus create "${BUS_AUDIO}"
+# fi
+
diff --git a/doc/examples/audio-volume-control/monitor b/doc/examples/audio-volume-control/monitor
new file mode 100755
index 0000000..82fe7bc
--- /dev/null
+++ b/doc/examples/audio-volume-control/monitor
@@ -0,0 +1,15 @@
+#!/bin/sh
+if [ $# = 1 ]; then
+ if [ "$(echo "${1}" | cut -d ' ' -f 2)" = "volume-changed" ]; then
+ printf '\e[H\e[2J'
+ amixer get Master
+ fi
+ exit 0
+fi
+
+exec 2>/dev/null
+
+printf '\e[?1049h\e[H\e[2J'
+trap -- "printf '\e[?1049l'" SIGINT
+bus listen "/tmp/example-bus" \'"${0/\'/\'\\\'\'}"\'' "${arg}"'
+