-- | Standard SC3 graphs, referenced in documentation.
module Sound.Sc3.Ugen.Help.Graph where

import Sound.Sc3.Common.Enum
import Sound.Sc3.Common.Envelope
import Sound.Sc3.Common.Rate

import Sound.Sc3.Ugen.Bindings
import Sound.Sc3.Ugen.Mce
import Sound.Sc3.Ugen.Ugen
import Sound.Sc3.Ugen.Util

-- | The SC3 /default/ instrument 'Ugen' graph.
default_ugen_graph :: Ugen
default_ugen_graph :: Ugen
default_ugen_graph =
    let f :: Ugen
f = Rate -> String -> Double -> Ugen
control Rate
kr String
"freq" Double
440
        a :: Ugen
a = Rate -> String -> Double -> Ugen
control Rate
kr String
"amp" Double
0.1
        p :: Ugen
p = Rate -> String -> Double -> Ugen
control Rate
kr String
"pan" Double
0
        g :: Ugen
g = Rate -> String -> Double -> Ugen
control Rate
kr String
"gate" Double
1
        o :: Ugen
o = Rate -> String -> Double -> Ugen
control Rate
kr String
"out" Double
0
        e :: Ugen
e = Ugen -> Ugen -> Ugen -> Ugen -> DoneAction Ugen -> Ugen
linen Ugen
g Ugen
0.01 Ugen
0.7 Ugen
0.3 forall t. DoneAction t
RemoveSynth
        f3 :: Ugen
f3 = [Ugen] -> Ugen
mce [Ugen
f,Ugen
f forall a. Num a => a -> a -> a
+ forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId Char
'α' (-Ugen
0.4) Ugen
0,Ugen
f forall a. Num a => a -> a -> a
+ forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId Char
'β' Ugen
0 Ugen
0.4]
        l :: Ugen
l = Rate -> Ugen -> Ugen -> Ugen -> DoneAction Ugen -> Ugen
xLine Rate
kr (forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId Char
'γ' Ugen
4000 Ugen
5000) (forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId Char
'δ' Ugen
2500 Ugen
3200) Ugen
1 forall t. DoneAction t
DoNothing
        z :: Ugen
z = Ugen -> Ugen -> Ugen
lpf (Ugen -> Ugen
mix (Rate -> Ugen -> Ugen -> Ugen -> Ugen
varSaw Rate
ar Ugen
f3 Ugen
0 Ugen
0.3 forall a. Num a => a -> a -> a
* Ugen
0.3)) Ugen
l forall a. Num a => a -> a -> a
* Ugen
e
    in Ugen -> Ugen -> Ugen
out Ugen
o (Ugen -> Ugen -> Ugen -> Ugen
pan2 Ugen
z Ugen
p Ugen
a)

-- | A /Gabor/ grain, envelope is by 'lfGauss'.
gabor_grain_ugen_graph :: Ugen
gabor_grain_ugen_graph :: Ugen
gabor_grain_ugen_graph =
    let o :: Ugen
o = Rate -> String -> Double -> Ugen
control Rate
ir String
"out" Double
0
        f :: Ugen
f = Rate -> String -> Double -> Ugen
control Rate
ir String
"freq" Double
440
        d :: Ugen
d = Rate -> String -> Double -> Ugen
control Rate
ir String
"sustain" Double
1
        l :: Ugen
l = Rate -> String -> Double -> Ugen
control Rate
ir String
"pan" Double
0
        a :: Ugen
a = Rate -> String -> Double -> Ugen
control Rate
ir String
"amp" Double
0.1
        w :: Ugen
w = Rate -> String -> Double -> Ugen
control Rate
ir String
"width" Double
0.25
        e :: Ugen
e = Rate
-> Ugen -> Ugen -> Ugen -> Loop Ugen -> DoneAction Ugen -> Ugen
lfGauss Rate
ar Ugen
d Ugen
w Ugen
0 forall t. Loop t
NoLoop forall t. DoneAction t
RemoveSynth
        s :: Ugen
s = Rate -> Ugen -> Ugen -> Ugen
fSinOsc Rate
ar Ugen
f (Ugen
0.5 forall a. Num a => a -> a -> a
* forall a. Floating a => a
pi) forall a. Num a => a -> a -> a
* Ugen
e
    in Ugen -> Ugen -> Ugen
offsetOut Ugen
o (Ugen -> Ugen -> Ugen -> Ugen
pan2 Ugen
s Ugen
l Ugen
a)

-- | A /sine/ grain, envelope is by 'envGen' of 'envSine'.
sine_grain_ugen_graph :: Ugen
sine_grain_ugen_graph :: Ugen
sine_grain_ugen_graph =
    let o :: Ugen
o = Rate -> String -> Double -> Ugen
control Rate
ir String
"out" Double
0
        f :: Ugen
f = Rate -> String -> Double -> Ugen
control Rate
ir String
"freq" Double
440
        d :: Ugen
d = Rate -> String -> Double -> Ugen
control Rate
ir String
"sustain" Double
1
        l :: Ugen
