1//! Thin but safe wrappers for [ALSA](https://alsa-project.org).
2//!
3//! [GitHub repo](https://github.com/diwic/alsa-rs)
4//!
5//! [Crates.io](https://crates.io/crates/alsa)
6//!
7//! This ALSA API wrapper/binding is WIP - the ALSA API is huge, and new
8//! functions and structs might be added as requested.
9//!
10//! Most functions map 1-to-1 to alsa-lib functions, e g, `ctl::CardInfo::get_id()` is a wrapper around
11//! `snd_ctl_card_info_get_id` and the [alsa-lib documentation](https://www.alsa-project.org/alsa-doc/alsa-lib/)
12//! can be consulted for additional information.
13//!
14//! Enjoy!
15
16#![allow(clippy::all)]
17#![warn(clippy::correctness, clippy::suspicious, clippy::perf)]
18
19extern crate alsa_sys as alsa;
20extern crate libc;
21#[macro_use]
22extern crate bitflags;
23
24macro_rules! alsa_enum {
25 ($(#[$attr:meta])+ $name:ident, $static_name:ident [$count:expr], $( $a:ident = $b:ident),* ,) =>
26{
27#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
28$(#[$attr])*
29pub enum $name {
30$(
31 $a = alsa::$b as isize,
32)*
33}
34
35static $static_name: [$name; $count] =
36 [ $( $name::$a, )* ];
37
38impl $name {
39 /// Returns a slice of all possible values; useful for iteration
40 pub fn all() -> &'static [$name] { &$static_name[..] }
41
42 #[allow(dead_code)]
43 fn from_c_int(c: ::libc::c_int, s: &'static str) -> Result<$name> {
44 Self::all().iter().find(|&&x| c == x as ::libc::c_int).map(|&x| x)
45 .ok_or_else(|| Error::unsupported(s))
46 }
47
48 #[allow(dead_code)]
49 fn to_c_int(&self) -> ::libc::c_int {
50 return *self as ::libc::c_int;
51 }
52}
53
54}
55}
56
57/// Replaces constants ending with PLAYBACK/CAPTURE as well as
58/// INPUT/OUTPUT
59#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
60pub enum Direction {
61 Playback,
62 Capture
63}
64impl Direction {
65 #[inline]
66 pub fn input() -> Direction { Direction::Capture }
67 #[inline]
68 pub fn output() -> Direction { Direction::Playback }
69}
70
71/// Used to restrict hw parameters. In case the submitted
72/// value is unavailable, in which direction should one search
73/// for available values?
74#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
75pub enum ValueOr {
76 /// The value set is the submitted value, or less
77 Less = -1,
78 /// The value set is the submitted value, or the nearest
79 Nearest = 0,
80 /// The value set is the submitted value, or greater
81 Greater = 1,
82}
83
84/// Rounding mode (used in some mixer related calls)
85#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
86pub enum Round {
87 /// Round down (towards negative infinity)
88 Floor = 0,
89 /// Round up (towards positive infinity)
90 Ceil = 1,
91}
92
93mod error;
94pub use crate::error::{Error, Result};
95
96pub mod card;
97pub use crate::card::Card as Card;
98
99mod ctl_int;
100pub mod ctl {
101 //! Control device API
102 pub use super::ctl_int::{Ctl, CardInfo, DeviceIter, ElemIface, ElemId, ElemType, ElemValue, ElemInfo};
103}
104
105pub use crate::ctl::Ctl as Ctl;
106
107pub mod hctl;
108pub use crate::hctl::HCtl as HCtl;
109
110pub mod pcm;
111pub use crate::pcm::PCM as PCM;
112
113pub mod rawmidi;
114pub use crate::rawmidi::Rawmidi as Rawmidi;
115
116pub mod device_name;
117
118pub mod poll;
119pub use crate::poll::Descriptors as PollDescriptors;
120
121pub mod mixer;
122pub use crate::mixer::Mixer as Mixer;
123
124pub mod seq;
125pub use crate::seq::Seq as Seq;
126
127mod io;
128pub use crate::io::Output;
129
130// Reexported inside PCM module
131mod chmap;
132
133pub mod direct;
134