-- 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.Kajar (patches) where
import qualified Cmd.Instrument.CUtil as CUtil
import qualified Derive.Attrs as Attrs
import qualified Derive.C.Bali.Gong as Gong
import qualified Derive.Call.Module as Module
import qualified Derive.Call.Sub as Sub
import qualified Derive.Derive as Derive
import qualified Derive.Eval as Eval
import qualified Derive.Instrument.DUtil as DUtil

import qualified Perform.RealTime as RealTime
import qualified Synth.Sampler.Patch as Patch
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 Ui.Meter.Meter as Meter

import           Global


patches :: [Patch.Patch]
patches :: [Patch]
patches = [forall art.
Ord art =>
FilePath
-> Text
-> StrokeMap art
-> ConvertMap art
-> (Maybe art -> CallConfig)
-> Patch
Drum.patch FilePath
dir Text
patchName StrokeMap Articulation
strokeMap ConvertMap Articulation
convertMap (forall a b. a -> b -> a
const CallConfig
config)]
    where
    config :: CallConfig
config = CallConfig
CUtil.call_config { _tuning_control :: Maybe Control
CUtil._tuning_control = forall a. a -> Maybe a
Just Control
"kajar-tune" }
    dir :: FilePath
dir = Text -> FilePath
untxt Text
patchName

patchName :: Text
patchName :: Text
patchName = Text
"kajar"

data Articulation =
    CenterClosed | CenterOpen | Damp | RimClosed | RimOpen | RimStaccato
    deriving (Articulation -> Articulation -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Articulation -> Articulation -> Bool
$c/= :: Articulation -> Articulation -> Bool
== :: Articulation -> Articulation -> Bool
$c== :: Articulation -> Articulation -> Bool
Eq, Eq Articulation
Articulation -> Articulation -> Bool
Articulation -> Articulation -> Ordering
Articulation -> Articulation -> Articulation
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 :: Articulation -> Articulation -> Articulation
$cmin :: Articulation -> Articulation -> Articulation
max :: Articulation -> Articulation -> Articulation
$cmax :: Articulation -> Articulation -> Articulation
>= :: Articulation -> Articulation -> Bool
$c>= :: Articulation -> Articulation -> Bool
> :: Articulation -> Articulation -> Bool
$c> :: Articulation -> Articulation -> Bool
<= :: Articulation -> Articulation -> Bool
$c<= :: Articulation -> Articulation -> Bool
< :: Articulation -> Articulation -> Bool
$c< :: Articulation -> Articulation -> Bool
compare :: Articulation -> Articulation -> Ordering
$ccompare :: Articulation -> Articulation -> Ordering
Ord, Int -> Articulation -> ShowS
[Articulation] -> ShowS
Articulation -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Articulation] -> ShowS
$cshowList :: [Articulation] -> ShowS
show :: Articulation -> FilePath
$cshow :: Articulation -> FilePath
showsPrec :: Int -> Articulation -> ShowS
$cshowsPrec :: Int -> Articulation -> ShowS
Show, Int -> Articulation
Articulation -> Int
Articulation -> [Articulation]
Articulation -> Articulation
Articulation -> Articulation -> [Articulation]
Articulation -> Articulation -> Articulation -> [Articulation]
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 :: Articulation -> Articulation -> Articulation -> [Articulation]
$cenumFromThenTo :: Articulation -> Articulation -> Articulation -> [Articulation]
enumFromTo :: Articulation -> Articulation -> [Articulation]
$cenumFromTo :: Articulation -> Articulation -> [Articulation]
enumFromThen :: Articulation -> Articulation -> [Articulation]
$cenumFromThen :: Articulation -> Articulation -> [Articulation]
enumFrom :: Articulation -> [Articulation]
$cenumFrom :: Articulation -> [Articulation]
fromEnum :: Articulation -> Int
$cfromEnum :: Articulation -> Int
toEnum :: Int -> Articulation
$ctoEnum :: Int -> Articulation
pred :: Articulation -> Articulation
$cpred :: Articulation -> Articulation
succ :: Articulation -> Articulation
$csucc :: Articulation -> Articulation
Enum, Articulation
forall a. a -> a -> Bounded a
maxBound :: Articulation
$cmaxBound :: Articulation
minBound :: Articulation
$cminBound :: Articulation
Bounded)

-- copied from User.Elaforge.Instrument.Kontakt.Gong