l = Rate -> String -> Double -> Ugen
control Rate
ir String
"pan" Double
0
        a :: Ugen
a = Rate -> String -> Double -> Ugen
control Rate
ir String
"amp" Double
0.1
        w :: Ugen
w = Rate -> String -> Double -> Ugen
control Rate
ir String
"width" Double
0.25
        e :: Ugen
e = Rate
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> DoneAction Ugen
-> Envelope Ugen
-> Ugen
envGen Rate
ar Ugen
1 Ugen
1 Ugen
0 Ugen
1 forall t. DoneAction t
RemoveSynth (forall a. Fractional a => a -> a -> Envelope a
envSine (Ugen
d forall a. Num a => a -> a -> a
* Ugen
w) Ugen
1)
        s :: Ugen
s = Rate -> Ugen -> Ugen -> Ugen
fSinOsc Rate
ar Ugen
f (Ugen
0.5 forall a. Num a => a -> a -> a
* forall a. Floating a => a
pi) forall a. Num a => a -> a -> a
* Ugen
e
    in Ugen -> Ugen -> Ugen
offsetOut Ugen
o (Ugen -> Ugen -> Ugen -> Ugen
pan2 Ugen
s Ugen
l Ugen
a)

-- | Trivial file playback instrument.
--
-- If /use_gate/ is 'True' there is a /gate/ parameter and the synth
-- ends either when the sound file ends or the gate closes, else there
-- is a /sustain/ parameter to indicate the duration.  In both cases a
-- linear envelope with a decay time of /decay/ is applied.
--
-- The /rdelay/ parameter sets the maximum pre-delay time (in
-- seconds), each instance is randomly pre-delayed between zero and
-- the indicated time.  The /ramplitude/ parameter sets the maximum
-- amplitude offset of the /amp/ parameter, each instance is randomly
-- amplified between zero and the indicated value.
default_sampler_ugen_graph :: Bool -> Ugen
default_sampler_ugen_graph :: Bool -> Ugen
default_sampler_ugen_graph Bool
use_gate =
    let b :: Ugen
b = Rate -> String -> Double -> Ugen
control Rate
kr String
"bufnum" Double
0
        l :: Ugen
l = Rate -> String -> Double -> Ugen
control Rate
kr String
"pan" Double
0
        a :: Ugen
a = Rate -> String -> Double -> Ugen
control Rate
kr String
"amp" Double
0.1
        r :: Ugen
r = Rate -> String -> Double -> Ugen
control Rate
kr String
"rate" Double
1
        m :: Ugen
m = Rate -> String -> Double -> Ugen
control Rate
kr String
"rdelay" Double
0
        v :: Ugen
v = Rate -> String -> Double -> Ugen
control Rate
kr String
"ramplitude" Double
0
        w :: Ugen
w = Rate -> String -> Double -> Ugen
control Rate
kr String
"attack" Double
0
        y :: Ugen
y = Rate -> String -> Double -> Ugen
control Rate
kr String
"decay" Double
0.5
        r' :: Ugen
r' = Rate -> Ugen -> Ugen
bufRateScale Rate
kr Ugen
b forall a. Num a => a -> a -> a
* Ugen
r
        p :: Ugen
p = Int
-> Rate
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Loop Ugen
-> DoneAction Ugen
-> Ugen
playBuf Int
1 Rate
ar Ugen
b Ugen
r' Ugen
1 Ugen
0 forall t. Loop t
NoLoop forall t. DoneAction t
RemoveSynth
        e :: Ugen
e = if Bool
use_gate
            then let g :: Ugen
g = Rate -> String -> Double -> Ugen
control Rate
kr String
"gate" Double
1
                 in Rate
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> DoneAction Ugen
-> Envelope Ugen
-> Ugen
envGen Rate
kr Ugen
g Ugen
1 Ugen
0 Ugen
1 forall t. DoneAction t
RemoveSynth (forall a. Num a => a -> a -> a -> Envelope_Curve a -> Envelope a
envAsr Ugen
w Ugen
1 Ugen
y forall a. Envelope_Curve a
EnvSin)
            else let s :: Ugen
s = Rate -> String -> Double -> Ugen
control Rate
kr String
"sustain" Double
1
                 in Rate
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> DoneAction Ugen
-> Envelope Ugen
-> Ugen
envGen Rate
kr Ugen
1 Ugen
1 Ugen
0 Ugen
1 forall t. DoneAction t
RemoveSynth (forall a. Num a => a -> a -> a -> a -> Envelope a
envLinen Ugen
w Ugen
s Ugen
y Ugen
1)
        d :: Ugen
d = Ugen -> Ugen -> Ugen -> Ugen
delayC (Ugen
p forall a. Num a => a -> a -> a
* Ugen
e) Ugen
m (forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId Char
'α' Ugen
0 Ugen
m)
    in Ugen -> Ugen -> Ugen
out Ugen
0 (Ugen -> Ugen -> Ugen -> Ugen
pan2 Ugen
d Ugen
l (Ugen
a forall a. Num a => a -> a -> a
+ forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId Char
'β' Ugen
0 Ugen
v))