{-# LANGUAGE CPP #-}
module Cmd.PhysicalKey where
import qualified Data.Map as Map
import qualified Util.CallStack as CallStack
import qualified Cmd.KeyLayouts as KeyLayouts
#ifndef TESTING
import qualified Local.KeyLayout
#endif
import qualified Perform.Pitch as Pitch
import Global
physical_key :: CallStack.Stack => Char -> Char
physical_key :: Stack => Char -> Char
physical_key Char
c =
forall a. a -> Maybe a -> a
fromMaybe (forall a. Stack => Text -> a
errorStack forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> Text
showt Char
c forall a. Semigroup a => a -> a -> a
<> Text
" not found") forall a b. (a -> b) -> a -> b
$
#ifdef TESTING
KeyLayouts.from_qwerty KeyLayouts.dvorak c
#else
Layout -> Char -> Maybe Char
KeyLayouts.from_qwerty Layout
Local.KeyLayout.layout Char
c
#endif
pitch_map :: Map Char Pitch.Pitch
pitch_map :: Map Char Pitch
pitch_map = forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
[ [(Char
'1', Accidentals -> Degree -> Pitch
Pitch.Pitch Accidentals
1 (Accidentals -> Accidentals -> Degree
Pitch.Degree Accidentals
0 (-Accidentals
1)))]
, Accidentals -> [Char] -> Accidentals -> [(Char, Pitch)]
keys Accidentals
1 [Char]
"234567890" Accidentals
1
, Accidentals -> [Char] -> Accidentals -> [(Char, Pitch)]
keys Accidentals
1 [Char]
"qwertyuiop" Accidentals
0
, Accidentals -> [Char] -> Accidentals -> [(Char, Pitch)]
keys Accidentals
0 [Char]
"sdfghjkl;" Accidentals
1
, Accidentals -> [Char] -> Accidentals -> [(Char, Pitch)]
keys Accidentals
0 [Char]
"zxcvbnm,." Accidentals
0
]
where
keys :: Accidentals -> [Char] -> Accidentals -> [(Char, Pitch)]
keys Accidentals
oct [Char]
letters Accidentals
accs =
[ (Char
c, Accidentals -> Degree -> Pitch
Pitch.Pitch Accidentals
oct forall a b. (a -> b) -> a -> b
$ Accidentals -> Accidentals -> Degree
Pitch.Degree Accidentals
pc Accidentals
accs)
| (Accidentals
pc, Char
c) <- forall a b. [a] -> [b] -> [(a, b)]
zip [Accidentals
0..] (forall a b. (a -> b) -> [a] -> [b]
map Stack => Char -> Char
physical_key [Char]
letters)
]