-- 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 = SNote Sollu
forall stroke. SNote stroke
Realize.rest
note Sollu
sollu = Note Sollu -> SNote Sollu
forall g a. a -> Note g a
S.Note (Stroke Sollu -> Note Sollu
forall stroke. Stroke stroke -> Note stroke
Realize.Note (Sollu -> Stroke Sollu
forall stroke. stroke -> Stroke stroke
Realize.stroke Sollu
sollu))

defaultPatterns :: Realize.PatternMap Sollu
defaultPatterns :: PatternMap Sollu
defaultPatterns = Either Error (PatternMap Sollu) -> PatternMap Sollu
forall a. Stack => Either Error a -> a
Solkattu.check (Either Error (PatternMap Sollu) -> PatternMap Sollu)
-> Either Error (PatternMap Sollu) -> PatternMap Sollu
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 = Either Error (PatternMap Sollu) -> PatternMap Sollu
forall a. Stack => Either Error a -> a
Solkattu.check (Either Error (PatternMap Sollu) -> PatternMap Sollu)
-> Either Error (PatternMap Sollu) -> PatternMap Sollu
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 = [(Pattern, Sequence () (Note Sollu))]
-> Either Error (PatternMap Sollu)
forall stroke.
[(Pattern, Sequence () (Note stroke))]
-> Either Error (PatternMap stroke)
Realize.patternMap ([(Pattern, Sequence () (Note Sollu))]
 -> Either Error (PatternMap Sollu))
-> ([(Matra, [Sollu])] -> [(Pattern, Sequence () (Note Sollu))])
-> [(Matra, [Sollu])]
-> Either Error (PatternMap Sollu)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Pattern, [Sollu]) -> (Pattern, Sequence () (Note Sollu)))
-> [(Pattern, [Sollu])] -> [(Pattern, Sequence () (Note Sollu))]
forall a b. (a -> b) -> [a] -> [b]
map (([Sollu] -> Sequence () (Note Sollu))
-> (Pattern, [Sollu]) -> (Pattern, Sequence () (Note Sollu))
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second ([SNote Sollu] -> Sequence () (Note Sollu)
forall g a. [Note g a] -> Sequence g a
S.fromList ([SNote Sollu] -> Sequence () (Note Sollu))
-> ([Sollu] -> [SNote Sollu])
-> [Sollu]
-> Sequence () (Note Sollu)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Sollu -> SNote Sollu) -> [Sollu] -> [SNote Sollu]
forall a b. (a -> b) -> [a] -> [b]
map Sollu -> SNote Sollu
note))
    ([(Pattern, [Sollu])] -> [(Pattern, Sequence () (Note Sollu))])
-> ([(Matra, [Sollu])] -> [(Pattern, [Sollu])])
-> [(Matra, [Sollu])]
-> [(Pattern, Sequence () (Note Sollu))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Matra, [Sollu]) -> (Pattern, [Sollu]))
-> [(Matra, [Sollu])] -> [(Pattern, [Sollu])]
forall a b. (a -> b) -> [a] -> [b]
map ((Matra -> Pattern) -> (Matra, [Sollu]) -> (Pattern, [Sollu])
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 = Symbol -> Expr MiniVal
forall val. Symbol -> Expr val
Expr.generator0 (Symbol -> Expr MiniVal)
-> (Sollu -> Symbol) -> Sollu -> Expr MiniVal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Error -> Symbol
Expr.Symbol (Error -> Symbol) -> (Sollu -> Error) -> Sollu -> Symbol
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sollu -> Error
forall a. Pretty a => a -> Error
pretty
instance Expr.ToExpr (Realize.Stroke Sollu) where
    to_expr :: Stroke Sollu -> Expr MiniVal
to_expr = Stroke Sollu -> Expr MiniVal
forall a. ToExpr a => Stroke a -> Expr MiniVal
Realize.toExpr