-- Copyright 2020 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

module Synth.Sampler.Patch.CengCeng (patches) where
import qualified Data.Set as Set

import qualified Util.Lists as Lists
import qualified Cmd.Instrument.CUtil as CUtil
import qualified Cmd.Instrument.ImInst as ImInst
import qualified Derive.Attrs as Attrs
import qualified Derive.Call.Module as Module
import qualified Derive.Call.Post as Post
import qualified Derive.Derive as Derive
import qualified Derive.Score as Score
import qualified Derive.Sig as Sig

import qualified Synth.Sampler.Patch as Patch
import qualified Synth.Sampler.Patch.Lib.Code as Code
import qualified Synth.Sampler.Patch.Lib.Drum as Drum
import           Synth.Sampler.Patch.Lib.Drum (Call(..))
import qualified Synth.Sampler.Patch.Lib.Util as Util
import qualified Synth.Shared.Signal as Signal

import           Global


patches :: [Patch.Patch]
patches :: [Patch]
patches = Patch
rincik forall a. a -> [a] -> [a]
: [Patch]
kopyaks

-- * cengceng rincik

rincik :: Patch.Patch
rincik :: Patch
rincik = Code -> Patch -> Patch
Patch.addCode Code
code forall a b. (a -> b) -> a -> b
$
    forall art.
Ord art =>
FilePath
-> PatchName
-> StrokeMap art
-> ConvertMap art
-> (Maybe art -> CallConfig)
-> Patch
Drum.patch FilePath
dir PatchName
"cengceng-rincik" StrokeMap Rincik
rincikStrokeMap ConvertMap Rincik
rincikConvertMap
        (forall a b. a -> b -> a
const CallConfig
rincikCallConfig)
    where
    code :: Code
code = [(Symbol, Transformer Note)] -> Code
ImInst.note_transformers [(Symbol
"infer-hands", Transformer Note
c_inferHands)]
    dir :: FilePath
dir = FilePath
"cengceng/rincik"

rincikCallConfig :: CUtil.CallConfig
rincikCallConfig :: CallConfig
rincikCallConfig = CallConfig
CUtil.call_config
    { _tuning_control :: Maybe Control
CUtil._tuning_control = forall a. a -> Maybe a
Just Control
"cengceng-rincik-tune"
    , _transform :: NoteDeriver -> NoteDeriver
CUtil._transform = forall a. Deriver a -> Deriver a
Code.withVariation
    }

