Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. module Main where
  2.  
  3. import Data.Time.Clock.POSIX
  4. import System.IO
  5.  
  6. main :: IO ()
  7. main = do
  8. putStrLn "Tap to the beat of a song to determine its BPM."
  9. hSetEcho stdin False
  10. hSetBuffering stdin NoBuffering
  11. loop [1]
  12.  
  13. average :: (Foldable t, Integral a) => t a -> a
  14. average n = sum n `div` fromIntegral (length n)
  15.  
  16. takeLast :: Int -> [t] -> [t]
  17. takeLast n [] = []
  18. takeLast n l = drop (length l - n) l
  19.  
  20. diff :: Num t => [t] -> [t]
  21. diff [] = []
  22. diff ls = zipWith (-) (tail ls) ls
  23.  
  24. loop :: [Integer] -> IO a
  25. loop lst = do
  26. getChar
  27. t <- getPOSIXTime
  28. let lastFew = takeLast 4 lst ++ [round (t * 1000)]
  29. print (60000 `div` average (diff lastFew))
  30. loop lastFew
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement