module Csound.Typed.Control (
    -- * SE
    module Csound.Typed.GlobalState.SE,
    -- ** SE reference
    module Csound.Typed.Control.Ref,
    -- * Global settings
    instr0, getIns, setDur,
    -- * Misc
    freshId,
    -- * Score
    module Csound.Typed.Control.Mix,
    -- * Midi
    module Csound.Typed.Control.Midi,
    -- * Named instruments (API)
    module Csound.Typed.Control.Api,
    -- * OSC
    module Csound.Typed.Control.Osc,
    -- * Channel
    module Csound.Typed.Control.Channel,
    -- * Sf2
    module Csound.Typed.Control.Sf2,
    -- * Events
    module Csound.Typed.Control.Evt,
    -- * Band-limited oscillators
    module Csound.Typed.Control.Vco,
    -- * Imperative instruments
    module Csound.Typed.Control.InstrRef,
    -- * Array folding and traversals    
    module Csound.Typed.Control.ArrayTraverse,
    -- * Reads global config arguments from command line
    module Csound.Typed.Control.MacrosArgs
) where

import Csound.Typed.GlobalState.SE
import Csound.Typed.Control.Ref

import Csound.Typed.Control.Evt
import Csound.Typed.Control.Mix
import Csound.Typed.Control.Midi
import Csound.Typed.Control.Api
import Csound.Typed.Control.Osc
import Csound.Typed.Control.Channel
import Csound.Typed.Control.Sf2
import Csound.Typed.Control.Vco
import Csound.Typed.Control.InstrRef
import Csound.Typed.Control.ArrayTraverse
import Csound.Typed.Control.MacrosArgs

import Csound.Typed.Types
import Csound.Typed.GlobalState

instr0 :: Tuple a => SE a -> SE a
instr0 :: SE a -> SE a
instr0 SE a
a = a -> SE a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> SE a) -> a -> SE a
forall a b. (a -> b) -> a -> b
$ GE [E] -> a
forall a. Tuple a => GE [E] -> a
toTuple (GE [E] -> a) -> GE [E] -> a
forall a b. (a -> b) -> a -> b
$ Int -> [Rate] -> SE [E] -> GE [E]
saveIns0 Int
ins0Arity (a -> [Rate]
forall a. Tuple a => a -> [Rate]
tupleRates (a -> [Rate]) -> a -> [Rate]
forall a b. (a -> b) -> a -> b
$ SE a -> a
forall a. Tuple a => SE a -> a
proxy SE a
a) SE [E]
ins0Exp
    where
        ins0Exp :: SE [E]
ins0Exp = SE (GE [E]) -> SE [E]
forall a. SE (GE a) -> SE a
execGEinSE (SE (GE [E]) -> SE [E]) -> SE (GE [E]) -> SE [E]
forall a b. (a -> b) -> a -> b
$ (a -> GE [E]) -> SE a -> SE (GE [E])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> GE [E]
forall a. Tuple a => a -> GE [E]
fromTuple SE a
a

        ins0Arity :: Int
ins0Arity = a -> Int
forall a. Tuple a => a -> Int
tupleArity (a -> Int) -> a -> Int
forall a b. (a -> b) -> a -> b
$ SE a -> a
forall a. Tuple a => SE a -> a
proxy SE a
a

        proxy :: Tuple a => SE a -> a
        proxy :: SE a -> a
proxy = a -> SE a -> a
forall a b. a -> b -> a
const (GE [E] -> a
forall a. Tuple a => GE [E] -> a
toTuple (GE [E] -> a) -> GE [E] -> a
forall a b. (a -> b) -> a -> b
$ [E] -> GE [E]
forall (m :: * -> *) a. Monad m => a -> m a
return ([E] -> GE [E]) -> [E] -> GE [E]
forall a b. (a -> b) -> a -> b
$ E -> [E]
forall a. a -> [a]
repeat E
forall a. HasCallStack => a
undefined)

getIns :: Sigs a => SE a
getIns :: SE a
getIns = SE a
res
    where 
        res :: SE a
res = (GE [E] -> a) -> SE (GE [E]) -> SE a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap GE [E] -> a
forall a. Tuple a => GE [E] -> a
toTuple (SE (GE [E]) -> SE a) -> SE (GE [E]) -> SE a
forall a b. (a -> b) -> a -> b
$ Dep [E] -> SE (GE [E])
forall a. Dep a -> SE (GE a)
fromDep (Dep [E] -> SE (GE [E])) -> Dep [E] -> SE (GE [E])
forall a b. (a -> b) -> a -> b
$ Int -> Dep [E]
forall (m :: * -> *). Monad m => Int -> DepT m [E]
getIn (a -> Int
forall a. Tuple a => a -> Int
tupleArity (a -> Int) -> a -> Int
forall a b. (a -> b) -> a -> b
$ SE a -> a
forall a. SE a -> a
proxy SE a
res) 

        proxy :: SE a -> a
        proxy :: SE a -> a
proxy = a -> SE a -> a
forall a b. a -> b -> a
const a
forall a. HasCallStack => a
undefined

-- | Sets the global duration of the file or output signal to the given value.
-- It should be used only once! The proper place is in the top-most
-- expression before sending to @dac@ or @writeWav@.
setDur :: Sigs a => D -> a -> a
setDur :: D -> a -> a
setDur D
mdt a
as = GE [E] -> a
forall a. Tuple a => GE [E] -> a
toTuple (GE [E] -> a) -> GE [E] -> a
forall a b. (a -> b) -> a -> b
$ do
    E
dt <- D -> GE E
forall a. Val a => a -> GE E
toGE D
mdt
    [E]
vals <- a -> GE [E]
forall a. Tuple a => a -> GE [E]
fromTuple a
as
    E -> GE ()
setDurationForce E
dt
    [E] -> GE [E]
forall (m :: * -> *) a. Monad m => a -> m a
return [E]
vals

-- | Gets new id.
freshId :: SE D
freshId :: SE D
freshId = Dep D -> SE D
forall a. Dep a -> SE a
SE (Dep D -> SE D) -> Dep D -> SE D
forall a b. (a -> b) -> a -> b
$ (E -> D) -> DepT GE E -> Dep D
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap E -> D
forall a. Val a => E -> a
fromE DepT GE E
forall (m :: * -> *). Monad m => DepT m E
freeChn