alsa-mixer-0.3.0: Bindings to the ALSA simple mixer API.

Copyright | (c) Thomas Tuegel 2011
License | BSD
Maintainer | Thomas Tuegel <ttuegel@gmail.com>
Stability | experimental
Portability | non-portable (Linux only)
Safe Haskell | Safe
Language | Haskell98

Sound.ALSA.Mixer

Contents

- Types
- Functions
  - Mixers
  - Controls
  - PerChannels
- Examples
  - Getting and setting the volume of a Control
  - Getting and setting the switch of a Control

Description

This library provides bindings to the Advanced Linux Sound Architecture (ALSA) library API. The portability of this library is limited to systems with ALSA (i.e., Linux systems). The functions in this library throw errors of type `T` on failure.

Synopsis

- data Control = Control {
  - index :: CUInt
  - name :: String
  - switch :: Either Switch (Maybe Switch, Maybe Switch)
  - volume :: Either Volume (Maybe Volume, Maybe Volume)
  }
- data Mixer
- data Channel
  - = Unknown
  - | FrontLeft
  - | SND_MIXER_SCHN_MONO
  - | FrontRight
  - | RearLeft
  - | RearRight
  - | FrontCenter
  - | Woofer
  - | SideLeft
  - | SideRight
  - | RearCenter
  - | Last
- data PerChannel e
  - = Joined {
    - getJoined :: IO e
    - setJoined :: e -> IO ()
    - joinedChannels :: [Channel]
    }
  - | PerChannel {
    - getPerChannel :: IO [(Channel, e)]
    - setPerChannel :: [(Channel, e)] -> IO ()
    - perChannels :: [Channel]
    }
- data Volume = Volume {
  - getRange :: IO (CLong, CLong)
  - setRange :: (CLong, CLong) -> IO ()
  - getRangeDb :: IO (CLong, CLong)
  - value :: PerChannel CLong
  - dB :: PerChannel CLong
  }
- type Switch = PerChannel Bool
- data CUInt
- data CLong
- controls :: Mixer -> IO [Control]
- withMixer :: String -> (Mixer -> IO a) -> IO a
- getControlByName :: Mixer -> String -> IO (Maybe Control)
- common :: Either a (Maybe a, Maybe a) -> Maybe a
- playback :: Either a (Maybe a, Maybe a) -> Maybe a
- capture :: Either a (Maybe a, Maybe a) -> Maybe a
- channels :: PerChannel e -> [Channel]
- allChannels :: [Channel]
- joined :: PerChannel e -> Bool
- perChannel :: PerChannel e -> Bool
- getChannel :: Channel -> PerChannel x -> IO (Maybe x)
- setChannel :: Channel -> PerChannel x -> x -> IO ()

# Types

data Control Source #

`Control` represents one of the controls belonging to an ALSA mixer element. Each control has a number of playback and capture channels. The control may also have a switch and/or a volume capability associated with it. The capability can be common to both playback and capture, or there can be separate capabilities for each.

Constructors

Control |

Fields

- index :: CUInt
- name :: String
- switch :: Either Switch (Maybe Switch, Maybe Switch)
- volume :: Either Volume (Maybe Volume, Maybe Volume)

data Mixer Source #

data Channel Source #

Constructors

Unknown |
FrontLeft |
SND_MIXER_SCHN_MONO |
FrontRight |
RearLeft |
RearRight |
FrontCenter |
Woofer |
SideLeft |
SideRight |
RearCenter |
Last |

#### Instances

Instances details

Enum Channel Source # |
Instance details Defined in Sound.ALSA.Mixer.Internal Methods succ :: Channel -> Channel pred :: Channel -> Channel toEnum :: Int -> Channel fromEnum :: Channel -> Int enumFrom :: Channel -> [Channel] enumFromThen :: Channel -> Channel -> [Channel] enumFromTo :: Channel -> Channel -> [Channel] enumFromThenTo :: Channel -> Channel -> Channel -> [Channel]
Eq Channel Source # |
Instance details Defined in Sound.ALSA.Mixer.Internal Methods (==) :: Channel -> Channel -> Bool (/=) :: Channel -> Channel -> Bool
Read Channel Source # |
Instance details Defined in Sound.ALSA.Mixer.Internal Methods readsPrec :: Int -> ReadS Channel readList :: ReadS [Channel] readPrec :: ReadPrec Channel readListPrec :: ReadPrec [Channel]
Show Channel Source # |
Instance details Defined in Sound.ALSA.Mixer.Internal Methods showsPrec :: Int -> Channel -> ShowS show :: Channel -> String showList :: [Channel] -> ShowS

