module Sound.ALSA.Mixer
(
Control(..)
, Mixer()
, Channel(..)
, PerChannel(..)
, Volume(..)
, Switch()
, CUInt
, CLong
, controls
, withMixer
, getControlByName
, common
, playback
, capture
, channels
, allChannels
, joined
, perChannel
, getChannel
, setChannel
) where
import Control.Monad ( forM, liftM, when )
import Data.Maybe ( catMaybes )
import Foreign.C.Error ( Errno(..) )
import Foreign.C.Types
import Sound.ALSA.Exception ( catchErrno )
import Sound.ALSA.Mixer.Internal
data Control = Control { Control -> CUInt
index :: CUInt
, Control -> String
name :: String
, Control -> Either Switch (Maybe Switch, Maybe Switch)
switch :: Either Switch (Maybe Switch, Maybe Switch)
, Control -> Either Volume (Maybe Volume, Maybe Volume)
volume :: Either Volume (Maybe Volume, Maybe Volume)
}
data PerChannel e = Joined { forall e. PerChannel e -> IO e
getJoined :: IO e
, forall e. PerChannel e -> e -> IO ()
setJoined :: e -> IO ()
, forall e. PerChannel e -> [Channel]
joinedChannels :: [Channel]
}
| PerChannel { forall e. PerChannel e -> IO [(Channel, e)]
getPerChannel :: IO [(Channel, e)]
, forall e. PerChannel e -> [(Channel, e)] -> IO ()
setPerChannel :: [(Channel, e)] -> IO ()
, forall e. PerChannel e -> [Channel]
perChannels :: [Channel]
}
joined :: PerChannel e -> Bool
joined :: forall e. PerChannel e -> Bool
joined j :: PerChannel e
j@(Joined IO e
_ e -> IO ()
_ [Channel]
_) = Bool
True
joined PerChannel e
_ = Bool
False
perChannel :: PerChannel e -> Bool
perChannel :: forall e. PerChannel e -> Bool
perChannel p :: PerChannel e
p@(PerChannel IO [(Channel, e)]
_ [(Channel, e)] -> IO ()
_ [Channel]
_) = Bool
True
perChannel PerChannel e
_ = Bool
False
channels :: PerChannel e -> [Channel]
channels :: forall e. PerChannel e -> [Channel]
channels PerChannel e
p | forall e. PerChannel e -> Bool
joined PerChannel e
p = forall e. PerChannel e -> [Channel]
joinedChannels PerChannel e
p
| Bool
otherwise = forall e. PerChannel e -> [Channel]
perChannels PerChannel e
p
type Switch = PerChannel Bool
data Volume = Volume { Volume -> IO (CLong, CLong)
getRange :: IO (CLong, CLong)
, Volume -> (CLong, CLong) -> IO ()
setRange :: (CLong, CLong) -> IO ()
, Volume -> IO (CLong, CLong)
getRangeDb :: IO (CLong, CLong)
, Volume -> PerChannel CLong
value :: PerChannel CLong
, Volume -> PerChannel CLong
dB :: PerChannel CLong
}
getChannel :: Channel -> PerChannel x -> IO (Maybe x)
getChannel :: forall x. Channel -> PerChannel x -> IO (Maybe x)
getChannel Channel
c PerChannel x
p | forall e. PerChannel e -> Bool
joined PerChannel x
p = let r :: IO (Maybe x)
r | Channel
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall e. PerChannel e -> [Channel]
channels PerChannel x
p =
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall e. PerChannel e -> IO e
getJoined PerChannel x
p
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
in IO (Maybe x)
r
| Bool
otherwise = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Channel
c) forall a b. (a -> b) -> a -> b
$ forall e. PerChannel e -> IO [(Channel, e)]
getPerChannel PerChannel x
p
setChannel :: Channel -> PerChannel x -> x -> IO ()
setChannel :: forall x. Channel -> PerChannel x -> x -> IO ()
setChannel Channel
c PerChannel x
p x
v | forall e. PerChannel e -> Bool
joined PerChannel x
p = forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Channel
c forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall e. PerChannel e -> [Channel]
channels PerChannel x
p) forall a b. (a -> b) -> a -> b
$ forall e. PerChannel e -> e -> IO ()
setJoined PerChannel x
p x
v
| Bool
otherwise = forall e. PerChannel e -> [(Channel, e)] -> IO ()
setPerChannel PerChannel x
p [(Channel
c, x
v)]
playback :: Either a (Maybe a, Maybe a) -> Maybe a
playback :: forall a. Either a (Maybe a, Maybe a) -> Maybe a
playback (Left a
_) = forall a. Maybe a
Nothing
playback (Right (Maybe a
x, Maybe a
_)) = Maybe a
x
capture :: Either a (Maybe a, Maybe a) -> Maybe a
capture :: forall a. Either a (Maybe a, Maybe a) -> Maybe a
capture (Left a
_) = forall a. Maybe a
Nothing
capture (Right (Maybe a
_, Maybe a
x)) = Maybe a
x
common :: Either a (Maybe a, Maybe a) -> Maybe a
common :: forall a. Either a (Maybe a, Maybe a) -> Maybe a
common (Left a
x) = forall a. a -> Maybe a
Just a
x
common (Right (Maybe a, Maybe a)
_) = forall a. Maybe a
Nothing
mkSwitch :: SimpleElement -> IO (Either Switch (Maybe Switch, Maybe Switch))
mkSwitch :: SimpleElement -> IO (Either Switch (Maybe Switch, Maybe Switch))
mkSwitch SimpleElement
se = do
[Bool]
hasPlayChan <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SimpleElement -> Channel -> IO Bool
hasPlaybackChannel SimpleElement
se) [Channel]
allChannels
[Bool]
hasCaptChan <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SimpleElement -> Channel -> IO Bool
hasCaptureChannel SimpleElement
se) [Channel]
allChannels
let pChans :: [Channel]
pChans = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Channel]
allChannels [Bool]
hasPlayChan
cChans :: [Channel]
cChans = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Channel]
allChannels [Bool]
hasCaptChan
Bool
hasComSw <- SimpleElement -> IO Bool
hasCommonSwitch SimpleElement
se
Bool
hasPlaySw <- SimpleElement -> IO Bool
hasPlaybackSwitch SimpleElement
se
Bool
hasPlaySwJ <- SimpleElement -> IO Bool
hasPlaybackSwitchJoined SimpleElement
se
Bool
hasCaptSw <- SimpleElement -> IO Bool
hasCaptureSwitch SimpleElement
se
Bool
hasCaptSwJ <- SimpleElement -> IO Bool
hasCaptureSwitchJoined SimpleElement
se
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
hasComSw
then forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ if Bool
hasPlaySwJ
then [Channel] -> Switch
comJoinedSwitch [Channel]
pChans
else [Channel] -> Switch
comPerChannelSwitch [Channel]
pChans
else let playSw :: Maybe Switch
playSw | Bool -> Bool
not Bool
hasPlaySw = forall a. Maybe a
Nothing
| Bool
otherwise = forall a. a -> Maybe a
Just
forall a b. (a -> b) -> a -> b
$ if Bool
hasPlaySwJ
then [Channel] -> Switch
playJoinedSwitch [Channel]
pChans
else [Channel] -> Switch
playPerChannelSwitch [Channel]
pChans
captSw :: Maybe Switch
captSw | Bool -> Bool
not Bool
hasCaptSw = forall a. Maybe a
Nothing
| Bool
otherwise = forall a. a -> Maybe a
Just
forall a b. (a -> b) -> a -> b
$ if Bool
hasCaptSwJ
then [Channel] -> Switch
captJoinedSwitch [Channel]
cChans
else [Channel] -> Switch
captPerChannelSwitch [Channel]
cChans
in forall a b. b -> Either a b
Right (Maybe Switch
playSw, Maybe Switch
captSw)
where joined :: (SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
joined SimpleElement -> Channel -> IO e
fGet SimpleElement -> Channel -> e -> IO ()
fSet [Channel]
chans =
Joined { getJoined :: IO e
getJoined = SimpleElement -> Channel -> IO e
fGet SimpleElement
se (forall a. [a] -> a
head [Channel]
chans)
, setJoined :: e -> IO ()
setJoined = SimpleElement -> Channel -> e -> IO ()
fSet SimpleElement
se (forall a. [a] -> a
head [Channel]
chans)
, joinedChannels :: [Channel]
joinedChannels = [Channel]
chans
}
perChannel :: (SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
perChannel SimpleElement -> Channel -> IO e
fGet SimpleElement -> Channel -> e -> IO b
fSet [Channel]
chans =
PerChannel { getPerChannel :: IO [(Channel, e)]
getPerChannel = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall a b. [a] -> [b] -> [(a, b)]
zip [Channel]
chans)
forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SimpleElement -> Channel -> IO e
fGet SimpleElement
se) [Channel]
chans
, setPerChannel :: [(Channel, e)] -> IO ()
setPerChannel = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (SimpleElement -> Channel -> e -> IO b
fSet SimpleElement
se))
, perChannels :: [Channel]
perChannels = [Channel]
chans
}
comJoinedSwitch :: [Channel] -> Switch
comJoinedSwitch = forall {e}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
joined SimpleElement -> Channel -> IO Bool
getPlaybackSwitch SimpleElement -> Channel -> Bool -> IO ()
setPlaybackSwitch
comPerChannelSwitch :: [Channel] -> Switch
comPerChannelSwitch = forall {e} {b}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
perChannel SimpleElement -> Channel -> IO Bool
getPlaybackSwitch SimpleElement -> Channel -> Bool -> IO ()
setPlaybackSwitch
playJoinedSwitch :: [Channel] -> Switch
playJoinedSwitch = [Channel] -> Switch
comJoinedSwitch
playPerChannelSwitch :: [Channel] -> Switch
playPerChannelSwitch = [Channel] -> Switch
comPerChannelSwitch
captJoinedSwitch :: [Channel] -> Switch
captJoinedSwitch = forall {e}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
joined SimpleElement -> Channel -> IO Bool
getCaptureSwitch SimpleElement -> Channel -> Bool -> IO ()
setCaptureSwitch
captPerChannelSwitch :: [Channel] -> Switch
captPerChannelSwitch = forall {e} {b}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
perChannel SimpleElement -> Channel -> IO Bool
getCaptureSwitch SimpleElement -> Channel -> Bool -> IO ()
setCaptureSwitch
mkVolume :: SimpleElement -> IO (Either Volume (Maybe Volume, Maybe Volume))
mkVolume :: SimpleElement -> IO (Either Volume (Maybe Volume, Maybe Volume))
mkVolume SimpleElement
se = do
[Bool]
hasPlayChan <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SimpleElement -> Channel -> IO Bool
hasPlaybackChannel SimpleElement
se) [Channel]
allChannels
[Bool]
hasCaptChan <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SimpleElement -> Channel -> IO Bool
hasCaptureChannel SimpleElement
se) [Channel]
allChannels
let pChans :: [Channel]
pChans = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Channel]
allChannels [Bool]
hasPlayChan
cChans :: [Channel]
cChans = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Channel]
allChannels [Bool]
hasCaptChan
Bool
hasComV <- SimpleElement -> IO Bool
hasCommonVolume SimpleElement
se
Bool
hasPlayV <- SimpleElement -> IO Bool
hasPlaybackVolume SimpleElement
se
Bool
hasPlayVJ <- SimpleElement -> IO Bool
hasPlaybackVolumeJoined SimpleElement
se
Bool
hasCaptV <- SimpleElement -> IO Bool
hasCaptureVolume SimpleElement
se
Bool
hasCaptVJ <- SimpleElement -> IO Bool
hasCaptureVolumeJoined SimpleElement
se
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$
if Bool
hasComV
then let (PerChannel CLong
v, PerChannel CLong
d) | Bool
hasPlayVJ = ( [Channel] -> PerChannel CLong
comJoinedVol [Channel]
pChans
, [Channel] -> PerChannel CLong
comJoinedDb [Channel]
pChans
)
| Bool
otherwise = ( [Channel] -> PerChannel CLong
comPerChannelVol [Channel]
pChans
, [Channel] -> PerChannel CLong
comPerChannelDb [Channel]
pChans
)
in forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Volume
playVolume { value :: PerChannel CLong
value = PerChannel CLong
v, dB :: PerChannel CLong
dB = PerChannel CLong
d }
else let playVol :: Maybe Volume
playVol | Bool -> Bool
not Bool
hasPlayV = forall a. Maybe a
Nothing
| Bool
otherwise =
let (PerChannel CLong
v, PerChannel CLong
d) | Bool
hasPlayVJ =
( [Channel] -> PerChannel CLong
playJoinedVol [Channel]
pChans
, [Channel] -> PerChannel CLong
playJoinedDb [Channel]
pChans
)
| Bool
otherwise =
( [Channel] -> PerChannel CLong
playPerChannelVol [Channel]
pChans
, [Channel] -> PerChannel CLong
playPerChannelDb [Channel]
pChans
)
in forall a. a -> Maybe a
Just Volume
playVolume { value :: PerChannel CLong
value = PerChannel CLong
v, dB :: PerChannel CLong
dB = PerChannel CLong
d }
captVol :: Maybe Volume
captVol | Bool -> Bool
not Bool
hasCaptV = forall a. Maybe a
Nothing
| Bool
otherwise =
let (PerChannel CLong
v, PerChannel CLong
d) | Bool
hasCaptVJ =
( [Channel] -> PerChannel CLong
captJoinedVol [Channel]
cChans
, [Channel] -> PerChannel CLong
captJoinedDb [Channel]
cChans
)
| Bool
otherwise =
( [Channel] -> PerChannel CLong
captPerChannelVol [Channel]
cChans
, [Channel] -> PerChannel CLong
captPerChannelDb [Channel]
cChans
)
in forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Volume
captVolume { value :: PerChannel CLong
value = PerChannel CLong
v, dB :: PerChannel CLong
dB = PerChannel CLong
d }
in forall a b. b -> Either a b
Right (Maybe Volume
playVol, Maybe Volume
captVol)
where j :: (SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
j SimpleElement -> Channel -> IO e
fGet SimpleElement -> Channel -> e -> IO ()
fSet [Channel]
chans =
Joined { getJoined :: IO e
getJoined = SimpleElement -> Channel -> IO e
fGet SimpleElement
se (forall a. [a] -> a
head [Channel]
chans)
, setJoined :: e -> IO ()
setJoined = SimpleElement -> Channel -> e -> IO ()
fSet SimpleElement
se (forall a. [a] -> a
head [Channel]
chans)
, joinedChannels :: [Channel]
joinedChannels = [Channel]
chans
}
pc :: (SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
pc SimpleElement -> Channel -> IO e
fGet SimpleElement -> Channel -> e -> IO b
fSet [Channel]
chans =
PerChannel { getPerChannel :: IO [(Channel, e)]
getPerChannel = forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (forall a b. [a] -> [b] -> [(a, b)]
zip [Channel]
chans)
forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (SimpleElement -> Channel -> IO e
fGet SimpleElement
se) [Channel]
chans
, setPerChannel :: [(Channel, e)] -> IO ()
setPerChannel = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (SimpleElement -> Channel -> e -> IO b
fSet SimpleElement
se))
, perChannels :: [Channel]
perChannels = [Channel]
chans
}
playVolume :: Volume
playVolume = Volume { getRange :: IO (CLong, CLong)
getRange = SimpleElement -> IO (CLong, CLong)
getPlaybackVolumeRange SimpleElement
se
, setRange :: (CLong, CLong) -> IO ()
setRange = SimpleElement -> (CLong, CLong) -> IO ()
setPlaybackVolumeRange SimpleElement
se
, getRangeDb :: IO (CLong, CLong)
getRangeDb = SimpleElement -> IO (CLong, CLong)
getPlaybackDbRange SimpleElement
se
, value :: PerChannel CLong
value = forall a. HasCallStack => a
undefined
, dB :: PerChannel CLong
dB = forall a. HasCallStack => a
undefined
}
captVolume :: Volume
captVolume = Volume { getRange :: IO (CLong, CLong)
getRange = SimpleElement -> IO (CLong, CLong)
getCaptureVolumeRange SimpleElement
se
, setRange :: (CLong, CLong) -> IO ()
setRange = SimpleElement -> (CLong, CLong) -> IO ()
setCaptureVolumeRange SimpleElement
se
, getRangeDb :: IO (CLong, CLong)
getRangeDb = SimpleElement -> IO (CLong, CLong)
getCaptureDbRange SimpleElement
se
, value :: PerChannel CLong
value = forall a. HasCallStack => a
undefined
, dB :: PerChannel CLong
dB = forall a. HasCallStack => a
undefined
}
comJoinedVol :: [Channel] -> PerChannel CLong
comJoinedVol = forall {e}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
j SimpleElement -> Channel -> IO CLong
getPlaybackVolume SimpleElement -> Channel -> CLong -> IO ()
setPlaybackVolume
comJoinedDb :: [Channel] -> PerChannel CLong
comJoinedDb = forall {e}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
j SimpleElement -> Channel -> IO CLong
getPlaybackDb SimpleElement -> Channel -> CLong -> IO ()
setPlaybackDb
comPerChannelVol :: [Channel] -> PerChannel CLong
comPerChannelVol = forall {e} {b}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
pc SimpleElement -> Channel -> IO CLong
getPlaybackVolume SimpleElement -> Channel -> CLong -> IO ()
setPlaybackVolume
comPerChannelDb :: [Channel] -> PerChannel CLong
comPerChannelDb = forall {e} {b}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
pc SimpleElement -> Channel -> IO CLong
getPlaybackDb SimpleElement -> Channel -> CLong -> IO ()
setPlaybackDb
playJoinedVol :: [Channel] -> PerChannel CLong
playJoinedVol = [Channel] -> PerChannel CLong
comJoinedVol
playPerChannelVol :: [Channel] -> PerChannel CLong
playPerChannelVol = [Channel] -> PerChannel CLong
comPerChannelVol
playJoinedDb :: [Channel] -> PerChannel CLong
playJoinedDb = [Channel] -> PerChannel CLong
comJoinedDb
playPerChannelDb :: [Channel] -> PerChannel CLong
playPerChannelDb = [Channel] -> PerChannel CLong
comPerChannelDb
captJoinedVol :: [Channel] -> PerChannel CLong
captJoinedVol = forall {e}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
j SimpleElement -> Channel -> IO CLong
getCaptureVolume SimpleElement -> Channel -> CLong -> IO ()
setCaptureVolume
captPerChannelVol :: [Channel] -> PerChannel CLong
captPerChannelVol = forall {e} {b}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
pc SimpleElement -> Channel -> IO CLong
getCaptureVolume SimpleElement -> Channel -> CLong -> IO ()
setCaptureVolume
captJoinedDb :: [Channel] -> PerChannel CLong
captJoinedDb = forall {e}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO ())
-> [Channel]
-> PerChannel e
j SimpleElement -> Channel -> IO CLong
getCaptureDb SimpleElement -> Channel -> CLong -> IO ()
setCaptureDb
captPerChannelDb :: [Channel] -> PerChannel CLong
captPerChannelDb = forall {e} {b}.
(SimpleElement -> Channel -> IO e)
-> (SimpleElement -> Channel -> e -> IO b)
-> [Channel]
-> PerChannel e
pc SimpleElement -> Channel -> IO CLong
getCaptureDb SimpleElement -> Channel -> CLong -> IO ()
setCaptureDb
controls :: Mixer -> IO [Control]
controls :: Mixer -> IO [Control]
controls Mixer
mix = do
[(SimpleElementId, SimpleElement)]
es <- Mixer -> IO [(SimpleElementId, SimpleElement)]
elements Mixer
mix
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(SimpleElementId, SimpleElement)]
es forall a b. (a -> b) -> a -> b
$ \(SimpleElementId
idN, SimpleElement
se) -> do
String
n <- SimpleElementId -> IO String
getName SimpleElementId
idN
CUInt
i <- SimpleElementId -> IO CUInt
getIndex SimpleElementId
idN
Either Switch (Maybe Switch, Maybe Switch)
sw <- SimpleElement -> IO (Either Switch (Maybe Switch, Maybe Switch))
mkSwitch SimpleElement
se
Either Volume (Maybe Volume, Maybe Volume)
v <- SimpleElement -> IO (Either Volume (Maybe Volume, Maybe Volume))
mkVolume SimpleElement
se
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$! Control { name :: String
name = String
n
, index :: CUInt
index = CUInt
i
, switch :: Either Switch (Maybe Switch, Maybe Switch)
switch = Either Switch (Maybe Switch, Maybe Switch)
sw
, volume :: Either Volume (Maybe Volume, Maybe Volume)
volume = Either Volume (Maybe Volume, Maybe Volume)
v
}
getControlByName :: Mixer
-> String
-> IO (Maybe Control)
getControlByName :: Mixer -> String -> IO (Maybe Control)
getControlByName Mixer
mix String
controlName = do
[Control]
cs <- Mixer -> IO [Control]
controls Mixer
mix
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
controlName forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip (forall a b. (a -> b) -> [a] -> [b]
map Control -> String
name [Control]
cs) [Control]
cs