-- | For hand-writing UGens.
module Sound.SC3.UGen.Bindings.HW.Construct where

import Sound.SC3.Common.Rate
import Sound.SC3.UGen.Type

-- | Oscillator constructor with constrained set of operating 'Rate's.
mk_osc :: [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc :: [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc [Rate]
rs UGenId
z Rate
r String
c [UGen]
i Int
o =
    if Rate
r Rate -> [Rate] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Rate]
rs
    then 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]
rs (Rate -> Either Rate [Int]
forall a b. a -> Either a b
Left Rate
r) String
c [UGen]
i Maybe [UGen]
forall a. Maybe a
Nothing Int
o (Int -> Special
Special Int
0) UGenId
z
    else String -> UGen
forall a. HasCallStack => String -> a
error (String
"mk_osc: rate restricted: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ (Rate, [Rate], String) -> String
forall a. Show a => a -> String
show (Rate
r, [Rate]
rs, String
c))

-- | Oscillator constructor with 'all_rates'.
mkOsc :: Rate -> String -> [UGen] -> Int -> UGen
mkOsc :: Rate -> String -> [UGen] -> Int -> UGen
mkOsc = [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc [Rate]
all_rates UGenId
no_id

-- | Oscillator constructor, rate restricted variant.
mkOscR :: [Rate] -> Rate -> String -> [UGen] -> Int -> UGen
mkOscR :: [Rate] -> Rate -> String -> [UGen] -> Int -> UGen
mkOscR [Rate]
rs = [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc [Rate]
rs UGenId
no_id

-- | Rate restricted oscillator constructor, setting identifier.
mkOscIdR :: [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mkOscIdR :: [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mkOscIdR = [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc

-- | Oscillator constructor, setting identifier.
mkOscId :: UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mkOscId :: UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mkOscId = [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc [Rate]
all_rates

-- | Provided 'UGenId' variant of 'mkOscMCE'.
mk_osc_mce :: UGenId -> Rate -> String -> [UGen] -> UGen -> Int -> UGen
mk_osc_mce :: UGenId -> Rate -> String -> [UGen] -> UGen -> Int -> UGen
mk_osc_mce UGenId
z Rate
r String
c [UGen]
i UGen
j =
    let i' :: [UGen]
i' = [UGen]
i [UGen] -> [UGen] -> [UGen]
forall a. [a] -> [a] -> [a]
++ UGen -> [UGen]
mceChannels UGen
j
    in [Rate] -> UGenId -> Rate -> String -> [UGen] -> Int -> UGen
mk_osc [Rate]
all_rates UGenId
z Rate
r String
c [UGen]
i'

-- | Variant oscillator constructor with MCE collapsing input.
mkOscMCE :: Rate -> String -> [UGen] -> UGen -> Int -> UGen
mkOscMCE :: Rate -> String -> [UGen] -> UGen -> Int -> UGen
mkOscMCE = UGenId -> Rate -> String -> [UGen] -> UGen -> Int -> UGen
mk_osc_mce UGenId
no_id

-- | Variant oscillator constructor with MCE collapsing input.
mkOscMCEId :: UGenId -> Rate -> String -> [UGen] -> UGen -> Int -> UGen
mkOscMCEId :: UGenId -> Rate -> String -> [UGen] -> UGen -> Int -> UGen
mkOscMCEId = UGenId -> Rate -> String -> [UGen] -> UGen -> Int -> UGen
mk_osc_mce

-- | Rate constrained filter 'UGen' constructor.
mk_filter :: [Rate] -> [Int] -> UGenId -> String -> [UGen] -> Int -> UGen
mk_filter :: [Rate] -> [Int] -> UGenId -> String -> [UGen] -> Int -> UGen
mk_filter [Rate]
rs [Int]
ix UGenId
z String
c [UGen]
i Int
o = 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]
rs ([Int] -> Either Rate [Int]
forall a b. b -> Either a b
Right [Int]
ix) String
c [UGen]
i Maybe [UGen]
forall a. Maybe a
Nothing Int
o (Int -> Special
Special Int
0) UGenId
z

-- | Filter UGen constructor.
mkFilterIdR :: [Rate] -> UGenId -> String -> [UGen] -> Int -> UGen
mkFilterIdR :: [Rate] -> UGenId -> String -> [UGen] -> Int -> UGen
mkFilterIdR [Rate]
rs UGenId
z String
nm [UGen]
i = [Rate] -> [Int] -> UGenId -> String -> [UGen] -> Int -> UGen
mk_filter [Rate]
rs [Int
0 .. [UGen] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [UGen]
i Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1] UGenId
z String
nm [UGen]
i

-- | Filter UGen constructor.
mkFilterR :: [Rate] -> String -> [UGen] -> Int -> UGen
mkFilterR :: [Rate] -> String -> [UGen] -> Int -> UGen
mkFilterR [Rate]
rs = [Rate] -> UGenId -> String -> [UGen] -> Int -> UGen
mkFilterIdR [Rate]
rs UGenId
no_id

-- | Filter 'UGen' constructor.
mkFilter :: String -> [UGen] -> Int -> UGen
mkFilter :: String -> [UGen] -> Int -> UGen
mkFilter = [Rate] -> String -> [UGen] -> Int -> UGen
mkFilterR [Rate]
all_rates

-- | Filter UGen constructor.
mkFilterId :: UGenId -> String -> [UGen] -> Int -> UGen
mkFilterId :: UGenId -> String -> [UGen] -> Int -> UGen
mkFilterId = [Rate] -> UGenId -> String -> [UGen] -> Int -> UGen
mkFilterIdR [Rate]
all_rates

-- | Provided 'UGenId' filter with 'mce' input.
mk_filter_mce :: [Rate] -> UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mk_filter_mce :: [Rate] -> UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mk_filter_mce [Rate]
rs UGenId
z String
c [UGen]
i UGen
j = [Rate] -> UGenId -> String -> [UGen] -> Int -> UGen
mkFilterIdR [Rate]
rs UGenId
z String
c ([UGen]
i [UGen] -> [UGen] -> [UGen]
forall a. [a] -> [a] -> [a]
++ UGen -> [UGen]
mceChannels UGen
j)

-- | Variant filter constructor with MCE collapsing input.
mkFilterMCER :: [Rate] -> String -> [UGen] -> UGen -> Int -> UGen
mkFilterMCER :: [Rate] -> String -> [UGen] -> UGen -> Int -> UGen
mkFilterMCER [Rate]
rs = [Rate] -> UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mk_filter_mce [Rate]
rs UGenId
no_id

-- | Variant filter constructor with MCE collapsing input.
mkFilterMCE :: String -> [UGen] -> UGen -> Int -> UGen
mkFilterMCE :: String -> [UGen] -> UGen -> Int -> UGen
mkFilterMCE = [Rate] -> UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mk_filter_mce [Rate]
all_rates UGenId
no_id

-- | Variant filter constructor with MCE collapsing input.
mkFilterMCEId :: UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mkFilterMCEId :: UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mkFilterMCEId = [Rate] -> UGenId -> String -> [UGen] -> UGen -> Int -> UGen
mk_filter_mce [Rate]
all_rates

-- | Information unit generators are very specialized.
mkInfo :: String -> UGen
mkInfo :: String -> UGen
mkInfo String
name = Rate -> String -> [UGen] -> Int -> UGen
mkOsc Rate
IR String
name [] Int
1