data PerChannel e Source #

`PerChannel` represents a capability that with either a separate value for each channel or with a common value for all channels.

Constructors

Joined |

Fields

- getJoined :: IO e
- setJoined :: e -> IO ()
- joinedChannels :: [Channel]

PerChannel |

Fields

- getPerChannel :: IO [(Channel, e)]
- setPerChannel :: [(Channel, e)] -> IO ()
- perChannels :: [Channel]

data Volume Source #

`Volume` represents a volume capability. There may be a separate value per channel, but each capability has only one range.

Constructors

Volume |

Fields

- getRange :: IO (CLong, CLong)

  Returns the minimum and maximum volumes (unitless).

- setRange :: (CLong, CLong) -> IO ()

  Sets the minimum and maximum volumes (unitless).

- getRangeDb :: IO (CLong, CLong)

  Returns the minimum and maximum volumes in hundredths of a decibel.

- value :: PerChannel CLong

  Volume values for each channel.

- dB :: PerChannel CLong

  Volume values for each channel in hundredths of a decibel.

type Switch = PerChannel Bool Source #

`Switch` represents a switch capability for controls and channels that can be muted and unmuted.

data CUInt #

#### Instances

Instances details

Bounded CUInt |
Instance details Defined in Foreign.C.Types Methods minBound :: CUInt maxBound :: CUInt
Enum CUInt |
Instance details Defined in Foreign.C.Types Methods succ :: CUInt -> CUInt pred :: CUInt -> CUInt toEnum :: Int -> CUInt fromEnum :: CUInt -> Int enumFrom :: CUInt -> [CUInt] enumFromThen :: CUInt -> CUInt -> [CUInt] enumFromTo :: CUInt -> CUInt -> [CUInt] enumFromThenTo :: CUInt -> CUInt -> CUInt -> [CUInt]
Eq CUInt |
Instance details Defined in Foreign.C.Types Methods (==) :: CUInt -> CUInt -> Bool (/=) :: CUInt -> CUInt -> Bool
Integral CUInt |
Instance details Defined in Foreign.C.Types Methods quot :: CUInt -> CUInt -> CUInt rem :: CUInt -> CUInt -> CUInt div :: CUInt -> CUInt -> CUInt mod :: CUInt -> CUInt -> CUInt quotRem :: CUInt -> CUInt -> (CUInt, CUInt) divMod :: CUInt -> CUInt -> (CUInt, CUInt) toInteger :: CUInt -> Integer
Num CUInt |
Instance details Defined in Foreign.C.Types Methods (+) :: CUInt -> CUInt -> CUInt (-) :: CUInt -> CUInt -> CUInt (*) :: CUInt -> CUInt -> CUInt negate :: CUInt -> CUInt abs :: CUInt -> CUInt signum :: CUInt -> CUInt fromInteger :: Integer -> CUInt
Ord CUInt |
Instance details Defined in Foreign.C.Types Methods compare :: CUInt -> CUInt -> Ordering (<) :: CUInt -> CUInt -> Bool (<=) :: CUInt -> CUInt -> Bool (>) :: CUInt -> CUInt -> Bool (>=) :: CUInt -> CUInt -> Bool max :: CUInt -> CUInt -> CUInt min :: CUInt -> CUInt -> CUInt
Read CUInt |
Instance details Defined in Foreign.C.Types Methods readsPrec :: Int -> ReadS CUInt readList :: ReadS [CUInt] readPrec :: ReadPrec CUInt readListPrec :: ReadPrec [CUInt]
Real CUInt |
Instance details Defined in Foreign.C.Types Methods toRational :: CUInt -> Rational
Show CUInt |
Instance details Defined in Foreign.C.Types Methods showsPrec :: Int -> CUInt -> ShowS show :: CUInt -> String showList :: [CUInt] -> ShowS
Bits CUInt |

Instance details

Defined in Foreign.C.Types

Methods

(.&.) :: CUInt -> CUInt -> CUInt

(.|.) :: CUInt -> CUInt -> CUInt

