module Music.Theory.Z.Drape_1999.Cli where

import Data.Char {- base -}
import Data.Int {- base -}

import Music.Theory.Z {- hmt -}
import Music.Theory.Z.Drape_1999 {- hmt -}
import Music.Theory.Z.Forte_1973 {- hmt -}
import Music.Theory.Z.Sro {- hmt -}

type Z12 = Int8

help :: [String]
help :: [String]
help =
    [String
"pct ess pcset"
    ,String
"pct fl -c cset"
    ,String
"pct frg pcset"
    ,String
"pct si [pcset]"
    ,String
"pct spsc set-class..."
    ,String
"pct sra"
    ,String
"pct sro sro"
    ,String
"pct tmatrix pcseg"
    ,String
"pct trs [-m] pcseg"]

z16_seq_parse :: String -> [Int]
z16_seq_parse :: String -> [Int]
z16_seq_parse = forall a b. (a -> b) -> [a] -> [b]
map Char -> Int
digitToInt

pco_parse :: String -> [Z12]
pco_parse :: String -> [Z12]
pco_parse = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (Integral a, Num b) => a -> b
fromIntegral forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Int]
z16_seq_parse

pco_pp :: [Z12] -> String
pco_pp :: [Z12] -> String
pco_pp = forall a b. (a -> b) -> [a] -> [b]
map (Char -> Char
toUpper forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Integral t => t -> Char
integral_to_digit)

-- > cset_parse "34" == [3,4]
cset_parse :: String -> [Int]
cset_parse :: String -> [Int]
cset_parse = forall a b. (a -> b) -> [a] -> [b]
map Char -> Int
digitToInt

type CMD = String -> String

mk_cmd :: ([Z12] -> [Z12]) -> CMD
mk_cmd :: ([Z12] -> [Z12]) -> CMD
mk_cmd [Z12] -> [Z12]
f = [Z12] -> String
pco_pp forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Z12] -> [Z12]
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Z12]
pco_parse

mk_cmd_many :: ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many :: ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many [Z12] -> [[Z12]]
f = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map [Z12] -> String
pco_pp forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Z12] -> [[Z12]]
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Z12]
pco_parse

-- > ess_cmd "0164325" "23A" == unlines ["923507A","2B013A9"]
ess_cmd :: String -> CMD
ess_cmd :: String -> CMD
ess_cmd String
p = ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many (forall i. Integral i => Z i -> [i] -> [i] -> [[i]]
ess forall i. Num i => Z i
z12 (String -> [Z12]
pco_parse String
p))

z12_sc_name :: [Z12] -> SC_Name
z12_sc_name :: [Z12] -> String
z12_sc_name = forall i. Integral i => [i] -> String
sc_name

fl_c_cmd :: CMD
fl_c_cmd :: CMD
fl_c_cmd = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map [Z12] -> String
z12_sc_name forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall i n. (Integral i, Num n) => i -> [[n]]
scs_n forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Int]
cset_parse

frg_cmd :: CMD
frg_cmd :: CMD
frg_cmd String
p =
    let p' :: [Z12]
p' = String -> [Z12]
pco_parse String
p
    in [String] -> String
