summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2014-01-18 05:15:25 -0500
committerAndrew Cady <d@jerkface.net>2014-01-18 05:15:25 -0500
commit4429a9397e5e5fefe307be2a19fcd17585d1ee6f (patch)
treeed3a0fa8d694f8eda760fdb8a4cd628e6f4d2024
parent9a825911e6e73eefbaac5470e13a178276ef3370 (diff)
add "octave squash" functionality but disable it
it looks terrible because the squashing is into a horizontal band.
-rw-r--r--AlsaSeq.hs4
-rw-r--r--axis.hs97
2 files changed, 49 insertions, 52 deletions
diff --git a/AlsaSeq.hs b/AlsaSeq.hs
index 0d722e9..99e7c80 100644
--- a/AlsaSeq.hs
+++ b/AlsaSeq.hs
@@ -1,5 +1,7 @@
1{-# LANGUAGE NondecreasingIndentation #-} 1{-# LANGUAGE NondecreasingIndentation #-}
2module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent, cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch, unPitch, unChannel) where 2module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent,
3cmdlineAlsaConnect, printChordLn, showChord, pitchList, showPitch,
4unPitch, unChannel) where
3import qualified Sound.ALSA.Exception as AlsaExc 5import qualified Sound.ALSA.Exception as AlsaExc
4import qualified Sound.ALSA.Sequencer.Address as Addr 6import qualified Sound.ALSA.Sequencer.Address as Addr
5import qualified Sound.ALSA.Sequencer as SndSeq 7import qualified Sound.ALSA.Sequencer as SndSeq
diff --git a/axis.hs b/axis.hs
index 312283e..e35f7a8 100644
--- a/axis.hs
+++ b/axis.hs
@@ -18,6 +18,7 @@ import qualified System.Exit as Exit
18import Data.List (elemIndex, elemIndices, filter) 18import Data.List (elemIndex, elemIndices, filter)
19import GHC.Word 19import GHC.Word
20import Data.Bits 20import Data.Bits
21import qualified Sound.ALSA.Sequencer.Event as Event
21 22
22netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String 23netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String
23netwireIsCool = 24netwireIsCool =
@@ -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
7015 – bright white (#FFFFFF) 111111 63 7215 – 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
96drawFilledHexircle = _drawHexircle True 98drawFilledHexircle = _drawHexircle True
97colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b 99colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b
98 100
99drawKeys pitches videoSurface font axis_key_locations axis_key_size = do 101smartDrawKeys 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
120drawKey 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
128eraseKeys_ 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
107reallyEraseKeys = eraseKeys_ True 132reallyEraseKeys = eraseKeys_ True
108eraseKeys = eraseKeys_ False 133eraseKeys = eraseKeys_ False
109 134
110
111smartDrawKeys 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
131eraseKeys_ 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
140fi = fromIntegral 135fi = fromIntegral
141rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255)) 136rgbColor r g b = SDL.Pixel (shiftL (fi r) 24 .|. shiftL (fi g) 16 .|. shiftL (fi b) 8 .|. (fi 255))
142 137