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-Inferred
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 Source #

pred :: Channel -> Channel Source #

toEnum :: Int -> Channel Source #

fromEnum :: Channel -> Int Source #

enumFrom :: Channel -> [Channel] Source #

enumFromThen :: Channel -> Channel -> [Channel] Source #

enumFromTo :: Channel -> Channel -> [Channel] Source #

enumFromThenTo :: Channel -> Channel -> Channel -> [Channel] Source #

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

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 Source #

Haskell type representing the C `unsigned int` type. (The concrete types of Foreign.C.Types are platform-specific.)

#### Instances

Instances details

Storable CUInt |

Instance details

Defined in Foreign.C.Types

Methods

sizeOf :: CUInt -> Int Source #

alignment :: CUInt -> Int Source #

peekElemOff :: Ptr CUInt -> Int -> IO CUInt Source #

pokeElemOff :: Ptr CUInt -> Int -> CUInt -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO CUInt Source #

pokeByteOff :: Ptr b -> Int -> CUInt -> IO () Source #

peek :: Ptr CUInt -> IO CUInt Source #

poke :: Ptr CUInt -> CUInt -> IO () Source #

Bits CUInt |

Instance details

Defined in Foreign.C.Types

Methods

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

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

xor :: CUInt -> CUInt -> CUInt Source #

complement :: CUInt -> CUInt Source #

shift :: CUInt -> Int -> CUInt Source #

rotate :: CUInt -> Int -> CUInt Source #

zeroBits :: CUInt Source #

bit :: Int -> CUInt Source #

setBit :: CUInt -> Int -> CUInt Source #

clearBit :: CUInt -> Int -> CUInt Source #

complementBit :: CUInt -> Int -> CUInt Source #

testBit :: CUInt -> Int -> Bool Source #

bitSizeMaybe :: CUInt -> Maybe Int Source #

bitSize :: CUInt -> Int Source #

isSigned :: CUInt -> Bool Source #

shiftL :: CUInt -> Int -> CUInt Source #

unsafeShiftL :: CUInt -> Int -> CUInt Source #

shiftR :: CUInt -> Int -> CUInt Source #

unsafeShiftR :: CUInt -> Int -> CUInt Source #

rotateL :: CUInt -> Int -> CUInt Source #

rotateR :: CUInt -> Int -> CUInt Source #

popCount :: CUInt -> Int Source #

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

data CLong Source #

Haskell type representing the C `long` type. (The concrete types of Foreign.C.Types are platform-specific.)

#### Instances

Instances details

Storable CLong |

Instance details

Defined in Foreign.C.Types

Methods

sizeOf :: CLong -> Int Source #

alignment :: CLong -> Int Source #

peekElemOff :: Ptr CLong -> Int -> IO CLong Source #

pokeElemOff :: Ptr CLong -> Int -> CLong -> IO () Source #

peekByteOff :: Ptr b -> Int -> IO CLong Source #

pokeByteOff :: Ptr b -> Int -> CLong -> IO () Source #

peek :: Ptr CLong -> IO CLong Source #

poke :: Ptr CLong -> CLong -> IO () Source #

Bits CLong |

Instance details

Defined in Foreign.C.Types

Methods

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

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

xor :: CLong -> CLong -> CLong Source #

complement :: CLong -> CLong Source #

shift :: CLong -> Int -> CLong Source #

rotate :: CLong -> Int -> CLong Source #

zeroBits :: CLong Source #

bit :: Int -> CLong Source #

setBit :: CLong -> Int -> CLong Source #

clearBit :: CLong -> Int -> CLong Source #

complementBit :: CLong -> Int -> CLong Source #

testBit :: CLong -> Int -> Bool Source #

bitSizeMaybe :: CLong -> Maybe Int Source #

bitSize :: CLong -> Int Source #

isSigned :: CLong -> Bool Source #

shiftL :: CLong -> Int -> CLong Source #

unsafeShiftL :: CLong -> Int -> CLong Source #

shiftR :: CLong -> Int -> CLong Source #

unsafeShiftR :: CLong -> Int -> CLong Source #

rotateL :: CLong -> Int -> CLong Source #

rotateR :: CLong -> Int -> CLong Source #

popCount :: CLong -> Int Source #

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

# 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