From e8bd291609192725ea0b40190fd3bd84f0d96920 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 15 May 2018 19:14:48 +0200 Subject: =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trivmix.cabal | 2 +- trivmix.nix | 2 +- trivmix/Trivmix.hs | 11 ++++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/trivmix.cabal b/trivmix.cabal index f5cf777..0cbccdb 100644 --- a/trivmix.cabal +++ b/trivmix.cabal @@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: trivmix -version: 3.3.1 +version: 3.3.2 -- synopsis: -- description: license: PublicDomain diff --git a/trivmix.nix b/trivmix.nix index f5bb6c0..be84746 100644 --- a/trivmix.nix +++ b/trivmix.nix @@ -5,7 +5,7 @@ }: mkDerivation { pname = "trivmix"; - version = "3.3.1"; + version = "3.3.2"; src = ./.; isLibrary = true; isExecutable = true; diff --git a/trivmix/Trivmix.hs b/trivmix/Trivmix.hs index 41a1046..b2d87ec 100644 --- a/trivmix/Trivmix.hs +++ b/trivmix/Trivmix.hs @@ -162,9 +162,9 @@ main = execParser opts >>= trivmix trivmix :: Options -> IO () trivmix Options{..} = do - level <- newMVar 0 + level <- newMVar initialLevel balance <- newMVar initialBalance - level' <- newMVar initialLevel + level' <- newMVar 0 let withFiles = foldl (.) id $ map (\f -> onStateFile f (show initialLevel ++ "\n")) levelFiles ++ map (\f -> onStateFile f (show initialBalance ++ "\n")) balanceFiles withFiles $ withINotify $ \inotify -> do @@ -178,17 +178,18 @@ trivmix Options{..} = do Jack.withActivation client' . Trans.lift $ do forM_ run $ \script -> (callProcess script [client ++ ":" ++ input, client ++ ":" ++ output]) `catch` (\code -> hPutStrLn stderr $ script ++ " failed: " ++ show (code :: ExitCode)) - notifyReady - forever $ do -- Smooth out discontinuity + forkIO . forever $ do -- Smooth out discontinuity let frames = interval * fps delay = round $ recip fps * 1e6 linInt x a b = a * (1 - x) + b * x - linInt' x a b = either (const 0) id $ asFloat (linInt x) a b + linInt' x a b = either error id $ asFloat (linInt x) a b mulBalance (bToFloat -> b) x = either error id $ asFloat (*) (Lin . either error id $ refine b) x newLevel <- mulBalance <$> readMVar balance <*> readMVar level currentLevel <- readMVar level' mapM_ (\x -> swapMVar level' (linInt' x currentLevel newLevel) >> threadDelay delay) [0,recip frames..1] + notifyReady + forever $ threadDelay 1000000 >> notifyWatchdog mix :: MVar Level -> CFloat -> IO CFloat mix level input = do -- cgit v1.2.3