strokeMap :: Drum.StrokeMap Articulation
strokeMap :: StrokeMap Articulation
strokeMap = 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
    [ (Char
'q', Symbol
"P", forall art. Attributes -> art -> Text -> Call art
Stroke (Attributes
Attrs.rim forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.closed)     Articulation
RimClosed Text
closed)

    , (Char
'a', Symbol
"+/", forall art. Attributes -> art -> Text -> Call art
Stroke (Attributes
Attrs.rim forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.staccato)  Articulation
RimStaccato Text
open)
    , (Char
'z', Symbol
"+", forall art. Attributes -> art -> Text -> Call art
Stroke (Attributes
Attrs.rim forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.open)       Articulation
RimOpen Text
open)
    , (Char
's', Symbol
".", forall art. Attributes -> art -> Text -> Call art
Stroke (Attributes
Attrs.center forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.closed forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.soft)
                        Articulation
CenterClosed Text
closed)
    , (Char
'x', Symbol
"o", forall art. Attributes -> art -> Text -> Call art
Stroke (Attributes
Attrs.center forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.closed)  Articulation
CenterClosed Text
closed)
    , (Char
'c', Symbol
"oo", forall art. Generator Event -> Call art
Call forall a b. (a -> b) -> a -> b
$
        Symbol -> CallName -> Placement -> RealTime -> Y -> Generator Event
DUtil.doubled_call Symbol
"o" CallName
"oo" Placement
DUtil.After (Y -> RealTime
RealTime.seconds Y
0.09) Y
0.75)
    , (Char
'f', Symbol
"o..", forall art. Generator Event -> Call art
Call Generator Event
c_nruk)

    -- This is not commonly used.
    , (Char
'v', Symbol
"c", forall art. Attributes -> art -> Text -> Call art
Stroke (Attributes
Attrs.center forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.open)    Articulation
CenterOpen Text
open)
    -- I think the idea was to use this to damp open strokes.
    , (Char
'm', Symbol
"m", forall art. Attributes -> art -> Text -> Call art
Stroke Attributes
Attrs.damp                      Articulation
Damp Text
closed)

    , (Char
' ', Symbol
"k", forall art. Generator Event -> Call art
Call forall a b. (a -> b) -> a -> b
$
        CallName
-> Maybe (Either Text [Quoted])
-> Maybe (Either Rank DefaultScore)
-> Generator Event
Gong.make_cycle CallName
"kajar" (forall a. a -> Maybe a
Just (forall a b. a -> Either a b
Left Text
"o")) (forall a. a -> Maybe a
Just (forall a b. a -> Either a b
Left Rank
Meter.Q)))
    ]
    where
    stops :: Stops
stops = [(Text
closed, [Text
open])]
    open :: Text
open = Text
"open"
    closed :: Text
closed = Text
"closed"

convertMap :: Drum.ConvertMap Articulation
convertMap :: ConvertMap Articulation
convertMap = Drum.ConvertMap
    { _dynRange :: (Y, Y)
_dynRange = (Y
0.5, Y
1)
    , _naturalNn :: Maybe (Articulation -> NoteNumber)
_naturalNn = forall a. Maybe a
Nothing
    , _muteTime :: Maybe RealTime
_muteTime = forall a. a -> Maybe a
Just RealTime
0.05
    , _getFilename :: Articulation -> Y -> Y -> (FilePath, Maybe (Y, Y))
_getFilename = forall art a.
Show art =>
Y -> (art -> [FilePath]) -> art -> Y -> Y -> (FilePath, Maybe a)
Drum.variableDynamic Y
0.15 Articulation -> [FilePath]
articulationSamples
    , _allFilenames :: Set FilePath
_allFilenames = forall a.
(HasCallStack, Enum a, Bounded a, Show a) =>
Int -> (a -> [FilePath]) -> Set FilePath
Drum.allFilenames Int
171 Articulation -> [FilePath]
articulationSamples
    }

-- * calls

-- copied from User.Elaforge.Instrument.Kontakt.Gong

c_nruk :: Derive.Generator Derive.Note
c_nruk :: Generator Event
c_nruk = Module
-> CallName -> Doc -> (NoteArgs -> NoteDeriver) -> Generator Event
Gong.nruk_generator Module
Module.instrument CallName
"nruk" Doc
"Nruktuk on `o`." forall a b. (a -> b) -> a -> b
$
    forall d.
