-- | 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 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
randId 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
randId 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
randId Char
'γ' Ugen
4000 Ugen
5000) (Char -> Ugen -> Ugen -> Ugen
forall a. ID a => a -> Ugen -> Ugen -> Ugen
randId 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
randId 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
randId Char
'β' Ugen
0 Ugen
v))