-- 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.LittleGong (patches) where
import qualified Cmd.Instrument.CUtil as CUtil
import qualified Derive.Attrs as Attrs
import qualified Synth.Sampler.Patch as Patch
import qualified Synth.Sampler.Patch.Lib.Drum as Drum
import qualified Synth.Sampler.Patch.Lib.Util as Util

import           Global


patches :: [Patch.Patch]
patches :: [Patch]
patches = (Patch -> [Patch] -> [Patch]
forall a. a -> [a] -> [a]
:[]) (Patch -> [Patch]) -> Patch -> [Patch]
forall a b. (a -> b) -> a -> b
$
    FilePath
-> Text
-> StrokeMap Articulation
-> ConvertMap Articulation
-> (Maybe Articulation -> CallConfig)
-> Patch
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 (CallConfig -> Maybe Articulation -> CallConfig
forall a b. a -> b -> a
const CallConfig
CUtil.call_config)
    where dir :: FilePath
dir = Text -> FilePath
untxt Text
patchName

patchName :: Text
patchName :: Text
patchName = Text
"little-gong"

data Articulation = OpenCenter | MuteCenter | OpenEdge | MuteEdge
    deriving (Articulation -> Articulation -> Bool
(Articulation -> Articulation -> Bool)
-> (Articulation -> Articulation -> Bool) -> Eq Articulation
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
Eq Articulation
-> (Articulation -> Articulation -> Ordering)
-> (Articulation -> Articulation -> Bool)
-> (Articulation -> Articulation -> Bool)
-> (Articulation -> Articulation -> Bool)
-> (Articulation -> Articulation -> Bool)
-> (Articulation -> Articulation -> Articulation)
-> (Articulation -> Articulation -> Articulation)
-> Ord 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
(Int -> Articulation -> ShowS)
-> (Articulation -> FilePath)
-> ([Articulation] -> ShowS)
-> Show Articulation
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]
(Articulation -> Articulation)
-> (Articulation -> Articulation)
-> (Int -> Articulation)
-> (Articulation -> Int)
-> (Articulation -> [Articulation])
-> (Articulation -> Articulation -> [Articulation])
-> (Articulation -> Articulation -> [Articulation])
-> (Articulation -> Articulation -> Articulation -> [Articulation])
-> Enum 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
Articulation -> Articulation -> Bounded Articulation
forall a. a -> a -> Bounded a
maxBound :: Articulation
$cmaxBound :: Articulation
minBound :: Articulation
$cminBound :: Articulation
Bounded)

convertMap :: Drum.ConvertMap Articulation
convertMap :: ConvertMap Articulation
convertMap = Drum.ConvertMap
    { _dynRange :: (Y, Y)
_dynRange = (Y
0.8, Y
1.15)
    , _naturalNn :: Maybe (Articulation -> NoteNumber)
_naturalNn = (Articulation -> NoteNumber) -> Maybe (Articulation -> NoteNumber)
forall a. a -> Maybe a
Just (NoteNumber -> Articulation -> NoteNumber
forall a b. a -> b -> a
const NoteNumber
79.92) -- 5g#
    , _muteTime :: Maybe RealTime
_muteTime = RealTime -> Maybe RealTime
forall a. a -> Maybe a
Just RealTime
0.15
    , _getFilename :: Articulation -> Y -> Y -> (FilePath, Maybe (Y, Y))
_getFilename = Y
-> (Articulation -> [FilePath])
-> Articulation
-> Y
-> Y
-> (FilePath, Maybe (Y, Y))
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 = Int -> (Articulation -> [FilePath]) -> Set FilePath
forall a.
(HasCallStack, Enum a, Bounded a, Show a) =>
Int -> (a -> [FilePath]) -> Set FilePath
Drum.allFilenames Int
62 Articulation -> [FilePath]
articulationSamples
    }