data Dynamic3 = P | M | F
    deriving (Dynamic3 -> Dynamic3 -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Dynamic3 -> Dynamic3 -> Bool
$c/= :: Dynamic3 -> Dynamic3 -> Bool
== :: Dynamic3 -> Dynamic3 -> Bool
$c== :: Dynamic3 -> Dynamic3 -> Bool
Eq, Eq Dynamic3
Dynamic3 -> Dynamic3 -> Bool
Dynamic3 -> Dynamic3 -> Ordering
Dynamic3 -> Dynamic3 -> Dynamic3
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Dynamic3 -> Dynamic3 -> Dynamic3
$cmin :: Dynamic3 -> Dynamic3 -> Dynamic3
max :: Dynamic3 -> Dynamic3 -> Dynamic3
$cmax :: Dynamic3 -> Dynamic3 -> Dynamic3
>= :: Dynamic3 -> Dynamic3 -> Bool
$c>= :: Dynamic3 -> Dynamic3 -> Bool
> :: Dynamic3 -> Dynamic3 -> Bool
$c> :: Dynamic3 -> Dynamic3 -> Bool
<= :: Dynamic3 -> Dynamic3 -> Bool
$c<= :: Dynamic3 -> Dynamic3 -> Bool
< :: Dynamic3 -> Dynamic3 -> Bool
$c< :: Dynamic3 -> Dynamic3 -> Bool
compare :: Dynamic3 -> Dynamic3 -> Ordering
$ccompare :: Dynamic3 -> Dynamic3 -> Ordering
Ord, Int -> Dynamic3 -> ShowS
[Dynamic3] -> ShowS
Dynamic3 -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Dynamic3] -> ShowS
$cshowList :: [Dynamic3] -> ShowS
show :: Dynamic3 -> FilePath
$cshow :: Dynamic3 -> FilePath
showsPrec :: Int -> Dynamic3 -> ShowS
$cshowsPrec :: Int -> Dynamic3 -> ShowS
Show, ReadPrec [Dynamic3]
ReadPrec Dynamic3
Int -> ReadS Dynamic3
ReadS [Dynamic3]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Dynamic3]
$creadListPrec :: ReadPrec [Dynamic3]
readPrec :: ReadPrec Dynamic3
$creadPrec :: ReadPrec Dynamic3
readList :: ReadS [Dynamic3]
$creadList :: ReadS [Dynamic3]
readsPrec :: Int -> ReadS Dynamic3
$creadsPrec :: Int -> ReadS Dynamic3
Read, Dynamic3
forall a. a -> a -> Bounded a
maxBound :: Dynamic3
$cmaxBound :: Dynamic3
minBound :: Dynamic3
$cminBound :: Dynamic3
Bounded, Int -> Dynamic3
Dynamic3 -> Int
Dynamic3 -> [Dynamic3]
Dynamic3 -> Dynamic3
Dynamic3 -> Dynamic3 -> [Dynamic3]
Dynamic3 -> Dynamic3 -> Dynamic3 -> [Dynamic3]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Dynamic3 -> Dynamic3 -> Dynamic3 -> [Dynamic3]
$cenumFromThenTo :: Dynamic3 -> Dynamic3 -> Dynamic3 -> [Dynamic3]
enumFromTo :: Dynamic3 -> Dynamic3 -> [Dynamic3]
$cenumFromTo :: Dynamic3 -> Dynamic3 -> [Dynamic3]
enumFromThen :: Dynamic3 -> Dynamic3 -> [Dynamic3]
$cenumFromThen :: Dynamic3 -> Dynamic3 -> [Dynamic3]
enumFrom :: Dynamic3 -> [Dynamic3]
$cenumFrom :: Dynamic3 -> [Dynamic3]
fromEnum :: Dynamic3 -> Int
$cfromEnum :: Dynamic3 -> Int
toEnum :: Int -> Dynamic3
$ctoEnum :: Int -> Dynamic3
pred :: Dynamic3 -> Dynamic3
$cpred :: Dynamic3 -> Dynamic3
succ :: Dynamic3 -> Dynamic3
$csucc :: Dynamic3 -> Dynamic3
Enum)

data Rincik = ROpen Hand | RClosed Hand | RMute Hand
    | ROpenBoth | RClosedBoth
    | RKopyakOpen | RKopyakClosed
    deriving (Rincik -> Rincik -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Rincik -> Rincik -> Bool
$c/= :: Rincik -> Rincik -> Bool
== :: Rincik -> Rincik -> Bool
$c== :: Rincik -> Rincik -> Bool
Eq, Eq Rincik
Rincik -> Rincik -> Bool
Rincik -> Rincik -> Ordering
Rincik -> Rincik -> Rincik
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Rincik -> Rincik -> Rincik
$cmin :: Rincik -> Rincik -> Rincik
max :: Rincik -> Rincik -> Rincik
$cmax :: Rincik -> Rincik -> Rincik
>= :: Rincik -> Rincik -> Bool
$c>= :: Rincik -> Rincik -> Bool
> :: Rincik -> Rincik -> Bool
$c> :: Rincik -> Rincik -> Bool
<= :: Rincik -> Rincik -> Bool
$c<= :: Rincik -> Rincik -> Bool
< :: Rincik -> Rincik -> Bool
$c< :: Rincik -> Rincik -> Bool
compare :: Rincik -> Rincik -> Ordering
$ccompare :: Rincik -> Rincik -> Ordering
Ord, Int -> Rincik -> ShowS
[Rincik] -> ShowS
Rincik -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Rincik] -> ShowS
$cshowList :: [Rincik] -> ShowS
show :: Rincik -> FilePath
$cshow :: Rincik -> FilePath
showsPrec :: Int -> Rincik -> ShowS
$cshowsPrec :: Int -> Rincik -> ShowS
Show)

