| 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 | |
| 24 | macro_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])* |
| 29 | pub enum $name { |
| 30 | $( |
| 31 | $a = alsa::$b as isize, |
| 32 | )* |
| 33 | } |
| 34 | |
| 35 | static $static_name: [$name; $count] = |
| 36 | [ $( $name::$a, )* ]; |
| 37 | |
| 38 | impl $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)] |
| 60 | pub enum Direction { |
| 61 | Playback, |
| 62 | Capture |
| 63 | } |
| 64 | impl 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)] |
| 75 | pub 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)] |
| 86 | pub enum Round { |
| 87 | /// Round down (towards negative infinity) |
| 88 | Floor = 0, |
| 89 | /// Round up (towards positive infinity) |
| 90 | Ceil = 1, |
| 91 | } |
| 92 | |
| 93 | mod error; |
| 94 | pub use crate::error::{Error, Result}; |
| 95 | |
| 96 | pub mod card; |
| 97 | pub use crate::card::Card as Card; |
| 98 | |
| 99 | mod ctl_int; |
| 100 | pub mod ctl { |
| 101 | //! Control device API |
| 102 | pub use super::ctl_int::{Ctl, CardInfo, DeviceIter, ElemIface, ElemId, ElemType, ElemValue, ElemInfo}; |
| 103 | } |
| 104 | |
| 105 | pub use crate::ctl::Ctl as Ctl; |
| 106 | |
| 107 | pub mod hctl; |
| 108 | pub use crate::hctl::HCtl as HCtl; |
| 109 | |
| 110 | pub mod pcm; |
| 111 | pub use crate::pcm::PCM as PCM; |
| 112 | |
| 113 | pub mod rawmidi; |
| 114 | pub use crate::rawmidi::Rawmidi as Rawmidi; |
| 115 | |
| 116 | pub mod device_name; |
| 117 | |
| 118 | pub mod poll; |
| 119 | pub use crate::poll::Descriptors as PollDescriptors; |
| 120 | |
| 121 | pub mod mixer; |
| 122 | pub use crate::mixer::Mixer as Mixer; |
| 123 | |
| 124 | pub mod seq; |
| 125 | pub use crate::seq::Seq as Seq; |
| 126 | |
| 127 | mod io; |
| 128 | pub use crate::io::Output; |
| 129 | |
| 130 | // Reexported inside PCM module |
| 131 | mod chmap; |
| 132 | |
| 133 | pub mod direct; |
| 134 | |