summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2015-12-03 08:06:43 -0500
committerAndrew Cady <d@jerkface.net>2015-12-03 08:06:43 -0500
commit2246eee55d60ef6d955136492b57ad04b073fb57 (patch)
tree85aaedb10e5a3f56e61bd5cf08ecc03f0860db23
parent3c4d35d9f88ae2f1139d0f402c05132bf7e3ec81 (diff)
record timestamps of silence
-rw-r--r--midi-dump.hs19
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
9import Data.List 9import Data.List
10import System.Clock 10import System.Clock
11 11
12verbose = False
13
12main = main' `AlsaExc.catch` handler 14main = 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
16data EVENT = EVENT TimeSpec Event.T 18data EVENT = MidiEvent TimeSpec Event.T | Silence TimeSpec
17 deriving Show 19 deriving Show
18 20
21isSilence (Silence _) = True
22isSilence _ = False
23
19data LoopState = LoopState { 24data 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