data Hand = HLeft | HRight
    deriving (Hand -> Hand -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Hand -> Hand -> Bool
$c/= :: Hand -> Hand -> Bool
== :: Hand -> Hand -> Bool
$c== :: Hand -> Hand -> Bool
Eq, Eq Hand
Hand -> Hand -> Bool
Hand -> Hand -> Ordering
Hand -> Hand -> Hand
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Hand -> Hand -> Hand
$cmin :: Hand -> Hand -> Hand
max :: Hand -> Hand -> Hand
$cmax :: Hand -> Hand -> Hand
>= :: Hand -> Hand -> Bool
$c>= :: Hand -> Hand -> Bool
> :: Hand -> Hand -> Bool
$c> :: Hand -> Hand -> Bool
<= :: Hand -> Hand -> Bool
$c<= :: Hand -> Hand -> Bool
< :: Hand -> Hand -> Bool
$c< :: Hand -> Hand -> Bool
compare :: Hand -> Hand -> Ordering
$ccompare :: Hand -> Hand -> Ordering
Ord, Int -> Hand -> ShowS
[Hand] -> ShowS
Hand -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Hand] -> ShowS
$cshowList :: [Hand] -> ShowS
show :: Hand -> FilePath
$cshow :: Hand -> FilePath
showsPrec :: Int -> Hand -> ShowS
$cshowsPrec :: Int -> Hand -> ShowS
Show)

rincikAll :: [Rincik]
rincikAll :: [Rincik]
rincikAll =
    [ Rincik
ROpenBoth, Rincik
RClosedBoth
    , Rincik
RKopyakOpen, Rincik
RKopyakClosed
    ] forall a. [a] -> [a] -> [a]
++ [Hand -> Rincik
r Hand
h | Hand -> Rincik
r <- [Hand -> Rincik
ROpen, Hand -> Rincik
RClosed, Hand -> Rincik
RMute], Hand
h <- [Hand
HLeft, Hand
HRight]]

rincikStrokeMap :: Drum.StrokeMap Rincik
rincikStrokeMap :: StrokeMap Rincik
rincikStrokeMap = forall art. Y -> StrokeMap art -> StrokeMap art
Drum.replaceSoft Y
0.75 forall a b. (a -> b) -> a -> b
$ forall art.
Ord art =>
Stops -> [(Char, Symbol, Call art)] -> StrokeMap art
Drum.strokeMapTable Stops
stops forall a b. (a -> b) -> a -> b
$
    [ (Char
'1', Symbol
"ko", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.open forall a. Semigroup a => a -> a -> a
<> Attributes
kopyak forall a. Semigroup a => a -> a -> a
<> Attributes
soft) Rincik
RKopyakOpen PatchName
opened)
    , (Char
'q', Symbol
"kO", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.open forall a. Semigroup a => a -> a -> a
<> Attributes
kopyak)         Rincik
RKopyakOpen PatchName
opened)
    , (Char
'2', Symbol
"kx", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
kopyak forall a. Semigroup a => a -> a -> a
<> Attributes
soft) Rincik
RKopyakClosed PatchName
closed)
    , (Char
'w', Symbol
"kX", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
kopyak)       Rincik
RKopyakClosed PatchName
closed)
    , (Char
'f', Symbol
"oo", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.open forall a. Semigroup a => a -> a -> a
<> Attributes
both forall a. Semigroup a => a -> a -> a
<> Attributes
soft)   Rincik
ROpenBoth PatchName
opened)
    , (Char
'v', Symbol
"OO", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.open forall a. Semigroup a => a -> a -> a
<> Attributes
both)           Rincik
ROpenBoth PatchName
opened)
    , (Char
'b', Symbol
"--", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
both forall a. Semigroup a => a -> a -> a
<> Attributes
soft) Rincik
RClosedBoth PatchName
closed)
    , (Char
'b', Symbol
"++", forall art. Attributes -> art -> PatchName -> Call art
Stroke (Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
both)         Rincik
RClosedBoth PatchName
closed)
    , (Char
'a', Symbol
"o", forall art. Attributes -> Call art
Attr forall a b. (a -> b) -> a -> b
$ Attributes
Attrs.open forall a. Semigroup a => a -> a -> a
<> Attributes
soft)
    , (Char
'z', Symbol
"O", forall art. Attributes -> Call art
Attr forall a b. (a -> b) -> a -> b
$ Attributes
Attrs.open)
    , (Char
's', Symbol
"-", forall art. Attributes -> Call art
Attr forall a b. (a -> b) -> a -> b
$ Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
soft)
    , (Char
'x', Symbol
"+", forall art. Attributes -> Call art
Attr forall a b. (a -> b) -> a -> b
$ Attributes
Attrs.closed)
    , (Char
'd', Symbol
"X", forall art. Attributes -> Call art
Attr forall a b. (a -> b) -> a -> b
$ Attributes
Attrs.mute forall a. Semigroup a => a -> a -> a
<> Attributes
soft)
    , (Char
'c', Symbol
"X", forall art. Attributes -> Call art
Attr forall a b. (a -> b) -> a -> b
$ Attributes
Attrs.mute)
    ] forall a. [a] -> [a] -> [a]
