summaryrefslogtreecommitdiff
path: root/trivmix/Trivmix.hs
diff options
context:
space:
mode:
Diffstat (limited to 'trivmix/Trivmix.hs')
-rw-r--r--trivmix/Trivmix.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/trivmix/Trivmix.hs b/trivmix/Trivmix.hs
index 0758921..91dd440 100644
--- a/trivmix/Trivmix.hs
+++ b/trivmix/Trivmix.hs
@@ -53,6 +53,7 @@ data Options = Options
53 , client :: String 53 , client :: String
54 , initialLevel :: Level 54 , initialLevel :: Level
55 , initialBalance :: Balance 55 , initialBalance :: Balance
56 , fps, interval :: Rational
56 , run :: [FilePath] 57 , run :: [FilePath]
57 , balanceFiles :: [FilePath] 58 , balanceFiles :: [FilePath]
58 , levelFiles :: [FilePath] 59 , levelFiles :: [FilePath]
@@ -88,6 +89,18 @@ optionParser = Options
88 <> value def 89 <> value def
89 <> showDefault 90 <> showDefault
90 ) 91 )
92 <*> option auto ( long "fps"
93 <> metavar "NUMBER"
94 <> help "Update level ‘NUMBER’ times per second"
95 <> value 200
96 <> showDefault
97 )
98 <*> option auto ( long "interval"
99 <> metavar "NUMBER"
100 <> help "Smooth level transitions over ‘NUMBER’ seconds"
101 <> value 0.2
102 <> showDefault
103 )
91 <*> many ( strOption ( long "run" 104 <*> many ( strOption ( long "run"
92 <> metavar "FILE" 105 <> metavar "FILE"
93 <> help [str|Execute a file once setup of jacks is done (use this to autoconnect) 106 <> help [str|Execute a file once setup of jacks is done (use this to autoconnect)
@@ -168,8 +181,6 @@ trivmix Options{..} = do
168 notifyReady 181 notifyReady
169 forever $ do -- Smooth out discontinuity 182 forever $ do -- Smooth out discontinuity
170 let 183 let
171 fps = 200
172 interval = 0.2
173 frames = interval * fps 184 frames = interval * fps
174 delay = round $ recip fps * 1e6 185 delay = round $ recip fps * 1e6
175 linInt x a b = a * (1 - x) + b * x 186 linInt x a b = a * (1 - x) + b * x
@@ -177,7 +188,7 @@ trivmix Options{..} = do
177 mulBalance (bToFloat -> b) x = either error id $ asFloat (*) (Lin . either error id $ refine b) x 188 mulBalance (bToFloat -> b) x = either error id $ asFloat (*) (Lin . either error id $ refine b) x
178 newLevel <- mulBalance <$> readMVar balance <*> readMVar level 189 newLevel <- mulBalance <$> readMVar balance <*> readMVar level
179 currentLevel <- readMVar level' 190 currentLevel <- readMVar level'
180 mapM_ (\x -> swapMVar level' (linInt' x currentLevel newLevel) >> threadDelay delay) ([0,recip frames..1] :: [Float]) 191 mapM_ (\(fromRational -> x) -> swapMVar level' (linInt' x currentLevel newLevel) >> threadDelay delay) [0,recip frames..1]
181 192
182mix :: MVar Level -> CFloat -> IO CFloat 193mix :: MVar Level -> CFloat -> IO CFloat
183mix level input = do 194mix level input = do