-- | Common unit generator graphs.
module Sound.Sc3.Ugen.Bindings.Composite.External where

import Data.List {- base -}
import Data.Maybe {- base -}

import Sound.Sc3.Common.Math {- hsc3 -}
import Sound.Sc3.Common.Rate {- hsc3 -}
import Sound.Sc3.Common.Uid {- hsc3 -}
import Sound.Sc3.Common.Unsafe {- hsc3 -}

import Sound.Sc3.Ugen.Analysis  {- hsc3 -}
import Sound.Sc3.Ugen.Ugen {- hsc3 -}
import Sound.Sc3.Ugen.Util {- hsc3 -}

import qualified Sound.Sc3.Ugen.Bindings.Db as Db {- hsc3 -}
import qualified Sound.Sc3.Ugen.Bindings.Db.External as External {- hsc3 -}

-- | FM7 variant where input matrices are not in MCE form.
fm7_mx :: [[Ugen]] -> [[Ugen]] -> Ugen
fm7_mx :: [[Ugen]] -> [[Ugen]] -> Ugen
fm7_mx [[Ugen]]
ctlMatrix [[Ugen]]
modMatrix = Rate -> Ugen -> Ugen -> Ugen
External.fm7 Rate
ar ([Ugen] -> Ugen
mce (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Ugen]]
ctlMatrix)) ([Ugen] -> Ugen
mce (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Ugen]]
modMatrix))

{- | greyhole re-orders parameters as well as unpacking the input signal.

in1=0.0 in2=0.0 damping=0.0 delayTime=2.0 diffusion=0.5 feedback=0.9 moddepth=0.1 modfreq=2.0 size=1.0
in              delayTime=2.0 damping=0.0 size=1.0 diffusion=0.7 feedback=0.9 modDepth=0.1 modFreq=2.0
-}
greyhole :: Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen
greyhole :: Ugen
-> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen
greyhole Ugen
i Ugen
delayTime Ugen
damping Ugen
size Ugen
diffusion Ugen
feedback Ugen
modDepth Ugen
modFreq =
  let (Ugen
i1,Ugen
i2) = Ugen -> (Ugen, Ugen)
unmce2 Ugen
i
  in Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
External.greyholeRaw Ugen
i1 Ugen
i2 Ugen
damping Ugen
delayTime Ugen
diffusion Ugen
feedback Ugen
modDepth Ugen
modFreq Ugen
size

-- | Association list giving names for MiBraids modes.
miBraids_mode_dict :: Num n => [(n,String)]
miBraids_mode_dict :: forall n. Num n => [(n, String)]
miBraids_mode_dict =
  [(n
0,String
"CSAW")
  ,(n
1,String
"MORPH")
  ,(n
2,String
"SAW_SQUARE")
  ,(n
3,String
"SINE_TRIANGLE")
  ,(n
4,String
"BUZZ")
  ,(n
5,String
"SQUARE_SUB")
  ,(n
6,String
"SAW_SUB")
  ,(n
7,String
"SQUARE_SYNC")
  ,(n
8,String
"SAW_SYNC")
  ,(n
9,String
"TRIPLE_SAW")
  ,(n
10,String
"TRIPLE_SQUARE")
  ,(n
11,String
"TRIPLE_TRIANGLE")
  ,(n
12,String
"TRIPLE_SINE")
  ,(n
13,String
"TRIPLE_RING_MOD")
  ,(n
14,String
"SAW_SWARM")
  ,(n
15,String
"SAW_COMB")
  ,(n
16,String
"TOY")
  ,(n
17,String
"DIGITAL_FILTER_LP")
  ,(n
18,String
"DIGITAL_FILTER_PK")
  ,(n
19,String
"DIGITAL_FILTER_BP")
  ,(n
20,String
"DIGITAL_FILTER_HP")
  ,(n
21,String
"VOSIM")
  ,(n
22,String
"VOWEL")
  ,(n
23,String
"VOWEL_FOF")
  ,(n
24,String
"HARMONICS")
  ,(n
25,String
"FM")
  ,(n
26,String
"FEEDbACK_FM")
  ,(n
27,String
"CHAOTIC_FEEDbACK_FM")
  ,(n
28,String
"PLUCKED")
  ,(n
29,String
"BOWED")
  ,(n
30,String
"BLOWN")
  ,(n
31,String
"FLUTED")
  ,(n
32,String
"STRUCK_BELL")
  ,(n
33,String
"STRUCK_DRUM")
  ,(n
34,String
"KICK")
  ,(n
35,String
"CYMBAL")
  ,(n
36,String
"SNARE")
  ,(n
37,String
"WAVETABLES")
  ,(n
38,String
"WAVE_MAP")
  ,(n
39,String
"WAVE_LINE")
  ,(n
40,String
"WAVE_PARAPHONIC")
  ,(n
41,String
"FILTERED_NOISE")
  ,(n
42,String
"TWIN_PEAKS_NOISE")
  ,(n
43,String
"CLOCKED_NOISE")
  ,(n
44,String
"GRANULAR_CLOUD")
  ,(n
45,String
"PARTICLE_NOISE")
  ,(n
46,String
"DIGITAL_MODULATION")
  ,(n
47,String
"QUESTION_MARK")]