xor :: CUInt -> CUInt -> CUInt

complement :: CUInt -> CUInt

shift :: CUInt -> Int -> CUInt

rotate :: CUInt -> Int -> CUInt

zeroBits :: CUInt

bit :: Int -> CUInt

setBit :: CUInt -> Int -> CUInt

clearBit :: CUInt -> Int -> CUInt

complementBit :: CUInt -> Int -> CUInt

testBit :: CUInt -> Int -> Bool

bitSizeMaybe :: CUInt -> Maybe Int

bitSize :: CUInt -> Int

isSigned :: CUInt -> Bool

shiftL :: CUInt -> Int -> CUInt

unsafeShiftL :: CUInt -> Int -> CUInt

shiftR :: CUInt -> Int -> CUInt

unsafeShiftR :: CUInt -> Int -> CUInt

rotateL :: CUInt -> Int -> CUInt

rotateR :: CUInt -> Int -> CUInt

popCount :: CUInt -> Int

FiniteBits CUInt |
Instance details Defined in Foreign.C.Types Methods finiteBitSize :: CUInt -> Int countLeadingZeros :: CUInt -> Int countTrailingZeros :: CUInt -> Int
Storable CUInt |
Instance details Defined in Foreign.C.Types Methods sizeOf :: CUInt -> Int alignment :: CUInt -> Int peekElemOff :: Ptr CUInt -> Int -> IO CUInt pokeElemOff :: Ptr CUInt -> Int -> CUInt -> IO () peekByteOff :: Ptr b -> Int -> IO CUInt pokeByteOff :: Ptr b -> Int -> CUInt -> IO () peek :: Ptr CUInt -> IO CUInt poke :: Ptr CUInt -> CUInt -> IO ()

data CLong #

#### Instances

Instances details

Bounded CLong |
Instance details Defined in Foreign.C.Types Methods minBound :: CLong maxBound :: CLong
Enum CLong |
Instance details Defined in Foreign.C.Types Methods succ :: CLong -> CLong pred :: CLong -> CLong toEnum :: Int -> CLong fromEnum :: CLong -> Int enumFrom :: CLong -> [CLong] enumFromThen :: CLong -> CLong -> [CLong] enumFromTo :: CLong -> CLong -> [CLong] enumFromThenTo :: CLong -> CLong -> CLong -> [CLong]
Eq CLong |
Instance details Defined in Foreign.C.Types Methods (==) :: CLong -> CLong -> Bool (/=) :: CLong -> CLong -> Bool
Integral CLong |
Instance details Defined in Foreign.C.Types Methods quot :: CLong -> CLong -> CLong rem :: CLong -> CLong -> CLong div :: CLong -> CLong -> CLong mod :: CLong -> CLong -> CLong quotRem :: CLong -> CLong -> (CLong, CLong) divMod :: CLong -> CLong -> (CLong, CLong) toInteger :: CLong -> Integer
Num CLong |
Instance details Defined in Foreign.C.Types Methods (+) :: CLong -> CLong -> CLong (-) :: CLong -> CLong -> CLong (*) :: CLong -> CLong -> CLong negate :: CLong -> CLong abs :: CLong -> CLong signum :: CLong -> CLong fromInteger :: Integer -> CLong
Ord CLong |
Instance details Defined in Foreign.C.Types Methods compare :: CLong -> CLong -> Ordering (<) :: CLong -> CLong -> Bool (<=) :: CLong -> CLong -> Bool (>) :: CLong -> CLong -> Bool (>=) :: CLong -> CLong -> Bool max :: CLong -> CLong -> CLong min :: CLong -> CLong -> CLong
Read CLong |
Instance details Defined in Foreign.C.Types Methods readsPrec :: Int -> ReadS CLong readList :: ReadS [CLong] readPrec :: ReadPrec CLong readListPrec :: ReadPrec [CLong]
Real CLong |
Instance details Defined in Foreign.C.Types Methods toRational :: CLong -> Rational
Show CLong |
Instance details Defined in Foreign.C.Types Methods showsPrec :: Int -> CLong -> ShowS show :: CLong -> String showList :: [CLong] -> ShowS
Bits CLong |

Instance details

Defined in Foreign.C.Types

Methods

(.&.) :: CLong -> CLong -> CLong

(.|.) :: CLong -> CLong -> CLong

xor :: CLong -> CLong -> CLong

