summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2014-04-05 02:53:01 -0400
committerAndrew Cady <d@jerkface.net>2014-04-05 02:53:01 -0400
commit0af4a980467850b9fdfd684f82983bad58631933 (patch)
tree510510ce49ce912179ceacf9fdfd321b96517a8c
parent00a8d88b26818c1dd3a8a5fa7e73fcabecf27f62 (diff)
don't use smartDrawKeys to erase keys
-rw-r--r--axis.hs26
1 files changed, 25 insertions, 1 deletions
diff --git a/axis.hs b/axis.hs
index e51b6cb..95f3930 100644
--- a/axis.hs
+++ b/axis.hs
@@ -140,6 +140,30 @@ smartDrawKeys colsRepeat reallyErase beforeKeys_ nowKeys_ videoSurface font axis
140 (if showLabel then (Just text) else Nothing) 140 (if showLabel then (Just text) else Nothing)
141 chans 141 chans
142 142
143allKeysOff colsRepeat reallyErase videoSurface font axis_key_locations axis_key_size = do
144 let indices = [0 .. length axis_key_locations - 1]
145 showLabel = (not reallyErase) && _LABEL_ALL_KEYS
146 forM_ indices $ \idx -> do
147 let pitch = pitchIndex colsRepeat !! idx
148 bgColor = if reallyErase then _KB_BG_COLOR else pitchToColor pitch
149 text = smartShowPitch pitch
150 label = (if showLabel then (Just text) else Nothing)
151 drawKey idx videoSurface font axis_key_locations axis_key_size bgColor label []
152
153-- OK, what we need to do now...
154-- 1. change smartDrawKeys to take key locations instead of midi events; these are channel/location pairs
155-- 2. change the main loop to calculate the key locations, per channel, by choosing the location closest to the average from the last N locations
156-- That should be accomplished through a Data.Map mapping from each channel to a Data.Queue of locations
157-- Note that this data needs to be thrown out if the size of the keyboard changes.
158-- The data should also be thrown out if it gets too old; if the channel isn't being used
159-- The algorithm to choose can be stupid (just use the average), because
160-- the goal is just to get the code organized so that it has the
161-- previous locations available to make a choice. But a smart algorithm
162-- would choose based on the "structure" of the actual music.
163-- Question: how to deal with simultaneous keypresses?
164
165-- First order of business: get rid of all calls to smartDrawKeys but one
166
143--drawKey :: (Integral a1, Integral a2, Integral a) => Int -> SDL.Surface -> SDL.TTF.Font -> [(a1, a2)] -> a -> SDL.Color -> t -> Maybe String -> [Int] -> IO () 167--drawKey :: (Integral a1, Integral a2, Integral a) => Int -> SDL.Surface -> SDL.TTF.Font -> [(a1, a2)] -> a -> SDL.Color -> t -> Maybe String -> [Int] -> IO ()
144drawKey idx videoSurface font axis_key_locations axis_key_size fillColor text channels = do 168drawKey idx videoSurface font axis_key_locations axis_key_size fillColor text channels = do
145 let (x, y) = axis_key_locations !! idx 169 let (x, y) = axis_key_locations !! idx
@@ -234,7 +258,7 @@ main =
234 let (axis_key_size, axis_key_locations) = getKeyLocations colsRepeat' videoClipRect 258 let (axis_key_size, axis_key_locations) = getKeyLocations colsRepeat' videoClipRect
235 259
236 let _ALL_PITCHES = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) [_AXIS_BOTTOMLEFT_PITCH .. _AXIS_TOPRIGHT_PITCH] 260 let _ALL_PITCHES = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) [_AXIS_BOTTOMLEFT_PITCH .. _AXIS_TOPRIGHT_PITCH]
237 keysOFF really = smartDrawKeys colsRepeat' really _ALL_PITCHES Set.empty videoSurface font' axis_key_locations axis_key_size 261 keysOFF really = allKeysOff colsRepeat' really videoSurface font' axis_key_locations axis_key_size
238 allKeysOFF = keysOFF False 262 allKeysOFF = keysOFF False
239 allKeysReallyOFF = keysOFF True 263 allKeysReallyOFF = keysOFF True
240 264