module Harmonic.Interface.Tidal.Utils (
oct,
pullBy, pushBy,
humanise,
onset,
hemidemisemiquaver, demisemiquaver, semiquaver, quaver, crotchet, minim,
) where
import Sound.Tidal.Context
oct :: Int -> Pattern ValueMap
oct :: Int -> Pattern ValueMap
oct Int
n = Pattern Note -> Pattern ValueMap
note (Int -> Pattern Note
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
12 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
n))
pullBy :: Time -> Pattern a -> Pattern a
pullBy :: forall a. Time -> Pattern a -> Pattern a
pullBy Time
t Pattern a
pat = (Time -> Pattern Time
forall a. a -> Pattern a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Time
t) Pattern Time -> Pattern a -> Pattern a
forall a. Pattern Time -> Pattern a -> Pattern a
<~ Pattern a
pat
pushBy :: Time -> Pattern a -> Pattern a
pushBy :: forall a. Time -> Pattern a -> Pattern a
pushBy Time
t Pattern a
pat = (Time -> Pattern Time
forall a. a -> Pattern a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Time
t) Pattern Time -> Pattern a -> Pattern a
forall a. Pattern Time -> Pattern a -> Pattern a
~> Pattern a
pat
humanise :: Double -> Pattern ValueMap
humanise :: Double -> Pattern ValueMap
humanise Double
n = String -> Pattern Double -> Pattern ValueMap
pF String
"amp" (Pattern Double
-> Pattern Double -> Pattern Double -> Pattern Double
forall a. Num a => Pattern a -> Pattern a -> Pattern a -> Pattern a
range (Double -> Pattern Double
forall a. a -> Pattern a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (-Double
0.09 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n)) (Double -> Pattern Double
forall a. a -> Pattern a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Double
0.09 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n)) Pattern Double
forall a. Fractional a => Pattern a
rand)
onset :: Pattern a -> Pattern a
onset :: forall a. Pattern a -> Pattern a
onset Pattern a
pat = Pattern a
pat {query = q, pureValue = Nothing}
where
q :: State -> [EventF (ArcF Time) a]
q State
st = (EventF (ArcF Time) a -> EventF (ArcF Time) a)
-> [EventF (ArcF Time) a] -> [EventF (ArcF Time) a]
forall a b. (a -> b) -> [a] -> [b]
map EventF (ArcF Time) a -> EventF (ArcF Time) a
forall {b}. EventF (ArcF Time) b -> EventF (ArcF Time) b
align (Pattern a -> State -> [EventF (ArcF Time) a]
forall a. Pattern a -> State -> [Event a]
query Pattern a
pat State
st)
align :: EventF (ArcF Time) b -> EventF (ArcF Time) b
align EventF (ArcF Time) b
ev = case EventF (ArcF Time) b -> Maybe (ArcF Time)
forall a b. EventF a b -> Maybe a
whole EventF (ArcF Time) b
ev of
Maybe (ArcF Time)
Nothing -> EventF (ArcF Time) b
ev
Just (Arc Time
_ Time
we) ->
let ps :: Time
ps = ArcF Time -> Time
forall a. ArcF a -> a
start (EventF (ArcF Time) b -> ArcF Time
forall a b. EventF a b -> a
part EventF (ArcF Time) b
ev)
in if Time
ps Time -> Time -> Bool
forall a. Eq a => a -> a -> Bool
== Time -> Time
sam Time
ps
then EventF (ArcF Time) b
ev {whole = Just (Arc ps (min we (nextSam ps)))}
else EventF (ArcF Time) b
ev
hemidemisemiquaver, demisemiquaver, semiquaver, quaver, crotchet, minim :: Time
hemidemisemiquaver :: Time
hemidemisemiquaver = Time
1Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/Time
64
demisemiquaver :: Time
demisemiquaver = Time
1Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/Time
32
semiquaver :: Time
semiquaver = Time
1Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/Time
16
quaver :: Time
quaver = Time
1Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/Time
8
crotchet :: Time
crotchet = Time
1Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/Time
4
minim :: Time
minim = Time
1Time -> Time -> Time
forall a. Fractional a => a -> a -> a
/Time
2