-- Copyright 2017 Evan Laforge
-- This program is distributed under the terms of the GNU General Public
-- License 3.0, see COPYING or http://www.gnu.org/licenses/gpl-3.0.txt

-- | Realize to konnakol.  This is simpler than instruments since I just use
-- the sollus directly, but I still need realizations for 'Realize.PatternMap'.
module Solkattu.Instrument.Konnakol where
import qualified Derive.Expr as Expr
import qualified Solkattu.Realize as Realize
import qualified Solkattu.S as S
import qualified Solkattu.Solkattu as Solkattu
import Solkattu.Solkattu (Sollu(..))

import Global


note :: Sollu -> Realize.SNote Sollu
note :: Sollu -> SNote Sollu
note Sollu
NoSollu = forall stroke. SNote stroke
Realize.rest
note Sollu
sollu = forall g a. a -> Note g a
S.Note (forall stroke. Stroke stroke -> Note stroke
Realize.Note (forall stroke. stroke -> Stroke stroke
Realize.stroke Sollu
sollu))

defaultPatterns :: Realize.PatternMap Sollu
defaultPatterns :: PatternMap Sollu
defaultPatterns = forall a. Stack => Either Error a -> a
Solkattu.check forall a b. (a -> b) -> a -> b
$ [(Matra, [Sollu])] -> Either Error (PatternMap Sollu)
patterns
    [ (Matra
5, [Sollu
Ta, Sollu
Din, Sollu
Gin, Sollu
Na, Sollu
Thom])
    , (Matra
6, [Sollu
Ta, Sollu
Din, Sollu
__, Sollu
Gin, Sollu
Na, Sollu
Thom])
    , (Matra
7, [Sollu
Ta, Sollu
__, Sollu
Din, Sollu
__, Sollu
Gin, Sollu
Na, Sollu
Thom])
    , (Matra
8, [Sollu
Ta, Sollu
Din, Sollu
__, Sollu
Gin, Sollu
__, Sollu
Na, Sollu
__, Sollu
Thom])
    , (Matra
9, [Sollu
Ta, Sollu
__, Sollu
Din, Sollu
__, Sollu
Gin, Sollu
__, Sollu
Na, Sollu
__, Sollu
Thom])
    ]

alternatePatterns :: Realize.PatternMap Sollu
alternatePatterns :: PatternMap Sollu
alternatePatterns = forall a. Stack => Either Error a -> a
Solkattu.check forall a b. (a -> b) -> a -> b
$ [(Matra, [Sollu])] -> Either Error (PatternMap Sollu)
patterns
    [ (Matra
5, [Sollu
Ta, Sollu
Di, Sollu
Ki, Sollu
Tha, Sollu
Thom])
    , (Matra
6, [Sollu
Ta, Sollu
Di, Sollu
__, Sollu
Ki, Sollu
Tha, Sollu
Thom])
    , (Matra
7, [Sollu
Ta, Sollu
__, Sollu
Di, Sollu
__, Sollu
Ki, Sollu
Tha, Sollu
Thom])
    , (Matra
8, [Sollu
Ta, Sollu
Di, Sollu
__, Sollu
Ki, Sollu
__, Sollu
Tha, Sollu
__, Sollu
Thom])
    , (Matra
9, [Sollu
Ta, Sollu
__, Sollu
Di, Sollu
__, Sollu
Ki, Sollu
__, Sollu
Tha, Sollu
__, Sollu
Thom])
    ]

__ :: Sollu
__ :: Sollu
__ = Sollu
NoSollu

patterns :: [(S.Matra, [Sollu])] -> Either Text (Realize.PatternMap Sollu)
patterns :: [(Matra, [Sollu])] -> Either Error (PatternMap Sollu)
patterns = forall stroke.
[(Pattern, Sequence () (Note stroke))]
-> Either Error (PatternMap stroke)
Realize.patternMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (forall g a. [Note g a] -> Sequence g a
S.fromList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map Sollu -> SNote Sollu
note))
    forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first Matra -> Pattern
Solkattu.pattern)

instance Expr.ToExpr Sollu where
    to_expr :: Sollu -> Expr MiniVal
to_expr = forall val. Symbol -> Expr val
Expr.generator0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. Error -> Symbol
Expr.Symbol forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Pretty a => a -> Error
pretty
instance Expr.ToExpr (Realize.Stroke Sollu) where
    to_expr :: Stroke Sollu -> Expr MiniVal
to_expr = forall a. ToExpr a => Stroke a -> Expr MiniVal
Realize.toExpr