diff options
author | Andrew Cady <d@jerkface.net> | 2014-01-20 09:36:20 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2014-01-20 09:36:20 -0500 |
commit | 47ae11f017ad2cecb15ffe807a30f6cbd647f758 (patch) | |
tree | d64132f83594e1c4cc76a199a6818d1e723158bb | |
parent | 09a78e65b503437f3defaac924a4ea316e8f7f62 (diff) |
change smartDrawKeys interface
-rw-r--r-- | axis.hs | 48 |
1 files changed, 29 insertions, 19 deletions
@@ -116,30 +116,37 @@ pitchToColor p = | |||
116 | _ -> _CGA !! 8 | 116 | _ -> _CGA !! 8 |
117 | 117 | ||
118 | smartDrawKeys' :: (Integral a, Integral a2, Integral a1) => Bool -> Set.Set (Event.Channel, Event.Pitch) -> Set.Set (Event.Channel, Event.Pitch) -> SDL.Surface -> SDL.TTF.Font -> [(a1, a2)] -> a -> IO () | 118 | smartDrawKeys' :: (Integral a, Integral a2, Integral a1) => Bool -> Set.Set (Event.Channel, Event.Pitch) -> Set.Set (Event.Channel, Event.Pitch) -> SDL.Surface -> SDL.TTF.Font -> [(a1, a2)] -> a -> IO () |
119 | smartDrawKeys' reallyErase drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do | 119 | smartDrawKeys' reallyErase oldKeys nowKeys videoSurface font axis_key_locations axis_key_size = do |
120 | let | 120 | let |
121 | ignoreThese = Set.intersection nowKeys oldKeys | ||
122 | drawThese = Set.difference nowKeys ignoreThese | ||
123 | eraseThese = Set.difference oldKeys ignoreThese | ||
124 | drawSet = Set.difference nowKeys ignoreThese | ||
125 | eraseSet = Set.difference oldKeys ignoreThese | ||
126 | |||
121 | changroup = groupBy (\(_, n1) (_, n2) -> n1 == n2) | 127 | changroup = groupBy (\(_, n1) (_, n2) -> n1 == n2) |
122 | chanfilter = filter (\ (c, _) -> unChannel c /= 9) | 128 | chanfilter = filter (\ (c, _) -> unChannel c /= 9) |
123 | drawList = changroup . chanfilter $ Set.toList drawSet | 129 | drawList = changroup . chanfilter $ Set.toList drawSet |
124 | eraseList = changroup . chanfilter $ Set.toList eraseSet | 130 | eraseList = changroup . chanfilter $ Set.toList eraseSet |
125 | 131 | ||
132 | |||
126 | forM_ [(eraseList, True), (drawList, False)] $ \ (ls, erase) -> do | 133 | forM_ [(eraseList, True), (drawList, False)] $ \ (ls, erase) -> do |
127 | forM_ ls $ \ls' -> do | 134 | forM_ ls $ \ls' -> do |
128 | let chans = map (\ (c, _) -> unChannel c) ls' | 135 | let chans = map (\ (c, _) -> unChannel c) ls' |
129 | (_, n) = head ls' | 136 | (_, n) = head ls' |
130 | text = smartShowPitch (unPitch n) | 137 | text = smartShowPitch (unPitch n) |
131 | pitch = if _OCTAVE_SQUASH then (unPitch n) `mod` 12 + 12 * 6 else (unPitch n) | 138 | pitch = if _OCTAVE_SQUASH then unPitch n `mod` 12 + 12 * 6 else unPitch n |
132 | onColor = _KEY_ON_COLOR | 139 | onColor = _KEY_ON_COLOR |
133 | offColor = pitchToColor pitch | 140 | offColor = pitchToColor pitch |
134 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do | 141 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do |
135 | drawKey' idx videoSurface font axis_key_locations axis_key_size | 142 | drawKey idx videoSurface font axis_key_locations axis_key_size |
136 | offColor | 143 | offColor |
137 | (if reallyErase then _KB_BG_COLOR_PIXEL else _KEY_BORDER_COLOR_PIXEL) | 144 | (if reallyErase then _KB_BG_COLOR_PIXEL else _KEY_BORDER_COLOR_PIXEL) |
138 | (if erase then Nothing else (Just text)) | 145 | (if erase then Nothing else (Just text)) |
139 | (if erase then [] else (map fromIntegral chans)) | 146 | (if erase then [] else (map fromIntegral chans)) |
140 | 147 | ||
141 | drawKey' :: (Integral a1, Integral a2, Integral a) => Int -> SDL.Surface -> SDL.TTF.Font -> [(a1, a2)] -> a -> SDL.Color -> t -> Maybe String -> [Int] -> IO () | 148 | drawKey :: (Integral a1, Integral a2, Integral a) => Int -> SDL.Surface -> SDL.TTF.Font -> [(a1, a2)] -> a -> SDL.Color -> t -> Maybe String -> [Int] -> IO () |
142 | drawKey' idx videoSurface font axis_key_locations axis_key_size fillColor borderColor text channels = do | 149 | drawKey idx videoSurface font axis_key_locations axis_key_size fillColor borderColor text channels = do |
143 | let (x, y) = axis_key_locations !! idx | 150 | let (x, y) = axis_key_locations !! idx |
144 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel fillColor) | 151 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel fillColor) |
145 | let len = length channels | 152 | let len = length channels |
@@ -161,13 +168,6 @@ drawKey' idx videoSurface font axis_key_locations axis_key_size fillColor border | |||
161 | (Just t) -> centerText videoSurface x y font _KEY_TEXT_COLOR fillColor t | 168 | (Just t) -> centerText videoSurface x y font _KEY_TEXT_COLOR fillColor t |
162 | _ -> return () | 169 | _ -> return () |
163 | 170 | ||
164 | eraseKeys_ really pitches videoSurface font axis_key_locations axis_key_size = | ||
165 | let pitchSet = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) pitches | ||
166 | in | ||
167 | smartDrawKeys' really Set.empty pitchSet videoSurface font axis_key_locations axis_key_size | ||
168 | reallyEraseKeys = eraseKeys_ True | ||
169 | eraseKeys = eraseKeys_ False | ||
170 | |||
171 | fi = fromIntegral | 171 | fi = fromIntegral |
172 | rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255)) | 172 | rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255)) |
173 | 173 | ||
@@ -199,9 +199,10 @@ main = | |||
199 | 199 | ||
200 | let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect | 200 | let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect |
201 | 201 | ||
202 | let _ALL_PITCHES = [_AXIS_BOTTOM_PITCH .. _AXIS_TOP_PITCH] | 202 | let _ALL_PITCHES = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) [_AXIS_BOTTOM_PITCH .. _AXIS_TOP_PITCH] |
203 | let allKeysOFF = eraseKeys _ALL_PITCHES videoSurface font axis_key_locations axis_key_size | 203 | keysOFF really = smartDrawKeys' really _ALL_PITCHES Set.empty videoSurface font axis_key_locations axis_key_size |
204 | allKeysReallyOFF = reallyEraseKeys _ALL_PITCHES videoSurface font axis_key_locations axis_key_size | 204 | allKeysOFF = keysOFF False |
205 | allKeysReallyOFF = keysOFF True | ||
205 | allKeysOFF | 206 | allKeysOFF |
206 | 207 | ||
207 | putStrLn "Initialized." | 208 | putStrLn "Initialized." |
@@ -223,11 +224,20 @@ main = | |||
223 | -- let chord = show $ pitchList midiKeysDown' | 224 | -- let chord = show $ pitchList midiKeysDown' |
224 | -- let chord = show $ map (\i->elemIndices i pitchIndex) $ pitchList midiKeysDown' | 225 | -- let chord = show $ map (\i->elemIndices i pitchIndex) $ pitchList midiKeysDown' |
225 | -- textBand videoSurface videoClipRect (SDL.Rect 0 70 0 70) font chord | 226 | -- textBand videoSurface videoClipRect (SDL.Rect 0 70 0 70) font chord |
226 | let ignoreThese = Set.intersection midiKeysDown' midiKeysDown | ||
227 | let drawThese = Set.difference midiKeysDown' ignoreThese | ||
228 | let eraseThese = Set.difference midiKeysDown ignoreThese | ||
229 | 227 | ||
230 | smartDrawKeys' False drawThese eraseThese videoSurface font axis_key_locations axis_key_size | 228 | -- gah! This is all wrong with the channels added! Unless |
229 | -- smartDrawKeys gets smarter... but really, this interface | ||
230 | -- is awkward now and should be changed. | ||
231 | -- | ||
232 | -- What we actually want here is the set of pitches where | ||
233 | -- there has been an event. Which is simply derived from | ||
234 | -- just the Set.difference midiKeys midiKeys'. But we also | ||
235 | -- want the set of channels for each pitch -- which is just | ||
236 | -- midiKeysDown' (processed as we are doing already in | ||
237 | -- smartDrawKeys). Then we build up a map of pitches -> | ||
238 | -- channels. | ||
239 | |||
240 | smartDrawKeys' False midiKeysDown midiKeysDown' videoSurface font axis_key_locations axis_key_size | ||
231 | return () | 241 | return () |
232 | 242 | ||
233 | Control.Monad.when (keysDown' /= keysDown && keyDown SDL.SDLK_BACKSPACE keysDown') allKeysOFF | 243 | Control.Monad.when (keysDown' /= keysDown && keyDown SDL.SDLK_BACKSPACE keysDown') allKeysOFF |