-- | Reverse lookup of 'miBraids_mode_dict'.
miBraids_mode_maybe :: Num n => String -> Maybe n
miBraids_mode_maybe :: forall n. Num n => String -> Maybe n
miBraids_mode_maybe String
x = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((forall a. Eq a => a -> a -> Bool
== String
x) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall n. Num n => [(n, String)]
miBraids_mode_dict)

-- | 'error' of 'miBraids_mode_maybe'
miBraids_mode :: Num n => String -> n
miBraids_mode :: forall n. Num n => String -> n
miBraids_mode = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"miBraids_mode?") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Num n => String -> Maybe n
miBraids_mode_maybe

-- | Association list giving names for MiClouds modes.
miClouds_mode_dict :: Num n => [(n,String)]
miClouds_mode_dict :: forall n. Num n => [(n, String)]
miClouds_mode_dict =
  [(n
0,String
"GRANULAR")
  ,(n
1,String
"STRETCH")
  ,(n
2,String
"LOOPING_DELAY")
  ,(n
3,String
"SPECTRAL")]

-- | Reverse lookup of 'miClouds_mode_dict'.
miClouds_mode_maybe :: Num n => String -> Maybe n
miClouds_mode_maybe :: forall n. Num n => String -> Maybe n
miClouds_mode_maybe String
x = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((forall a. Eq a => a -> a -> Bool
== String
x) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall n. Num n => [(n, String)]
miClouds_mode_dict)

-- | 'error' of 'miClouds_mode_maybe'
miClouds_mode :: Num n => String -> n
miClouds_mode :: forall n. Num n => String -> n
miClouds_mode = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"miClouds_mode?") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Num n => String -> Maybe n
miClouds_mode_maybe

-- | Association list giving names for MiPlaits modes.
miPlaits_mode_dict :: Num n => [(n,String)]
miPlaits_mode_dict :: forall n. Num n => [(n, String)]
miPlaits_mode_dict =
  [(n
0,String
"virtual_analog")
  ,(n
1,String
"waveshaping")
  ,(n
2,String
"fm")
  ,(n
3,String
"grain")
  ,(n
4,String
"additive")
  ,(n
5,String
"wavetable")
  ,(n
6,String
"chord")
  ,(n
7,String
"speech")
  ,(n
8,String
"swarm")
  ,(n
9,String
"noise")
  ,(n
10,String
"particle")
  ,(n
11,String
"string")
  ,(n
12,String
"modal")
  ,(n
13,String
"bass_drum")
  ,(n
14,String
"snare_drum")
  ,(n
15,String
"hi_hat")]

-- | Reverse lookup of 'miPlaits_mode_dict'.
miPlaits_mode_maybe :: Num n => String -> Maybe n
miPlaits_mode_maybe :: forall n. Num n => String -> Maybe n
miPlaits_mode_maybe String
x = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((forall a. Eq a => a -> a -> Bool
== String
x) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall n. Num n => [(n, String)]
miPlaits_mode_dict)

-- | 'error' of 'miPlaits_mode_maybe'
miPlaits_mode :: Num n => String -> n
miPlaits_mode :: forall n. Num n => String -> n
miPlaits_mode = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"miPlaits_mode?") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Num n => String -> Maybe n
miPlaits_mode_maybe

-- | Association list giving names for MiPlaits modes.
miRings_mode_dict :: Num n => [(n,String)]
miRings_mode_dict :: forall n. Num n => [(n, String)]
miRings_mode_dict =
  [(n
0,String
"MODAL_RESONATOR")
  ,(n
1,String
"SYMPATHETIC_STRING")
  ,(n
2,String
"MODULATED/INHARMONIC_STRING")
  ,(n
3,String
"2-OP_FM_VOICE")
  ,(n
4,String
"SYMPATHETIC_STRING_QUANTIZED")
  ,(n
5,String
"STRING_AND_REVERB")]

