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

-- | PA3 Derailer.
module User.Elaforge.Instrument.Derailer where
import qualified Cmd.Instrument.MidiInst as MidiInst
import qualified Derive.ScoreT as ScoreT
import Global


synth :: MidiInst.Synth
synth :: Synth
synth =
    SynthName -> SynthName -> [Patch] -> Synth
MidiInst.synth SynthName
"derailer" SynthName
"PA3 Derailer." ([Patch] -> Synth) -> [Patch] -> Synth
forall a b. (a -> b) -> a -> b
$
        [(Control, Control)] -> [Patch] -> [Patch]
MidiInst.synth_controls [(Control, Control)]
controls [Patch]
patches
    where
    controls :: [(Control, Control)]
controls = ((Control, SynthName) -> (Control, Control))
-> [(Control, SynthName)] -> [(Control, Control)]
forall a b. (a -> b) -> [a] -> [b]
map ((SynthName -> Control)
-> (Control, SynthName) -> (Control, Control)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second SynthName -> Control
ScoreT.Control) ([(Control, SynthName)] -> [(Control, Control)])
-> [(Control, SynthName)] -> [(Control, Control)]
forall a b. (a -> b) -> a -> b
$ [[(Control, SynthName)]] -> [(Control, SynthName)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
        [ [ (Control
cc, SynthName
"drone" SynthName -> SynthName -> SynthName
forall a. Semigroup a => a -> a -> a
<> Integer -> SynthName
forall a. Show a => a -> SynthName
showt Integer
n SynthName -> SynthName -> SynthName
forall a. Semigroup a => a -> a -> a
<> SynthName
"-mass")
          | (Integer
n, Control
cc) <- [Integer] -> [Control] -> [(Integer, Control)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Integer
1..Integer
5] [Control
21..Control
25]
          ]
        , [(Control
28, SynthName
"strike-mass")]
        , [ (Control
cc, SynthName
"drone" SynthName -> SynthName -> SynthName
forall a. Semigroup a => a -> a -> a
<> Integer -> SynthName
forall a. Show a => a -> SynthName
showt Integer
n SynthName -> SynthName -> SynthName
forall a. Semigroup a => a -> a -> a
<> SynthName
"-gain")
          | (Integer
n, Control
cc) <- [Integer] -> [Control] -> [(Integer, Control)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Integer
1..Integer
5] [Control
41..Control
45]
          ]
        , [ (Control
48, SynthName
"strike-gain")
          , (Control
31, SynthName
"con-strength")
          , (Control
32, SynthName
"in-pos")
          , (Control
33, SynthName
"strike-rate")
          ]
        ]
    patches :: [Patch]
patches =
        [ SynthName -> [(Control, Control)] -> Patch
patch SynthName
"strike" []
        , SynthName -> [(Control, Control)] -> Patch
patch SynthName
"multi-strike" [(Control
33, Control
"strike-rate"), (Control
1, Control
"breath")]
        , Patch -> Patch
MidiInst.pressure (Patch -> Patch) -> Patch -> Patch
forall a b. (a -> b) -> a -> b
$ SynthName -> [(Control, Control)] -> Patch
patch SynthName
"bow" [(Control
34, Control
"bow-depth"), (Control
1, Control
"dyn")]
        ]
    patch :: SynthName -> [(Control, Control)] -> Patch
patch = PbRange -> SynthName -> [(Control, Control)] -> Patch
MidiInst.named_patch (-Int
2, Int
2)