Debian Codegraph @

third_party/rust/alsa/src/lib.rs

raw
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
19 extern crate alsa_sys as alsa;
20 extern crate libc;
21 #[macro_use]
22 extern crate bitflags;
23 #[macro_use]
24 extern crate nix as nix_the_crate;
25
26 macro_rules! alsa_enum {
27 ($(#[$attr:meta])+ $name:ident, $static_name:ident [$count:expr], $( $a:ident = $b:ident),* ,) =>
28 {
29 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
30 $(#[$attr])*
31 pub enum $name {
32 $(
33 $a = alsa::$b as isize,
34 )*
35 }
36
37 static $static_name: [$name; $count] =
38 [ $( $name::$a, )* ];
39
40 impl $name {
41 /// Returns a slice of all possible values; useful for iteration
42 pub fn all() -> &'static [$name] { &$static_name[..] }
43
44 #[allow(dead_code)]
45 fn from_c_int(c: ::libc::c_int, s: &'static str) -> Result<$name> {
46 Self::all().iter().find(|&&x| c == x as ::libc::c_int).map(|&x| x)
47 .ok_or_else(|| Error::unsupported(s))
48 }
49
50 #[allow(dead_code)]
51 fn to_c_int(&self) -> ::libc::c_int {
52 return *self as ::libc::c_int;
53 }
54 }
55
56 }
57 }
58
59 /// Replaces constants ending with PLAYBACK/CAPTURE as well as
60 /// INPUT/OUTPUT
61 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
62 pub enum Direction {
63 Playback,
64 Capture
65 }
66 impl Direction {
67 #[inline]
68 pub fn input() -> Direction { Direction::Capture }
69 #[inline]
70 pub fn output() -> Direction { Direction::Playback }
71 }
72
73 /// Used to restrict hw parameters. In case the submitted
74 /// value is unavailable, in which direction should one search
75 /// for available values?
76 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
77 pub enum ValueOr {
78 /// The value set is the submitted value, or less
79 Less = -1,
80 /// The value set is the submitted value, or the nearest
81 Nearest = 0,
82 /// The value set is the submitted value, or greater
83 Greater = 1,
84 }
85
86 /// Rounding mode (used in some mixer related calls)
87 #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
88 pub enum Round {
89 /// Round down (towards negative infinity)
90 Floor = 0,
91 /// Round up (towards positive infinity)
92 Ceil = 1,
93 }
94
95 mod error;
96 pub use crate::error::{Error, Result};
97
98 pub mod card;
99 pub use crate::card::Card as Card;
100
101 mod ctl_int;
102 pub mod ctl {
103 //! Control device API
104 pub use super::ctl_int::{Ctl, CardInfo, DeviceIter, ElemIface, ElemId, ElemType, ElemValue, ElemInfo};
105 }
106
107 pub use crate::ctl::Ctl as Ctl;
108
109 pub mod hctl;
110 pub use crate::hctl::HCtl as HCtl;
111
112 pub mod pcm;
113 pub use crate::pcm::PCM as PCM;
114
115 pub mod rawmidi;
116 pub use crate::rawmidi::Rawmidi as Rawmidi;
117
118 pub mod device_name;
119
120 pub mod poll;
121 pub use crate::poll::Descriptors as PollDescriptors;
122
123 pub mod mixer;
124 pub use crate::mixer::Mixer as Mixer;
125
126 pub mod seq;
127 pub use crate::seq::Seq as Seq;
128
129 mod io;
130 pub use crate::io::Output;
131
132 // Reexported inside PCM module
133 mod chmap;
134
135 pub mod direct;
136
137 /// Re-exports from the nix crate.
138 ///
139 /// Use these re-exports instead of also depending on the nix crate. There
140 /// is no guarantee that these will match a specific nix version, it may
141 /// change between minor updates of the library.
142 pub mod nix {
143 pub use nix_the_crate::Error;
144 pub use nix_the_crate::errno;
145 }