-- | Reverse lookup of 'miRings_mode_dict'.
miRings_mode_maybe :: Num n => String -> Maybe n
miRings_mode_maybe :: forall n. Num n => String -> Maybe n
miRings_mode_maybe String
x = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a b. (a, b) -> a
fst (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((forall a. Eq a => a -> a -> Bool
== String
x) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) forall n. Num n => [(n, String)]
miRings_mode_dict)

-- | 'error' of 'miRings_mode_maybe'
miRings_mode :: Num n => String -> n
miRings_mode :: forall n. Num n => String -> n
miRings_mode = forall a. a -> Maybe a -> a
fromMaybe (forall a. HasCallStack => String -> a
error String
"miRings_mode?") forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Num n => String -> Maybe n
miRings_mode_maybe

-- | pulse signal as difference of two 'sawDPW' signals.
pulseDPW :: Rate -> Ugen -> Ugen -> Ugen
pulseDPW :: Rate -> Ugen -> Ugen -> Ugen
pulseDPW Rate
rt Ugen
freq Ugen
width =
  let o1 :: Ugen
o1 = Rate -> Ugen -> Ugen -> Ugen
External.sawDPW Rate
rt Ugen
freq Ugen
0
      o2 :: Ugen
o2 = Rate -> Ugen -> Ugen -> Ugen
External.sawDPW Rate
rt Ugen
freq (forall n. RealFrac n => (n, n) -> n -> n
wrap_hs (-Ugen
1,Ugen
1) (Ugen
widthforall a. Num a => a -> a -> a
+Ugen
width))
  in Ugen
o1 forall a. Num a => a -> a -> a
- Ugen
o2

-- * rdu

-- | Variant that unpacks the output /mce/ node.
pv_SplitUnpack :: Ugen -> Ugen -> (Ugen,Ugen)
pv_SplitUnpack :: Ugen -> Ugen -> (Ugen, Ugen)
pv_SplitUnpack Ugen
a Ugen
b =
    case Ugen -> [Ugen]
mceChannels (Ugen -> Ugen -> Ugen
External.pv_Split Ugen
a Ugen
b) of
      [Ugen
p,Ugen
q] -> (Ugen
p,Ugen
q)
      [Ugen]
_ -> forall a. HasCallStack => String -> a
error String
"pv_SplitUnpack"

-- | A 'pv_Split' variant, like 'ffta', that allocates a 'localBuf' by
-- tracing the input graph to locate the parent @FFT@ or @PV_Split@
-- node.
pv_SplitAllocId :: ID i => i -> Ugen -> Ugen
pv_SplitAllocId :: forall i. ID i => i -> Ugen -> Ugen
pv_SplitAllocId i
z Ugen
u =
    case Ugen -> Either String Ugen
pv_track_nframes Ugen
u of
      Left String
err -> forall a. HasCallStack => String -> a
error String
err
      Right Ugen
nf -> let b :: Ugen
b = forall a. ID a => a -> Ugen -> Ugen -> Ugen
Db.localBufId i
z Ugen
nf Ugen
1 in Ugen -> Ugen -> Ugen
External.pv_Split Ugen
u Ugen
b

pv_SplitAllocM :: Uid m => Ugen -> m Ugen
pv_SplitAllocM :: forall (m :: * -> *). Uid m => Ugen -> m Ugen
pv_SplitAllocM = forall (m :: * -> *) a b. Uid m => (Int -> Fn1 a b) -> Fn1 a (m b)
liftUid1 forall i. ID i => i -> Ugen -> Ugen
pv_SplitAllocId

pv_SplitAlloc :: Ugen -> Ugen
pv_SplitAlloc :: Ugen -> Ugen
pv_SplitAlloc = forall a r. (a -> IO r) -> a -> r
liftUnsafe1 forall (m :: * -> *). Uid m => Ugen -> m Ugen
pv_SplitAllocM

-- | Variant that unpacks the output /mce/ node.
pv_SplitAllocUnpackId :: ID i => i -> Ugen -> (Ugen,Ugen)
pv_SplitAllocUnpackId :: forall i. ID i => i -> Ugen -> (Ugen, Ugen)
pv_SplitAllocUnpackId i
z Ugen
u =
    case Ugen -> [Ugen]
mceChannels (forall i. ID i => i -> Ugen -> Ugen
pv_SplitAllocId i
z Ugen
u) of
      [Ugen
p,Ugen
q] -> (Ugen
p,Ugen
q)
      [Ugen]
_ -> forall a. HasCallStack => String -> a
error String
"pv_SplitAllocUnpackId"