diff options
author | Andrew Cady <d@jerkface.net> | 2015-12-03 08:06:43 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2015-12-03 08:06:43 -0500 |
commit | 2246eee55d60ef6d955136492b57ad04b073fb57 (patch) | |
tree | 85aaedb10e5a3f56e61bd5cf08ecc03f0860db23 | |
parent | 3c4d35d9f88ae2f1139d0f402c05132bf7e3ec81 (diff) |
record timestamps of silence
-rw-r--r-- | midi-dump.hs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/midi-dump.hs b/midi-dump.hs index b3698ae..308e008 100644 --- a/midi-dump.hs +++ b/midi-dump.hs | |||
@@ -9,16 +9,21 @@ import Data.Maybe | |||
9 | import Data.List | 9 | import Data.List |
10 | import System.Clock | 10 | import System.Clock |
11 | 11 | ||
12 | verbose = False | ||
13 | |||
12 | main = main' `AlsaExc.catch` handler | 14 | main = main' `AlsaExc.catch` handler |
13 | where | 15 | where |
14 | handler e = putStrLn $ "alsa_exception: " ++ AlsaExc.show e | 16 | handler e = when (verbose) $ putStrLn $ "alsa_exception: " ++ AlsaExc.show e |
15 | 17 | ||
16 | data EVENT = EVENT TimeSpec Event.T | 18 | data EVENT = MidiEvent TimeSpec Event.T | Silence TimeSpec |
17 | deriving Show | 19 | deriving Show |
18 | 20 | ||
21 | isSilence (Silence _) = True | ||
22 | isSilence _ = False | ||
23 | |||
19 | data LoopState = LoopState { | 24 | data LoopState = LoopState { |
20 | keysDown :: MidiPitchSet, | 25 | keysDown :: MidiPitchSet, |
21 | inputHistory :: [Maybe EVENT], | 26 | inputHistory :: [EVENT], |
22 | lastTick :: TimeSpec | 27 | lastTick :: TimeSpec |
23 | } | 28 | } |
24 | 29 | ||
@@ -45,15 +50,15 @@ loop = do | |||
45 | else do | 50 | else do |
46 | now <- liftIO $ getTime Monotonic | 51 | now <- liftIO $ getTime Monotonic |
47 | let delta = now - startTime | 52 | let delta = now - startTime |
48 | let newEvents = map (Just . (EVENT now)) events | 53 | let newEvents = map (MidiEvent now) events |
49 | 54 | ||
50 | liftIO $ printChordLn newKeys | 55 | liftIO $ printChordLn newKeys |
51 | modify $ \s -> s { keysDown = newKeys, inputHistory = newEvents ++ inputHistory s } | 56 | modify $ \s -> s { keysDown = newKeys, inputHistory = newEvents ++ inputHistory s } |
52 | 57 | ||
53 | when (Set.null newKeys) $ do | 58 | when (Set.null newKeys) $ do |
54 | hist <- gets (takeWhile isJust . inputHistory) | 59 | hist <- gets $ takeWhile (not . isSilence) . inputHistory |
55 | liftIO $ print hist | 60 | liftIO $ print $ reverse hist |
56 | modify $ \s -> s { inputHistory = Nothing:inputHistory s } | 61 | modify $ \s -> s { inputHistory = Silence now:inputHistory s } |
57 | 62 | ||
58 | modify $ \s -> s { lastTick = now } | 63 | modify $ \s -> s { lastTick = now } |
59 | loop | 64 | loop |