{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies, NoMonoLocalBinds #-}
{-# LANGUAGE NoIncoherentInstances #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE NoUndecidableInstances #-}
module Vivid.UGens.Conversion (
a2k
, k2a
) where
import Vivid.SC.SynthDef.Types (CalculationRate(..))
import Vivid.SynthDef
import qualified Data.ByteString.UTF8 as UTF8
a2k :: ToSig s a => s -> SDBody' a Signal
a2k = AR `to` KR
k2a :: ToSig s a => s -> SDBody' a Signal
k2a = KR `to` AR
to :: ToSig s a => CalculationRate -> CalculationRate -> (s -> SDBody' a Signal)
to fromRate toRate = \s -> do
s' <- toSig s
getCalcRate s' >>= \case
rate | rate == fromRate -> return ()
_ -> error $ mconcat [
show fromRate,"->",show toRate
," called without a "
,show fromRate," input"
]
addUGen $ UGen (UGName_S letters) toRate [s'] 1
where
letters = UTF8.fromString [calcLetter fromRate,'2',calcLetter toRate]
calcLetter = \case
KR -> 'K'
AR -> 'A'
IR -> error "ir?!?!"
DR -> error "dominican republic?!?!"