pub struct Audio { /* private fields */ }Expand description
The audio service, from cx.audio(). Cloning it is cheap.
Implementations§
Source§impl Audio
impl Audio
Sourcepub fn peaks(
&self,
target: impl IntoProp<Option<PeakTarget>>,
) -> ReadSignal<Vec<f32>>
pub fn peaks( &self, target: impl IntoProp<Option<PeakTarget>>, ) -> ReadSignal<Vec<f32>>
A peak meter, as Quickshell’s PwNodePeakMonitor: each channel’s
loudest sample over the last 1/25 s, from 0 to 1, in the order of
the target’s channels. The loudest of them, Quickshell’s peak, is
peaks.with(|p| p.iter().copied().fold(0.0, f32::max)). Empty
before the first reading, while there is no target and once it goes;
all 0 while a sink plays nothing or a stream is paused.
target takes a PeakTarget or a closure returning an Option
of one: the meter moves when a signal the closure read changes, and
None stops it, as Quickshell’s enabled. A panic in the closure is
logged and stops the meter until the next change.
This is the one audio reading that wakes the shell while nothing changes on screen: while the meter records, libpulse’s thread and the shell wake 25 times a second. The signal is set only when a peak changes, so silence repaints nothing. A sink’s or a stream’s meter records only while something plays, is corked while nothing does, and never keeps a device awake; a source’s records all the time, as any recording of a microphone does. Nothing records until a config asks for a meter, and it stops when the context that asked goes.
On PipeWire a sink’s peaks come before its volume; a source’s and a stream’s come after their own volume, as a recording of them would.
Source§impl Audio
impl Audio
Sourcepub fn default_sink(&self) -> ReadSignal<Option<Sink>>
pub fn default_sink(&self) -> ReadSignal<Option<Sink>>
The default sink. None while there is no audio server or the
server has no sink. Every caller gets the same signal.
Sourcepub fn change_volume(&self, percent: i32)
pub fn change_volume(&self, percent: i32)
Changes the default sink’s volume by percent, louder when
positive, and keeps it within 0-100%, so a step from above 100%
lands on 100%. Every channel moves by the same amount, keeping their
balance, except that one reaching 0% or 100% stops there. With no
sink or no server it does nothing.
Sourcepub fn toggle_mute(&self)
pub fn toggle_mute(&self)
Mutes the default sink, or unmutes it. With no sink or no server it does nothing.
Sourcepub fn sinks(&self) -> ReadSignal<Vec<AudioNode>>
pub fn sinks(&self) -> ReadSignal<Vec<AudioNode>>
Every sink, in the server’s order. Empty while there is no server.
Sourcepub fn sources(&self) -> ReadSignal<Vec<AudioNode>>
pub fn sources(&self) -> ReadSignal<Vec<AudioNode>>
Every source except sinks’ monitors, in the server’s order.
Sourcepub fn default_source(&self) -> ReadSignal<Option<AudioNode>>
pub fn default_source(&self) -> ReadSignal<Option<AudioNode>>
The default source, where a call’s microphone sound comes from.
Sourcepub fn streams(&self) -> ReadSignal<Vec<AudioStream>>
pub fn streams(&self) -> ReadSignal<Vec<AudioStream>>
Every app playing sound, in the server’s order.
Sourcepub fn set_default_sink(&self, name: &str)
pub fn set_default_sink(&self, name: &str)
Makes the sink called name the default.
Sourcepub fn set_default_source(&self, name: &str)
pub fn set_default_source(&self, name: &str)
Makes the source called name the default.
Sourcepub fn set_sink_volume(&self, name: &str, percent: u32)
pub fn set_sink_volume(&self, name: &str, percent: u32)
Sets every channel of the sink called name to percent, at most
100.
Sourcepub fn set_sink_volumes(&self, name: &str, percents: &[u32])
pub fn set_sink_volumes(&self, name: &str, percents: &[u32])
Sets each channel of the sink called name to its own percent, at
most 100, in the order of AudioNode::channels, as a balance
slider does. A list of another length than the sink’s channels is
logged and not sent.
Sourcepub fn set_sink_mute(&self, name: &str, muted: bool)
pub fn set_sink_mute(&self, name: &str, muted: bool)
Mutes the sink called name, or unmutes it.
Sourcepub fn set_source_volume(&self, name: &str, percent: u32)
pub fn set_source_volume(&self, name: &str, percent: u32)
Sets every channel of the source called name to percent, at most
100.
Sourcepub fn set_source_volumes(&self, name: &str, percents: &[u32])
pub fn set_source_volumes(&self, name: &str, percents: &[u32])
Sets each channel of the source called name, as
set_sink_volumes does a sink’s.
Sourcepub fn set_source_mute(&self, name: &str, muted: bool)
pub fn set_source_mute(&self, name: &str, muted: bool)
Mutes the source called name, or unmutes it, as a microphone
button does.
Sourcepub fn set_stream_volume(&self, index: u32, percent: u32)
pub fn set_stream_volume(&self, index: u32, percent: u32)
Sets every channel of the stream numbered index to percent, at
most 100.
Sourcepub fn set_stream_volumes(&self, index: u32, percents: &[u32])
pub fn set_stream_volumes(&self, index: u32, percents: &[u32])
Sets each channel of the stream numbered index, as
set_sink_volumes does a sink’s.
Sourcepub fn set_stream_mute(&self, index: u32, muted: bool)
pub fn set_stream_mute(&self, index: u32, muted: bool)
Mutes the stream numbered index, or unmutes it.
Sourcepub fn move_stream(&self, index: u32, sink: &str)
pub fn move_stream(&self, index: u32, sink: &str)
Moves the stream numbered index to play to the sink called sink.