-- | For hand-writing Ugens.
module Sound.Sc3.Ugen.Bindings.Hw.Construct where

import Sound.Sc3.Common.Rate

import Sound.Sc3.Ugen.Types

-- | 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 a. Eq a => a -> [a] -> 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 a. [a] -> 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
InitialisationRate String
name [] Int
1