From 2246eee55d60ef6d955136492b57ad04b073fb57 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 3 Dec 2015 08:06:43 -0500 Subject: record timestamps of silence --- midi-dump.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'midi-dump.hs') 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 import Data.List import System.Clock +verbose = False + main = main' `AlsaExc.catch` handler where - handler e = putStrLn $ "alsa_exception: " ++ AlsaExc.show e + handler e = when (verbose) $ putStrLn $ "alsa_exception: " ++ AlsaExc.show e -data EVENT = EVENT TimeSpec Event.T +data EVENT = MidiEvent TimeSpec Event.T | Silence TimeSpec deriving Show +isSilence (Silence _) = True +isSilence _ = False + data LoopState = LoopState { keysDown :: MidiPitchSet, - inputHistory :: [Maybe EVENT], + inputHistory :: [EVENT], lastTick :: TimeSpec } @@ -45,15 +50,15 @@ loop = do else do now <- liftIO $ getTime Monotonic let delta = now - startTime - let newEvents = map (Just . (EVENT now)) events + let newEvents = map (MidiEvent now) events liftIO $ printChordLn newKeys modify $ \s -> s { keysDown = newKeys, inputHistory = newEvents ++ inputHistory s } when (Set.null newKeys) $ do - hist <- gets (takeWhile isJust . inputHistory) - liftIO $ print hist - modify $ \s -> s { inputHistory = Nothing:inputHistory s } + hist <- gets $ takeWhile (not . isSilence) . inputHistory + liftIO $ print $ reverse hist + modify $ \s -> s { inputHistory = Silence now:inputHistory s } modify $ \s -> s { lastTick = now } loop -- cgit v1.2.3