From 3e89e9e7486ae0fdd04a68b2ba799dbf89a621f0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 9 Jun 2015 23:20:13 +0200 Subject: moved logging to stderr --- src/Trivmix.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/Trivmix.hs') diff --git a/src/Trivmix.hs b/src/Trivmix.hs index 4af2165..5dc213c 100644 --- a/src/Trivmix.hs +++ b/src/Trivmix.hs @@ -24,6 +24,7 @@ import qualified Control.Monad.Exception.Synchronous as Sync import Control.Exception import System.IO.Error +import System.IO import System.INotify @@ -47,14 +48,16 @@ data Level = Lin Float | DB Float instance Show Level where show (Lin x) = show x - show (DB x) = (show x) ++ "dB" + show (DB x) = (show x') ++ "dB" + where + x' = 20 * (logBase 10 x) instance Read Level where readsPrec i = map toL . readsPrec i where toL :: (Float, String) -> (Level, String) toL (f, str) - | ((==) `on` CI.mk) prec unit = (DB f, rest) + | ((==) `on` CI.mk) prec unit = (DB $ 10 ** (0.05 * f), rest) | otherwise = (Lin f, str) where prec = take lU str @@ -133,7 +136,7 @@ mix level input = do return $ (CFloat $ toFloat level') * input where toFloat (Lin x) = x - toFloat (DB x) = 10 ** (0.05 * x) + toFloat (DB x) = x handleFiles :: INotify -> MVar Level -> [FilePath] -> IO () handleFiles inotify level files = do @@ -159,7 +162,7 @@ onStateFile file initial action = do let acquireFile = case exists of True -> return () False -> do - putStrLn $ "Creating ‘" ++ file ++ "’ (file)" + hPutStrLn stderr $ "Creating ‘" ++ file ++ "’ (file)" createFile file fileMode >>= closeFd >> writeFile file initial fileMode = foldl unionFileModes nullFileMode [ ownerReadMode , ownerWriteMode @@ -169,17 +172,17 @@ onStateFile file initial action = do releaseFile = case exists of True -> return () False -> do - putStrLn $ "Removing ‘" ++ file ++ "’ (file)" + hPutStrLn stderr $ "Removing ‘" ++ file ++ "’ (file)" removeFile file acquireDir = case dirExists of True -> return () False -> do - putStrLn $ "Creating ‘" ++ directory ++ "’ (dir" + hPutStrLn stderr $ "Creating ‘" ++ directory ++ "’ (dir" createDirectoryIfMissing True directory releaseDir = case dirExists of True -> return () False -> do - putStrLn $ "Removing ‘" ++ directory ++ "’ (dir)" + hPutStrLn stderr $ "Removing ‘" ++ directory ++ "’ (dir)" removeDirectory directory acquire = acquireDir >> acquireFile release = releaseFile >> releaseDir @@ -191,10 +194,10 @@ readLevel levelChan current file = catch action handler action = do level <- readFile file >>= readIO . stripSpace writeChan levelChan level - putStrLn $ "Detected new level: " ++ (show level) + hPutStrLn stderr $ "Detected new level: " ++ (show level) handler e = if isUserError e then do - putStrLn $ "Could not parse new level from ‘" ++ file ++ "’ - overwriting." + hPutStrLn stderr $ "Could not parse new level from ‘" ++ file ++ "’ - overwriting." readMVar current >>= writeLevel file else throw e stripSpace = reverse . stripSpace' . reverse . stripSpace' @@ -205,5 +208,5 @@ readLevel levelChan current file = catch action handler writeLevel :: FilePath -> Level -> IO () writeLevel file level = do - putStrLn $ "Writing out level ‘" ++ (show level) ++ "’ to ‘" ++ file ++ "’" + hPutStrLn stderr $ "Writing out level ‘" ++ (show level) ++ "’ to ‘" ++ file ++ "’" writeFile file (show level ++ "\n") -- cgit v1.2.3