{-# OPTIONS_GHC -threaded #-}
module Composition.Sound.Keyboard (
qwerty2dvorak
, dvorak2qwerty
, input2BL
, input2BLN
, input2BLMN
, readFile2BL
, readFile2BLN
, readFile2BLMN
, readFile2BLGen
, readFile2BLGenN
, readFile2BLGenMN
, readFileDoubles
, readFileDoublesN
, readFileDoublesMN
, readFileDoublesGen
, readFileDoublesGenN
, readFileDoublesGenMN
, takeDoubles
, hashStr2
, convH
) where
import CaseBi.Arr (getBFstL',getBFstLSorted')
import Data.Char (isAsciiLower)
import GHC.Arr
import Data.Foldable.Ix
import GHC.Int (Int64)
import qualified Data.ByteString.Lazy.Char8 as BL (ByteString,map,zipWith,tail,filter,getContents,readFile,take,drop)
takeDoubles :: BL.ByteString -> [Int]
takeDoubles :: ByteString -> [Int]
takeDoubles ByteString
xs = (Char -> Char -> Int) -> ByteString -> ByteString -> [Int]
forall a. (Char -> Char -> a) -> ByteString -> ByteString -> [a]
BL.zipWith Char -> Char -> Int
hashStr2 ByteString
xs (ByteString -> [Int]) -> ByteString -> [Int]
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
BL.tail ByteString
xs
qwerty2dvorak :: BL.ByteString -> BL.ByteString
qwerty2dvorak :: ByteString -> ByteString
qwerty2dvorak = (Char -> Char) -> ByteString -> ByteString
BL.map (Char -> [(Char, Char)] -> Char -> Char
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstL' Char
' ' ([Char] -> [Char] -> [(Char, Char)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([Char]
"/;<>" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char
'a'..Char
'z']) [Char]
"wvszaxje.uidchtnmbrl'poygk,qf;"))
dvorak2qwerty :: BL.ByteString -> BL.ByteString
dvorak2qwerty :: ByteString -> ByteString
dvorak2qwerty = (Char -> Char) -> ByteString -> ByteString
BL.map (Char -> [(Char, Char)] -> Char -> Char
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstL' Char
' ' ([Char] -> [Char] -> [(Char, Char)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([Char]
"',.;" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char
'a'..Char
'z']) [Char]
"qwezanihdyujgcvpmlsrxo;kf.,bt/"))
hashStr2 :: Char -> Char -> Int
hashStr2 :: Char -> Char -> Int
hashStr2 Char
x Char
y = Int -> [(Char, Int)] -> Char -> Int
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstLSorted' Int
57 ([Char] -> [Int] -> [(Char, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Char
'a'..Char
'z'] ([Int] -> [(Char, Int)])
-> ([[Int]] -> [Int]) -> [[Int]] -> [(Char, Int)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map (\Int
t -> Int -> [(Char, Int)] -> Char -> Int
forall a b. Ord a => b -> [(a, b)] -> a -> b
getBFstLSorted' (Int
26 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
t Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
18) ([Char] -> [Int] -> [(Char, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Char
'a'..Char
'z'] [(Int
26 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
t Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
4)..]) Char
y) ([Int] -> [Int]) -> ([[Int]] -> [Int]) -> [[Int]] -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
[[Int]] -> [Int]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Int]] -> [(Char, Int)]) -> [[Int]] -> [(Char, Int)]
forall a b. (a -> b) -> a -> b
$ [[Int
0],[Int
6..Int
8],[Int
1],[Int
9..Int
11],[Int
4],[Int
12..Int
16],[Int
2],[Int
17..Int
21],[Int
3],[Int
22..Int
24],[Int
5,Int
25]]) Char
x
input2BL :: IO (BL.ByteString)
input2BL :: IO ByteString
input2BL = (ByteString -> ByteString) -> IO ByteString -> IO ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [] ((Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) IO ByteString
BL.getContents
input2BLN :: Int64 -> IO (BL.ByteString)
input2BLN :: Int64 -> IO ByteString
input2BLN Int64
n = (ByteString -> ByteString) -> IO ByteString -> IO ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [] (Int64 -> ByteString -> ByteString
BL.take Int64
n (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) IO ByteString
BL.getContents
input2BLMN :: Int64 -> Int64 -> IO (BL.ByteString)
input2BLMN :: Int64 -> Int64 -> IO ByteString
input2BLMN Int64
m Int64
n = (ByteString -> ByteString) -> IO ByteString -> IO ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [] (Int64 -> ByteString -> ByteString
BL.take Int64
n (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> ByteString -> ByteString
BL.drop Int64
m (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) IO ByteString
BL.getContents
readFile2BLGen :: String -> FilePath -> IO (BL.ByteString)
readFile2BLGen :: [Char] -> [Char] -> IO ByteString
readFile2BLGen [Char]
ys = (ByteString -> ByteString) -> IO ByteString -> IO ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys ((Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) (IO ByteString -> IO ByteString)
-> ([Char] -> IO ByteString) -> [Char] -> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO ByteString
BL.readFile
readFile2BLGenN :: Int64 -> String -> FilePath -> IO (BL.ByteString)
readFile2BLGenN :: Int64 -> [Char] -> [Char] -> IO ByteString
readFile2BLGenN Int64
n [Char]
ys = (ByteString -> ByteString) -> IO ByteString -> IO ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys (Int64 -> ByteString -> ByteString
BL.take Int64
n (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) (IO ByteString -> IO ByteString)
-> ([Char] -> IO ByteString) -> [Char] -> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO ByteString
BL.readFile
readFile2BLGenMN :: Int64 -> Int64 -> String -> FilePath -> IO (BL.ByteString)
readFile2BLGenMN :: Int64 -> Int64 -> [Char] -> [Char] -> IO ByteString
readFile2BLGenMN Int64
m Int64
n [Char]
ys = (ByteString -> ByteString) -> IO ByteString -> IO ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys (Int64 -> ByteString -> ByteString
BL.take Int64
n (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> ByteString -> ByteString
BL.drop Int64
m (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) (IO ByteString -> IO ByteString)
-> ([Char] -> IO ByteString) -> [Char] -> IO ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO ByteString
BL.readFile
convH :: String -> (BL.ByteString -> BL.ByteString) -> (BL.ByteString -> BL.ByteString)
convH :: [Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys ByteString -> ByteString
f
| [Char] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Char]
ys = ByteString -> ByteString
f
| [Char]
ys [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"q" = ByteString -> ByteString
qwerty2dvorak (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
f
| Bool
otherwise = ByteString -> ByteString
dvorak2qwerty (ByteString -> ByteString)
-> (ByteString -> ByteString) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
f
readFile2BL :: FilePath -> IO (BL.ByteString)
readFile2BL :: [Char] -> IO ByteString
readFile2BL = [Char] -> [Char] -> IO ByteString
readFile2BLGen []
{-# INLINE readFile2BL #-}
readFile2BLN :: Int64 -> FilePath -> IO (BL.ByteString)
readFile2BLN :: Int64 -> [Char] -> IO ByteString
readFile2BLN Int64
n = Int64 -> [Char] -> [Char] -> IO ByteString
readFile2BLGenN Int64
n []
{-# INLINE readFile2BLN #-}
readFile2BLMN :: Int64 -> Int64 -> FilePath -> IO (BL.ByteString)
readFile2BLMN :: Int64 -> Int64 -> [Char] -> IO ByteString
readFile2BLMN Int64
m Int64
n = Int64 -> Int64 -> [Char] -> [Char] -> IO ByteString
readFile2BLGenMN Int64
m Int64
n []
{-# INLINE readFile2BLMN #-}
readFileDoublesGen :: String -> FilePath -> IO [Int]
readFileDoublesGen :: [Char] -> [Char] -> IO [Int]
readFileDoublesGen [Char]
ys = (ByteString -> [Int]) -> IO ByteString -> IO [Int]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ByteString -> [Int]
takeDoubles (ByteString -> [Int])
-> (ByteString -> ByteString) -> ByteString -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys ((Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) (IO ByteString -> IO [Int])
-> ([Char] -> IO ByteString) -> [Char] -> IO [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO ByteString
BL.readFile
readFileDoublesGenN :: Int64 -> String -> FilePath -> IO [Int]
readFileDoublesGenN :: Int64 -> [Char] -> [Char] -> IO [Int]
readFileDoublesGenN Int64
n [Char]
ys = (ByteString -> [Int]) -> IO ByteString -> IO [Int]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> [Int] -> [Int]
forall a. Int -> [a] -> [a]
take (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n) ([Int] -> [Int]) -> (ByteString -> [Int]) -> ByteString -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [Int]
takeDoubles (ByteString -> [Int])
-> (ByteString -> ByteString) -> ByteString -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys ((Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) (IO ByteString -> IO [Int])
-> ([Char] -> IO ByteString) -> [Char] -> IO [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO ByteString
BL.readFile
readFileDoublesGenMN :: Int64 -> Int64 -> String -> FilePath -> IO [Int]
readFileDoublesGenMN :: Int64 -> Int64 -> [Char] -> [Char] -> IO [Int]
readFileDoublesGenMN Int64
m Int64
n [Char]
ys = (ByteString -> [Int]) -> IO ByteString -> IO [Int]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> Int -> [Int] -> [Int]
forall a. Eq a => Int -> Int -> [a] -> [a]
s2L (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
m) (Int64 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n) ([Int] -> [Int]) -> (ByteString -> [Int]) -> ByteString -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [Int]
takeDoubles (ByteString -> [Int])
-> (ByteString -> ByteString) -> ByteString -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> (ByteString -> ByteString) -> ByteString -> ByteString
convH [Char]
ys ((Char -> Bool) -> ByteString -> ByteString
BL.filter Char -> Bool
isAsciiLower)) (IO ByteString -> IO [Int])
-> ([Char] -> IO ByteString) -> [Char] -> IO [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> IO ByteString
BL.readFile
readFileDoubles :: FilePath -> IO [Int]
readFileDoubles :: [Char] -> IO [Int]
readFileDoubles = [Char] -> [Char] -> IO [Int]
readFileDoublesGen []
{-# INLINE readFileDoubles #-}
readFileDoublesN :: Int64 -> FilePath -> IO [Int]
readFileDoublesN :: Int64 -> [Char] -> IO [Int]
readFileDoublesN Int64
n = Int64 -> [Char] -> [Char] -> IO [Int]
readFileDoublesGenN Int64
n []
{-# INLINE readFileDoublesN #-}
readFileDoublesMN :: Int64 -> Int64 -> FilePath -> IO [Int]
readFileDoublesMN :: Int64 -> Int64 -> [Char] -> IO [Int]
readFileDoublesMN Int64
m Int64
n = Int64 -> Int64 -> [Char] -> [Char] -> IO [Int]
readFileDoublesGenMN Int64
m Int64
n []
{-# INLINE readFileDoublesMN #-}