From 80c9f83af0885969967bec2540362ed8ba89447f Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 3 Dec 2015 09:13:05 -0500 Subject: print extracted info from history --- midi-dump.hs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/midi-dump.hs b/midi-dump.hs index 308e008..c7cd5e1 100644 --- a/midi-dump.hs +++ b/midi-dump.hs @@ -21,6 +21,9 @@ data EVENT = MidiEvent TimeSpec Event.T | Silence TimeSpec isSilence (Silence _) = True isSilence _ = False +getTS (MidiEvent ts _) = ts +getTS (Silence ts) = ts + data LoopState = LoopState { keysDown :: MidiPitchSet, inputHistory :: [EVENT], @@ -57,8 +60,21 @@ loop = do when (Set.null newKeys) $ do hist <- gets $ takeWhile (not . isSilence) . inputHistory - liftIO $ print $ reverse hist + liftIO $ print $ map (`div` 1000000) $ tsDeltas $ map getTS $ reverse hist + liftIO $ print $ mapMaybe getMidiDesc $ reverse hist modify $ \s -> s { inputHistory = Silence now:inputHistory s } modify $ \s -> s { lastTick = now } loop + +getMidiDesc :: EVENT -> Maybe String +getMidiDesc (MidiEvent _ (Event.Cons _ _ _ _ _ _ (Event.NoteEv Event.NoteOn ev))) = return $ ("on:" ++) $ showPitch $ unPitch $ Event.noteNote ev +getMidiDesc (MidiEvent _ (Event.Cons _ _ _ _ _ _ (Event.NoteEv Event.NoteOff ev))) = return $ ("off:" ++) $ showPitch $ unPitch $ Event.noteNote ev +getMidiDesc _ = Nothing + +tsDeltas :: [TimeSpec] -> [Integer] +tsDeltas [] = [] +tsDeltas ls@(x:xs) = map (\(a,b) -> a - b) $ zip nsecs (0:nsecs) + where + nsecs = map timeSpecAsNanoSecs rel + rel = map (\y -> y - x) ls -- cgit v1.2.3