summaryrefslogtreecommitdiff
path: root/axis.hs
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2014-01-17 03:55:49 -0500
committerAndrew Cady <d@jerkface.net>2014-01-17 03:55:49 -0500
commit5736ae0a30c2a4844c0f26d6847356193482ee61 (patch)
treef19315c551ceafc933585323f08a308dcc0db0ce /axis.hs
parentf619a4c584fe6c21c234b05487e9f2259e12d4a0 (diff)
pretty close to live key display
Diffstat (limited to 'axis.hs')
-rw-r--r--axis.hs23
1 files changed, 15 insertions, 8 deletions
diff --git a/axis.hs b/axis.hs
index a31199e..3108779 100644
--- a/axis.hs
+++ b/axis.hs
@@ -14,6 +14,8 @@ import Data.String
14import Graphics.UI.SDL.Keysym as SDL.Keysym 14import Graphics.UI.SDL.Keysym as SDL.Keysym
15import Graphics.UI.SDL.Primitives as SDL.Primitive 15import Graphics.UI.SDL.Primitives as SDL.Primitive
16import Data.Int (Int16) 16import Data.Int (Int16)
17import qualified System.Exit as Exit
18import Data.List (elemIndex, elemIndices)
17 19
18netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String 20netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String
19netwireIsCool = 21netwireIsCool =
@@ -61,7 +63,8 @@ main =
61 63
62 forM_ [0 .. length axis_key_locations - 1] $ \i -> do 64 forM_ [0 .. length axis_key_locations - 1] $ \i -> do
63 let (centerx, centery) = axis_key_locations !! i 65 let (centerx, centery) = axis_key_locations !! i
64 centerText videoSurface centerx centery font (show i) 66 centerText videoSurface centerx centery font (showPitch $ pitchIndex !! i)
67-- centerText videoSurface centerx centery font (show i)
65 68
66 putStrLn "Initialized." 69 putStrLn "Initialized."
67 70
@@ -78,18 +81,19 @@ main =
78 return () 81 return ()
79 82
80 Control.Monad.when (midiKeysDown' /= midiKeysDown) $ do 83 Control.Monad.when (midiKeysDown' /= midiKeysDown) $ do
81 let chord = showChord midiKeysDown' 84 --let chord = showChord midiKeysDown'
85 --let chord = show $ pitchList midiKeysDown'
86 let chord = show $ map (\i->elemIndices i pitchIndex) $ pitchList midiKeysDown'
82 textBand videoSurface videoClipRect (SDL.Rect 0 70 0 70) font chord 87 textBand videoSurface videoClipRect (SDL.Rect 0 70 0 70) font chord
83 return () 88 return ()
84 89
85 Control.Monad.when (keysDown' /= keysDown) $ do 90 Control.Monad.when (keysDown' /= keysDown) $ do
86 let chord = unwords $ map (\k -> drop 5 (show k)) $ Set.toList keysDown' 91 let chord = unwords $ map (\k -> drop 5 (show k)) $ Set.toList keysDown'
87 textBand videoSurface videoClipRect (SDL.Rect 0 210 0 70) font chord 92 textBand videoSurface videoClipRect (SDL.Rect 0 210 0 70) font chord
93 textBand videoSurface videoClipRect (SDL.Rect 0 280 0 70) font $
94 if keyDown SDL.SDLK_a keysDown' then "arpeggiate" else ""
88 return () 95 return ()
89 96
90 textBand videoSurface videoClipRect (SDL.Rect 0 280 0 70) font $
91 if keyDown SDL.SDLK_a keysDown' then "arpeggiate" else ""
92
93 Control.Monad.when(False) $ do 97 Control.Monad.when(False) $ do
94 98
95 mouse <- SDL.getRelativeMouseState 99 mouse <- SDL.getRelativeMouseState
@@ -121,13 +125,16 @@ drawHexagonSDL videoSurface centerx centery radius pixel = do
121 return () 125 return ()
122 126
123centerText videoSurface x y font text = do 127centerText videoSurface x y font text = do
124 fontSurface <- SDL.TTF.renderUTF8Shaded font text (SDL.Color 0 255 0) (SDL.Color 80 80 80) 128--fontSurface <- SDL.TTF.renderUTF8Shaded font text (SDL.Color 0 255 0) (SDL.Color 80 80 80) -- useful for testing
129 fontSurface <- SDL.TTF.renderUTF8Shaded font text (SDL.Color 0 255 0) (SDL.Color 0 0 0)
125 fontClipRect <- SDL.getClipRect fontSurface 130 fontClipRect <- SDL.getClipRect fontSurface
126 let (SDL.Rect _ _ w h) = fontClipRect 131 let (SDL.Rect _ _ w h) = fontClipRect
127 _ <- SDL.blitSurface fontSurface (Just fontClipRect) videoSurface (Just (SDL.Rect (fromIntegral(x) - w `div` 2) (fromIntegral(y) - h `div` 2) w h)) 132 _ <- SDL.blitSurface fontSurface (Just fontClipRect) videoSurface (Just (SDL.Rect (fromIntegral(x) - w `div` 2) (fromIntegral(y) - h `div` 2) w h))
128--_ <- SDL.blitSurface fontSurface (Just fontClipRect) videoSurface (Just (SDL.Rect (fromIntegral(x) + w) (fromIntegral(y) + h `div` 2) w h))
129 return () 133 return ()
130 134
135colfrom top = map (+ top) $ map (* (-7)) [0 .. 6]
136pitchIndex = (\x -> x ++ x) $ concat $ map colfrom [81, 78, 82, 79, 83, 80, 84]
137
131getKeyLocations (SDL.Rect offx offy totalw totalh) = 138getKeyLocations (SDL.Rect offx offy totalw totalh) =
132 let (key_height, key_width, xys) = getKeyLocationsAbs 139 let (key_height, key_width, xys) = getKeyLocationsAbs
133 140
@@ -160,7 +167,7 @@ getKeyLocationsAbs =
160 kb_cols = 14 :: Double 167 kb_cols = 14 :: Double
161 -- the edges of the hexagon are equal in length to its "radius" 168 -- the edges of the hexagon are equal in length to its "radius"
162 -- if the radius is 1, then horizontal movement is 1.5 and vertical movement is sqrt(3) from one center to the next 169 -- if the radius is 1, then horizontal movement is 1.5 and vertical movement is sqrt(3) from one center to the next
163 -- or else it is 2*sqrt(3) to move up 170 -- or else it is 2*sqrt(3) to move down
164 171
165 kw = 1 :: Double 172 kw = 1 :: Double
166 kh = kw/2 * sqrt(3) -- hexagon ratio 173 kh = kw/2 * sqrt(3) -- hexagon ratio