-- | 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.Type
import Sound.SC3.UGen.UGen

-- | 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 DoneAction UGen
forall t. DoneAction t
RemoveSynth
        f3 :: UGen
f3 = [UGen] -> UGen
mce [UGen
f,UGen
f UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
+ Char -> UGen -> UGen -> UGen
forall a. ID a => a -> UGen -> UGen -> UGen
rand Char
'α' (-UGen
0.4) UGen
0,UGen
f UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
+ Char -> UGen -> UGen -> UGen
forall a. ID a => a -> UGen -> UGen -> UGen
rand Char
'β' UGen
0 UGen
0.4]
        l :: UGen
l = Rate -> UGen -> UGen -> UGen -> DoneAction UGen -> UGen
xLine Rate
KR (Char -> UGen -> UGen -> UGen
forall a. ID a => a -> UGen -> UGen -> UGen
rand Char
'γ' UGen
4000 UGen
5000) (Char -> UGen -> UGen -> UGen
forall a. ID a => a -> UGen -> UGen -> UGen
rand Char
'δ' UGen
2500 UGen
3200) UGen
1 DoneAction UGen
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 UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
* UGen
0.3)) UGen
l UGen -> UGen -> UGen
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 Loop UGen
forall t. Loop t
NoLoop DoneAction UGen
forall t. DoneAction t
RemoveSynth
        s :: UGen
s = Rate -> UGen -> UGen -> UGen
fSinOsc Rate
AR UGen
f (UGen
0.5 UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
* UGen
forall a. Floating a => a
pi) UGen -> UGen -> UGen
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 DoneAction UGen
forall t. DoneAction t
RemoveSynth (UGen -> UGen -> Envelope UGen
forall a. Fractional a => a -> a -> Envelope a
envSine (UGen
d UGen -> UGen -> UGen
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 UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
* UGen
forall a. Floating a => a
pi) UGen -> UGen -> UGen
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 UGen -> UGen -> UGen
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 Loop UGen
forall t. Loop t
NoLoop DoneAction UGen
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 DoneAction UGen
forall t. DoneAction t
RemoveSynth (UGen -> UGen -> UGen -> Envelope_Curve UGen -> Envelope UGen
forall a. Num a => a -> a -> a -> Envelope_Curve a -> Envelope a
envASR UGen
w UGen
1 UGen
y Envelope_Curve UGen
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 DoneAction UGen
forall t. DoneAction t
RemoveSynth (UGen -> UGen -> UGen -> UGen -> Envelope UGen
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 UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
* UGen
e) UGen
m (Char -> UGen -> UGen -> UGen
forall a. ID a => a -> UGen -> UGen -> UGen
rand Char
'α' UGen
0 UGen
m)
    in UGen -> UGen -> UGen
out UGen
0 (UGen -> UGen -> UGen -> UGen
pan2 UGen
d UGen
l (UGen
a UGen -> UGen -> UGen
forall a. Num a => a -> a -> a
+ Char -> UGen -> UGen -> UGen
forall a. ID a => a -> UGen -> UGen -> UGen
rand Char
'β' UGen
0 UGen
v))