summaryrefslogtreecommitdiff
path: root/axis.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2014-01-15 15:18:30 -0500
committerAndrew Cady <d@jerkface.net>2014-01-15 15:18:44 -0500
commitec69d4ca77538a5624c4974181b6dc0879cfca59 (patch)
tree9f955ee3610e01f6cdfce9ddcf3316d45efb77e3 /axis.hs
parente83c155a8be7053ea90118659e83a334c3d1c382 (diff)
show currently-playing midi notes in real-time through sdl!
Diffstat (limited to 'axis.hs')
-rw-r--r--axis.hs31
1 files changed, 27 insertions, 4 deletions
diff --git a/axis.hs b/axis.hs
index 37b187f..3e0b8b1 100644
--- a/axis.hs
+++ b/axis.hs
@@ -53,13 +53,28 @@ main =
53 putStrLn x' 53 putStrLn x'
54 fontSurface <- SDL.TTF.renderUTF8Blended font x' (SDL.Color 0 255 0) 54 fontSurface <- SDL.TTF.renderUTF8Blended font x' (SDL.Color 0 255 0)
55 fontClipRect <- SDL.getClipRect fontSurface 55 fontClipRect <- SDL.getClipRect fontSurface
56-- _ <- SDL.fillRect videoSurface (Just fontClipRect) (SDL.Pixel 0) 56 _ <- SDL.fillRect videoSurface (Just (widenRect fontClipRect videoClipRect)) (SDL.Pixel 0) -- clear a horizontal band
57 _ <- SDL.fillRect videoSurface (Just videoClipRect) (SDL.Pixel 0)
58 _ <- SDL.blitSurface fontSurface (Just fontClipRect) videoSurface (Just fontClipRect) 57 _ <- SDL.blitSurface fontSurface (Just fontClipRect) videoSurface (Just fontClipRect)
59-- _ <- SDL.updateRect videoSurface fontClipRect
60 _ <- SDL.updateRect videoSurface videoClipRect
61 return () 58 return ()
62 59
60 Control.Monad.when (midiKeysDown' /= midiKeysDown) $ do
61 let chord = showChord midiKeysDown'
62 putStrLn chord
63 if (chord /= "")
64 then do
65 chordFontSurface <- SDL.TTF.renderUTF8Blended font chord (SDL.Color 0 255 0)
66 chordFontClipRect <- SDL.getClipRect chordFontSurface
67 let r = chordFontClipRect `underNeath` (SDL.Rect 0 0 0 70)
68 _ <- SDL.fillRect videoSurface (Just (widenRect r videoClipRect)) (SDL.Pixel 0) -- clear a horizontal band
69 _ <- SDL.blitSurface chordFontSurface (Just chordFontClipRect) videoSurface (Just r)
70 return ()
71 else do
72 _ <- SDL.fillRect videoSurface (Just (widenRect (SDL.Rect 0 70 0 70) videoClipRect)) (SDL.Pixel 0) -- clear a horizontal band
73 return ()
74 return ()
75
76 _ <- SDL.updateRect videoSurface videoClipRect
77
63 let framerate = 30 78 let framerate = 30
64 let delay = 1000 `div` framerate - 1000 * (floor $ dtime ds) 79 let delay = 1000 `div` framerate - 1000 * (floor $ dtime ds)
65 SDL.delay (delay) 80 SDL.delay (delay)
@@ -68,6 +83,14 @@ main =
68 83
69 loop Set.empty Set.empty clockSession_ netwireIsCool "" 84 loop Set.empty Set.empty clockSession_ netwireIsCool ""
70 85
86widenRect a b =
87 let ((SDL.Rect x1 y1 w1 h1), (SDL.Rect x2 _ w2 _)) = (a, b) in
88 (SDL.Rect x2 y1 w2 h1)
89
90underNeath a b =
91 let ((SDL.Rect x1 y1 w1 h1), (SDL.Rect _ _ _ h2)) = (a, b) in
92 (SDL.Rect x1 (y1+h2) w1 h1)
93
71parseSDLEvents :: Set.Set SDL.Keysym -> IO (Set.Set SDL.Keysym) 94parseSDLEvents :: Set.Set SDL.Keysym -> IO (Set.Set SDL.Keysym)
72parseSDLEvents keysDown = do 95parseSDLEvents keysDown = do
73 event <- SDL.pollEvent 96 event <- SDL.pollEvent