++
    -- Create articulation associations for per-hand strokes, though there is
    -- no call that directly emits them.  Instead, the Attr calls above emit
    -- without the hand, and use infer-hands to infer it.
    [ (Char
' ', Symbol
"", forall art. Attributes -> art -> PatchName -> Call art
Stroke Attributes
attr Rincik
art PatchName
group)
    | (Attributes
attr, Hand -> Rincik
stroke, PatchName
group) <-
        [ (Attributes
Attrs.open, Hand -> Rincik
ROpen, PatchName
opened)
        , (Attributes
Attrs.closed, Hand -> Rincik
RClosed, PatchName
closed)
        , (Attributes
Attrs.mute, Hand -> Rincik
RMute, PatchName
muted)
        ]
    , (Attributes
attr, Rincik
art, PatchName
group) <-
      [ (Attributes
attr, Hand -> Rincik
stroke Hand
HLeft, PatchName
group)
      , (Attributes
attr forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.left, Hand -> Rincik
stroke Hand
HLeft, PatchName
group)
      , (Attributes
attr forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.right, Hand -> Rincik
stroke Hand
HRight, PatchName
group)
      ]
    ]
    where
    kopyak :: Attributes
kopyak = PatchName -> Attributes
Attrs.attr PatchName
"kopyak"
    both :: Attributes
both = PatchName -> Attributes
Attrs.attr PatchName
"both"
    stops :: Stops
stops = [(PatchName
closed, [PatchName
opened]), (PatchName
muted, [PatchName
opened, PatchName
closed])]
    opened :: PatchName
opened = PatchName
"opened"
    closed :: PatchName
closed = PatchName
"closed"
    muted :: PatchName
muted = PatchName
"muted"
    soft :: Attributes
soft = Attributes
Attrs.soft

c_inferHands :: Derive.Transformer Derive.Note
c_inferHands :: Transformer Note
c_inferHands = forall d.
Module
-> CallName
-> Tags
-> Doc
-> WithArgDoc (TransformerF d)
-> Transformer d
Derive.transformer Module
Module.instrument CallName
"infer-hands" forall a. Monoid a => a
mempty
    Doc
"Infer alternating +right and +left for notes without it.  Only applies\
    \ to +open, +closed, +mute."
    forall a b. (a -> b) -> a -> b
$ forall y d.
Taggable y =>
Transformer y d -> WithArgDoc (Transformer y d)
Sig.call0t forall a b. (a -> b) -> a -> b
$ \PassedArgs Note
_ NoteDeriver
deriver -> forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall state a b.
(state -> a -> (state, b))
-> state -> Stream a -> (state, Stream b)
Post.emap1 Hand -> Note -> (Hand, Note)
assign Hand
HRight forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NoteDeriver
deriver
    where
    assign :: Hand -> Note -> (Hand, Note)
assign Hand
hand Note
event
        | Attributes -> Bool
has Attributes
Attrs.left = (Hand
HRight, Note
event)
        | Attributes -> Bool
has Attributes
Attrs.right = (Hand
HLeft, Note
event)
        | forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Attributes -> Bool
has [Attributes
Attrs.open, Attributes
Attrs.closed, Attributes
Attrs.mute] =
            (Hand -> Hand
other Hand
hand, Attributes -> Note -> Note
Score.add_attributes (Hand -> Attributes
handAttr Hand
hand) Note
event)
        | Bool
otherwise = (Hand
hand, Note
event)
        where
        has :: Attributes -> Bool
has Attributes
a = Attributes -> Note -> Bool
Score.has_attribute Attributes
a Note
event
    other :: Hand -> Hand
other Hand
HRight = Hand
HLeft
    other Hand
HLeft = Hand
HRight
    handAttr :: Hand -> Attributes
handAttr Hand
HRight = Attributes
Attrs.right
    handAttr Hand
HLeft = Attributes
Attrs.left

rincikConvertMap :: Drum.ConvertMap Rincik
rincikConvertMap :: ConvertMap Rincik
rincikConvertMap = Drum.ConvertMap
    { _dynRange :: (Y, Y)
_dynRange = (Y
0.5, Y
1)
    , _naturalNn :: Maybe (Rincik -> NoteNumber)
_naturalNn = forall a. Maybe a
Nothing
    , _muteTime :: Maybe RealTime
_muteTime = forall a. a -> Maybe a
Just RealTime
0.05
    , _getFilename :: Rincik -> Y -> Y -> (FilePath, Maybe (Y, Y))
_getFilename = Rincik -> Y -> Y -> (FilePath, Maybe (Y, Y))
rincikGetFilename
    , _allFilenames :: Set FilePath
_allFilenames = Set FilePath
rincikAllFilenames
    }

