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

Portabilitynon-portable (Linux only)
Stabilityexperimental
MaintainerThomas Tuegel <ttuegel@gmail.com>
Safe HaskellNone

Sound.ALSA.Mixer

Contents

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).

Synopsis

Types

data Control

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.

type Mixer = ForeignPtr ()

data PerChannel e

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

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 (Integer, Integer)

Returns the minimum and maximum volumes (unitless).

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

Sets the minimum and maximum volumes (unitless).

getRangeDb :: IO (Integer, Integer)

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

value :: PerChannel Integer

Volume values for each channel.

dB :: PerChannel Integer

Volume values for each channel in hundredths of a decibel.

type Switch = PerChannel Bool

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

Functions

Mixers

controls :: Mixer -> IO [Control]

All the Control objects associated with a particular Mixer.

getMixerByName :: String -> IO Mixer

Returns the named Mixer. Will throw an exception if the named mixer cannot be found. A mixer named "default" should always exist.

Controls

getControlByName

Arguments

:: String

Mixer name

-> String

Control name

-> IO (Maybe Control) 

Get the named Control, if it exists, from the named Mixer. Will throw an exception if the named Mixer does not exist.

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

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

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

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]

All channels supported by a PerChannel object.

joined :: PerChannel e -> Bool

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

perChannel :: PerChannel e -> Bool

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

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

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

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

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 :: Integer -> IO ()
   changeVolumeBy i = do
       Just control <- getControlByName "default" "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 = do
       Just control <- getControlByName "default" "Master"
       let Just playbackSwitch = playback $ switch control
       Just sw <- getChannel FrontLeft playbackSwitch
       setChannel FrontLeft playbackSwitch $ not sw