Skip to content

Commit 160ae8e

Browse files
committed
Add node-type to support sources and sinks
Before this commit, pulseaudio-control supported solely sinks. After this commit, it supports sinks and sources, under a new name "node". A new flag `--node-type` changing the behavior of the script to handle sources instead of sinks. All the existing mentions of sinks have been changed to node when appropriate. Sinks and sources almost share the same commands, with the main difference being the command name (i.e. sink for Sinks). Thus, this commit adds a simple and hacky way to handle sources: a variable SINK_OR_SOURCE holds either `ink` or `ource` so that commands that were using `Sink` `Sinks` `sinks` `sink` can be transformed to `Source` `Sources` `sources` `source` easily.
1 parent 166a778 commit 160ae8e

File tree

4 files changed

+333
-216
lines changed

4 files changed

+333
-216
lines changed

README.md

+72-41
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
A feature-full volume control module for PulseAudio. Also known as Pavolume. Main features:
44

5-
* Increase/Decrease and Mute the default sink's audio.
6-
* Switch between sinks easily. You can also blacklist useless devices.
5+
* Increase/Decrease and Mute the default audio node (can be sink or source).
6+
* Switch between nodes easily. You can also blacklist useless devices.
77
* Optionally enable notifications and OSD messages.
88
* Works as a shortcut to pavucontrol or your favorite audio manager tool.
99
* Highly customizable: check the [Usage](#usage) section for details.
@@ -51,62 +51,74 @@ exec = pulseaudio-control [option...] <action>
5151
where `action`, and (optionally) `option`s are as specified in `pulseaudio-control help`:
5252

5353
```
54-
Usage: pulseaudio-control [OPTION...] ACTION
54+
Usage: ./pulseaudio-control.bash [OPTION...] ACTION
55+
56+
Terminology: A node represents either a sink (output) or source (input).
5557
5658
Options:
5759
--autosync | --no-autosync
5860
Whether to maintain same volume for all programs.
59-
Default: no
61+
Default: "no"
6062
--color-muted <rrggbb>
6163
Color in which to format when muted.
62-
Default: 6b6b6b
64+
Default: "6b6b6b"
6365
--notifications | --no-notifications
64-
Whether to show notifications when changing sinks.
65-
Default: no
66+
Whether to show notifications when changing nodes.
67+
Default: "no"
6668
--osd | --no-osd
6769
Whether to display KDE's OSD message.
68-
Default: no
70+
Default: "no"
6971
--icon-muted <icon>
7072
Icon to use when muted.
7173
Default: none
72-
--icon-sink <icon>
73-
Icon to use for sink.
74+
--icon-node <icon>
75+
Icon to use for node.
7476
Default: none
7577
--format <string>
7678
Use a format string to control the output.
79+
Remember to pass this argument wrapped in single quotes (`'`) instead
80+
of double quotes (`"`) to avoid your shell from evaluating the
81+
variables early.
7782
Available variables:
7883
* $VOL_ICON
7984
* $VOL_LEVEL
80-
* $ICON_SINK
81-
* $SINK_NICKNAME
85+
* $ICON_NODE
86+
* $NODE_NICKNAME
8287
* $IS_MUTED (yes/no)
83-
Default: $VOL_ICON ${VOL_LEVEL}% $ICON_SINK $SINK_NICKNAME
88+
Default: '$VOL_ICON ${VOL_LEVEL}% $ICON_NODE $NODE_NICKNAME'
8489
--icons-volume <icon>[,<icon>...]
8590
Icons for volume, from lower to higher.
8691
Default: none
92+
--node-type <node_type>
93+
Whether to consider PulseAudio sinks (output) or sources (input).
94+
All the operations of pulseaudio-control will apply to one of the two.
95+
Pass `input` for the sources, e.g. a microphone
96+
Pass `output` for the sinks, e.g. speakers, headphones
97+
Default: "output"
8798
--volume-max <int>
8899
Maximum volume to which to allow increasing.
89-
Default: 130
100+
Default: "130"
90101
--volume-step <int>
91102
Step size when inc/decrementing volume.
92-
Default: 2
93-
--sink-blacklist <name>[,<name>...]
94-
Sinks to ignore when switching. You can use globs. Don't forget to
103+
Default: "2"
104+
--node-blacklist <name>[,<name>...]
105+
Nodes to ignore when switching. You can use globs. Don't forget to
95106
quote the string when using globs, to avoid unwanted shell glob
96107
extension.
97108
Default: none
98-
--sink-nicknames-from <prop>
99-
pactl property to use for sink names, unless overriden by
100-
--sink-nickname. Its possible values are listed under the 'Properties'
101-
key in the output of `pactl list sinks`
109+
--node-nicknames-from <prop>
110+
pactl property to use for node names, unless overriden by
111+
--node-nickname. Its possible values are listed under the 'Properties'
112+
key in the output of `pactl list sinks` and `pactl list sources`
102113
Default: none
103-
--sink-nickname <name>:<nick>
104-
Nickname to assign to given sink name, taking priority over
105-
--sink-nicknames-from. May be given multiple times, and 'name' is
106-
exactly as listed in the output of `pactl list sinks short | cut -f2`.
107-
Note that you can also specify a port name for the sink with
114+
--node-nickname <name>:<nick>
115+
Nickname to assign to given node name, taking priority over
116+
--node-nicknames-from. May be given multiple times, and 'name' is
117+
exactly as listed in the output of `pactl list sinks short | cut -f2`
118+
and `pactl list sources short | cut -f2`.
119+
Note that you can also specify a port name for the node with
108120
`<name>/<port>`.
109-
It is also possible to use glob matching to match sink and port names.
121+
It is also possible to use glob matching to match node and port names.
110122
Exact matches are prioritized. Don't forget to quote the string when
111123
using globs, to avoid unwanted shell glob extension.
112124
Default: none
@@ -116,12 +128,17 @@ Actions:
116128
output print the PulseAudio status once
117129
listen listen for changes in PulseAudio to automatically update
118130
this script's output
119-
up, down increase or decrease the default sink's volume
120-
mute, unmute mute or unmute the default sink's audio
131+
up, down increase or decrease the default node's volume
132+
mute, unmute mute or unmute the default node's audio
121133
togmute switch between muted and unmuted
122-
next-sink switch to the next available sink
134+
next-node switch to the next available node
123135
sync synchronize all the output streams volume to be the same as
124-
the current sink's volume
136+
the current node's volume
137+
138+
Author:
139+
Mario Ortiz Manero
140+
More info on GitHub:
141+
https://github.com/marioortizmanero/polybar-pulseaudio-control
125142
```
126143

127144
See the [Module](#module) section for an example, or the [Useful icons](#useful-icons) section for some packs of icons.
@@ -137,7 +154,7 @@ The example from the screenshot can:
137154
* Open `pavucontrol` on right click
138155

139156
```ini
140-
[module/pulseaudio-control]
157+
[module/pulseaudio-control-output]
141158
type = custom/script
142159
tail = true
143160
format-underline = ${colors.cyan}
@@ -147,25 +164,39 @@ label-foreground = ${colors.foreground}
147164
# Icons mixed from Font Awesome 5 and Material Icons
148165
# You can copy-paste your options for each possible action, which is more
149166
# trouble-free but repetitive, or apply only the relevant ones (for example
150-
# --sink-blacklist is only needed for next-sink).
151-
exec = pulseaudio-control --icons-volume " , " --icon-muted "" --sink-nicknames-from "device.description" --sink-nickname "alsa_output.pci-0000_00_1b.0.analog-stereo: Speakers" --sink-nickname "alsa_output.usb-Kingston_HyperX_Virtual_Surround_Sound_00000000-00.analog-stereo: Headphones" listen
167+
# --node-blacklist is only needed for next-node).
168+
exec = pulseaudio-control --icons-volume " , " --icon-muted "" --node-nicknames-from "device.description" --node-nickname "alsa_output.pci-0000_00_1b.0.analog-stereo: Speakers" --node-nickname "alsa_output.usb-Kingston_HyperX_Virtual_Surround_Sound_00000000-00.analog-stereo: Headphones" listen
152169
click-right = exec pavucontrol &
153170
click-left = pulseaudio-control togmute
154-
click-middle = pulseaudio-control --sink-blacklist "alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2" next-sink
171+
click-middle = pulseaudio-control --node-blacklist "alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2" next-node
155172
scroll-up = pulseaudio-control --volume-max 130 up
156173
scroll-down = pulseaudio-control --volume-max 130 down
174+
175+
[module/pulseaudio-control-input]
176+
type = custom/script
177+
tail = true
178+
format-underline = ${colors.cyan}
179+
label-padding = 2
180+
label-foreground = ${colors.foreground}
181+
182+
exec = pulseaudio-control --node-type input --icons-volume "" --icon-muted "" --node-nickname "alsa_output.pci-0000_0c_00.3.analog-stereo: Webcam" --node-nickname "alsa_output.usb-Kingston_HyperX_Virtual_Surround_Sound_00000000-00.analog-stereo: Headphones" listen
183+
click-right = exec pavucontrol &
184+
click-left = pulseaudio-control --node-type input togmute
185+
click-middle = pulseaudio-control --node-type input next-node
186+
scroll-up = pulseaudio-control --node-type input --volume-max 130 up
187+
scroll-down = pulseaudio-control --node-type input --volume-max 130 down
157188
```
158189

159190
## Useful icons
160191

161192
Here's a list with some icons from different fonts you can copy-paste. Most have an space afterwards so that the module has a bit of spacing. They may appear bugged on your browser if the font isn't available there. Please add yours if they aren't in the list.
162193

163-
| Font name | Volumes | Muted | Sink icons |
164-
| ----------------------------------------------- | :-------------: | :-----: | :------------------------: |
165-
| [FontAwesome](https://fontawesome.com) | `" , "` | `" "` | `" "` or `" "` |
166-
| [Material](https://material.io/resources/icons) | `" , , "` | `" "` | `" "` or `" "` or `" "` |
167-
| Emoji | `"🔈 ,🔉 ,🔊 "` | `"🔇 "` | `"🔈 "` or `"🎧 "` |
168-
| Emoji v2 | `"🕨 ,🕩 ,🕪 "` | `"🔇 "` | `"🕨 "` or `"🎧 "` |
194+
| Font name | Volumes | Muted | Output icons | Input icons |
195+
| ----------------------------------------------- | :-------------: | :--------------: | :------------------------: | :-----------: |
196+
| [FontAwesome](https://fontawesome.com) | `" , "` | `" "` or `" "` | `" "` or `" "` | `", "` |
197+
| [Material](https://material.io/resources/icons) | `" , , "` | `" "` or `"󰍭 "` | `" "` or `" "` or `" "` | `"󰍬, 󰍮"` |
198+
| Emoji | `"🔈 ,🔉 ,🔊 "` | `"🔇 "` | `"🔈 "` or `"🎧 "` | `"🎙️ "` |
199+
| Emoji v2 | `"🕨 ,🕩 ,🕪 "` | `"🔇 "` | `"🕨 "` or `"🎧 "` | `"🎤 "` |
169200

170201
Most of these can be used after downloading a [Nerd Font](https://www.nerdfonts.com/) and including it in your [Polybar config](https://github.com/polybar/polybar/wiki/Fonts). For example:
171202

0 commit comments

Comments
 (0)