strokeMap :: Drum.StrokeMap Articulation
strokeMap :: StrokeMap Articulation
strokeMap = Stops
-> [(Char, Symbol, Attributes, Articulation, Text)]
-> StrokeMap Articulation
forall art.
Ord art =>
Stops -> [(Char, Symbol, Attributes, art, Text)] -> StrokeMap art
Drum.strokeMapSimple Stops
stops
    [ (Char
'1', Symbol
"+", Attributes
Attrs.mute Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.center, Articulation
MuteCenter, Text
closed)
    , (Char
'q', Symbol
"o", Attributes
forall a. Monoid a => a
mempty, Articulation
OpenCenter,  Text
open)
    , (Char
'2', Symbol
"/", Attributes
Attrs.mute Attributes -> Attributes -> Attributes
forall a. Semigroup a => a -> a -> a
<> Attributes
Attrs.edge, Articulation
MuteEdge, Text
closed)
    , (Char
'w', Symbol
"T", Attributes
Attrs.edge, Articulation
OpenEdge, Text
open)
    ]
    where
    stops :: Stops
stops = [(Text
closed, [Text
open])]
    open :: Text
open = Text
"open"
    closed :: Text
closed = Text
"closed"

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

articulationSamples :: Articulation -> [FilePath]
articulationSamples :: Articulation -> [FilePath]
articulationSamples = \case
    Articulation
OpenCenter ->
        [ FilePath
"open+center-001.flac"
        , FilePath
"open+center-002.flac"
        , FilePath
"open+center-003.flac"
        , FilePath
"open+center-004.flac"
        , FilePath
"open+center-005.flac"
        , FilePath
"open+center-006.flac"
        , FilePath
"open+center-007.flac"
        , FilePath
"open+center-008.flac"
        , FilePath
"open+center-009.flac"
        , FilePath
"open+center-010.flac"
        , FilePath
"open+center-011.flac"
        , FilePath
"open+center-012.flac"
        , FilePath
"open+center-013.flac"
        , FilePath
"open+center-014.flac"
        , FilePath
"open+center-015.flac"
        , FilePath
"open+center-016.flac"
        , FilePath
"open+center-017.flac"
        , FilePath
"open+center-018.flac"
        ]
    Articulation
MuteCenter ->
        [ FilePath
"mute+center-001.flac"
        , FilePath
"mute+center-002.flac"
        , FilePath
"mute+center-003.flac"
        , FilePath
"mute+center-004.flac"
        , FilePath
"mute+center-005.flac"
        , FilePath
"mute+center-006.flac"
        , FilePath
"mute+center-007.flac"
        , FilePath
"mute+center-008.flac"
        , FilePath
"mute+center-009.flac"
        , FilePath
"mute+center-010.flac"
        , FilePath
"mute+center-011.flac"
        , FilePath
"mute+center-012.flac"
        , FilePath
"mute+center-013.flac"
        , FilePath
"mute+center-014.flac"
        , FilePath
"mute+center-015.flac"
        , FilePath
"mute+center-016.flac"
        , FilePath
"mute+center-017.flac"
        , FilePath
"mute+center-018.flac"
        ]
    Articulation
OpenEdge ->
        [ FilePath
"open+edge-001.flac"
        , FilePath
"open+edge-002.flac"
        , FilePath
"open+edge-003.flac"
        , FilePath
"open+edge-004.flac"
        , FilePath
"open+edge-005.flac"
        , FilePath
"open+edge-006.flac"
        , FilePath
"open+edge-007.flac"
        , FilePath
"open+edge-008.flac"
        , FilePath
"open+edge-009.flac"
        , FilePath
"open+edge-010.flac"
        , FilePath
"open+edge-011.flac"
        , FilePath
"open+edge-012.flac"
        , FilePath
"open+edge-013.flac"
        , FilePath
"open+edge-014.flac"
        ]
    Articulation
MuteEdge ->
        [ FilePath
"mute+edge-001.flac"
        , FilePath
"mute+edge-002.flac"
        , FilePath
"mute+edge-003.flac"
        , FilePath
"mute+edge-004.flac"
        , FilePath
"mute+edge-005.flac"
        , FilePath
"mute+edge-006.flac"
        , FilePath
"mute+edge-007.flac"
        , FilePath
"mute+edge-008.flac"
        , FilePath
"mute+edge-009.flac"
        , FilePath
"mute+edge-010.flac"
        , FilePath
"mute+edge-011.flac"
        , FilePath
"mute+edge-012.flac"
        ]