(PassedArgs d -> NoteDeriver) -> PassedArgs d -> NoteDeriver
Sub.inverting forall a b. (a -> b) -> a -> b
$ \NoteArgs
args -> do
        Generator Event
gen <- forall d. Callable (Generator d) => Symbol -> Deriver (Generator d)
Eval.get_generator Symbol
"o"
        forall d. Context d -> Generator d -> [Val] -> Deriver (Stream d)
Eval.apply_generator (forall val. PassedArgs val -> Context val
Derive.passed_ctx NoteArgs
args) Generator Event
gen []

-- * articulationSamples

_makeArticulationSamples :: IO ()
_makeArticulationSamples :: IO ()
_makeArticulationSamples = FilePath -> [FilePath] -> FilePath -> IO ()
Drum.makeFileList (Text -> FilePath
untxt Text
patchName)
    (forall a b. (a -> b) -> [a] -> [b]
map forall a. Show a => a -> FilePath
show (forall a. (Enum a, Bounded a) => [a]
Util.enumAll :: [Articulation])) FilePath
"articulationSamples"

-- generated
articulationSamples :: Articulation -> [FilePath]
articulationSamples :: Articulation -> [FilePath]
articulationSamples = \case
    Articulation
CenterClosed ->
        [ FilePath
"24-30-35-0-4-center+closed.flac"
        , FilePath
"24-30-35-5-9-center+closed.flac"
        , FilePath
"24-30-35-10-14-center+closed.flac"
        , FilePath
"24-30-35-15-19-center+closed.flac"
        , FilePath
"24-30-35-20-24-center+closed.flac"
        , FilePath
"24-30-35-25-29-center+closed.flac"
        , FilePath
"24-30-35-30-34-center+closed.flac"
        , FilePath
"24-30-35-35-39-center+closed.flac"
        , FilePath
"24-30-35-40-43-center+closed.flac"
        , FilePath
"24-30-35-44-47-center+closed.flac"
        , FilePath
"24-30-35-48-51-center+closed.flac"
        , FilePath
"24-30-35-52-55-center+closed.flac"
        , FilePath
"24-30-35-56-59-center+closed.flac"
        , FilePath
"24-30-35-60-63-center+closed.flac"
        , FilePath
"24-30-35-64-67-center+closed.flac"
        , FilePath
"24-30-35-68-71-center+closed.flac"
        , FilePath
"24-30-35-72-75-center+closed.flac"
        , FilePath
"24-30-35-76-79-center+closed.flac"
        , FilePath
"24-30-35-80-83-center+closed.flac"
        , FilePath
"24-30-35-84-87-center+closed.flac"
        , FilePath
"24-30-35-88-91-center+closed.flac"
        , FilePath
"24-30-35-92-95-center+closed.flac"
        , FilePath
"24-30-35-96-99-center+closed.flac"
        , FilePath
"24-30-35-100-103-center+closed.flac"
        , FilePath
"24-30-35-104-107-center+closed.flac"
        , FilePath
"24-30-35-108-111-center+closed.flac"
        , FilePath
"24-30-35-112-115-center+closed.flac"
        , FilePath
"24-30-35-116-119-center+closed.flac"
        , FilePath
"24-30-35-120-123-center+closed.flac"
        , FilePath
"24-30-35-124-127-center+closed.flac"
        ]
    Articulation
CenterOpen ->
        [ FilePath
"36-42-47-0-4-center+open.flac"
        , FilePath
"36-42-47-5-9-center+open.flac"
        , FilePath
"36-42-47-10-14-center+open.flac"
        , FilePath
"36-42-47-15-19-center+open.flac"
        , FilePath
"36-42-47-20-24-center+open.flac"
        , FilePath
"36-42-47-25-29-center+open.flac"
        , FilePath
"36-42-47-30-34-center+open.flac"
        , FilePath
"36-42-47-35-39-center+open.flac"
        , FilePath
"36-42-47-40-44-center+open.flac"
        , FilePath
"36-42-47-45-49-center+open.flac"
        , FilePath
"36-42-47-50-54-center+open.flac"
        , FilePath
"36-42-47-55-59-center+open.flac"
        , FilePath
"36-42-47-60-64-center+open.flac"
        , FilePath
"36-42-47-65-69-center+open.flac"
        , FilePath
"36-42-47-70-74-center+open.flac"
        , FilePath
"36-42-47-75-79-center+open.flac"
        , FilePath
"36-42-47-80-83-center+open.flac"
        , FilePath
"36-42-47-84-87-center+open.flac"
        , FilePath
"36-42-47-88-91-center+open.flac"
        , FilePath
"36-42-47-92-95-center+open.flac"
        , FilePath
"36-42-47-96-99-center+open.flac"
        , FilePath
"36-42-47-100-103-center+open.flac"
        , FilePath
"36-42-47-104-107-center+open.flac"
        , FilePath
"36-42-47-108-111-center+open.flac"
        , FilePath
"36-42-47-112-115-center+open.flac"
        , FilePath
"36-42-47-116-119-center+open.flac"
        , FilePath
"36-42-47-120-123-center+open.flac"
        , FilePath
"36-42-47-124-127-center+open.flac"
        ]
    Articulation
