-- | Bindings to unit generators in sc3-plugins.
module Sound.Sc3.Ugen.Bindings.Hw.External.Sc3_Plugins where

import Sound.Sc3.Common.Rate

import qualified Sound.Sc3.Ugen.Bindings.Hw.Construct as C
import Sound.Sc3.Ugen.Types
import qualified Sound.Sc3.Ugen.Util as Util
import qualified Sound.Sc3.Ugen.Bindings.Db.External as X

-- | Convert frequency value to value appropriate for AY tone inputs.
ayFreqToTone :: Fractional a => a -> a
ayFreqToTone :: forall a. Fractional a => a -> a
ayFreqToTone a
f = a
110300 forall a. Fractional a => a -> a -> a
/ (a
f forall a. Num a => a -> a -> a
- a
0.5)

-- | LADSPA plugins inside SuperCollider.
ladspa :: Int -> Rate -> Ugen -> [Ugen] -> Ugen
ladspa :: Int -> Rate -> Ugen -> [Ugen] -> Ugen
ladspa Int
nc Rate
rt Ugen
k [Ugen]
z = Rate -> String -> [Ugen] -> Int -> Ugen
C.mkOsc Rate
rt String
"LADSPA" (forall n. Real n => n -> Ugen
constant Int
nc forall a. a -> [a] -> [a]
: Ugen
k forall a. a -> [a] -> [a]
: [Ugen]
z) Int
nc

-- | Lookup index of STK instrument by name.
stkAt :: (Num t,Enum t) => String -> t
stkAt :: forall t. (Num t, Enum t) => String -> t
stkAt String
nm =
  let nm_seq :: [String]
nm_seq = [String
"Clarinet", String
"BlowHole", String
"Saxofony", String
"Flute", String
"Brass"
               ,String
"BlowBotl", String
"Bowed", String
"Plucked", String
"StifKarp", String
"Sitar", String
"Mandolin"
               ,String
"Rhodey", String
"Wurley", String
"TubeBell", String
"HevyMetl", String
"PercFlut"
               ,String
"BeeThree", String
"FMVoices", String
"VoicForm", String
"Moog", String
"Simple", String
"Drummer"
               ,String
"BandedWG", String
"Shakers", String
"ModalBar", String
"Mesh2D", String
"Resonate", String
"Whistle"]
      tbl :: [(String, t)]
tbl = forall a b. [a] -> [b] -> [(a, b)]
zip [String]
nm_seq [t
0..]
  in case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup String
nm [(String, t)]
tbl of
       Just t
ix -> t
ix
       Maybe t
Nothing -> forall a. HasCallStack => String -> a
error String
"stkAt: unknown instr"

-- | freq=220, gate=1, onamp=1, offamp=1, bowpressure=64, bowposition=64, vibfreq=64, vibgain=64, loudness=64
stkBowedI :: Rate -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen
stkBowedI :: Rate
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
-> Ugen
stkBowedI Rate
rt Ugen
freq Ugen
gate_ Ugen
onamp Ugen
offamp Ugen
bowpressure Ugen
bowposition Ugen
vibfreq Ugen
vibgain Ugen
loudness =
  let args :: Ugen
args = [Ugen] -> Ugen
mce [Ugen
2,Ugen
bowpressure,Ugen
4,Ugen
bowposition,Ugen
11,Ugen
vibfreq,Ugen
1,Ugen
vibgain,Ugen
128,Ugen
loudness]
  in Rate -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen -> Ugen
X.stkInst Rate
rt (forall t. (Num t, Enum t) => String -> t
stkAt String
"Bowed") Ugen
freq Ugen
gate_ Ugen
onamp Ugen
offamp Ugen
args

-- | Wrapping Synthesis toolkit.
--
--  StkGlobals [ar] showWarnings=0.0 printErrors=0.0 rawfilepath=0.0
stkGlobals :: Rate -> Ugen -> Ugen -> Ugen -> Ugen
stkGlobals :: Rate -> Ugen -> Ugen -> Ugen -> Ugen
stkGlobals Rate
rate Ugen
showWarnings Ugen
printErrors Ugen
rawfilepath =
  Maybe ([Sample] -> Sample)
-> [Rate]
-> Either Rate [Int]
-> String
-> [Ugen]
-> Maybe [Ugen]
-> Int
-> Special
-> UgenId
-> Ugen
mkUgen forall a. Maybe a
Nothing [Rate
ar] (forall a b. a -> Either a b
Left Rate
rate) String
"StkGlobals" ([Ugen
showWarnings,Ugen
printErrors] forall a. [a] -> [a] -> [a]
++ Bool -> Ugen -> [Ugen]
Util.unpackLabel Bool
False Ugen
rawfilepath) forall a. Maybe a
Nothing Int
1 (Int -> Special
Special Int
0) UgenId
NoId