Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(volume): Add pulseaudio backend #779

Merged
merged 16 commits into from
Jan 20, 2018
Merged

Conversation

NBonaparte
Copy link
Member

@NBonaparte NBonaparte commented Sep 26, 2017

Provides an option to use PulseAudio instead of ALSA for the volume module, which is determined at compile time. If both are available, it will be compiled with PulseAudio by default.
Provides a new PulseAudio module, including an adapter.

The only configuration option currently is sink, which provides the sink to be used as default (name can be found by running pacmd list-sinks). The backend subscribes to any changes in the PulseAudio sinks, so if the sinks change (e.g. headphones are unplugged) and the specified sink disappears, it will automatically revert to the default sink. Similarly, when the specified sink reappears, it will use it instead of the default. It seems like usually there is only one sink, so this option should be optional. The default configuration uses the default sink at all times.

Currently, there is no volume cap, so it can go over 100% to an extremely high value, as supported by PulseAudio (not sure whether to limit or leave it to the user).
The volume cap is set to PA_VOLUME_UI_MAX, which is the recommended maximum value for UIs.

To-Do after merge:

  • Add module wiki page
  • Rename internal/volume to internal/alsa
  • Deprecate internal/volume

@NBonaparte NBonaparte changed the title feat(volume): Add pulseaudio backend WIP: feat(volume): Add pulseaudio backend Sep 26, 2017
@patrick96
Copy link
Member

I have not looked at the code yet, but I think it's great that polybar gets native pulse support. One thing right away: I think it would be better to have a dedicated pulseaudio module instead of cramming the functionality into the same module.
This way people can setup either module without having to recompile everything and also the valid syntax of the volume module would not depend on how polybar was compiled. Also it would break all existing configurations that use the built-in volume module on systems that also have pulse installed, once polybar is recompiled.

I will try to take another look at this on the weekend and give some more feedback.
Thanks!

@NBonaparte
Copy link
Member Author

Yeah, I think I made a mess of the build configuration there as well. Since the volume module is essentially the alsa module, I think it would be best to rename it to alsa and deprecate volume (but still link the option internal/volume to internal/alsa for now).

@patrick96
Copy link
Member

Yeah, I thought the same thing. And once we push the next major release we can remove the internal/volume module.

@NBonaparte
Copy link
Member Author

Should I rename the volume module in this PR or do it separately?

@patrick96
Copy link
Member

I think we leave it like it is in this PR and open a separate one, once this one is merged

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now tested this on my machine and it works great.
I think we should cap the volume at 100% because the user can increase the volume with the scroll wheel which can go pretty fast.
There should probably be more log messages as well.
For example warn, whenever the fallback sink is used.

Looking at modules/pulseaudio.cpp, it seems that it shares a lot of code with the alsa module, and I think that is why you wanted them to be the same module in the first place, especially for loading the format-* and label-* settings and in the builder. Would it be feasible to create a sort of abstract volume module that contains all the functionality used by both modules (builder, event handler, common formatting config parameters etc), which both modules call upon?

@NBonaparte
Copy link
Member Author

I've added logging, a volume limit, and cleaned up some redundant volume retrieving.

If an abstract module were to be built, it would only have get_output(), get_format(), part of update(), and part of the constructor. Creating one would probably make things too complicated.

@NBonaparte NBonaparte modified the milestone: 3.1.0 Oct 29, 2017
@NBonaparte NBonaparte changed the title WIP: feat(volume): Add pulseaudio backend feat(volume): Add pulseaudio backend Nov 27, 2017
@patrick96 patrick96 added this to the 3.2.0 milestone Dec 3, 2017
@patrick96
Copy link
Member

Sorry for the wait on this. This is quite a big PR and I haven't had the time to review it properly. I will try to get in some thourough testing in the next few weeks.

@NBonaparte
Copy link
Member Author

Have you had a chance to test this yet?

@patrick96
Copy link
Member

