-- | 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.Type
import qualified Sound.SC3.UGen.UGen as U
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 :: a -> a
ayFreqToTone a
f = a
110300 a -> a -> a
forall a. Fractional a => a -> a -> a
/ (a
f a -> a -> a
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" (Int -> UGen
forall n. Real n => n -> UGen
constant Int
nc UGen -> [UGen] -> [UGen]
forall a. a -> [a] -> [a]
: UGen
k UGen -> [UGen] -> [UGen]
forall a. a -> [a] -> [a]
: [UGen]
z) Int
nc

-- | Lookup index of STK instrument by name.
stkAt :: (Num t,Enum t) => String -> t
stkAt :: 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 = [String] -> [t] -> [(String, t)]
forall a b. [a] -> [b] -> [(a, b)]
zip [String]
nm_seq [t
0..]
  in case String -> [(String, t)] -> Maybe t
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 -> String -> t
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 (String -> UGen
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 Maybe ([Sample] -> Sample)
forall a. Maybe a
Nothing [Rate
AR] (Rate -> Either Rate [Int]
forall a b. a -> Either a b
Left Rate
rate) String
"StkGlobals" ([UGen
showWarnings,UGen
printErrors] [UGen] -> [UGen] -> [UGen]
forall a. [a] -> [a] -> [a]
++ Bool -> UGen -> [UGen]
U.unpackLabel Bool
False UGen
rawfilepath) Maybe [UGen]
forall a. Maybe a
Nothing Int
1 (Int -> Special
Special Int
0) UGenId
NoId