module Solkattu.Tala (
Akshara
, anga_aksharas
, tala_angas
, tala_aksharas
, tala_labels
, Tala(..)
, tala_name
, Anga(..)
, dhruva, matya, rupaka, jhampa, triputa, ata, eka
, dhruva_tala, matya_tala, rupaka_tala, jhampa_tala, triputa_tala, ata_tala
, eka_tala
, adi_tala
, misra_chapu
, kanda_chapu
, rupaka_fast
, any_beats
, beats
) where
import qualified Data.Map as Map
import qualified Data.Text as Text
import qualified Util.Num as Num
import Global
type Akshara = Int
anga_aksharas :: Jati -> Anga -> Akshara
anga_aksharas :: Jati -> Anga -> Jati
anga_aksharas Jati
jati Anga
anga = case Anga
anga of
Clap Jati
n -> Jati
n
Wave Jati
n -> Jati
n
Anga
I -> Jati
jati
Anga
O -> Jati
2
Anga
U -> Jati
1
anga_labels :: Jati -> Anga -> [Text]
anga_labels :: Jati -> Anga -> [Text]
anga_labels Jati
jati = \case
Clap Jati
n -> Text
"X" forall a. a -> [a] -> [a]
: forall a. Jati -> a -> [a]
replicate (Jati
nforall a. Num a => a -> a -> a
-Jati
1) Text
"-"
Wave Jati
n -> Text
"O" forall a. a -> [a] -> [a]
: forall a. Jati -> a -> [a]
replicate (Jati
nforall a. Num a => a -> a -> a
-Jati
1) Text
"-"
Anga
I -> forall a. Jati -> [a] -> [a]
take Jati
jati (forall a b. (a -> b) -> [a] -> [b]
map forall a. Show a => a -> Text
showt [Integer
0..])
Anga
O -> [Text
"X", Text
"O"]
Anga
U -> [Text
"X"]
tala_angas :: Tala -> [Akshara]
tala_angas :: Tala -> [Jati]
tala_angas Tala
tala = forall a b. (a -> b) -> [a] -> [b]
map (Jati -> Anga -> Jati
anga_aksharas (Tala -> Jati
_jati Tala
tala)) (Tala -> [Anga]
_angas Tala
tala)
tala_aksharas :: Tala -> Akshara
tala_aksharas :: Tala -> Jati
tala_aksharas = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
Num.sum forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tala -> [Jati]
tala_angas
tala_labels :: Tala -> [Text]
tala_labels :: Tala -> [Text]
tala_labels Tala
tala = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Jati -> Anga -> [Text]
anga_labels (Tala -> Jati
_jati Tala
tala)) (Tala -> [Anga]
_angas Tala
tala)
data Tala = Tala {
Tala -> Text
_name :: !Text
, Tala -> [Anga]
_angas :: ![Anga]
, Tala -> Jati
_jati :: !Jati
} deriving (Jati -> Tala -> ShowS
[Tala] -> ShowS
Tala -> String
forall a.
(Jati -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tala] -> ShowS
$cshowList :: [Tala] -> ShowS
show :: Tala -> String
$cshow :: Tala -> String
showsPrec :: Jati -> Tala -> ShowS
$cshowsPrec :: Jati -> Tala -> ShowS
Show, Tala -> Tala -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tala -> Tala -> Bool
$c/= :: Tala -> Tala -> Bool
== :: Tala -> Tala -> Bool
$c== :: Tala -> Tala -> Bool
Eq)
instance Pretty Tala where pretty :: Tala -> Text
pretty = forall a. Show a => a -> Text
showt
tala_name :: Tala -> Text
tala_name :: Tala -> Text
tala_name Tala
tala
| Tala
tala forall a. Eq a => a -> a -> Bool
== Tala
adi_tala = Text
"adi"
| Tala -> [Anga]
_angas Tala
tala forall a. Eq a => a -> a -> Bool
== [Anga
I] = forall a. Show a => a -> Text
showt (Tala -> Jati
_jati Tala
tala) forall a. Semigroup a => a -> a -> a
<> Text
" beats"
| Tala -> Jati
_jati Tala
tala forall a. Eq a => a -> a -> Bool
== Jati
0 = Tala -> Text
_name Tala
tala
| Bool
otherwise = [Text] -> Text
Text.unwords
[ Tala -> Text
_name Tala
tala
, forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault (forall a. Show a => a -> Text
showt (Tala -> Jati
_jati Tala
tala)) (Tala -> Jati
_jati Tala
tala) Map Jati Text
jatis
, Text
"jati"
]
where
jatis :: Map Jati Text
jatis = forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
[ (Jati
3, Text
"tisra")
, (Jati
4, Text
"chatusra")
, (Jati
5, Text
"kanda")
, (Jati
9, Text
"sankirna")
]
data Anga = Clap !Akshara | Wave !Akshara
| I | O | U
deriving (Jati -> Anga -> ShowS
[Anga] -> ShowS
Anga -> String
forall a.
(Jati -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Anga] -> ShowS
$cshowList :: [Anga] -> ShowS
show :: Anga -> String
$cshow :: Anga -> String
showsPrec :: Jati -> Anga -> ShowS
$cshowsPrec :: Jati -> Anga -> ShowS
Show, Anga -> Anga -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Anga -> Anga -> Bool
$c/= :: Anga -> Anga -> Bool
== :: Anga -> Anga -> Bool
$c== :: Anga -> Anga -> Bool
Eq)
instance Pretty Anga where pretty :: Anga -> Text
pretty = forall a. Show a => a -> Text
showt
type Jati = Int
dhruva, matya, rupaka, jhampa, triputa, ata, eka :: [Anga]
dhruva :: [Anga]
dhruva = [Anga
I, Anga
O, Anga
I, Anga
I]
matya :: [Anga]
matya = [Anga
I, Anga
O, Anga
I]
rupaka :: [Anga]
rupaka = [Anga
O, Anga
I]
jhampa :: [Anga]
jhampa = [Anga
I, Anga
U, Anga
O]
triputa :: [Anga]
triputa = [Anga
I, Anga
O, Anga
O]
ata :: [Anga]
ata = [Anga
I, Anga
I, Anga
O, Anga
O]
eka :: [Anga]
eka = [Anga
I]
dhruva_tala, matya_tala, rupaka_tala, jhampa_tala, triputa_tala, ata_tala,
eka_tala :: Tala
dhruva_tala :: Tala
dhruva_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"dhruva" [Anga]
dhruva Jati
4
matya_tala :: Tala
matya_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"matya" [Anga]
matya Jati
4
rupaka_tala :: Tala
rupaka_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"rupaka" [Anga]
rupaka Jati
4
jhampa_tala :: Tala
jhampa_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"jhampa" [Anga]
jhampa Jati
7
triputa_tala :: Tala
triputa_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"triputa" [Anga]
triputa Jati
3
ata_tala :: Tala
ata_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"ata" [Anga]
ata Jati
5
eka_tala :: Tala
eka_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"eka" [Anga]
eka Jati
4
adi_tala :: Tala
adi_tala :: Tala
adi_tala = Text -> [Anga] -> Jati -> Tala
Tala Text
"adi" [Anga]
triputa Jati
4
misra_chapu :: Tala
misra_chapu :: Tala
misra_chapu = Text -> [Anga] -> Jati -> Tala
Tala Text
"misra chapu" [Jati -> Anga
Wave Jati
1, Jati -> Anga
Wave Jati
2, Jati -> Anga
Clap Jati
2, Jati -> Anga
Clap Jati
2] Jati
0
kanda_chapu :: Tala
kanda_chapu :: Tala
kanda_chapu = Text -> [Anga] -> Jati -> Tala
Tala Text
"kanda chapu" [Jati -> Anga
Clap Jati
2, Jati -> Anga
Clap Jati
1, Jati -> Anga
Clap Jati
2] Jati
0
rupaka_fast :: Tala
rupaka_fast :: Tala
rupaka_fast = Text -> [Anga] -> Jati -> Tala
Tala Text
"rupaka" [Jati -> Anga
Clap Jati
1, Jati -> Anga
Clap Jati
1, Jati -> Anga
Wave Jati
1] Jati
0
any_beats :: Tala
any_beats :: Tala
any_beats = Text -> [Anga] -> Jati -> Tala
Tala Text
"any beats" [Anga
I] Jati
4
beats :: Akshara -> Tala
beats :: Jati -> Tala
beats Jati
aksharas = Text -> [Anga] -> Jati -> Tala
Tala Text
"beats" [Anga
I] Jati
aksharas