module Csound.Types(
Sig, D, Tab, Str, Spec, Wspec,
BoolSig, BoolD, Val(..), SigOrD,
Sig2, Sig3, Sig4, Sig5, Sig6, Sig8,
Sig2_2, Sig2_3, Sig2_4, Sig2_5, Sig2_6, Sig2_7, Sig2_8,
double, int, text,
idur, getSampleRate, getControlRate, getBlockSize,
getBpm, setBpm, syn, takt,
ar, kr, ir, sig,
withInits, withDs, withSigs, withTabs,
withD, withSig, withTab, withSeed,
quot', rem', div', mod', ceil', floor', round', int', frac',
boolSig, when1, whens, whenElse, whenD1, whenDs, whileDo, untilDo, whileDoD, untilDoD, whenElseD, compareWhenD,
equalsTo, notEqualsTo, lessThan, greaterThan, lessThanEquals, greaterThanEquals,
ar1, ar2, ar4, ar6, ar8,
Tuple(..), makeTupleMethods, Unit, unit, atTuple,
ifTuple, guardedTuple, caseTuple,
Arg, atArg,
ifArg, guardedArg, caseArg,
MonoArg(..), MonoAdsr, adsrMonoSynt, monoAdsr,
Sigs,
Arr, newLocalArr, newGlobalArr, newLocalCtrlArr, newGlobalCtrlArr,
writeArr, readArr, modifyArr, mixArr,
Arr1, DArr1, Arr2, DArr2, Arr3, DArr3,
arr1, darr1, arr2, darr2, arr3, darr3,
foreachArr, foreachArrD, forRowArr, forColumnArr, forRowArrD, forColumnArrD,
foldArr, foldRowArr, foldColumnArr, foldRowsArrD, foldColumnsArrD,
fillLocalArr, fillGlobalArr, fillLocalCtrlArr, fillGlobalCtrlArr,
maparrayNew, lenarray, copyf2array, copya2ftab, minarray, maxarray, sumarray,
scalearray, slicearrayNew,
maparrayCopy, slicearrayCopy,
SpecArr,
fftNew, fftinvNew, rfftNew, rifftNew, pvs2tab, tab2pvs, cmplxprodNew,
rect2polNew, pol2rectNew, pol2rect2New, windowArrayNew,
r2cNew, c2rNew, magsArrayNew, phsArrayNew,
fftCopy, fftinvCopy, rfftCopy, rifftCopy, cmplxprodCopy,
rect2polCopy, pol2rectCopy, pol2rect2Copy, windowArrayCopy,
r2cCopy, c2rCopy, magsArrayCopy, phsArrayCopy
) where
import Data.Boolean
import Csound.Typed.Types
import Csound.Typed.Control
import Csound.Control.SE
atArg :: (Tuple a, Arg a) => [a] -> D -> a
atArg as ind = guardedArg (zip (fmap (\x -> int x ==* ind) [0 .. ]) as) (head as)
atTuple :: (Tuple a) => [a] -> Sig -> a
atTuple as ind = guardedTuple (zip (fmap (\x -> sig (int x) ==* ind) [0 .. ]) as) (head as)
whenElseD :: BoolD -> SE () -> SE () -> SE ()
whenElseD cond ifDo elseDo = whenDs [(cond, ifDo)] elseDo
whenElse :: BoolSig -> SE () -> SE () -> SE ()
whenElse cond ifDo elseDo = whens [(cond, ifDo)] elseDo
compareWhenD :: D -> [(D, SE ())] -> SE ()
compareWhenD val conds = case conds of
[] -> return ()
[(cond, ifDo)] -> ifDo
(cond1, do1):(cond2, do2): [] -> whenElseD (val `lessThan` cond1) do1 do2
_ -> whenElseD (val `lessThan` rootCond) (compareWhenD val less) (compareWhenD val more)
where
(less, more) = splitAt (length conds `div` 2) conds
rootCond = fst $ last less
syn :: Sig -> Sig
syn x = (bpm / 60) * x
where bpm = getBpm
takt :: Sig -> Sig
takt = recip . syn