From 21b3a615d08f6b6019c0e8ab0a3f8f21d0de4204 Mon Sep 17 00:00:00 2001 From: Sergei Trofimovich Date: Fri, 7 Mar 2014 22:19:19 +0300 Subject: src/Plugins/Monitors/Volume.hs: port to alsa-mixer-0.2 Signed-off-by: Sergei Trofimovich --- src/Plugins/Monitors/Volume.hs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/Plugins/Monitors') diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs index 76831ff..024292f 100644 --- a/src/Plugins/Monitors/Volume.hs +++ b/src/Plugins/Monitors/Volume.hs @@ -110,11 +110,13 @@ formatDb opts dbi = do runVolume :: String -> String -> [String] -> Monitor String runVolume mixerName controlName argv = do opts <- io $ parseOpts argv - control <- io $ getControlByName mixerName controlName - (lo, hi) <- io . liftMaybe $ getRange <$> volumeControl control - val <- getVal $ volumeControl control - db <- getDB $ volumeControl control - sw <- getSw $ switchControl control + (lo, hi, val, db, sw) <- io $ withMixer mixerName $ \mixer -> do + control <- getControlByName mixer controlName + (lo, hi) <- liftMaybe $ getRange <$> volumeControl control + val <- getVal $ volumeControl control + db <- getDB $ volumeControl control + sw <- getSw $ switchControl control + return (lo, hi, val, db, sw) p <- liftMonitor $ liftM3 formatVol lo hi val b <- liftMonitor $ liftM3 formatVolBar lo hi val d <- getFormatDB opts db @@ -138,18 +140,18 @@ runVolume mixerName controlName argv = do liftMonitor Nothing = unavailable liftMonitor (Just m) = m - getDB :: Maybe Volume -> Monitor (Maybe Integer) + getDB :: Maybe Volume -> IO (Maybe Integer) getDB Nothing = return Nothing - getDB (Just v) = io $ AE.catch (getChannel FrontLeft $ dB v) - (const $ return $ Just 0) + getDB (Just v) = AE.catch (getChannel FrontLeft $ dB v) + (const $ return $ Just 0) - getVal :: Maybe Volume -> Monitor (Maybe Integer) + getVal :: Maybe Volume -> IO (Maybe Integer) getVal Nothing = return Nothing - getVal (Just v) = io $ getChannel FrontLeft $ value v + getVal (Just v) = getChannel FrontLeft $ value v - getSw :: Maybe Switch -> Monitor (Maybe Bool) + getSw :: Maybe Switch -> IO (Maybe Bool) getSw Nothing = return Nothing - getSw (Just s) = io $ getChannel FrontLeft s + getSw (Just s) = getChannel FrontLeft s getFormatDB :: VolumeOpts -> Maybe Integer -> Monitor String getFormatDB _ Nothing = unavailable -- cgit v1.2.3