-
Notifications
You must be signed in to change notification settings - Fork 0
/
chopBy.tidal
62 lines (41 loc) · 1.84 KB
/
chopBy.tidal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Prelude hiding ((*>), (<*))
import qualified Data.Map.Strict as Map
import Data.Maybe (fromJust, fromMaybe, isJust)
import Data.Ratio
chopBy :: Pattern Int -> Pattern Double -> ControlPattern -> ControlPattern
chopBy = patternify2 _chopBy
-- v1?
_chopBy :: Int -> Double -> ControlPattern -> ControlPattern
_chopBy n f pat = squeezeJoin $ fmap (chopPart n f) pat
chopPart :: Int -> Double -> ValueMap -> ControlPattern
chopPart n f v = fastcat $ map (pure . rangemap v) slices
where
rangemap v (b, e) = Map.union (fromMaybe (makeMap (b,e)) $ merge v (b,e)) v
merge :: ValueMap -> (Double, Double) -> Maybe ValueMap
merge v (b, e) = do
b' <- Map.lookup "begin" v >>= getF
e' <- Map.lookup "end" v >>= getF
let d = e' - b'
return $ makeMap (b' + b*d, b' + e*d)
makeMap (b,e) = Map.fromList [("begin", VF b), ("end", VF e)]
slices = map (\i -> (slot * fromIntegral i, slot * fromIntegral i + f)) [0 .. n-1]
slot = (1 - f) / fromIntegral n
-- v2 ?
chopPart :: Int -> Double -> ValueMap -> ControlPattern
chopPart n f v = fastcat $ map (pure . rangemap v) slices
where
rangemap v (b, e) = Map.union (fromMaybe (makeMap (b, e)) $ merge v (b, e)) v
merge :: ValueMap -> (Double, Double) -> Maybe ValueMap
merge v (b, e) = do
b' <- Map.lookup "begin" v >>= getF
e' <- Map.lookup "end" v >>= getF
let d = e' - b'
return $ makeMap (b' + b * d, b' + e * d)
makeMap (b, e) = Map.fromList [("begin", VF b), ("end", VF e)]
slices = map (\i -> (i * slot, i * slot + f)) [0 .. fromIntegral (n - 1)]
slot = f
_chopBy 2 (1/6) "a b c d"
d1 $ chopBy 2 (1/6) $ s "k"
let scaleChoice = ["mixolydian", "aeolian"]
scaleChoice!!0
d1 $ note (scale (scaleChoice!!0) "0 1 2 3") # s "arpy*8"