rincikAllFilenames :: Set FilePath
rincikAllFilenames :: Set FilePath
rincikAllFilenames = forall (t :: * -> *) a.
(HasCallStack, Foldable t) =>
Int -> t a -> t a
Util.assertLength Int
186 forall a b. (a -> b) -> a -> b
$ forall a. Ord a => [a] -> Set a
Set.fromList
    [ forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ Rincik -> Y -> Y -> (FilePath, Maybe (Y, Y))
rincikGetFilename Rincik
art Y
dyn Y
var
    | Rincik
art <- [Rincik]
rincikAll
    , Y
dyn <- [Y
0, Y
0.35, Y
0.7, Y
1]
    , Y
var <- forall a. (Num a, Ord a) => a -> a -> a -> [a]
Lists.range Y
0 Y
1 (Y
1forall a. Fractional a => a -> a -> a
/Y
8)
    ]

-- | $attr-{p,m,f}-v{1..n}.flac
rincikGetFilename :: Rincik -> Signal.Y -> Signal.Y
    -> (FilePath, Maybe (Signal.Y, Signal.Y))
rincikGetFilename :: Rincik -> Y -> Y -> (FilePath, Maybe (Y, Y))
rincikGetFilename Rincik
art Y
dyn Y
var = (FilePath
fname, forall a. a -> Maybe a
Just (Y, Y)
dynRange)
    where
    dynRange :: (Y, Y)
dynRange =
        ( if Dynamic3
dynSym forall a. Eq a => a -> a -> Bool
== forall a. Bounded a => a
minBound then Y
0 else Dynamic3 -> Y
dynamicThreshold (forall a. Enum a => a -> a
pred Dynamic3
dynSym)
        , Dynamic3 -> Y
dynamicThreshold Dynamic3
dynSym
        )
    (Dynamic3
dynSym, Y
_) = forall dyn. (Bounded dyn, Enum dyn) => (dyn -> Y) -> Y -> (dyn, Y)
Util.findDynamic Dynamic3 -> Y
dynamicThreshold Y
dyn
    fname :: FilePath
fname = forall a. Monoid a => a -> [a] -> a
Lists.join FilePath
"-"
        [ Rincik -> FilePath
showArt Rincik
art
        , forall a. Show a => a -> FilePath
Util.showLower Dynamic3
dynSym
        , Char
'v' forall a. a -> [a] -> [a]
: forall a. Show a => a -> FilePath
show (forall a. [a] -> Y -> a
Util.pickVariation [Integer
1 .. Integer
variations] Y
var)
        ] forall a. Semigroup a => a -> a -> a
<> FilePath
".flac"
    showArt :: Rincik -> FilePath
showArt = \case
        ROpen Hand
h -> FilePath
"open+" forall a. Semigroup a => a -> a -> a
<> Hand -> FilePath
showHand Hand
h
        RClosed Hand
h -> FilePath
"closed+" forall a. Semigroup a => a -> a -> a
<> Hand -> FilePath
showHand Hand
h
        RMute Hand
h -> FilePath
"mute+" forall a. Semigroup a => a -> a -> a
<> Hand -> FilePath
showHand Hand
h
        Rincik
ROpenBoth -> FilePath
"open+both"
        Rincik
RClosedBoth -> FilePath
"closed+both"
        Rincik
RKopyakOpen -> FilePath
"kopyak+open"
        Rincik
RKopyakClosed -> FilePath
"kopyak+closed"
    variations :: Integer
variations = case Rincik
art of
        ROpen Hand
h -> case Dynamic3
dynSym of
            Dynamic3
P -> forall {p}. Hand -> p -> p -> p
hand Hand
h Integer
3 Integer
4
            Dynamic3
M -> Integer
5
            Dynamic3
F -> forall {p}. Hand -> p -> p -> p
hand Hand
h Integer
4 Integer
3
        RClosed Hand
_ -> forall {a}. (a, a, a) -> a
d (Integer
14, Integer
8, Integer
8) forall a. Integral a => a -> a -> a
`div` Integer
2
        RMute Hand
_ -> Integer
16 forall a. Integral a => a -> a -> a
`div` Integer
2
        Rincik
