module Sound.Tidal.Strategies where
import Data.Ratio
import Control.Applicative
import Sound.Tidal.Dirt
import Sound.Tidal.Pattern
import Sound.Tidal.Stream
import Sound.Tidal.Time
import Sound.Tidal.Utils
stutter n t p = stack $ map (\i -> (t * (fromIntegral i)) ~> p) [0 .. (n1)]
echo = stutter 2
triple = stutter 3
quad = stutter 4
double = echo
jux f p = stack [p |+| pan (pure 0), f $ p |+| pan (pure 1)]
juxcut f p = stack [p |+| pan (pure 0) |+| cut (pure (1)),
f $ p |+| pan (pure 1) |+| cut (pure (2))
]
jux4 f p = stack [p |+| pan (pure 0), f $ p |+| pan (pure 2)]
superimpose f p = stack [p, f p]
smash n xs p = slowcat $ map (\n -> slow n p') xs
where p' = striate n p
brak = every 2 (((1%4) <~) . (\x -> cat [x, silence]))
samples :: Applicative f => f String -> f Int -> f String
samples p p' = pick <$> p <*> p'
spread :: (a -> t -> Pattern b) -> [a] -> t -> Pattern b
spread f xs p = cat $ map (\x -> f x p) xs
slowspread :: (a -> t -> Pattern b) -> [a] -> t -> Pattern b
slowspread f xs p = slowcat $ map (\x -> f x p) xs
spread' :: (a -> Pattern b -> Pattern c) -> Pattern a -> Pattern b -> Pattern c
spread' f timepat pat =
Pattern $ \r -> concatMap (\(_,r', x) -> (arc (f x pat) r')) (rs r)
where rs r = arc (filterOnsetsInRange timepat) r
whenmod :: Int -> Int -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
whenmod a b = Sound.Tidal.Pattern.when ((\t -> (t `mod` a) >= b ))
trunc :: Time -> Pattern a -> Pattern a
trunc t p = slow t $ Pattern $ \a -> concatMap f $ arcCycles a
where f a = mapArcs (stretch . trunc') $ arc p (trunc' a)
trunc' (s,e) = (min s ((sam s) + t), min e ((sam s) + t))
stretch (s,e) = (sam s + ((s sam s) / t), sam s + ((e sam s) / t))
spreadf ts p = spread ($)
spin :: Int -> OscPattern -> OscPattern
spin steps p = stack $ map (\n -> (((fromIntegral n)%(fromIntegral steps)) <~ p |+| pan (pure $ (fromIntegral n)/(fromIntegral steps)))) [0 .. steps]
iter :: Int -> Pattern a -> Pattern a
iter n p = slowcat $ map (\i -> ((fromIntegral i)%(fromIntegral n)) <~ p) [0 .. n]
spin4 step p = stack $ map (\n -> ((toRational n)/4) <~ p |+| pan (pure $ n)) [0,step .. 3]
spin16 step p = stack $ map (\n -> ((toRational n)/16) <~ p |+| pan (pure $ n)) [0,step .. 15]
sawwave4 = ((*4) <$> sawwave1)
sinewave4 = ((*4) <$> sinewave1)
rand4 = ((*4) <$> rand)
stackwith p ps | null ps = silence
| otherwise = stack $ map (\(i, p') -> p' |+| (((fromIntegral i) % l) <~ p)) (zip [0 ..] ps)
where l = fromIntegral $ length ps
inside n f p = density n $ f (slow n p)
stut :: Integer -> Double -> Rational -> OscPattern -> OscPattern
stut steps feedback time p = stack (p:(map (\x -> (((x%steps)*time) <~ (p |+| gain (pure $ scale (fromIntegral x))))) [0..(steps1)]))
where scale x
= ((+feedback) . (*(1feedback)) . (/(fromIntegral steps)) . ((fromIntegral steps))) x