diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2018-05-15 17:52:11 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2018-05-15 17:52:11 +0200 |
commit | 5d9387af919e68ef51328352eca3e0bdf3b4989e (patch) | |
tree | ff4d52e15031ec660d7a1fbae53079802607bb78 /trivmix | |
parent | 9f564c877b1166f6d0c637a4db0b2453c628efc6 (diff) | |
download | trivmix-5d9387af919e68ef51328352eca3e0bdf3b4989e.tar trivmix-5d9387af919e68ef51328352eca3e0bdf3b4989e.tar.gz trivmix-5d9387af919e68ef51328352eca3e0bdf3b4989e.tar.bz2 trivmix-5d9387af919e68ef51328352eca3e0bdf3b4989e.tar.xz trivmix-5d9387af919e68ef51328352eca3e0bdf3b4989e.zip |
Make smoothing configurable
Diffstat (limited to 'trivmix')
-rw-r--r-- | trivmix/Trivmix.hs | 17 |
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 | ||
182 | mix :: MVar Level -> CFloat -> IO CFloat | 193 | mix :: MVar Level -> CFloat -> IO CFloat |
183 | mix level input = do | 194 | mix level input = do |