ROpenBoth -> Integer
6
        Rincik
RClosedBoth -> Integer
6
        Rincik
RKopyakOpen -> Integer
8
        Rincik
RKopyakClosed -> Integer
8
    hand :: Hand -> p -> p -> p
hand Hand
HLeft p
a p
_ = p
a
    hand Hand
HRight p
_ p
a = p
a
    d :: (a, a, a) -> a
d (a
p, a
m, a
f) = case Dynamic3
dynSym of
        Dynamic3
P -> a
p
        Dynamic3
M -> a
m
        Dynamic3
F -> a
f
    showHand :: Hand -> FilePath
showHand = \case
        Hand
HLeft -> FilePath
"left"
        Hand
HRight -> FilePath
"right"
    dynamicThreshold :: Dynamic3 -> Y
dynamicThreshold = \case
        Dynamic3
P -> Y
0.35
        Dynamic3
M -> Y
0.7
        Dynamic3
F -> Y
1


-- * cengceng kopyak

kopyaks :: [Patch.Patch]
kopyaks :: [Patch]
kopyaks = forall a b. (a -> b) -> [a] -> [b]
map Inst -> Patch
make [Inst
K1, Inst
K2, Inst
K3]
    where
    make :: Inst -> Patch
make Inst
inst = forall art.
Ord art =>
FilePath
-> PatchName
-> StrokeMap art
-> ConvertMap art
-> (Maybe art -> CallConfig)
-> Patch
Drum.patch
        (Inst -> FilePath
kopyakDir Inst
inst) (PatchName
"cengceng-kopyak" forall a. Semigroup a => a -> a -> a
<> FilePath -> PatchName
txt (Inst -> FilePath
kopyakNum Inst
inst))
        StrokeMap Kopyak
kopyakStrokeMap (Inst -> ConvertMap Kopyak
kopyakConvertMap Inst
inst) (forall a b. a -> b -> a
const CallConfig
config)
    config :: CallConfig
config = CallConfig
CUtil.call_config
        { _tuning_control :: Maybe Control
CUtil._tuning_control = forall a. a -> Maybe a
Just Control
"cengceng-kopyak-tune" }

data Inst = K1 | K2 | K3 deriving (Int -> Inst -> ShowS
[Inst] -> ShowS
Inst -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Inst] -> ShowS
$cshowList :: [Inst] -> ShowS
show :: Inst -> FilePath
$cshow :: Inst -> FilePath
showsPrec :: Int -> Inst -> ShowS
$cshowsPrec :: Int -> Inst -> ShowS
Show)

kopyakDir :: Inst -> FilePath
kopyakDir :: Inst -> FilePath
kopyakDir Inst
inst = FilePath
"cengceng/kopyak/" forall a. Semigroup a => a -> a -> a
<> Inst -> FilePath
kopyakNum Inst
inst

kopyakNum :: Inst -> String
kopyakNum :: Inst -> FilePath
kopyakNum = forall a. Int -> [a] -> [a]
drop Int
1 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> FilePath
show

data Kopyak = Open | Closed | Rim
    deriving (Kopyak -> Kopyak -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Kopyak -> Kopyak -> Bool
$c/= :: Kopyak -> Kopyak -> Bool
== :: Kopyak -> Kopyak -> Bool
$c== :: Kopyak -> Kopyak -> Bool
Eq, Eq Kopyak
Kopyak -> Kopyak -> Bool
Kopyak -> Kopyak -> Ordering
Kopyak -> Kopyak -> Kopyak
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Kopyak -> Kopyak -> Kopyak
$cmin :: Kopyak -> Kopyak -> Kopyak
max :: Kopyak -> Kopyak -> Kopyak
$cmax :: Kopyak -> Kopyak -> Kopyak
>= :: Kopyak -> Kopyak -> Bool
$c>= :: Kopyak -> Kopyak -> Bool
> :: Kopyak -> Kopyak -> Bool
$c> :: Kopyak -> Kopyak -> Bool
<= :: Kopyak -> Kopyak -> Bool
$c<= :: Kopyak -> Kopyak -> Bool
< :: Kopyak -> Kopyak -> Bool
$c< :: Kopyak -> Kopyak -> Bool
compare :: Kopyak -> Kopyak -> Ordering
$ccompare :: Kopyak -> Kopyak -> Ordering
Ord, Int -> Kopyak -> ShowS
[Kopyak] -> ShowS
Kopyak -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Kopyak] -> ShowS
$cshowList :: [Kopyak] -> ShowS
show :: Kopyak -> FilePath
$cshow :: Kopyak -> FilePath
showsPrec :: Int -> Kopyak -> ShowS
$cshowsPrec :: Int -> Kopyak -> ShowS
Show, Kopyak
forall a. a -> a -> Bounded a
maxBound :: Kopyak
$cmaxBound :: Kopyak
minBound :: Kopyak
$cminBound :: Kopyak
Bounded, Int -> Kopyak
Kopyak -> Int
Kopyak -> [Kopyak]
Kopyak -> Kopyak
Kopyak -> Kopyak -> [Kopyak]
Kopyak -> Kopyak -> Kopyak -> [Kopyak]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: Kopyak -> Kopyak -> Kopyak -> [Kopyak]
$cenumFromThenTo :: Kopyak -> Kopyak -> Kopyak -> [Kopyak]
enumFromTo :: Kopyak -> Kopyak -> [Kopyak]
$cenumFromTo :: Kopyak -> Kopyak -> [Kopyak]
enumFromThen :: Kopyak -> Kopyak -> [Kopyak]
$cenumFromThen :: Kopyak -> Kopyak -> [Kopyak]
enumFrom :: Kopyak -> [Kopyak]
$cenumFrom :: Kopyak -> [Kopyak]
fromEnum :: Kopyak -> Int
$cfromEnum :: Kopyak -> Int
toEnum :: Int -> Kopyak
$ctoEnum :: Int -> Kopyak
pred :: Kopyak -> Kopyak
$cpred :: Kopyak -> Kopyak
succ :: Kopyak -> Kopyak
$csucc :: Kopyak -> Kopyak
Enum)

kopyakStrokeMap :: Drum.StrokeMap Kopyak
kopyakStrokeMap :: StrokeMap Kopyak
kopyakStrokeMap = forall art. Y -> StrokeMap art -> StrokeMap art
Drum.replaceSoft Y
0.75 forall a b. (a -> b) -> a -> b
$ forall art.
Ord art =>
Stops
-> [(Char, Symbol, Attributes, art, PatchName)] -> StrokeMap art
Drum.strokeMapSimple Stops
stops
    [ (Char
'a', Symbol
"o", Attributes
Attrs.open forall a. Semigroup a => a -> a -> a
<> Attributes
soft,    Kopyak
Open, PatchName
open)
    , (Char
'z', Symbol
"O", Attributes
Attrs.open,            Kopyak
Open, PatchName
open)
    , (Char
's', Symbol
"x", Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
soft,  Kopyak
Closed, PatchName
closed)
    , (Char
'x', Symbol
"X", Attributes
Attrs.closed,          Kopyak
Closed, PatchName
closed)
    , (Char
'd', Symbol
"t", Attributes
Attrs.rim forall a. Semigroup a => a -> a -> a
<> Attributes
soft,     Kopyak
Rim, PatchName
open)
    , (Char
'c', Symbol
"T", Attributes
Attrs.rim,             Kopyak
Rim, PatchName
open)
    ]
    where
    stops :: Stops
stops = [(PatchName
closed, [PatchName
open])]
    soft :: Attributes
soft = Attributes
Attrs.soft
    open :: PatchName
open = PatchName
"open"
    closed :: PatchName
closed = PatchName
"closed"

kopyakConvertMap :: Inst -> Drum.ConvertMap Kopyak
kopyakConvertMap :: Inst -> ConvertMap Kopyak
kopyakConvertMap Inst
inst = Drum.ConvertMap
    { _dynRange :: (Y, Y)
_dynRange = (Y
0.5, Y
1)
    , _naturalNn :: Maybe (Kopyak -> NoteNumber)
_naturalNn = forall a. Maybe a
Nothing
    , _muteTime :: Maybe RealTime
_muteTime = forall a. a -> Maybe a
Just RealTime
0.05
    , _getFilename :: Kopyak -> Y -> Y -> (FilePath, Maybe (Y, Y))
_getFilename = Inst -> Kopyak -> Y -> Y -> (FilePath, Maybe (Y, Y))
kopyakGetFilename Inst
inst
    , _allFilenames :: Set FilePath
_allFilenames = Inst -> Set FilePath
kopyakAllFilenames Inst
inst
    }

kopyakAllFilenames :: Inst -> Set FilePath
kopyakAllFilenames :: Inst -> Set FilePath
kopyakAllFilenames Inst
inst = forall (t :: * -> *) a.
(HasCallStack, Foldable t) =>
Int -> t a -> t a
Util.assertLength Int
len forall a b. (a -> b) -> a -> b
$ forall a. Ord a => [a] -> Set a
Set.fromList
    [ forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ Inst -> Kopyak -> Y -> Y -> (FilePath, Maybe (Y, Y))
kopyakGetFilename Inst
inst Kopyak
art Y
dyn Y
var
    | Kopyak
art <- forall a. (Enum a, Bounded a) => [a]
Util.enumAll
    , Y
dyn <- [Y
0, Y
0.25, Y
0.5, Y
0.75]
    , Y
var <- forall a. (Num a, Ord a) => a -> a -> a -> [a]
Lists.range Y
0 Y
1 (Y
1forall a. Fractional a => a -> a -> a
/Y
8)
    ]
    where
    len :: Int
len = case Inst
inst of
        Inst
K1 -> Int
83
        Inst
K2 -> Int
92
        Inst
K3 -> Int
92

-- | {open,closed}-{pp,mp,mf,ff}-v{1..n}.flac
kopyakGetFilename :: Inst -> Kopyak -> Signal.Y -> Signal.Y
    -> (FilePath, Maybe (Signal.Y, Signal.Y))
kopyakGetFilename :: Inst -> Kopyak -> Y -> Y -> (FilePath, Maybe (Y, Y))
kopyakGetFilename Inst
inst Kopyak
art Y
dyn Y
var = (FilePath
fname, forall a. a -> Maybe a
Just (Y, Y)
dynRange)
    where
    dynRange :: (Y, Y)
dynRange =
        ( if Dynamic
dynSym forall a. Eq a => a -> a -> Bool
== forall a. Bounded a => a
minBound then Y
0 else Dynamic -> Y
dynamicThreshold (forall a. Enum a => a -> a
pred Dynamic
dynSym)
        , Dynamic -> Y
dynamicThreshold Dynamic
dynSym
        )
    (Dynamic
dynSym, Y
_) = forall dyn. (Bounded dyn, Enum dyn) => (dyn -> Y) -> Y -> (dyn, Y)
Util.findDynamic Dynamic -> Y
dynamicThreshold Y
dyn
    fname :: FilePath
fname = forall a. Monoid a => a -> [a] -> a
Lists.join FilePath
"-"
        [ forall a. Show a => a -> FilePath
Util.showLower Kopyak
art
        , forall a. Show a => a -> FilePath
Util.showLower Dynamic
dynSym
        , Char
'v' forall a. a -> [a] -> [a]
: forall a. Show a => a -> FilePath
show (forall a. [a] -> Y -> a
Util.pickVariation [Integer
1 .. Integer
variations] Y
var)
        ] forall a. Semigroup a => a -> a -> a
<> FilePath
".flac"
    variations :: Integer
variations = case (Inst
inst, Kopyak
art) of
        (Inst
_, Kopyak
Closed) -> Integer
8
        (Inst
K1, Kopyak
Open) -> Integer
6
        (Inst
K1, Kopyak
Rim) -> forall {a}. (a, a, a, a) -> a
d (Integer
7, Integer
6, Integer
7, Integer
7)
        (Inst
K2, Kopyak
Open) -> forall {a}. (a, a, a, a) -> a
d (Integer
8, Integer
7, Integer
8, Integer
7)
        (Inst
K2, Kopyak
Rim) -> forall {a}. (a, a, a, a) -> a
d (Integer
8, Integer
8, Integer
6, Integer
8)
        (Inst
K3, Kopyak
Open) -> forall {a}. (a, a, a, a) -> a
d (Integer
8, Integer
7, Integer
8, Integer
8)
        (Inst
K3, Kopyak
Rim) -> forall {a}. (a, a, a, a) -> a
d (Integer
8, Integer
7, Integer
7, Integer
7)
    d :: (a, a, a, a) -> a
d (a
pp, a
mp, a
mf, a
ff) = case Dynamic
dynSym of
        Dynamic
Util.PP -> a
pp
        Dynamic
Util.MP -> a
mp
        Dynamic
Util.MF -> a
mf
        Dynamic
Util.FF -> a
ff
    dynamicThreshold :: Dynamic -> Y
dynamicThreshold = \case
        Dynamic
Util.PP -> Y
0.25
        Dynamic
Util.MP -> Y
0.5
        Dynamic
Util.MF -> Y
0.75
        Dynamic
Util.FF -> Y
1