complement :: CLong -> CLong

shift :: CLong -> Int -> CLong

rotate :: CLong -> Int -> CLong

zeroBits :: CLong

bit :: Int -> CLong

setBit :: CLong -> Int -> CLong

clearBit :: CLong -> Int -> CLong

complementBit :: CLong -> Int -> CLong

testBit :: CLong -> Int -> Bool

bitSizeMaybe :: CLong -> Maybe Int

bitSize :: CLong -> Int

isSigned :: CLong -> Bool

shiftL :: CLong -> Int -> CLong

unsafeShiftL :: CLong -> Int -> CLong

shiftR :: CLong -> Int -> CLong

unsafeShiftR :: CLong -> Int -> CLong

rotateL :: CLong -> Int -> CLong

rotateR :: CLong -> Int -> CLong

popCount :: CLong -> Int

FiniteBits CLong |
Instance details Defined in Foreign.C.Types Methods finiteBitSize :: CLong -> Int countLeadingZeros :: CLong -> Int countTrailingZeros :: CLong -> Int
Storable CLong |
Instance details Defined in Foreign.C.Types Methods sizeOf :: CLong -> Int alignment :: CLong -> Int peekElemOff :: Ptr CLong -> Int -> IO CLong pokeElemOff :: Ptr CLong -> Int -> CLong -> IO () peekByteOff :: Ptr b -> Int -> IO CLong pokeByteOff :: Ptr b -> Int -> CLong -> IO () peek :: Ptr CLong -> IO CLong poke :: Ptr CLong -> CLong -> IO ()

# Functions

## Mixers

controls :: Mixer -> IO [Control] Source #

All the `Control` objects associated with a particular `Mixer`.

withMixer :: String -> (Mixer -> IO a) -> IO a Source #

Perform an `IO` action with the named mixer. An exception of type `T` will be thrown if the named mixer cannot be found. A mixer named "default" should always exist.

## Controls

getControlByName Source #

Arguments

:: Mixer | Mixer
-> String | Control name
-> IO (Maybe Control) |

Get the named `Control`, if it exists, from the named `Mixer`.

common :: Either a (Maybe a, Maybe a) -> Maybe a Source #

For a given capability, which may be for either playback or capture, or common to both, return the common capability if it exists.

playback :: Either a (Maybe a, Maybe a) -> Maybe a Source #

For a given capability, which may be for either playback or capture, or common to both, return the playback capability if it exists.

capture :: Either a (Maybe a, Maybe a) -> Maybe a Source #

For a given capability, which may be for either playback or capture, or common to both, return the capture capability if it exists.

## PerChannels

channels :: PerChannel e -> [Channel] Source #

All channels supported by a `PerChannel` object.

allChannels :: [Channel] Source #

joined :: PerChannel e -> Bool Source #

True if the `PerChannel` object has a common value for all channels.

perChannel :: PerChannel e -> Bool Source #

True if the `PerChannel` object has a separate value for each channel.

getChannel :: Channel -> PerChannel x -> IO (Maybe x) Source #

Get the value associated with a particular channel, if that channel exists.

setChannel :: Channel -> PerChannel x -> x -> IO () Source #

Set the value associated with a particular channel, if that channel exists.

# Examples

## Getting and setting the volume of a Control

This example demonstrates the method of accessing the volume of a Control. The example function reads the volume and increases it by the value supplied.

      changeVolumeBy :: CLong -> IO ()
      changeVolumeBy i =
          withMixer "default" $ \mixer ->
            do Just control <- getControlByName mixer "Master"
               let Just playbackVolume = playback $ volume control
               (min, max) <- getRange playbackVolume
               Just vol <- getChannel FrontLeft $ value $ playbackVolume
               when ((i > 0 && vol < max) || (i < 0 && vol > min))
                 $ setChannel FrontLeft (value $ playbackVolume) $ vol + i

## Getting and setting the switch of a Control

This example demonstrates the method of accessing the switch of a Control. The example function reads the value of the switch and toggles it.

      toggleMute :: IO ()
      toggleMute =
          withMixer "default" $ \mixer ->
            do Just control <- getControlByName mixer "Master"
               let Just playbackSwitch = playback $ switch control
               Just sw <- getChannel FrontLeft playbackSwitch
               setChannel FrontLeft playbackSwitch $ not sw