Damp ->
        [ FilePath
"84-90-95-0-14-damp.flac"
        , FilePath
"84-90-95-15-29-damp.flac"
        , FilePath
"84-90-95-30-43-damp.flac"
        , FilePath
"84-90-95-44-57-damp.flac"
        , FilePath
"84-90-95-58-71-damp.flac"
        , FilePath
"84-90-95-72-85-damp.flac"
        , FilePath
"84-90-95-86-99-damp.flac"
        , FilePath
"84-90-95-100-113-damp.flac"
        , FilePath
"84-90-95-114-127-damp.flac"
        ]
    Articulation
RimClosed ->
        [ FilePath
"48-54-59-0-3-rim+closed.flac"
        , FilePath
"48-54-59-4-7-rim+closed.flac"
        , FilePath
"48-54-59-8-10-rim+closed.flac"
        , FilePath
"48-54-59-11-13-rim+closed.flac"
        , FilePath
"48-54-59-14-16-rim+closed.flac"
        , FilePath
"48-54-59-17-19-rim+closed.flac"
        , FilePath
"48-54-59-20-22-rim+closed.flac"
        , FilePath
"48-54-59-23-25-rim+closed.flac"
        , FilePath
"48-54-59-26-28-rim+closed.flac"
        , FilePath
"48-54-59-29-31-rim+closed.flac"
        , FilePath
"48-54-59-32-34-rim+closed.flac"
        , FilePath
"48-54-59-35-37-rim+closed.flac"
        , FilePath
"48-54-59-38-40-rim+closed.flac"
        , FilePath
"48-54-59-41-43-rim+closed.flac"
        , FilePath
"48-54-59-44-46-rim+closed.flac"
        , FilePath
"48-54-59-47-49-rim+closed.flac"
        , FilePath
"48-54-59-50-52-rim+closed.flac"
        , FilePath
"48-54-59-53-55-rim+closed.flac"
        , FilePath
"48-54-59-56-58-rim+closed.flac"
        , FilePath
"48-54-59-59-61-rim+closed.flac"
        , FilePath
"48-54-59-62-64-rim+closed.flac"
        , FilePath
"48-54-59-65-67-rim+closed.flac"
        , FilePath
"48-54-59-68-70-rim+closed.flac"
        , FilePath
"48-54-59-71-73-rim+closed.flac"
        , FilePath
"48-54-59-74-76-rim+closed.flac"
        , FilePath
"48-54-59-77-79-rim+closed.flac"
        , FilePath
"48-54-59-80-82-rim+closed.flac"
        , FilePath
"48-54-59-83-85-rim+closed.flac"
        , FilePath
"48-54-59-86-88-rim+closed.flac"
        , FilePath
"48-54-59-89-91-rim+closed.flac"
        , FilePath
"48-54-59-92-94-rim+closed.flac"
        , FilePath
"48-54-59-95-97-rim+closed.flac"
        , FilePath
"48-54-59-98-100-rim+closed.flac"
        , FilePath
"48-54-59-101-103-rim+closed.flac"
        , FilePath
"48-54-59-104-106-rim+closed.flac"
        , FilePath
"48-54-59-107-109-rim+closed.flac"
        , FilePath
"48-54-59-110-112-rim+closed.flac"
        , FilePath
"48-54-59-113-115-rim+closed.flac"
        , FilePath
"48-54-59-116-118-rim+closed.flac"
        , FilePath
"48-54-59-119-121-rim+closed.flac"
        , FilePath
"48-54-59-122-124-rim+closed.flac"
        , FilePath
"48-54-59-125-127-rim+closed.flac"
        ]
    Articulation
RimOpen ->
        [ FilePath
"60-66-71-0-5-rim+open.flac"
        , FilePath
"60-66-71-6-11-rim+open.flac"
        , FilePath
"60-66-71-12-17-rim+open.flac"
        , FilePath
"60-66-71-18-23-rim+open.flac"
        , FilePath
"60-66-71-24-29-rim+open.flac"
        , FilePath
"60-66-71-30-35-rim+open.flac"
        , FilePath
"60-66-71-36-41-rim+open.flac"
        , FilePath
"60-66-71-42-47-rim+open.flac"
        , FilePath
"60-66-71-48-53-rim+open.flac"
        , FilePath
"60-66-71-54-59-rim+open.flac"
        , FilePath
"60-66-71-60-65-rim+open.flac"
        , FilePath
"60-66-71-66-71-rim+open.flac"
        , FilePath
"60-66-71-72-77-rim+open.flac"
        , FilePath
"60-66-71-78-83-rim+open.flac"
        , FilePath
"60-66-71-84-89-rim+open.flac"
        , FilePath
"60-66-71-90-95-rim+open.flac"
        , FilePath
"60-66-71-96-101-rim+open.flac"
        , FilePath
"60-66-71-102-107-rim+open.flac"
        , FilePath
"60-66-71-108-112-rim+open.flac"
        , FilePath
"60-66-71-113-117-rim+open.flac"
        , FilePath
"60-66-71-118-122-rim+open.flac"
        , FilePath
"60-66-71-123-127-rim+open.flac"
        ]
    Articulation
RimStaccato ->
        [ FilePath
"72-78-83-0-3-rim+staccato.flac"
        , FilePath
"72-78-83-4-7-rim+staccato.flac"
        , FilePath
"72-78-83-8-11-rim+staccato.flac"
        , FilePath
"72-78-83-12-15-rim+staccato.flac"
        , FilePath
"72-78-83-16-19-rim+staccato.flac"
        , FilePath
"72-78-83-20-23-rim+staccato.flac"
        , FilePath
"72-78-83-24-27-rim+staccato.flac"
        , FilePath
"72-78-83-28-31-rim+staccato.flac"
        , FilePath
"72-78-83-32-34-rim+staccato.flac"
        , FilePath
"72-78-83-35-37-rim+staccato.flac"
        , FilePath
"72-78-83-38-40-rim+staccato.flac"
        , FilePath
"72-78-83-41-43-rim+staccato.flac"
        , FilePath
"72-78-83-44-46-rim+staccato.flac"
        , FilePath
"72-78-83-47-49-rim+staccato.flac"
        , FilePath
"72-78-83-50-52-rim+staccato.flac"
        , FilePath
"72-78-83-53-55-rim+staccato.flac"
        , FilePath
"72-78-83-56-58-rim+staccato.flac"
        , FilePath
"72-78-83-59-61-rim+staccato.flac"
        , FilePath
"72-78-83-62-64-rim+staccato.flac"
        , FilePath
"72-78-83-65-67-rim+staccato.flac"
        , FilePath
"72-78-83-68-70-rim+staccato.flac"
        , FilePath
"72-78-83-71-73-rim+staccato.flac"
        , FilePath
"72-78-83-74-76-rim+staccato.flac"
        , FilePath
"72-78-83-77-79-rim+staccato.flac"
        , FilePath
"72-78-83-80-82-rim+staccato.flac"
        , FilePath
"72-78-83-83-85-rim+staccato.flac"
        , FilePath
"72-78-83-86-88-rim+staccato.flac"
        , FilePath
"72-78-83-89-91-rim+staccato.flac"
        , FilePath
"72-78-83-92-94-rim+staccato.flac"
        , FilePath
"72-78-83-95-97-rim+staccato.flac"
        , FilePath
"72-78-83-98-100-rim+staccato.flac"
        , FilePath
"72-78-83-101-103-rim+staccato.flac"
        , FilePath
"72-78-83-104-106-rim+staccato.flac"
        , FilePath
"72-78-83-107-109-rim+staccato.flac"
        , FilePath
"72-78-83-110-112-rim+staccato.flac"
        , FilePath
"72-78-83-113-115-rim+staccato.flac"
        , FilePath
"72-78-83-116-118-rim+staccato.flac"
        , FilePath
"72-78-83-119-121-rim+staccato.flac"
        , FilePath
"72-78-83-122-124-rim+staccato.flac"
        , FilePath
"72-78-83-125-127-rim+staccato.flac"
        ]