diff options
author | Andrew Cady <d@jerkface.net> | 2014-04-03 14:01:42 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2014-04-03 14:01:42 -0400 |
commit | 3328bb11eaa9d3e1b74b607f919ec345c8b9db2b (patch) | |
tree | e90cc4405653a152b9f3f0e26ec5a009306c8829 | |
parent | 4230dee81a4da577772344d736b9194ea4fda8da (diff) |
move state into data structure
-rw-r--r-- | axis.hs | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -43,7 +43,7 @@ _AXIS_ROWS = 7 + 4 | |||
43 | _AXIS_UNIQUE_COLS = 7 | 43 | _AXIS_UNIQUE_COLS = 7 |
44 | _AXIS_COLS_REPEAT = 2 | 44 | _AXIS_COLS_REPEAT = 2 |
45 | _AXIS_TOPLEFT_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2) | 45 | _AXIS_TOPLEFT_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2) |
46 | _AXIS_BOTTOMRIGHT_PITCH = 81 - (7 * _AXIS_ROWS) - 3 | 46 | _AXIS_BOTTOMLEFT_PITCH = _AXIS_TOPLEFT_PITCH - (_AXIS_ROWS * 7) |
47 | _AXIS_TOPRIGHT_PITCH = _AXIS_TOPLEFT_PITCH + _AXIS_UNIQUE_COLS `div` 2 | 47 | _AXIS_TOPRIGHT_PITCH = _AXIS_TOPLEFT_PITCH + _AXIS_UNIQUE_COLS `div` 2 |
48 | 48 | ||
49 | --_KEY_BORDER_COLOR = (SDL.Color 0 0 255) | 49 | --_KEY_BORDER_COLOR = (SDL.Color 0 0 255) |
@@ -166,6 +166,10 @@ rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi | |||
166 | 166 | ||
167 | chooseFontSize h w = 30 * d `div` 1024 where d = min h w | 167 | chooseFontSize h w = 30 * d `div` 1024 where d = min h w |
168 | 168 | ||
169 | data LoopState = LoopState { | ||
170 | firstLoop :: Bool | ||
171 | } deriving (Show) | ||
172 | |||
169 | main = | 173 | main = |
170 | withAlsaInit $ \h public private q publicAddr privateAddr -> do | 174 | withAlsaInit $ \h public private q publicAddr privateAddr -> do |
171 | cmdlineAlsaConnect h public -- fail early if bad command lines | 175 | cmdlineAlsaConnect h public -- fail early if bad command lines |
@@ -195,7 +199,9 @@ main = | |||
195 | putStrLn "Initialized." | 199 | putStrLn "Initialized." |
196 | 200 | ||
197 | let parseAlsa keysDown = parseAlsaEvents h keysDown (forwardNoteEvent h q publicAddr) | 201 | let parseAlsa keysDown = parseAlsaEvents h keysDown (forwardNoteEvent h q publicAddr) |
198 | let loop firstLoop midiKeysDown keysDown resolution font s w x = do | 202 | let loop state midiKeysDown keysDown resolution font s w x = do |
203 | let (LoopState firstLoop) = state | ||
204 | |||
199 | (keysDown', resolution') <- parseSDLEvents keysDown resolution | 205 | (keysDown', resolution') <- parseSDLEvents keysDown resolution |
200 | midiKeysDown' <- parseAlsa midiKeysDown | 206 | midiKeysDown' <- parseAlsa midiKeysDown |
201 | (ds, s') <- stepSession s | 207 | (ds, s') <- stepSession s |
@@ -216,7 +222,7 @@ main = | |||
216 | videoClipRect <- SDL.getClipRect videoSurface | 222 | videoClipRect <- SDL.getClipRect videoSurface |
217 | let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect | 223 | let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect |
218 | 224 | ||
219 | let _ALL_PITCHES = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) [_AXIS_BOTTOMRIGHT_PITCH .. _AXIS_TOPRIGHT_PITCH] | 225 | let _ALL_PITCHES = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) [_AXIS_BOTTOMLEFT_PITCH .. _AXIS_TOPRIGHT_PITCH] |
220 | keysOFF really = smartDrawKeys really _ALL_PITCHES Set.empty videoSurface font' axis_key_locations axis_key_size | 226 | keysOFF really = smartDrawKeys really _ALL_PITCHES Set.empty videoSurface font' axis_key_locations axis_key_size |
221 | allKeysOFF = keysOFF False | 227 | allKeysOFF = keysOFF False |
222 | allKeysReallyOFF = keysOFF True | 228 | allKeysReallyOFF = keysOFF True |
@@ -266,9 +272,9 @@ main = | |||
266 | let delay = 1000 `div` framerate - 1000 * (floor $ dtime ds) | 272 | let delay = 1000 `div` framerate - 1000 * (floor $ dtime ds) |
267 | SDL.delay (delay) | 273 | SDL.delay (delay) |
268 | Control.Monad.when (not $ keyDown SDL.SDLK_ESCAPE keysDown) $ | 274 | Control.Monad.when (not $ keyDown SDL.SDLK_ESCAPE keysDown) $ |
269 | loop False midiKeysDown' keysDown' resolution' font' s' w' x' | 275 | loop (LoopState False) midiKeysDown' keysDown' resolution' font' s' w' x' |
270 | 276 | ||
271 | loop True Set.empty Set.empty (sWidth, sHeight) font clockSession_ netwireIsCool "" | 277 | loop (LoopState True) Set.empty Set.empty (sWidth, sHeight) font clockSession_ netwireIsCool "" |
272 | 278 | ||
273 | zipzip ls = if (head ls) == [] then [] else (map head ls) : (zipzip $ map tail ls) | 279 | zipzip ls = if (head ls) == [] then [] else (map head ls) : (zipzip $ map tail ls) |
274 | 280 | ||