I'm sorry, I haven't. My exams start in a week and I'm busy studying. I'll try to fit in some testing on my laptop and desktop on the weekend (nothing too thourough though)

Copy link
Member

@patrick96 patrick96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now tested this on my laptop and desktop and everything seems to work. I also tested it with wired and usb headphones. I only tried it on arch, it could be that other distros may have problems, but I think we can merge this and then handle issues in other distros, as they come in

@NBonaparte NBonaparte merged commit 3af3aea into polybar:master Jan 20, 2018
@NBonaparte NBonaparte deleted the pulseaudio branch January 27, 2018 05:12
patrick96 added a commit that referenced this pull request Jul 23, 2018
Breaking Changes:

* `0 < label-NAME-maxlen < 3` will now throw an exception and disable the containing module, if ellipsis is enabled for that label. (#1198)

Changelog:

Deprecations:
* `internal/volume` is now called `internal/alsa` (#967)
* temperature: The `%temperature%` is deprecated in favor of `%temperature-c%`(#897)
* mpd: `icon-repeatone` is deprecated in favor of `icon-single` (#1295), see #1279

Features:
* feat(mpd): Add support for icon-consume (#861)
* feat(bspwm): Add workspace separator (#942) 
* feat(i3): Add workspace separator (#938), see #929
* feat(build): Make polybar build on FreeBSD (#931, polybar/xpp#8), see #239
* feat(volume): Add pulseaudio backend (#779)
* feat(script): Add %pid% token for tail commands (#934)
* feat(temp): Add temperature tokens without unit (#897)
* feat(memory): Add memory used/free ramp (#1038), see #1037
* feat(memory): Add swap tokens (#1018) 
* feat(net): Add unknown-as-up option (#1077), see #457
* feat(config): Support fractional size and offset (#972), see #953
* feat(xwindow): Add label-empty (#1136)
* feat(battery): Add animation-discharging (analog to animation-charging) (#1190)
* feat(config): Support pixel offset for bar size and offset values (#1224)
* feat(mpd): Add `%album-artist%` token (#1263)
* feat(net): Add local_ip6 token (#1239), see #1234
* feat(net): Add nl80211 support (#1009), see #277

Fixes:
* fix(mpd): Wrong elapsed time when after standby (#921), see #915
* fix(config): Wrong min, maxlen when using the same token multiple times (#974), see #971
* fix(battery): use power_now correctly (#958), see #928
* fix(mpd): Crash when mpd isn't running (#983), see #979
* fix(xworkspaces): Respect 'enable-scroll' (#1002)
* fix(xbacklight): Respect 'enable-scroll' (#1014)
* fix(build): support xcb-proto >=1.13 (polybar/xpp#11), see #973
* fix(mpd): Respect MPD_HOST env variable (#1025), see #1007
* fix(i3): Reconnect i3 IPC socket on restart/error (#1099), see #762
* fix(cursor): Occasional crash on mouseover (#1124), see #1117
* fix(net): Mark 'not connected' on querying failure (#1171), see #1163
* fix(gcc): Fix -Wstringop-truncation warning (#1216, polybar/i3ipcpp#7), see #1215
* fix(builder): Don't truncate colors with same channels (#1217), see #1183
* fix(bspwm): Consistent behavior when scrolling through multiple desktops (#986), see #981
* fix(builder): Respect label-ellipsis option (#1198), see #1194
@patrick96
Copy link
Member

@NBonaparte Why do we check for the pulseaudio binary in addition to the libpulse library?

If we only checked for the library we could change the dependency in the AUR frompulseaudio to only libpulse.

@NBonaparte
Copy link
Member Author

You can have libpulse installed without having pulseaudio. For instance, chromium only requires the former, and I tried to run pulseaudio a long time ago before realizing I actually didn’t have the binary installed.

@patrick96
Copy link
Member

Ah, I see. But the binary is not necessary for polybar to run?

@NBonaparte
Copy link
Member Author

Yeah I suppose. It would be up to the user to ensure that they actually have the binary installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants