Skip to content

Commit

Permalink
pipewire: update beep example to support pipewire
Browse files Browse the repository at this point in the history
Signed-off-by: mbodmer <marc.bodmer@email.ch>
  • Loading branch information
mbodmer authored and ImUrX committed Jan 28, 2023
1 parent 483e344 commit 739b623
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions examples/beep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,26 @@ struct Opt {
#[arg(short, long)]
#[allow(dead_code)]
jack: bool,
/// Use the Pipewire host
#[cfg(all(
any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd"
),
feature = "pipewire"
))]
#[allow(dead_code)]
pipewire: bool,
}

fn main() -> anyhow::Result<()> {
let opt = Opt::parse();

// Conditionally compile with jack if the feature is specified.
// Manually check for flags. Can be passed through cargo with -- e.g.
// cargo run --release --example beep --features jack -- --jack
#[cfg(all(
any(
target_os = "linux",
Expand All @@ -40,8 +54,6 @@ fn main() -> anyhow::Result<()> {
),
feature = "jack"
))]
// Manually check for flags. Can be passed through cargo with -- e.g.
// cargo run --release --example beep --features jack -- --jack
let host = if opt.jack {
cpal::host_from_id(cpal::available_hosts()
.into_iter()
Expand All @@ -53,14 +65,37 @@ fn main() -> anyhow::Result<()> {
cpal::default_host()
};

// Conditionally compile with PipeWire if the feature is specified.
#[cfg(all(
any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd"
),
feature = "pipewire"
))]
// Manually check for flags. Can be passed through cargo with -- e.g.
// cargo run --release --example beep --features pipewire -- --pipewire
let host = if opt.pipewire {
cpal::host_from_id(cpal::available_hosts()
.into_iter()
.find(|id| *id == cpal::HostId::PipeWire)
.expect(
"make sure --features pipewire is specified. only works on OSes where PipeWire is available",
)).expect("PipeWire host unavailable")
} else {
cpal::default_host()
};

#[cfg(any(
not(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd"
)),
not(feature = "jack")
not(any(feature = "jack", feature = "pipewire"))
))]
let host = cpal::default_host();

Expand Down

0 comments on commit 739b623

Please sign in to comment.