module Sound.Sc3.Ugen.Analysis where
import Data.List
import qualified Sound.Sc3.Common.Rate as Rate
import qualified Sound.Sc3.Ugen.Bindings.Db as Db
import qualified Sound.Sc3.Common.Mce as Mce
import Sound.Sc3.Ugen.Types
ugen_primitive_set :: Ugen -> [Primitive Ugen]
ugen_primitive_set :: Ugen -> [Primitive Ugen]
ugen_primitive_set Ugen
u =
case Ugen
u of
Constant_U Constant
_ -> []
Control_U Control
_ -> []
Label_U Label
_ -> []
Primitive_U Primitive Ugen
p -> [Primitive Ugen
p]
Proxy_U Proxy Ugen
p -> [forall t. Proxy t -> Primitive t
proxySource Proxy Ugen
p]
Mce_U Mce Ugen
m -> forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Ugen -> [Primitive Ugen]
ugen_primitive_set (forall t. Mce t -> [t]
Mce.mce_to_list Mce Ugen
m)
Mrg_U Mrg Ugen
m -> Ugen -> [Primitive Ugen]
ugen_primitive_set (forall t. Mrg t -> t
mrgLeft Mrg Ugen
m)
primitive_is_pv_rate :: String -> Bool
primitive_is_pv_rate :: String -> Bool
primitive_is_pv_rate String
nm = String
nm forall a. Eq a => a -> a -> Bool
== String
"FFT" Bool -> Bool -> Bool
|| String
"PV_" forall a. Eq a => [a] -> [a] -> Bool
`isPrefixOf` String
nm
ugen_is_pv_rate :: Ugen -> Bool
ugen_is_pv_rate :: Ugen -> Bool
ugen_is_pv_rate = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (String -> Bool
primitive_is_pv_rate forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. Primitive t -> String
ugenName) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ugen -> [Primitive Ugen]
ugen_primitive_set
pv_track_buffer :: Ugen -> Either String Ugen
pv_track_buffer :: Ugen -> Either String Ugen
pv_track_buffer Ugen
u =
case Ugen -> [Primitive Ugen]
ugen_primitive_set Ugen
u of
[] -> forall a b. a -> Either a b
Left String
"pv_track_buffer: not located"
Primitive Ugen
p:[Primitive Ugen]
_ -> case forall t. Primitive t -> String
ugenName Primitive Ugen
p of
String
"FFT" -> forall a b. b -> Either a b
Right (forall t. Primitive t -> [t]
ugenInputs Primitive Ugen
p forall a. [a] -> Int -> a
!! Int
0)
String
"PV_Split" -> forall a b. b -> Either a b
Right (forall t. Primitive t -> [t]
ugenInputs Primitive Ugen
p forall a. [a] -> Int -> a
!! Int
1)
String
_ -> Ugen -> Either String Ugen
pv_track_buffer (forall t. Primitive t -> [t]
ugenInputs Primitive Ugen
p forall a. [a] -> Int -> a
!! Int
0)
buffer_nframes :: Ugen -> Ugen
buffer_nframes :: Ugen -> Ugen
buffer_nframes Ugen
u =
case Ugen -> [Primitive Ugen]
ugen_primitive_set Ugen
u of
[] -> Rate -> Ugen -> Ugen
Db.bufFrames (Ugen -> Rate
rateOf Ugen
u) Ugen
u
Primitive Ugen
p:[Primitive Ugen]
_ -> case forall t. Primitive t -> String
ugenName Primitive Ugen
p of
String
"LocalBuf" -> forall t. Primitive t -> [t]
ugenInputs Primitive Ugen
p forall a. [a] -> Int -> a
!! Int
1
String
_ -> Rate -> Ugen -> Ugen
Db.bufFrames (Ugen -> Rate
rateOf Ugen
u) Ugen
u
pv_track_nframes :: Ugen -> Either String Ugen
pv_track_nframes :: Ugen -> Either String Ugen
pv_track_nframes Ugen
u = Ugen -> Either String Ugen
pv_track_buffer Ugen
u forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a b. b -> Either a b
Right forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ugen -> Ugen
buffer_nframes
ugen_remove_out_node :: Ugen -> (String,Ugen)
ugen_remove_out_node :: Ugen -> (String, Ugen)
ugen_remove_out_node Ugen
u =
let err :: a
err = forall a. HasCallStack => String -> a
error String
"ugen_remove_out_node?"
assert_is_output :: String -> String
assert_is_output String
x = if String
x forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String
"Out", String
"ReplaceOut", String
"OffsetOut"] then String
x else forall {a}. a
err
in case Ugen
u of
Primitive_U (Primitive Rate
Rate.AudioRate String
nm (Ugen
_bus:[Ugen]
inputs) [] Special
_special UgenId
_uid Brackets
_brk) -> (String -> String
assert_is_output String
nm, [Ugen] -> Ugen
mce [Ugen]
inputs)
Mrg_U (Mrg Ugen
lhs Ugen
rhs) -> let (String
nm,Ugen
res) = Ugen -> (String, Ugen)
ugen_remove_out_node Ugen
lhs in (String
nm,Mrg Ugen -> Ugen
Mrg_U (forall t. t -> t -> Mrg t
Mrg Ugen
res Ugen
rhs))
Ugen
_ -> forall {a}. a
err