unlines [forall i. Integral i => [i] -> String
frg_pp [Z12]
p',T6 [Int] -> String
ic_cycle_vector_pp (forall i. Integral i => [i] -> T6 [Int]
ic_cycle_vector [Z12]
p')]

pi_cmd :: String -> CMD
pi_cmd :: String -> CMD
pi_cmd String
p = ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many (forall i. Integral i => Z i -> [Int] -> [i] -> [[i]]
pci forall i. Num i => Z i
z12 (String -> [Int]
z16_seq_parse String
p))

scc_cmd :: String -> CMD
scc_cmd :: String -> CMD
scc_cmd String
p = ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many (forall i. Integral i => Z i -> [i] -> [i] -> [[i]]
scc forall i. Num i => Z i
z12 (forall n. Num n => String -> [n]
sc String
p))

si_cmd :: CMD
si_cmd :: CMD
si_cmd = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. (Integral i, Show i) => [i] -> [String]
si forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [Z12]
pco_parse

z12_sc_name_long :: [Z12] -> SC_Name
z12_sc_name_long :: [Z12] -> String
z12_sc_name_long = forall i. Integral i => [i] -> String
sc_name_long

-- > spsc_cmd ["4-11","4-12"] == "5-26[02458]\n"
spsc_cmd :: [String] -> String
spsc_cmd :: [String] -> String
spsc_cmd = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map [Z12] -> String
z12_sc_name_long forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => Z i -> [[i]] -> [[i]]
spsc forall i. Num i => Z i
z12 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall n. Num n => String -> [n]
sc

sra_cmd :: CMD
sra_cmd :: CMD
sra_cmd = ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many (forall i. Integral i => Z i -> [i] -> [[i]]
sra forall i. Num i => Z i
z12)

sro_cmd :: String -> CMD
sro_cmd :: String -> CMD
sro_cmd String
o = ([Z12] -> [Z12]) -> CMD
mk_cmd (forall i. Integral i => Z i -> Sro i -> [i] -> [i]
sro forall i. Num i => Z i
z12 (forall i. Integral i => i -> String -> Sro i
sro_parse Z12
5 String
o))

-- > putStrLn $ tmatrix_cmd "1258"
tmatrix_cmd :: CMD
tmatrix_cmd :: CMD
tmatrix_cmd = ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many (forall i. Integral i => Z i -> [i] -> [[i]]
tmatrix forall i. Num i => Z i
z12)

-- > putStrLn $ trs_cmd (trs z12) "024579" "642"
trs_cmd :: ([Z12] -> [Z12] -> [[Z12]]) -> String -> CMD
trs_cmd :: ([Z12] -> [Z12] -> [[Z12]]) -> String -> CMD
trs_cmd [Z12] -> [Z12] -> [[Z12]]
f String
p = ([Z12] -> [[Z12]]) -> CMD
mk_cmd_many ([Z12] -> [Z12] -> [[Z12]]
f (String -> [Z12]
pco_parse String
p))

interact_ln :: CMD -> IO ()
interact_ln :: CMD -> IO ()
interact_ln CMD
f = CMD -> IO ()
interact ([String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map CMD
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> [String]
lines)

pct_cli :: [String] -> IO ()
pct_cli :: [String] -> IO ()
pct_cli [String]
arg = do
  case [String]
arg of
    [String
"ess",String
p] -> CMD -> IO ()
interact_ln (String -> CMD
ess_cmd String
p)
    [String
"fl",String
"-c",String
c] -> String -> IO ()
putStr (CMD
fl_c_cmd String
c)
    [String
"frg",String
p] -> String -> IO ()
putStr (CMD
frg_cmd String
p)
    [String
"pi",String
p,String
q] -> String -> IO ()
putStr (String -> CMD
pi_cmd String
q String
p)
    [String
"scc",String
p] -> CMD -> IO ()
interact_ln (String -> CMD
scc_cmd String
p)
    [String
"scc",String
p,String
q] -> String -> IO ()
putStr (String -> CMD
scc_cmd String
p String
q)
    [String
"si"] -> CMD -> IO ()
interact_ln CMD
si_cmd
    [String
"si",String
p] -> String -> IO ()
putStr (CMD
si_cmd String
p)
    String
"spsc":[String]
p -> String -> IO ()
putStr ([String] -> String
spsc_cmd [String]
p)
    [String
"sra"] -> CMD -> IO ()
interact_ln CMD
sra_cmd
    [String
"sro",String
o] -> CMD -> IO ()
interact_ln (String -> CMD
sro_cmd String
o)
    [String
"tmatrix",String
p] -> String -> IO ()
putStr (CMD
tmatrix_cmd String
p)
    [String
"trs",String
p] -> CMD -> IO ()
interact_ln (([Z12] -> [Z12] -> [[Z12]]) -> String -> CMD
trs_cmd (forall i. Integral i => Z i -> [i] -> [i] -> [[i]]
trs forall i. Num i => Z i
z12) String
p)
    [String
"trs",String
"-m",String
p] -> CMD -> IO ()
interact_ln (([Z12] -> [Z12] -> [[Z12]]) -> String -> CMD
trs_cmd (forall i. Integral i => Z i -> [i] -> [i] -> [[i]]
trs_m forall i. Num i => Z i
z12) String
p)
    [String]
_ -> String -> IO ()
putStrLn ([String] -> String
unlines [String]
help)