diff options
author | Andrew Cady <d@jerkface.net> | 2014-01-18 05:15:25 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2014-01-18 05:15:25 -0500 |
commit | 4429a9397e5e5fefe307be2a19fcd17585d1ee6f (patch) | |
tree | ed3a0fa8d694f8eda760fdb8a4cd628e6f4d2024 | |
parent | 9a825911e6e73eefbaac5470e13a178276ef3370 (diff) |
add "octave squash" functionality but disable it
it looks terrible because the squashing is into a horizontal band.
-rw-r--r-- | AlsaSeq.hs | 4 | ||||
-rw-r--r-- | axis.hs | 97 |
2 files changed, 49 insertions, 52 deletions
@@ -1,5 +1,7 @@ | |||
1 | {-# LANGUAGE NondecreasingIndentation #-} | 1 | {-# LANGUAGE NondecreasingIndentation #-} |
2 | module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent, cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch, unPitch, unChannel) where | 2 | module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent, |
3 | cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch, | ||
4 | unPitch, unChannel) where | ||
3 | import qualified Sound.ALSA.Exception as AlsaExc | 5 | import qualified Sound.ALSA.Exception as AlsaExc |
4 | import qualified Sound.ALSA.Sequencer.Address as Addr | 6 | import qualified Sound.ALSA.Sequencer.Address as Addr |
5 | import qualified Sound.ALSA.Sequencer as SndSeq | 7 | import qualified Sound.ALSA.Sequencer as SndSeq |
@@ -18,6 +18,7 @@ import qualified System.Exit as Exit | |||
18 | import Data.List (elemIndex, elemIndices, filter) | 18 | import Data.List (elemIndex, elemIndices, filter) |
19 | import GHC.Word | 19 | import GHC.Word |
20 | import Data.Bits | 20 | import Data.Bits |
21 | import qualified Sound.ALSA.Sequencer.Event as Event | ||
21 | 22 | ||
22 | netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String | 23 | netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String |
23 | netwireIsCool = | 24 | netwireIsCool = |
@@ -42,6 +43,7 @@ _AXIS_UNIQUE_COLS = 7 | |||
42 | _AXIS_COLS_REPEAT = 2 | 43 | _AXIS_COLS_REPEAT = 2 |
43 | _AXIS_TOP_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2) | 44 | _AXIS_TOP_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2) |
44 | _AXIS_BOTTOM_PITCH = 81 - (7 * _AXIS_ROWS) - 3 | 45 | _AXIS_BOTTOM_PITCH = 81 - (7 * _AXIS_ROWS) - 3 |
46 | _OCTAVE_SQUASH = False -- it's terrible, because it draws the octave in the wrong shape | ||
45 | 47 | ||
46 | _KEY_COLOR = (SDL.Color 0 0 255) | 48 | _KEY_COLOR = (SDL.Color 0 0 255) |
47 | _KEY_BG_COLOR = (SDL.Color 0 0 0) | 49 | _KEY_BG_COLOR = (SDL.Color 0 0 0) |
@@ -70,22 +72,22 @@ http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter | |||
70 | 15 – bright white (#FFFFFF) 111111 63 | 72 | 15 – bright white (#FFFFFF) 111111 63 |
71 | -} | 73 | -} |
72 | 74 | ||
73 | _CGA = [--(SDL.Color 0x00 0x00 0x00), --black | 75 | _CGA = [--(SDL.Color 0x00 0x00 0x00), --black |
74 | (SDL.Color 0x00 0x00 0xAA), --blue | 76 | (SDL.Color 0x00 0x00 0xAA), --blue |
75 | (SDL.Color 0x00 0xAA 0x00), --green | 77 | (SDL.Color 0x00 0xAA 0x00), --green |
76 | (SDL.Color 0x00 0xAA 0xAA), --cyan | 78 | (SDL.Color 0x00 0xAA 0xAA), --cyan |
77 | (SDL.Color 0xAA 0x00 0x00), --red | 79 | (SDL.Color 0xAA 0x00 0x00), --red |
78 | (SDL.Color 0xAA 0x00 0xAA), --magenta | 80 | (SDL.Color 0xAA 0x00 0xAA), --magenta |
79 | (SDL.Color 0xAA 0x55 0x00), --brown | 81 | (SDL.Color 0xAA 0x55 0x00), --brown |
80 | (SDL.Color 0xAA 0xAA 0xAA), --white / light gray | 82 | (SDL.Color 0xAA 0xAA 0xAA), --white / light gray |
81 | (SDL.Color 0x55 0x55 0x55), --dark gray / bright black | 83 | (SDL.Color 0x55 0x55 0x55), --dark gray / bright black |
82 | (SDL.Color 0x55 0x55 0xFF), --bright blue | 84 | (SDL.Color 0x55 0x55 0xFF), --bright blue |
83 | (SDL.Color 0x55 0xFF 0x55), --bright green | 85 | (SDL.Color 0x55 0xFF 0x55), --bright green |
84 | (SDL.Color 0x55 0xFF 0xFF), --bright cyan | 86 | (SDL.Color 0x55 0xFF 0xFF), --bright cyan |
85 | (SDL.Color 0xFF 0x55 0x55), --bright red | 87 | (SDL.Color 0xFF 0x55 0x55), --bright red |
86 | (SDL.Color 0xFF 0x55 0xFF), --bright magenta | 88 | (SDL.Color 0xFF 0x55 0xFF), --bright magenta |
87 | (SDL.Color 0xFF 0xFF 0x55), --bright yellow | 89 | (SDL.Color 0xFF 0xFF 0x55), --bright yellow |
88 | (SDL.Color 0xFF 0xFF 0xFF)] --bright white | 90 | (SDL.Color 0xFF 0xFF 0xFF)] --bright white |
89 | 91 | ||
90 | _drawHexircle f v x y s c = | 92 | _drawHexircle f v x y s c = |
91 | if _USE_HEXAGONS | 93 | if _USE_HEXAGONS |
@@ -96,47 +98,40 @@ drawHexircle = _drawHexircle False | |||
96 | drawFilledHexircle = _drawHexircle True | 98 | drawFilledHexircle = _drawHexircle True |
97 | colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b | 99 | colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b |
98 | 100 | ||
99 | drawKeys pitches videoSurface font axis_key_locations axis_key_size = do | 101 | smartDrawKeys reallyErase drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do |
100 | 102 | ||
101 | forM_ pitches $ \pitch -> do | 103 | let drawList = filter (\ (c, _) -> unChannel c /= 9) $ Set.toList drawSet |
102 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do | 104 | let eraseList = filter (\ (c, _) -> unChannel c /= 9) $ Set.toList eraseSet |
103 | let (x, y) = axis_key_locations !! idx | ||
104 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) _KEY_COLOR_PIXEL | ||
105 | centerText videoSurface x y font _KEY_TEXT_COLOR _KEY_COLOR (smartShowPitch pitch) | ||
106 | 105 | ||
106 | forM_ [(eraseList, True), (drawList, False)] $ \ (ls, erase) -> do | ||
107 | forM_ ls $ \ (c, n) -> do | ||
108 | let text = smartShowPitch (unPitch n) | ||
109 | let pitch = if _OCTAVE_SQUASH then (unPitch n) `mod` 12 + 12 * 6 else (unPitch n) | ||
110 | let chann = unChannel c | ||
111 | let fillColor = if _COLORIZE_BY_CHANNEL | ||
112 | then _CGA !! (((fromIntegral chann) + 2) `mod` 16) | ||
113 | else _KEY_COLOR | ||
114 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do | ||
115 | drawKey idx videoSurface font axis_key_locations axis_key_size | ||
116 | (if erase then _KEY_BG_COLOR else fillColor) -- TODO: rename KEY_BG_COLOR as CANVAS_BG_COLOR | ||
117 | (if reallyErase then _KEY_BG_COLOR_PIXEL else _KEY_COLOR_PIXEL) | ||
118 | (if erase then Nothing else (Just text)) | ||
119 | |||
120 | drawKey idx videoSurface font axis_key_locations axis_key_size fillColor borderColor text = do | ||
121 | let (x, y) = axis_key_locations !! idx | ||
122 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel fillColor) | ||
123 | drawHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) borderColor | ||
124 | case text of | ||
125 | (Just t) -> centerText videoSurface x y font _KEY_TEXT_COLOR fillColor t | ||
126 | _ -> return () | ||
127 | |||
128 | eraseKeys_ really pitches videoSurface font axis_key_locations axis_key_size = | ||
129 | let pitchSet = Set.fromList $ map (\p -> (Event.Channel 1, Event.Pitch p)) pitches | ||
130 | in | ||
131 | smartDrawKeys really Set.empty pitchSet videoSurface font axis_key_locations axis_key_size | ||
107 | reallyEraseKeys = eraseKeys_ True | 132 | reallyEraseKeys = eraseKeys_ True |
108 | eraseKeys = eraseKeys_ False | 133 | eraseKeys = eraseKeys_ False |
109 | 134 | ||
110 | |||
111 | smartDrawKeys really drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do | ||
112 | |||
113 | let drawList = map (\ (_, n) -> unPitch n) $ Set.toList drawSet | ||
114 | let eraseList = map (\ (_, n) -> unPitch n) $ filter (\ (c, _) -> unChannel c /= 9) $ Set.toList eraseSet | ||
115 | |||
116 | eraseKeys_ really eraseList videoSurface font axis_key_locations axis_key_size | ||
117 | |||
118 | forM_ (Set.toList drawSet) $ \ (c, n) -> do | ||
119 | let pitch = unPitch n | ||
120 | let chann = unChannel c | ||
121 | let color = if _COLORIZE_BY_CHANNEL | ||
122 | then _CGA !! (((fromIntegral chann) + 2) `mod` 16) | ||
123 | else _KEY_COLOR | ||
124 | Control.Monad.when(chann /= 9) $ -- TODO: do this elsewhere | ||
125 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do | ||
126 | let (x, y) = axis_key_locations !! idx | ||
127 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel color) | ||
128 | drawHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) _KEY_COLOR_PIXEL | ||
129 | centerText videoSurface x y font _KEY_TEXT_COLOR color (smartShowPitch pitch) | ||
130 | |||
131 | eraseKeys_ really pitches videoSurface font axis_key_locations axis_key_size = do | ||
132 | |||
133 | forM_ pitches $ \pitch -> do | ||
134 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do | ||
135 | let (x, y) = axis_key_locations !! idx | ||
136 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) _KEY_BG_COLOR_PIXEL | ||
137 | drawHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (if really then _KEY_BG_COLOR_PIXEL else _KEY_COLOR_PIXEL) | ||
138 | -- centerText videoSurface x y font _KEY_TEXT_COLOR _KEY_BG_COLOR (smartShowPitch pitch) | ||
139 | |||
140 | fi = fromIntegral | 135 | fi = fromIntegral |
141 | rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255)) | 136 | rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255)) |
142 | 137 | ||